blob: c365ca6214406d022118b1ee3fb38ec22b649709 [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 Moolenaar0e7c4b92015-06-20 15:30:03 +0200619 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
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 Moolenaar071d4272004-06-13 20:20:40 +00001988 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1989 (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 Moolenaar071d4272004-06-13 20:20:40 +00002082 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002083#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002084 (char_u *)VAR_WIN, PV_PVW,
2085#else
2086 (char_u *)NULL, PV_NONE,
2087#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002088 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002089 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002090#ifdef FEAT_PRINTER
2091 (char_u *)&p_pdev, PV_NONE,
2092 {(char_u *)"", (char_u *)0L}
2093#else
2094 (char_u *)NULL, PV_NONE,
2095 {(char_u *)NULL, (char_u *)0L}
2096#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002097 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002098 {"printencoding", "penc", P_STRING|P_VI_DEF,
2099#ifdef FEAT_POSTSCRIPT
2100 (char_u *)&p_penc, 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 Moolenaar031cb742016-11-24 21:46:19 +01002107 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002108#ifdef FEAT_POSTSCRIPT
2109 (char_u *)&p_pexpr, PV_NONE,
2110 {(char_u *)"", (char_u *)0L}
2111#else
2112 (char_u *)NULL, PV_NONE,
2113 {(char_u *)NULL, (char_u *)0L}
2114#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002115 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002116 {"printfont", "pfn", P_STRING|P_VI_DEF,
2117#ifdef FEAT_PRINTER
2118 (char_u *)&p_pfn, PV_NONE,
2119 {
2120# ifdef MSWIN
2121 (char_u *)"Courier_New:h10",
2122# else
2123 (char_u *)"courier",
2124# endif
2125 (char_u *)0L}
2126#else
2127 (char_u *)NULL, PV_NONE,
2128 {(char_u *)NULL, (char_u *)0L}
2129#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002130 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002131 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2132#ifdef FEAT_PRINTER
2133 (char_u *)&p_header, PV_NONE,
Bram Moolenaar0903d562017-08-26 22:30:15 +02002134 /* untranslated to avoid problems when 'encoding'
2135 * is changed */
2136 {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002137#else
2138 (char_u *)NULL, PV_NONE,
2139 {(char_u *)NULL, (char_u *)0L}
2140#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002141 SCTX_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002142 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01002143#if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002144 (char_u *)&p_pmcs, PV_NONE,
2145 {(char_u *)"", (char_u *)0L}
2146#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 {"printmbfont", "pmbfn", 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_pmfn, 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 Moolenaar0e7c4b92015-06-20 15:30:03 +02002160 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002161#ifdef FEAT_PRINTER
2162 (char_u *)&p_popt, 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 Moolenaar071d4272004-06-13 20:20:40 +00002169 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002170 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002171 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002172 {"pumheight", "ph", P_NUM|P_VI_DEF,
2173#ifdef FEAT_INS_EXPAND
2174 (char_u *)&p_ph, PV_NONE,
2175#else
2176 (char_u *)NULL, PV_NONE,
2177#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002178 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaara8f04aa2018-02-10 15:36:55 +01002179 {"pumwidth", "pw", P_NUM|P_VI_DEF,
2180#ifdef FEAT_INS_EXPAND
2181 (char_u *)&p_pw, PV_NONE,
2182#else
2183 (char_u *)NULL, PV_NONE,
2184#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002185 {(char_u *)15L, (char_u *)15L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002186 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002187#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002188 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002189 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002190#else
2191 (char_u *)NULL, PV_NONE,
2192 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002193#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002194 SCTX_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002195 {"pythonthreehome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2196#if defined(FEAT_PYTHON3)
2197 (char_u *)&p_py3home, PV_NONE,
2198 {(char_u *)"", (char_u *)0L}
2199#else
2200 (char_u *)NULL, PV_NONE,
2201 {(char_u *)NULL, (char_u *)0L}
2202#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002203 SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002204 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002205#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002206 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002207 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002208#else
2209 (char_u *)NULL, PV_NONE,
2210 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002211#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002212 SCTX_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002213 {"pythonhome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2214#if defined(FEAT_PYTHON)
2215 (char_u *)&p_pyhome, PV_NONE,
2216 {(char_u *)"", (char_u *)0L}
2217#else
2218 (char_u *)NULL, PV_NONE,
2219 {(char_u *)NULL, (char_u *)0L}
2220#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002221 SCTX_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002222 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2223#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2224 (char_u *)&p_pyx, PV_NONE,
2225#else
2226 (char_u *)NULL, PV_NONE,
2227#endif
2228 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002229 SCTX_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002230 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2231#ifdef FEAT_TEXTOBJ
2232 (char_u *)&p_qe, PV_QE,
2233 {(char_u *)"\\", (char_u *)0L}
2234#else
2235 (char_u *)NULL, PV_NONE,
2236 {(char_u *)NULL, (char_u *)0L}
2237#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002238 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002239 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2240 (char_u *)&p_ro, PV_RO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002241 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002242 {"redraw", NULL, P_BOOL|P_VI_DEF,
2243 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002244 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002245 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2246#ifdef FEAT_RELTIME
2247 (char_u *)&p_rdt, PV_NONE,
2248#else
2249 (char_u *)NULL, PV_NONE,
2250#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002251 {(char_u *)2000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002252 {"regexpengine", "re", P_NUM|P_VI_DEF,
2253 (char_u *)&p_re, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002254 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002255 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2256 (char_u *)VAR_WIN, PV_RNU,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002257 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002258 {"remap", NULL, P_BOOL|P_VI_DEF,
2259 (char_u *)&p_remap, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002260 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002261 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002262#ifdef FEAT_RENDER_OPTIONS
2263 (char_u *)&p_rop, PV_NONE,
2264 {(char_u *)"", (char_u *)0L}
2265#else
2266 (char_u *)NULL, PV_NONE,
2267 {(char_u *)NULL, (char_u *)0L}
2268#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002269 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002270 {"report", NULL, P_NUM|P_VI_DEF,
2271 (char_u *)&p_report, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002272 {(char_u *)2L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002273 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
Bram Moolenaar4f974752019-02-17 17:44:42 +01002274#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00002275 (char_u *)&p_rs, PV_NONE,
2276#else
2277 (char_u *)NULL, PV_NONE,
2278#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002279 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002280 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2281#ifdef FEAT_RIGHTLEFT
2282 (char_u *)&p_ri, PV_NONE,
2283#else
2284 (char_u *)NULL, PV_NONE,
2285#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002286 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002287 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2288#ifdef FEAT_RIGHTLEFT
2289 (char_u *)VAR_WIN, PV_RL,
2290#else
2291 (char_u *)NULL, PV_NONE,
2292#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002293 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002294 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2295#ifdef FEAT_RIGHTLEFT
2296 (char_u *)VAR_WIN, PV_RLC,
2297 {(char_u *)"search", (char_u *)NULL}
2298#else
2299 (char_u *)NULL, PV_NONE,
2300 {(char_u *)NULL, (char_u *)0L}
2301#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002302 SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002303 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002304#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002305 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002306 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002307#else
2308 (char_u *)NULL, PV_NONE,
2309 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002310#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002311 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002312 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2313#ifdef FEAT_CMDL_INFO
2314 (char_u *)&p_ru, PV_NONE,
2315#else
2316 (char_u *)NULL, PV_NONE,
2317#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002318 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02002319 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002320#ifdef FEAT_STL_OPT
2321 (char_u *)&p_ruf, PV_NONE,
2322#else
2323 (char_u *)NULL, PV_NONE,
2324#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002325 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002326 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2327 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002328 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002329 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002330 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002331 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2332 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002333 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002334 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002335 (char_u *)VAR_WIN, PV_SCBIND,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002336 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002337 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2338 (char_u *)&p_sj, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002339 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002340 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
Bram Moolenaar375e3392019-01-31 18:26:10 +01002341 (char_u *)&p_so, PV_SO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002342 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002343 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002344 (char_u *)&p_sbo, PV_NONE,
2345 {(char_u *)"ver,jump", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002346 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002347 {"sections", "sect", P_STRING|P_VI_DEF,
2348 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002349 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002350 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002351 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2352 (char_u *)&p_secure, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002353 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002354 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002355 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002356 {(char_u *)"inclusive", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002357 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002358 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002359 (char_u *)&p_slm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002360 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002361 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002362#ifdef FEAT_SESSION
2363 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar4d8bac82018-03-09 21:33:34 +01002364 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize,terminal",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002365 (char_u *)0L}
2366#else
2367 (char_u *)NULL, PV_NONE,
2368 {(char_u *)0L, (char_u *)0L}
2369#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002370 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002371 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2372 (char_u *)&p_sh, PV_NONE,
2373 {
2374#ifdef VMS
2375 (char_u *)"-",
2376#else
Bram Moolenaar4f974752019-02-17 17:44:42 +01002377# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002378 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002379# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002380 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002381# endif
2382#endif /* VMS */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002383 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002384 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2385 (char_u *)&p_shcf, PV_NONE,
2386 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002387#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002388 (char_u *)"/c",
2389#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002390 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002391#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002392 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002393 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2394#ifdef FEAT_QUICKFIX
2395 (char_u *)&p_sp, PV_NONE,
2396 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002397#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002398 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002399#else
2400 (char_u *)">",
2401#endif
2402 (char_u *)0L}
2403#else
2404 (char_u *)NULL, PV_NONE,
2405 {(char_u *)0L, (char_u *)0L}
2406#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002407 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002408 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2409 (char_u *)&p_shq, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002410 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002411 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2412 (char_u *)&p_srr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002413 {(char_u *)">", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002414 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2415#ifdef BACKSLASH_IN_FILENAME
2416 (char_u *)&p_ssl, PV_NONE,
2417#else
2418 (char_u *)NULL, PV_NONE,
2419#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002420 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002421 {"shelltemp", "stmp", P_BOOL,
2422 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002423 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002424 {"shelltype", "st", P_NUM|P_VI_DEF,
2425#ifdef AMIGA
2426 (char_u *)&p_st, PV_NONE,
2427#else
2428 (char_u *)NULL, PV_NONE,
2429#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002430 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002431 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2432 (char_u *)&p_sxq, PV_NONE,
2433 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002434#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002435 (char_u *)"\"",
2436#else
2437 (char_u *)"",
2438#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002439 (char_u *)0L} SCTX_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002440 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2441 (char_u *)&p_sxe, PV_NONE,
2442 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01002443#if defined(MSWIN)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002444 (char_u *)"\"&|<>()@^",
2445#else
2446 (char_u *)"",
2447#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002448 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002449 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2450 (char_u *)&p_sr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002451 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002452 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2453 (char_u *)&p_sw, PV_SW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002454 {(char_u *)8L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002455 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2456 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar9dfa3132019-05-04 21:08:40 +02002457 {(char_u *)"S", (char_u *)"filnxtToOS"}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002458 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002459 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002460 (char_u *)&p_sn, PV_SN,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002461 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002462 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2463#ifdef FEAT_LINEBREAK
2464 (char_u *)&p_sbr, PV_NONE,
2465#else
2466 (char_u *)NULL, PV_NONE,
2467#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002468 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002469 {"showcmd", "sc", P_BOOL|P_VIM,
2470#ifdef FEAT_CMDL_INFO
2471 (char_u *)&p_sc, PV_NONE,
2472#else
2473 (char_u *)NULL, PV_NONE,
2474#endif
2475 {(char_u *)FALSE,
2476#ifdef UNIX
2477 (char_u *)FALSE
2478#else
2479 (char_u *)TRUE
2480#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002481 } SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002482 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2483 (char_u *)&p_sft, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002484 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002485 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2486 (char_u *)&p_sm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002487 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002488 {"showmode", "smd", P_BOOL|P_VIM,
2489 (char_u *)&p_smd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002490 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002491 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002492 (char_u *)&p_stal, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002493 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002494 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2495 (char_u *)&p_ss, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002496 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002497 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar375e3392019-01-31 18:26:10 +01002498 (char_u *)&p_siso, PV_SISO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002499 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002500 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2501#ifdef FEAT_SIGNS
2502 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002503 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002504#else
2505 (char_u *)NULL, PV_NONE,
2506 {(char_u *)NULL, (char_u *)0L}
2507#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002508 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002509 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2510 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002511 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002512 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2513 (char_u *)&p_scs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002514 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002515 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2516#ifdef FEAT_SMARTINDENT
2517 (char_u *)&p_si, PV_SI,
2518#else
2519 (char_u *)NULL, PV_NONE,
2520#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002521 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002522 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2523 (char_u *)&p_sta, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002524 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002525 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2526 (char_u *)&p_sts, PV_STS,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002527 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002528 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2529 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002530 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002531 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002532#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002533 (char_u *)VAR_WIN, PV_SPELL,
2534#else
2535 (char_u *)NULL, PV_NONE,
2536#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002537 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002538 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002539#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002540 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002541 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002542#else
2543 (char_u *)NULL, PV_NONE,
2544 {(char_u *)0L, (char_u *)0L}
2545#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002546 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002547 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2548 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002549#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002550 (char_u *)&p_spf, PV_SPF,
2551 {(char_u *)"", (char_u *)0L}
2552#else
2553 (char_u *)NULL, PV_NONE,
2554 {(char_u *)0L, (char_u *)0L}
2555#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002556 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002557 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2558 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002559#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002560 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002561 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002562#else
2563 (char_u *)NULL, PV_NONE,
2564 {(char_u *)0L, (char_u *)0L}
2565#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002566 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002567 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002568#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002569 (char_u *)&p_sps, PV_NONE,
2570 {(char_u *)"best", (char_u *)0L}
2571#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 Moolenaar071d4272004-06-13 20:20:40 +00002576 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002577 (char_u *)&p_sb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002578 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002579 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002580 (char_u *)&p_spr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002581 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002582 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2583 (char_u *)&p_sol, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002584 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02002585 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002586#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002587 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002588#else
2589 (char_u *)NULL, PV_NONE,
2590#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002591 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002592 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002593 (char_u *)&p_su, PV_NONE,
2594 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002595 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002596 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002597#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002598 (char_u *)&p_sua, PV_SUA,
2599 {(char_u *)"", (char_u *)0L}
2600#else
2601 (char_u *)NULL, PV_NONE,
2602 {(char_u *)0L, (char_u *)0L}
2603#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002604 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002605 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2606 (char_u *)&p_swf, PV_SWF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002607 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002608 {"swapsync", "sws", P_STRING|P_VI_DEF,
2609 (char_u *)&p_sws, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002610 {(char_u *)"fsync", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002611 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002612 (char_u *)&p_swb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002613 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002614 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2615#ifdef FEAT_SYN_HL
2616 (char_u *)&p_smc, PV_SMC,
2617 {(char_u *)3000L, (char_u *)0L}
2618#else
2619 (char_u *)NULL, PV_NONE,
2620 {(char_u *)0L, (char_u *)0L}
2621#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002622 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002623 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002624#ifdef FEAT_SYN_HL
2625 (char_u *)&p_syn, PV_SYN,
2626 {(char_u *)"", (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 Moolenaar110289e2019-05-23 15:38:06 +02002632 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL|P_MLE,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002633#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002634 (char_u *)&p_tal, PV_NONE,
2635#else
2636 (char_u *)NULL, PV_NONE,
2637#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002638 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002639 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002640 (char_u *)&p_tpm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002641 {(char_u *)10L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002642 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2643 (char_u *)&p_ts, PV_TS,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002644 {(char_u *)8L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002645 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2646 (char_u *)&p_tbs, PV_NONE,
2647#ifdef VMS /* binary searching doesn't appear to work on VMS */
2648 {(char_u *)0L, (char_u *)0L}
2649#else
2650 {(char_u *)TRUE, (char_u *)0L}
2651#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002652 SCTX_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002653 {"tagcase", "tc", P_STRING|P_VIM,
2654 (char_u *)&p_tc, PV_TC,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002655 {(char_u *)"followic", (char_u *)"followic"} SCTX_INIT},
Bram Moolenaar45e18cb2019-04-28 18:05:35 +02002656 {"tagfunc", "tfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
2657#ifdef FEAT_EVAL
2658 (char_u *)&p_tfu, PV_TFU,
2659 {(char_u *)"", (char_u *)0L}
2660#else
2661 (char_u *)NULL, PV_NONE,
2662 {(char_u *)0L, (char_u *)0L}
2663#endif
2664 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002665 {"taglength", "tl", P_NUM|P_VI_DEF,
2666 (char_u *)&p_tl, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002667 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002668 {"tagrelative", "tr", P_BOOL|P_VIM,
2669 (char_u *)&p_tr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002670 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002671 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002672 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002673 {
2674#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2675 (char_u *)"./tags,./TAGS,tags,TAGS",
2676#else
2677 (char_u *)"./tags,tags",
2678#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002679 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002680 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2681 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002682 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002683 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002684#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002685 (char_u *)&p_tcldll, PV_NONE,
2686 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002687#else
2688 (char_u *)NULL, PV_NONE,
2689 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002690#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002691 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002692 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2693 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002694 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002695 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2696#ifdef FEAT_ARABIC
2697 (char_u *)&p_tbidi, PV_NONE,
2698#else
2699 (char_u *)NULL, PV_NONE,
2700#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002701 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002702 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002703 (char_u *)&p_tenc, PV_NONE,
2704 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002705 SCTX_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002706 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2707#ifdef FEAT_TERMGUICOLORS
2708 (char_u *)&p_tgc, PV_NONE,
2709 {(char_u *)FALSE, (char_u *)FALSE}
2710#else
2711 (char_u*)NULL, PV_NONE,
2712 {(char_u *)FALSE, (char_u *)FALSE}
2713#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002714 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002715 {"termwinkey", "twk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2716#ifdef FEAT_TERMINAL
2717 (char_u *)VAR_WIN, PV_TWK,
2718 {(char_u *)"", (char_u *)NULL}
2719#else
2720 (char_u *)NULL, PV_NONE,
2721 {(char_u *)NULL, (char_u *)0L}
2722#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002723 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002724 {"termwinscroll", "twsl", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2725#ifdef FEAT_TERMINAL
2726 (char_u *)&p_twsl, PV_TWSL,
2727 {(char_u *)10000L, (char_u *)10000L}
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 {"termwinsize", "tws", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2734#ifdef FEAT_TERMINAL
2735 (char_u *)VAR_WIN, PV_TWS,
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002736 {(char_u *)"", (char_u *)NULL}
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 Moolenaarc6ddce32019-02-08 12:47:03 +01002742 {"termwintype", "twt", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar4f974752019-02-17 17:44:42 +01002743#if defined(MSWIN) && defined(FEAT_TERMINAL)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01002744 (char_u *)&p_twt, PV_NONE,
2745 {(char_u *)"", (char_u *)NULL}
2746#else
2747 (char_u *)NULL, PV_NONE,
2748 {(char_u *)NULL, (char_u *)0L}
2749#endif
2750 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002751 {"terse", NULL, P_BOOL|P_VI_DEF,
2752 (char_u *)&p_terse, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002753 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002754 {"textauto", "ta", P_BOOL|P_VIM,
2755 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002756 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002757 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002758 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2759 (char_u *)&p_tx, PV_TX,
2760 {
2761#ifdef USE_CRNL
2762 (char_u *)TRUE,
2763#else
2764 (char_u *)FALSE,
2765#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002766 (char_u *)0L} SCTX_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002767 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002768 (char_u *)&p_tw, PV_TW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002769 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002770 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002771#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002772 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002773#else
2774 (char_u *)NULL, PV_NONE,
2775#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002776 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002777 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2778 (char_u *)&p_to, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002779 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002780 {"timeout", "to", P_BOOL|P_VI_DEF,
2781 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002782 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002783 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2784 (char_u *)&p_tm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002785 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002786 {"title", NULL, P_BOOL|P_VI_DEF,
2787#ifdef FEAT_TITLE
2788 (char_u *)&p_title, PV_NONE,
2789#else
2790 (char_u *)NULL, PV_NONE,
2791#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002792 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002793 {"titlelen", NULL, P_NUM|P_VI_DEF,
2794#ifdef FEAT_TITLE
2795 (char_u *)&p_titlelen, PV_NONE,
2796#else
2797 (char_u *)NULL, PV_NONE,
2798#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002799 {(char_u *)85L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002800 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002801#ifdef FEAT_TITLE
2802 (char_u *)&p_titleold, PV_NONE,
2803 {(char_u *)N_("Thanks for flying Vim"),
2804 (char_u *)0L}
2805#else
2806 (char_u *)NULL, PV_NONE,
2807 {(char_u *)0L, (char_u *)0L}
2808#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002809 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02002810 {"titlestring", NULL, P_STRING|P_VI_DEF|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002811#ifdef FEAT_TITLE
2812 (char_u *)&p_titlestring, PV_NONE,
2813#else
2814 (char_u *)NULL, PV_NONE,
2815#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002816 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002817 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar4f974752019-02-17 17:44:42 +01002818#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002819 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002820 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002821#else
2822 (char_u *)NULL, PV_NONE,
2823 {(char_u *)0L, (char_u *)0L}
2824#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002825 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002826 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002827#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002828 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002829 {(char_u *)"small", (char_u *)0L}
2830#else
2831 (char_u *)NULL, PV_NONE,
2832 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002833#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002834 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002835 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2836 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002837 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002838 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2839 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002840 {(char_u *)-1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002841 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2842 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002843 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002844 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2845 (char_u *)&p_tf, 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 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2848#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2849 (char_u *)&p_ttym, PV_NONE,
2850#else
2851 (char_u *)NULL, PV_NONE,
2852#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002853 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002854 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2855 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002856 {(char_u *)999L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002857 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2858 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002859 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002860 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2861 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002862#ifdef FEAT_PERSISTENT_UNDO
2863 (char_u *)&p_udir, PV_NONE,
2864 {(char_u *)".", (char_u *)0L}
2865#else
2866 (char_u *)NULL, PV_NONE,
2867 {(char_u *)0L, (char_u *)0L}
2868#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002869 SCTX_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002870 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2871#ifdef FEAT_PERSISTENT_UNDO
2872 (char_u *)&p_udf, PV_UDF,
2873#else
2874 (char_u *)NULL, PV_NONE,
2875#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002876 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002877 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002878 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002879 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01002880#if defined(UNIX) || defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002881 (char_u *)1000L,
2882#else
2883 (char_u *)100L,
2884#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002885 (char_u *)0L} SCTX_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002886 {"undoreload", "ur", P_NUM|P_VI_DEF,
2887 (char_u *)&p_ur, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002888 { (char_u *)10000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002889 {"updatecount", "uc", P_NUM|P_VI_DEF,
2890 (char_u *)&p_uc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002891 {(char_u *)200L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002892 {"updatetime", "ut", P_NUM|P_VI_DEF,
2893 (char_u *)&p_ut, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002894 {(char_u *)4000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar04958cb2018-06-23 19:23:02 +02002895 {"varsofttabstop", "vsts", P_STRING|P_VI_DEF|P_VIM|P_COMMA,
2896#ifdef FEAT_VARTABS
2897 (char_u *)&p_vsts, PV_VSTS,
2898 {(char_u *)"", (char_u *)0L}
2899#else
2900 (char_u *)NULL, PV_NONE,
2901 {(char_u *)"", (char_u *)NULL}
2902#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002903 SCTX_INIT},
Bram Moolenaar04958cb2018-06-23 19:23:02 +02002904 {"vartabstop", "vts", P_STRING|P_VI_DEF|P_VIM|P_RBUF|P_COMMA,
2905#ifdef FEAT_VARTABS
2906 (char_u *)&p_vts, PV_VTS,
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 Moolenaar071d4272004-06-13 20:20:40 +00002913 {"verbose", "vbs", P_NUM|P_VI_DEF,
2914 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002915 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002916 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2917 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002918 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002919 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2920#ifdef FEAT_SESSION
2921 (char_u *)&p_vdir, PV_NONE,
2922 {(char_u *)DFLT_VDIR, (char_u *)0L}
2923#else
2924 (char_u *)NULL, PV_NONE,
2925 {(char_u *)0L, (char_u *)0L}
2926#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002927 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002928 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002929#ifdef FEAT_SESSION
2930 (char_u *)&p_vop, PV_NONE,
Bram Moolenaar13e90412017-11-11 18:16:48 +01002931 {(char_u *)"folds,options,cursor,curdir",
2932 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002933#else
2934 (char_u *)NULL, PV_NONE,
2935 {(char_u *)0L, (char_u *)0L}
2936#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002937 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002938 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002939#ifdef FEAT_VIMINFO
2940 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002941#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002942 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002943#else
2944# ifdef AMIGA
2945 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002946 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002947# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002948 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002949# endif
2950#endif
2951#else
2952 (char_u *)NULL, PV_NONE,
2953 {(char_u *)0L, (char_u *)0L}
2954#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002955 SCTX_INIT},
Bram Moolenaarc229e542018-07-08 21:46:56 +02002956 {"viminfofile", "vif", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP
2957 |P_SECURE|P_VI_DEF,
Bram Moolenaarc4da1132017-07-15 19:39:43 +02002958#ifdef FEAT_VIMINFO
2959 (char_u *)&p_viminfofile, PV_NONE,
2960 {(char_u *)"", (char_u *)0L}
2961#else
2962 (char_u *)NULL, PV_NONE,
2963 {(char_u *)0L, (char_u *)0L}
2964#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002965 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002966 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2967 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002968 (char_u *)&p_ve, PV_NONE,
2969 {(char_u *)"", (char_u *)""}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002970 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002971 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2972 (char_u *)&p_vb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002973 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002974 {"w300", NULL, P_NUM|P_VI_DEF,
2975 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002976 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002977 {"w1200", NULL, P_NUM|P_VI_DEF,
2978 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002979 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002980 {"w9600", NULL, P_NUM|P_VI_DEF,
2981 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002982 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002983 {"warn", NULL, P_BOOL|P_VI_DEF,
2984 (char_u *)&p_warn, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002985 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002986 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2987 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002988 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002989 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002990 (char_u *)&p_ww, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002991 {(char_u *)"", (char_u *)"b,s"} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002992 {"wildchar", "wc", P_NUM|P_VIM,
2993 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002994 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002995 SCTX_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002996 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002997 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002998 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002999 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003000#ifdef FEAT_WILDIGN
3001 (char_u *)&p_wig, PV_NONE,
3002#else
3003 (char_u *)NULL, PV_NONE,
3004#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003005 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003006 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3007 (char_u *)&p_wic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003008 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003009 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
3010#ifdef FEAT_WILDMENU
3011 (char_u *)&p_wmnu, PV_NONE,
3012#else
3013 (char_u *)NULL, PV_NONE,
3014#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003015 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003016 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003017 (char_u *)&p_wim, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003018 {(char_u *)"full", (char_u *)0L} SCTX_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003019 {"wildoptions", "wop", P_STRING|P_VI_DEF,
3020#ifdef FEAT_CMDL_COMPL
3021 (char_u *)&p_wop, PV_NONE,
3022 {(char_u *)"", (char_u *)0L}
3023#else
3024 (char_u *)NULL, PV_NONE,
3025 {(char_u *)NULL, (char_u *)0L}
3026#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003027 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003028 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3029#ifdef FEAT_WAK
3030 (char_u *)&p_wak, PV_NONE,
3031 {(char_u *)"menu", (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 Moolenaar4d784b22019-05-25 19:51:39 +02003037 {"wincolor", "wcr", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
3038 (char_u *)VAR_WIN, PV_WCR,
3039 {(char_u *)"", (char_u *)NULL}
3040 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003041 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003042 (char_u *)&p_window, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003043 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003044 {"winheight", "wh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003045 (char_u *)&p_wh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003046 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003047 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003048 (char_u *)VAR_WIN, PV_WFH,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003049 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003050 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003051 (char_u *)VAR_WIN, PV_WFW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003052 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003053 {"winminheight", "wmh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003054 (char_u *)&p_wmh, 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 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003057 (char_u *)&p_wmw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003058 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003059 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar4f974752019-02-17 17:44:42 +01003060#if defined(MSWIN) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003061 (char_u *)&p_winptydll, PV_NONE, {
3062# ifdef _WIN64
3063 (char_u *)"winpty64.dll",
3064# else
3065 (char_u *)"winpty32.dll",
3066# endif
3067 (char_u *)0L}
3068#else
3069 (char_u *)NULL, PV_NONE,
3070 {(char_u *)0L, (char_u *)0L}
3071#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003072 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003073 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003074 (char_u *)&p_wiw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003075 {(char_u *)20L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003076 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3077 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003078 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003079 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3080 (char_u *)&p_wm, PV_WM,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003081 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003082 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3083 (char_u *)&p_ws, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003084 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003085 {"write", NULL, P_BOOL|P_VI_DEF,
3086 (char_u *)&p_write, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003087 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003088 {"writeany", "wa", P_BOOL|P_VI_DEF,
3089 (char_u *)&p_wa, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003090 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003091 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3092 (char_u *)&p_wb, PV_NONE,
3093 {
3094#ifdef FEAT_WRITEBACKUP
3095 (char_u *)TRUE,
3096#else
3097 (char_u *)FALSE,
3098#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003099 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003100 {"writedelay", "wd", P_NUM|P_VI_DEF,
3101 (char_u *)&p_wd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003102 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003103
3104/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003105#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003106 (char_u *)&vvv, PV_NONE, \
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003107 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003108
3109 p_term("t_AB", T_CAB)
3110 p_term("t_AF", T_CAF)
3111 p_term("t_AL", T_CAL)
3112 p_term("t_al", T_AL)
3113 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003114 p_term("t_BE", T_BE)
3115 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003116 p_term("t_cd", T_CD)
3117 p_term("t_ce", T_CE)
3118 p_term("t_cl", T_CL)
3119 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003120 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003121 p_term("t_Co", T_CCO)
3122 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003123 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003124 p_term("t_cs", T_CS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003125 p_term("t_CV", T_CSV)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003126 p_term("t_da", T_DA)
3127 p_term("t_db", T_DB)
3128 p_term("t_DL", T_CDL)
3129 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003130 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003131 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003132 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003133 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003134 p_term("t_IE", T_CIE)
3135 p_term("t_IS", T_CIS)
3136 p_term("t_ke", T_KE)
3137 p_term("t_ks", T_KS)
3138 p_term("t_le", T_LE)
3139 p_term("t_mb", T_MB)
3140 p_term("t_md", T_MD)
3141 p_term("t_me", T_ME)
3142 p_term("t_mr", T_MR)
3143 p_term("t_ms", T_MS)
3144 p_term("t_nd", T_ND)
3145 p_term("t_op", T_OP)
Bram Moolenaara20f83d2017-10-15 13:35:01 +02003146 p_term("t_RF", T_RFG)
Bram Moolenaare5401222015-06-25 19:16:56 +02003147 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003148 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003149 p_term("t_RI", T_CRI)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003150 p_term("t_Ri", T_SRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003151 p_term("t_RS", T_CRS)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003152 p_term("t_RT", T_CRT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003153 p_term("t_RV", T_CRV)
3154 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003155 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003156 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003157 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003158 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003159 p_term("t_SI", T_CSI)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003160 p_term("t_Si", T_SSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003161 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003162 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003163 p_term("t_sr", T_SR)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003164 p_term("t_ST", T_CST)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003165 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003166 p_term("t_te", T_TE)
3167 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003168 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003169 p_term("t_ts", T_TS)
3170 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003171 p_term("t_ue", T_UE)
3172 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003173 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003174 p_term("t_vb", T_VB)
3175 p_term("t_ve", T_VE)
3176 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003177 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003178 p_term("t_vs", T_VS)
3179 p_term("t_WP", T_CWP)
3180 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003181 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003182 p_term("t_xs", T_XS)
3183 p_term("t_ZH", T_CZH)
3184 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003185 p_term("t_8f", T_8F)
3186 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003187
3188/* terminal key codes are not in here */
3189
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003190 /* end marker */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003191 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCTX_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003192};
3193
3194#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3195
Bram Moolenaar071d4272004-06-13 20:20:40 +00003196static char *(p_ambw_values[]) = {"single", "double", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003197static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003198static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003199static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003200#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003201static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003202#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003203#ifdef FEAT_CMDL_COMPL
3204static char *(p_wop_values[]) = {"tagfile", NULL};
3205#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003206#ifdef FEAT_WAK
3207static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3208#endif
3209static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003210static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3211static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003212static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003213#ifdef FEAT_BROWSE
3214static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3215#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003216static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
Bram Moolenaar57657d82006-04-21 22:12:41 +00003217static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003218static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003219static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", "prompt", "popup", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003220static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003221static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3222#ifdef FEAT_FOLDING
3223static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003224# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003225 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003226# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003227 NULL};
3228static char *(p_fcl_values[]) = {"all", NULL};
3229#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003230#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003231static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003232#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003233#ifdef FEAT_SIGNS
3234static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3235#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01003236#if defined(MSWIN) && defined(FEAT_TERMINAL)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01003237static char *(p_twt_values[]) = {"winpty", "conpty", "", NULL};
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01003238#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003239
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003240static void set_options_default(int opt_flags);
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003241static void set_string_default_esc(char *name, char_u *val, int escape);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003242static char_u *term_bg_default(void);
Bram Moolenaar916a8182018-11-25 02:18:29 +01003243static void did_set_option(int opt_idx, int opt_flags, int new_value, int value_checked);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003244static char_u *option_expand(int opt_idx, char_u *val);
3245static void didset_options(void);
3246static void didset_options2(void);
3247static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003248#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003249static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003250#else
3251# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3252#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003253static void set_string_option_global(int opt_idx, char_u **varp);
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003254static 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);
3255static char *set_chars_option(char_u **varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003256#ifdef FEAT_CLIPBOARD
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003257static char *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003258#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003259#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003260static char *did_set_spell_option(int is_spellfile);
3261static char *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003262#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003263#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003264static void set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003265#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003266static char *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3267static 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 +01003268static void check_redraw(long_u flags);
3269static int findoption(char_u *);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02003270static int find_key_option(char_u *arg_arg, int has_lt);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003271static void showoptions(int all, int opt_flags);
3272static int optval_default(struct vimoption *, char_u *varp);
3273static void showoneopt(struct vimoption *, int opt_flags);
Bram Moolenaared18f2c2019-01-24 20:30:52 +01003274static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, long_u flags);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003275static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3276static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3277static int istermoption(struct vimoption *);
3278static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3279static char_u *get_varp(struct vimoption *);
3280static void option_value2string(struct vimoption *, int opt_flags);
3281static void check_winopt(winopt_T *wop);
3282static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003283#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003284static void langmap_init(void);
3285static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003286#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003287static void paste_option_changed(void);
3288static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003289#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003290static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003291#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003292static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3293static int check_opt_strings(char_u *val, char **values, int);
3294static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003295#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003296static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003297#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003298
3299/*
3300 * Initialize the options, first part.
3301 *
3302 * Called only once from main(), just after creating the first buffer.
Bram Moolenaar07268702018-03-01 21:57:32 +01003303 * If "clean_arg" is TRUE Vim was started with --clean.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003304 */
3305 void
Bram Moolenaar07268702018-03-01 21:57:32 +01003306set_init_1(int clean_arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003307{
3308 char_u *p;
3309 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003310 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003311
3312#ifdef FEAT_LANGMAP
3313 langmap_init();
3314#endif
3315
3316 /* Be Vi compatible by default */
3317 p_cp = TRUE;
3318
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003319 /* Use POSIX compatibility when $VIM_POSIX is set. */
3320 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003321 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003322 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar9dfa3132019-05-04 21:08:40 +02003323 set_string_default("shm", (char_u *)SHM_POSIX);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003324 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003325
Bram Moolenaar071d4272004-06-13 20:20:40 +00003326 /*
3327 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003328 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003329 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003330 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003331#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003332 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003333 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003334#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003335 )
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003336 set_string_default_esc("sh", p, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003337
3338#ifdef FEAT_WILDIGN
3339 /*
3340 * Set the default for 'backupskip' to include environment variables for
3341 * temp files.
3342 */
3343 {
3344# ifdef UNIX
3345 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3346# else
3347 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3348# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003349 int len;
3350 garray_T ga;
3351 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003352
3353 ga_init2(&ga, 1, 100);
3354 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3355 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003356 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003357# ifdef UNIX
3358 if (*names[n] == NUL)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003359# ifdef MACOS_X
3360 p = (char_u *)"/private/tmp";
3361# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003362 p = (char_u *)"/tmp";
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003363# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003364 else
3365# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003366 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003367 if (p != NULL && *p != NUL)
3368 {
3369 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003370 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003371 if (ga_grow(&ga, len) == OK)
3372 {
3373 if (ga.ga_len > 0)
3374 STRCAT(ga.ga_data, ",");
3375 STRCAT(ga.ga_data, p);
3376 add_pathsep(ga.ga_data);
3377 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003378 ga.ga_len += len;
3379 }
3380 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003381 if (mustfree)
3382 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003383 }
3384 if (ga.ga_data != NULL)
3385 {
3386 set_string_default("bsk", ga.ga_data);
3387 vim_free(ga.ga_data);
3388 }
3389 }
3390#endif
3391
3392 /*
3393 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3394 */
3395 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003396 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003397 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003398#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3399 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3400#endif
3401 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003402#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003403 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003404 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003405#else
3406# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003407 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003408 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003409# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003410 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003411# endif
3412#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003413 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003414 opt_idx = findoption((char_u *)"maxmem");
3415 if (opt_idx >= 0)
3416 {
3417#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003418 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3419 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003420#endif
3421 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3422 }
3423 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003424 }
3425
Bram Moolenaar071d4272004-06-13 20:20:40 +00003426#ifdef FEAT_SEARCHPATH
3427 {
3428 char_u *cdpath;
3429 char_u *buf;
3430 int i;
3431 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003432 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003433
3434 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003435 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003436 if (cdpath != NULL)
3437 {
Bram Moolenaar964b3742019-05-24 18:54:09 +02003438 buf = alloc((STRLEN(cdpath) << 1) + 2);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003439 if (buf != NULL)
3440 {
3441 buf[0] = ','; /* start with ",", current dir first */
3442 j = 1;
3443 for (i = 0; cdpath[i] != NUL; ++i)
3444 {
3445 if (vim_ispathlistsep(cdpath[i]))
3446 buf[j++] = ',';
3447 else
3448 {
3449 if (cdpath[i] == ' ' || cdpath[i] == ',')
3450 buf[j++] = '\\';
3451 buf[j++] = cdpath[i];
3452 }
3453 }
3454 buf[j] = NUL;
3455 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003456 if (opt_idx >= 0)
3457 {
3458 options[opt_idx].def_val[VI_DEFAULT] = buf;
3459 options[opt_idx].flags |= P_DEF_ALLOCED;
3460 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003461 else
3462 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003463 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003464 if (mustfree)
3465 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003466 }
3467 }
3468#endif
3469
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003470#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003471 /* Set print encoding on platforms that don't default to latin1 */
3472 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003473# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003474 (char_u *)"cp1252"
3475# else
3476# ifdef VMS
3477 (char_u *)"dec-mcs"
3478# else
3479# ifdef EBCDIC
3480 (char_u *)"ebcdic-uk"
3481# else
3482# ifdef MAC
3483 (char_u *)"mac-roman"
3484# else /* HPUX */
3485 (char_u *)"hp-roman8"
3486# endif
3487# endif
3488# endif
3489# endif
3490 );
3491#endif
3492
3493#ifdef FEAT_POSTSCRIPT
3494 /* 'printexpr' must be allocated to be able to evaluate it. */
3495 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003496# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003497 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003498# else
3499# ifdef VMS
3500 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3501
3502# else
3503 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3504# endif
3505# endif
3506 );
3507#endif
3508
3509 /*
3510 * Set all the options (except the terminal options) to their default
3511 * value. Also set the global value for local options.
3512 */
3513 set_options_default(0);
3514
Bram Moolenaar07268702018-03-01 21:57:32 +01003515#ifdef CLEAN_RUNTIMEPATH
3516 if (clean_arg)
3517 {
3518 opt_idx = findoption((char_u *)"runtimepath");
3519 if (opt_idx >= 0)
3520 {
3521 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3522 p_rtp = (char_u *)CLEAN_RUNTIMEPATH;
3523 }
3524 opt_idx = findoption((char_u *)"packpath");
3525 if (opt_idx >= 0)
3526 {
3527 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3528 p_pp = (char_u *)CLEAN_RUNTIMEPATH;
3529 }
3530 }
3531#endif
3532
Bram Moolenaar071d4272004-06-13 20:20:40 +00003533#ifdef FEAT_GUI
3534 if (found_reverse_arg)
3535 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3536#endif
3537
3538 curbuf->b_p_initialized = TRUE;
3539 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003540 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003541 check_buf_options(curbuf);
3542 check_win_options(curwin);
3543 check_options();
3544
3545 /* Must be before option_expand(), because that one needs vim_isIDc() */
3546 didset_options();
3547
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003548#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003549 /* Use the current chartab for the generic chartab. This is not in
3550 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003551 init_spell_chartab();
3552#endif
3553
Bram Moolenaar071d4272004-06-13 20:20:40 +00003554 /*
3555 * Expand environment variables and things like "~" for the defaults.
3556 * If option_expand() returns non-NULL the variable is expanded. This can
3557 * only happen for non-indirect options.
3558 * Also set the default to the expanded value, so ":set" does not list
3559 * them.
3560 * Don't set the P_ALLOCED flag, because we don't want to free the
3561 * default.
3562 */
3563 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3564 {
3565 if ((options[opt_idx].flags & P_GETTEXT)
3566 && options[opt_idx].var != NULL)
3567 p = (char_u *)_(*(char **)options[opt_idx].var);
3568 else
3569 p = option_expand(opt_idx, NULL);
3570 if (p != NULL && (p = vim_strsave(p)) != NULL)
3571 {
3572 *(char_u **)options[opt_idx].var = p;
3573 /* VIMEXP
3574 * Defaults for all expanded options are currently the same for Vi
3575 * and Vim. When this changes, add some code here! Also need to
3576 * split P_DEF_ALLOCED in two.
3577 */
3578 if (options[opt_idx].flags & P_DEF_ALLOCED)
3579 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3580 options[opt_idx].def_val[VI_DEFAULT] = p;
3581 options[opt_idx].flags |= P_DEF_ALLOCED;
3582 }
3583 }
3584
Bram Moolenaar071d4272004-06-13 20:20:40 +00003585 save_file_ff(curbuf); /* Buffer is unchanged */
3586
Bram Moolenaar071d4272004-06-13 20:20:40 +00003587#if defined(FEAT_ARABIC)
3588 /* Detect use of mlterm.
3589 * Mlterm is a terminal emulator akin to xterm that has some special
3590 * abilities (bidi namely).
3591 * NOTE: mlterm's author is being asked to 'set' a variable
3592 * instead of an environment variable due to inheritance.
3593 */
3594 if (mch_getenv((char_u *)"MLTERM") != NULL)
3595 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3596#endif
3597
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003598 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003599
Bram Moolenaar4f974752019-02-17 17:44:42 +01003600# if defined(MSWIN) && defined(FEAT_GETTEXT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003601 /*
3602 * If $LANG isn't set, try to get a good value for it. This makes the
3603 * right language be used automatically. Don't do this for English.
3604 */
3605 if (mch_getenv((char_u *)"LANG") == NULL)
3606 {
3607 char buf[20];
3608
3609 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3610 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3611 * only the first two. */
3612 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3613 (LPTSTR)buf, 20);
3614 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3615 {
3616 /* There are a few exceptions (probably more) */
3617 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3618 STRCPY(buf, "zh_TW");
3619 else if (STRNICMP(buf, "chs", 3) == 0
3620 || STRNICMP(buf, "zhc", 3) == 0)
3621 STRCPY(buf, "zh_CN");
3622 else if (STRNICMP(buf, "jp", 2) == 0)
3623 STRCPY(buf, "ja");
3624 else
3625 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003626 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003627 }
3628 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003629# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003630# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003631 /* Moved to os_mac_conv.c to avoid dependency problems. */
3632 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003633# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003634# endif
3635
3636 /* enc_locale() will try to find the encoding of the current locale. */
3637 p = enc_locale();
3638 if (p != NULL)
3639 {
3640 char_u *save_enc;
3641
3642 /* Try setting 'encoding' and check if the value is valid.
3643 * If not, go back to the default "latin1". */
3644 save_enc = p_enc;
3645 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003646 if (STRCMP(p_enc, "gb18030") == 0)
3647 {
3648 /* We don't support "gb18030", but "cp936" is a good substitute
3649 * for practical purposes, thus use that. It's not an alias to
3650 * still support conversion between gb18030 and utf-8. */
3651 p_enc = vim_strsave((char_u *)"cp936");
3652 vim_free(p);
3653 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003654 if (mb_init() == NULL)
3655 {
3656 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003657 if (opt_idx >= 0)
3658 {
3659 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3660 options[opt_idx].flags |= P_DEF_ALLOCED;
3661 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003662
Bram Moolenaard0573012017-10-28 21:11:06 +02003663#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003664 if (STRCMP(p_enc, "latin1") == 0 || enc_utf8)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003665 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003666 /* Adjust the default for 'isprint' and 'iskeyword' to match
3667 * latin1. Also set the defaults for when 'nocompatible' is
3668 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003669 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003670 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003671 set_string_option_direct((char_u *)"isk", -1,
3672 ISK_LATIN1, OPT_FREE, SID_NONE);
3673 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003674 if (opt_idx >= 0)
3675 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003676 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003677 if (opt_idx >= 0)
3678 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003679 (void)init_chartab();
3680 }
3681#endif
3682
Bram Moolenaarafde13b2019-04-28 19:46:49 +02003683#if defined(MSWIN) && (!defined(FEAT_GUI) || defined(VIMDLL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003684 /* Win32 console: When GetACP() returns a different value from
3685 * GetConsoleCP() set 'termencoding'. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02003686 if (
3687# ifdef VIMDLL
3688 (!gui.in_use && !gui.starting) &&
3689# endif
3690 GetACP() != GetConsoleCP())
Bram Moolenaar071d4272004-06-13 20:20:40 +00003691 {
3692 char buf[50];
3693
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01003694 /* Win32 console: In ConPTY, GetConsoleCP() returns zero.
3695 * Use an alternative value. */
3696 if (GetConsoleCP() == 0)
3697 sprintf(buf, "cp%ld", (long)GetACP());
3698 else
3699 sprintf(buf, "cp%ld", (long)GetConsoleCP());
Bram Moolenaar071d4272004-06-13 20:20:40 +00003700 p_tenc = vim_strsave((char_u *)buf);
3701 if (p_tenc != NULL)
3702 {
3703 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003704 if (opt_idx >= 0)
3705 {
3706 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3707 options[opt_idx].flags |= P_DEF_ALLOCED;
3708 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003709 convert_setup(&input_conv, p_tenc, p_enc);
3710 convert_setup(&output_conv, p_enc, p_tenc);
3711 }
3712 else
3713 p_tenc = empty_option;
3714 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003715#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01003716#if defined(MSWIN)
Bram Moolenaar05159a02005-02-26 23:04:13 +00003717 /* $HOME may have characters in active code page. */
3718 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003719#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003720 }
3721 else
3722 {
3723 vim_free(p_enc);
3724 p_enc = save_enc;
3725 }
3726 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003727
3728#ifdef FEAT_MULTI_LANG
3729 /* Set the default for 'helplang'. */
3730 set_helplang_default(get_mess_lang());
3731#endif
3732}
3733
3734/*
3735 * Set an option to its default value.
3736 * This does not take care of side effects!
3737 */
3738 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003739set_option_default(
3740 int opt_idx,
3741 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3742 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003743{
3744 char_u *varp; /* pointer to variable for current option */
3745 int dvi; /* index in def_val[] */
3746 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003747 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003748 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3749
3750 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3751 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003752 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003753 {
3754 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3755 if (flags & P_STRING)
3756 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003757 /* Use set_string_option_direct() for local options to handle
3758 * freeing and allocating the value. */
3759 if (options[opt_idx].indir != PV_NONE)
3760 set_string_option_direct(NULL, opt_idx,
3761 options[opt_idx].def_val[dvi], opt_flags, 0);
3762 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003763 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003764 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3765 free_string_option(*(char_u **)(varp));
3766 *(char_u **)varp = options[opt_idx].def_val[dvi];
3767 options[opt_idx].flags &= ~P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003768 }
3769 }
3770 else if (flags & P_NUM)
3771 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003772 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003773 win_comp_scroll(curwin);
3774 else
3775 {
Bram Moolenaar375e3392019-01-31 18:26:10 +01003776 long def_val = (long)(long_i)options[opt_idx].def_val[dvi];
3777
3778 if ((long *)varp == &curwin->w_p_so
3779 || (long *)varp == &curwin->w_p_siso)
3780 // 'scrolloff' and 'sidescrolloff' local values have a
3781 // different default value than the global default.
3782 *(long *)varp = -1;
3783 else
3784 *(long *)varp = def_val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003785 /* May also set global value for local option. */
3786 if (both)
3787 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
Bram Moolenaar375e3392019-01-31 18:26:10 +01003788 def_val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003789 }
3790 }
3791 else /* P_BOOL */
3792 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003793 /* the cast to long is required for Manx C, long_i is needed for
3794 * MSVC */
3795 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003796#ifdef UNIX
3797 /* 'modeline' defaults to off for root */
3798 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3799 *(int *)varp = FALSE;
3800#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003801 /* May also set global value for local option. */
3802 if (both)
3803 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3804 *(int *)varp;
3805 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003806
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003807 /* The default value is not insecure. */
3808 flagsp = insecure_flag(opt_idx, opt_flags);
3809 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003810 }
3811
3812#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003813 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003814#endif
3815}
3816
3817/*
3818 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003819 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003820 */
3821 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003822set_options_default(
3823 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003824{
3825 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003826 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003827 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003828
3829 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003830 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003831 && (opt_flags == 0
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003832 || (options[i].var != (char_u *)&p_enc
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003833# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003834 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003835 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003836# endif
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003837 )))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003838 set_option_default(i, opt_flags, p_cp);
3839
Bram Moolenaar071d4272004-06-13 20:20:40 +00003840 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003841 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003842 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003843#ifdef FEAT_CINDENT
3844 parse_cino(curbuf);
3845#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003846}
3847
3848/*
3849 * Set the Vi-default value of a string option.
3850 * Used for 'sh', 'backupskip' and 'term'.
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003851 * When "escape" is TRUE escape spaces with a backslash.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003852 */
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003853 static void
3854set_string_default_esc(char *name, char_u *val, int escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003855{
3856 char_u *p;
3857 int opt_idx;
3858
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003859 if (escape && vim_strchr(val, ' ') != NULL)
3860 p = vim_strsave_escaped(val, (char_u *)" ");
3861 else
3862 p = vim_strsave(val);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003863 if (p != NULL) /* we don't want a NULL */
3864 {
3865 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003866 if (opt_idx >= 0)
3867 {
3868 if (options[opt_idx].flags & P_DEF_ALLOCED)
3869 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3870 options[opt_idx].def_val[VI_DEFAULT] = p;
3871 options[opt_idx].flags |= P_DEF_ALLOCED;
3872 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003873 }
3874}
3875
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003876 void
3877set_string_default(char *name, char_u *val)
3878{
3879 set_string_default_esc(name, val, FALSE);
3880}
3881
Bram Moolenaar071d4272004-06-13 20:20:40 +00003882/*
3883 * Set the Vi-default value of a number option.
3884 * Used for 'lines' and 'columns'.
3885 */
3886 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003887set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003888{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003889 int opt_idx;
3890
3891 opt_idx = findoption((char_u *)name);
3892 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003893 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003894}
3895
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003896#if defined(EXITFREE) || defined(PROTO)
3897/*
3898 * Free all options.
3899 */
3900 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003901free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003902{
3903 int i;
3904
3905 for (i = 0; !istermoption(&options[i]); i++)
3906 {
3907 if (options[i].indir == PV_NONE)
3908 {
3909 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003910 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003911 free_string_option(*(char_u **)options[i].var);
3912 if (options[i].flags & P_DEF_ALLOCED)
3913 free_string_option(options[i].def_val[VI_DEFAULT]);
3914 }
3915 else if (options[i].var != VAR_WIN
3916 && (options[i].flags & P_STRING))
3917 /* buffer-local option: free global value */
3918 free_string_option(*(char_u **)options[i].var);
3919 }
3920}
3921#endif
3922
3923
Bram Moolenaar071d4272004-06-13 20:20:40 +00003924/*
3925 * Initialize the options, part two: After getting Rows and Columns and
3926 * setting 'term'.
3927 */
3928 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003929set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003930{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003931 int idx;
3932
Bram Moolenaar071d4272004-06-13 20:20:40 +00003933 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003934 * 'scroll' defaults to half the window height. The stored default is zero,
3935 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003936 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003937 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003938 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003939 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003940 comp_col();
3941
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003942 /*
3943 * 'window' is only for backwards compatibility with Vi.
3944 * Default is Rows - 1.
3945 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003946 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003947 p_window = Rows - 1;
3948 set_number_default("window", Rows - 1);
3949
Bram Moolenaarf740b292006-02-16 22:11:02 +00003950 /* For DOS console the default is always black. */
Bram Moolenaar4f974752019-02-17 17:44:42 +01003951#if !((defined(MSWIN)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003952 /*
3953 * If 'background' wasn't set by the user, try guessing the value,
3954 * depending on the terminal name. Only need to check for terminals
3955 * with a dark background, that can handle color.
3956 */
3957 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003958 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3959 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003960 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003961 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003962 /* don't mark it as set, when starting the GUI it may be
3963 * changed again */
3964 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003965 }
3966#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003967
3968#ifdef CURSOR_SHAPE
3969 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3970#endif
3971#ifdef FEAT_MOUSESHAPE
3972 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3973#endif
3974#ifdef FEAT_PRINTER
3975 (void)parse_printoptions(); /* parse 'printoptions' default value */
3976#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003977}
3978
3979/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003980 * Return "dark" or "light" depending on the kind of terminal.
3981 * This is just guessing! Recognized are:
3982 * "linux" Linux console
3983 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003984 * "cygwin.*" Cygwin shell
3985 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00003986 * We also check the COLORFGBG environment variable, which is set by
3987 * rxvt and derivatives. This variable contains either two or three
3988 * values separated by semicolons; we want the last value in either
3989 * case. If this value is 0-6 or 8, our background is dark.
3990 */
3991 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003992term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003993{
Bram Moolenaar4f974752019-02-17 17:44:42 +01003994#if defined(MSWIN)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003995 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003996 return (char_u *)"dark";
3997#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003998 char_u *p;
3999
Bram Moolenaarf740b292006-02-16 22:11:02 +00004000 if (STRCMP(T_NAME, "linux") == 0
4001 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004002 || STRNCMP(T_NAME, "cygwin", 6) == 0
4003 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00004004 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
4005 && (p = vim_strrchr(p, ';')) != NULL
4006 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
4007 && p[2] == NUL))
4008 return (char_u *)"dark";
4009 return (char_u *)"light";
4010#endif
4011}
4012
4013/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004014 * Initialize the options, part three: After reading the .vimrc
4015 */
4016 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004017set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004018{
Bram Moolenaar4f974752019-02-17 17:44:42 +01004019#if defined(UNIX) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004020/*
4021 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4022 * This is done after other initializations, where 'shell' might have been
4023 * set, but only if they have not been set before.
4024 */
4025 char_u *p;
4026 int idx_srr;
4027 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004028# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004029 int idx_sp;
4030 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004031# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004032
4033 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004034 if (idx_srr < 0)
4035 do_srr = FALSE;
4036 else
4037 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004038# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004039 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004040 if (idx_sp < 0)
4041 do_sp = FALSE;
4042 else
4043 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004044# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004045 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004046 if (p != NULL)
4047 {
4048 /*
4049 * Default for p_sp is "| tee", for p_srr is ">".
4050 * For known shells it is changed here to include stderr.
4051 */
4052 if ( fnamecmp(p, "csh") == 0
4053 || fnamecmp(p, "tcsh") == 0
Bram Moolenaar4f974752019-02-17 17:44:42 +01004054# if defined(MSWIN) // also check with .exe extension
Bram Moolenaar071d4272004-06-13 20:20:40 +00004055 || fnamecmp(p, "csh.exe") == 0
4056 || fnamecmp(p, "tcsh.exe") == 0
4057# endif
4058 )
4059 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004060# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004061 if (do_sp)
4062 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01004063# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004064 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004065# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004066 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004067# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004068 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4069 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004070# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004071 if (do_srr)
4072 {
4073 p_srr = (char_u *)">&";
4074 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4075 }
4076 }
4077 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004078 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004079 if ( fnamecmp(p, "sh") == 0
4080 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004081 || fnamecmp(p, "mksh") == 0
4082 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004083 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004084 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004085 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004086 || fnamecmp(p, "fish") == 0
Bram Moolenaar4f974752019-02-17 17:44:42 +01004087# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004088 || fnamecmp(p, "cmd") == 0
4089 || fnamecmp(p, "sh.exe") == 0
4090 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004091 || fnamecmp(p, "mksh.exe") == 0
4092 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004093 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004094 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004095 || fnamecmp(p, "bash.exe") == 0
4096 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004097# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004098 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004099 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004100# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004101 if (do_sp)
4102 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01004103# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004104 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004105# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004106 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004107# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004108 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4109 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004110# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004111 if (do_srr)
4112 {
4113 p_srr = (char_u *)">%s 2>&1";
4114 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4115 }
4116 }
4117 vim_free(p);
4118 }
4119#endif
4120
Bram Moolenaar4f974752019-02-17 17:44:42 +01004121#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004122 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004123 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4124 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004125 * This is done after other initializations, where 'shell' might have been
4126 * set, but only if they have not been set before. Default for p_shcf is
4127 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004128 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004129 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004130 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004131 {
4132 int idx3;
4133
4134 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004135 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004136 {
4137 p_shcf = (char_u *)"-c";
4138 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4139 }
4140
Bram Moolenaar071d4272004-06-13 20:20:40 +00004141 /* Somehow Win32 requires the quotes around the redirection too */
4142 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004143 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004144 {
4145 p_sxq = (char_u *)"\"";
4146 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4147 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004148 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004149 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4150 {
4151 int idx3;
4152
4153 /*
4154 * cmd.exe on Windows will strip the first and last double quote given
4155 * on the command line, e.g. most of the time things like:
4156 * cmd /c "my path/to/echo" "my args to echo"
4157 * become:
4158 * my path/to/echo" "my args to echo
4159 * when executed.
4160 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004161 * To avoid this, set shellxquote to surround the command in
4162 * parenthesis. This appears to make most commands work, without
4163 * breaking commands that worked previously, such as
4164 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004165 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004166 idx3 = findoption((char_u *)"sxq");
4167 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4168 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004169 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004170 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4171 }
4172
Bram Moolenaara64ba222012-02-12 23:23:31 +01004173 idx3 = findoption((char_u *)"shcf");
4174 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4175 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004176 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004177 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4178 }
4179 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004180#endif
4181
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004182 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004183 {
4184 int idx_ffs = findoption((char_u *)"ffs");
4185
4186 /* Apply the first entry of 'fileformats' to the initial buffer. */
4187 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4188 set_fileformat(default_fileformat(), OPT_LOCAL);
4189 }
4190
Bram Moolenaar071d4272004-06-13 20:20:40 +00004191#ifdef FEAT_TITLE
4192 set_title_defaults();
4193#endif
4194}
4195
4196#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4197/*
4198 * When 'helplang' is still at its default value, set it to "lang".
4199 * Only the first two characters of "lang" are used.
4200 */
4201 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004202set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004203{
4204 int idx;
4205
4206 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4207 return;
4208 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004209 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004210 {
4211 if (options[idx].flags & P_ALLOCED)
4212 free_string_option(p_hlg);
4213 p_hlg = vim_strsave(lang);
4214 if (p_hlg == NULL)
4215 p_hlg = empty_option;
4216 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004217 {
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004218 // zh_CN becomes "cn", zh_TW becomes "tw"
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004219 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4220 {
4221 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4222 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4223 }
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004224 // any C like setting, such as C.UTF-8, becomes "en"
4225 else if (STRLEN(p_hlg) >= 1 && *p_hlg == 'C')
4226 {
4227 p_hlg[0] = 'e';
4228 p_hlg[1] = 'n';
4229 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004230 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004231 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004232 options[idx].flags |= P_ALLOCED;
4233 }
4234}
4235#endif
4236
4237#ifdef FEAT_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00004238 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004239gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004240{
4241 if (gui_get_lightness(gui.back_pixel) < 127)
4242 return (char_u *)"dark";
4243 return (char_u *)"light";
4244}
4245
4246/*
4247 * Option initializations that can only be done after opening the GUI window.
4248 */
4249 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004250init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004251{
4252 /* Set the 'background' option according to the lightness of the
4253 * background color, unless the user has set it already. */
4254 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4255 {
4256 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4257 highlight_changed();
4258 }
4259}
4260#endif
4261
4262#ifdef FEAT_TITLE
4263/*
4264 * 'title' and 'icon' only default to true if they have not been set or reset
4265 * in .vimrc and we can read the old value.
4266 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4267 * they can be reset. This reduces startup time when using X on a remote
4268 * machine.
4269 */
4270 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004271set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004272{
4273 int idx1;
4274 long val;
4275
4276 /*
4277 * If GUI is (going to be) used, we can always set the window title and
4278 * icon name. Saves a bit of time, because the X11 display server does
4279 * not need to be contacted.
4280 */
4281 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004282 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004283 {
4284#ifdef FEAT_GUI
4285 if (gui.starting || gui.in_use)
4286 val = TRUE;
4287 else
4288#endif
4289 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004290 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004291 p_title = val;
4292 }
4293 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004294 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004295 {
4296#ifdef FEAT_GUI
4297 if (gui.starting || gui.in_use)
4298 val = TRUE;
4299 else
4300#endif
4301 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004302 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004303 p_icon = val;
4304 }
4305}
4306#endif
4307
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004308#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004309 static void
4310trigger_optionsset_string(
4311 int opt_idx,
4312 int opt_flags,
4313 char_u *oldval,
4314 char_u *newval)
4315{
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02004316 // Don't do this recursively.
4317 if (oldval != NULL && newval != NULL
4318 && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004319 {
4320 char_u buf_type[7];
4321
4322 sprintf((char *)buf_type, "%s",
4323 (opt_flags & OPT_LOCAL) ? "local" : "global");
4324 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4325 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4326 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4327 apply_autocmds(EVENT_OPTIONSET,
4328 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4329 reset_v_option_vars();
4330 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004331}
4332#endif
4333
Bram Moolenaar071d4272004-06-13 20:20:40 +00004334/*
4335 * Parse 'arg' for option settings.
4336 *
4337 * 'arg' may be IObuff, but only when no errors can be present and option
4338 * does not need to be expanded with option_expand().
4339 * "opt_flags":
4340 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004341 * OPT_GLOBAL for ":setglobal"
4342 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004343 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004344 * OPT_WINONLY to only set window-local options
4345 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004346 *
4347 * returns FAIL if an error is detected, OK otherwise
4348 */
4349 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004350do_set(
4351 char_u *arg, /* option string (may be written to!) */
4352 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004353{
4354 int opt_idx;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004355 char *errmsg;
4356 char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00004357 char_u *startarg;
4358 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4359 int nextchar; /* next non-white char after option name */
4360 int afterchar; /* character just after option name */
4361 int len;
4362 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004363 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004364 int key;
4365 long_u flags; /* flags for current option */
4366 char_u *varp = NULL; /* pointer to variable for current option */
4367 int did_show = FALSE; /* already showed one value */
4368 int adding; /* "opt+=arg" */
4369 int prepending; /* "opt^=arg" */
4370 int removing; /* "opt-=arg" */
4371 int cp_val = 0;
4372 char_u key_name[2];
4373
4374 if (*arg == NUL)
4375 {
4376 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004377 did_show = TRUE;
4378 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004379 }
4380
4381 while (*arg != NUL) /* loop to process all options */
4382 {
4383 errmsg = NULL;
4384 startarg = arg; /* remember for error message */
4385
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004386 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4387 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004388 {
4389 /*
4390 * ":set all" show all options.
4391 * ":set all&" set all options to their default value.
4392 */
4393 arg += 3;
4394 if (*arg == '&')
4395 {
4396 ++arg;
4397 /* Only for :set command set global value of local options. */
4398 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004399 didset_options();
4400 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004401 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004402 }
4403 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004404 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004405 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004406 did_show = TRUE;
4407 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004408 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004409 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004410 {
4411 showoptions(2, opt_flags);
4412 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004413 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004414 arg += 7;
4415 }
4416 else
4417 {
4418 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004419 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004420 {
4421 prefix = 0;
4422 arg += 2;
4423 }
4424 else if (STRNCMP(arg, "inv", 3) == 0)
4425 {
4426 prefix = 2;
4427 arg += 3;
4428 }
4429
4430 /* find end of name */
4431 key = 0;
4432 if (*arg == '<')
4433 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004434 opt_idx = -1;
4435 /* look out for <t_>;> */
4436 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4437 len = 5;
4438 else
4439 {
4440 len = 1;
4441 while (arg[len] != NUL && arg[len] != '>')
4442 ++len;
4443 }
4444 if (arg[len] != '>')
4445 {
4446 errmsg = e_invarg;
4447 goto skip;
4448 }
4449 arg[len] = NUL; /* put NUL after name */
4450 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4451 opt_idx = findoption(arg + 1);
4452 arg[len++] = '>'; /* restore '>' */
4453 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004454 key = find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004455 }
4456 else
4457 {
4458 len = 0;
4459 /*
4460 * The two characters after "t_" may not be alphanumeric.
4461 */
4462 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4463 len = 4;
4464 else
4465 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4466 ++len;
4467 nextchar = arg[len];
4468 arg[len] = NUL; /* put NUL after name */
4469 opt_idx = findoption(arg);
4470 arg[len] = nextchar; /* restore nextchar */
4471 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004472 key = find_key_option(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004473 }
4474
4475 /* remember character after option name */
4476 afterchar = arg[len];
4477
4478 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004479 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004480 ++len;
4481
4482 adding = FALSE;
4483 prepending = FALSE;
4484 removing = FALSE;
4485 if (arg[len] != NUL && arg[len + 1] == '=')
4486 {
4487 if (arg[len] == '+')
4488 {
4489 adding = TRUE; /* "+=" */
4490 ++len;
4491 }
4492 else if (arg[len] == '^')
4493 {
4494 prepending = TRUE; /* "^=" */
4495 ++len;
4496 }
4497 else if (arg[len] == '-')
4498 {
4499 removing = TRUE; /* "-=" */
4500 ++len;
4501 }
4502 }
4503 nextchar = arg[len];
4504
4505 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4506 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004507 errmsg = N_("E518: Unknown option");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004508 goto skip;
4509 }
4510
4511 if (opt_idx >= 0)
4512 {
4513 if (options[opt_idx].var == NULL) /* hidden option: skip */
4514 {
4515 /* Only give an error message when requesting the value of
4516 * a hidden option, ignore setting it. */
4517 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4518 && (!(options[opt_idx].flags & P_BOOL)
4519 || nextchar == '?'))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004520 errmsg = N_("E519: Option not supported");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004521 goto skip;
4522 }
4523
4524 flags = options[opt_idx].flags;
4525 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4526 }
4527 else
4528 {
4529 flags = P_STRING;
4530 if (key < 0)
4531 {
4532 key_name[0] = KEY2TERMCAP0(key);
4533 key_name[1] = KEY2TERMCAP1(key);
4534 }
4535 else
4536 {
4537 key_name[0] = KS_KEY;
4538 key_name[1] = (key & 0xff);
4539 }
4540 }
4541
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004542 /* Skip all options that are not window-local (used when showing
4543 * an already loaded buffer in a window). */
4544 if ((opt_flags & OPT_WINONLY)
4545 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4546 goto skip;
4547
Bram Moolenaara3227e22006-03-08 21:32:40 +00004548 /* Skip all options that are window-local (used for :vimgrep). */
4549 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4550 && options[opt_idx].var == VAR_WIN)
4551 goto skip;
4552
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004553 /* Disallow changing some options from modelines. */
4554 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004555 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004556 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004557 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004558 errmsg = _("E520: Not allowed in a modeline");
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004559 goto skip;
4560 }
Bram Moolenaar110289e2019-05-23 15:38:06 +02004561 if ((flags & P_MLE) && !p_mle)
4562 {
4563 errmsg = _("E992: Not allowed in a modeline when 'modelineexpr' is off");
4564 goto skip;
4565 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004566#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004567 /* In diff mode some options are overruled. This avoids that
4568 * 'foldmethod' becomes "marker" instead of "diff" and that
4569 * "wrap" gets set. */
4570 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004571 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004572 && (
4573#ifdef FEAT_FOLDING
4574 options[opt_idx].indir == PV_FDM ||
4575#endif
4576 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004577 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004578#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004579 }
4580
4581#ifdef HAVE_SANDBOX
4582 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004583 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004584 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004585 errmsg = _(e_sandbox);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004586 goto skip;
4587 }
4588#endif
4589
4590 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4591 {
4592 arg += len;
4593 cp_val = p_cp;
4594 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4595 {
4596 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4597 {
4598 cp_val = FALSE;
4599 arg += 3;
4600 }
4601 else /* "opt&vi": set to Vi default */
4602 {
4603 cp_val = TRUE;
4604 arg += 2;
4605 }
4606 }
4607 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004608 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004609 {
4610 errmsg = e_trailing;
4611 goto skip;
4612 }
4613 }
4614
4615 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004616 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4617 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004618 */
4619 if (nextchar == '?'
4620 || (prefix == 1
4621 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4622 && !(flags & P_BOOL)))
4623 {
4624 /*
4625 * print value
4626 */
4627 if (did_show)
4628 msg_putchar('\n'); /* cursor below last one */
4629 else
4630 {
4631 gotocmdline(TRUE); /* cursor at status line */
4632 did_show = TRUE; /* remember that we did a line */
4633 }
4634 if (opt_idx >= 0)
4635 {
4636 showoneopt(&options[opt_idx], opt_flags);
4637#ifdef FEAT_EVAL
4638 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004639 {
4640 /* Mention where the option was last set. */
4641 if (varp == options[opt_idx].var)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004642 last_set_msg(options[opt_idx].script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004643 else if ((int)options[opt_idx].indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004644 last_set_msg(curwin->w_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004645 (int)options[opt_idx].indir & PV_MASK]);
4646 else if ((int)options[opt_idx].indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004647 last_set_msg(curbuf->b_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004648 (int)options[opt_idx].indir & PV_MASK]);
4649 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004650#endif
4651 }
4652 else
4653 {
4654 char_u *p;
4655
4656 p = find_termcode(key_name);
4657 if (p == NULL)
4658 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004659 errmsg = N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004660 goto skip;
4661 }
4662 else
4663 (void)show_one_termcode(key_name, p, TRUE);
4664 }
4665 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004666 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004667 errmsg = e_trailing;
4668 }
4669 else
4670 {
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004671 int value_is_replaced = !prepending && !adding && !removing;
Bram Moolenaar916a8182018-11-25 02:18:29 +01004672 int value_checked = FALSE;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004673
Bram Moolenaar071d4272004-06-13 20:20:40 +00004674 if (flags & P_BOOL) /* boolean */
4675 {
4676 if (nextchar == '=' || nextchar == ':')
4677 {
4678 errmsg = e_invarg;
4679 goto skip;
4680 }
4681
4682 /*
4683 * ":set opt!": invert
4684 * ":set opt&": reset to default value
4685 * ":set opt<": reset to global value
4686 */
4687 if (nextchar == '!')
4688 value = *(int *)(varp) ^ 1;
4689 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004690 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004691 ((flags & P_VI_DEF) || cp_val)
4692 ? VI_DEFAULT : VIM_DEFAULT];
4693 else if (nextchar == '<')
4694 {
4695 /* For 'autoread' -1 means to use global value. */
4696 if ((int *)varp == &curbuf->b_p_ar
4697 && opt_flags == OPT_LOCAL)
4698 value = -1;
4699 else
4700 value = *(int *)get_varp_scope(&(options[opt_idx]),
4701 OPT_GLOBAL);
4702 }
4703 else
4704 {
4705 /*
4706 * ":set invopt": invert
4707 * ":set opt" or ":set noopt": set or reset
4708 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004709 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004710 {
4711 errmsg = e_trailing;
4712 goto skip;
4713 }
4714 if (prefix == 2) /* inv */
4715 value = *(int *)(varp) ^ 1;
4716 else
4717 value = prefix;
4718 }
4719
4720 errmsg = set_bool_option(opt_idx, varp, (int)value,
4721 opt_flags);
4722 }
4723 else /* numeric or string */
4724 {
4725 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4726 || prefix != 1)
4727 {
4728 errmsg = e_invarg;
4729 goto skip;
4730 }
4731
4732 if (flags & P_NUM) /* numeric */
4733 {
4734 /*
4735 * Different ways to set a number option:
4736 * & set to default value
4737 * < set to global value
4738 * <xx> accept special key codes for 'wildchar'
4739 * c accept any non-digit for 'wildchar'
4740 * [-]0-9 set number
4741 * other error
4742 */
4743 ++arg;
4744 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004745 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004746 ((flags & P_VI_DEF) || cp_val)
4747 ? VI_DEFAULT : VIM_DEFAULT];
4748 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004749 {
4750 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4751 * use the global value. */
4752 if ((long *)varp == &curbuf->b_p_ul
4753 && opt_flags == OPT_LOCAL)
4754 value = NO_LOCAL_UNDOLEVEL;
4755 else
4756 value = *(long *)get_varp_scope(
4757 &(options[opt_idx]), OPT_GLOBAL);
4758 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004759 else if (((long *)varp == &p_wc
4760 || (long *)varp == &p_wcm)
4761 && (*arg == '<'
4762 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004763 || (*arg != NUL
4764 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004765 && !VIM_ISDIGIT(*arg))))
4766 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004767 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004768 if (value == 0 && (long *)varp != &p_wcm)
4769 {
4770 errmsg = e_invarg;
4771 goto skip;
4772 }
4773 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004774 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4775 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004776 /* Allow negative (for 'undolevels'), octal and
4777 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004778 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
Bram Moolenaar16e9b852019-05-19 19:59:35 +02004779 &value, NULL, 0, TRUE);
4780 if (i == 0 || (arg[i] != NUL && !VIM_ISWHITE(arg[i])))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004781 {
Bram Moolenaar16e9b852019-05-19 19:59:35 +02004782 errmsg = N_("E521: Number required after =");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004783 goto skip;
4784 }
4785 }
4786 else
4787 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004788 errmsg = N_("E521: Number required after =");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004789 goto skip;
4790 }
4791
4792 if (adding)
4793 value = *(long *)varp + value;
4794 if (prepending)
4795 value = *(long *)varp * value;
4796 if (removing)
4797 value = *(long *)varp - value;
4798 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004799 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004800 }
4801 else if (opt_idx >= 0) /* string */
4802 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004803 char_u *save_arg = NULL;
4804 char_u *s = NULL;
4805 char_u *oldval = NULL; /* previous value if *varp */
4806 char_u *newval;
4807 char_u *origval = NULL;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004808#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004809 char_u *saved_origval = NULL;
4810 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004811#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004812 unsigned newlen;
4813 int comma;
4814 int bs;
4815 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004816 was allocated */
4817
4818 /* When using ":set opt=val" for a global option
4819 * with a local value the local value will be
4820 * reset, use the global value here. */
4821 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004822 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004823 varp = options[opt_idx].var;
4824
4825 /* The old value is kept until we are sure that the
4826 * new value is valid. */
4827 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004828
4829 /* When setting the local value of a global
4830 * option, the old value may be the global value. */
4831 if (((int)options[opt_idx].indir & PV_BOTH)
4832 && (opt_flags & OPT_LOCAL))
4833 origval = *(char_u **)get_varp(
4834 &options[opt_idx]);
4835 else
4836 origval = oldval;
4837
Bram Moolenaar071d4272004-06-13 20:20:40 +00004838 if (nextchar == '&') /* set to default val */
4839 {
4840 newval = options[opt_idx].def_val[
4841 ((flags & P_VI_DEF) || cp_val)
4842 ? VI_DEFAULT : VIM_DEFAULT];
4843 if ((char_u **)varp == &p_bg)
4844 {
4845 /* guess the value of 'background' */
4846#ifdef FEAT_GUI
4847 if (gui.in_use)
4848 newval = gui_bg_default();
4849 else
4850#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004851 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004852 }
4853
4854 /* expand environment variables and ~ (since the
4855 * default value was already expanded, only
4856 * required when an environment variable was set
4857 * later */
4858 if (newval == NULL)
4859 newval = empty_option;
4860 else
4861 {
4862 s = option_expand(opt_idx, newval);
4863 if (s == NULL)
4864 s = newval;
4865 newval = vim_strsave(s);
4866 }
4867 new_value_alloced = TRUE;
4868 }
4869 else if (nextchar == '<') /* set to global val */
4870 {
4871 newval = vim_strsave(*(char_u **)get_varp_scope(
4872 &(options[opt_idx]), OPT_GLOBAL));
4873 new_value_alloced = TRUE;
4874 }
4875 else
4876 {
4877 ++arg; /* jump to after the '=' or ':' */
4878
4879 /*
4880 * Set 'keywordprg' to ":help" if an empty
4881 * value was passed to :set by the user.
4882 * Misuse errbuf[] for the resulting string.
4883 */
4884 if (varp == (char_u *)&p_kp
4885 && (*arg == NUL || *arg == ' '))
4886 {
4887 STRCPY(errbuf, ":help");
4888 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004889 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004890 }
4891 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004892 * Convert 'backspace' number to string, for
4893 * adding, prepending and removing string.
4894 */
4895 else if (varp == (char_u *)&p_bs
4896 && VIM_ISDIGIT(**(char_u **)varp))
4897 {
4898 i = getdigits((char_u **)varp);
4899 switch (i)
4900 {
4901 case 0:
4902 *(char_u **)varp = empty_option;
4903 break;
4904 case 1:
4905 *(char_u **)varp = vim_strsave(
4906 (char_u *)"indent,eol");
4907 break;
4908 case 2:
4909 *(char_u **)varp = vim_strsave(
4910 (char_u *)"indent,eol,start");
4911 break;
4912 }
4913 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004914 if (origval == oldval)
4915 origval = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004916 oldval = *(char_u **)varp;
4917 }
4918 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004919 * Convert 'whichwrap' number to string, for
4920 * backwards compatibility with Vim 3.0.
4921 * Misuse errbuf[] for the resulting string.
4922 */
4923 else if (varp == (char_u *)&p_ww
4924 && VIM_ISDIGIT(*arg))
4925 {
4926 *errbuf = NUL;
4927 i = getdigits(&arg);
4928 if (i & 1)
4929 STRCAT(errbuf, "b,");
4930 if (i & 2)
4931 STRCAT(errbuf, "s,");
4932 if (i & 4)
4933 STRCAT(errbuf, "h,l,");
4934 if (i & 8)
4935 STRCAT(errbuf, "<,>,");
4936 if (i & 16)
4937 STRCAT(errbuf, "[,],");
4938 if (*errbuf != NUL) /* remove trailing , */
4939 errbuf[STRLEN(errbuf) - 1] = NUL;
4940 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004941 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004942 }
4943 /*
4944 * Remove '>' before 'dir' and 'bdir', for
4945 * backwards compatibility with version 3.0
4946 */
4947 else if ( *arg == '>'
4948 && (varp == (char_u *)&p_dir
4949 || varp == (char_u *)&p_bdir))
4950 {
4951 ++arg;
4952 }
4953
Bram Moolenaar071d4272004-06-13 20:20:40 +00004954 /*
4955 * Copy the new string into allocated memory.
4956 * Can't use set_string_option_direct(), because
4957 * we need to remove the backslashes.
4958 */
4959 /* get a bit too much */
4960 newlen = (unsigned)STRLEN(arg) + 1;
4961 if (adding || prepending || removing)
4962 newlen += (unsigned)STRLEN(origval) + 1;
4963 newval = alloc(newlen);
4964 if (newval == NULL) /* out of mem, don't change */
4965 break;
4966 s = newval;
4967
4968 /*
4969 * Copy the string, skip over escaped chars.
4970 * For MS-DOS and WIN32 backslashes before normal
4971 * file name characters are not removed, and keep
4972 * backslash at start, for "\\machine\path", but
4973 * do remove it for "\\\\machine\\path".
4974 * The reverse is found in ExpandOldSetting().
4975 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004976 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004977 {
4978 if (*arg == '\\' && arg[1] != NUL
4979#ifdef BACKSLASH_IN_FILENAME
4980 && !((flags & P_EXPAND)
4981 && vim_isfilec(arg[1])
4982 && (arg[1] != '\\'
4983 || (s == newval
4984 && arg[2] != '\\')))
4985#endif
4986 )
4987 ++arg; /* remove backslash */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004988 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004989 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004990 {
4991 /* copy multibyte char */
4992 mch_memmove(s, arg, (size_t)i);
4993 arg += i;
4994 s += i;
4995 }
4996 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004997 *s++ = *arg++;
4998 }
4999 *s = NUL;
5000
5001 /*
5002 * Expand environment variables and ~.
5003 * Don't do it when adding without inserting a
5004 * comma.
5005 */
5006 if (!(adding || prepending || removing)
5007 || (flags & P_COMMA))
5008 {
5009 s = option_expand(opt_idx, newval);
5010 if (s != NULL)
5011 {
5012 vim_free(newval);
5013 newlen = (unsigned)STRLEN(s) + 1;
5014 if (adding || prepending || removing)
5015 newlen += (unsigned)STRLEN(origval) + 1;
5016 newval = alloc(newlen);
5017 if (newval == NULL)
5018 break;
5019 STRCPY(newval, s);
5020 }
5021 }
5022
5023 /* locate newval[] in origval[] when removing it
5024 * and when adding to avoid duplicates */
5025 i = 0; /* init for GCC */
5026 if (removing || (flags & P_NODUP))
5027 {
5028 i = (int)STRLEN(newval);
5029 bs = 0;
5030 for (s = origval; *s; ++s)
5031 {
5032 if ((!(flags & P_COMMA)
5033 || s == origval
5034 || (s[-1] == ',' && !(bs & 1)))
5035 && STRNCMP(s, newval, i) == 0
5036 && (!(flags & P_COMMA)
5037 || s[i] == ','
5038 || s[i] == NUL))
5039 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005040 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005041 * even number of backslashes or a single
5042 * backslash preceded by a comma before it
5043 * is recognized as a separator */
5044 if ((s > origval + 1
5045 && s[-1] == '\\'
5046 && s[-2] != ',')
5047 || (s == origval + 1
5048 && s[-1] == '\\'))
5049
Bram Moolenaar071d4272004-06-13 20:20:40 +00005050 ++bs;
5051 else
5052 bs = 0;
5053 }
5054
5055 /* do not add if already there */
5056 if ((adding || prepending) && *s)
5057 {
5058 prepending = FALSE;
5059 adding = FALSE;
5060 STRCPY(newval, origval);
5061 }
5062 }
5063
5064 /* concatenate the two strings; add a ',' if
5065 * needed */
5066 if (adding || prepending)
5067 {
5068 comma = ((flags & P_COMMA) && *origval != NUL
5069 && *newval != NUL);
5070 if (adding)
5071 {
5072 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005073 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005074 if (comma && i > 1
5075 && (flags & P_ONECOMMA) == P_ONECOMMA
5076 && origval[i - 1] == ','
5077 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005078 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005079 mch_memmove(newval + i + comma, newval,
5080 STRLEN(newval) + 1);
5081 mch_memmove(newval, origval, (size_t)i);
5082 }
5083 else
5084 {
5085 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005086 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005087 }
5088 if (comma)
5089 newval[i] = ',';
5090 }
5091
5092 /* Remove newval[] from origval[]. (Note: "i" has
5093 * been set above and is used here). */
5094 if (removing)
5095 {
5096 STRCPY(newval, origval);
5097 if (*s)
5098 {
5099 /* may need to remove a comma */
5100 if (flags & P_COMMA)
5101 {
5102 if (s == origval)
5103 {
5104 /* include comma after string */
5105 if (s[i] == ',')
5106 ++i;
5107 }
5108 else
5109 {
5110 /* include comma before string */
5111 --s;
5112 ++i;
5113 }
5114 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005115 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005116 }
5117 }
5118
5119 if (flags & P_FLAGLIST)
5120 {
5121 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005122 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005123 {
5124 /* if options have P_FLAGLIST and
5125 * P_ONECOMMA such as 'whichwrap' */
5126 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005127 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005128 if (*s != ',' && *(s + 1) == ','
5129 && vim_strchr(s + 2, *s) != NULL)
5130 {
5131 /* Remove the duplicated value and
5132 * the next comma. */
5133 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005134 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005135 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005136 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005137 else
5138 {
5139 if ((!(flags & P_COMMA) || *s != ',')
5140 && vim_strchr(s + 1, *s) != NULL)
5141 {
5142 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005143 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005144 }
5145 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005146 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005147 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005148 }
5149
5150 if (save_arg != NULL) /* number for 'whichwrap' */
5151 arg = save_arg;
5152 new_value_alloced = TRUE;
5153 }
5154
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005155 /*
5156 * Set the new value.
5157 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005158 *(char_u **)(varp) = newval;
5159
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005160#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005161 if (!starting
5162# ifdef FEAT_CRYPT
5163 && options[opt_idx].indir != PV_KEY
5164# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005165 && origval != NULL && newval != NULL)
5166 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005167 /* origval may be freed by
5168 * did_set_string_option(), make a copy. */
5169 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005170 /* newval (and varp) may become invalid if the
5171 * buffer is closed by autocommands. */
5172 saved_newval = vim_strsave(newval);
5173 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005174#endif
5175
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005176 {
5177 long_u *p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005178 int secure_saved = secure;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005179
5180 // When an option is set in the sandbox, from a
5181 // modeline or in secure mode, then deal with side
5182 // effects in secure mode. Also when the value was
5183 // set with the P_INSECURE flag and is not
5184 // completely replaced.
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005185 if ((opt_flags & OPT_MODELINE)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005186#ifdef HAVE_SANDBOX
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005187 || sandbox != 0
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005188#endif
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005189 || (!value_is_replaced && (*p & P_INSECURE)))
5190 secure = 1;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005191
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005192 // Handle side effects, and set the global value
5193 // for ":set" on local options. Note: when setting
5194 // 'syntax' or 'filetype' autocommands may be
5195 // triggered that can cause havoc.
5196 errmsg = did_set_string_option(
5197 opt_idx, (char_u **)varp,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005198 new_value_alloced, oldval, errbuf,
5199 opt_flags, &value_checked);
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005200
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005201 secure = secure_saved;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005202 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005203
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005204#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005205 if (errmsg == NULL)
5206 trigger_optionsset_string(opt_idx, opt_flags,
5207 saved_origval, saved_newval);
5208 vim_free(saved_origval);
5209 vim_free(saved_newval);
5210#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005211 /* If error detected, print the error message. */
5212 if (errmsg != NULL)
5213 goto skip;
5214 }
5215 else /* key code option */
5216 {
5217 char_u *p;
5218
5219 if (nextchar == '&')
5220 {
5221 if (add_termcap_entry(key_name, TRUE) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005222 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005223 }
5224 else
5225 {
5226 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005227 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005228 if (*p == '\\' && p[1] != NUL)
5229 ++p;
5230 nextchar = *p;
5231 *p = NUL;
5232 add_termcode(key_name, arg, FALSE);
5233 *p = nextchar;
5234 }
5235 if (full_screen)
5236 ttest(FALSE);
5237 redraw_all_later(CLEAR);
5238 }
5239 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005240
Bram Moolenaar071d4272004-06-13 20:20:40 +00005241 if (opt_idx >= 0)
Bram Moolenaar916a8182018-11-25 02:18:29 +01005242 did_set_option(
5243 opt_idx, opt_flags, value_is_replaced, value_checked);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005244 }
5245
5246skip:
5247 /*
5248 * Advance to next argument.
5249 * - skip until a blank found, taking care of backslashes
5250 * - skip blanks
5251 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5252 */
5253 for (i = 0; i < 2 ; ++i)
5254 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005255 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005256 if (*arg++ == '\\' && *arg != NUL)
5257 ++arg;
5258 arg = skipwhite(arg);
5259 if (*arg != '=')
5260 break;
5261 }
5262 }
5263
5264 if (errmsg != NULL)
5265 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005266 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005267 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005268 if (i + (arg - startarg) < IOSIZE)
5269 {
5270 /* append the argument with the error */
5271 STRCAT(IObuff, ": ");
5272 mch_memmove(IObuff + i, startarg, (arg - startarg));
5273 IObuff[i + (arg - startarg)] = NUL;
5274 }
5275 /* make sure all characters are printable */
5276 trans_characters(IObuff, IOSIZE);
5277
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005278 ++no_wait_return; // wait_return done later
5279 emsg((char *)IObuff); // show error highlighted
Bram Moolenaar071d4272004-06-13 20:20:40 +00005280 --no_wait_return;
5281
5282 return FAIL;
5283 }
5284
5285 arg = skipwhite(arg);
5286 }
5287
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005288theend:
5289 if (silent_mode && did_show)
5290 {
5291 /* After displaying option values in silent mode. */
5292 silent_mode = FALSE;
5293 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5294 msg_putchar('\n');
5295 cursor_on(); /* msg_start() switches it off */
5296 out_flush();
5297 silent_mode = TRUE;
5298 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5299 }
5300
Bram Moolenaar071d4272004-06-13 20:20:40 +00005301 return OK;
5302}
5303
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005304/*
5305 * Call this when an option has been given a new value through a user command.
5306 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5307 */
5308 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005309did_set_option(
5310 int opt_idx,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005311 int opt_flags, // possibly with OPT_MODELINE
5312 int new_value, // value was replaced completely
5313 int value_checked) // value was checked to be safe, no need to set the
5314 // P_INSECURE flag.
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005315{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005316 long_u *p;
5317
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005318 options[opt_idx].flags |= P_WAS_SET;
5319
5320 /* When an option is set in the sandbox, from a modeline or in secure mode
5321 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005322 * flag. */
5323 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar916a8182018-11-25 02:18:29 +01005324 if (!value_checked && (secure
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005325#ifdef HAVE_SANDBOX
5326 || sandbox != 0
5327#endif
Bram Moolenaar916a8182018-11-25 02:18:29 +01005328 || (opt_flags & OPT_MODELINE)))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005329 *p = *p | P_INSECURE;
5330 else if (new_value)
5331 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005332}
5333
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005334 static char *
5335illegal_char(char *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005336{
5337 if (errbuf == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005338 return "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00005339 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005340 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005341 return errbuf;
5342}
5343
5344/*
5345 * Convert a key name or string into a key value.
5346 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005347 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005348 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005349 int
5350string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005351{
5352 if (*arg == '<')
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02005353 return find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005354 if (*arg == '^')
5355 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005356 if (multi_byte)
5357 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005358 return *arg;
5359}
5360
5361#ifdef FEAT_CMDWIN
5362/*
5363 * Check value of 'cedit' and set cedit_key.
5364 * Returns NULL if value is OK, error message otherwise.
5365 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005366 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005367check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005368{
5369 int n;
5370
5371 if (*p_cedit == NUL)
5372 cedit_key = -1;
5373 else
5374 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005375 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005376 if (vim_isprintc(n))
5377 return e_invarg;
5378 cedit_key = n;
5379 }
5380 return NULL;
5381}
5382#endif
5383
5384#ifdef FEAT_TITLE
5385/*
5386 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5387 * maketitle() to create and display it.
5388 * When switching the title or icon off, call mch_restore_title() to get
5389 * the old value back.
5390 */
5391 static void
Bram Moolenaar84a93082018-06-16 22:58:15 +02005392did_set_title(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005393{
5394 if (starting != NO_SCREEN
5395#ifdef FEAT_GUI
5396 && !gui.starting
5397#endif
5398 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00005399 maketitle();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005400}
5401#endif
5402
5403/*
5404 * set_options_bin - called when 'bin' changes value.
5405 */
5406 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005407set_options_bin(
5408 int oldval,
5409 int newval,
5410 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005411{
5412 /*
5413 * The option values that are changed when 'bin' changes are
5414 * copied when 'bin is set and restored when 'bin' is reset.
5415 */
5416 if (newval)
5417 {
5418 if (!oldval) /* switched on */
5419 {
5420 if (!(opt_flags & OPT_GLOBAL))
5421 {
5422 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5423 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5424 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5425 curbuf->b_p_et_nobin = curbuf->b_p_et;
5426 }
5427 if (!(opt_flags & OPT_LOCAL))
5428 {
5429 p_tw_nobin = p_tw;
5430 p_wm_nobin = p_wm;
5431 p_ml_nobin = p_ml;
5432 p_et_nobin = p_et;
5433 }
5434 }
5435
5436 if (!(opt_flags & OPT_GLOBAL))
5437 {
5438 curbuf->b_p_tw = 0; /* no automatic line wrap */
5439 curbuf->b_p_wm = 0; /* no automatic line wrap */
5440 curbuf->b_p_ml = 0; /* no modelines */
5441 curbuf->b_p_et = 0; /* no expandtab */
5442 }
5443 if (!(opt_flags & OPT_LOCAL))
5444 {
5445 p_tw = 0;
5446 p_wm = 0;
5447 p_ml = FALSE;
5448 p_et = FALSE;
5449 p_bin = TRUE; /* needed when called for the "-b" argument */
5450 }
5451 }
5452 else if (oldval) /* switched off */
5453 {
5454 if (!(opt_flags & OPT_GLOBAL))
5455 {
5456 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5457 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5458 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5459 curbuf->b_p_et = curbuf->b_p_et_nobin;
5460 }
5461 if (!(opt_flags & OPT_LOCAL))
5462 {
5463 p_tw = p_tw_nobin;
5464 p_wm = p_wm_nobin;
5465 p_ml = p_ml_nobin;
5466 p_et = p_et_nobin;
5467 }
5468 }
5469}
5470
5471#ifdef FEAT_VIMINFO
5472/*
5473 * Find the parameter represented by the given character (eg ', :, ", or /),
5474 * and return its associated value in the 'viminfo' string.
5475 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005476 * If the parameter is not specified in the string or there is no following
5477 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005478 */
5479 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005480get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005481{
5482 char_u *p;
5483
5484 p = find_viminfo_parameter(type);
5485 if (p != NULL && VIM_ISDIGIT(*p))
5486 return atoi((char *)p);
5487 return -1;
5488}
5489
5490/*
5491 * Find the parameter represented by the given character (eg ''', ':', '"', or
5492 * '/') in the 'viminfo' option and return a pointer to the string after it.
5493 * Return NULL if the parameter is not specified in the string.
5494 */
5495 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005496find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005497{
5498 char_u *p;
5499
5500 for (p = p_viminfo; *p; ++p)
5501 {
5502 if (*p == type)
5503 return p + 1;
5504 if (*p == 'n') /* 'n' is always the last one */
5505 break;
5506 p = vim_strchr(p, ','); /* skip until next ',' */
5507 if (p == NULL) /* hit the end without finding parameter */
5508 break;
5509 }
5510 return NULL;
5511}
5512#endif
5513
5514/*
5515 * Expand environment variables for some string options.
5516 * These string options cannot be indirect!
5517 * If "val" is NULL expand the current value of the option.
5518 * Return pointer to NameBuff, or NULL when not expanded.
5519 */
5520 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005521option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005522{
5523 /* if option doesn't need expansion nothing to do */
5524 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5525 return NULL;
5526
5527 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5528 * expand_env() would truncate the string. */
5529 if (val != NULL && STRLEN(val) > MAXPATHL)
5530 return NULL;
5531
5532 if (val == NULL)
5533 val = *(char_u **)options[opt_idx].var;
5534
5535 /*
5536 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5537 * Escape spaces when expanding 'tags', they are used to separate file
5538 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005539 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005540 */
5541 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005542 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005543#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005544 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5545#endif
5546 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005547 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5548 return NULL;
5549
5550 return NameBuff;
5551}
5552
5553/*
5554 * After setting various option values: recompute variables that depend on
5555 * option values.
5556 */
5557 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005558didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005559{
5560 /* initialize the table for 'iskeyword' et.al. */
5561 (void)init_chartab();
5562
5563 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
5564 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005565 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005566#ifdef FEAT_SESSION
5567 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5568 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5569#endif
5570#ifdef FEAT_FOLDING
5571 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5572#endif
5573 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005574 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005575 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005576#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5577 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5578#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005579#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005580 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005581 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005582 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005583 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005584#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01005585#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005586 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5587#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005588#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005589 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5590#endif
5591#ifdef FEAT_CMDWIN
5592 /* set cedit_key */
5593 (void)check_cedit();
5594#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005595#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005596 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005597#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005598#ifdef FEAT_LINEBREAK
5599 /* initialize the table for 'breakat'. */
5600 fill_breakat_flags();
5601#endif
5602
5603}
5604
5605/*
5606 * More side effects of setting options.
5607 */
5608 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005609didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005610{
5611 /* Initialize the highlight_attr[] table. */
5612 (void)highlight_changed();
5613
5614 /* Parse default for 'wildmode' */
5615 check_opt_wim();
5616
5617 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005618 /* Parse default for 'fillchars'. */
5619 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005620
5621#ifdef FEAT_CLIPBOARD
5622 /* Parse default for 'clipboard' */
5623 (void)check_clipboard_option();
5624#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005625#ifdef FEAT_VARTABS
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01005626 vim_free(curbuf->b_p_vsts_array);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005627 tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_array);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01005628 vim_free(curbuf->b_p_vts_array);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005629 tabstop_set(curbuf->b_p_vts, &curbuf->b_p_vts_array);
5630#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005631}
5632
5633/*
5634 * Check for string options that are NULL (normally only termcap options).
5635 */
5636 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005637check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005638{
5639 int opt_idx;
5640
5641 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5642 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5643 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5644}
5645
5646/*
5647 * Check string options in a buffer for NULL value.
5648 */
5649 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005650check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005651{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005652 check_string_option(&buf->b_p_bh);
5653 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005654 check_string_option(&buf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005655 check_string_option(&buf->b_p_ff);
5656#ifdef FEAT_FIND_ID
5657 check_string_option(&buf->b_p_def);
5658 check_string_option(&buf->b_p_inc);
5659# ifdef FEAT_EVAL
5660 check_string_option(&buf->b_p_inex);
5661# endif
5662#endif
5663#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5664 check_string_option(&buf->b_p_inde);
5665 check_string_option(&buf->b_p_indk);
5666#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005667#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5668 check_string_option(&buf->b_p_bexpr);
5669#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005670#if defined(FEAT_CRYPT)
5671 check_string_option(&buf->b_p_cm);
5672#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005673 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005674#if defined(FEAT_EVAL)
5675 check_string_option(&buf->b_p_fex);
5676#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005677#ifdef FEAT_CRYPT
5678 check_string_option(&buf->b_p_key);
5679#endif
5680 check_string_option(&buf->b_p_kp);
5681 check_string_option(&buf->b_p_mps);
5682 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005683 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005684 check_string_option(&buf->b_p_isk);
5685#ifdef FEAT_COMMENTS
5686 check_string_option(&buf->b_p_com);
5687#endif
5688#ifdef FEAT_FOLDING
5689 check_string_option(&buf->b_p_cms);
5690#endif
5691 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005692#ifdef FEAT_TEXTOBJ
5693 check_string_option(&buf->b_p_qe);
5694#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005695#ifdef FEAT_SYN_HL
5696 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005697 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005698#endif
5699#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005700 check_string_option(&buf->b_s.b_p_spc);
5701 check_string_option(&buf->b_s.b_p_spf);
5702 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005703#endif
5704#ifdef FEAT_SEARCHPATH
5705 check_string_option(&buf->b_p_sua);
5706#endif
5707#ifdef FEAT_CINDENT
5708 check_string_option(&buf->b_p_cink);
5709 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005710 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005711#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005712 check_string_option(&buf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005713#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5714 check_string_option(&buf->b_p_cinw);
5715#endif
5716#ifdef FEAT_INS_EXPAND
5717 check_string_option(&buf->b_p_cpt);
5718#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005719#ifdef FEAT_COMPL_FUNC
5720 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005721 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005722#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +02005723#ifdef FEAT_EVAL
5724 check_string_option(&buf->b_p_tfu);
5725#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005726#ifdef FEAT_KEYMAP
5727 check_string_option(&buf->b_p_keymap);
5728#endif
5729#ifdef FEAT_QUICKFIX
5730 check_string_option(&buf->b_p_gp);
5731 check_string_option(&buf->b_p_mp);
5732 check_string_option(&buf->b_p_efm);
5733#endif
5734 check_string_option(&buf->b_p_ep);
5735 check_string_option(&buf->b_p_path);
5736 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005737 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005738#ifdef FEAT_INS_EXPAND
5739 check_string_option(&buf->b_p_dict);
5740 check_string_option(&buf->b_p_tsr);
5741#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005742#ifdef FEAT_LISP
5743 check_string_option(&buf->b_p_lw);
5744#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005745 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005746 check_string_option(&buf->b_p_menc);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005747#ifdef FEAT_VARTABS
5748 check_string_option(&buf->b_p_vsts);
5749 check_string_option(&buf->b_p_vts);
5750#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005751}
5752
5753/*
5754 * Free the string allocated for an option.
5755 * Checks for the string being empty_option. This may happen if we're out of
5756 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5757 * check_options().
5758 * Does NOT check for P_ALLOCED flag!
5759 */
5760 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005761free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005762{
5763 if (p != empty_option)
5764 vim_free(p);
5765}
5766
5767 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005768clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005769{
5770 if (*pp != empty_option)
5771 vim_free(*pp);
5772 *pp = empty_option;
5773}
5774
5775 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005776check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005777{
5778 if (*pp == NULL)
5779 *pp = empty_option;
5780}
5781
5782/*
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005783 * Return the option index found by a pointer into term_strings[].
5784 * Return -1 if not found.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005785 */
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005786 int
5787get_term_opt_idx(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005788{
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005789 int opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005790
5791 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5792 if (options[opt_idx].var == (char_u *)p)
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005793 return opt_idx;
5794 return -1; // cannot happen: didn't find it!
5795}
5796
5797/*
5798 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5799 * Return the option index or -1 if not found.
5800 */
5801 int
5802set_term_option_alloced(char_u **p)
5803{
5804 int opt_idx = get_term_opt_idx(p);
5805
5806 if (opt_idx >= 0)
5807 options[opt_idx].flags |= P_ALLOCED;
5808 return opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005809}
5810
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005811#if defined(FEAT_EVAL) || defined(PROTO)
5812/*
5813 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5814 * Return FALSE when it wasn't.
5815 * Return -1 for an unknown option.
5816 */
5817 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005818was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005819{
5820 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005821 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005822
5823 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005824 {
5825 flagp = insecure_flag(idx, opt_flags);
5826 return (*flagp & P_INSECURE) != 0;
5827 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005828 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005829 return -1;
5830}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005831
5832/*
5833 * Get a pointer to the flags used for the P_INSECURE flag of option
5834 * "opt_idx". For some local options a local flags field is used.
5835 */
5836 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005837insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005838{
5839 if (opt_flags & OPT_LOCAL)
5840 switch ((int)options[opt_idx].indir)
5841 {
5842#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005843 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005844#endif
5845#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005846# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005847 case PV_FDE: return &curwin->w_p_fde_flags;
5848 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005849# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005850# ifdef FEAT_BEVAL
5851 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5852# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005853# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005854 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005855# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005856 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005857# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005858 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005859# endif
5860#endif
5861 }
5862
5863 /* Nothing special, return global flags field. */
5864 return &options[opt_idx].flags;
5865}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005866#endif
5867
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005868#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005869/*
5870 * Redraw the window title and/or tab page text later.
5871 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005872static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005873{
5874 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005875 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005876}
5877#endif
5878
Bram Moolenaar071d4272004-06-13 20:20:40 +00005879/*
5880 * Set a string option to a new value (without checking the effect).
5881 * The string is copied into allocated memory.
5882 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005883 * When "set_sid" is zero set the scriptID to current_sctx.sc_sid. When
5884 * "set_sid" is SID_NONE don't set the scriptID. Otherwise set the scriptID to
5885 * "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005886 */
5887 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005888set_string_option_direct(
5889 char_u *name,
5890 int opt_idx,
5891 char_u *val,
5892 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5893 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005894{
5895 char_u *s;
5896 char_u **varp;
5897 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005898 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005899
Bram Moolenaar89d40322006-08-29 15:30:07 +00005900 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005901 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005902 idx = findoption(name);
5903 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005904 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005905 semsg(_(e_intern2), "set_string_option_direct()");
5906 siemsg(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005907 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005908 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005909 }
5910
Bram Moolenaar89d40322006-08-29 15:30:07 +00005911 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005912 return;
5913
5914 s = vim_strsave(val);
5915 if (s != NULL)
5916 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005917 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005918 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005919 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005920 free_string_option(*varp);
5921 *varp = s;
5922
5923 /* For buffer/window local option may also set the global value. */
5924 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005925 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005926
Bram Moolenaar89d40322006-08-29 15:30:07 +00005927 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005928
5929 /* When setting both values of a global option with a local value,
5930 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005931 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005932 {
5933 free_string_option(*varp);
5934 *varp = empty_option;
5935 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005936# ifdef FEAT_EVAL
5937 if (set_sid != SID_NONE)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005938 {
5939 sctx_T script_ctx;
5940
5941 if (set_sid == 0)
5942 script_ctx = current_sctx;
5943 else
5944 {
5945 script_ctx.sc_sid = set_sid;
Bram Moolenaarded5f1b2018-11-10 17:33:29 +01005946 script_ctx.sc_seq = 0;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005947 script_ctx.sc_lnum = 0;
Bram Moolenaar558ca4a2019-04-04 18:15:38 +02005948 script_ctx.sc_version = 1;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005949 }
5950 set_option_sctx_idx(idx, opt_flags, script_ctx);
5951 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005952# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005953 }
5954}
5955
5956/*
Bram Moolenaar20c023a2019-05-26 21:03:24 +02005957 * Like set_string_option_direct(), but for a window-local option in "wp".
5958 * Blocks autocommands to avoid the old curwin becoming invalid.
5959 */
5960 void
5961set_string_option_direct_in_win(
5962 win_T *wp,
5963 char_u *name,
5964 int opt_idx,
5965 char_u *val,
5966 int opt_flags,
5967 int set_sid)
5968{
5969 win_T *save_curwin = curwin;
5970
5971 block_autocmds();
5972 curwin = wp;
5973 curbuf = curwin->w_buffer;
5974 set_string_option_direct(name, opt_idx, val, opt_flags, set_sid);
5975 curwin = save_curwin;
5976 curbuf = curwin->w_buffer;
5977 unblock_autocmds();
5978}
5979
5980/*
5981 * Like set_string_option_direct(), but for a buffer-local option in "buf".
5982 * Blocks autocommands to avoid the old curbuf becoming invalid.
5983 */
5984 void
5985set_string_option_direct_in_buf(
5986 buf_T *buf,
5987 char_u *name,
5988 int opt_idx,
5989 char_u *val,
5990 int opt_flags,
5991 int set_sid)
5992{
5993 buf_T *save_curbuf = curbuf;
5994
5995 block_autocmds();
5996 curbuf = buf;
5997 curwin->w_buffer = curbuf;
5998 set_string_option_direct(name, opt_idx, val, opt_flags, set_sid);
5999 curbuf = save_curbuf;
6000 curwin->w_buffer = curbuf;
6001 unblock_autocmds();
6002}
6003
6004/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006005 * Set global value for string option when it's a local option.
6006 */
6007 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01006008set_string_option_global(
6009 int opt_idx, /* option index */
6010 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006011{
6012 char_u **p, *s;
6013
6014 /* the global value is always allocated */
6015 if (options[opt_idx].var == VAR_WIN)
6016 p = (char_u **)GLOBAL_WO(varp);
6017 else
6018 p = (char_u **)options[opt_idx].var;
6019 if (options[opt_idx].indir != PV_NONE
6020 && p != varp
6021 && (s = vim_strsave(*varp)) != NULL)
6022 {
6023 free_string_option(*p);
6024 *p = s;
6025 }
6026}
6027
6028/*
6029 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006030 *
6031 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006032 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006033 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006034set_string_option(
6035 int opt_idx,
6036 char_u *value,
6037 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006038{
6039 char_u *s;
6040 char_u **varp;
6041 char_u *oldval;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006042#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02006043 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006044 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02006045#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006046 char *r = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01006047 int value_checked = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006048
6049 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006050 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006051
6052 s = vim_strsave(value);
6053 if (s != NULL)
6054 {
6055 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
6056 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006057 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006058 ? OPT_GLOBAL : OPT_LOCAL)
6059 : opt_flags);
6060 oldval = *varp;
6061 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02006062
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006063#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02006064 if (!starting
6065# ifdef FEAT_CRYPT
6066 && options[opt_idx].indir != PV_KEY
6067# endif
6068 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006069 {
Bram Moolenaar53744302015-07-17 17:38:22 +02006070 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006071 saved_newval = vim_strsave(s);
6072 }
Bram Moolenaar53744302015-07-17 17:38:22 +02006073#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006074 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
Bram Moolenaar916a8182018-11-25 02:18:29 +01006075 opt_flags, &value_checked)) == NULL)
6076 did_set_option(opt_idx, opt_flags, TRUE, value_checked);
Bram Moolenaar53744302015-07-17 17:38:22 +02006077
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006078#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006079 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006080 if (r == NULL)
6081 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006082 saved_oldval, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006083 vim_free(saved_oldval);
6084 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02006085#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006086 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006087 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006088}
6089
6090/*
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006091 * Return TRUE if "val" is a valid name: only consists of alphanumeric ASCII
6092 * characters or characters in "allowed".
6093 */
6094 static int
6095valid_name(char_u *val, char *allowed)
6096{
6097 char_u *s;
6098
6099 for (s = val; *s != NUL; ++s)
6100 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)allowed, *s) == NULL)
6101 return FALSE;
6102 return TRUE;
6103}
6104
6105/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01006106 * Return TRUE if "val" is a valid 'filetype' name.
6107 * Also used for 'syntax' and 'keymap'.
6108 */
6109 static int
6110valid_filetype(char_u *val)
6111{
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006112 return valid_name(val, ".-_");
6113}
Bram Moolenaard0b51382016-11-04 15:23:45 +01006114
Bram Moolenaara7be0f22019-04-11 11:19:32 +02006115#if defined(FEAT_SPELL) || defined(PROTO)
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006116/*
6117 * Return TRUE if "val" is a valid 'spellang' value.
6118 */
6119 int
6120valid_spellang(char_u *val)
6121{
Bram Moolenaar9a061cb2019-05-05 16:55:03 +02006122 return valid_name(val, ".-_,@");
Bram Moolenaard0b51382016-11-04 15:23:45 +01006123}
6124
6125/*
Bram Moolenaar862f1e12019-04-10 22:33:41 +02006126 * Return TRUE if "val" is a valid 'spellfile' value.
6127 */
6128 static int
6129valid_spellfile(char_u *val)
6130{
6131 char_u *s;
6132
6133 for (s = val; *s != NUL; ++s)
6134 if (!vim_isfilec(*s) && *s != ',')
6135 return FALSE;
6136 return TRUE;
6137}
Bram Moolenaara7be0f22019-04-11 11:19:32 +02006138#endif
Bram Moolenaar862f1e12019-04-10 22:33:41 +02006139
6140/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006141 * Handle string options that need some action to perform when changed.
6142 * Returns NULL for success, or an error message for an error.
6143 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006144 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006145did_set_string_option(
Bram Moolenaar916a8182018-11-25 02:18:29 +01006146 int opt_idx, // index in options[] table
6147 char_u **varp, // pointer to the option variable
6148 int new_value_alloced, // new value was allocated
6149 char_u *oldval, // previous value of the option
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006150 char *errbuf, // buffer for errors, or NULL
Bram Moolenaar916a8182018-11-25 02:18:29 +01006151 int opt_flags, // OPT_LOCAL and/or OPT_GLOBAL
6152 int *value_checked) // value was checked to be save, no
6153 // need to set P_INSECURE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006154{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006155 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006156 char_u *s, *p;
6157 int did_chartab = FALSE;
6158 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006159 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006160#ifdef FEAT_GUI
6161 /* set when changing an option that only requires a redraw in the GUI */
6162 int redraw_gui_only = FALSE;
6163#endif
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02006164 int value_changed = FALSE;
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006165#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6166 int did_swaptcap = FALSE;
6167#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006168
6169 /* Get the global option to compare with, otherwise we would have to check
6170 * two values for all local options. */
6171 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6172
6173 /* Disallow changing some options from secure mode */
6174 if ((secure
6175#ifdef HAVE_SANDBOX
6176 || sandbox != 0
6177#endif
6178 ) && (options[opt_idx].flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006179 errmsg = e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006180
Bram Moolenaar916a8182018-11-25 02:18:29 +01006181 // Check for a "normal" directory or file name in some options. Disallow a
6182 // path separator (slash and/or backslash), wildcards and characters that
6183 // are often illegal in a file name. Be more permissive if "secure" is off.
Bram Moolenaar7554da42016-11-25 22:04:13 +01006184 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006185 && vim_strpbrk(*varp, (char_u *)(secure
6186 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006187 || ((options[opt_idx].flags & P_NDNAME)
6188 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006189 errmsg = e_invarg;
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006190
Bram Moolenaar071d4272004-06-13 20:20:40 +00006191 /* 'term' */
6192 else if (varp == &T_NAME)
6193 {
6194 if (T_NAME[0] == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006195 errmsg = N_("E529: Cannot set 'term' to empty string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006196#ifdef FEAT_GUI
6197 if (gui.in_use)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006198 errmsg = N_("E530: Cannot change term in GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006199 else if (term_is_gui(T_NAME))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006200 errmsg = N_("E531: Use \":gui\" to start the GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006201#endif
6202 else if (set_termname(T_NAME) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006203 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006204 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006205 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006206 /* Screen colors may have changed. */
6207 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006208
6209 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6210 * P_ALLOCED flag on 'term'. */
6211 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006212 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006213 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006214 }
6215
6216 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006217 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006218 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006219 char_u *bkc = p_bkc;
6220 unsigned int *flags = &bkc_flags;
6221
6222 if (opt_flags & OPT_LOCAL)
6223 {
6224 bkc = curbuf->b_p_bkc;
6225 flags = &curbuf->b_bkc_flags;
6226 }
6227
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006228 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6229 /* make the local value empty: use the global value */
6230 *flags = 0;
6231 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006232 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006233 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6234 errmsg = e_invarg;
6235 if ((((int)*flags & BKC_AUTO) != 0)
6236 + (((int)*flags & BKC_YES) != 0)
6237 + (((int)*flags & BKC_NO) != 0) != 1)
6238 {
6239 /* Must have exactly one of "auto", "yes" and "no". */
6240 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6241 errmsg = e_invarg;
6242 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006243 }
6244 }
6245
6246 /* 'backupext' and 'patchmode' */
6247 else if (varp == &p_bex || varp == &p_pm)
6248 {
6249 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6250 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006251 errmsg = N_("E589: 'backupext' and 'patchmode' are equal");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006252 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006253#ifdef FEAT_LINEBREAK
6254 /* 'breakindentopt' */
6255 else if (varp == &curwin->w_p_briopt)
6256 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006257 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006258 errmsg = e_invarg;
6259 }
6260#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006261
6262 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006263 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006264 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006265 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006266 */
6267 else if ( varp == &p_isi
6268 || varp == &(curbuf->b_p_isk)
6269 || varp == &p_isp
6270 || varp == &p_isf)
6271 {
6272 if (init_chartab() == FAIL)
6273 {
6274 did_chartab = TRUE; /* need to restore it below */
6275 errmsg = e_invarg; /* error in value */
6276 }
6277 }
6278
6279 /* 'helpfile' */
6280 else if (varp == &p_hf)
6281 {
6282 /* May compute new values for $VIM and $VIMRUNTIME */
6283 if (didset_vim)
6284 {
6285 vim_setenv((char_u *)"VIM", (char_u *)"");
6286 didset_vim = FALSE;
6287 }
6288 if (didset_vimruntime)
6289 {
6290 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6291 didset_vimruntime = FALSE;
6292 }
6293 }
6294
Bram Moolenaar1a384422010-07-14 19:53:30 +02006295#ifdef FEAT_SYN_HL
6296 /* 'colorcolumn' */
6297 else if (varp == &curwin->w_p_cc)
6298 errmsg = check_colorcolumn(curwin);
6299#endif
6300
Bram Moolenaar071d4272004-06-13 20:20:40 +00006301#ifdef FEAT_MULTI_LANG
6302 /* 'helplang' */
6303 else if (varp == &p_hlg)
6304 {
6305 /* Check for "", "ab", "ab,cd", etc. */
6306 for (s = p_hlg; *s != NUL; s += 3)
6307 {
6308 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6309 {
6310 errmsg = e_invarg;
6311 break;
6312 }
6313 if (s[2] == NUL)
6314 break;
6315 }
6316 }
6317#endif
6318
6319 /* 'highlight' */
6320 else if (varp == &p_hl)
6321 {
6322 if (highlight_changed() == FAIL)
6323 errmsg = e_invarg; /* invalid flags */
6324 }
6325
6326 /* 'nrformats' */
6327 else if (gvarp == &p_nf)
6328 {
6329 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6330 errmsg = e_invarg;
6331 }
6332
6333#ifdef FEAT_SESSION
6334 /* 'sessionoptions' */
6335 else if (varp == &p_ssop)
6336 {
6337 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6338 errmsg = e_invarg;
6339 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6340 {
6341 /* Don't allow both "sesdir" and "curdir". */
6342 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6343 errmsg = e_invarg;
6344 }
6345 }
6346 /* 'viewoptions' */
6347 else if (varp == &p_vop)
6348 {
6349 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6350 errmsg = e_invarg;
6351 }
6352#endif
6353
6354 /* 'scrollopt' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006355 else if (varp == &p_sbo)
6356 {
6357 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6358 errmsg = e_invarg;
6359 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006360
6361 /* 'ambiwidth' */
Bram Moolenaar3848e002016-03-19 18:42:29 +01006362 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006363 {
6364 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6365 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006366 else if (set_chars_option(&p_lcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006367 errmsg = _("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006368 else if (set_chars_option(&p_fcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006369 errmsg = _("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006370 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006371
6372 /* 'background' */
6373 else if (varp == &p_bg)
6374 {
6375 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6376 {
6377#ifdef FEAT_EVAL
6378 int dark = (*p_bg == 'd');
6379#endif
6380
6381 init_highlight(FALSE, FALSE);
6382
6383#ifdef FEAT_EVAL
6384 if (dark != (*p_bg == 'd')
6385 && get_var_value((char_u *)"g:colors_name") != NULL)
6386 {
6387 /* The color scheme must have set 'background' back to another
6388 * value, that's not what we want here. Disable the color
6389 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006390 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006391 free_string_option(p_bg);
6392 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6393 check_string_option(&p_bg);
6394 init_highlight(FALSE, FALSE);
6395 }
6396#endif
6397 }
6398 else
6399 errmsg = e_invarg;
6400 }
6401
6402 /* 'wildmode' */
6403 else if (varp == &p_wim)
6404 {
6405 if (check_opt_wim() == FAIL)
6406 errmsg = e_invarg;
6407 }
6408
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006409#ifdef FEAT_CMDL_COMPL
6410 /* 'wildoptions' */
6411 else if (varp == &p_wop)
6412 {
6413 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6414 errmsg = e_invarg;
6415 }
6416#endif
6417
Bram Moolenaar071d4272004-06-13 20:20:40 +00006418#ifdef FEAT_WAK
6419 /* 'winaltkeys' */
6420 else if (varp == &p_wak)
6421 {
6422 if (*p_wak == NUL
6423 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6424 errmsg = e_invarg;
6425# ifdef FEAT_MENU
6426# ifdef FEAT_GUI_MOTIF
6427 else if (gui.in_use)
6428 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6429# else
6430# ifdef FEAT_GUI_GTK
6431 else if (gui.in_use)
6432 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6433# endif
6434# endif
6435# endif
6436 }
6437#endif
6438
Bram Moolenaar071d4272004-06-13 20:20:40 +00006439 /* 'eventignore' */
6440 else if (varp == &p_ei)
6441 {
6442 if (check_ei() == FAIL)
6443 errmsg = e_invarg;
6444 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006445
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006446 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6447 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6448 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006449 {
6450 if (gvarp == &p_fenc)
6451 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006452 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006453 errmsg = e_modifiable;
6454 else if (vim_strchr(*varp, ',') != NULL)
6455 /* No comma allowed in 'fileencoding'; catches confusing it
6456 * with 'fileencodings'. */
6457 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006458 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006459 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006460#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006461 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006462 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006463#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006464 /* Add 'fileencoding' to the swap file. */
6465 ml_setflags(curbuf);
6466 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006467 }
6468 if (errmsg == NULL)
6469 {
6470 /* canonize the value, so that STRCMP() can be used on it */
6471 p = enc_canonize(*varp);
6472 if (p != NULL)
6473 {
6474 vim_free(*varp);
6475 *varp = p;
6476 }
6477 if (varp == &p_enc)
6478 {
6479 errmsg = mb_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006480#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006481 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006482#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006483 }
6484 }
6485
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006486#if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006487 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6488 {
6489 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6490 if (STRCMP(p_tenc, "utf-8") != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006491 errmsg = N_("E617: Cannot be changed in the GTK+ 2 GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006492 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006493#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006494
6495 if (errmsg == NULL)
6496 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006497#ifdef FEAT_KEYMAP
Bram Moolenaar071d4272004-06-13 20:20:40 +00006498 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6499 * (with another encoding). */
6500 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6501 (void)keymap_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006502#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006503
6504 /* When 'termencoding' is not empty and 'encoding' changes or when
6505 * 'termencoding' changes, need to setup for keyboard input and
6506 * display output conversion. */
6507 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6508 {
Bram Moolenaar17471e82017-11-26 23:47:18 +01006509 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6510 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6511 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006512 semsg(_("E950: Cannot convert between %s and %s"),
Bram Moolenaar17471e82017-11-26 23:47:18 +01006513 p_tenc, p_enc);
6514 errmsg = e_invarg;
6515 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006516 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006517
Bram Moolenaar4f974752019-02-17 17:44:42 +01006518#if defined(MSWIN)
Bram Moolenaar05159a02005-02-26 23:04:13 +00006519 /* $HOME may have characters in active code page. */
6520 if (varp == &p_enc)
6521 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006522#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006523 }
6524 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006525
6526#if defined(FEAT_POSTSCRIPT)
6527 else if (varp == &p_penc)
6528 {
6529 /* Canonize printencoding if VIM standard one */
6530 p = enc_canonize(p_penc);
6531 if (p != NULL)
6532 {
6533 vim_free(p_penc);
6534 p_penc = p;
6535 }
6536 else
6537 {
6538 /* Ensure lower case and '-' for '_' */
6539 for (s = p_penc; *s != NUL; s++)
6540 {
6541 if (*s == '_')
6542 *s = '-';
6543 else
6544 *s = TOLOWER_ASC(*s);
6545 }
6546 }
6547 }
6548#endif
6549
Bram Moolenaar9372a112005-12-06 19:59:18 +00006550#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006551 else if (varp == &p_imak)
6552 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006553 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006554 errmsg = e_invarg;
6555 }
6556#endif
6557
6558#ifdef FEAT_KEYMAP
6559 else if (varp == &curbuf->b_p_keymap)
6560 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006561 if (!valid_filetype(*varp))
6562 errmsg = e_invarg;
6563 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01006564 {
6565 int secure_save = secure;
6566
6567 // Reset the secure flag, since the value of 'keymap' has
6568 // been checked to be safe.
6569 secure = 0;
6570
6571 // load or unload key mapping tables
Bram Moolenaard0b51382016-11-04 15:23:45 +01006572 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006573
Bram Moolenaar916a8182018-11-25 02:18:29 +01006574 secure = secure_save;
6575
6576 // Since we check the value, there is no need to set P_INSECURE,
6577 // even when the value comes from a modeline.
6578 *value_checked = TRUE;
6579 }
6580
Bram Moolenaarfab06232009-03-04 03:13:35 +00006581 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006582 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006583 if (*curbuf->b_p_keymap != NUL)
6584 {
6585 /* Installed a new keymap, switch on using it. */
6586 curbuf->b_p_iminsert = B_IMODE_LMAP;
6587 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6588 curbuf->b_p_imsearch = B_IMODE_LMAP;
6589 }
6590 else
6591 {
6592 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6593 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6594 curbuf->b_p_iminsert = B_IMODE_NONE;
6595 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6596 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6597 }
6598 if ((opt_flags & OPT_LOCAL) == 0)
6599 {
6600 set_iminsert_global();
6601 set_imsearch_global();
6602 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006603 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006604 }
6605 }
6606#endif
6607
6608 /* 'fileformat' */
6609 else if (gvarp == &p_ff)
6610 {
6611 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6612 errmsg = e_modifiable;
6613 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6614 errmsg = e_invarg;
6615 else
6616 {
6617 /* may also change 'textmode' */
6618 if (get_fileformat(curbuf) == EOL_DOS)
6619 curbuf->b_p_tx = TRUE;
6620 else
6621 curbuf->b_p_tx = FALSE;
6622#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006623 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006624#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006625 /* update flag in swap file */
6626 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006627 /* Redraw needed when switching to/from "mac": a CR in the text
6628 * will be displayed differently. */
6629 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6630 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006631 }
6632 }
6633
6634 /* 'fileformats' */
6635 else if (varp == &p_ffs)
6636 {
6637 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6638 errmsg = e_invarg;
6639 else
6640 {
6641 /* also change 'textauto' */
6642 if (*p_ffs == NUL)
6643 p_ta = FALSE;
6644 else
6645 p_ta = TRUE;
6646 }
6647 }
6648
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006649#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006650 /* 'cryptkey' */
6651 else if (gvarp == &p_key)
6652 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006653# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006654 /* Make sure the ":set" command doesn't show the new value in the
6655 * history. */
6656 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006657# endif
6658 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6659 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006660 ml_set_crypt_key(curbuf, oldval,
6661 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006662 }
6663
6664 else if (gvarp == &p_cm)
6665 {
6666 if (opt_flags & OPT_LOCAL)
6667 p = curbuf->b_p_cm;
6668 else
6669 p = p_cm;
6670 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6671 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006672 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006673 errmsg = e_invarg;
6674 else
6675 {
6676 /* When setting the global value to empty, make it "zip". */
6677 if (*p_cm == NUL)
6678 {
6679 if (new_value_alloced)
6680 free_string_option(p_cm);
6681 p_cm = vim_strsave((char_u *)"zip");
6682 new_value_alloced = TRUE;
6683 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006684 /* When using ":set cm=name" the local value is going to be empty.
6685 * Do that here, otherwise the crypt functions will still use the
6686 * local value. */
6687 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6688 {
6689 free_string_option(curbuf->b_p_cm);
6690 curbuf->b_p_cm = empty_option;
6691 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006692
6693 /* Need to update the swapfile when the effective method changed.
6694 * Set "s" to the effective old value, "p" to the effective new
6695 * method and compare. */
6696 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6697 s = p_cm; /* was previously using the global value */
6698 else
6699 s = oldval;
6700 if (*curbuf->b_p_cm == NUL)
6701 p = p_cm; /* is now using the global value */
6702 else
6703 p = curbuf->b_p_cm;
6704 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006705 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006706
6707 /* If the global value changes need to update the swapfile for all
6708 * buffers using that value. */
6709 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6710 {
6711 buf_T *buf;
6712
Bram Moolenaar29323592016-07-24 22:04:11 +02006713 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006714 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006715 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006716 }
6717 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006718 }
6719#endif
6720
6721 /* 'matchpairs' */
6722 else if (gvarp == &p_mps)
6723 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006724 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006725 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006726 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006727 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006728 int x2 = -1;
6729 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006730
6731 if (*p != NUL)
6732 p += mb_ptr2len(p);
6733 if (*p != NUL)
6734 x2 = *p++;
6735 if (*p != NUL)
6736 {
6737 x3 = mb_ptr2char(p);
6738 p += mb_ptr2len(p);
6739 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006740 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006741 {
6742 errmsg = e_invarg;
6743 break;
6744 }
6745 if (*p == NUL)
6746 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006747 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006748 }
6749 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006750 {
6751 /* Check for "x:y,x:y" */
6752 for (p = *varp; *p != NUL; p += 4)
6753 {
6754 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6755 {
6756 errmsg = e_invarg;
6757 break;
6758 }
6759 if (p[3] == NUL)
6760 break;
6761 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006762 }
6763 }
6764
6765#ifdef FEAT_COMMENTS
6766 /* 'comments' */
6767 else if (gvarp == &p_com)
6768 {
6769 for (s = *varp; *s; )
6770 {
6771 while (*s && *s != ':')
6772 {
6773 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6774 && !VIM_ISDIGIT(*s) && *s != '-')
6775 {
6776 errmsg = illegal_char(errbuf, *s);
6777 break;
6778 }
6779 ++s;
6780 }
6781 if (*s++ == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006782 errmsg = N_("E524: Missing colon");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006783 else if (*s == ',' || *s == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006784 errmsg = N_("E525: Zero length string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006785 if (errmsg != NULL)
6786 break;
6787 while (*s && *s != ',')
6788 {
6789 if (*s == '\\' && s[1] != NUL)
6790 ++s;
6791 ++s;
6792 }
6793 s = skip_to_option_part(s);
6794 }
6795 }
6796#endif
6797
6798 /* 'listchars' */
6799 else if (varp == &p_lcs)
6800 {
6801 errmsg = set_chars_option(varp);
6802 }
6803
Bram Moolenaar071d4272004-06-13 20:20:40 +00006804 /* 'fillchars' */
6805 else if (varp == &p_fcs)
6806 {
6807 errmsg = set_chars_option(varp);
6808 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006809
6810#ifdef FEAT_CMDWIN
6811 /* 'cedit' */
6812 else if (varp == &p_cedit)
6813 {
6814 errmsg = check_cedit();
6815 }
6816#endif
6817
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006818 /* 'verbosefile' */
6819 else if (varp == &p_vfile)
6820 {
6821 verbose_stop();
6822 if (*p_vfile != NUL && verbose_open() == FAIL)
6823 errmsg = e_invarg;
6824 }
6825
Bram Moolenaar071d4272004-06-13 20:20:40 +00006826#ifdef FEAT_VIMINFO
6827 /* 'viminfo' */
6828 else if (varp == &p_viminfo)
6829 {
6830 for (s = p_viminfo; *s;)
6831 {
6832 /* Check it's a valid character */
6833 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6834 {
6835 errmsg = illegal_char(errbuf, *s);
6836 break;
6837 }
6838 if (*s == 'n') /* name is always last one */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006839 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006840 else if (*s == 'r') /* skip until next ',' */
6841 {
6842 while (*++s && *s != ',')
6843 ;
6844 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006845 else if (*s == '%')
6846 {
6847 /* optional number */
6848 while (vim_isdigit(*++s))
6849 ;
6850 }
6851 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006852 ++s; /* no extra chars */
6853 else /* must have a number */
6854 {
6855 while (vim_isdigit(*++s))
6856 ;
6857
6858 if (!VIM_ISDIGIT(*(s - 1)))
6859 {
6860 if (errbuf != NULL)
6861 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006862 sprintf(errbuf, _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006863 transchar_byte(*(s - 1)));
6864 errmsg = errbuf;
6865 }
6866 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006867 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006868 break;
6869 }
6870 }
6871 if (*s == ',')
6872 ++s;
6873 else if (*s)
6874 {
6875 if (errbuf != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006876 errmsg = N_("E527: Missing comma");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006877 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006878 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006879 break;
6880 }
6881 }
6882 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006883 errmsg = N_("E528: Must specify a ' value");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006884 }
6885#endif /* FEAT_VIMINFO */
6886
6887 /* terminal options */
6888 else if (istermoption(&options[opt_idx]) && full_screen)
6889 {
6890 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6891 if (varp == &T_CCO)
6892 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006893 int colors = atoi((char *)T_CCO);
6894
6895 /* Only reinitialize colors if t_Co value has really changed to
6896 * avoid expensive reload of colorscheme if t_Co is set to the
6897 * same value multiple times. */
6898 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006899 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006900 t_colors = colors;
6901 if (t_colors <= 1)
6902 {
6903 if (new_value_alloced)
6904 vim_free(T_CCO);
6905 T_CCO = empty_option;
6906 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006907#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6908 if (is_term_win32())
6909 {
6910 swap_tcap();
6911 did_swaptcap = TRUE;
6912 }
6913#endif
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006914 /* We now have a different color setup, initialize it again. */
6915 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006916 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006917 }
6918 ttest(FALSE);
6919 if (varp == &T_ME)
6920 {
6921 out_str(T_ME);
6922 redraw_later(CLEAR);
Bram Moolenaarafde13b2019-04-28 19:46:49 +02006923#if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006924 /* Since t_me has been set, this probably means that the user
6925 * wants to use this as default colors. Need to reset default
6926 * background/foreground colors. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02006927# ifdef VIMDLL
6928 if (!gui.in_use && !gui.starting)
6929# endif
6930 mch_set_normal_colors();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006931#endif
6932 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006933 if (varp == &T_BE && termcap_active)
6934 {
6935 if (*T_BE == NUL)
6936 /* When clearing t_BE we assume the user no longer wants
6937 * bracketed paste, thus disable it by writing t_BD. */
6938 out_str(T_BD);
6939 else
6940 out_str(T_BE);
6941 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006942 }
6943
6944#ifdef FEAT_LINEBREAK
6945 /* 'showbreak' */
6946 else if (varp == &p_sbr)
6947 {
6948 for (s = p_sbr; *s; )
6949 {
6950 if (ptr2cells(s) != 1)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006951 errmsg = N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006952 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006953 }
6954 }
6955#endif
6956
6957#ifdef FEAT_GUI
6958 /* 'guifont' */
6959 else if (varp == &p_guifont)
6960 {
6961 if (gui.in_use)
6962 {
6963 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006964# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006965 /*
6966 * Put up a font dialog and let the user select a new value.
6967 * If this is cancelled go back to the old value but don't
6968 * give an error message.
6969 */
6970 if (STRCMP(p, "*") == 0)
6971 {
6972 p = gui_mch_font_dialog(oldval);
6973
6974 if (new_value_alloced)
6975 free_string_option(p_guifont);
6976
6977 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6978 new_value_alloced = TRUE;
6979 }
6980# endif
6981 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6982 {
6983# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6984 if (STRCMP(p_guifont, "*") == 0)
6985 {
6986 /* Dialog was cancelled: Keep the old value without giving
6987 * an error message. */
6988 if (new_value_alloced)
6989 free_string_option(p_guifont);
6990 p_guifont = vim_strsave(oldval);
6991 new_value_alloced = TRUE;
6992 }
6993 else
6994# endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006995 errmsg = N_("E596: Invalid font(s)");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006996 }
6997 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006998 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006999 }
7000# ifdef FEAT_XFONTSET
7001 else if (varp == &p_guifontset)
7002 {
7003 if (STRCMP(p_guifontset, "*") == 0)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007004 errmsg = N_("E597: can't select fontset");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007005 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007006 errmsg = N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007007 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007008 }
7009# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007010 else if (varp == &p_guifontwide)
7011 {
7012 if (STRCMP(p_guifontwide, "*") == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007013 errmsg = N_("E533: can't select wide font");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007014 else if (gui_get_wide_font() == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007015 errmsg = N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007016 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007017 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007018#endif
7019
7020#ifdef CURSOR_SHAPE
7021 /* 'guicursor' */
7022 else if (varp == &p_guicursor)
7023 errmsg = parse_shape_opt(SHAPE_CURSOR);
7024#endif
7025
7026#ifdef FEAT_MOUSESHAPE
7027 /* 'mouseshape' */
7028 else if (varp == &p_mouseshape)
7029 {
7030 errmsg = parse_shape_opt(SHAPE_MOUSE);
7031 update_mouseshape(-1);
7032 }
7033#endif
7034
7035#ifdef FEAT_PRINTER
7036 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00007037 errmsg = parse_printoptions();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01007038# if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00007039 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00007040 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00007041# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007042#endif
7043
7044#ifdef FEAT_LANGMAP
7045 /* 'langmap' */
7046 else if (varp == &p_langmap)
7047 langmap_set();
7048#endif
7049
7050#ifdef FEAT_LINEBREAK
7051 /* 'breakat' */
7052 else if (varp == &p_breakat)
7053 fill_breakat_flags();
7054#endif
7055
7056#ifdef FEAT_TITLE
7057 /* 'titlestring' and 'iconstring' */
7058 else if (varp == &p_titlestring || varp == &p_iconstring)
7059 {
7060# ifdef FEAT_STL_OPT
7061 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
7062
7063 /* NULL => statusline syntax */
7064 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
7065 stl_syntax |= flagval;
7066 else
7067 stl_syntax &= ~flagval;
7068# endif
Bram Moolenaar84a93082018-06-16 22:58:15 +02007069 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007070 }
7071#endif
7072
7073#ifdef FEAT_GUI
7074 /* 'guioptions' */
7075 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007076 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007077 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007078 redraw_gui_only = TRUE;
7079 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007080#endif
7081
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00007082#if defined(FEAT_GUI_TABLINE)
7083 /* 'guitablabel' */
7084 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007085 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00007086 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007087 redraw_gui_only = TRUE;
7088 }
7089 /* 'guitabtooltip' */
7090 else if (varp == &p_gtt)
7091 {
7092 redraw_gui_only = TRUE;
7093 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00007094#endif
7095
Bram Moolenaar071d4272004-06-13 20:20:40 +00007096#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
7097 /* 'ttymouse' */
7098 else if (varp == &p_ttym)
7099 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007100 /* Switch the mouse off before changing the escape sequences used for
7101 * that. */
7102 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007103 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
7104 errmsg = e_invarg;
7105 else
7106 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00007107 if (termcap_active)
7108 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007109 }
7110#endif
7111
Bram Moolenaar071d4272004-06-13 20:20:40 +00007112 /* 'selection' */
7113 else if (varp == &p_sel)
7114 {
7115 if (*p_sel == NUL
7116 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
7117 errmsg = e_invarg;
7118 }
7119
7120 /* 'selectmode' */
7121 else if (varp == &p_slm)
7122 {
7123 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
7124 errmsg = e_invarg;
7125 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007126
7127#ifdef FEAT_BROWSE
7128 /* 'browsedir' */
7129 else if (varp == &p_bsdir)
7130 {
7131 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7132 && !mch_isdir(p_bsdir))
7133 errmsg = e_invarg;
7134 }
7135#endif
7136
Bram Moolenaar071d4272004-06-13 20:20:40 +00007137 /* 'keymodel' */
7138 else if (varp == &p_km)
7139 {
7140 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7141 errmsg = e_invarg;
7142 else
7143 {
7144 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7145 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7146 }
7147 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007148
7149 /* 'mousemodel' */
7150 else if (varp == &p_mousem)
7151 {
7152 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7153 errmsg = e_invarg;
7154#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7155 else if (*p_mousem != *oldval)
7156 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7157 * to create or delete the popup menus. */
7158 gui_motif_update_mousemodel(root_menu);
7159#endif
7160 }
7161
7162 /* 'switchbuf' */
7163 else if (varp == &p_swb)
7164 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007165 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007166 errmsg = e_invarg;
7167 }
7168
7169 /* 'debug' */
7170 else if (varp == &p_debug)
7171 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007172 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007173 errmsg = e_invarg;
7174 }
7175
7176 /* 'display' */
7177 else if (varp == &p_dy)
7178 {
7179 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7180 errmsg = e_invarg;
7181 else
7182 (void)init_chartab();
7183
7184 }
7185
Bram Moolenaar071d4272004-06-13 20:20:40 +00007186 /* 'eadirection' */
7187 else if (varp == &p_ead)
7188 {
7189 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7190 errmsg = e_invarg;
7191 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007192
7193#ifdef FEAT_CLIPBOARD
7194 /* 'clipboard' */
7195 else if (varp == &p_cb)
7196 errmsg = check_clipboard_option();
7197#endif
7198
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007199#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007200 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7201 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007202 else if (varp == &(curwin->w_s->b_p_spl)
7203 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007204 {
Bram Moolenaar862f1e12019-04-10 22:33:41 +02007205 int is_spellfile = varp == &(curwin->w_s->b_p_spf);
7206
7207 if ((is_spellfile && !valid_spellfile(*varp))
7208 || (!is_spellfile && !valid_spellang(*varp)))
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02007209 errmsg = e_invarg;
7210 else
Bram Moolenaar862f1e12019-04-10 22:33:41 +02007211 errmsg = did_set_spell_option(is_spellfile);
Bram Moolenaar217ad922005-03-20 22:37:15 +00007212 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007213 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007214 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007215 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007216 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007217 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007218 /* 'spellsuggest' */
7219 else if (varp == &p_sps)
7220 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007221 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007222 errmsg = e_invarg;
7223 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007224 /* 'mkspellmem' */
7225 else if (varp == &p_msm)
7226 {
7227 if (spell_check_msm() != OK)
7228 errmsg = e_invarg;
7229 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007230#endif
7231
Bram Moolenaar071d4272004-06-13 20:20:40 +00007232 /* When 'bufhidden' is set, check for valid value. */
7233 else if (gvarp == &p_bh)
7234 {
7235 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7236 errmsg = e_invarg;
7237 }
7238
7239 /* When 'buftype' is set, check for valid value. */
7240 else if (gvarp == &p_bt)
7241 {
7242 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7243 errmsg = e_invarg;
7244 else
7245 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007246 if (curwin->w_status_height)
7247 {
7248 curwin->w_redr_status = TRUE;
7249 redraw_later(VALID);
7250 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007251 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007252#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007253 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007254#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007255 }
7256 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007257
7258#ifdef FEAT_STL_OPT
7259 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007260 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007261 {
7262 int wid;
7263
7264 if (varp == &p_ruf) /* reset ru_wid first */
7265 ru_wid = 0;
7266 s = *varp;
7267 if (varp == &p_ruf && *s == '%')
7268 {
7269 /* set ru_wid if 'ruf' starts with "%99(" */
7270 if (*++s == '-') /* ignore a '-' */
7271 s++;
7272 wid = getdigits(&s);
7273 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7274 ru_wid = wid;
7275 else
7276 errmsg = check_stl_option(p_ruf);
7277 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007278 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007279 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007280 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007281 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007282 comp_col();
7283 }
7284#endif
7285
7286#ifdef FEAT_INS_EXPAND
7287 /* check if it is a valid value for 'complete' -- Acevedo */
7288 else if (gvarp == &p_cpt)
7289 {
7290 for (s = *varp; *s;)
7291 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007292 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007293 s++;
7294 if (!*s)
7295 break;
7296 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7297 {
7298 errmsg = illegal_char(errbuf, *s);
7299 break;
7300 }
7301 if (*++s != NUL && *s != ',' && *s != ' ')
7302 {
7303 if (s[-1] == 'k' || s[-1] == 's')
7304 {
7305 /* skip optional filename after 'k' and 's' */
7306 while (*s && *s != ',' && *s != ' ')
7307 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007308 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007309 ++s;
7310 ++s;
7311 }
7312 }
7313 else
7314 {
7315 if (errbuf != NULL)
7316 {
7317 sprintf((char *)errbuf,
7318 _("E535: Illegal character after <%c>"),
7319 *--s);
7320 errmsg = errbuf;
7321 }
7322 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007323 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00007324 break;
7325 }
7326 }
7327 }
7328 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007329
7330 /* 'completeopt' */
7331 else if (varp == &p_cot)
7332 {
7333 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7334 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007335 else
7336 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007337 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007338#endif /* FEAT_INS_EXPAND */
7339
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007340#ifdef FEAT_SIGNS
7341 /* 'signcolumn' */
7342 else if (varp == &curwin->w_p_scl)
7343 {
7344 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7345 errmsg = e_invarg;
7346 }
7347#endif
7348
Bram Moolenaar071d4272004-06-13 20:20:40 +00007349
Bram Moolenaar4f974752019-02-17 17:44:42 +01007350#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007351 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007352 else if (varp == &p_toolbar)
7353 {
7354 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7355 &toolbar_flags, TRUE) != OK)
7356 errmsg = e_invarg;
7357 else
7358 {
7359 out_flush();
7360 gui_mch_show_toolbar((toolbar_flags &
7361 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7362 }
7363 }
7364#endif
7365
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007366#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007367 /* 'toolbariconsize': GTK+ 2 only */
7368 else if (varp == &p_tbis)
7369 {
7370 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7371 errmsg = e_invarg;
7372 else
7373 {
7374 out_flush();
7375 gui_mch_show_toolbar((toolbar_flags &
7376 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7377 }
7378 }
7379#endif
7380
7381 /* 'pastetoggle': translate key codes like in a mapping */
7382 else if (varp == &p_pt)
7383 {
7384 if (*p_pt)
7385 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007386 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007387 if (p != NULL)
7388 {
7389 if (new_value_alloced)
7390 free_string_option(p_pt);
7391 p_pt = p;
7392 new_value_alloced = TRUE;
7393 }
7394 }
7395 }
7396
7397 /* 'backspace' */
7398 else if (varp == &p_bs)
7399 {
7400 if (VIM_ISDIGIT(*p_bs))
7401 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007402 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007403 errmsg = e_invarg;
7404 }
7405 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7406 errmsg = e_invarg;
7407 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007408 else if (varp == &p_bo)
7409 {
7410 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7411 errmsg = e_invarg;
7412 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007413
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007414 /* 'tagcase' */
7415 else if (gvarp == &p_tc)
7416 {
7417 unsigned int *flags;
7418
7419 if (opt_flags & OPT_LOCAL)
7420 {
7421 p = curbuf->b_p_tc;
7422 flags = &curbuf->b_tc_flags;
7423 }
7424 else
7425 {
7426 p = p_tc;
7427 flags = &tc_flags;
7428 }
7429
7430 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7431 /* make the local value empty: use the global value */
7432 *flags = 0;
7433 else if (*p == NUL
7434 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7435 errmsg = e_invarg;
7436 }
7437
Bram Moolenaar071d4272004-06-13 20:20:40 +00007438 /* 'casemap' */
7439 else if (varp == &p_cmp)
7440 {
7441 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7442 errmsg = e_invarg;
7443 }
7444
7445#ifdef FEAT_DIFF
7446 /* 'diffopt' */
7447 else if (varp == &p_dip)
7448 {
7449 if (diffopt_changed() == FAIL)
7450 errmsg = e_invarg;
7451 }
7452#endif
7453
7454#ifdef FEAT_FOLDING
7455 /* 'foldmethod' */
7456 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7457 {
7458 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7459 || *curwin->w_p_fdm == NUL)
7460 errmsg = e_invarg;
7461 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007462 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007463 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007464 if (foldmethodIsDiff(curwin))
7465 newFoldLevel();
7466 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007467 }
7468# ifdef FEAT_EVAL
7469 /* 'foldexpr' */
7470 else if (varp == &curwin->w_p_fde)
7471 {
7472 if (foldmethodIsExpr(curwin))
7473 foldUpdateAll(curwin);
7474 }
7475# endif
7476 /* 'foldmarker' */
7477 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7478 {
7479 p = vim_strchr(*varp, ',');
7480 if (p == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007481 errmsg = N_("E536: comma required");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007482 else if (p == *varp || p[1] == NUL)
7483 errmsg = e_invarg;
7484 else if (foldmethodIsMarker(curwin))
7485 foldUpdateAll(curwin);
7486 }
7487 /* 'commentstring' */
7488 else if (gvarp == &p_cms)
7489 {
7490 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007491 errmsg = N_("E537: 'commentstring' must be empty or contain %s");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007492 }
7493 /* 'foldopen' */
7494 else if (varp == &p_fdo)
7495 {
7496 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7497 errmsg = e_invarg;
7498 }
7499 /* 'foldclose' */
7500 else if (varp == &p_fcl)
7501 {
7502 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7503 errmsg = e_invarg;
7504 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007505 /* 'foldignore' */
7506 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7507 {
7508 if (foldmethodIsIndent(curwin))
7509 foldUpdateAll(curwin);
7510 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007511#endif
7512
Bram Moolenaar071d4272004-06-13 20:20:40 +00007513 /* 'virtualedit' */
7514 else if (varp == &p_ve)
7515 {
7516 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7517 errmsg = e_invarg;
7518 else if (STRCMP(p_ve, oldval) != 0)
7519 {
7520 /* Recompute cursor position in case the new 've' setting
7521 * changes something. */
7522 validate_virtcol();
7523 coladvance(curwin->w_virtcol);
7524 }
7525 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007526
7527#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7528 else if (varp == &p_csqf)
7529 {
7530 if (p_csqf != NULL)
7531 {
7532 p = p_csqf;
7533 while (*p != NUL)
7534 {
7535 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7536 || p[1] == NUL
7537 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7538 || (p[2] != NUL && p[2] != ','))
7539 {
7540 errmsg = e_invarg;
7541 break;
7542 }
7543 else if (p[2] == NUL)
7544 break;
7545 else
7546 p += 3;
7547 }
7548 }
7549 }
7550#endif
7551
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007552#ifdef FEAT_CINDENT
7553 /* 'cinoptions' */
7554 else if (gvarp == &p_cino)
7555 {
7556 /* TODO: recognize errors */
7557 parse_cino(curbuf);
7558 }
7559#endif
7560
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007561#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007562 /* 'renderoptions' */
Bram Moolenaar3767c6e2017-12-05 16:57:56 +01007563 else if (varp == &p_rop)
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007564 {
7565 if (!gui_mch_set_rendering_options(p_rop))
7566 errmsg = e_invarg;
7567 }
7568#endif
7569
Bram Moolenaard0b51382016-11-04 15:23:45 +01007570 else if (gvarp == &p_ft)
7571 {
7572 if (!valid_filetype(*varp))
7573 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007574 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007575 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007576 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007577
7578 // Since we check the value, there is no need to set P_INSECURE,
7579 // even when the value comes from a modeline.
7580 *value_checked = TRUE;
7581 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007582 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007583
7584#ifdef FEAT_SYN_HL
7585 else if (gvarp == &p_syn)
7586 {
7587 if (!valid_filetype(*varp))
7588 errmsg = e_invarg;
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007589 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007590 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007591 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007592
7593 // Since we check the value, there is no need to set P_INSECURE,
7594 // even when the value comes from a modeline.
7595 *value_checked = TRUE;
7596 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007597 }
7598#endif
7599
Bram Moolenaar825680f2017-07-22 17:04:02 +02007600#ifdef FEAT_TERMINAL
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007601 // 'termwinkey'
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007602 else if (varp == &curwin->w_p_twk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007603 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007604 if (*curwin->w_p_twk != NUL
7605 && string_to_key(curwin->w_p_twk, TRUE) == 0)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007606 errmsg = e_invarg;
7607 }
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007608 // 'termwinsize'
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007609 else if (varp == &curwin->w_p_tws)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007610 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007611 if (*curwin->w_p_tws != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007612 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007613 p = skipdigits(curwin->w_p_tws);
7614 if (p == curwin->w_p_tws
Bram Moolenaar498c2562018-04-15 23:45:15 +02007615 || (*p != 'x' && *p != '*')
7616 || *skipdigits(p + 1) != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007617 errmsg = e_invarg;
7618 }
7619 }
Bram Moolenaar4f974752019-02-17 17:44:42 +01007620# if defined(MSWIN)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007621 // 'termwintype'
7622 else if (varp == &p_twt)
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007623 {
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007624 if (check_opt_strings(*varp, p_twt_values, FALSE) != OK)
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007625 errmsg = e_invarg;
7626 }
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007627# endif
Bram Moolenaar825680f2017-07-22 17:04:02 +02007628#endif
7629
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007630#ifdef FEAT_VARTABS
7631 /* 'varsofttabstop' */
7632 else if (varp == &(curbuf->b_p_vsts))
7633 {
7634 char_u *cp;
7635
7636 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7637 {
7638 if (curbuf->b_p_vsts_array)
7639 {
7640 vim_free(curbuf->b_p_vsts_array);
7641 curbuf->b_p_vsts_array = 0;
7642 }
7643 }
7644 else
7645 {
7646 for (cp = *varp; *cp; ++cp)
7647 {
7648 if (vim_isdigit(*cp))
7649 continue;
7650 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7651 continue;
7652 errmsg = e_invarg;
7653 break;
7654 }
7655 if (errmsg == NULL)
7656 {
7657 int *oldarray = curbuf->b_p_vsts_array;
7658 if (tabstop_set(*varp, &(curbuf->b_p_vsts_array)))
7659 {
7660 if (oldarray)
7661 vim_free(oldarray);
7662 }
7663 else
7664 errmsg = e_invarg;
7665 }
7666 }
7667 }
7668
7669 /* 'vartabstop' */
7670 else if (varp == &(curbuf->b_p_vts))
7671 {
7672 char_u *cp;
7673
7674 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7675 {
7676 if (curbuf->b_p_vts_array)
7677 {
7678 vim_free(curbuf->b_p_vts_array);
7679 curbuf->b_p_vts_array = NULL;
7680 }
7681 }
7682 else
7683 {
7684 for (cp = *varp; *cp; ++cp)
7685 {
7686 if (vim_isdigit(*cp))
7687 continue;
7688 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7689 continue;
7690 errmsg = e_invarg;
7691 break;
7692 }
7693 if (errmsg == NULL)
7694 {
7695 int *oldarray = curbuf->b_p_vts_array;
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007696
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007697 if (tabstop_set(*varp, &(curbuf->b_p_vts_array)))
7698 {
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007699 vim_free(oldarray);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007700#ifdef FEAT_FOLDING
7701 if (foldmethodIsIndent(curwin))
7702 foldUpdateAll(curwin);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007703#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007704 }
7705 else
7706 errmsg = e_invarg;
7707 }
7708 }
7709 }
7710#endif
7711
Bram Moolenaar071d4272004-06-13 20:20:40 +00007712 /* Options that are a list of flags. */
7713 else
7714 {
7715 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007716 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007717 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007718 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007719 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007720 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007721 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007722 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007723 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007724#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007725 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007726 p = (char_u *)COCU_ALL;
7727#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007728 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007729 {
7730#ifdef FEAT_MOUSE
7731 p = (char_u *)MOUSE_ALL;
7732#else
7733 if (*p_mouse != NUL)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007734 errmsg = N_("E538: No mouse support");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007735#endif
7736 }
7737#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007738 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007739 p = (char_u *)GO_ALL;
7740#endif
7741 if (p != NULL)
7742 {
7743 for (s = *varp; *s; ++s)
7744 if (vim_strchr(p, *s) == NULL)
7745 {
7746 errmsg = illegal_char(errbuf, *s);
7747 break;
7748 }
7749 }
7750 }
7751
7752 /*
7753 * If error detected, restore the previous value.
7754 */
7755 if (errmsg != NULL)
7756 {
7757 if (new_value_alloced)
7758 free_string_option(*varp);
7759 *varp = oldval;
7760 /*
7761 * When resetting some values, need to act on it.
7762 */
7763 if (did_chartab)
7764 (void)init_chartab();
7765 if (varp == &p_hl)
7766 (void)highlight_changed();
7767 }
7768 else
7769 {
7770#ifdef FEAT_EVAL
7771 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02007772 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007773#endif
7774 /*
7775 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007776 * Use "free_oldval", because recursiveness may change the flags under
7777 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007778 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007779 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007780 free_string_option(oldval);
7781 if (new_value_alloced)
7782 options[opt_idx].flags |= P_ALLOCED;
7783 else
7784 options[opt_idx].flags &= ~P_ALLOCED;
7785
7786 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007787 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007788 {
7789 /* global option with local value set to use global value; free
7790 * the local value and make it empty */
7791 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7792 free_string_option(*(char_u **)p);
7793 *(char_u **)p = empty_option;
7794 }
7795
7796 /* May set global value for local option. */
7797 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7798 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007799
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007800 /*
7801 * Trigger the autocommand only after setting the flags.
7802 */
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007803#ifdef FEAT_SYN_HL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007804 /* When 'syntax' is set, load the syntax of that name */
7805 if (varp == &(curbuf->b_p_syn))
7806 {
Bram Moolenaara5616b02018-06-17 19:08:30 +02007807 static int syn_recursive = 0;
7808
7809 ++syn_recursive;
7810 // Only pass TRUE for "force" when the value changed or not used
7811 // recursively, to avoid endless recurrence.
7812 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname,
7813 value_changed || syn_recursive == 1, curbuf);
7814 --syn_recursive;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007815 }
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007816#endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007817 else if (varp == &(curbuf->b_p_ft))
7818 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007819 /* 'filetype' is set, trigger the FileType autocommand.
7820 * Skip this when called from a modeline and the filetype was
Bram Moolenaara5616b02018-06-17 19:08:30 +02007821 * already set to this value. */
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007822 if (!(opt_flags & OPT_MODELINE) || value_changed)
Bram Moolenaar90492982017-06-22 14:16:31 +02007823 {
Bram Moolenaar916a8182018-11-25 02:18:29 +01007824 static int ft_recursive = 0;
7825 int secure_save = secure;
7826
7827 // Reset the secure flag, since the value of 'filetype' has
7828 // been checked to be safe.
7829 secure = 0;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007830
7831 ++ft_recursive;
Bram Moolenaar90492982017-06-22 14:16:31 +02007832 did_filetype = TRUE;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007833 // Only pass TRUE for "force" when the value changed or not
7834 // used recursively, to avoid endless recurrence.
7835 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname,
7836 value_changed || ft_recursive == 1, curbuf);
7837 --ft_recursive;
Bram Moolenaar163095f2017-07-09 15:41:53 +02007838 /* Just in case the old "curbuf" is now invalid. */
7839 if (varp != &(curbuf->b_p_ft))
7840 varp = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007841
7842 secure = secure_save;
Bram Moolenaar90492982017-06-22 14:16:31 +02007843 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007844 }
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007845#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007846 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007847 {
7848 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007849 char_u *q = curwin->w_s->b_p_spl;
7850
7851 /* Skip the first name if it is "cjk". */
7852 if (STRNCMP(q, "cjk,", 4) == 0)
7853 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007854
7855 /*
7856 * Source the spell/LANG.vim in 'runtimepath'.
7857 * They could set 'spellcapcheck' depending on the language.
7858 * Use the first name in 'spelllang' up to '_region' or
7859 * '.encoding'.
7860 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007861 for (p = q; *p != NUL; ++p)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01007862 if (!ASCII_ISALNUM(*p) && *p != '-')
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007863 break;
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007864 if (p > q)
7865 {
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02007866 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
7867 (int)(p - q), q);
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007868 source_runtime(fname, DIP_ALL);
7869 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007870 }
7871#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007872 }
7873
7874#ifdef FEAT_MOUSE
7875 if (varp == &p_mouse)
7876 {
7877# ifdef FEAT_MOUSE_TTY
7878 if (*p_mouse == NUL)
7879 mch_setmouse(FALSE); /* switch mouse off */
7880 else
7881# endif
7882 setmouse(); /* in case 'mouse' changed */
7883 }
7884#endif
7885
Bram Moolenaar913077c2012-03-28 19:59:04 +02007886 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007887 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007888 curwin->w_set_curswant = TRUE;
7889
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007890#ifdef FEAT_GUI
7891 /* check redraw when it's not a GUI option or the GUI is active. */
7892 if (!redraw_gui_only || gui.in_use)
7893#endif
7894 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007895
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007896#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
7897 if (did_swaptcap)
7898 {
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007899 set_termname((char_u *)"win32");
7900 init_highlight(TRUE, FALSE);
7901 }
7902#endif
7903
Bram Moolenaar071d4272004-06-13 20:20:40 +00007904 return errmsg;
7905}
7906
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007907#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007908/*
7909 * Simple int comparison function for use with qsort()
7910 */
7911 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007912int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007913{
7914 return *(const int *)a - *(const int *)b;
7915}
7916
7917/*
7918 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7919 * Returns error message, NULL if it's OK.
7920 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007921 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007922check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007923{
7924 char_u *s;
7925 int col;
7926 int count = 0;
7927 int color_cols[256];
7928 int i;
7929 int j = 0;
7930
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007931 if (wp->w_buffer == NULL)
7932 return NULL; /* buffer was closed */
7933
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007934 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007935 {
7936 if (*s == '-' || *s == '+')
7937 {
7938 /* -N and +N: add to 'textwidth' */
7939 col = (*s == '-') ? -1 : 1;
7940 ++s;
7941 if (!VIM_ISDIGIT(*s))
7942 return e_invarg;
7943 col = col * getdigits(&s);
7944 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007945 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007946 col += wp->w_buffer->b_p_tw;
7947 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007948 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007949 }
7950 else if (VIM_ISDIGIT(*s))
7951 col = getdigits(&s);
7952 else
7953 return e_invarg;
7954 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007955skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007956 if (*s == NUL)
7957 break;
7958 if (*s != ',')
7959 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007960 if (*++s == NUL)
7961 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007962 }
7963
7964 vim_free(wp->w_p_cc_cols);
7965 if (count == 0)
7966 wp->w_p_cc_cols = NULL;
7967 else
7968 {
Bram Moolenaarc799fe22019-05-28 23:08:19 +02007969 wp->w_p_cc_cols = ALLOC_MULT(int, count + 1);
Bram Moolenaar1a384422010-07-14 19:53:30 +02007970 if (wp->w_p_cc_cols != NULL)
7971 {
7972 /* sort the columns for faster usage on screen redraw inside
7973 * win_line() */
7974 qsort(color_cols, count, sizeof(int), int_cmp);
7975
7976 for (i = 0; i < count; ++i)
7977 /* skip duplicates */
7978 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7979 wp->w_p_cc_cols[j++] = color_cols[i];
7980 wp->w_p_cc_cols[j] = -1; /* end marker */
7981 }
7982 }
7983
7984 return NULL; /* no error */
7985}
7986#endif
7987
Bram Moolenaar071d4272004-06-13 20:20:40 +00007988/*
7989 * Handle setting 'listchars' or 'fillchars'.
7990 * Returns error message, NULL if it's OK.
7991 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007992 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007993set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007994{
7995 int round, i, len, entries;
7996 char_u *p, *s;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007997 int c1 = 0, c2 = 0, c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007998 struct charstab
7999 {
8000 int *cp;
8001 char *name;
8002 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00008003 static struct charstab filltab[] =
8004 {
8005 {&fill_stl, "stl"},
8006 {&fill_stlnc, "stlnc"},
8007 {&fill_vert, "vert"},
8008 {&fill_fold, "fold"},
8009 {&fill_diff, "diff"},
8010 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00008011 static struct charstab lcstab[] =
8012 {
8013 {&lcs_eol, "eol"},
8014 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008015 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00008016 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02008017 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00008018 {&lcs_tab2, "tab"},
8019 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02008020#ifdef FEAT_CONCEAL
8021 {&lcs_conceal, "conceal"},
8022#else
8023 {NULL, "conceal"},
8024#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008025 };
8026 struct charstab *tab;
8027
Bram Moolenaar071d4272004-06-13 20:20:40 +00008028 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008029 {
8030 tab = lcstab;
8031 entries = sizeof(lcstab) / sizeof(struct charstab);
8032 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008033 else
8034 {
8035 tab = filltab;
8036 entries = sizeof(filltab) / sizeof(struct charstab);
8037 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008038
8039 /* first round: check for valid value, second round: assign values */
8040 for (round = 0; round <= 1; ++round)
8041 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008042 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008043 {
8044 /* After checking that the value is valid: set defaults: space for
8045 * 'fillchars', NUL for 'listchars' */
8046 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008047 if (tab[i].cp != NULL)
8048 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar83a52172019-01-16 22:41:54 +01008049
Bram Moolenaar071d4272004-06-13 20:20:40 +00008050 if (varp == &p_lcs)
Bram Moolenaar83a52172019-01-16 22:41:54 +01008051 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008052 lcs_tab1 = NUL;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008053 lcs_tab3 = NUL;
8054 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008055 else
8056 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008057 }
8058 p = *varp;
8059 while (*p)
8060 {
8061 for (i = 0; i < entries; ++i)
8062 {
8063 len = (int)STRLEN(tab[i].name);
8064 if (STRNCMP(p, tab[i].name, len) == 0
8065 && p[len] == ':'
8066 && p[len + 1] != NUL)
8067 {
Bram Moolenaar2c519cf2019-03-21 21:45:34 +01008068 c2 = c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008069 s = p + len + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008070 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00008071 if (mb_char2cells(c1) > 1)
8072 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008073 if (tab[i].cp == &lcs_tab2)
8074 {
8075 if (*s == NUL)
8076 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008077 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00008078 if (mb_char2cells(c2) > 1)
8079 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008080 if (!(*s == ',' || *s == NUL))
8081 {
Bram Moolenaar83a52172019-01-16 22:41:54 +01008082 c3 = mb_ptr2char_adv(&s);
8083 if (mb_char2cells(c3) > 1)
8084 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008085 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008086 }
Bram Moolenaar83a52172019-01-16 22:41:54 +01008087
Bram Moolenaar071d4272004-06-13 20:20:40 +00008088 if (*s == ',' || *s == NUL)
8089 {
8090 if (round)
8091 {
8092 if (tab[i].cp == &lcs_tab2)
8093 {
8094 lcs_tab1 = c1;
8095 lcs_tab2 = c2;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008096 lcs_tab3 = c3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008097 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008098 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008099 *(tab[i].cp) = c1;
8100
8101 }
8102 p = s;
8103 break;
8104 }
8105 }
8106 }
8107
8108 if (i == entries)
8109 return e_invarg;
8110 if (*p == ',')
8111 ++p;
8112 }
8113 }
8114
8115 return NULL; /* no error */
8116}
8117
8118#ifdef FEAT_STL_OPT
8119/*
8120 * Check validity of options with the 'statusline' format.
8121 * Return error message or NULL.
8122 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008123 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008124check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008125{
8126 int itemcnt = 0;
8127 int groupdepth = 0;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008128 static char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00008129
8130 while (*s && itemcnt < STL_MAX_ITEM)
8131 {
8132 /* Check for valid keys after % sequences */
8133 while (*s && *s != '%')
8134 s++;
8135 if (!*s)
8136 break;
8137 s++;
8138 if (*s != '%' && *s != ')')
8139 ++itemcnt;
8140 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
8141 {
8142 s++;
8143 continue;
8144 }
8145 if (*s == ')')
8146 {
8147 s++;
8148 if (--groupdepth < 0)
8149 break;
8150 continue;
8151 }
8152 if (*s == '-')
8153 s++;
8154 while (VIM_ISDIGIT(*s))
8155 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00008156 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008157 continue;
8158 if (*s == '.')
8159 {
8160 s++;
8161 while (*s && VIM_ISDIGIT(*s))
8162 s++;
8163 }
8164 if (*s == '(')
8165 {
8166 groupdepth++;
8167 continue;
8168 }
8169 if (vim_strchr(STL_ALL, *s) == NULL)
8170 {
8171 return illegal_char(errbuf, *s);
8172 }
8173 if (*s == '{')
8174 {
8175 s++;
8176 while (*s != '}' && *s)
8177 s++;
8178 if (*s != '}')
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008179 return N_("E540: Unclosed expression sequence");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008180 }
8181 }
8182 if (itemcnt >= STL_MAX_ITEM)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008183 return N_("E541: too many items");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008184 if (groupdepth != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008185 return N_("E542: unbalanced groups");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008186 return NULL;
8187}
8188#endif
8189
8190#ifdef FEAT_CLIPBOARD
8191/*
8192 * Extract the items in the 'clipboard' option and set global values.
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008193 * Return an error message or NULL for success.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008194 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008195 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008196check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008197{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008198 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008199 int new_autoselect_star = FALSE;
8200 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008201 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008202 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008203 regprog_T *new_exclude_prog = NULL;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008204 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008205 char_u *p;
8206
8207 for (p = p_cb; *p != NUL; )
8208 {
8209 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
8210 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008211 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008212 p += 7;
8213 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02008214 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008215 && (p[11] == ',' || p[11] == NUL))
8216 {
8217 new_unnamed |= CLIP_UNNAMED_PLUS;
8218 p += 11;
8219 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008220 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008221 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008222 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02008223 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008224 p += 10;
8225 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02008226 else if (STRNCMP(p, "autoselectplus", 14) == 0
8227 && (p[14] == ',' || p[14] == NUL))
8228 {
8229 new_autoselect_plus = TRUE;
8230 p += 14;
8231 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008232 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008233 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008234 {
8235 new_autoselectml = TRUE;
8236 p += 12;
8237 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008238 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
8239 {
8240 new_html = TRUE;
8241 p += 4;
8242 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008243 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
8244 {
8245 p += 8;
8246 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
8247 if (new_exclude_prog == NULL)
8248 errmsg = e_invarg;
8249 break;
8250 }
8251 else
8252 {
8253 errmsg = e_invarg;
8254 break;
8255 }
8256 if (*p == ',')
8257 ++p;
8258 }
8259 if (errmsg == NULL)
8260 {
8261 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008262 clip_autoselect_star = new_autoselect_star;
8263 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008264 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008265 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008266 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008267 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008268#ifdef FEAT_GUI_GTK
8269 if (gui.in_use)
8270 {
8271 gui_gtk_set_selection_targets();
8272 gui_gtk_set_dnd_targets();
8273 }
8274#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008275 }
8276 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008277 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008278
8279 return errmsg;
8280}
8281#endif
8282
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008283#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008284/*
8285 * Handle side effects of setting 'spell'.
8286 * Return an error message or NULL for success.
8287 */
8288 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008289did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008290{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008291 char *errmsg = NULL;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008292 win_T *wp;
8293 int l;
8294
8295 if (is_spellfile)
8296 {
8297 l = (int)STRLEN(curwin->w_s->b_p_spf);
8298 if (l > 0 && (l < 4
8299 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8300 errmsg = e_invarg;
8301 }
8302
8303 if (errmsg == NULL)
8304 {
8305 FOR_ALL_WINDOWS(wp)
8306 if (wp->w_buffer == curbuf && wp->w_p_spell)
8307 {
8308 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008309 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008310 }
8311 }
8312 return errmsg;
8313}
8314
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008315/*
8316 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8317 * Return error message when failed, NULL when OK.
8318 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008319 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008320compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008321{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008322 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008323 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008324
Bram Moolenaar860cae12010-06-05 23:22:07 +02008325 if (*synblock->b_p_spc == NUL)
8326 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008327 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008328 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008329 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008330 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008331 if (re != NULL)
8332 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008333 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008334 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008335 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008336 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008337 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008338 return e_invarg;
8339 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008340 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008341 }
8342
Bram Moolenaar473de612013-06-08 18:19:48 +02008343 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008344 return NULL;
8345}
8346#endif
8347
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008348#if defined(FEAT_EVAL) || defined(PROTO)
8349/*
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008350 * Set the script_ctx for an option, taking care of setting the buffer- or
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008351 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008352 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008353 static void
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008354set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008355{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008356 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8357 int indir = (int)options[opt_idx].indir;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008358 sctx_T new_script_ctx = script_ctx;
8359
8360 new_script_ctx.sc_lnum += sourcing_lnum;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008361
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008362 /* Remember where the option was set. For local options need to do that
8363 * in the buffer or window structure. */
8364 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008365 options[opt_idx].script_ctx = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008366 if (both || (opt_flags & OPT_LOCAL))
8367 {
8368 if (indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008369 curbuf->b_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008370 else if (indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008371 curwin->w_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008372 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008373}
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02008374
8375/*
8376 * Set the script_ctx for a termcap option.
8377 * "name" must be the two character code, e.g. "RV".
8378 * When "name" is NULL use "opt_idx".
8379 */
8380 void
8381set_term_option_sctx_idx(char *name, int opt_idx)
8382{
8383 char_u buf[5];
8384 int idx;
8385
8386 if (name == NULL)
8387 idx = opt_idx;
8388 else
8389 {
8390 buf[0] = 't';
8391 buf[1] = '_';
8392 buf[2] = name[0];
8393 buf[3] = name[1];
8394 buf[4] = 0;
8395 idx = findoption(buf);
8396 }
8397 if (idx >= 0)
8398 set_option_sctx_idx(idx, OPT_GLOBAL, current_sctx);
8399}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008400#endif
8401
Bram Moolenaar071d4272004-06-13 20:20:40 +00008402/*
8403 * Set the value of a boolean option, and take care of side effects.
8404 * Returns NULL for success, or an error message for an error.
8405 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008406 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008407set_bool_option(
8408 int opt_idx, /* index in options[] table */
8409 char_u *varp, /* pointer to the option variable */
8410 int value, /* new value */
8411 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008412{
8413 int old_value = *(int *)varp;
8414
Bram Moolenaar071d4272004-06-13 20:20:40 +00008415 /* Disallow changing some options from secure mode */
8416 if ((secure
8417#ifdef HAVE_SANDBOX
8418 || sandbox != 0
8419#endif
8420 ) && (options[opt_idx].flags & P_SECURE))
8421 return e_secure;
8422
8423 *(int *)varp = value; /* set the new value */
8424#ifdef FEAT_EVAL
8425 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008426 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008427#endif
8428
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008429#ifdef FEAT_GUI
8430 need_mouse_correct = TRUE;
8431#endif
8432
Bram Moolenaar071d4272004-06-13 20:20:40 +00008433 /* May set global value for local option. */
8434 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8435 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8436
8437 /*
8438 * Handle side effects of changing a bool option.
8439 */
8440
8441 /* 'compatible' */
8442 if ((int *)varp == &p_cp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008443 compatible_set();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008444
Bram Moolenaar920694c2016-08-21 17:45:02 +02008445#ifdef FEAT_LANGMAP
8446 if ((int *)varp == &p_lrm)
8447 /* 'langremap' -> !'langnoremap' */
8448 p_lnr = !p_lrm;
8449 else if ((int *)varp == &p_lnr)
8450 /* 'langnoremap' -> !'langremap' */
8451 p_lrm = !p_lnr;
8452#endif
8453
Bram Moolenaar8c63e0e2018-09-25 22:17:54 +02008454#ifdef FEAT_SYN_HL
8455 else if ((int *)varp == &curwin->w_p_cul && !value && old_value)
8456 reset_cursorline();
8457#endif
8458
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008459#ifdef FEAT_PERSISTENT_UNDO
8460 /* 'undofile' */
8461 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8462 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008463 /* Only take action when the option was set. When reset we do not
8464 * delete the undo file, the option may be set again without making
8465 * any changes in between. */
8466 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008467 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008468 char_u hash[UNDO_HASH_SIZE];
8469 buf_T *save_curbuf = curbuf;
8470
Bram Moolenaar29323592016-07-24 22:04:11 +02008471 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008472 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008473 /* When 'undofile' is set globally: for every buffer, otherwise
8474 * only for the current buffer: Try to read in the undofile,
8475 * if one exists, the buffer wasn't changed and the buffer was
8476 * loaded */
8477 if ((curbuf == save_curbuf
8478 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8479 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8480 {
8481 u_compute_hash(hash);
8482 u_read_undo(NULL, hash, curbuf->b_fname);
8483 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008484 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008485 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008486 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008487 }
8488#endif
8489
Bram Moolenaar071d4272004-06-13 20:20:40 +00008490 else if ((int *)varp == &curbuf->b_p_ro)
8491 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008492 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008493 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8494 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008495
8496 /* when 'readonly' is set may give W10 again */
8497 if (curbuf->b_p_ro)
8498 curbuf->b_did_warn = FALSE;
8499
Bram Moolenaar071d4272004-06-13 20:20:40 +00008500#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008501 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008502#endif
8503 }
8504
Bram Moolenaar9c449722010-07-20 18:44:27 +02008505#ifdef FEAT_GUI
8506 else if ((int *)varp == &p_mh)
8507 {
8508 if (!p_mh)
8509 gui_mch_mousehide(FALSE);
8510 }
8511#endif
8512
Bram Moolenaara539df02010-08-01 14:35:05 +02008513 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008514 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008515 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008516# ifdef FEAT_TERMINAL
8517 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaard7db27b2018-03-07 23:02:33 +01008518 if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf)
8519 && curbuf->b_term != NULL && !term_is_finished(curbuf))))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008520 {
8521 curbuf->b_p_ma = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008522 return N_("E946: Cannot make a terminal with running job modifiable");
Bram Moolenaar423802d2017-07-30 16:52:24 +02008523 }
8524# endif
8525# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008526 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008527# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008528 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008529#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008530 /* when 'endofline' is changed, redraw the window title */
8531 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008532 {
8533 redraw_titles();
8534 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008535 /* when 'fixeol' is changed, redraw the window title */
8536 else if ((int *)varp == &curbuf->b_p_fixeol)
8537 {
8538 redraw_titles();
8539 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008540 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008541 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008542 {
8543 redraw_titles();
8544 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008545#endif
8546
8547 /* when 'bin' is set also set some other options */
8548 else if ((int *)varp == &curbuf->b_p_bin)
8549 {
8550 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8551#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008552 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008553#endif
8554 }
8555
Bram Moolenaar071d4272004-06-13 20:20:40 +00008556 /* when 'buflisted' changes, trigger autocommands */
8557 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8558 {
8559 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8560 NULL, NULL, TRUE, curbuf);
8561 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008562
8563 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8564 else if ((int *)varp == &curbuf->b_p_swf)
8565 {
8566 if (curbuf->b_p_swf && p_uc)
8567 ml_open_file(curbuf); /* create the swap file */
8568 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008569 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8570 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008571 mf_close_file(curbuf, TRUE); /* remove the swap file */
8572 }
8573
8574 /* when 'terse' is set change 'shortmess' */
8575 else if ((int *)varp == &p_terse)
8576 {
8577 char_u *p;
8578
8579 p = vim_strchr(p_shm, SHM_SEARCH);
8580
8581 /* insert 's' in p_shm */
8582 if (p_terse && p == NULL)
8583 {
8584 STRCPY(IObuff, p_shm);
8585 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008586 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008587 }
8588 /* remove 's' from p_shm */
8589 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008590 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008591 }
8592
8593 /* when 'paste' is set or reset also change other options */
8594 else if ((int *)varp == &p_paste)
8595 {
8596 paste_option_changed();
8597 }
8598
8599 /* when 'insertmode' is set from an autocommand need to do work here */
8600 else if ((int *)varp == &p_im)
8601 {
8602 if (p_im)
8603 {
8604 if ((State & INSERT) == 0)
8605 need_start_insertmode = TRUE;
8606 stop_insert_mode = FALSE;
8607 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008608 /* only reset if it was set previously */
8609 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008610 {
8611 need_start_insertmode = FALSE;
8612 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008613 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008614 clear_cmdline = TRUE; /* remove "(insert)" */
8615 restart_edit = 0;
8616 }
8617 }
8618
8619 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8620 else if ((int *)varp == &p_ic && p_hls)
8621 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008622 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008623 }
8624
8625#ifdef FEAT_SEARCH_EXTRA
8626 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8627 else if ((int *)varp == &p_hls)
8628 {
Bram Moolenaar451fc7b2018-04-27 22:53:07 +02008629 set_no_hlsearch(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008630 }
8631#endif
8632
Bram Moolenaar071d4272004-06-13 20:20:40 +00008633 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8634 * at the end of normal_cmd() */
8635 else if ((int *)varp == &curwin->w_p_scb)
8636 {
8637 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008638 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008639 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008640 curwin->w_scbind_pos = curwin->w_topline;
8641 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008642 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008643
Bram Moolenaar4033c552017-09-16 20:54:51 +02008644#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008645 /* There can be only one window with 'previewwindow' set. */
8646 else if ((int *)varp == &curwin->w_p_pvw)
8647 {
8648 if (curwin->w_p_pvw)
8649 {
8650 win_T *win;
8651
Bram Moolenaar29323592016-07-24 22:04:11 +02008652 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008653 if (win->w_p_pvw && win != curwin)
8654 {
8655 curwin->w_p_pvw = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008656 return N_("E590: A preview window already exists");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008657 }
8658 }
8659 }
8660#endif
8661
8662 /* when 'textmode' is set or reset also change 'fileformat' */
8663 else if ((int *)varp == &curbuf->b_p_tx)
8664 {
8665 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8666 }
8667
8668 /* when 'textauto' is set or reset also change 'fileformats' */
8669 else if ((int *)varp == &p_ta)
Bram Moolenaarabab0b02019-03-30 18:47:01 +01008670 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008671 set_string_option_direct((char_u *)"ffs", -1,
8672 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008673 OPT_FREE | opt_flags, 0);
Bram Moolenaarabab0b02019-03-30 18:47:01 +01008674 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008675
8676 /*
8677 * When 'lisp' option changes include/exclude '-' in
8678 * keyword characters.
8679 */
8680#ifdef FEAT_LISP
8681 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8682 {
8683 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8684 }
8685#endif
8686
8687#ifdef FEAT_TITLE
8688 /* when 'title' changed, may need to change the title; same for 'icon' */
Bram Moolenaar84a93082018-06-16 22:58:15 +02008689 else if ((int *)varp == &p_title || (int *)varp == &p_icon)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008690 {
Bram Moolenaar84a93082018-06-16 22:58:15 +02008691 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008692 }
8693#endif
8694
8695 else if ((int *)varp == &curbuf->b_changed)
8696 {
8697 if (!value)
8698 save_file_ff(curbuf); /* Buffer is unchanged */
8699#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008700 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008701#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008702 modified_was_set = value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008703 }
8704
8705#ifdef BACKSLASH_IN_FILENAME
8706 else if ((int *)varp == &p_ssl)
8707 {
8708 if (p_ssl)
8709 {
8710 psepc = '/';
8711 psepcN = '\\';
8712 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008713 }
8714 else
8715 {
8716 psepc = '\\';
8717 psepcN = '/';
8718 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008719 }
8720
8721 /* need to adjust the file name arguments and buffer names. */
8722 buflist_slash_adjust();
8723 alist_slash_adjust();
8724# ifdef FEAT_EVAL
8725 scriptnames_slash_adjust();
8726# endif
8727 }
8728#endif
8729
8730 /* If 'wrap' is set, set w_leftcol to zero. */
8731 else if ((int *)varp == &curwin->w_p_wrap)
8732 {
8733 if (curwin->w_p_wrap)
8734 curwin->w_leftcol = 0;
8735 }
8736
Bram Moolenaar071d4272004-06-13 20:20:40 +00008737 else if ((int *)varp == &p_ea)
8738 {
8739 if (p_ea && !old_value)
8740 win_equal(curwin, FALSE, 0);
8741 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008742
8743 else if ((int *)varp == &p_wiv)
8744 {
8745 /*
8746 * When 'weirdinvert' changed, set/reset 't_xs'.
8747 * Then set 'weirdinvert' according to value of 't_xs'.
8748 */
8749 if (p_wiv && !old_value)
8750 T_XS = (char_u *)"y";
8751 else if (!p_wiv && old_value)
8752 T_XS = empty_option;
8753 p_wiv = (*T_XS != NUL);
8754 }
8755
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008756#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008757 else if ((int *)varp == &p_beval)
8758 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008759 if (!balloonEvalForTerm)
8760 {
8761 if (p_beval && !old_value)
8762 gui_mch_enable_beval_area(balloonEval);
8763 else if (!p_beval && old_value)
8764 gui_mch_disable_beval_area(balloonEval);
8765 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008766 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008767#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008768#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008769 else if ((int *)varp == &p_bevalterm)
8770 {
8771 mch_bevalterm_changed();
8772 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008773#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008774
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008775#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008776 else if ((int *)varp == &p_acd)
8777 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008778 /* Change directories when the 'acd' option is set now. */
Bram Moolenaar6f470022018-04-10 18:47:20 +02008779 DO_AUTOCHDIR;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008780 }
8781#endif
8782
8783#ifdef FEAT_DIFF
8784 /* 'diff' */
8785 else if ((int *)varp == &curwin->w_p_diff)
8786 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008787 /* May add or remove the buffer from the list of diff buffers. */
8788 diff_buf_adjust(curwin);
8789# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008790 if (foldmethodIsDiff(curwin))
8791 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008792# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008793 }
8794#endif
8795
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008796#ifdef HAVE_INPUT_METHOD
Bram Moolenaar071d4272004-06-13 20:20:40 +00008797 /* 'imdisable' */
8798 else if ((int *)varp == &p_imdisable)
8799 {
8800 /* Only de-activate it here, it will be enabled when changing mode. */
8801 if (p_imdisable)
8802 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008803 else if (State & INSERT)
8804 /* When the option is set from an autocommand, it may need to take
8805 * effect right away. */
8806 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008807 }
8808#endif
8809
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008810#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008811 /* 'spell' */
8812 else if ((int *)varp == &curwin->w_p_spell)
8813 {
8814 if (curwin->w_p_spell)
8815 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008816 char *errmsg = did_set_spelllang(curwin);
8817
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008818 if (errmsg != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008819 emsg(_(errmsg));
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008820 }
8821 }
8822#endif
8823
Bram Moolenaar071d4272004-06-13 20:20:40 +00008824#ifdef FEAT_ARABIC
8825 if ((int *)varp == &curwin->w_p_arab)
8826 {
8827 if (curwin->w_p_arab)
8828 {
8829 /*
8830 * 'arabic' is set, handle various sub-settings.
8831 */
8832 if (!p_tbidi)
8833 {
8834 /* set rightleft mode */
8835 if (!curwin->w_p_rl)
8836 {
8837 curwin->w_p_rl = TRUE;
8838 changed_window_setting();
8839 }
8840
8841 /* Enable Arabic shaping (major part of what Arabic requires) */
8842 if (!p_arshape)
8843 {
8844 p_arshape = TRUE;
8845 redraw_later_clear();
8846 }
8847 }
8848
8849 /* Arabic requires a utf-8 encoding, inform the user if its not
8850 * set. */
8851 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008852 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008853 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8854
Bram Moolenaar8820b482017-03-16 17:23:31 +01008855 msg_source(HL_ATTR(HLF_W));
Bram Moolenaar32526b32019-01-19 17:43:09 +01008856 msg_attr(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008857#ifdef FEAT_EVAL
8858 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8859#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008860 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008861
Bram Moolenaar071d4272004-06-13 20:20:40 +00008862 /* set 'delcombine' */
8863 p_deco = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008864
8865# ifdef FEAT_KEYMAP
8866 /* Force-set the necessary keymap for arabic */
8867 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8868 OPT_LOCAL);
8869# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008870 }
8871 else
8872 {
8873 /*
8874 * 'arabic' is reset, handle various sub-settings.
8875 */
8876 if (!p_tbidi)
8877 {
8878 /* reset rightleft mode */
8879 if (curwin->w_p_rl)
8880 {
8881 curwin->w_p_rl = FALSE;
8882 changed_window_setting();
8883 }
8884
8885 /* 'arabicshape' isn't reset, it is a global option and
8886 * another window may still need it "on". */
8887 }
8888
8889 /* 'delcombine' isn't reset, it is a global option and another
8890 * window may still want it "on". */
8891
8892# ifdef FEAT_KEYMAP
8893 /* Revert to the default keymap */
8894 curbuf->b_p_iminsert = B_IMODE_NONE;
8895 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8896# endif
8897 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008898 }
8899
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008900#endif
8901
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008902#ifdef FEAT_TERMGUICOLORS
8903 /* 'termguicolors' */
8904 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008905 {
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008906# ifdef FEAT_VTP
8907 /* Do not turn on 'tgc' when 24-bit colors are not supported. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02008908 if (
8909# ifdef VIMDLL
8910 !gui.in_use && !gui.starting &&
8911# endif
8912 !has_vtp_working())
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008913 {
8914 p_tgc = 0;
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01008915 return N_("E954: 24-bit colors are not supported on this environment");
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008916 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008917 if (is_term_win32())
8918 swap_tcap();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008919# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008920# ifdef FEAT_GUI
8921 if (!gui.in_use && !gui.starting)
8922# endif
8923 highlight_gui_started();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008924# ifdef FEAT_VTP
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008925 /* reset t_Co */
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008926 if (is_term_win32())
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02008927 {
8928 control_console_color_rgb();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008929 set_termname(T_NAME);
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02008930 init_highlight(TRUE, FALSE);
8931 }
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008932# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008933 }
8934#endif
8935
Bram Moolenaar071d4272004-06-13 20:20:40 +00008936 /*
8937 * End of handling side effects for bool options.
8938 */
8939
Bram Moolenaar53744302015-07-17 17:38:22 +02008940 /* after handling side effects, call autocommand */
8941
Bram Moolenaar071d4272004-06-13 20:20:40 +00008942 options[opt_idx].flags |= P_WAS_SET;
8943
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008944#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02008945 // Don't do this while starting up or recursively.
8946 if (!starting && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02008947 {
8948 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02008949
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008950 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8951 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8952 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008953 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8954 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8955 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8956 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8957 reset_v_option_vars();
8958 }
8959#endif
8960
Bram Moolenaar071d4272004-06-13 20:20:40 +00008961 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008962 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008963 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008964 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008965 check_redraw(options[opt_idx].flags);
8966
8967 return NULL;
8968}
8969
8970/*
8971 * Set the value of a number option, and take care of side effects.
8972 * Returns NULL for success, or an error message for an error.
8973 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008974 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008975set_num_option(
8976 int opt_idx, /* index in options[] table */
8977 char_u *varp, /* pointer to the option variable */
8978 long value, /* new value */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008979 char *errbuf, /* buffer for error messages */
Bram Moolenaar9b578142016-01-30 19:39:49 +01008980 size_t errbuflen, /* length of "errbuf" */
8981 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008982 OPT_MODELINE */
8983{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008984 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008985 long old_value = *(long *)varp;
8986 long old_Rows = Rows; /* remember old Rows */
8987 long old_Columns = Columns; /* remember old Columns */
8988 long *pp = (long *)varp;
8989
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008990 /* Disallow changing some options from secure mode. */
8991 if ((secure
8992#ifdef HAVE_SANDBOX
8993 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008994#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008995 ) && (options[opt_idx].flags & P_SECURE))
8996 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008997
8998 *pp = value;
8999#ifdef FEAT_EVAL
9000 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02009001 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009002#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009003#ifdef FEAT_GUI
9004 need_mouse_correct = TRUE;
9005#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009006
Bram Moolenaar14f24742012-08-08 18:01:05 +02009007 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009008 {
9009 errmsg = e_positive;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02009010#ifdef FEAT_VARTABS
9011 // Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use.
9012 curbuf->b_p_sw = tabstop_count(curbuf->b_p_vts_array) > 0
9013 ? tabstop_first(curbuf->b_p_vts_array)
9014 : curbuf->b_p_ts;
9015#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00009016 curbuf->b_p_sw = curbuf->b_p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02009017#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009018 }
9019
9020 /*
9021 * Number options that need some action when changed
9022 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009023 if (pp == &p_wh || pp == &p_hh)
9024 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009025 // 'winheight' and 'helpheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009026 if (p_wh < 1)
9027 {
9028 errmsg = e_positive;
9029 p_wh = 1;
9030 }
9031 if (p_wmh > p_wh)
9032 {
9033 errmsg = e_winheight;
9034 p_wh = p_wmh;
9035 }
9036 if (p_hh < 0)
9037 {
9038 errmsg = e_positive;
9039 p_hh = 0;
9040 }
9041
9042 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01009043 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009044 {
9045 if (pp == &p_wh && curwin->w_height < p_wh)
9046 win_setheight((int)p_wh);
9047 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
9048 win_setheight((int)p_hh);
9049 }
9050 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009051 else if (pp == &p_wmh)
9052 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009053 // 'winminheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009054 if (p_wmh < 0)
9055 {
9056 errmsg = e_positive;
9057 p_wmh = 0;
9058 }
9059 if (p_wmh > p_wh)
9060 {
9061 errmsg = e_winheight;
9062 p_wmh = p_wh;
9063 }
9064 win_setminheight();
9065 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009066 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009067 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009068 // 'winwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009069 if (p_wiw < 1)
9070 {
9071 errmsg = e_positive;
9072 p_wiw = 1;
9073 }
9074 if (p_wmw > p_wiw)
9075 {
9076 errmsg = e_winwidth;
9077 p_wiw = p_wmw;
9078 }
9079
9080 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01009081 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009082 win_setwidth((int)p_wiw);
9083 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009084 else if (pp == &p_wmw)
9085 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009086 // 'winminwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009087 if (p_wmw < 0)
9088 {
9089 errmsg = e_positive;
9090 p_wmw = 0;
9091 }
9092 if (p_wmw > p_wiw)
9093 {
9094 errmsg = e_winwidth;
9095 p_wmw = p_wiw;
9096 }
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009097 win_setminwidth();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009098 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009099
Bram Moolenaar071d4272004-06-13 20:20:40 +00009100 /* (re)set last window status line */
9101 else if (pp == &p_ls)
9102 {
9103 last_status(FALSE);
9104 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009105
9106 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00009107 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009108 {
9109 shell_new_rows(); /* recompute window positions and heights */
9110 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009111
9112#ifdef FEAT_GUI
9113 else if (pp == &p_linespace)
9114 {
Bram Moolenaar02743632005-07-25 20:42:36 +00009115 /* Recompute gui.char_height and resize the Vim window to keep the
9116 * same number of lines. */
9117 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00009118 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009119 }
9120#endif
9121
9122#ifdef FEAT_FOLDING
9123 /* 'foldlevel' */
9124 else if (pp == &curwin->w_p_fdl)
9125 {
9126 if (curwin->w_p_fdl < 0)
9127 curwin->w_p_fdl = 0;
9128 newFoldLevel();
9129 }
9130
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00009131 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009132 else if (pp == &curwin->w_p_fml)
9133 {
9134 foldUpdateAll(curwin);
9135 }
9136
9137 /* 'foldnestmax' */
9138 else if (pp == &curwin->w_p_fdn)
9139 {
9140 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
9141 foldUpdateAll(curwin);
9142 }
9143
9144 /* 'foldcolumn' */
9145 else if (pp == &curwin->w_p_fdc)
9146 {
9147 if (curwin->w_p_fdc < 0)
9148 {
9149 errmsg = e_positive;
9150 curwin->w_p_fdc = 0;
9151 }
9152 else if (curwin->w_p_fdc > 12)
9153 {
9154 errmsg = e_invarg;
9155 curwin->w_p_fdc = 12;
9156 }
9157 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009158#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009159
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009160#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009161 /* 'shiftwidth' or 'tabstop' */
9162 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
9163 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009164# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00009165 if (foldmethodIsIndent(curwin))
9166 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009167# endif
9168# ifdef FEAT_CINDENT
9169 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
9170 * parse 'cinoptions'. */
9171 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
9172 parse_cino(curbuf);
9173# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009174 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009175#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009176
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009177 /* 'maxcombine' */
9178 else if (pp == &p_mco)
9179 {
9180 if (p_mco > MAX_MCO)
9181 p_mco = MAX_MCO;
9182 else if (p_mco < 0)
9183 p_mco = 0;
9184 screenclear(); /* will re-allocate the screen */
9185 }
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009186
Bram Moolenaar071d4272004-06-13 20:20:40 +00009187 else if (pp == &curbuf->b_p_iminsert)
9188 {
9189 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
9190 {
9191 errmsg = e_invarg;
9192 curbuf->b_p_iminsert = B_IMODE_NONE;
9193 }
9194 p_iminsert = curbuf->b_p_iminsert;
9195 if (termcap_active) /* don't do this in the alternate screen */
9196 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02009197#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009198 /* Show/unshow value of 'keymap' in status lines. */
9199 status_redraw_curbuf();
9200#endif
9201 }
9202
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02009203#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
9204 /* 'imstyle' */
9205 else if (pp == &p_imst)
9206 {
9207 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
9208 errmsg = e_invarg;
9209 }
9210#endif
9211
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009212 else if (pp == &p_window)
9213 {
9214 if (p_window < 1)
9215 p_window = 1;
9216 else if (p_window >= Rows)
9217 p_window = Rows - 1;
9218 }
9219
Bram Moolenaar071d4272004-06-13 20:20:40 +00009220 else if (pp == &curbuf->b_p_imsearch)
9221 {
9222 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
9223 {
9224 errmsg = e_invarg;
9225 curbuf->b_p_imsearch = B_IMODE_NONE;
9226 }
9227 p_imsearch = curbuf->b_p_imsearch;
9228 }
9229
9230#ifdef FEAT_TITLE
9231 /* if 'titlelen' has changed, redraw the title */
9232 else if (pp == &p_titlelen)
9233 {
9234 if (p_titlelen < 0)
9235 {
9236 errmsg = e_positive;
9237 p_titlelen = 85;
9238 }
9239 if (starting != NO_SCREEN && old_value != p_titlelen)
9240 need_maketitle = TRUE;
9241 }
9242#endif
9243
9244 /* if p_ch changed value, change the command line height */
9245 else if (pp == &p_ch)
9246 {
9247 if (p_ch < 1)
9248 {
9249 errmsg = e_positive;
9250 p_ch = 1;
9251 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009252 if (p_ch > Rows - min_rows() + 1)
9253 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009254
9255 /* Only compute the new window layout when startup has been
9256 * completed. Otherwise the frame sizes may be wrong. */
9257 if (p_ch != old_value && full_screen
9258#ifdef FEAT_GUI
9259 && !gui.starting
9260#endif
9261 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009262 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009263 }
9264
9265 /* when 'updatecount' changes from zero to non-zero, open swap files */
9266 else if (pp == &p_uc)
9267 {
9268 if (p_uc < 0)
9269 {
9270 errmsg = e_positive;
9271 p_uc = 100;
9272 }
9273 if (p_uc && !old_value)
9274 ml_open_files();
9275 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009276#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009277 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009278 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009279 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009280 {
9281 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009282 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009283 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009284 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009285 {
9286 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009287 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009288 }
9289 }
9290#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009291#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009292 else if (pp == &p_mzq)
9293 mzvim_reset_timer();
9294#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009295
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009296#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9297 /* 'pyxversion' */
9298 else if (pp == &p_pyx)
9299 {
9300 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9301 errmsg = e_invarg;
9302 }
9303#endif
9304
Bram Moolenaar071d4272004-06-13 20:20:40 +00009305 /* sync undo before 'undolevels' changes */
9306 else if (pp == &p_ul)
9307 {
9308 /* use the old value, otherwise u_sync() may not work properly */
9309 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009310 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009311 p_ul = value;
9312 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009313 else if (pp == &curbuf->b_p_ul)
9314 {
9315 /* use the old value, otherwise u_sync() may not work properly */
9316 curbuf->b_p_ul = old_value;
9317 u_sync(TRUE);
9318 curbuf->b_p_ul = value;
9319 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009320
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009321#ifdef FEAT_LINEBREAK
9322 /* 'numberwidth' must be positive */
9323 else if (pp == &curwin->w_p_nuw)
9324 {
9325 if (curwin->w_p_nuw < 1)
9326 {
9327 errmsg = e_positive;
9328 curwin->w_p_nuw = 1;
9329 }
9330 if (curwin->w_p_nuw > 10)
9331 {
9332 errmsg = e_invarg;
9333 curwin->w_p_nuw = 10;
9334 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009335 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009336 }
9337#endif
9338
Bram Moolenaar1a384422010-07-14 19:53:30 +02009339 else if (pp == &curbuf->b_p_tw)
9340 {
9341 if (curbuf->b_p_tw < 0)
9342 {
9343 errmsg = e_positive;
9344 curbuf->b_p_tw = 0;
9345 }
9346#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009347 {
9348 win_T *wp;
9349 tabpage_T *tp;
9350
9351 FOR_ALL_TAB_WINDOWS(tp, wp)
9352 check_colorcolumn(wp);
9353 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009354#endif
9355 }
9356
Bram Moolenaar071d4272004-06-13 20:20:40 +00009357 /*
9358 * Check the bounds for numeric options here
9359 */
9360 if (Rows < min_rows() && full_screen)
9361 {
9362 if (errbuf != NULL)
9363 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009364 vim_snprintf((char *)errbuf, errbuflen,
9365 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009366 errmsg = errbuf;
9367 }
9368 Rows = min_rows();
9369 }
9370 if (Columns < MIN_COLUMNS && full_screen)
9371 {
9372 if (errbuf != NULL)
9373 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009374 vim_snprintf((char *)errbuf, errbuflen,
9375 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009376 errmsg = errbuf;
9377 }
9378 Columns = MIN_COLUMNS;
9379 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009380 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009381
Bram Moolenaar071d4272004-06-13 20:20:40 +00009382 /*
9383 * If the screen (shell) height has been changed, assume it is the
9384 * physical screenheight.
9385 */
9386 if (old_Rows != Rows || old_Columns != Columns)
9387 {
9388 /* Changing the screen size is not allowed while updating the screen. */
9389 if (updating_screen)
9390 *pp = old_value;
9391 else if (full_screen
9392#ifdef FEAT_GUI
9393 && !gui.starting
9394#endif
9395 )
9396 set_shellsize((int)Columns, (int)Rows, TRUE);
9397 else
9398 {
9399 /* Postpone the resizing; check the size and cmdline position for
9400 * messages. */
9401 check_shellsize();
9402 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9403 cmdline_row = Rows - p_ch;
9404 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009405 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009406 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009407 }
9408
Bram Moolenaar071d4272004-06-13 20:20:40 +00009409 if (curbuf->b_p_ts <= 0)
9410 {
9411 errmsg = e_positive;
9412 curbuf->b_p_ts = 8;
9413 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009414 if (p_tm < 0)
9415 {
9416 errmsg = e_positive;
9417 p_tm = 0;
9418 }
9419 if ((curwin->w_p_scr <= 0
9420 || (curwin->w_p_scr > curwin->w_height
9421 && curwin->w_height > 0))
9422 && full_screen)
9423 {
9424 if (pp == &(curwin->w_p_scr))
9425 {
9426 if (curwin->w_p_scr != 0)
9427 errmsg = e_scroll;
9428 win_comp_scroll(curwin);
9429 }
9430 /* If 'scroll' became invalid because of a side effect silently adjust
9431 * it. */
9432 else if (curwin->w_p_scr <= 0)
9433 curwin->w_p_scr = 1;
9434 else /* curwin->w_p_scr > curwin->w_height */
9435 curwin->w_p_scr = curwin->w_height;
9436 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009437 if (p_hi < 0)
9438 {
9439 errmsg = e_positive;
9440 p_hi = 0;
9441 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009442 else if (p_hi > 10000)
9443 {
9444 errmsg = e_invarg;
9445 p_hi = 10000;
9446 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009447 if (p_re < 0 || p_re > 2)
9448 {
9449 errmsg = e_invarg;
9450 p_re = 0;
9451 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009452 if (p_report < 0)
9453 {
9454 errmsg = e_positive;
9455 p_report = 1;
9456 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009457 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009458 {
9459 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9460 p_sj = Rows / 2;
9461 else
9462 {
9463 errmsg = e_scroll;
9464 p_sj = 1;
9465 }
9466 }
9467 if (p_so < 0 && full_screen)
9468 {
Bram Moolenaar375e3392019-01-31 18:26:10 +01009469 errmsg = e_positive;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009470 p_so = 0;
9471 }
9472 if (p_siso < 0 && full_screen)
9473 {
9474 errmsg = e_positive;
9475 p_siso = 0;
9476 }
9477#ifdef FEAT_CMDWIN
9478 if (p_cwh < 1)
9479 {
9480 errmsg = e_positive;
9481 p_cwh = 1;
9482 }
9483#endif
9484 if (p_ut < 0)
9485 {
9486 errmsg = e_positive;
9487 p_ut = 2000;
9488 }
9489 if (p_ss < 0)
9490 {
9491 errmsg = e_positive;
9492 p_ss = 0;
9493 }
9494
9495 /* May set global value for local option. */
9496 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9497 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9498
9499 options[opt_idx].flags |= P_WAS_SET;
9500
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009501#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009502 // Don't do this while starting up, failure or recursively.
9503 if (!starting && errmsg == NULL && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009504 {
9505 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaar2c519cf2019-03-21 21:45:34 +01009506
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009507 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9508 vim_snprintf((char *)buf_new, 10, "%ld", value);
9509 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009510 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9511 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9512 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9513 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9514 reset_v_option_vars();
9515 }
9516#endif
9517
Bram Moolenaar071d4272004-06-13 20:20:40 +00009518 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009519 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009520 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009521 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009522 check_redraw(options[opt_idx].flags);
9523
9524 return errmsg;
9525}
9526
9527/*
9528 * Called after an option changed: check if something needs to be redrawn.
9529 */
9530 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009531check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009532{
9533 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009534 int doclear = (flags & P_RCLR) == P_RCLR;
9535 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009536
Bram Moolenaar071d4272004-06-13 20:20:40 +00009537 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9538 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009539
9540 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9541 changed_window_setting();
9542 if (flags & P_RBUF)
9543 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009544 if (flags & P_RWINONLY)
9545 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009546 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009547 redraw_all_later(CLEAR);
9548 else if (all)
9549 redraw_all_later(NOT_VALID);
9550}
9551
9552/*
9553 * Find index for option 'arg'.
9554 * Return -1 if not found.
9555 */
9556 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009557findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009558{
9559 int opt_idx;
9560 char *s, *p;
9561 static short quick_tab[27] = {0, 0}; /* quick access table */
9562 int is_term_opt;
9563
9564 /*
9565 * For first call: Initialize the quick-access table.
9566 * It contains the index for the first option that starts with a certain
9567 * letter. There are 26 letters, plus the first "t_" option.
9568 */
9569 if (quick_tab[1] == 0)
9570 {
9571 p = options[0].fullname;
9572 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9573 {
9574 if (s[0] != p[0])
9575 {
9576 if (s[0] == 't' && s[1] == '_')
9577 quick_tab[26] = opt_idx;
9578 else
9579 quick_tab[CharOrdLow(s[0])] = opt_idx;
9580 }
9581 p = s;
9582 }
9583 }
9584
9585 /*
9586 * Check for name starting with an illegal character.
9587 */
9588#ifdef EBCDIC
9589 if (!islower(arg[0]))
9590#else
9591 if (arg[0] < 'a' || arg[0] > 'z')
9592#endif
9593 return -1;
9594
9595 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9596 if (is_term_opt)
9597 opt_idx = quick_tab[26];
9598 else
9599 opt_idx = quick_tab[CharOrdLow(arg[0])];
9600 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9601 {
9602 if (STRCMP(arg, s) == 0) /* match full name */
9603 break;
9604 }
9605 if (s == NULL && !is_term_opt)
9606 {
9607 opt_idx = quick_tab[CharOrdLow(arg[0])];
9608 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9609 {
9610 s = options[opt_idx].shortname;
9611 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9612 break;
9613 s = NULL;
9614 }
9615 }
9616 if (s == NULL)
9617 opt_idx = -1;
9618 return opt_idx;
9619}
9620
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009621#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009622/*
9623 * Get the value for an option.
9624 *
9625 * Returns:
9626 * Number or Toggle option: 1, *numval gets value.
9627 * String option: 0, *stringval gets allocated string.
9628 * Hidden Number or Toggle option: -1.
9629 * hidden String option: -2.
9630 * unknown option: -3.
9631 */
9632 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009633get_option_value(
9634 char_u *name,
9635 long *numval,
9636 char_u **stringval, /* NULL when only checking existence */
9637 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009638{
9639 int opt_idx;
9640 char_u *varp;
9641
9642 opt_idx = findoption(name);
9643 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009644 {
9645 int key;
9646
9647 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009648 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009649 {
9650 char_u key_name[2];
9651 char_u *p;
9652
9653 if (key < 0)
9654 {
9655 key_name[0] = KEY2TERMCAP0(key);
9656 key_name[1] = KEY2TERMCAP1(key);
9657 }
9658 else
9659 {
9660 key_name[0] = KS_KEY;
9661 key_name[1] = (key & 0xff);
9662 }
9663 p = find_termcode(key_name);
9664 if (p != NULL)
9665 {
9666 if (stringval != NULL)
9667 *stringval = vim_strsave(p);
9668 return 0;
9669 }
9670 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009671 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009672 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009673
9674 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9675
9676 if (options[opt_idx].flags & P_STRING)
9677 {
9678 if (varp == NULL) /* hidden option */
9679 return -2;
9680 if (stringval != NULL)
9681 {
9682#ifdef FEAT_CRYPT
9683 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009684 if ((char_u **)varp == &curbuf->b_p_key
9685 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009686 *stringval = vim_strsave((char_u *)"*****");
9687 else
9688#endif
9689 *stringval = vim_strsave(*(char_u **)(varp));
9690 }
9691 return 0;
9692 }
9693
9694 if (varp == NULL) /* hidden option */
9695 return -1;
9696 if (options[opt_idx].flags & P_NUM)
9697 *numval = *(long *)varp;
9698 else
9699 {
9700 /* Special case: 'modified' is b_changed, but we also want to consider
9701 * it set when 'ff' or 'fenc' changed. */
9702 if ((int *)varp == &curbuf->b_changed)
9703 *numval = curbufIsChanged();
9704 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009705 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009706 }
9707 return 1;
9708}
9709#endif
9710
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009711#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009712/*
9713 * Returns the option attributes and its value. Unlike the above function it
9714 * will return either global value or local value of the option depending on
9715 * what was requested, but it will never return global value if it was
9716 * requested to return local one and vice versa. Neither it will return
9717 * buffer-local value if it was requested to return window-local one.
9718 *
9719 * Pretends that option is absent if it is not present in the requested scope
9720 * (i.e. has no global, window-local or buffer-local value depending on
9721 * opt_type). Uses
9722 *
9723 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009724 * 0 hidden or unknown option, also option that does not have requested
9725 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009726 * see SOPT_* in vim.h for other flags
9727 *
9728 * Possible opt_type values: see SREQ_* in vim.h
9729 */
9730 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009731get_option_value_strict(
9732 char_u *name,
9733 long *numval,
9734 char_u **stringval, /* NULL when only obtaining attributes */
9735 int opt_type,
9736 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009737{
9738 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009739 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009740 struct vimoption *p;
9741 int r = 0;
9742
9743 opt_idx = findoption(name);
9744 if (opt_idx < 0)
9745 return 0;
9746
9747 p = &(options[opt_idx]);
9748
9749 /* Hidden option */
9750 if (p->var == NULL)
9751 return 0;
9752
9753 if (p->flags & P_BOOL)
9754 r |= SOPT_BOOL;
9755 else if (p->flags & P_NUM)
9756 r |= SOPT_NUM;
9757 else if (p->flags & P_STRING)
9758 r |= SOPT_STRING;
9759
9760 if (p->indir == PV_NONE)
9761 {
9762 if (opt_type == SREQ_GLOBAL)
9763 r |= SOPT_GLOBAL;
9764 else
9765 return 0; /* Did not request global-only option */
9766 }
9767 else
9768 {
9769 if (p->indir & PV_BOTH)
9770 r |= SOPT_GLOBAL;
9771 else if (opt_type == SREQ_GLOBAL)
9772 return 0; /* Requested global option */
9773
9774 if (p->indir & PV_WIN)
9775 {
9776 if (opt_type == SREQ_BUF)
9777 return 0; /* Did not request window-local option */
9778 else
9779 r |= SOPT_WIN;
9780 }
9781 else if (p->indir & PV_BUF)
9782 {
9783 if (opt_type == SREQ_WIN)
9784 return 0; /* Did not request buffer-local option */
9785 else
9786 r |= SOPT_BUF;
9787 }
9788 }
9789
9790 if (stringval == NULL)
9791 return r;
9792
9793 if (opt_type == SREQ_GLOBAL)
9794 varp = p->var;
9795 else
9796 {
9797 if (opt_type == SREQ_BUF)
9798 {
9799 /* Special case: 'modified' is b_changed, but we also want to
9800 * consider it set when 'ff' or 'fenc' changed. */
9801 if (p->indir == PV_MOD)
9802 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009803 *numval = bufIsChanged((buf_T *)from);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009804 varp = NULL;
9805 }
9806#ifdef FEAT_CRYPT
9807 else if (p->indir == PV_KEY)
9808 {
9809 /* never return the value of the crypt key */
9810 *stringval = NULL;
9811 varp = NULL;
9812 }
9813#endif
9814 else
9815 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009816 buf_T *save_curbuf = curbuf;
9817
9818 // only getting a pointer, no need to use aucmd_prepbuf()
9819 curbuf = (buf_T *)from;
9820 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009821 varp = get_varp(p);
Bram Moolenaardefe6422018-06-24 15:14:07 +02009822 curbuf = save_curbuf;
9823 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009824 }
9825 }
9826 else if (opt_type == SREQ_WIN)
9827 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009828 win_T *save_curwin = curwin;
9829
9830 curwin = (win_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009831 curbuf = curwin->w_buffer;
9832 varp = get_varp(p);
9833 curwin = save_curwin;
9834 curbuf = curwin->w_buffer;
9835 }
9836 if (varp == p->var)
9837 return (r | SOPT_UNSET);
9838 }
9839
9840 if (varp != NULL)
9841 {
9842 if (p->flags & P_STRING)
9843 *stringval = vim_strsave(*(char_u **)(varp));
9844 else if (p->flags & P_NUM)
9845 *numval = *(long *) varp;
9846 else
9847 *numval = *(int *)varp;
9848 }
9849
9850 return r;
9851}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009852
9853/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009854 * Iterate over options. First argument is a pointer to a pointer to a
9855 * structure inside options[] array, second is option type like in the above
9856 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009857 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009858 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009859 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009860 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009861 * first argument to NULL.
9862 *
9863 * Returns full option name for current option on each call.
9864 */
9865 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009866option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009867{
9868 struct vimoption *ret = NULL;
9869 do
9870 {
9871 if (*option == NULL)
9872 *option = (void *) options;
9873 else if (((struct vimoption *) (*option))->fullname == NULL)
9874 {
9875 *option = NULL;
9876 return NULL;
9877 }
9878 else
9879 *option = (void *) (((struct vimoption *) (*option)) + 1);
9880
9881 ret = ((struct vimoption *) (*option));
9882
9883 /* Hidden option */
9884 if (ret->var == NULL)
9885 {
9886 ret = NULL;
9887 continue;
9888 }
9889
9890 switch (opt_type)
9891 {
9892 case SREQ_GLOBAL:
9893 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9894 ret = NULL;
9895 break;
9896 case SREQ_BUF:
9897 if (!(ret->indir & PV_BUF))
9898 ret = NULL;
9899 break;
9900 case SREQ_WIN:
9901 if (!(ret->indir & PV_WIN))
9902 ret = NULL;
9903 break;
9904 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009905 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009906 return NULL;
9907 }
9908 }
9909 while (ret == NULL);
9910
9911 return (char_u *)ret->fullname;
9912}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009913#endif
9914
Bram Moolenaar071d4272004-06-13 20:20:40 +00009915/*
9916 * Set the value of option "name".
9917 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009918 *
9919 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009920 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009921 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009922set_option_value(
9923 char_u *name,
9924 long number,
9925 char_u *string,
9926 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009927{
9928 int opt_idx;
9929 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009930 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009931
9932 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009933 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009934 {
9935 int key;
9936
9937 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009938 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009939 {
9940 char_u key_name[2];
9941
9942 if (key < 0)
9943 {
9944 key_name[0] = KEY2TERMCAP0(key);
9945 key_name[1] = KEY2TERMCAP1(key);
9946 }
9947 else
9948 {
9949 key_name[0] = KS_KEY;
9950 key_name[1] = (key & 0xff);
9951 }
9952 add_termcode(key_name, string, FALSE);
9953 if (full_screen)
9954 ttest(FALSE);
9955 redraw_all_later(CLEAR);
9956 return NULL;
9957 }
9958
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009959 semsg(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009960 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009961 else
9962 {
9963 flags = options[opt_idx].flags;
9964#ifdef HAVE_SANDBOX
9965 /* Disallow changing some options in the sandbox */
9966 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009967 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009968 emsg(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009969 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009970 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009971#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009972 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009973 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009974 else
9975 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009976 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009977 if (varp != NULL) /* hidden option is not changed */
9978 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009979 if (number == 0 && string != NULL)
9980 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009981 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009982
9983 /* Either we are given a string or we are setting option
9984 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009985 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009986 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009987 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009988 {
9989 /* There's another character after zeros or the string
9990 * is empty. In both cases, we are trying to set a
9991 * num option using a string. */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009992 semsg(_("E521: Number required: &%s = '%s'"),
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009993 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009994 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009995
9996 }
9997 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009998 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009999 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +000010000 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010001 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010002 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010003 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010004 }
10005 }
10006 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010007 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010008}
10009
10010/*
10011 * Get the terminal code for a terminal option.
10012 * Returns NULL when not found.
10013 */
10014 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010015get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010016{
10017 int opt_idx;
10018 char_u *varp;
10019
10020 if (tname[0] != 't' || tname[1] != '_' ||
10021 tname[2] == NUL || tname[3] == NUL)
10022 return NULL;
10023 if ((opt_idx = findoption(tname)) >= 0)
10024 {
10025 varp = get_varp(&(options[opt_idx]));
10026 if (varp != NULL)
10027 varp = *(char_u **)(varp);
10028 return varp;
10029 }
10030 return find_termcode(tname + 2);
10031}
10032
10033 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010034get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010035{
10036 int i;
10037
10038 i = findoption((char_u *)"hl");
10039 if (i >= 0)
10040 return options[i].def_val[VI_DEFAULT];
10041 return (char_u *)NULL;
10042}
10043
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010044 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010045get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010046{
10047 int i;
10048
10049 i = findoption((char_u *)"enc");
10050 if (i >= 0)
10051 return options[i].def_val[VI_DEFAULT];
10052 return (char_u *)NULL;
10053}
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010054
Bram Moolenaar071d4272004-06-13 20:20:40 +000010055/*
10056 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010057 * When "has_lt" is true there is a '<' before "*arg_arg".
10058 * Returns 0 when the key is not recognized.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010059 */
10060 static int
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010061find_key_option(char_u *arg_arg, int has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010062{
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010063 int key = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010064 int modifiers;
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010065 char_u *arg = arg_arg;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010066
10067 /*
10068 * Don't use get_special_key_code() for t_xx, we don't want it to call
10069 * add_termcap_entry().
10070 */
10071 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
10072 key = TERMCAP2KEY(arg[2], arg[3]);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010073 else if (has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010074 {
10075 --arg; /* put arg at the '<' */
10076 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +020010077 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010078 if (modifiers) /* can't handle modifiers here */
10079 key = 0;
10080 }
10081 return key;
10082}
10083
10084/*
10085 * if 'all' == 0: show changed options
10086 * if 'all' == 1: show all normal options
10087 * if 'all' == 2: show all terminal options
10088 */
10089 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010090showoptions(
10091 int all,
10092 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010093{
10094 struct vimoption *p;
10095 int col;
10096 int isterm;
10097 char_u *varp;
10098 struct vimoption **items;
10099 int item_count;
10100 int run;
10101 int row, rows;
10102 int cols;
10103 int i;
10104 int len;
10105
10106#define INC 20
10107#define GAP 3
10108
Bram Moolenaarc799fe22019-05-28 23:08:19 +020010109 items = ALLOC_MULT(struct vimoption *, PARAM_COUNT);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010110 if (items == NULL)
10111 return;
10112
10113 /* Highlight title */
10114 if (all == 2)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010115 msg_puts_title(_("\n--- Terminal codes ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010116 else if (opt_flags & OPT_GLOBAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010117 msg_puts_title(_("\n--- Global option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010118 else if (opt_flags & OPT_LOCAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010119 msg_puts_title(_("\n--- Local option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010120 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010121 msg_puts_title(_("\n--- Options ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010122
10123 /*
10124 * do the loop two times:
10125 * 1. display the short items
10126 * 2. display the long items (only strings and numbers)
10127 */
10128 for (run = 1; run <= 2 && !got_int; ++run)
10129 {
10130 /*
10131 * collect the items in items[]
10132 */
10133 item_count = 0;
10134 for (p = &options[0]; p->fullname != NULL; p++)
10135 {
Bram Moolenaarf86db782018-10-25 13:31:37 +020010136 // apply :filter /pat/
10137 if (message_filtered((char_u *) p->fullname))
10138 continue;
10139
Bram Moolenaar071d4272004-06-13 20:20:40 +000010140 varp = NULL;
10141 isterm = istermoption(p);
10142 if (opt_flags != 0)
10143 {
10144 if (p->indir != PV_NONE && !isterm)
10145 varp = get_varp_scope(p, opt_flags);
10146 }
10147 else
10148 varp = get_varp(p);
10149 if (varp != NULL
10150 && ((all == 2 && isterm)
10151 || (all == 1 && !isterm)
10152 || (all == 0 && !optval_default(p, varp))))
10153 {
10154 if (p->flags & P_BOOL)
10155 len = 1; /* a toggle option fits always */
10156 else
10157 {
10158 option_value2string(p, opt_flags);
10159 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
10160 }
10161 if ((len <= INC - GAP && run == 1) ||
10162 (len > INC - GAP && run == 2))
10163 items[item_count++] = p;
10164 }
10165 }
10166
10167 /*
10168 * display the items
10169 */
10170 if (run == 1)
10171 {
10172 cols = (Columns + GAP - 3) / INC;
10173 if (cols == 0)
10174 cols = 1;
10175 rows = (item_count + cols - 1) / cols;
10176 }
10177 else /* run == 2 */
10178 rows = item_count;
10179 for (row = 0; row < rows && !got_int; ++row)
10180 {
10181 msg_putchar('\n'); /* go to next line */
10182 if (got_int) /* 'q' typed in more */
10183 break;
10184 col = 0;
10185 for (i = row; i < item_count; i += rows)
10186 {
10187 msg_col = col; /* make columns */
10188 showoneopt(items[i], opt_flags);
10189 col += INC;
10190 }
10191 out_flush();
10192 ui_breakcheck();
10193 }
10194 }
10195 vim_free(items);
10196}
10197
10198/*
10199 * Return TRUE if option "p" has its default value.
10200 */
10201 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010202optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010203{
10204 int dvi;
10205
10206 if (varp == NULL)
10207 return TRUE; /* hidden option is always at default */
10208 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
10209 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010210 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010211 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010212 /* the cast to long is required for Manx C, long_i is
10213 * needed for MSVC */
10214 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010215 /* P_STRING */
10216 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
10217}
10218
10219/*
10220 * showoneopt: show the value of one option
10221 * must not be called with a hidden option!
10222 */
10223 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010224showoneopt(
10225 struct vimoption *p,
10226 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010227{
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010228 char_u *varp;
10229 int save_silent = silent_mode;
10230
10231 silent_mode = FALSE;
10232 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010233
10234 varp = get_varp_scope(p, opt_flags);
10235
10236 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
10237 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
10238 ? !curbufIsChanged() : !*(int *)varp))
Bram Moolenaar32526b32019-01-19 17:43:09 +010010239 msg_puts("no");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010240 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010241 msg_puts("--");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010242 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010243 msg_puts(" ");
10244 msg_puts(p->fullname);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010245 if (!(p->flags & P_BOOL))
10246 {
10247 msg_putchar('=');
10248 /* put value string in NameBuff */
10249 option_value2string(p, opt_flags);
10250 msg_outtrans(NameBuff);
10251 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010252
10253 silent_mode = save_silent;
10254 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010255}
10256
10257/*
10258 * Write modified options as ":set" commands to a file.
10259 *
10260 * There are three values for "opt_flags":
10261 * OPT_GLOBAL: Write global option values and fresh values of
10262 * buffer-local options (used for start of a session
10263 * file).
10264 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10265 * curwin (used for a vimrc file).
10266 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10267 * and local values for window-local options of
10268 * curwin. Local values are also written when at the
10269 * default value, because a modeline or autocommand
10270 * may have set them when doing ":edit file" and the
10271 * user has set them back at the default or fresh
10272 * value.
10273 * When "local_only" is TRUE, don't write fresh
10274 * values, only local values (for ":mkview").
10275 * (fresh value = value used for a new buffer or window for a local option).
10276 *
10277 * Return FAIL on error, OK otherwise.
10278 */
10279 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010280makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010281{
10282 struct vimoption *p;
10283 char_u *varp; /* currently used value */
10284 char_u *varp_fresh; /* local value */
10285 char_u *varp_local = NULL; /* fresh value */
10286 char *cmd;
10287 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010288 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010289
10290 /*
10291 * The options that don't have a default (terminal name, columns, lines)
10292 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010293 * Do the loop over "options[]" twice: once for options with the
10294 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010295 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010296 for (pri = 1; pri >= 0; --pri)
10297 {
10298 for (p = &options[0]; !istermoption(p); p++)
10299 if (!(p->flags & P_NO_MKRC)
10300 && !istermoption(p)
10301 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010302 {
10303 /* skip global option when only doing locals */
10304 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10305 continue;
10306
10307 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10308 * file, they are always buffer-specific. */
10309 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10310 continue;
10311
10312 /* Global values are only written when not at the default value. */
10313 varp = get_varp_scope(p, opt_flags);
10314 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10315 continue;
10316
10317 round = 2;
10318 if (p->indir != PV_NONE)
10319 {
10320 if (p->var == VAR_WIN)
10321 {
10322 /* skip window-local option when only doing globals */
10323 if (!(opt_flags & OPT_LOCAL))
10324 continue;
10325 /* When fresh value of window-local option is not at the
10326 * default, need to write it too. */
10327 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10328 {
10329 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10330 if (!optval_default(p, varp_fresh))
10331 {
10332 round = 1;
10333 varp_local = varp;
10334 varp = varp_fresh;
10335 }
10336 }
10337 }
10338 }
10339
10340 /* Round 1: fresh value for window-local options.
10341 * Round 2: other values */
10342 for ( ; round <= 2; varp = varp_local, ++round)
10343 {
10344 if (round == 1 || (opt_flags & OPT_GLOBAL))
10345 cmd = "set";
10346 else
10347 cmd = "setlocal";
10348
10349 if (p->flags & P_BOOL)
10350 {
10351 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10352 return FAIL;
10353 }
10354 else if (p->flags & P_NUM)
10355 {
10356 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10357 return FAIL;
10358 }
10359 else /* P_STRING */
10360 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010361 int do_endif = FALSE;
10362
Bram Moolenaar071d4272004-06-13 20:20:40 +000010363 /* Don't set 'syntax' and 'filetype' again if the value is
10364 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010365 if (
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +010010366#if defined(FEAT_SYN_HL)
10367 p->indir == PV_SYN ||
10368#endif
10369 p->indir == PV_FT)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010370 {
10371 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10372 *(char_u **)(varp)) < 0
10373 || put_eol(fd) < 0)
10374 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010375 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010376 }
10377 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010378 p->flags) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010379 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010380 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010381 {
10382 if (put_line(fd, "endif") == FAIL)
10383 return FAIL;
10384 }
10385 }
10386 }
10387 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010388 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010389 return OK;
10390}
10391
10392#if defined(FEAT_FOLDING) || defined(PROTO)
10393/*
10394 * Generate set commands for the local fold options only. Used when
10395 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10396 */
10397 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010398makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010399{
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010400 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, 0) == FAIL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010401# ifdef FEAT_EVAL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010402 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010403 == FAIL
10404# endif
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010405 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010406 == FAIL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010407 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010408 == FAIL
10409 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10410 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10411 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10412 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10413 )
10414 return FAIL;
10415
10416 return OK;
10417}
10418#endif
10419
10420 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010421put_setstring(
10422 FILE *fd,
10423 char *cmd,
10424 char *name,
10425 char_u **valuep,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010426 long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010427{
10428 char_u *s;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010429 char_u *buf = NULL;
10430 char_u *part = NULL;
10431 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010432
10433 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10434 return FAIL;
10435 if (*valuep != NULL)
10436 {
10437 /* Output 'pastetoggle' as key names. For other
10438 * options some characters have to be escaped with
10439 * CTRL-V or backslash */
10440 if (valuep == &p_pt)
10441 {
10442 s = *valuep;
10443 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010444 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010445 return FAIL;
10446 }
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010447 // expand the option value, replace $HOME by ~
10448 else if ((flags & P_EXPAND) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010449 {
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010450 int size = (int)STRLEN(*valuep) + 1;
10451
10452 // replace home directory in the whole option value into "buf"
10453 buf = alloc(size);
Bram Moolenaarf8441472011-04-28 17:24:58 +020010454 if (buf == NULL)
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010455 goto fail;
10456 home_replace(NULL, *valuep, buf, size, FALSE);
10457
10458 // If the option value is longer than MAXPATHL, we need to append
10459 // earch comma separated part of the option separately, so that it
10460 // can be expanded when read back.
10461 if (size >= MAXPATHL && (flags & P_COMMA) != 0
10462 && vim_strchr(*valuep, ',') != NULL)
10463 {
10464 part = alloc(size);
10465 if (part == NULL)
10466 goto fail;
10467
10468 // write line break to clear the option, e.g. ':set rtp='
10469 if (put_eol(fd) == FAIL)
10470 goto fail;
10471
10472 p = buf;
10473 while (*p != NUL)
10474 {
10475 // for each comma separated option part, append value to
10476 // the option, :set rtp+=value
10477 if (fprintf(fd, "%s %s+=", cmd, name) < 0)
10478 goto fail;
10479 (void)copy_option_part(&p, part, size, ",");
10480 if (put_escstr(fd, part, 2) == FAIL || put_eol(fd) == FAIL)
10481 goto fail;
10482 }
10483 vim_free(buf);
10484 vim_free(part);
10485 return OK;
10486 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010487 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010488 {
10489 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010490 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010491 }
10492 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010493 }
10494 else if (put_escstr(fd, *valuep, 2) == FAIL)
10495 return FAIL;
10496 }
10497 if (put_eol(fd) < 0)
10498 return FAIL;
10499 return OK;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010500fail:
10501 vim_free(buf);
10502 vim_free(part);
10503 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010504}
10505
10506 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010507put_setnum(
10508 FILE *fd,
10509 char *cmd,
10510 char *name,
10511 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010512{
10513 long wc;
10514
10515 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10516 return FAIL;
10517 if (wc_use_keyname((char_u *)valuep, &wc))
10518 {
10519 /* print 'wildchar' and 'wildcharm' as a key name */
10520 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10521 return FAIL;
10522 }
10523 else if (fprintf(fd, "%ld", *valuep) < 0)
10524 return FAIL;
10525 if (put_eol(fd) < 0)
10526 return FAIL;
10527 return OK;
10528}
10529
10530 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010531put_setbool(
10532 FILE *fd,
10533 char *cmd,
10534 char *name,
10535 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010536{
Bram Moolenaar893de922007-10-02 18:40:57 +000010537 if (value < 0) /* global/local option using global value */
10538 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010539 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10540 || put_eol(fd) < 0)
10541 return FAIL;
10542 return OK;
10543}
10544
10545/*
10546 * Clear all the terminal options.
10547 * If the option has been allocated, free the memory.
10548 * Terminal options are never hidden or indirect.
10549 */
10550 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010551clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010552{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010553 /*
10554 * Reset a few things before clearing the old options. This may cause
10555 * outputting a few things that the terminal doesn't understand, but the
10556 * screen will be cleared later, so this is OK.
10557 */
10558#ifdef FEAT_MOUSE_TTY
10559 mch_setmouse(FALSE); /* switch mouse off */
10560#endif
10561#ifdef FEAT_TITLE
Bram Moolenaar40385db2018-08-07 22:31:44 +020010562 mch_restore_title(SAVE_RESTORE_BOTH); /* restore window titles */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010563#endif
10564#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10565 /* When starting the GUI close the display opened for the clipboard.
10566 * After restoring the title, because that will need the display. */
10567 if (gui.starting)
10568 clear_xterm_clip();
10569#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010570 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010571
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010572 free_termoptions();
10573}
10574
10575 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010576free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010577{
10578 struct vimoption *p;
10579
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010580 for (p = options; p->fullname != NULL; p++)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010581 if (istermoption(p))
10582 {
10583 if (p->flags & P_ALLOCED)
10584 free_string_option(*(char_u **)(p->var));
10585 if (p->flags & P_DEF_ALLOCED)
10586 free_string_option(p->def_val[VI_DEFAULT]);
10587 *(char_u **)(p->var) = empty_option;
10588 p->def_val[VI_DEFAULT] = empty_option;
10589 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010590#ifdef FEAT_EVAL
10591 // remember where the option was cleared
10592 set_option_sctx_idx((int)(p - options), OPT_GLOBAL, current_sctx);
10593#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010594 }
10595 clear_termcodes();
10596}
10597
10598/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010599 * Free the string for one term option, if it was allocated.
10600 * Set the string to empty_option and clear allocated flag.
10601 * "var" points to the option value.
10602 */
10603 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010604free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010605{
10606 struct vimoption *p;
10607
10608 for (p = &options[0]; p->fullname != NULL; p++)
10609 if (p->var == var)
10610 {
10611 if (p->flags & P_ALLOCED)
10612 free_string_option(*(char_u **)(p->var));
10613 *(char_u **)(p->var) = empty_option;
10614 p->flags &= ~P_ALLOCED;
10615 break;
10616 }
10617}
10618
10619/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010620 * Set the terminal option defaults to the current value.
10621 * Used after setting the terminal name.
10622 */
10623 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010624set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010625{
10626 struct vimoption *p;
10627
10628 for (p = &options[0]; p->fullname != NULL; p++)
10629 {
10630 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10631 {
10632 if (p->flags & P_DEF_ALLOCED)
10633 {
10634 free_string_option(p->def_val[VI_DEFAULT]);
10635 p->flags &= ~P_DEF_ALLOCED;
10636 }
10637 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10638 if (p->flags & P_ALLOCED)
10639 {
10640 p->flags |= P_DEF_ALLOCED;
10641 p->flags &= ~P_ALLOCED; /* don't free the value now */
10642 }
10643 }
10644 }
10645}
10646
10647/*
10648 * return TRUE if 'p' starts with 't_'
10649 */
10650 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010651istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010652{
10653 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10654}
10655
10656/*
10657 * Compute columns for ruler and shown command. 'sc_col' is also used to
10658 * decide what the maximum length of a message on the status line can be.
10659 * If there is a status line for the last window, 'sc_col' is independent
10660 * of 'ru_col'.
10661 */
10662
10663#define COL_RULER 17 /* columns needed by standard ruler */
10664
10665 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010666comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010667{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010668#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010669 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010670
10671 sc_col = 0;
10672 ru_col = 0;
10673 if (p_ru)
10674 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010675# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010676 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010677# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010678 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010679# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010680 /* no last status line, adjust sc_col */
10681 if (!last_has_status)
10682 sc_col = ru_col;
10683 }
10684 if (p_sc)
10685 {
10686 sc_col += SHOWCMD_COLS;
10687 if (!p_ru || last_has_status) /* no need for separating space */
10688 ++sc_col;
10689 }
10690 sc_col = Columns - sc_col;
10691 ru_col = Columns - ru_col;
10692 if (sc_col <= 0) /* screen too narrow, will become a mess */
10693 sc_col = 1;
10694 if (ru_col <= 0)
10695 ru_col = 1;
10696#else
10697 sc_col = Columns;
10698 ru_col = Columns;
10699#endif
10700}
10701
Bram Moolenaar113e1072019-01-20 15:30:40 +010010702#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010703/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010704 * Unset local option value, similar to ":set opt<".
10705 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010706 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010707unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010708{
10709 struct vimoption *p;
10710 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010711 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010712
10713 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010714 if (opt_idx < 0)
10715 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010716 p = &(options[opt_idx]);
10717
10718 switch ((int)p->indir)
10719 {
10720 /* global option with local value: use local value if it's been set */
10721 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010722 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010723 break;
10724 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010725 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010726 break;
10727 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010728 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010729 break;
10730 case PV_AR:
10731 buf->b_p_ar = -1;
10732 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010733 case PV_BKC:
10734 clear_string_option(&buf->b_p_bkc);
10735 buf->b_bkc_flags = 0;
10736 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010737 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010738 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010739 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010740 case PV_TC:
10741 clear_string_option(&buf->b_p_tc);
10742 buf->b_tc_flags = 0;
10743 break;
Bram Moolenaar375e3392019-01-31 18:26:10 +010010744 case PV_SISO:
10745 curwin->w_p_siso = -1;
10746 break;
10747 case PV_SO:
10748 curwin->w_p_so = -1;
10749 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010750#ifdef FEAT_FIND_ID
10751 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010752 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010753 break;
10754 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010755 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010756 break;
10757#endif
10758#ifdef FEAT_INS_EXPAND
10759 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010760 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010761 break;
10762 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010763 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010764 break;
10765#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010766 case PV_FP:
10767 clear_string_option(&buf->b_p_fp);
10768 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010769#ifdef FEAT_QUICKFIX
10770 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010771 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010772 break;
10773 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010774 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010775 break;
10776 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010777 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010778 break;
10779#endif
10780#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10781 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010782 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010783 break;
10784#endif
10785#if defined(FEAT_CRYPT)
10786 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010787 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010788 break;
10789#endif
10790#ifdef FEAT_STL_OPT
10791 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010792 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010793 break;
10794#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010795 case PV_UL:
10796 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10797 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010798#ifdef FEAT_LISP
10799 case PV_LW:
10800 clear_string_option(&buf->b_p_lw);
10801 break;
10802#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010803 case PV_MENC:
10804 clear_string_option(&buf->b_p_menc);
10805 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010806 }
10807}
Bram Moolenaar113e1072019-01-20 15:30:40 +010010808#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010809
10810/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010811 * Get pointer to option variable, depending on local or global scope.
10812 */
10813 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010814get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010815{
10816 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10817 {
10818 if (p->var == VAR_WIN)
10819 return (char_u *)GLOBAL_WO(get_varp(p));
10820 return p->var;
10821 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010822 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010823 {
10824 switch ((int)p->indir)
10825 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010826 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010827#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010828 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10829 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10830 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010831#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010832 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10833 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10834 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010835 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010836 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010837 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar375e3392019-01-31 18:26:10 +010010838 case PV_SISO: return (char_u *)&(curwin->w_p_siso);
10839 case PV_SO: return (char_u *)&(curwin->w_p_so);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010840#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010841 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10842 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010843#endif
10844#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010845 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10846 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010847#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010848#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10849 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10850#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010851#if defined(FEAT_CRYPT)
10852 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10853#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010854#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010855 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010856#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010857 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010858#ifdef FEAT_LISP
10859 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10860#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010861 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010862 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010863 }
10864 return NULL; /* "cannot happen" */
10865 }
10866 return get_varp(p);
10867}
10868
10869/*
10870 * Get pointer to option variable.
10871 */
10872 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010873get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010874{
10875 /* hidden option, always return NULL */
10876 if (p->var == NULL)
10877 return NULL;
10878
10879 switch ((int)p->indir)
10880 {
10881 case PV_NONE: return p->var;
10882
10883 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010884 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010885 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010886 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010887 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010888 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010889 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010890 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010891 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010892 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010893 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010894 case PV_TC: return *curbuf->b_p_tc != NUL
10895 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010896 case PV_BKC: return *curbuf->b_p_bkc != NUL
10897 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar375e3392019-01-31 18:26:10 +010010898 case PV_SISO: return curwin->w_p_siso >= 0
10899 ? (char_u *)&(curwin->w_p_siso) : p->var;
10900 case PV_SO: return curwin->w_p_so >= 0
10901 ? (char_u *)&(curwin->w_p_so) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010902#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010903 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010904 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010905 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010906 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10907#endif
10908#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010909 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010910 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010911 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010912 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10913#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010914 case PV_FP: return *curbuf->b_p_fp != NUL
10915 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010916#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010917 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010918 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010919 case PV_GP: return *curbuf->b_p_gp != NUL
10920 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10921 case PV_MP: return *curbuf->b_p_mp != NUL
10922 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010923#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010924#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10925 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10926 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10927#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010928#if defined(FEAT_CRYPT)
10929 case PV_CM: return *curbuf->b_p_cm != NUL
10930 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10931#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010932#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010933 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010934 ? (char_u *)&(curwin->w_p_stl) : p->var;
10935#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010936 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10937 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010938#ifdef FEAT_LISP
10939 case PV_LW: return *curbuf->b_p_lw != NUL
10940 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10941#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010942 case PV_MENC: return *curbuf->b_p_menc != NUL
10943 ? (char_u *)&(curbuf->b_p_menc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010944
10945#ifdef FEAT_ARABIC
10946 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10947#endif
10948 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010949#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010950 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10951#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010952#ifdef FEAT_SYN_HL
10953 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10954 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010955 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010956#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010957#ifdef FEAT_DIFF
10958 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10959#endif
10960#ifdef FEAT_FOLDING
10961 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10962 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10963 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10964 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10965 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10966 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10967 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10968# ifdef FEAT_EVAL
10969 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10970 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10971# endif
10972 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10973#endif
10974 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010975 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010976#ifdef FEAT_LINEBREAK
10977 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10978#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010979 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010980 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020010981#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010982 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10983#endif
10984#ifdef FEAT_RIGHTLEFT
10985 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10986 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10987#endif
10988 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10989 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10990#ifdef FEAT_LINEBREAK
10991 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010992 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10993 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010994#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020010995 case PV_WCR: return (char_u *)&(curwin->w_p_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010996 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010997 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010998#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010999 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
11000 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
11001#endif
11002#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011003 case PV_TWK: return (char_u *)&(curwin->w_p_twk);
11004 case PV_TWS: return (char_u *)&(curwin->w_p_tws);
11005 case PV_TWSL: return (char_u *)&(curbuf->b_p_twsl);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011006#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011007
11008 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
11009 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011010 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011011 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
11012 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011013 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
11014 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
11015#ifdef FEAT_CINDENT
11016 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
11017 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
11018 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
11019#endif
11020#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11021 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
11022#endif
11023#ifdef FEAT_COMMENTS
11024 case PV_COM: return (char_u *)&(curbuf->b_p_com);
11025#endif
11026#ifdef FEAT_FOLDING
11027 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
11028#endif
11029#ifdef FEAT_INS_EXPAND
11030 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
11031#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011032#ifdef FEAT_COMPL_FUNC
11033 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011034 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011035#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +020011036#ifdef FEAT_EVAL
11037 case PV_TFU: return (char_u *)&(curbuf->b_p_tfu);
11038#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011039 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020011040 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011041 case PV_ET: return (char_u *)&(curbuf->b_p_et);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011042 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011043 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011044 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011045 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011046 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011047 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
11048 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
11049 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
11050 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
11051#ifdef FEAT_FIND_ID
11052# ifdef FEAT_EVAL
11053 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
11054# endif
11055#endif
11056#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11057 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
11058 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
11059#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011060#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011061 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
11062#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011063#ifdef FEAT_CRYPT
11064 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
11065#endif
11066#ifdef FEAT_LISP
11067 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
11068#endif
11069 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
11070 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
11071 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
11072 case PV_MOD: return (char_u *)&(curbuf->b_changed);
11073 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011074 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011075#ifdef FEAT_TEXTOBJ
11076 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
11077#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011078 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
11079#ifdef FEAT_SMARTINDENT
11080 case PV_SI: return (char_u *)&(curbuf->b_p_si);
11081#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011082 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011083 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
11084#ifdef FEAT_SEARCHPATH
11085 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
11086#endif
11087 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
11088#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011089 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011090 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
11091#endif
11092#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020011093 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
11094 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
11095 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011096#endif
11097 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
11098 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
11099 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
11100 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011101#ifdef FEAT_PERSISTENT_UNDO
11102 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
11103#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011104 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
11105#ifdef FEAT_KEYMAP
11106 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
11107#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011108#ifdef FEAT_SIGNS
11109 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
11110#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011111#ifdef FEAT_VARTABS
11112 case PV_VSTS: return (char_u *)&(curbuf->b_p_vsts);
11113 case PV_VTS: return (char_u *)&(curbuf->b_p_vts);
11114#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010011115 default: iemsg(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011116 }
11117 /* always return a valid pointer to avoid a crash! */
11118 return (char_u *)&(curbuf->b_p_wm);
11119}
11120
11121/*
11122 * Get the value of 'equalprg', either the buffer-local one or the global one.
11123 */
11124 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011125get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011126{
11127 if (*curbuf->b_p_ep == NUL)
11128 return p_ep;
11129 return curbuf->b_p_ep;
11130}
11131
Bram Moolenaar071d4272004-06-13 20:20:40 +000011132/*
11133 * Copy options from one window to another.
11134 * Used when splitting a window.
11135 */
11136 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011137win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011138{
11139 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
11140 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020011141#if defined(FEAT_LINEBREAK)
11142 briopt_check(wp_to);
11143#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011144}
Bram Moolenaar071d4272004-06-13 20:20:40 +000011145
11146/*
11147 * Copy the options from one winopt_T to another.
11148 * Doesn't free the old option values in "to", use clear_winopt() for that.
11149 * The 'scroll' option is not copied, because it depends on the window height.
11150 * The 'previewwindow' option is reset, there can be only one preview window.
11151 */
11152 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011153copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011154{
11155#ifdef FEAT_ARABIC
11156 to->wo_arab = from->wo_arab;
11157#endif
11158 to->wo_list = from->wo_list;
11159 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020011160 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011161#ifdef FEAT_LINEBREAK
11162 to->wo_nuw = from->wo_nuw;
11163#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011164#ifdef FEAT_RIGHTLEFT
11165 to->wo_rl = from->wo_rl;
11166 to->wo_rlc = vim_strsave(from->wo_rlc);
11167#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011168#ifdef FEAT_STL_OPT
11169 to->wo_stl = vim_strsave(from->wo_stl);
11170#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011171 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011172#ifdef FEAT_DIFF
11173 to->wo_wrap_save = from->wo_wrap_save;
11174#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011175#ifdef FEAT_LINEBREAK
11176 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020011177 to->wo_bri = from->wo_bri;
11178 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011179#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011180 to->wo_wcr = vim_strsave(from->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011181 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011182 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010011183 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011184 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011185#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000011186 to->wo_spell = from->wo_spell;
11187#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011188#ifdef FEAT_SYN_HL
11189 to->wo_cuc = from->wo_cuc;
11190 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020011191 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011192#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011193#ifdef FEAT_DIFF
11194 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011195 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011196#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011197#ifdef FEAT_CONCEAL
11198 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020011199 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011200#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011201#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011202 to->wo_twk = vim_strsave(from->wo_twk);
11203 to->wo_tws = vim_strsave(from->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011204#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011205#ifdef FEAT_FOLDING
11206 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011207 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011208 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011209 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011210 to->wo_fdi = vim_strsave(from->wo_fdi);
11211 to->wo_fml = from->wo_fml;
11212 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011213 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011214 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011215 to->wo_fdm_save = from->wo_diff_saved
11216 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011217 to->wo_fdn = from->wo_fdn;
11218# ifdef FEAT_EVAL
11219 to->wo_fde = vim_strsave(from->wo_fde);
11220 to->wo_fdt = vim_strsave(from->wo_fdt);
11221# endif
11222 to->wo_fmr = vim_strsave(from->wo_fmr);
11223#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011224#ifdef FEAT_SIGNS
11225 to->wo_scl = vim_strsave(from->wo_scl);
11226#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011227 check_winopt(to); /* don't want NULL pointers */
11228}
11229
11230/*
11231 * Check string options in a window for a NULL value.
11232 */
11233 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011234check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011235{
11236 check_winopt(&win->w_onebuf_opt);
11237 check_winopt(&win->w_allbuf_opt);
11238}
11239
11240/*
11241 * Check for NULL pointers in a winopt_T and replace them with empty_option.
11242 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020011243 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011244check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011245{
11246#ifdef FEAT_FOLDING
11247 check_string_option(&wop->wo_fdi);
11248 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011249 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011250# ifdef FEAT_EVAL
11251 check_string_option(&wop->wo_fde);
11252 check_string_option(&wop->wo_fdt);
11253# endif
11254 check_string_option(&wop->wo_fmr);
11255#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011256#ifdef FEAT_SIGNS
11257 check_string_option(&wop->wo_scl);
11258#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011259#ifdef FEAT_RIGHTLEFT
11260 check_string_option(&wop->wo_rlc);
11261#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011262#ifdef FEAT_STL_OPT
11263 check_string_option(&wop->wo_stl);
11264#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011265#ifdef FEAT_SYN_HL
11266 check_string_option(&wop->wo_cc);
11267#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011268#ifdef FEAT_CONCEAL
11269 check_string_option(&wop->wo_cocu);
11270#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011271#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011272 check_string_option(&wop->wo_twk);
11273 check_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011274#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011275#ifdef FEAT_LINEBREAK
11276 check_string_option(&wop->wo_briopt);
11277#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011278 check_string_option(&wop->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011279}
11280
11281/*
11282 * Free the allocated memory inside a winopt_T.
11283 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011284 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011285clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011286{
11287#ifdef FEAT_FOLDING
11288 clear_string_option(&wop->wo_fdi);
11289 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011290 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011291# ifdef FEAT_EVAL
11292 clear_string_option(&wop->wo_fde);
11293 clear_string_option(&wop->wo_fdt);
11294# endif
11295 clear_string_option(&wop->wo_fmr);
11296#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011297#ifdef FEAT_SIGNS
11298 clear_string_option(&wop->wo_scl);
11299#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011300#ifdef FEAT_LINEBREAK
11301 clear_string_option(&wop->wo_briopt);
11302#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011303 clear_string_option(&wop->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011304#ifdef FEAT_RIGHTLEFT
11305 clear_string_option(&wop->wo_rlc);
11306#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011307#ifdef FEAT_STL_OPT
11308 clear_string_option(&wop->wo_stl);
11309#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011310#ifdef FEAT_SYN_HL
11311 clear_string_option(&wop->wo_cc);
11312#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011313#ifdef FEAT_CONCEAL
11314 clear_string_option(&wop->wo_cocu);
11315#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011316#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011317 clear_string_option(&wop->wo_twk);
11318 clear_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011319#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011320}
11321
11322/*
11323 * Copy global option values to local options for one buffer.
11324 * Used when creating a new buffer and sometimes when entering a buffer.
11325 * flags:
11326 * BCO_ENTER We will enter the buf buffer.
11327 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11328 * appropriate.
11329 * BCO_NOHELP Don't copy the values to a help buffer.
11330 */
11331 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011332buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011333{
11334 int should_copy = TRUE;
11335 char_u *save_p_isk = NULL; /* init for GCC */
11336 int dont_do_help;
11337 int did_isk = FALSE;
11338
11339 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011340 * Skip this when the option defaults have not been set yet. Happens when
11341 * main() allocates the first buffer.
11342 */
11343 if (p_cpo != NULL)
11344 {
11345 /*
11346 * Always copy when entering and 'cpo' contains 'S'.
11347 * Don't copy when already initialized.
11348 * Don't copy when 'cpo' contains 's' and not entering.
11349 * 'S' BCO_ENTER initialized 's' should_copy
11350 * yes yes X X TRUE
11351 * yes no yes X FALSE
11352 * no X yes X FALSE
11353 * X no no yes FALSE
11354 * X no no no TRUE
11355 * no yes no X TRUE
11356 */
11357 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11358 && (buf->b_p_initialized
11359 || (!(flags & BCO_ENTER)
11360 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11361 should_copy = FALSE;
11362
11363 if (should_copy || (flags & BCO_ALWAYS))
11364 {
11365 /* Don't copy the options specific to a help buffer when
11366 * BCO_NOHELP is given or the options were initialized already
11367 * (jumping back to a help file with CTRL-T or CTRL-O) */
11368 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11369 || buf->b_p_initialized;
11370 if (dont_do_help) /* don't free b_p_isk */
11371 {
11372 save_p_isk = buf->b_p_isk;
11373 buf->b_p_isk = NULL;
11374 }
11375 /*
Bram Moolenaar40385db2018-08-07 22:31:44 +020011376 * Always free the allocated strings. If not already initialized,
11377 * reset 'readonly' and copy 'fileformat'.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011378 */
11379 if (!buf->b_p_initialized)
11380 {
11381 free_buf_options(buf, TRUE);
11382 buf->b_p_ro = FALSE; /* don't copy readonly */
11383 buf->b_p_tx = p_tx;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011384 buf->b_p_fenc = vim_strsave(p_fenc);
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011385 switch (*p_ffs)
11386 {
11387 case 'm':
11388 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11389 case 'd':
11390 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11391 case 'u':
11392 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11393 default:
11394 buf->b_p_ff = vim_strsave(p_ff);
11395 }
11396 if (buf->b_p_ff != NULL)
11397 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011398 buf->b_p_bh = empty_option;
11399 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011400 }
11401 else
11402 free_buf_options(buf, FALSE);
11403
11404 buf->b_p_ai = p_ai;
11405 buf->b_p_ai_nopaste = p_ai_nopaste;
11406 buf->b_p_sw = p_sw;
11407 buf->b_p_tw = p_tw;
11408 buf->b_p_tw_nopaste = p_tw_nopaste;
11409 buf->b_p_tw_nobin = p_tw_nobin;
11410 buf->b_p_wm = p_wm;
11411 buf->b_p_wm_nopaste = p_wm_nopaste;
11412 buf->b_p_wm_nobin = p_wm_nobin;
11413 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011414 buf->b_p_bomb = p_bomb;
Bram Moolenaarb388be02015-07-22 22:19:38 +020011415 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011416 buf->b_p_et = p_et;
11417 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011418 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011419 buf->b_p_ml = p_ml;
11420 buf->b_p_ml_nobin = p_ml_nobin;
11421 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011422 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011423#ifdef FEAT_INS_EXPAND
11424 buf->b_p_cpt = vim_strsave(p_cpt);
11425#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011426#ifdef FEAT_COMPL_FUNC
11427 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011428 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011429#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +020011430#ifdef FEAT_EVAL
11431 buf->b_p_tfu = vim_strsave(p_tfu);
11432#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011433 buf->b_p_sts = p_sts;
11434 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011435#ifdef FEAT_VARTABS
11436 buf->b_p_vsts = vim_strsave(p_vsts);
11437 if (p_vsts && p_vsts != empty_option)
11438 tabstop_set(p_vsts, &buf->b_p_vsts_array);
11439 else
11440 buf->b_p_vsts_array = 0;
11441 buf->b_p_vsts_nopaste = p_vsts_nopaste
11442 ? vim_strsave(p_vsts_nopaste) : NULL;
11443#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011444 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011445#ifdef FEAT_COMMENTS
11446 buf->b_p_com = vim_strsave(p_com);
11447#endif
11448#ifdef FEAT_FOLDING
11449 buf->b_p_cms = vim_strsave(p_cms);
11450#endif
11451 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011452 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011453 buf->b_p_nf = vim_strsave(p_nf);
11454 buf->b_p_mps = vim_strsave(p_mps);
11455#ifdef FEAT_SMARTINDENT
11456 buf->b_p_si = p_si;
11457#endif
11458 buf->b_p_ci = p_ci;
11459#ifdef FEAT_CINDENT
11460 buf->b_p_cin = p_cin;
11461 buf->b_p_cink = vim_strsave(p_cink);
11462 buf->b_p_cino = vim_strsave(p_cino);
11463#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011464 /* Don't copy 'filetype', it must be detected */
11465 buf->b_p_ft = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011466 buf->b_p_pi = p_pi;
11467#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11468 buf->b_p_cinw = vim_strsave(p_cinw);
11469#endif
11470#ifdef FEAT_LISP
11471 buf->b_p_lisp = p_lisp;
11472#endif
11473#ifdef FEAT_SYN_HL
11474 /* Don't copy 'syntax', it must be set */
11475 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011476 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011477 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011478#endif
11479#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011480 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011481 (void)compile_cap_prog(&buf->b_s);
11482 buf->b_s.b_p_spf = vim_strsave(p_spf);
11483 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011484#endif
11485#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11486 buf->b_p_inde = vim_strsave(p_inde);
11487 buf->b_p_indk = vim_strsave(p_indk);
11488#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011489 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011490#if defined(FEAT_EVAL)
11491 buf->b_p_fex = vim_strsave(p_fex);
11492#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011493#ifdef FEAT_CRYPT
11494 buf->b_p_key = vim_strsave(p_key);
11495#endif
11496#ifdef FEAT_SEARCHPATH
11497 buf->b_p_sua = vim_strsave(p_sua);
11498#endif
11499#ifdef FEAT_KEYMAP
11500 buf->b_p_keymap = vim_strsave(p_keymap);
11501 buf->b_kmap_state |= KEYMAP_INIT;
11502#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011503#ifdef FEAT_TERMINAL
11504 buf->b_p_twsl = p_twsl;
11505#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011506 /* This isn't really an option, but copying the langmap and IME
11507 * state from the current buffer is better than resetting it. */
11508 buf->b_p_iminsert = p_iminsert;
11509 buf->b_p_imsearch = p_imsearch;
11510
11511 /* options that are normally global but also have a local value
11512 * are not copied, start using the global value */
11513 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011514 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011515 buf->b_p_bkc = empty_option;
11516 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011517#ifdef FEAT_QUICKFIX
11518 buf->b_p_gp = empty_option;
11519 buf->b_p_mp = empty_option;
11520 buf->b_p_efm = empty_option;
11521#endif
11522 buf->b_p_ep = empty_option;
11523 buf->b_p_kp = empty_option;
11524 buf->b_p_path = empty_option;
11525 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011526 buf->b_p_tc = empty_option;
11527 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011528#ifdef FEAT_FIND_ID
11529 buf->b_p_def = empty_option;
11530 buf->b_p_inc = empty_option;
11531# ifdef FEAT_EVAL
11532 buf->b_p_inex = vim_strsave(p_inex);
11533# endif
11534#endif
11535#ifdef FEAT_INS_EXPAND
11536 buf->b_p_dict = empty_option;
11537 buf->b_p_tsr = empty_option;
11538#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011539#ifdef FEAT_TEXTOBJ
11540 buf->b_p_qe = vim_strsave(p_qe);
11541#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011542#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11543 buf->b_p_bexpr = empty_option;
11544#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011545#if defined(FEAT_CRYPT)
11546 buf->b_p_cm = empty_option;
11547#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011548#ifdef FEAT_PERSISTENT_UNDO
11549 buf->b_p_udf = p_udf;
11550#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011551#ifdef FEAT_LISP
11552 buf->b_p_lw = empty_option;
11553#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011554 buf->b_p_menc = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011555
11556 /*
11557 * Don't copy the options set by ex_help(), use the saved values,
11558 * when going from a help buffer to a non-help buffer.
11559 * Don't touch these at all when BCO_NOHELP is used and going from
11560 * or to a help buffer.
11561 */
11562 if (dont_do_help)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011563 {
Bram Moolenaar071d4272004-06-13 20:20:40 +000011564 buf->b_p_isk = save_p_isk;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011565#ifdef FEAT_VARTABS
11566 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11567 tabstop_set(p_vts, &buf->b_p_vts_array);
11568 else
11569 buf->b_p_vts_array = NULL;
11570#endif
11571 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011572 else
11573 {
11574 buf->b_p_isk = vim_strsave(p_isk);
11575 did_isk = TRUE;
11576 buf->b_p_ts = p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011577#ifdef FEAT_VARTABS
11578 buf->b_p_vts = vim_strsave(p_vts);
11579 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11580 tabstop_set(p_vts, &buf->b_p_vts_array);
11581 else
11582 buf->b_p_vts_array = NULL;
11583#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011584 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011585 if (buf->b_p_bt[0] == 'h')
11586 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011587 buf->b_p_ma = p_ma;
11588 }
11589 }
11590
11591 /*
11592 * When the options should be copied (ignoring BCO_ALWAYS), set the
11593 * flag that indicates that the options have been initialized.
11594 */
11595 if (should_copy)
11596 buf->b_p_initialized = TRUE;
11597 }
11598
11599 check_buf_options(buf); /* make sure we don't have NULLs */
11600 if (did_isk)
11601 (void)buf_init_chartab(buf, FALSE);
11602}
11603
11604/*
11605 * Reset the 'modifiable' option and its default value.
11606 */
11607 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011608reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011609{
11610 int opt_idx;
11611
11612 curbuf->b_p_ma = FALSE;
11613 p_ma = FALSE;
11614 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011615 if (opt_idx >= 0)
11616 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011617}
11618
11619/*
11620 * Set the global value for 'iminsert' to the local value.
11621 */
11622 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011623set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011624{
11625 p_iminsert = curbuf->b_p_iminsert;
11626}
11627
11628/*
11629 * Set the global value for 'imsearch' to the local value.
11630 */
11631 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011632set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011633{
11634 p_imsearch = curbuf->b_p_imsearch;
11635}
11636
11637#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11638static int expand_option_idx = -1;
11639static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11640static int expand_option_flags = 0;
11641
11642 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011643set_context_in_set_cmd(
11644 expand_T *xp,
11645 char_u *arg,
11646 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011647{
11648 int nextchar;
11649 long_u flags = 0; /* init for GCC */
11650 int opt_idx = 0; /* init for GCC */
11651 char_u *p;
11652 char_u *s;
11653 int is_term_option = FALSE;
11654 int key;
11655
11656 expand_option_flags = opt_flags;
11657
11658 xp->xp_context = EXPAND_SETTINGS;
11659 if (*arg == NUL)
11660 {
11661 xp->xp_pattern = arg;
11662 return;
11663 }
11664 p = arg + STRLEN(arg) - 1;
11665 if (*p == ' ' && *(p - 1) != '\\')
11666 {
11667 xp->xp_pattern = p + 1;
11668 return;
11669 }
11670 while (p > arg)
11671 {
11672 s = p;
11673 /* count number of backslashes before ' ' or ',' */
11674 if (*p == ' ' || *p == ',')
11675 {
11676 while (s > arg && *(s - 1) == '\\')
11677 --s;
11678 }
11679 /* break at a space with an even number of backslashes */
11680 if (*p == ' ' && ((p - s) & 1) == 0)
11681 {
11682 ++p;
11683 break;
11684 }
11685 --p;
11686 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011687 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011688 {
11689 xp->xp_context = EXPAND_BOOL_SETTINGS;
11690 p += 2;
11691 }
11692 if (STRNCMP(p, "inv", 3) == 0)
11693 {
11694 xp->xp_context = EXPAND_BOOL_SETTINGS;
11695 p += 3;
11696 }
11697 xp->xp_pattern = arg = p;
11698 if (*arg == '<')
11699 {
11700 while (*p != '>')
11701 if (*p++ == NUL) /* expand terminal option name */
11702 return;
11703 key = get_special_key_code(arg + 1);
11704 if (key == 0) /* unknown name */
11705 {
11706 xp->xp_context = EXPAND_NOTHING;
11707 return;
11708 }
11709 nextchar = *++p;
11710 is_term_option = TRUE;
11711 expand_option_name[2] = KEY2TERMCAP0(key);
11712 expand_option_name[3] = KEY2TERMCAP1(key);
11713 }
11714 else
11715 {
11716 if (p[0] == 't' && p[1] == '_')
11717 {
11718 p += 2;
11719 if (*p != NUL)
11720 ++p;
11721 if (*p == NUL)
11722 return; /* expand option name */
11723 nextchar = *++p;
11724 is_term_option = TRUE;
11725 expand_option_name[2] = p[-2];
11726 expand_option_name[3] = p[-1];
11727 }
11728 else
11729 {
11730 /* Allow * wildcard */
11731 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11732 p++;
11733 if (*p == NUL)
11734 return;
11735 nextchar = *p;
11736 *p = NUL;
11737 opt_idx = findoption(arg);
11738 *p = nextchar;
11739 if (opt_idx == -1 || options[opt_idx].var == NULL)
11740 {
11741 xp->xp_context = EXPAND_NOTHING;
11742 return;
11743 }
11744 flags = options[opt_idx].flags;
11745 if (flags & P_BOOL)
11746 {
11747 xp->xp_context = EXPAND_NOTHING;
11748 return;
11749 }
11750 }
11751 }
11752 /* handle "-=" and "+=" */
11753 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11754 {
11755 ++p;
11756 nextchar = '=';
11757 }
11758 if ((nextchar != '=' && nextchar != ':')
11759 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11760 {
11761 xp->xp_context = EXPAND_UNSUCCESSFUL;
11762 return;
11763 }
11764 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11765 {
11766 xp->xp_context = EXPAND_OLD_SETTING;
11767 if (is_term_option)
11768 expand_option_idx = -1;
11769 else
11770 expand_option_idx = opt_idx;
11771 xp->xp_pattern = p + 1;
11772 return;
11773 }
11774 xp->xp_context = EXPAND_NOTHING;
11775 if (is_term_option || (flags & P_NUM))
11776 return;
11777
11778 xp->xp_pattern = p + 1;
11779
11780 if (flags & P_EXPAND)
11781 {
11782 p = options[opt_idx].var;
11783 if (p == (char_u *)&p_bdir
11784 || p == (char_u *)&p_dir
11785 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011786 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011787 || p == (char_u *)&p_rtp
11788#ifdef FEAT_SEARCHPATH
11789 || p == (char_u *)&p_cdpath
11790#endif
11791#ifdef FEAT_SESSION
11792 || p == (char_u *)&p_vdir
11793#endif
11794 )
11795 {
11796 xp->xp_context = EXPAND_DIRECTORIES;
11797 if (p == (char_u *)&p_path
11798#ifdef FEAT_SEARCHPATH
11799 || p == (char_u *)&p_cdpath
11800#endif
11801 )
11802 xp->xp_backslash = XP_BS_THREE;
11803 else
11804 xp->xp_backslash = XP_BS_ONE;
11805 }
11806 else
11807 {
11808 xp->xp_context = EXPAND_FILES;
11809 /* for 'tags' need three backslashes for a space */
11810 if (p == (char_u *)&p_tags)
11811 xp->xp_backslash = XP_BS_THREE;
11812 else
11813 xp->xp_backslash = XP_BS_ONE;
11814 }
11815 }
11816
11817 /* For an option that is a list of file names, find the start of the
11818 * last file name. */
11819 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11820 {
11821 /* count number of backslashes before ' ' or ',' */
11822 if (*p == ' ' || *p == ',')
11823 {
11824 s = p;
11825 while (s > xp->xp_pattern && *(s - 1) == '\\')
11826 --s;
11827 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11828 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11829 {
11830 xp->xp_pattern = p + 1;
11831 break;
11832 }
11833 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011834
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011835#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011836 /* for 'spellsuggest' start at "file:" */
11837 if (options[opt_idx].var == (char_u *)&p_sps
11838 && STRNCMP(p, "file:", 5) == 0)
11839 {
11840 xp->xp_pattern = p + 5;
11841 break;
11842 }
11843#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011844 }
11845
11846 return;
11847}
11848
11849 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011850ExpandSettings(
11851 expand_T *xp,
11852 regmatch_T *regmatch,
11853 int *num_file,
11854 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011855{
11856 int num_normal = 0; /* Nr of matching non-term-code settings */
11857 int num_term = 0; /* Nr of matching terminal code settings */
11858 int opt_idx;
11859 int match;
11860 int count = 0;
11861 char_u *str;
11862 int loop;
11863 int is_term_opt;
11864 char_u name_buf[MAX_KEY_NAME_LEN];
11865 static char *(names[]) = {"all", "termcap"};
11866 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11867
11868 /* do this loop twice:
11869 * loop == 0: count the number of matching options
11870 * loop == 1: copy the matching options into allocated memory
11871 */
11872 for (loop = 0; loop <= 1; ++loop)
11873 {
11874 regmatch->rm_ic = ic;
11875 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11876 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011877 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11878 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011879 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11880 {
11881 if (loop == 0)
11882 num_normal++;
11883 else
11884 (*file)[count++] = vim_strsave((char_u *)names[match]);
11885 }
11886 }
11887 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11888 opt_idx++)
11889 {
11890 if (options[opt_idx].var == NULL)
11891 continue;
11892 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11893 && !(options[opt_idx].flags & P_BOOL))
11894 continue;
11895 is_term_opt = istermoption(&options[opt_idx]);
11896 if (is_term_opt && num_normal > 0)
11897 continue;
11898 match = FALSE;
11899 if (vim_regexec(regmatch, str, (colnr_T)0)
11900 || (options[opt_idx].shortname != NULL
11901 && vim_regexec(regmatch,
11902 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11903 match = TRUE;
11904 else if (is_term_opt)
11905 {
11906 name_buf[0] = '<';
11907 name_buf[1] = 't';
11908 name_buf[2] = '_';
11909 name_buf[3] = str[2];
11910 name_buf[4] = str[3];
11911 name_buf[5] = '>';
11912 name_buf[6] = NUL;
11913 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11914 {
11915 match = TRUE;
11916 str = name_buf;
11917 }
11918 }
11919 if (match)
11920 {
11921 if (loop == 0)
11922 {
11923 if (is_term_opt)
11924 num_term++;
11925 else
11926 num_normal++;
11927 }
11928 else
11929 (*file)[count++] = vim_strsave(str);
11930 }
11931 }
11932 /*
11933 * Check terminal key codes, these are not in the option table
11934 */
11935 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11936 {
11937 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11938 {
11939 if (!isprint(str[0]) || !isprint(str[1]))
11940 continue;
11941
11942 name_buf[0] = 't';
11943 name_buf[1] = '_';
11944 name_buf[2] = str[0];
11945 name_buf[3] = str[1];
11946 name_buf[4] = NUL;
11947
11948 match = FALSE;
11949 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11950 match = TRUE;
11951 else
11952 {
11953 name_buf[0] = '<';
11954 name_buf[1] = 't';
11955 name_buf[2] = '_';
11956 name_buf[3] = str[0];
11957 name_buf[4] = str[1];
11958 name_buf[5] = '>';
11959 name_buf[6] = NUL;
11960
11961 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11962 match = TRUE;
11963 }
11964 if (match)
11965 {
11966 if (loop == 0)
11967 num_term++;
11968 else
11969 (*file)[count++] = vim_strsave(name_buf);
11970 }
11971 }
11972
11973 /*
11974 * Check special key names.
11975 */
11976 regmatch->rm_ic = TRUE; /* ignore case here */
11977 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11978 {
11979 name_buf[0] = '<';
11980 STRCPY(name_buf + 1, str);
11981 STRCAT(name_buf, ">");
11982
11983 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11984 {
11985 if (loop == 0)
11986 num_term++;
11987 else
11988 (*file)[count++] = vim_strsave(name_buf);
11989 }
11990 }
11991 }
11992 if (loop == 0)
11993 {
11994 if (num_normal > 0)
11995 *num_file = num_normal;
11996 else if (num_term > 0)
11997 *num_file = num_term;
11998 else
11999 return OK;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020012000 *file = ALLOC_MULT(char_u *, *num_file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012001 if (*file == NULL)
12002 {
12003 *file = (char_u **)"";
12004 return FAIL;
12005 }
12006 }
12007 }
12008 return OK;
12009}
12010
12011 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012012ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012013{
12014 char_u *var = NULL; /* init for GCC */
12015 char_u *buf;
12016
12017 *num_file = 0;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020012018 *file = ALLOC_ONE(char_u *);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012019 if (*file == NULL)
12020 return FAIL;
12021
12022 /*
12023 * For a terminal key code expand_option_idx is < 0.
12024 */
12025 if (expand_option_idx < 0)
12026 {
12027 var = find_termcode(expand_option_name + 2);
12028 if (var == NULL)
12029 expand_option_idx = findoption(expand_option_name);
12030 }
12031
12032 if (expand_option_idx >= 0)
12033 {
12034 /* put string of option value in NameBuff */
12035 option_value2string(&options[expand_option_idx], expand_option_flags);
12036 var = NameBuff;
12037 }
12038 else if (var == NULL)
12039 var = (char_u *)"";
12040
12041 /* A backslash is required before some characters. This is the reverse of
12042 * what happens in do_set(). */
12043 buf = vim_strsave_escaped(var, escape_chars);
12044
12045 if (buf == NULL)
12046 {
Bram Moolenaard23a8232018-02-10 18:45:26 +010012047 VIM_CLEAR(*file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012048 return FAIL;
12049 }
12050
12051#ifdef BACKSLASH_IN_FILENAME
12052 /* For MS-Windows et al. we don't double backslashes at the start and
12053 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012054 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012055 if (var[0] == '\\' && var[1] == '\\'
12056 && expand_option_idx >= 0
12057 && (options[expand_option_idx].flags & P_EXPAND)
12058 && vim_isfilec(var[2])
12059 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000012060 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012061#endif
12062
12063 *file[0] = buf;
12064 *num_file = 1;
12065 return OK;
12066}
12067#endif
12068
12069/*
12070 * Get the value for the numeric or string option *opp in a nice format into
12071 * NameBuff[]. Must not be called with a hidden option!
12072 */
12073 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012074option_value2string(
12075 struct vimoption *opp,
12076 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012077{
12078 char_u *varp;
12079
12080 varp = get_varp_scope(opp, opt_flags);
12081
12082 if (opp->flags & P_NUM)
12083 {
12084 long wc = 0;
12085
12086 if (wc_use_keyname(varp, &wc))
12087 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
12088 else if (wc != 0)
12089 STRCPY(NameBuff, transchar((int)wc));
12090 else
12091 sprintf((char *)NameBuff, "%ld", *(long *)varp);
12092 }
12093 else /* P_STRING */
12094 {
12095 varp = *(char_u **)(varp);
12096 if (varp == NULL) /* just in case */
12097 NameBuff[0] = NUL;
12098#ifdef FEAT_CRYPT
12099 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000012100 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012101 STRCPY(NameBuff, "*****");
12102#endif
12103 else if (opp->flags & P_EXPAND)
12104 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
12105 /* Translate 'pastetoggle' into special key names */
12106 else if ((char_u **)opp->var == &p_pt)
12107 str2specialbuf(p_pt, NameBuff, MAXPATHL);
12108 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000012109 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012110 }
12111}
12112
12113/*
12114 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
12115 * printed as a keyname.
12116 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
12117 */
12118 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012119wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012120{
12121 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
12122 {
12123 *wcp = *(long *)varp;
12124 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
12125 return TRUE;
12126 }
12127 return FALSE;
12128}
12129
Bram Moolenaar01615492015-02-03 13:00:38 +010012130#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012131/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012132 * Any character has an equivalent 'langmap' character. This is used for
12133 * keyboards that have a special language mode that sends characters above
12134 * 128 (although other characters can be translated too). The "to" field is a
12135 * Vim command character. This avoids having to switch the keyboard back to
12136 * ASCII mode when leaving Insert mode.
12137 *
12138 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
12139 * commands.
Bram Moolenaarfc3abf42019-01-24 15:54:21 +010012140 * langmap_mapga.ga_data is a sorted table of langmap_entry_T. This does the
12141 * same as langmap_mapchar[] for characters >= 256.
12142 *
12143 * Use growarray for 'langmap' chars >= 256
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012144 */
12145typedef struct
12146{
12147 int from;
12148 int to;
12149} langmap_entry_T;
12150
12151static garray_T langmap_mapga;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012152
12153/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012154 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
12155 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012156 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012157 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012158langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012159{
12160 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020012161 int a = 0;
12162 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012163
12164 /* Do a binary search for an existing entry. */
12165 while (a != b)
12166 {
12167 int i = (a + b) / 2;
12168 int d = entries[i].from - from;
12169
12170 if (d == 0)
12171 {
12172 entries[i].to = to;
12173 return;
12174 }
12175 if (d < 0)
12176 a = i + 1;
12177 else
12178 b = i;
12179 }
12180
12181 if (ga_grow(&langmap_mapga, 1) != OK)
12182 return; /* out of memory */
12183
12184 /* insert new entry at position "a" */
12185 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
12186 mch_memmove(entries + 1, entries,
12187 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
12188 ++langmap_mapga.ga_len;
12189 entries[0].from = from;
12190 entries[0].to = to;
12191}
12192
12193/*
12194 * Apply 'langmap' to multi-byte character "c" and return the result.
12195 */
12196 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012197langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012198{
12199 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
12200 int a = 0;
12201 int b = langmap_mapga.ga_len;
12202
12203 while (a != b)
12204 {
12205 int i = (a + b) / 2;
12206 int d = entries[i].from - c;
12207
12208 if (d == 0)
12209 return entries[i].to; /* found matching entry */
12210 if (d < 0)
12211 a = i + 1;
12212 else
12213 b = i;
12214 }
12215 return c; /* no entry found, return "c" unmodified */
12216}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012217
12218 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012219langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012220{
12221 int i;
12222
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012223 for (i = 0; i < 256; i++)
12224 langmap_mapchar[i] = i; /* we init with a one-to-one map */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012225 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012226}
12227
12228/*
12229 * Called when langmap option is set; the language map can be
12230 * changed at any time!
12231 */
12232 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012233langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012234{
12235 char_u *p;
12236 char_u *p2;
12237 int from, to;
12238
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012239 ga_clear(&langmap_mapga); /* clear the previous map first */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012240 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012241
12242 for (p = p_langmap; p[0] != NUL; )
12243 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000012244 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012245 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012246 {
12247 if (p2[0] == '\\' && p2[1] != NUL)
12248 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012249 }
12250 if (p2[0] == ';')
12251 ++p2; /* abcd;ABCD form, p2 points to A */
12252 else
12253 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
12254 while (p[0])
12255 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012256 if (p[0] == ',')
12257 {
12258 ++p;
12259 break;
12260 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012261 if (p[0] == '\\' && p[1] != NUL)
12262 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012263 from = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012264 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012265 if (p2 == NULL)
12266 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012267 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012268 if (p[0] != ',')
12269 {
12270 if (p[0] == '\\')
12271 ++p;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012272 to = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012273 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012274 }
12275 else
12276 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012277 if (p2[0] != ',')
12278 {
12279 if (p2[0] == '\\')
12280 ++p2;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012281 to = (*mb_ptr2char)(p2);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012282 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012283 }
12284 if (to == NUL)
12285 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012286 semsg(_("E357: 'langmap': Matching character missing for %s"),
Bram Moolenaar071d4272004-06-13 20:20:40 +000012287 transchar(from));
12288 return;
12289 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012290
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012291 if (from >= 256)
12292 langmap_set_entry(from, to);
12293 else
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012294 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012295
12296 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012297 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012298 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012299 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012300 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012301 if (*p == ';')
12302 {
12303 p = p2;
12304 if (p[0] != NUL)
12305 {
12306 if (p[0] != ',')
12307 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012308 semsg(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012309 return;
12310 }
12311 ++p;
12312 }
12313 break;
12314 }
12315 }
12316 }
12317 }
12318}
12319#endif
12320
12321/*
12322 * Return TRUE if format option 'x' is in effect.
12323 * Take care of no formatting when 'paste' is set.
12324 */
12325 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012326has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012327{
12328 if (p_paste)
12329 return FALSE;
12330 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12331}
12332
12333/*
12334 * Return TRUE if "x" is present in 'shortmess' option, or
12335 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12336 */
12337 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012338shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012339{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012340 return p_shm != NULL &&
12341 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012342 || (vim_strchr(p_shm, 'a') != NULL
12343 && vim_strchr((char_u *)SHM_A, x) != NULL));
12344}
12345
12346/*
12347 * paste_option_changed() - Called after p_paste was set or reset.
12348 */
12349 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012350paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012351{
12352 static int old_p_paste = FALSE;
12353 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012354 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012355#ifdef FEAT_CMDL_INFO
12356 static int save_ru = 0;
12357#endif
12358#ifdef FEAT_RIGHTLEFT
12359 static int save_ri = 0;
12360 static int save_hkmap = 0;
12361#endif
12362 buf_T *buf;
12363
12364 if (p_paste)
12365 {
12366 /*
12367 * Paste switched from off to on.
12368 * Save the current values, so they can be restored later.
12369 */
12370 if (!old_p_paste)
12371 {
12372 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012373 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012374 {
12375 buf->b_p_tw_nopaste = buf->b_p_tw;
12376 buf->b_p_wm_nopaste = buf->b_p_wm;
12377 buf->b_p_sts_nopaste = buf->b_p_sts;
12378 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012379 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012380#ifdef FEAT_VARTABS
12381 if (buf->b_p_vsts_nopaste)
12382 vim_free(buf->b_p_vsts_nopaste);
12383 buf->b_p_vsts_nopaste = buf->b_p_vsts && buf->b_p_vsts != empty_option
12384 ? vim_strsave(buf->b_p_vsts) : NULL;
12385#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012386 }
12387
12388 /* save global options */
12389 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012390 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012391#ifdef FEAT_CMDL_INFO
12392 save_ru = p_ru;
12393#endif
12394#ifdef FEAT_RIGHTLEFT
12395 save_ri = p_ri;
12396 save_hkmap = p_hkmap;
12397#endif
12398 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012399 p_ai_nopaste = p_ai;
12400 p_et_nopaste = p_et;
12401 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012402 p_tw_nopaste = p_tw;
12403 p_wm_nopaste = p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012404#ifdef FEAT_VARTABS
12405 if (p_vsts_nopaste)
12406 vim_free(p_vsts_nopaste);
12407 p_vsts_nopaste = p_vsts && p_vsts != empty_option ? vim_strsave(p_vsts) : NULL;
12408#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012409 }
12410
12411 /*
12412 * Always set the option values, also when 'paste' is set when it is
12413 * already on.
12414 */
12415 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012416 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012417 {
12418 buf->b_p_tw = 0; /* textwidth is 0 */
12419 buf->b_p_wm = 0; /* wrapmargin is 0 */
12420 buf->b_p_sts = 0; /* softtabstop is 0 */
12421 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012422 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012423#ifdef FEAT_VARTABS
12424 if (buf->b_p_vsts)
12425 free_string_option(buf->b_p_vsts);
12426 buf->b_p_vsts = empty_option;
12427 if (buf->b_p_vsts_array)
12428 vim_free(buf->b_p_vsts_array);
12429 buf->b_p_vsts_array = 0;
12430#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012431 }
12432
12433 /* set global options */
12434 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012435 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012436#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012437 if (p_ru)
12438 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012439 p_ru = 0; /* no ruler */
12440#endif
12441#ifdef FEAT_RIGHTLEFT
12442 p_ri = 0; /* no reverse insert */
12443 p_hkmap = 0; /* no Hebrew keyboard */
12444#endif
12445 /* set global values for local buffer options */
12446 p_tw = 0;
12447 p_wm = 0;
12448 p_sts = 0;
12449 p_ai = 0;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012450#ifdef FEAT_VARTABS
12451 if (p_vsts)
12452 free_string_option(p_vsts);
12453 p_vsts = empty_option;
12454#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012455 }
12456
12457 /*
12458 * Paste switched from on to off: Restore saved values.
12459 */
12460 else if (old_p_paste)
12461 {
12462 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012463 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012464 {
12465 buf->b_p_tw = buf->b_p_tw_nopaste;
12466 buf->b_p_wm = buf->b_p_wm_nopaste;
12467 buf->b_p_sts = buf->b_p_sts_nopaste;
12468 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012469 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012470#ifdef FEAT_VARTABS
12471 if (buf->b_p_vsts)
12472 free_string_option(buf->b_p_vsts);
12473 buf->b_p_vsts = buf->b_p_vsts_nopaste
12474 ? vim_strsave(buf->b_p_vsts_nopaste) : empty_option;
12475 if (buf->b_p_vsts_array)
12476 vim_free(buf->b_p_vsts_array);
12477 if (buf->b_p_vsts && buf->b_p_vsts != empty_option)
12478 tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array);
12479 else
12480 buf->b_p_vsts_array = 0;
12481#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012482 }
12483
12484 /* restore global options */
12485 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012486 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012487#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012488 if (p_ru != save_ru)
12489 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012490 p_ru = save_ru;
12491#endif
12492#ifdef FEAT_RIGHTLEFT
12493 p_ri = save_ri;
12494 p_hkmap = save_hkmap;
12495#endif
12496 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012497 p_ai = p_ai_nopaste;
12498 p_et = p_et_nopaste;
12499 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012500 p_tw = p_tw_nopaste;
12501 p_wm = p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012502#ifdef FEAT_VARTABS
12503 if (p_vsts)
12504 free_string_option(p_vsts);
12505 p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option;
12506#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012507 }
12508
12509 old_p_paste = p_paste;
12510}
12511
12512/*
12513 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12514 *
12515 * Reset 'compatible' and set the values for options that didn't get set yet
12516 * to the Vim defaults.
12517 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012518 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012519 */
12520 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012521vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012522{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012523 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012524 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012525 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012526
12527 if (!option_was_set((char_u *)"cp"))
12528 {
12529 p_cp = FALSE;
12530 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12531 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12532 set_option_default(opt_idx, OPT_FREE, FALSE);
12533 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012534 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012535 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012536
12537 if (fname != NULL)
12538 {
12539 p = vim_getenv(envname, &dofree);
12540 if (p == NULL)
12541 {
12542 /* Set $MYVIMRC to the first vimrc file found. */
12543 p = FullName_save(fname, FALSE);
12544 if (p != NULL)
12545 {
12546 vim_setenv(envname, p);
12547 vim_free(p);
12548 }
12549 }
12550 else if (dofree)
12551 vim_free(p);
12552 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012553}
12554
12555/*
12556 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12557 */
12558 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012559change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012560{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012561 int opt_idx;
12562
Bram Moolenaar071d4272004-06-13 20:20:40 +000012563 if (p_cp != on)
12564 {
12565 p_cp = on;
12566 compatible_set();
12567 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012568 opt_idx = findoption((char_u *)"cp");
12569 if (opt_idx >= 0)
12570 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012571}
12572
12573/*
12574 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012575 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012576 */
12577 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012578option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012579{
12580 int idx;
12581
12582 idx = findoption(name);
12583 if (idx < 0) /* unknown option */
12584 return FALSE;
12585 if (options[idx].flags & P_WAS_SET)
12586 return TRUE;
12587 return FALSE;
12588}
12589
12590/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012591 * Reset the flag indicating option "name" was set.
12592 */
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012593 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012594reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012595{
12596 int idx = findoption(name);
12597
12598 if (idx >= 0)
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012599 {
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012600 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012601 return OK;
12602 }
12603 return FAIL;
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012604}
12605
12606/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012607 * compatible_set() - Called when 'compatible' has been set or unset.
12608 *
12609 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12610 * flag) to a Vi compatible value.
12611 * When 'compatible' is unset: Set all options that have a different default
12612 * for Vim (without the P_VI_DEF flag) to that default.
12613 */
12614 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012615compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012616{
12617 int opt_idx;
12618
12619 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12620 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12621 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12622 set_option_default(opt_idx, OPT_FREE, p_cp);
12623 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012624 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012625}
12626
12627#ifdef FEAT_LINEBREAK
12628
Bram Moolenaar071d4272004-06-13 20:20:40 +000012629/*
12630 * fill_breakat_flags() -- called when 'breakat' changes value.
12631 */
12632 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012633fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012634{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012635 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012636 int i;
12637
12638 for (i = 0; i < 256; i++)
12639 breakat_flags[i] = FALSE;
12640
12641 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012642 for (p = p_breakat; *p; p++)
12643 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012644}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012645#endif
12646
12647/*
12648 * Check an option that can be a range of string values.
12649 *
12650 * Return OK for correct value, FAIL otherwise.
12651 * Empty is always OK.
12652 */
12653 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012654check_opt_strings(
12655 char_u *val,
12656 char **values,
12657 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012658{
12659 return opt_strings_flags(val, values, NULL, list);
12660}
12661
12662/*
12663 * Handle an option that can be a range of string values.
12664 * Set a flag in "*flagp" for each string present.
12665 *
12666 * Return OK for correct value, FAIL otherwise.
12667 * Empty is always OK.
12668 */
12669 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012670opt_strings_flags(
12671 char_u *val, /* new value */
12672 char **values, /* array of valid string values */
12673 unsigned *flagp,
12674 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012675{
12676 int i;
12677 int len;
12678 unsigned new_flags = 0;
12679
12680 while (*val)
12681 {
12682 for (i = 0; ; ++i)
12683 {
12684 if (values[i] == NULL) /* val not found in values[] */
12685 return FAIL;
12686
12687 len = (int)STRLEN(values[i]);
12688 if (STRNCMP(values[i], val, len) == 0
12689 && ((list && val[len] == ',') || val[len] == NUL))
12690 {
12691 val += len + (val[len] == ',');
12692 new_flags |= (1 << i);
12693 break; /* check next item in val list */
12694 }
12695 }
12696 }
12697 if (flagp != NULL)
12698 *flagp = new_flags;
12699
12700 return OK;
12701}
12702
12703/*
12704 * Read the 'wildmode' option, fill wim_flags[].
12705 */
12706 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012707check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012708{
12709 char_u new_wim_flags[4];
12710 char_u *p;
12711 int i;
12712 int idx = 0;
12713
12714 for (i = 0; i < 4; ++i)
12715 new_wim_flags[i] = 0;
12716
12717 for (p = p_wim; *p; ++p)
12718 {
12719 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12720 ;
12721 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12722 return FAIL;
12723 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12724 new_wim_flags[idx] |= WIM_LONGEST;
12725 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12726 new_wim_flags[idx] |= WIM_FULL;
12727 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12728 new_wim_flags[idx] |= WIM_LIST;
12729 else
12730 return FAIL;
12731 p += i;
12732 if (*p == NUL)
12733 break;
12734 if (*p == ',')
12735 {
12736 if (idx == 3)
12737 return FAIL;
12738 ++idx;
12739 }
12740 }
12741
12742 /* fill remaining entries with last flag */
12743 while (idx < 3)
12744 {
12745 new_wim_flags[idx + 1] = new_wim_flags[idx];
12746 ++idx;
12747 }
12748
12749 /* only when there are no errors, wim_flags[] is changed */
12750 for (i = 0; i < 4; ++i)
12751 wim_flags[i] = new_wim_flags[i];
12752 return OK;
12753}
12754
12755/*
12756 * Check if backspacing over something is allowed.
12757 */
12758 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012759can_bs(
12760 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012761{
Bram Moolenaar6b810d92018-06-04 17:28:44 +020012762#ifdef FEAT_JOB_CHANNEL
12763 if (what == BS_START && bt_prompt(curbuf))
12764 return FALSE;
12765#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012766 switch (*p_bs)
12767 {
12768 case '2': return TRUE;
12769 case '1': return (what != BS_START);
12770 case '0': return FALSE;
12771 }
12772 return vim_strchr(p_bs, what) != NULL;
12773}
12774
12775/*
12776 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12777 * the file must be considered changed when the value is different.
12778 */
12779 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012780save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012781{
12782 buf->b_start_ffc = *buf->b_p_ff;
12783 buf->b_start_eol = buf->b_p_eol;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012784 buf->b_start_bomb = buf->b_p_bomb;
12785
Bram Moolenaar071d4272004-06-13 20:20:40 +000012786 /* Only use free/alloc when necessary, they take time. */
12787 if (buf->b_start_fenc == NULL
12788 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12789 {
12790 vim_free(buf->b_start_fenc);
12791 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12792 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012793}
12794
12795/*
12796 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12797 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012798 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12799 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012800 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012801 * When "ignore_empty" is true don't consider a new, empty buffer to be
12802 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012803 */
12804 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012805file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012806{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012807 /* In a buffer that was never loaded the options are not valid. */
12808 if (buf->b_flags & BF_NEVERLOADED)
12809 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012810 if (ignore_empty
12811 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012812 && buf->b_ml.ml_line_count == 1
12813 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12814 return FALSE;
12815 if (buf->b_start_ffc != *buf->b_p_ff)
12816 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012817 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012818 return TRUE;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012819 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12820 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012821 if (buf->b_start_fenc == NULL)
12822 return (*buf->b_p_fenc != NUL);
12823 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012824}
12825
12826/*
12827 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12828 */
12829 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012830check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012831{
12832 return check_opt_strings(p, p_ff_values, FALSE);
12833}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012834
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010012835#if defined(FEAT_VARTABS) || defined(PROTO)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012836
12837/*
12838 * Set the integer values corresponding to the string setting of 'vartabstop'.
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010012839 * "array" will be set, caller must free it if needed.
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012840 */
12841 int
12842tabstop_set(char_u *var, int **array)
12843{
12844 int valcount = 1;
12845 int t;
12846 char_u *cp;
12847
Bram Moolenaar64f41072018-10-15 22:51:50 +020012848 if (var[0] == NUL || (var[0] == '0' && var[1] == NUL))
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012849 {
12850 *array = NULL;
12851 return TRUE;
12852 }
12853
Bram Moolenaar64f41072018-10-15 22:51:50 +020012854 for (cp = var; *cp != NUL; ++cp)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012855 {
Bram Moolenaar64f41072018-10-15 22:51:50 +020012856 if (cp == var || cp[-1] == ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012857 {
12858 char_u *end;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012859
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012860 if (strtol((char *)cp, (char **)&end, 10) <= 0)
12861 {
12862 if (cp != end)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012863 emsg(_(e_positive));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012864 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012865 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012866 return FALSE;
12867 }
12868 }
12869
12870 if (VIM_ISDIGIT(*cp))
12871 continue;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012872 if (cp[0] == ',' && cp > var && cp[-1] != ',' && cp[1] != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012873 {
12874 ++valcount;
12875 continue;
12876 }
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012877 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012878 return FALSE;
12879 }
12880
Bram Moolenaarc799fe22019-05-28 23:08:19 +020012881 *array = ALLOC_MULT(int, valcount + 1);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010012882 if (*array == NULL)
12883 return FALSE;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012884 (*array)[0] = valcount;
12885
12886 t = 1;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012887 for (cp = var; *cp != NUL;)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012888 {
12889 (*array)[t++] = atoi((char *)cp);
Bram Moolenaar64f41072018-10-15 22:51:50 +020012890 while (*cp != NUL && *cp != ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012891 ++cp;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012892 if (*cp != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012893 ++cp;
12894 }
12895
12896 return TRUE;
12897}
12898
12899/*
12900 * Calculate the number of screen spaces a tab will occupy.
12901 * If "vts" is set then the tab widths are taken from that array,
12902 * otherwise the value of ts is used.
12903 */
12904 int
12905tabstop_padding(colnr_T col, int ts_arg, int *vts)
12906{
12907 int ts = ts_arg == 0 ? 8 : ts_arg;
12908 int tabcount;
12909 colnr_T tabcol = 0;
12910 int t;
12911 int padding = 0;
12912
12913 if (vts == NULL || vts[0] == 0)
12914 return ts - (col % ts);
12915
12916 tabcount = vts[0];
12917
12918 for (t = 1; t <= tabcount; ++t)
12919 {
12920 tabcol += vts[t];
12921 if (tabcol > col)
12922 {
12923 padding = (int)(tabcol - col);
12924 break;
12925 }
12926 }
12927 if (t > tabcount)
12928 padding = vts[tabcount] - (int)((col - tabcol) % vts[tabcount]);
12929
12930 return padding;
12931}
12932
12933/*
12934 * Find the size of the tab that covers a particular column.
12935 */
12936 int
12937tabstop_at(colnr_T col, int ts, int *vts)
12938{
12939 int tabcount;
12940 colnr_T tabcol = 0;
12941 int t;
12942 int tab_size = 0;
12943
12944 if (vts == 0 || vts[0] == 0)
12945 return ts;
12946
12947 tabcount = vts[0];
12948 for (t = 1; t <= tabcount; ++t)
12949 {
12950 tabcol += vts[t];
12951 if (tabcol > col)
12952 {
12953 tab_size = vts[t];
12954 break;
12955 }
12956 }
12957 if (t > tabcount)
12958 tab_size = vts[tabcount];
12959
12960 return tab_size;
12961}
12962
12963/*
12964 * Find the column on which a tab starts.
12965 */
12966 colnr_T
12967tabstop_start(colnr_T col, int ts, int *vts)
12968{
12969 int tabcount;
12970 colnr_T tabcol = 0;
12971 int t;
12972 int excess;
12973
Bram Moolenaar0119a592018-06-24 23:53:28 +020012974 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012975 return (col / ts) * ts;
12976
12977 tabcount = vts[0];
12978 for (t = 1; t <= tabcount; ++t)
12979 {
12980 tabcol += vts[t];
12981 if (tabcol > col)
12982 return tabcol - vts[t];
12983 }
12984
12985 excess = tabcol % vts[tabcount];
12986 return excess + ((col - excess) / vts[tabcount]) * vts[tabcount];
12987}
12988
12989/*
12990 * Find the number of tabs and spaces necessary to get from one column
12991 * to another.
12992 */
12993 void
12994tabstop_fromto(
12995 colnr_T start_col,
12996 colnr_T end_col,
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012997 int ts_arg,
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012998 int *vts,
12999 int *ntabs,
13000 int *nspcs)
13001{
13002 int spaces = end_col - start_col;
13003 colnr_T tabcol = 0;
13004 int padding = 0;
13005 int tabcount;
13006 int t;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013007 int ts = ts_arg == 0 ? curbuf->b_p_ts : ts_arg;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013008
Bram Moolenaar0119a592018-06-24 23:53:28 +020013009 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013010 {
13011 int tabs = 0;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013012 int initspc = 0;
Bram Moolenaar0119a592018-06-24 23:53:28 +020013013
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013014 initspc = ts - (start_col % ts);
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013015 if (spaces >= initspc)
13016 {
13017 spaces -= initspc;
13018 tabs++;
13019 }
13020 tabs += spaces / ts;
13021 spaces -= (spaces / ts) * ts;
13022
13023 *ntabs = tabs;
13024 *nspcs = spaces;
13025 return;
13026 }
13027
13028 /* Find the padding needed to reach the next tabstop. */
13029 tabcount = vts[0];
13030 for (t = 1; t <= tabcount; ++t)
13031 {
13032 tabcol += vts[t];
13033 if (tabcol > start_col)
13034 {
13035 padding = (int)(tabcol - start_col);
13036 break;
13037 }
13038 }
13039 if (t > tabcount)
13040 padding = vts[tabcount] - (int)((start_col - tabcol) % vts[tabcount]);
13041
13042 /* If the space needed is less than the padding no tabs can be used. */
13043 if (spaces < padding)
13044 {
13045 *ntabs = 0;
13046 *nspcs = spaces;
13047 return;
13048 }
13049
13050 *ntabs = 1;
13051 spaces -= padding;
13052
13053 /* At least one tab has been used. See if any more will fit. */
13054 while (spaces != 0 && ++t <= tabcount)
13055 {
13056 padding = vts[t];
13057 if (spaces < padding)
13058 {
13059 *nspcs = spaces;
13060 return;
13061 }
13062 ++*ntabs;
13063 spaces -= padding;
13064 }
13065
13066 *ntabs += spaces / vts[tabcount];
13067 *nspcs = spaces % vts[tabcount];
13068}
13069
13070/*
13071 * See if two tabstop arrays contain the same values.
13072 */
13073 int
13074tabstop_eq(int *ts1, int *ts2)
13075{
13076 int t;
13077
13078 if ((ts1 == 0 && ts2) || (ts1 && ts2 == 0))
13079 return FALSE;
13080 if (ts1 == ts2)
13081 return TRUE;
13082 if (ts1[0] != ts2[0])
13083 return FALSE;
13084
13085 for (t = 1; t <= ts1[0]; ++t)
13086 if (ts1[t] != ts2[t])
13087 return FALSE;
13088
13089 return TRUE;
13090}
13091
Bram Moolenaar113e1072019-01-20 15:30:40 +010013092#if defined(FEAT_BEVAL) || defined(PROTO)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013093/*
13094 * Copy a tabstop array, allocating space for the new array.
13095 */
13096 int *
13097tabstop_copy(int *oldts)
13098{
13099 int *newts;
13100 int t;
13101
Bram Moolenaar6ee96582019-04-27 22:06:37 +020013102 if (oldts == NULL)
13103 return NULL;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020013104 newts = ALLOC_MULT(int, oldts[0] + 1);
Bram Moolenaar6ee96582019-04-27 22:06:37 +020013105 if (newts != NULL)
13106 for (t = 0; t <= oldts[0]; ++t)
13107 newts[t] = oldts[t];
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013108 return newts;
13109}
Bram Moolenaar113e1072019-01-20 15:30:40 +010013110#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013111
13112/*
13113 * Return a count of the number of tabstops.
13114 */
13115 int
13116tabstop_count(int *ts)
13117{
13118 return ts != NULL ? ts[0] : 0;
13119}
13120
13121/*
13122 * Return the first tabstop, or 8 if there are no tabstops defined.
13123 */
13124 int
13125tabstop_first(int *ts)
13126{
13127 return ts != NULL ? ts[1] : 8;
13128}
13129
13130#endif
13131
Bram Moolenaar14f24742012-08-08 18:01:05 +020013132/*
13133 * Return the effective shiftwidth value for current buffer, using the
13134 * 'tabstop' value when 'shiftwidth' is zero.
13135 */
13136 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013137get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020013138{
Bram Moolenaarf9514162018-11-22 03:08:29 +010013139 return get_sw_value_col(buf, 0);
13140}
13141
13142/*
13143 * Idem, using the first non-black in the current line.
13144 */
13145 long
13146get_sw_value_indent(buf_T *buf)
13147{
13148 pos_T pos = curwin->w_cursor;
13149
13150 pos.col = getwhitecols_curline();
13151 return get_sw_value_pos(buf, &pos);
13152}
13153
13154/*
13155 * Idem, using "pos".
13156 */
13157 long
13158get_sw_value_pos(buf_T *buf, pos_T *pos)
13159{
13160 pos_T save_cursor = curwin->w_cursor;
13161 long sw_value;
13162
13163 curwin->w_cursor = *pos;
13164 sw_value = get_sw_value_col(buf, get_nolist_virtcol());
13165 curwin->w_cursor = save_cursor;
13166 return sw_value;
13167}
13168
13169/*
13170 * Idem, using virtual column "col".
13171 */
13172 long
13173get_sw_value_col(buf_T *buf, colnr_T col UNUSED)
13174{
13175 return buf->b_p_sw ? buf->b_p_sw :
13176 #ifdef FEAT_VARTABS
13177 tabstop_at(col, buf->b_p_ts, buf->b_p_vts_array);
13178 #else
13179 buf->b_p_ts;
13180 #endif
Bram Moolenaar14f24742012-08-08 18:01:05 +020013181}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013182
13183/*
13184 * Return the effective softtabstop value for the current buffer, using the
Bram Moolenaar33d5ab32018-07-02 20:51:24 +020013185 * 'shiftwidth' value when 'softtabstop' is negative.
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013186 */
13187 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013188get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013189{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010013190 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013191}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013192
13193/*
Bram Moolenaar375e3392019-01-31 18:26:10 +010013194 * Return the effective 'scrolloff' value for the current window, using the
13195 * global value when appropriate.
13196 */
13197 long
13198get_scrolloff_value(void)
13199{
13200 return curwin->w_p_so < 0 ? p_so : curwin->w_p_so;
13201}
13202
13203/*
13204 * Return the effective 'sidescrolloff' value for the current window, using the
13205 * global value when appropriate.
13206 */
13207 long
13208get_sidescrolloff_value(void)
13209{
13210 return curwin->w_p_siso < 0 ? p_siso : curwin->w_p_siso;
13211}
13212
13213/*
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013214 * Check matchpairs option for "*initc".
13215 * If there is a match set "*initc" to the matching character and "*findc" to
13216 * the opposite character. Set "*backwards" to the direction.
13217 * When "switchit" is TRUE swap the direction.
13218 */
13219 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010013220find_mps_values(
13221 int *initc,
13222 int *findc,
13223 int *backwards,
13224 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013225{
13226 char_u *ptr;
13227
13228 ptr = curbuf->b_p_mps;
13229 while (*ptr != NUL)
13230 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013231 if (has_mbyte)
13232 {
13233 char_u *prev;
13234
13235 if (mb_ptr2char(ptr) == *initc)
13236 {
13237 if (switchit)
13238 {
13239 *findc = *initc;
13240 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13241 *backwards = TRUE;
13242 }
13243 else
13244 {
13245 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13246 *backwards = FALSE;
13247 }
13248 return;
13249 }
13250 prev = ptr;
13251 ptr += mb_ptr2len(ptr) + 1;
13252 if (mb_ptr2char(ptr) == *initc)
13253 {
13254 if (switchit)
13255 {
13256 *findc = *initc;
13257 *initc = mb_ptr2char(prev);
13258 *backwards = FALSE;
13259 }
13260 else
13261 {
13262 *findc = mb_ptr2char(prev);
13263 *backwards = TRUE;
13264 }
13265 return;
13266 }
13267 ptr += mb_ptr2len(ptr);
13268 }
13269 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013270 {
13271 if (*ptr == *initc)
13272 {
13273 if (switchit)
13274 {
13275 *backwards = TRUE;
13276 *findc = *initc;
13277 *initc = ptr[2];
13278 }
13279 else
13280 {
13281 *backwards = FALSE;
13282 *findc = ptr[2];
13283 }
13284 return;
13285 }
13286 ptr += 2;
13287 if (*ptr == *initc)
13288 {
13289 if (switchit)
13290 {
13291 *backwards = FALSE;
13292 *findc = *initc;
13293 *initc = ptr[-2];
13294 }
13295 else
13296 {
13297 *backwards = TRUE;
13298 *findc = ptr[-2];
13299 }
13300 return;
13301 }
13302 ++ptr;
13303 }
13304 if (*ptr == ',')
13305 ++ptr;
13306 }
13307}
Bram Moolenaar597a4222014-06-25 14:39:50 +020013308
13309#if defined(FEAT_LINEBREAK) || defined(PROTO)
13310/*
13311 * This is called when 'breakindentopt' is changed and when a window is
13312 * initialized.
13313 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013314 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013315briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020013316{
13317 char_u *p;
13318 int bri_shift = 0;
13319 long bri_min = 20;
13320 int bri_sbr = FALSE;
13321
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013322 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013323 while (*p != NUL)
13324 {
13325 if (STRNCMP(p, "shift:", 6) == 0
13326 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
13327 {
13328 p += 6;
13329 bri_shift = getdigits(&p);
13330 }
13331 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
13332 {
13333 p += 4;
13334 bri_min = getdigits(&p);
13335 }
13336 else if (STRNCMP(p, "sbr", 3) == 0)
13337 {
13338 p += 3;
13339 bri_sbr = TRUE;
13340 }
13341 if (*p != ',' && *p != NUL)
13342 return FAIL;
13343 if (*p == ',')
13344 ++p;
13345 }
13346
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013347 wp->w_p_brishift = bri_shift;
13348 wp->w_p_brimin = bri_min;
13349 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013350
13351 return OK;
13352}
13353#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013354
13355/*
13356 * Get the local or global value of 'backupcopy'.
13357 */
13358 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013359get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013360{
13361 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
13362}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020013363
13364#if defined(FEAT_SIGNS) || defined(PROTO)
13365/*
13366 * Return TRUE when window "wp" has a column to draw signs in.
13367 */
13368 int
13369signcolumn_on(win_T *wp)
13370{
13371 if (*wp->w_p_scl == 'n')
13372 return FALSE;
13373 if (*wp->w_p_scl == 'y')
13374 return TRUE;
13375 return (wp->w_buffer->b_signlist != NULL
13376# ifdef FEAT_NETBEANS_INTG
13377 || wp->w_buffer->b_has_sign_column
13378# endif
13379 );
13380}
13381#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013382
13383#if defined(FEAT_EVAL) || defined(PROTO)
13384/*
13385 * Get window or buffer local options.
13386 */
13387 dict_T *
13388get_winbuf_options(int bufopt)
13389{
13390 dict_T *d;
13391 int opt_idx;
13392
13393 d = dict_alloc();
13394 if (d == NULL)
13395 return NULL;
13396
13397 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
13398 {
13399 struct vimoption *opt = &options[opt_idx];
13400
13401 if ((bufopt && (opt->indir & PV_BUF))
13402 || (!bufopt && (opt->indir & PV_WIN)))
13403 {
13404 char_u *varp = get_varp(opt);
13405
13406 if (varp != NULL)
13407 {
13408 if (opt->flags & P_STRING)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013409 dict_add_string(d, opt->fullname, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020013410 else if (opt->flags & P_NUM)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013411 dict_add_number(d, opt->fullname, *(long *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013412 else
Bram Moolenaare0be1672018-07-08 16:50:37 +020013413 dict_add_number(d, opt->fullname, *(int *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013414 }
13415 }
13416 }
13417
13418 return d;
13419}
13420#endif