blob: dfd4587c3df86cd4265145c7a99ce8a797144e65 [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)
170#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
Bram Moolenaar0f6562e2015-11-24 18:48:14 +0100171#define PV_TC OPT_BOTH(OPT_BUF(BV_TC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000172#define PV_TS OPT_BUF(BV_TS)
173#define PV_TW OPT_BUF(BV_TW)
174#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200175#ifdef FEAT_PERSISTENT_UNDO
176# define PV_UDF OPT_BUF(BV_UDF)
177#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000178#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200179#ifdef FEAT_VARTABS
180# define PV_VSTS OPT_BUF(BV_VSTS)
181# define PV_VTS OPT_BUF(BV_VTS)
182#endif
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000183
184/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000185 * Definition of the PV_ values for window-local options.
186 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000187 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000188#define PV_LIST OPT_WIN(WV_LIST)
189#ifdef FEAT_ARABIC
190# define PV_ARAB OPT_WIN(WV_ARAB)
191#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200192#ifdef FEAT_LINEBREAK
193# define PV_BRI OPT_WIN(WV_BRI)
194# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
195#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000196#ifdef FEAT_DIFF
197# define PV_DIFF OPT_WIN(WV_DIFF)
198#endif
199#ifdef FEAT_FOLDING
200# define PV_FDC OPT_WIN(WV_FDC)
201# define PV_FEN OPT_WIN(WV_FEN)
202# define PV_FDI OPT_WIN(WV_FDI)
203# define PV_FDL OPT_WIN(WV_FDL)
204# define PV_FDM OPT_WIN(WV_FDM)
205# define PV_FML OPT_WIN(WV_FML)
206# define PV_FDN OPT_WIN(WV_FDN)
207# ifdef FEAT_EVAL
208# define PV_FDE OPT_WIN(WV_FDE)
209# define PV_FDT OPT_WIN(WV_FDT)
210# endif
211# define PV_FMR OPT_WIN(WV_FMR)
212#endif
213#ifdef FEAT_LINEBREAK
214# define PV_LBR OPT_WIN(WV_LBR)
215#endif
216#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200217#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000218#ifdef FEAT_LINEBREAK
219# define PV_NUW OPT_WIN(WV_NUW)
220#endif
Bram Moolenaar4033c552017-09-16 20:54:51 +0200221#if defined(FEAT_QUICKFIX)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000222# define PV_PVW OPT_WIN(WV_PVW)
223#endif
224#ifdef FEAT_RIGHTLEFT
225# define PV_RL OPT_WIN(WV_RL)
226# define PV_RLC OPT_WIN(WV_RLC)
227#endif
Bram Moolenaar8a3bb562018-03-04 20:14:14 +0100228#define PV_SCBIND OPT_WIN(WV_SCBIND)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000229#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaar375e3392019-01-31 18:26:10 +0100230#define PV_SISO OPT_BOTH(OPT_WIN(WV_SISO))
231#define PV_SO OPT_BOTH(OPT_WIN(WV_SO))
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000232#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000233# define PV_SPELL OPT_WIN(WV_SPELL)
234#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000235#ifdef FEAT_SYN_HL
236# define PV_CUC OPT_WIN(WV_CUC)
237# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200238# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000239#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000240#ifdef FEAT_STL_OPT
241# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
242#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100243#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000244# define PV_WFH OPT_WIN(WV_WFH)
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000245# define PV_WFW OPT_WIN(WV_WFW)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000246#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar8a3bb562018-03-04 20:14:14 +0100247#define PV_CRBIND OPT_WIN(WV_CRBIND)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200248#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200249# define PV_COCU OPT_WIN(WV_COCU)
250# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200251#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200252#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200253# define PV_TWK OPT_WIN(WV_TWK)
254# define PV_TWS OPT_WIN(WV_TWS)
255# define PV_TWSL OPT_BUF(BV_TWSL)
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200256#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200257#ifdef FEAT_SIGNS
258# define PV_SCL OPT_WIN(WV_SCL)
259#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000260
261/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000262typedef enum
263{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000264 PV_NONE = 0,
265 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000266} idopt_T;
267
268/*
269 * Options local to a window have a value local to a buffer and global to all
270 * buffers. Indicate this by setting "var" to VAR_WIN.
271 */
272#define VAR_WIN ((char_u *)-1)
273
274/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000275 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000276 * Only to be used in option.c!
277 */
278static int p_ai;
279static int p_bin;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000280static int p_bomb;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000281static char_u *p_bh;
282static char_u *p_bt;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000283static int p_bl;
284static int p_ci;
285#ifdef FEAT_CINDENT
286static int p_cin;
287static char_u *p_cink;
288static char_u *p_cino;
289#endif
290#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
291static char_u *p_cinw;
292#endif
293#ifdef FEAT_COMMENTS
294static char_u *p_com;
295#endif
296#ifdef FEAT_FOLDING
297static char_u *p_cms;
298#endif
299#ifdef FEAT_INS_EXPAND
300static char_u *p_cpt;
301#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000302#ifdef FEAT_COMPL_FUNC
303static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000304static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000305#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000306static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200307static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000308static int p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000309static char_u *p_fenc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000310static char_u *p_ff;
311static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000312static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000313static char_u *p_ft;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000314static long p_iminsert;
315static long p_imsearch;
316#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
317static char_u *p_inex;
318#endif
319#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
320static char_u *p_inde;
321static char_u *p_indk;
322#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000323#if defined(FEAT_EVAL)
324static char_u *p_fex;
325#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000326static int p_inf;
327static char_u *p_isk;
328#ifdef FEAT_CRYPT
329static char_u *p_key;
330#endif
331#ifdef FEAT_LISP
332static int p_lisp;
333#endif
334static int p_ml;
335static int p_ma;
336static int p_mod;
337static char_u *p_mps;
338static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000339static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000340#ifdef FEAT_TEXTOBJ
341static char_u *p_qe;
342#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000343static int p_ro;
344#ifdef FEAT_SMARTINDENT
345static int p_si;
346#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000347static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000348static long p_sts;
349#if defined(FEAT_SEARCHPATH)
350static char_u *p_sua;
351#endif
352static long p_sw;
353static int p_swf;
354#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000355static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000356static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000357#endif
358#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000359static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000360static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000361static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000362#endif
363static long p_ts;
364static long p_tw;
365static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200366#ifdef FEAT_PERSISTENT_UNDO
367static int p_udf;
368#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000369static long p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200370#ifdef FEAT_VARTABS
371static char_u *p_vsts;
372static char_u *p_vts;
373#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000374#ifdef FEAT_KEYMAP
375static char_u *p_keymap;
376#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200377#ifdef FEAT_TERMINAL
Bram Moolenaarb833c1e2018-05-05 16:36:06 +0200378static long p_twsl; /* 'termwinscroll' */
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200379#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000380
381/* Saved values for when 'bin' is set. */
382static int p_et_nobin;
383static int p_ml_nobin;
384static long p_tw_nobin;
385static long p_wm_nobin;
386
387/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200388static int p_ai_nopaste;
389static int p_et_nopaste;
390static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000391static long p_tw_nopaste;
392static long p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200393#ifdef FEAT_VARTABS
394static char_u *p_vsts_nopaste;
395#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000396
397struct vimoption
398{
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200399 char *fullname; // full option name
400 char *shortname; // permissible abbreviation
401 long_u flags; // see below
402 char_u *var; // global option: pointer to variable;
403 // window-local option: VAR_WIN;
404 // buffer-local option: global value
405 idopt_T indir; // global option: PV_NONE;
406 // local option: indirect option index
407 char_u *def_val[2]; // default values for variable (vi and vim)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000408#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200409 sctx_T script_ctx; // script context where the option was last set
Bram Moolenaar558ca4a2019-04-04 18:15:38 +0200410# define SCTX_INIT , {0, 0, 0, 1}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000411#else
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200412# define SCTX_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000413#endif
414};
415
416#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
417#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
418
419/*
420 * Flags
421 */
422#define P_BOOL 0x01 /* the option is boolean */
423#define P_NUM 0x02 /* the option is numeric */
424#define P_STRING 0x04 /* the option is a string */
425#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000426 must use free_string_option() when
427 assigning new value. Not set if default is
428 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000429#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
430 never be used for local or hidden options! */
431#define P_NODEFAULT 0x40 /* don't set to default value */
432#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
433 use vim_free() when assigning new value */
434#define P_WAS_SET 0x100 /* option has been set/reset */
435#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
436#define P_VI_DEF 0x400 /* Use Vi default for Vim */
437#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
438
439 /* when option changed, what to display: */
440#define P_RSTAT 0x1000 /* redraw status lines */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100441#define P_RWIN 0x2000 /* redraw current window and recompute text */
442#define P_RBUF 0x4000 /* redraw current buffer and recompute text */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000443#define P_RALL 0x6000 /* redraw all windows */
444#define P_RCLR 0x7000 /* clear and redraw all */
445
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200446#define P_COMMA 0x8000 /* comma separated list */
447#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
448 * commas */
449#define P_NODUP 0x20000L /* don't allow duplicate strings */
450#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000451
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200452#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
453#define P_GETTEXT 0x100000L /* expand default value with _() */
454#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
455#define P_NFNAME 0x400000L /* only normal file name chars allowed */
456#define P_INSECURE 0x800000L /* option was set from a modeline */
457#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7554da42016-11-25 22:04:13 +0100458 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200459#define P_NO_ML 0x2000000L /* not allowed in modeline */
460#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200461 * there is a redraw flag */
Bram Moolenaar7554da42016-11-25 22:04:13 +0100462#define P_NDNAME 0x8000000L /* only normal dir name chars allowed */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100463#define P_RWINONLY 0x10000000L /* only redraw current window */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000464
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000465#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
466
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000467/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
468 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100469#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000470# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000471#else
472# define ISP_LATIN1 (char_u *)"@,161-255"
473#endif
474
Bram Moolenaar05fbfdc2017-08-14 22:35:08 +0200475# 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 +0000476
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +0100477/* Default python version for pyx* commands */
478#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
479# define DEFAULT_PYTHON_VER 0
480#elif defined(FEAT_PYTHON3)
481# define DEFAULT_PYTHON_VER 3
482#elif defined(FEAT_PYTHON)
483# define DEFAULT_PYTHON_VER 2
484#else
485# define DEFAULT_PYTHON_VER 0
486#endif
487
Bram Moolenaarce655742019-01-31 14:12:57 +0100488// used for 'cinkeys' and 'indentkeys'
489#define INDENTKEYS_DEFAULT (char_u *)"0{,0},0),0],:,0#,!^F,o,O,e"
490
Bram Moolenaar071d4272004-06-13 20:20:40 +0000491/*
492 * options[] is initialized here.
493 * The order of the options MUST be alphabetic for ":set all" and findoption().
494 * All option names MUST start with a lowercase letter (for findoption()).
495 * Exception: "t_" options are at the end.
496 * The options with a NULL variable are 'hidden': a set command for them is
497 * ignored and they are not printed.
498 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100499static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000500{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200501 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000502#ifdef FEAT_RIGHTLEFT
503 (char_u *)&p_aleph, PV_NONE,
504#else
505 (char_u *)NULL, PV_NONE,
506#endif
507 {
Bram Moolenaar4f974752019-02-17 17:44:42 +0100508#if defined(MSWIN) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000509 (char_u *)128L,
510#else
511 (char_u *)224L,
512#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200513 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000514 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
Bram Moolenaard0573012017-10-28 21:11:06 +0200515#if defined(FEAT_GUI_MAC)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000516 (char_u *)&p_antialias, PV_NONE,
517 {(char_u *)FALSE, (char_u *)FALSE}
518#else
519 (char_u *)NULL, PV_NONE,
520 {(char_u *)FALSE, (char_u *)FALSE}
521#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200522 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200523 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000524#ifdef FEAT_ARABIC
525 (char_u *)VAR_WIN, PV_ARAB,
526#else
527 (char_u *)NULL, PV_NONE,
528#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200529 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000530 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
531#ifdef FEAT_ARABIC
532 (char_u *)&p_arshape, PV_NONE,
533#else
534 (char_u *)NULL, PV_NONE,
535#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200536 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000537 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
538#ifdef FEAT_RIGHTLEFT
539 (char_u *)&p_ari, PV_NONE,
540#else
541 (char_u *)NULL, PV_NONE,
542#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200543 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000544 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000545 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200546 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000547 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000548 (char_u *)&p_ambw, PV_NONE,
549 {(char_u *)"single", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200550 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000551 {"autochdir", "acd", P_BOOL|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100552#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000553 (char_u *)&p_acd, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100554 {(char_u *)FALSE, (char_u *)0L}
555#else
556 (char_u *)NULL, PV_NONE,
557 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000558#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200559 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000560 {"autoindent", "ai", P_BOOL|P_VI_DEF,
561 (char_u *)&p_ai, PV_AI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200562 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000563 {"autoprint", "ap", P_BOOL|P_VI_DEF,
564 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200565 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000566 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000567 (char_u *)&p_ar, PV_AR,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200568 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000569 {"autowrite", "aw", P_BOOL|P_VI_DEF,
570 (char_u *)&p_aw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200571 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000572 {"autowriteall","awa", P_BOOL|P_VI_DEF,
573 (char_u *)&p_awa, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200574 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000575 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
576 (char_u *)&p_bg, PV_NONE,
577 {
Bram Moolenaar4f974752019-02-17 17:44:42 +0100578#if (defined(MSWIN)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000579 (char_u *)"dark",
580#else
581 (char_u *)"light",
582#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200583 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200584 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000585 (char_u *)&p_bs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200586 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000587 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
588 (char_u *)&p_bk, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200589 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200590 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200591 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000592#ifdef UNIX
593 {(char_u *)"yes", (char_u *)"auto"}
594#else
595 {(char_u *)"auto", (char_u *)"auto"}
596#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200597 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200598 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
599 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000600 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200601 {(char_u *)DFLT_BDIR, (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000602 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000603 (char_u *)&p_bex, PV_NONE,
604 {
605#ifdef VMS
606 (char_u *)"_",
607#else
608 (char_u *)"~",
609#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200610 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200611 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000612#ifdef FEAT_WILDIGN
613 (char_u *)&p_bsk, PV_NONE,
614 {(char_u *)"", (char_u *)0L}
615#else
616 (char_u *)NULL, PV_NONE,
617 {(char_u *)0L, (char_u *)0L}
618#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200619 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000620 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100621#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000622 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100623 {(char_u *)600L, (char_u *)0L}
624#else
625 (char_u *)NULL, PV_NONE,
626 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000627#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200628 SCTX_INIT},
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100629 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100630#ifdef FEAT_BEVAL_GUI
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100631 (char_u *)&p_beval, PV_NONE,
632 {(char_u *)FALSE, (char_u *)0L}
633#else
634 (char_u *)NULL, PV_NONE,
635 {(char_u *)0L, (char_u *)0L}
636#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200637 SCTX_INIT},
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100638 {"balloonevalterm", "bevalterm",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100639#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100640 (char_u *)&p_bevalterm, PV_NONE,
641 {(char_u *)FALSE, (char_u *)0L}
642#else
643 (char_u *)NULL, PV_NONE,
644 {(char_u *)0L, (char_u *)0L}
645#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200646 SCTX_INIT},
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100647 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
648#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
649 (char_u *)&p_bexpr, PV_BEXPR,
650 {(char_u *)"", (char_u *)0L}
651#else
652 (char_u *)NULL, PV_NONE,
653 {(char_u *)0L, (char_u *)0L}
654#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200655 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000656 {"beautify", "bf", P_BOOL|P_VI_DEF,
657 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200658 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200659 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
660 (char_u *)&p_bo, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200661 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000662 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
663 (char_u *)&p_bin, PV_BIN,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200664 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000665 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000666 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200667 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000668 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000669 (char_u *)&p_bomb, PV_BOMB,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200670 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000671 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
672#ifdef FEAT_LINEBREAK
673 (char_u *)&p_breakat, PV_NONE,
674 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
675#else
676 (char_u *)NULL, PV_NONE,
677 {(char_u *)0L, (char_u *)0L}
678#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200679 SCTX_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200680 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
681#ifdef FEAT_LINEBREAK
682 (char_u *)VAR_WIN, PV_BRI,
683 {(char_u *)FALSE, (char_u *)0L}
684#else
685 (char_u *)NULL, PV_NONE,
686 {(char_u *)0L, (char_u *)0L}
687#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200688 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200689 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
690 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200691#ifdef FEAT_LINEBREAK
692 (char_u *)VAR_WIN, PV_BRIOPT,
693 {(char_u *)"", (char_u *)NULL}
694#else
695 (char_u *)NULL, PV_NONE,
696 {(char_u *)"", (char_u *)NULL}
697#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200698 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000699 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
700#ifdef FEAT_BROWSE
701 (char_u *)&p_bsdir, PV_NONE,
702 {(char_u *)"last", (char_u *)0L}
703#else
704 (char_u *)NULL, PV_NONE,
705 {(char_u *)0L, (char_u *)0L}
706#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200707 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000708 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000709 (char_u *)&p_bh, PV_BH,
710 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200711 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000712 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
713 (char_u *)&p_bl, PV_BL,
714 {(char_u *)1L, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200715 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000716 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000717 (char_u *)&p_bt, PV_BT,
718 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200719 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200720 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000721 (char_u *)&p_cmp, PV_NONE,
722 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200723 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000724 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
725#ifdef FEAT_SEARCHPATH
726 (char_u *)&p_cdpath, PV_NONE,
727 {(char_u *)",,", (char_u *)0L}
728#else
729 (char_u *)NULL, PV_NONE,
730 {(char_u *)0L, (char_u *)0L}
731#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200732 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000733 {"cedit", NULL, P_STRING,
734#ifdef FEAT_CMDWIN
735 (char_u *)&p_cedit, PV_NONE,
736 {(char_u *)"", (char_u *)CTRL_F_STR}
737#else
738 (char_u *)NULL, PV_NONE,
739 {(char_u *)0L, (char_u *)0L}
740#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200741 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000742 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +0100743#if defined(FEAT_EVAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000744 (char_u *)&p_ccv, PV_NONE,
745 {(char_u *)"", (char_u *)0L}
746#else
747 (char_u *)NULL, PV_NONE,
748 {(char_u *)0L, (char_u *)0L}
749#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200750 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000751 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
752#ifdef FEAT_CINDENT
753 (char_u *)&p_cin, PV_CIN,
754#else
755 (char_u *)NULL, PV_NONE,
756#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200757 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200758 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000759#ifdef FEAT_CINDENT
760 (char_u *)&p_cink, PV_CINK,
Bram Moolenaarce655742019-01-31 14:12:57 +0100761 {INDENTKEYS_DEFAULT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000762#else
763 (char_u *)NULL, PV_NONE,
764 {(char_u *)0L, (char_u *)0L}
765#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200766 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200767 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000768#ifdef FEAT_CINDENT
769 (char_u *)&p_cino, PV_CINO,
770#else
771 (char_u *)NULL, PV_NONE,
772#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200773 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200774 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000775#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
776 (char_u *)&p_cinw, PV_CINW,
777 {(char_u *)"if,else,while,do,for,switch",
778 (char_u *)0L}
779#else
780 (char_u *)NULL, PV_NONE,
781 {(char_u *)0L, (char_u *)0L}
782#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200783 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200784 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000785#ifdef FEAT_CLIPBOARD
786 (char_u *)&p_cb, PV_NONE,
787# ifdef FEAT_XCLIPBOARD
788 {(char_u *)"autoselect,exclude:cons\\|linux",
789 (char_u *)0L}
790# else
791 {(char_u *)"", (char_u *)0L}
792# endif
793#else
794 (char_u *)NULL, PV_NONE,
795 {(char_u *)"", (char_u *)0L}
796#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200797 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000798 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
799 (char_u *)&p_ch, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200800 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000801 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
802#ifdef FEAT_CMDWIN
803 (char_u *)&p_cwh, PV_NONE,
804#else
805 (char_u *)NULL, PV_NONE,
806#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200807 {(char_u *)7L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200808 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200809#ifdef FEAT_SYN_HL
810 (char_u *)VAR_WIN, PV_CC,
811#else
812 (char_u *)NULL, PV_NONE,
813#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200814 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000815 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
816 (char_u *)&Columns, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200817 {(char_u *)80L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200818 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
819 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000820#ifdef FEAT_COMMENTS
821 (char_u *)&p_com, PV_COM,
822 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
823 (char_u *)0L}
824#else
825 (char_u *)NULL, PV_NONE,
826 {(char_u *)0L, (char_u *)0L}
827#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200828 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200829 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000830#ifdef FEAT_FOLDING
831 (char_u *)&p_cms, PV_CMS,
832 {(char_u *)"/*%s*/", (char_u *)0L}
833#else
834 (char_u *)NULL, PV_NONE,
835 {(char_u *)0L, (char_u *)0L}
836#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200837 SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000838 /* P_PRI_MKRC isn't needed here, optval_default()
839 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000840 {"compatible", "cp", P_BOOL|P_RALL,
841 (char_u *)&p_cp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200842 {(char_u *)TRUE, (char_u *)FALSE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200843 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000844#ifdef FEAT_INS_EXPAND
845 (char_u *)&p_cpt, PV_CPT,
846 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
847#else
848 (char_u *)NULL, PV_NONE,
849 {(char_u *)0L, (char_u *)0L}
850#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200851 SCTX_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200852 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200853#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200854 (char_u *)VAR_WIN, PV_COCU,
855 {(char_u *)"", (char_u *)NULL}
856#else
857 (char_u *)NULL, PV_NONE,
858 {(char_u *)NULL, (char_u *)0L}
859#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200860 SCTX_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200861 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
862#ifdef FEAT_CONCEAL
863 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200864#else
865 (char_u *)NULL, PV_NONE,
866#endif
867 {(char_u *)0L, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200868 SCTX_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000869 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
870#ifdef FEAT_COMPL_FUNC
871 (char_u *)&p_cfu, PV_CFU,
872 {(char_u *)"", (char_u *)0L}
873#else
874 (char_u *)NULL, PV_NONE,
875 {(char_u *)0L, (char_u *)0L}
876#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200877 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200878 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000879#ifdef FEAT_INS_EXPAND
880 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000881 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000882#else
883 (char_u *)NULL, PV_NONE,
884 {(char_u *)0L, (char_u *)0L}
885#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200886 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000887 {"confirm", "cf", P_BOOL|P_VI_DEF,
888#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
889 (char_u *)&p_confirm, PV_NONE,
890#else
891 (char_u *)NULL, PV_NONE,
892#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200893 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000894 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000895 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200896 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000897 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
898 (char_u *)&p_ci, PV_CI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200899 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000900 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
901 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000902 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200903 SCTX_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200904 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200905#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200906 (char_u *)&p_cm, PV_CM,
Bram Moolenaara86187b2018-12-16 18:20:00 +0100907 {(char_u *)"blowfish2", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200908#else
909 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200910 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200911#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200912 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000913 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
914#ifdef FEAT_CSCOPE
915 (char_u *)&p_cspc, PV_NONE,
916#else
917 (char_u *)NULL, PV_NONE,
918#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200919 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000920 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
921#ifdef FEAT_CSCOPE
922 (char_u *)&p_csprg, PV_NONE,
923 {(char_u *)"cscope", (char_u *)0L}
924#else
925 (char_u *)NULL, PV_NONE,
926 {(char_u *)0L, (char_u *)0L}
927#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200928 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200929 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000930#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
931 (char_u *)&p_csqf, PV_NONE,
932 {(char_u *)"", (char_u *)0L}
933#else
934 (char_u *)NULL, PV_NONE,
935 {(char_u *)0L, (char_u *)0L}
936#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200937 SCTX_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200938 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
939#ifdef FEAT_CSCOPE
940 (char_u *)&p_csre, PV_NONE,
941#else
942 (char_u *)NULL, PV_NONE,
943#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200944 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000945 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
946#ifdef FEAT_CSCOPE
947 (char_u *)&p_cst, PV_NONE,
948#else
949 (char_u *)NULL, PV_NONE,
950#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200951 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000952 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
953#ifdef FEAT_CSCOPE
954 (char_u *)&p_csto, PV_NONE,
955#else
956 (char_u *)NULL, PV_NONE,
957#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200958 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000959 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
960#ifdef FEAT_CSCOPE
961 (char_u *)&p_csverbose, PV_NONE,
962#else
963 (char_u *)NULL, PV_NONE,
964#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200965 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200966 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200967 (char_u *)VAR_WIN, PV_CRBIND,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200968 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar177ab9e2019-01-15 21:12:57 +0100969 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000970#ifdef FEAT_SYN_HL
971 (char_u *)VAR_WIN, PV_CUC,
972#else
973 (char_u *)NULL, PV_NONE,
974#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200975 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100976 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000977#ifdef FEAT_SYN_HL
978 (char_u *)VAR_WIN, PV_CUL,
979#else
980 (char_u *)NULL, PV_NONE,
981#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200982 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000983 {"debug", NULL, P_STRING|P_VI_DEF,
984 (char_u *)&p_debug, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200985 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200986 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000987#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000988 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000989 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000990#else
991 (char_u *)NULL, PV_NONE,
992 {(char_u *)NULL, (char_u *)0L}
993#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200994 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000995 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000996 (char_u *)&p_deco, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200997 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +0100998 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000999#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001000 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001001#else
1002 (char_u *)NULL, PV_NONE,
1003#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001004 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001005 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1006#ifdef FEAT_DIFF
1007 (char_u *)VAR_WIN, PV_DIFF,
1008#else
1009 (char_u *)NULL, PV_NONE,
1010#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001011 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001012 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001013#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1014 (char_u *)&p_dex, PV_NONE,
1015 {(char_u *)"", (char_u *)0L}
1016#else
1017 (char_u *)NULL, PV_NONE,
1018 {(char_u *)0L, (char_u *)0L}
1019#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001020 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001021 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1022 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001023#ifdef FEAT_DIFF
1024 (char_u *)&p_dip, PV_NONE,
Bram Moolenaarc93262b2018-09-10 21:15:40 +02001025 {(char_u *)"internal,filler", (char_u *)NULL}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001026#else
1027 (char_u *)NULL, PV_NONE,
1028 {(char_u *)"", (char_u *)NULL}
1029#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001030 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001031 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1032#ifdef FEAT_DIGRAPHS
1033 (char_u *)&p_dg, PV_NONE,
1034#else
1035 (char_u *)NULL, PV_NONE,
1036#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001037 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001038 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1039 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001040 (char_u *)&p_dir, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001041 {(char_u *)DFLT_DIR, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001042 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001043 (char_u *)&p_dy, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001044 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001045 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001046 (char_u *)&p_ead, PV_NONE,
1047 {(char_u *)"both", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001048 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001049 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1050 (char_u *)&p_ed, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001051 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001052 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaar3848e002016-03-19 18:42:29 +01001053 (char_u *)&p_emoji, PV_NONE,
1054 {(char_u *)TRUE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001055 SCTX_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001056 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001057 (char_u *)&p_enc, PV_NONE,
1058 {(char_u *)ENC_DFLT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001059 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001060 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1061 (char_u *)&p_eol, PV_EOL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001062 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001063 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1064 (char_u *)&p_ea, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001065 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001066 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001067 (char_u *)&p_ep, PV_EP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001068 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001069 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1070 (char_u *)&p_eb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001071 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001072 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1073#ifdef FEAT_QUICKFIX
1074 (char_u *)&p_ef, PV_NONE,
1075 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1076#else
1077 (char_u *)NULL, PV_NONE,
1078 {(char_u *)NULL, (char_u *)0L}
1079#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001080 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001081 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001082#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001083 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001084 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001085#else
1086 (char_u *)NULL, PV_NONE,
1087 {(char_u *)NULL, (char_u *)0L}
1088#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001089 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001090 {"esckeys", "ek", P_BOOL|P_VIM,
1091 (char_u *)&p_ek, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001092 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001093 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001094 (char_u *)&p_ei, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001095 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001096 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1097 (char_u *)&p_et, PV_ET,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001098 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001099 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1100 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001101 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001102 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1103 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001104 (char_u *)&p_fenc, PV_FENC,
1105 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001106 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001107 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001108 (char_u *)&p_fencs, PV_NONE,
1109 {(char_u *)"ucs-bom", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001110 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001111 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1112 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001113 (char_u *)&p_ff, PV_FF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001114 {(char_u *)DFLT_FF, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001115 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001116 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001117 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001118 SCTX_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001119 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1120 (char_u *)&p_fic, PV_NONE,
1121 {
1122#ifdef CASE_INSENSITIVE_FILENAME
1123 (char_u *)TRUE,
1124#else
1125 (char_u *)FALSE,
1126#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001127 (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001128 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001129 (char_u *)&p_ft, PV_FT,
1130 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001131 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001132 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001133 (char_u *)&p_fcs, PV_NONE,
1134 {(char_u *)"vert:|,fold:-", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001135 SCTX_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001136 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1137 (char_u *)&p_fixeol, PV_FIXEOL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001138 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001139 {"fkmap", "fk", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001140 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001141 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001142 {"flash", "fl", P_BOOL|P_VI_DEF,
1143 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001144 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001145 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001146#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001147 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001148 {(char_u *)"", (char_u *)0L}
1149#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001150 (char_u *)NULL, PV_NONE,
1151 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001152#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001153 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001154 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1155#ifdef FEAT_FOLDING
1156 (char_u *)VAR_WIN, PV_FDC,
1157 {(char_u *)FALSE, (char_u *)0L}
1158#else
1159 (char_u *)NULL, PV_NONE,
1160 {(char_u *)NULL, (char_u *)0L}
1161#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001162 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001163 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1164#ifdef FEAT_FOLDING
1165 (char_u *)VAR_WIN, PV_FEN,
1166 {(char_u *)TRUE, (char_u *)0L}
1167#else
1168 (char_u *)NULL, PV_NONE,
1169 {(char_u *)NULL, (char_u *)0L}
1170#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001171 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001172 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1173#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1174 (char_u *)VAR_WIN, PV_FDE,
1175 {(char_u *)"0", (char_u *)NULL}
1176#else
1177 (char_u *)NULL, PV_NONE,
1178 {(char_u *)NULL, (char_u *)0L}
1179#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001180 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001181 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001182#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001183 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001184 {(char_u *)"#", (char_u *)NULL}
1185#else
1186 (char_u *)NULL, PV_NONE,
1187 {(char_u *)NULL, (char_u *)0L}
1188#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001189 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001190 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001191#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001192 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001193 {(char_u *)0L, (char_u *)0L}
1194#else
1195 (char_u *)NULL, PV_NONE,
1196 {(char_u *)NULL, (char_u *)0L}
1197#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001198 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001199 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001200#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001201 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001202 {(char_u *)-1L, (char_u *)0L}
1203#else
1204 (char_u *)NULL, PV_NONE,
1205 {(char_u *)NULL, (char_u *)0L}
1206#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001207 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001208 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001209 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001210#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001211 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001212 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001213#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001214 (char_u *)NULL, PV_NONE,
1215 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001216#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001217 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001218 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1219#ifdef FEAT_FOLDING
1220 (char_u *)VAR_WIN, PV_FDM,
1221 {(char_u *)"manual", (char_u *)NULL}
1222#else
1223 (char_u *)NULL, PV_NONE,
1224 {(char_u *)NULL, (char_u *)0L}
1225#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001226 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001227 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1228#ifdef FEAT_FOLDING
1229 (char_u *)VAR_WIN, PV_FML,
1230 {(char_u *)1L, (char_u *)0L}
1231#else
1232 (char_u *)NULL, PV_NONE,
1233 {(char_u *)NULL, (char_u *)0L}
1234#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001235 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001236 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1237#ifdef FEAT_FOLDING
1238 (char_u *)VAR_WIN, PV_FDN,
1239 {(char_u *)20L, (char_u *)0L}
1240#else
1241 (char_u *)NULL, PV_NONE,
1242 {(char_u *)NULL, (char_u *)0L}
1243#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001244 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001245 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1246#ifdef FEAT_FOLDING
1247 (char_u *)&p_fdo, PV_NONE,
1248 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1249 (char_u *)0L}
1250#else
1251 (char_u *)NULL, PV_NONE,
1252 {(char_u *)NULL, (char_u *)0L}
1253#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001254 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001255 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1256#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1257 (char_u *)VAR_WIN, PV_FDT,
1258 {(char_u *)"foldtext()", (char_u *)NULL}
1259#else
1260 (char_u *)NULL, PV_NONE,
1261 {(char_u *)NULL, (char_u *)0L}
1262#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001263 SCTX_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001264 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001265#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001266 (char_u *)&p_fex, PV_FEX,
1267 {(char_u *)"", (char_u *)0L}
1268#else
1269 (char_u *)NULL, PV_NONE,
1270 {(char_u *)0L, (char_u *)0L}
1271#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001272 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001273 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1274 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001275 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001276 SCTX_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001277 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1278 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001279 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001280 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001281 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001282 (char_u *)&p_fp, PV_FP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001283 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001284 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1285#ifdef HAVE_FSYNC
1286 (char_u *)&p_fs, PV_NONE,
1287 {(char_u *)TRUE, (char_u *)0L}
1288#else
1289 (char_u *)NULL, PV_NONE,
1290 {(char_u *)FALSE, (char_u *)0L}
1291#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001292 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001293 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1294 (char_u *)&p_gd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001295 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001296 {"graphic", "gr", P_BOOL|P_VI_DEF,
1297 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001298 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001299 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001300#ifdef FEAT_QUICKFIX
1301 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001302 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001303#else
1304 (char_u *)NULL, PV_NONE,
1305 {(char_u *)NULL, (char_u *)0L}
1306#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001307 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001308 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1309#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001310 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001311 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01001312# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001313 /* may be changed to "grep -n" in os_win32.c */
1314 (char_u *)"findstr /n",
1315# else
1316# ifdef UNIX
1317 /* Add an extra file name so that grep will always
1318 * insert a file name in the match line. */
1319 (char_u *)"grep -n $* /dev/null",
1320# else
1321# ifdef VMS
1322 (char_u *)"SEARCH/NUMBERS ",
1323# else
1324 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001325# endif
1326# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001327# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001328 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001329#else
1330 (char_u *)NULL, PV_NONE,
1331 {(char_u *)NULL, (char_u *)0L}
1332#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001333 SCTX_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001334 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001335#ifdef CURSOR_SHAPE
1336 (char_u *)&p_guicursor, PV_NONE,
1337 {
1338# ifdef FEAT_GUI
1339 (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 +01001340# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001341 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1342# endif
1343 (char_u *)0L}
1344#else
1345 (char_u *)NULL, PV_NONE,
1346 {(char_u *)NULL, (char_u *)0L}
1347#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001348 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001349 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001350#ifdef FEAT_GUI
1351 (char_u *)&p_guifont, PV_NONE,
1352 {(char_u *)"", (char_u *)0L}
1353#else
1354 (char_u *)NULL, PV_NONE,
1355 {(char_u *)NULL, (char_u *)0L}
1356#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001357 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001358 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001359#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1360 (char_u *)&p_guifontset, PV_NONE,
1361 {(char_u *)"", (char_u *)0L}
1362#else
1363 (char_u *)NULL, PV_NONE,
1364 {(char_u *)NULL, (char_u *)0L}
1365#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001366 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001367 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001368#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001369 (char_u *)&p_guifontwide, PV_NONE,
1370 {(char_u *)"", (char_u *)0L}
1371#else
1372 (char_u *)NULL, PV_NONE,
1373 {(char_u *)NULL, (char_u *)0L}
1374#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001375 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001376 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001377#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001378 (char_u *)&p_ghr, PV_NONE,
1379#else
1380 (char_u *)NULL, PV_NONE,
1381#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001382 {(char_u *)50L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001383 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001384#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001385 (char_u *)&p_go, PV_NONE,
Bram Moolenaard0573012017-10-28 21:11:06 +02001386# if defined(UNIX) && !defined(FEAT_GUI_MAC)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001387 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001388# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001389 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001390# endif
1391#else
1392 (char_u *)NULL, PV_NONE,
1393 {(char_u *)NULL, (char_u *)0L}
1394#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001395 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001396 {"guipty", NULL, P_BOOL|P_VI_DEF,
1397#if defined(FEAT_GUI)
1398 (char_u *)&p_guipty, PV_NONE,
1399#else
1400 (char_u *)NULL, PV_NONE,
1401#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001402 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001403 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001404#if defined(FEAT_GUI_TABLINE)
1405 (char_u *)&p_gtl, PV_NONE,
1406 {(char_u *)"", (char_u *)0L}
1407#else
1408 (char_u *)NULL, PV_NONE,
1409 {(char_u *)NULL, (char_u *)0L}
1410#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001411 SCTX_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001412 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001413#if defined(FEAT_GUI_TABLINE)
1414 (char_u *)&p_gtt, PV_NONE,
1415 {(char_u *)"", (char_u *)0L}
1416#else
1417 (char_u *)NULL, PV_NONE,
1418 {(char_u *)NULL, (char_u *)0L}
1419#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001420 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001421 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1422 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001423 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001424 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1425 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001426 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001427 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001428 {"helpheight", "hh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001429 (char_u *)&p_hh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001430 {(char_u *)20L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001431 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001432#ifdef FEAT_MULTI_LANG
1433 (char_u *)&p_hlg, PV_NONE,
1434 {(char_u *)"", (char_u *)0L}
1435#else
1436 (char_u *)NULL, PV_NONE,
1437 {(char_u *)0L, (char_u *)0L}
1438#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001439 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001440 {"hidden", "hid", P_BOOL|P_VI_DEF,
1441 (char_u *)&p_hid, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001442 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001443 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001444 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001445 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001446 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001447 {"history", "hi", P_NUM|P_VIM,
1448 (char_u *)&p_hi, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001449 {(char_u *)0L, (char_u *)50L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001450 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1451#ifdef FEAT_RIGHTLEFT
1452 (char_u *)&p_hkmap, PV_NONE,
1453#else
1454 (char_u *)NULL, PV_NONE,
1455#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001456 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001457 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1458#ifdef FEAT_RIGHTLEFT
1459 (char_u *)&p_hkmapp, PV_NONE,
1460#else
1461 (char_u *)NULL, PV_NONE,
1462#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001463 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001464 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1465 (char_u *)&p_hls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001466 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001467 {"icon", NULL, P_BOOL|P_VI_DEF,
1468#ifdef FEAT_TITLE
1469 (char_u *)&p_icon, PV_NONE,
1470#else
1471 (char_u *)NULL, PV_NONE,
1472#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001473 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001474 {"iconstring", NULL, P_STRING|P_VI_DEF,
1475#ifdef FEAT_TITLE
1476 (char_u *)&p_iconstring, PV_NONE,
1477#else
1478 (char_u *)NULL, PV_NONE,
1479#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001480 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001481 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1482 (char_u *)&p_ic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001483 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001484 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001485#if defined(FEAT_EVAL)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001486 (char_u *)&p_imaf, PV_NONE,
1487 {(char_u *)"", (char_u *)NULL}
1488# else
1489 (char_u *)NULL, PV_NONE,
1490 {(char_u *)NULL, (char_u *)0L}
1491# endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001492 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001493 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001494#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001495 (char_u *)&p_imak, PV_NONE,
1496#else
1497 (char_u *)NULL, PV_NONE,
1498#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001499 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001500 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001501 (char_u *)&p_imcmdline, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001502 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001503 {"imdisable", "imd", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001504 (char_u *)&p_imdisable, PV_NONE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001505#ifdef __sgi
1506 {(char_u *)TRUE, (char_u *)0L}
1507#else
1508 {(char_u *)FALSE, (char_u *)0L}
1509#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001510 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001511 {"iminsert", "imi", P_NUM|P_VI_DEF,
1512 (char_u *)&p_iminsert, PV_IMI,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001513 {(char_u *)B_IMODE_NONE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001514 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001515 {"imsearch", "ims", P_NUM|P_VI_DEF,
1516 (char_u *)&p_imsearch, PV_IMS,
Bram Moolenaar4cf56bb2017-09-16 15:50:32 +02001517 {(char_u *)B_IMODE_USE_INSERT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001518 SCTX_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001519 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001520#if defined(FEAT_EVAL)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001521 (char_u *)&p_imsf, PV_NONE,
1522 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001523#else
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001524 (char_u *)NULL, PV_NONE,
1525 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001526#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001527 SCTX_INIT},
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001528 {"imstyle", "imst", P_NUM|P_VI_DEF|P_SECURE,
1529#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1530 (char_u *)&p_imst, PV_NONE,
1531 {(char_u *)IM_OVER_THE_SPOT, (char_u *)0L}
1532#else
1533 (char_u *)NULL, PV_NONE,
1534 {(char_u *)0L, (char_u *)0L}
1535#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001536 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001537 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1538#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001539 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001540 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1541#else
1542 (char_u *)NULL, PV_NONE,
1543 {(char_u *)0L, (char_u *)0L}
1544#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001545 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001546 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1547#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1548 (char_u *)&p_inex, PV_INEX,
1549 {(char_u *)"", (char_u *)0L}
1550#else
1551 (char_u *)NULL, PV_NONE,
1552 {(char_u *)0L, (char_u *)0L}
1553#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001554 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001555 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1556 (char_u *)&p_is, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001557 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001558 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1559#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1560 (char_u *)&p_inde, PV_INDE,
1561 {(char_u *)"", (char_u *)0L}
1562#else
1563 (char_u *)NULL, PV_NONE,
1564 {(char_u *)0L, (char_u *)0L}
1565#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001566 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001567 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001568#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1569 (char_u *)&p_indk, PV_INDK,
Bram Moolenaarce655742019-01-31 14:12:57 +01001570 {INDENTKEYS_DEFAULT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001571#else
1572 (char_u *)NULL, PV_NONE,
1573 {(char_u *)0L, (char_u *)0L}
1574#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001575 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001576 {"infercase", "inf", P_BOOL|P_VI_DEF,
1577 (char_u *)&p_inf, PV_INF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001578 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001579 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1580 (char_u *)&p_im, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001581 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001582 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1583 (char_u *)&p_isf, PV_NONE,
1584 {
1585#ifdef BACKSLASH_IN_FILENAME
1586 /* Excluded are: & and ^ are special in cmd.exe
1587 * ( and ) are used in text separating fnames */
1588 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1589#else
1590# ifdef AMIGA
1591 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1592# else
1593# ifdef VMS
1594 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1595# else /* UNIX et al. */
1596# ifdef EBCDIC
1597 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1598# else
1599 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1600# endif
1601# endif
1602# endif
1603#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001604 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001605 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1606 (char_u *)&p_isi, PV_NONE,
1607 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001608#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001609 (char_u *)"@,48-57,_,128-167,224-235",
1610#else
1611# ifdef EBCDIC
1612 /* TODO: EBCDIC Check this! @ == isalpha()*/
1613 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1614 "112-120,128,140-142,156,158,172,"
1615 "174,186,191,203-207,219-225,235-239,"
1616 "251-254",
1617# else
1618 (char_u *)"@,48-57,_,192-255",
1619# endif
1620#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001621 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001622 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1623 (char_u *)&p_isk, PV_ISK,
1624 {
1625#ifdef EBCDIC
1626 (char_u *)"@,240-249,_",
1627 /* TODO: EBCDIC Check this! @ == isalpha()*/
1628 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1629 "112-120,128,140-142,156,158,172,"
1630 "174,186,191,203-207,219-225,235-239,"
1631 "251-254",
1632#else
1633 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001634# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001635 (char_u *)"@,48-57,_,128-167,224-235"
1636# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001637 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001638# endif
1639#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001640 } SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001641 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1642 (char_u *)&p_isp, PV_NONE,
1643 {
Bram Moolenaard0573012017-10-28 21:11:06 +02001644#if defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001645 (char_u *)"@,~-255",
1646#else
1647# ifdef EBCDIC
1648 /* all chars above 63 are printable */
1649 (char_u *)"63-255",
1650# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001651 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001652# endif
1653#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001654 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001655 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1656 (char_u *)&p_js, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001657 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001658 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1659#ifdef FEAT_CRYPT
1660 (char_u *)&p_key, PV_KEY,
1661 {(char_u *)"", (char_u *)0L}
1662#else
1663 (char_u *)NULL, PV_NONE,
1664 {(char_u *)0L, (char_u *)0L}
1665#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001666 SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001667 {"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 +00001668#ifdef FEAT_KEYMAP
1669 (char_u *)&p_keymap, PV_KMAP,
1670 {(char_u *)"", (char_u *)0L}
1671#else
1672 (char_u *)NULL, PV_NONE,
1673 {(char_u *)"", (char_u *)0L}
1674#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001675 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001676 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001677 (char_u *)&p_km, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001678 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001679 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001680 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001681 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001682#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001683 (char_u *)":help",
1684#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001685# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001686 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001687# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001688# ifdef USEMAN_S
1689 (char_u *)"man -s",
1690# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001691 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001692# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001693# endif
1694#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001695 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001696 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001697#ifdef FEAT_LANGMAP
1698 (char_u *)&p_langmap, PV_NONE,
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001699 {(char_u *)"", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001700#else
1701 (char_u *)NULL, PV_NONE,
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001702 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001703#endif
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001704 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001705 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001706#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1707 (char_u *)&p_lm, PV_NONE,
1708#else
1709 (char_u *)NULL, PV_NONE,
1710#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001711 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001712 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1713#ifdef FEAT_LANGMAP
1714 (char_u *)&p_lnr, PV_NONE,
1715#else
1716 (char_u *)NULL, PV_NONE,
1717#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001718 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001719 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1720#ifdef FEAT_LANGMAP
1721 (char_u *)&p_lrm, PV_NONE,
1722#else
1723 (char_u *)NULL, PV_NONE,
1724#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001725 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001726 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001727 (char_u *)&p_ls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001728 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001729 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1730 (char_u *)&p_lz, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001731 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001732 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1733#ifdef FEAT_LINEBREAK
1734 (char_u *)VAR_WIN, PV_LBR,
1735#else
1736 (char_u *)NULL, PV_NONE,
1737#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001738 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001739 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1740 (char_u *)&Rows, PV_NONE,
1741 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01001742#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001743 (char_u *)25L,
1744#else
1745 (char_u *)24L,
1746#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001747 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001748 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1749#ifdef FEAT_GUI
1750 (char_u *)&p_linespace, PV_NONE,
1751#else
1752 (char_u *)NULL, PV_NONE,
1753#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01001754#ifdef FEAT_GUI_MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001755 {(char_u *)1L, (char_u *)0L}
1756#else
1757 {(char_u *)0L, (char_u *)0L}
1758#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001759 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001760 {"lisp", NULL, P_BOOL|P_VI_DEF,
1761#ifdef FEAT_LISP
1762 (char_u *)&p_lisp, PV_LISP,
1763#else
1764 (char_u *)NULL, PV_NONE,
1765#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001766 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001767 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001768#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001769 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001770 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1771#else
1772 (char_u *)NULL, PV_NONE,
1773 {(char_u *)"", (char_u *)0L}
1774#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001775 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001776 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1777 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001778 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001779 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001780 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001781 {(char_u *)"eol:$", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001782 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1783 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001784 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001785 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001786#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001787 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001788 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001789#else
1790 (char_u *)NULL, PV_NONE,
1791 {(char_u *)"", (char_u *)0L}
1792#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001793 SCTX_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001794 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001795#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001796 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001797 {(char_u *)TRUE, (char_u *)0L}
1798#else
1799 (char_u *)NULL, PV_NONE,
1800 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001801#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001802 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001803 {"magic", NULL, P_BOOL|P_VI_DEF,
1804 (char_u *)&p_magic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001805 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001806 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001807#ifdef FEAT_QUICKFIX
1808 (char_u *)&p_mef, PV_NONE,
1809 {(char_u *)"", (char_u *)0L}
1810#else
1811 (char_u *)NULL, PV_NONE,
1812 {(char_u *)NULL, (char_u *)0L}
1813#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001814 SCTX_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001815 {"makeencoding","menc", P_STRING|P_VI_DEF,
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001816 (char_u *)&p_menc, PV_MENC,
1817 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001818 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001819 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1820#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001821 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001822# ifdef VMS
1823 {(char_u *)"MMS", (char_u *)0L}
1824# else
1825 {(char_u *)"make", (char_u *)0L}
1826# endif
1827#else
1828 (char_u *)NULL, PV_NONE,
1829 {(char_u *)NULL, (char_u *)0L}
1830#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001831 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001832 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001833 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001834 {(char_u *)"(:),{:},[:]", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001835 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001836 {"matchtime", "mat", P_NUM|P_VI_DEF,
1837 (char_u *)&p_mat, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001838 {(char_u *)5L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001839 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001840 (char_u *)&p_mco, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001841 {(char_u *)2, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001842 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1843#ifdef FEAT_EVAL
1844 (char_u *)&p_mfd, PV_NONE,
1845#else
1846 (char_u *)NULL, PV_NONE,
1847#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001848 {(char_u *)100L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001849 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1850 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001851 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001852 {"maxmem", "mm", P_NUM|P_VI_DEF,
1853 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001854 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001855 SCTX_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001856 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1857 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001858 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001859 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1860 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001861 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001862 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001863 {"menuitems", "mis", P_NUM|P_VI_DEF,
1864#ifdef FEAT_MENU
1865 (char_u *)&p_mis, PV_NONE,
1866#else
1867 (char_u *)NULL, PV_NONE,
1868#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001869 {(char_u *)25L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001870 {"mesg", NULL, P_BOOL|P_VI_DEF,
1871 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001872 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001873 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001874#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001875 (char_u *)&p_msm, PV_NONE,
1876 {(char_u *)"460000,2000,500", (char_u *)0L}
1877#else
1878 (char_u *)NULL, PV_NONE,
1879 {(char_u *)0L, (char_u *)0L}
1880#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001881 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001882 {"modeline", "ml", P_BOOL|P_VIM,
1883 (char_u *)&p_ml, PV_ML,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001884 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001885 {"modelines", "mls", P_NUM|P_VI_DEF,
1886 (char_u *)&p_mls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001887 {(char_u *)5L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001888 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1889 (char_u *)&p_ma, PV_MA,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001890 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001891 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1892 (char_u *)&p_mod, PV_MOD,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001893 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001894 {"more", NULL, P_BOOL|P_VIM,
1895 (char_u *)&p_more, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001896 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001897 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1898 (char_u *)&p_mouse, PV_NONE,
1899 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01001900#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001901 (char_u *)"a",
1902#else
1903 (char_u *)"",
1904#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001905 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001906 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1907#ifdef FEAT_GUI
1908 (char_u *)&p_mousef, PV_NONE,
1909#else
1910 (char_u *)NULL, PV_NONE,
1911#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001912 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001913 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1914#ifdef FEAT_GUI
1915 (char_u *)&p_mh, PV_NONE,
1916#else
1917 (char_u *)NULL, PV_NONE,
1918#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001919 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001920 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1921 (char_u *)&p_mousem, PV_NONE,
1922 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001923#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001924 (char_u *)"popup",
1925#else
Bram Moolenaard0573012017-10-28 21:11:06 +02001926# if defined(MACOS_X)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001927 (char_u *)"popup_setpos",
1928# else
1929 (char_u *)"extend",
1930# endif
1931#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001932 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001933 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001934#ifdef FEAT_MOUSESHAPE
1935 (char_u *)&p_mouseshape, PV_NONE,
1936 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1937#else
1938 (char_u *)NULL, PV_NONE,
1939 {(char_u *)NULL, (char_u *)0L}
1940#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001941 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001942 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1943 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001944 {(char_u *)500L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02001945 {"mzschemedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1946#if defined(DYNAMIC_MZSCHEME)
1947 (char_u *)&p_mzschemedll, PV_NONE,
1948 {(char_u *)DYNAMIC_MZSCH_DLL, (char_u *)0L}
1949#else
1950 (char_u *)NULL, PV_NONE,
1951 {(char_u *)"", (char_u *)0L}
1952#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001953 SCTX_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02001954 {"mzschemegcdll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1955#if defined(DYNAMIC_MZSCHEME)
1956 (char_u *)&p_mzschemegcdll, PV_NONE,
1957 {(char_u *)DYNAMIC_MZGC_DLL, (char_u *)0L}
1958#else
1959 (char_u *)NULL, PV_NONE,
1960 {(char_u *)"", (char_u *)0L}
1961#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001962 SCTX_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001963 {"mzquantum", "mzq", P_NUM,
1964#ifdef FEAT_MZSCHEME
1965 (char_u *)&p_mzq, PV_NONE,
1966#else
1967 (char_u *)NULL, PV_NONE,
1968#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001969 {(char_u *)100L, (char_u *)100L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001970 {"novice", NULL, P_BOOL|P_VI_DEF,
1971 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001972 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001973 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001974 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01001975 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001976 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001977 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1978 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001979 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001980 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1981#ifdef FEAT_LINEBREAK
1982 (char_u *)VAR_WIN, PV_NUW,
1983#else
1984 (char_u *)NULL, PV_NONE,
1985#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001986 {(char_u *)8L, (char_u *)4L} SCTX_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001987 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001988#ifdef FEAT_COMPL_FUNC
1989 (char_u *)&p_ofu, PV_OFU,
1990 {(char_u *)"", (char_u *)0L}
1991#else
1992 (char_u *)NULL, PV_NONE,
1993 {(char_u *)0L, (char_u *)0L}
1994#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001995 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001996 {"open", NULL, P_BOOL|P_VI_DEF,
1997 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001998 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001999 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002000#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002001 (char_u *)&p_odev, PV_NONE,
2002#else
2003 (char_u *)NULL, PV_NONE,
2004#endif
2005 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002006 SCTX_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002007 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2008 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002009 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002010 {"optimize", "opt", P_BOOL|P_VI_DEF,
2011 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002012 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002013 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002014 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002015 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002016 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2017 |P_SECURE,
2018 (char_u *)&p_pp, PV_NONE,
2019 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002020 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002021 {"paragraphs", "para", P_STRING|P_VI_DEF,
2022 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002023 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002024 (char_u *)0L} SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002025 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002026 (char_u *)&p_paste, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002027 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002028 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2029 (char_u *)&p_pt, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002030 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002031 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2032#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2033 (char_u *)&p_pex, PV_NONE,
2034 {(char_u *)"", (char_u *)0L}
2035#else
2036 (char_u *)NULL, PV_NONE,
2037 {(char_u *)0L, (char_u *)0L}
2038#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002039 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002040 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002041 (char_u *)&p_pm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002042 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002043 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002044 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002045 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002046#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002047 (char_u *)".,,",
2048#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002049 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002050#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002051 (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002052 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002053#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002054 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002055 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002056#else
2057 (char_u *)NULL, PV_NONE,
2058 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002059#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002060 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002061 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2062 (char_u *)&p_pi, PV_PI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002063 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002064 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002065#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002066 (char_u *)&p_pvh, PV_NONE,
2067#else
2068 (char_u *)NULL, PV_NONE,
2069#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002070 {(char_u *)12L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002071 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002072#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002073 (char_u *)VAR_WIN, PV_PVW,
2074#else
2075 (char_u *)NULL, PV_NONE,
2076#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002077 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002078 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002079#ifdef FEAT_PRINTER
2080 (char_u *)&p_pdev, PV_NONE,
2081 {(char_u *)"", (char_u *)0L}
2082#else
2083 (char_u *)NULL, PV_NONE,
2084 {(char_u *)NULL, (char_u *)0L}
2085#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002086 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002087 {"printencoding", "penc", P_STRING|P_VI_DEF,
2088#ifdef FEAT_POSTSCRIPT
2089 (char_u *)&p_penc, PV_NONE,
2090 {(char_u *)"", (char_u *)0L}
2091#else
2092 (char_u *)NULL, PV_NONE,
2093 {(char_u *)NULL, (char_u *)0L}
2094#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002095 SCTX_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002096 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002097#ifdef FEAT_POSTSCRIPT
2098 (char_u *)&p_pexpr, PV_NONE,
2099 {(char_u *)"", (char_u *)0L}
2100#else
2101 (char_u *)NULL, PV_NONE,
2102 {(char_u *)NULL, (char_u *)0L}
2103#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002104 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002105 {"printfont", "pfn", P_STRING|P_VI_DEF,
2106#ifdef FEAT_PRINTER
2107 (char_u *)&p_pfn, PV_NONE,
2108 {
2109# ifdef MSWIN
2110 (char_u *)"Courier_New:h10",
2111# else
2112 (char_u *)"courier",
2113# endif
2114 (char_u *)0L}
2115#else
2116 (char_u *)NULL, PV_NONE,
2117 {(char_u *)NULL, (char_u *)0L}
2118#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002119 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002120 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2121#ifdef FEAT_PRINTER
2122 (char_u *)&p_header, PV_NONE,
Bram Moolenaar0903d562017-08-26 22:30:15 +02002123 /* untranslated to avoid problems when 'encoding'
2124 * is changed */
2125 {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002126#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 Moolenaar8299df92004-07-10 09:47:34 +00002131 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01002132#if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002133 (char_u *)&p_pmcs, PV_NONE,
2134 {(char_u *)"", (char_u *)0L}
2135#else
2136 (char_u *)NULL, PV_NONE,
2137 {(char_u *)NULL, (char_u *)0L}
2138#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002139 SCTX_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002140 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01002141#if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002142 (char_u *)&p_pmfn, PV_NONE,
2143 {(char_u *)"", (char_u *)0L}
2144#else
2145 (char_u *)NULL, PV_NONE,
2146 {(char_u *)NULL, (char_u *)0L}
2147#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002148 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002149 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002150#ifdef FEAT_PRINTER
2151 (char_u *)&p_popt, PV_NONE,
2152 {(char_u *)"", (char_u *)0L}
2153#else
2154 (char_u *)NULL, PV_NONE,
2155 {(char_u *)NULL, (char_u *)0L}
2156#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002157 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002158 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002159 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002160 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002161 {"pumheight", "ph", P_NUM|P_VI_DEF,
2162#ifdef FEAT_INS_EXPAND
2163 (char_u *)&p_ph, PV_NONE,
2164#else
2165 (char_u *)NULL, PV_NONE,
2166#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002167 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaara8f04aa2018-02-10 15:36:55 +01002168 {"pumwidth", "pw", P_NUM|P_VI_DEF,
2169#ifdef FEAT_INS_EXPAND
2170 (char_u *)&p_pw, PV_NONE,
2171#else
2172 (char_u *)NULL, PV_NONE,
2173#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002174 {(char_u *)15L, (char_u *)15L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002175 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002176#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002177 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002178 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002179#else
2180 (char_u *)NULL, PV_NONE,
2181 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002182#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002183 SCTX_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002184 {"pythonthreehome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2185#if defined(FEAT_PYTHON3)
2186 (char_u *)&p_py3home, PV_NONE,
2187 {(char_u *)"", (char_u *)0L}
2188#else
2189 (char_u *)NULL, PV_NONE,
2190 {(char_u *)NULL, (char_u *)0L}
2191#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002192 SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002193 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002194#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002195 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002196 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002197#else
2198 (char_u *)NULL, PV_NONE,
2199 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002200#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002201 SCTX_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002202 {"pythonhome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2203#if defined(FEAT_PYTHON)
2204 (char_u *)&p_pyhome, PV_NONE,
2205 {(char_u *)"", (char_u *)0L}
2206#else
2207 (char_u *)NULL, PV_NONE,
2208 {(char_u *)NULL, (char_u *)0L}
2209#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002210 SCTX_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002211 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2212#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2213 (char_u *)&p_pyx, PV_NONE,
2214#else
2215 (char_u *)NULL, PV_NONE,
2216#endif
2217 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002218 SCTX_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002219 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2220#ifdef FEAT_TEXTOBJ
2221 (char_u *)&p_qe, PV_QE,
2222 {(char_u *)"\\", (char_u *)0L}
2223#else
2224 (char_u *)NULL, PV_NONE,
2225 {(char_u *)NULL, (char_u *)0L}
2226#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002227 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002228 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2229 (char_u *)&p_ro, PV_RO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002230 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002231 {"redraw", NULL, P_BOOL|P_VI_DEF,
2232 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002233 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002234 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2235#ifdef FEAT_RELTIME
2236 (char_u *)&p_rdt, PV_NONE,
2237#else
2238 (char_u *)NULL, PV_NONE,
2239#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002240 {(char_u *)2000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002241 {"regexpengine", "re", P_NUM|P_VI_DEF,
2242 (char_u *)&p_re, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002243 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002244 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2245 (char_u *)VAR_WIN, PV_RNU,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002246 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002247 {"remap", NULL, P_BOOL|P_VI_DEF,
2248 (char_u *)&p_remap, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002249 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002250 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002251#ifdef FEAT_RENDER_OPTIONS
2252 (char_u *)&p_rop, PV_NONE,
2253 {(char_u *)"", (char_u *)0L}
2254#else
2255 (char_u *)NULL, PV_NONE,
2256 {(char_u *)NULL, (char_u *)0L}
2257#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002258 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002259 {"report", NULL, P_NUM|P_VI_DEF,
2260 (char_u *)&p_report, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002261 {(char_u *)2L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002262 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
Bram Moolenaar4f974752019-02-17 17:44:42 +01002263#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00002264 (char_u *)&p_rs, PV_NONE,
2265#else
2266 (char_u *)NULL, PV_NONE,
2267#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002268 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002269 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2270#ifdef FEAT_RIGHTLEFT
2271 (char_u *)&p_ri, PV_NONE,
2272#else
2273 (char_u *)NULL, PV_NONE,
2274#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002275 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002276 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2277#ifdef FEAT_RIGHTLEFT
2278 (char_u *)VAR_WIN, PV_RL,
2279#else
2280 (char_u *)NULL, PV_NONE,
2281#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002282 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002283 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2284#ifdef FEAT_RIGHTLEFT
2285 (char_u *)VAR_WIN, PV_RLC,
2286 {(char_u *)"search", (char_u *)NULL}
2287#else
2288 (char_u *)NULL, PV_NONE,
2289 {(char_u *)NULL, (char_u *)0L}
2290#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002291 SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002292 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002293#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002294 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002295 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002296#else
2297 (char_u *)NULL, PV_NONE,
2298 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002299#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002300 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002301 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2302#ifdef FEAT_CMDL_INFO
2303 (char_u *)&p_ru, PV_NONE,
2304#else
2305 (char_u *)NULL, PV_NONE,
2306#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002307 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002308 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2309#ifdef FEAT_STL_OPT
2310 (char_u *)&p_ruf, PV_NONE,
2311#else
2312 (char_u *)NULL, PV_NONE,
2313#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002314 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002315 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2316 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002317 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002318 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002319 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002320 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2321 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002322 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002323 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002324 (char_u *)VAR_WIN, PV_SCBIND,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002325 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002326 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2327 (char_u *)&p_sj, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002328 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002329 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
Bram Moolenaar375e3392019-01-31 18:26:10 +01002330 (char_u *)&p_so, PV_SO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002331 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002332 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002333 (char_u *)&p_sbo, PV_NONE,
2334 {(char_u *)"ver,jump", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002335 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002336 {"sections", "sect", P_STRING|P_VI_DEF,
2337 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002338 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002339 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002340 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2341 (char_u *)&p_secure, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002342 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002343 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002344 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002345 {(char_u *)"inclusive", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002346 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002347 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002348 (char_u *)&p_slm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002349 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002350 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002351#ifdef FEAT_SESSION
2352 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar4d8bac82018-03-09 21:33:34 +01002353 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize,terminal",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002354 (char_u *)0L}
2355#else
2356 (char_u *)NULL, PV_NONE,
2357 {(char_u *)0L, (char_u *)0L}
2358#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002359 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002360 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2361 (char_u *)&p_sh, PV_NONE,
2362 {
2363#ifdef VMS
2364 (char_u *)"-",
2365#else
Bram Moolenaar4f974752019-02-17 17:44:42 +01002366# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002367 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002368# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002369 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002370# endif
2371#endif /* VMS */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002372 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002373 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2374 (char_u *)&p_shcf, PV_NONE,
2375 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002376#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002377 (char_u *)"/c",
2378#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002379 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002380#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002381 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002382 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2383#ifdef FEAT_QUICKFIX
2384 (char_u *)&p_sp, PV_NONE,
2385 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002386#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002387 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002388#else
2389 (char_u *)">",
2390#endif
2391 (char_u *)0L}
2392#else
2393 (char_u *)NULL, PV_NONE,
2394 {(char_u *)0L, (char_u *)0L}
2395#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002396 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002397 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2398 (char_u *)&p_shq, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002399 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002400 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2401 (char_u *)&p_srr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002402 {(char_u *)">", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002403 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2404#ifdef BACKSLASH_IN_FILENAME
2405 (char_u *)&p_ssl, PV_NONE,
2406#else
2407 (char_u *)NULL, PV_NONE,
2408#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002409 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002410 {"shelltemp", "stmp", P_BOOL,
2411 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002412 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002413 {"shelltype", "st", P_NUM|P_VI_DEF,
2414#ifdef AMIGA
2415 (char_u *)&p_st, PV_NONE,
2416#else
2417 (char_u *)NULL, PV_NONE,
2418#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002419 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002420 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2421 (char_u *)&p_sxq, PV_NONE,
2422 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002423#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002424 (char_u *)"\"",
2425#else
2426 (char_u *)"",
2427#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002428 (char_u *)0L} SCTX_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002429 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2430 (char_u *)&p_sxe, PV_NONE,
2431 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01002432#if defined(MSWIN)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002433 (char_u *)"\"&|<>()@^",
2434#else
2435 (char_u *)"",
2436#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002437 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002438 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2439 (char_u *)&p_sr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002440 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002441 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2442 (char_u *)&p_sw, PV_SW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002443 {(char_u *)8L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002444 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2445 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002446 {(char_u *)"", (char_u *)"filnxtToO"}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002447 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002448 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002449 (char_u *)&p_sn, PV_SN,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002450 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002451 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2452#ifdef FEAT_LINEBREAK
2453 (char_u *)&p_sbr, PV_NONE,
2454#else
2455 (char_u *)NULL, PV_NONE,
2456#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002457 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002458 {"showcmd", "sc", P_BOOL|P_VIM,
2459#ifdef FEAT_CMDL_INFO
2460 (char_u *)&p_sc, PV_NONE,
2461#else
2462 (char_u *)NULL, PV_NONE,
2463#endif
2464 {(char_u *)FALSE,
2465#ifdef UNIX
2466 (char_u *)FALSE
2467#else
2468 (char_u *)TRUE
2469#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002470 } SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002471 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2472 (char_u *)&p_sft, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002473 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002474 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2475 (char_u *)&p_sm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002476 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002477 {"showmode", "smd", P_BOOL|P_VIM,
2478 (char_u *)&p_smd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002479 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002480 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002481 (char_u *)&p_stal, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002482 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002483 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2484 (char_u *)&p_ss, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002485 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002486 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar375e3392019-01-31 18:26:10 +01002487 (char_u *)&p_siso, PV_SISO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002488 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002489 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2490#ifdef FEAT_SIGNS
2491 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002492 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002493#else
2494 (char_u *)NULL, PV_NONE,
2495 {(char_u *)NULL, (char_u *)0L}
2496#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002497 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002498 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2499 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002500 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002501 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2502 (char_u *)&p_scs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002503 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002504 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2505#ifdef FEAT_SMARTINDENT
2506 (char_u *)&p_si, PV_SI,
2507#else
2508 (char_u *)NULL, PV_NONE,
2509#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002510 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002511 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2512 (char_u *)&p_sta, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002513 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002514 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2515 (char_u *)&p_sts, PV_STS,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002516 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002517 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2518 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002519 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002520 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002521#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002522 (char_u *)VAR_WIN, PV_SPELL,
2523#else
2524 (char_u *)NULL, PV_NONE,
2525#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002526 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002527 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002528#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002529 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002530 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002531#else
2532 (char_u *)NULL, PV_NONE,
2533 {(char_u *)0L, (char_u *)0L}
2534#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002535 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002536 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2537 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002538#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002539 (char_u *)&p_spf, PV_SPF,
2540 {(char_u *)"", (char_u *)0L}
2541#else
2542 (char_u *)NULL, PV_NONE,
2543 {(char_u *)0L, (char_u *)0L}
2544#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002545 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002546 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2547 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002548#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002549 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002550 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002551#else
2552 (char_u *)NULL, PV_NONE,
2553 {(char_u *)0L, (char_u *)0L}
2554#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002555 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002556 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002557#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002558 (char_u *)&p_sps, PV_NONE,
2559 {(char_u *)"best", (char_u *)0L}
2560#else
2561 (char_u *)NULL, PV_NONE,
2562 {(char_u *)0L, (char_u *)0L}
2563#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002564 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002565 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002566 (char_u *)&p_sb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002567 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002568 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002569 (char_u *)&p_spr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002570 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002571 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2572 (char_u *)&p_sol, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002573 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002574 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2575#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002576 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002577#else
2578 (char_u *)NULL, PV_NONE,
2579#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002580 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002581 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002582 (char_u *)&p_su, PV_NONE,
2583 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002584 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002585 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002586#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002587 (char_u *)&p_sua, PV_SUA,
2588 {(char_u *)"", (char_u *)0L}
2589#else
2590 (char_u *)NULL, PV_NONE,
2591 {(char_u *)0L, (char_u *)0L}
2592#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002593 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002594 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2595 (char_u *)&p_swf, PV_SWF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002596 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002597 {"swapsync", "sws", P_STRING|P_VI_DEF,
2598 (char_u *)&p_sws, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002599 {(char_u *)"fsync", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002600 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002601 (char_u *)&p_swb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002602 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002603 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2604#ifdef FEAT_SYN_HL
2605 (char_u *)&p_smc, PV_SMC,
2606 {(char_u *)3000L, (char_u *)0L}
2607#else
2608 (char_u *)NULL, PV_NONE,
2609 {(char_u *)0L, (char_u *)0L}
2610#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002611 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002612 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002613#ifdef FEAT_SYN_HL
2614 (char_u *)&p_syn, PV_SYN,
2615 {(char_u *)"", (char_u *)0L}
2616#else
2617 (char_u *)NULL, PV_NONE,
2618 {(char_u *)0L, (char_u *)0L}
2619#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002620 SCTX_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002621 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2622#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002623 (char_u *)&p_tal, PV_NONE,
2624#else
2625 (char_u *)NULL, PV_NONE,
2626#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002627 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002628 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002629 (char_u *)&p_tpm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002630 {(char_u *)10L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002631 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2632 (char_u *)&p_ts, PV_TS,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002633 {(char_u *)8L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002634 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2635 (char_u *)&p_tbs, PV_NONE,
2636#ifdef VMS /* binary searching doesn't appear to work on VMS */
2637 {(char_u *)0L, (char_u *)0L}
2638#else
2639 {(char_u *)TRUE, (char_u *)0L}
2640#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002641 SCTX_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002642 {"tagcase", "tc", P_STRING|P_VIM,
2643 (char_u *)&p_tc, PV_TC,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002644 {(char_u *)"followic", (char_u *)"followic"} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002645 {"taglength", "tl", P_NUM|P_VI_DEF,
2646 (char_u *)&p_tl, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002647 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002648 {"tagrelative", "tr", P_BOOL|P_VIM,
2649 (char_u *)&p_tr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002650 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002651 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002652 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002653 {
2654#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2655 (char_u *)"./tags,./TAGS,tags,TAGS",
2656#else
2657 (char_u *)"./tags,tags",
2658#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002659 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002660 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2661 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002662 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002663 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002664#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002665 (char_u *)&p_tcldll, PV_NONE,
2666 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002667#else
2668 (char_u *)NULL, PV_NONE,
2669 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002670#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002671 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002672 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2673 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002674 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002675 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2676#ifdef FEAT_ARABIC
2677 (char_u *)&p_tbidi, PV_NONE,
2678#else
2679 (char_u *)NULL, PV_NONE,
2680#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002681 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002682 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002683 (char_u *)&p_tenc, PV_NONE,
2684 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002685 SCTX_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002686 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2687#ifdef FEAT_TERMGUICOLORS
2688 (char_u *)&p_tgc, PV_NONE,
2689 {(char_u *)FALSE, (char_u *)FALSE}
2690#else
2691 (char_u*)NULL, PV_NONE,
2692 {(char_u *)FALSE, (char_u *)FALSE}
2693#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002694 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002695 {"termwinkey", "twk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2696#ifdef FEAT_TERMINAL
2697 (char_u *)VAR_WIN, PV_TWK,
2698 {(char_u *)"", (char_u *)NULL}
2699#else
2700 (char_u *)NULL, PV_NONE,
2701 {(char_u *)NULL, (char_u *)0L}
2702#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002703 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002704 {"termwinscroll", "twsl", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2705#ifdef FEAT_TERMINAL
2706 (char_u *)&p_twsl, PV_TWSL,
2707 {(char_u *)10000L, (char_u *)10000L}
2708#else
2709 (char_u *)NULL, PV_NONE,
2710 {(char_u *)NULL, (char_u *)0L}
2711#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002712 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002713 {"termwinsize", "tws", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2714#ifdef FEAT_TERMINAL
2715 (char_u *)VAR_WIN, PV_TWS,
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002716 {(char_u *)"", (char_u *)NULL}
2717#else
2718 (char_u *)NULL, PV_NONE,
2719 {(char_u *)NULL, (char_u *)0L}
2720#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002721 SCTX_INIT},
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01002722 {"termwintype", "twt", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar4f974752019-02-17 17:44:42 +01002723#if defined(MSWIN) && defined(FEAT_TERMINAL)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01002724 (char_u *)&p_twt, PV_NONE,
2725 {(char_u *)"", (char_u *)NULL}
2726#else
2727 (char_u *)NULL, PV_NONE,
2728 {(char_u *)NULL, (char_u *)0L}
2729#endif
2730 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002731 {"terse", NULL, P_BOOL|P_VI_DEF,
2732 (char_u *)&p_terse, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002733 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002734 {"textauto", "ta", P_BOOL|P_VIM,
2735 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002736 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002737 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002738 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2739 (char_u *)&p_tx, PV_TX,
2740 {
2741#ifdef USE_CRNL
2742 (char_u *)TRUE,
2743#else
2744 (char_u *)FALSE,
2745#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002746 (char_u *)0L} SCTX_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002747 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002748 (char_u *)&p_tw, PV_TW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002749 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002750 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002751#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002752 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002753#else
2754 (char_u *)NULL, PV_NONE,
2755#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002756 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002757 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2758 (char_u *)&p_to, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002759 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002760 {"timeout", "to", P_BOOL|P_VI_DEF,
2761 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002762 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002763 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2764 (char_u *)&p_tm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002765 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002766 {"title", NULL, P_BOOL|P_VI_DEF,
2767#ifdef FEAT_TITLE
2768 (char_u *)&p_title, PV_NONE,
2769#else
2770 (char_u *)NULL, PV_NONE,
2771#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002772 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002773 {"titlelen", NULL, P_NUM|P_VI_DEF,
2774#ifdef FEAT_TITLE
2775 (char_u *)&p_titlelen, PV_NONE,
2776#else
2777 (char_u *)NULL, PV_NONE,
2778#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002779 {(char_u *)85L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002780 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002781#ifdef FEAT_TITLE
2782 (char_u *)&p_titleold, PV_NONE,
2783 {(char_u *)N_("Thanks for flying Vim"),
2784 (char_u *)0L}
2785#else
2786 (char_u *)NULL, PV_NONE,
2787 {(char_u *)0L, (char_u *)0L}
2788#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002789 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002790 {"titlestring", NULL, P_STRING|P_VI_DEF,
2791#ifdef FEAT_TITLE
2792 (char_u *)&p_titlestring, PV_NONE,
2793#else
2794 (char_u *)NULL, PV_NONE,
2795#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002796 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002797 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar4f974752019-02-17 17:44:42 +01002798#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002799 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002800 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002801#else
2802 (char_u *)NULL, PV_NONE,
2803 {(char_u *)0L, (char_u *)0L}
2804#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002805 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002806 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002807#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002808 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002809 {(char_u *)"small", (char_u *)0L}
2810#else
2811 (char_u *)NULL, PV_NONE,
2812 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002813#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002814 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002815 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2816 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002817 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002818 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2819 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002820 {(char_u *)-1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002821 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2822 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002823 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002824 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2825 (char_u *)&p_tf, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002826 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002827 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2828#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2829 (char_u *)&p_ttym, PV_NONE,
2830#else
2831 (char_u *)NULL, PV_NONE,
2832#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002833 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002834 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2835 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002836 {(char_u *)999L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002837 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2838 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002839 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002840 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2841 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002842#ifdef FEAT_PERSISTENT_UNDO
2843 (char_u *)&p_udir, PV_NONE,
2844 {(char_u *)".", (char_u *)0L}
2845#else
2846 (char_u *)NULL, PV_NONE,
2847 {(char_u *)0L, (char_u *)0L}
2848#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002849 SCTX_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002850 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2851#ifdef FEAT_PERSISTENT_UNDO
2852 (char_u *)&p_udf, PV_UDF,
2853#else
2854 (char_u *)NULL, PV_NONE,
2855#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002856 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002857 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002858 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002859 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01002860#if defined(UNIX) || defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002861 (char_u *)1000L,
2862#else
2863 (char_u *)100L,
2864#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002865 (char_u *)0L} SCTX_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002866 {"undoreload", "ur", P_NUM|P_VI_DEF,
2867 (char_u *)&p_ur, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002868 { (char_u *)10000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002869 {"updatecount", "uc", P_NUM|P_VI_DEF,
2870 (char_u *)&p_uc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002871 {(char_u *)200L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002872 {"updatetime", "ut", P_NUM|P_VI_DEF,
2873 (char_u *)&p_ut, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002874 {(char_u *)4000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar04958cb2018-06-23 19:23:02 +02002875 {"varsofttabstop", "vsts", P_STRING|P_VI_DEF|P_VIM|P_COMMA,
2876#ifdef FEAT_VARTABS
2877 (char_u *)&p_vsts, PV_VSTS,
2878 {(char_u *)"", (char_u *)0L}
2879#else
2880 (char_u *)NULL, PV_NONE,
2881 {(char_u *)"", (char_u *)NULL}
2882#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002883 SCTX_INIT},
Bram Moolenaar04958cb2018-06-23 19:23:02 +02002884 {"vartabstop", "vts", P_STRING|P_VI_DEF|P_VIM|P_RBUF|P_COMMA,
2885#ifdef FEAT_VARTABS
2886 (char_u *)&p_vts, PV_VTS,
2887 {(char_u *)"", (char_u *)0L}
2888#else
2889 (char_u *)NULL, PV_NONE,
2890 {(char_u *)"", (char_u *)NULL}
2891#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002892 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002893 {"verbose", "vbs", P_NUM|P_VI_DEF,
2894 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002895 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002896 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2897 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002898 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002899 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2900#ifdef FEAT_SESSION
2901 (char_u *)&p_vdir, PV_NONE,
2902 {(char_u *)DFLT_VDIR, (char_u *)0L}
2903#else
2904 (char_u *)NULL, PV_NONE,
2905 {(char_u *)0L, (char_u *)0L}
2906#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002907 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002908 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002909#ifdef FEAT_SESSION
2910 (char_u *)&p_vop, PV_NONE,
Bram Moolenaar13e90412017-11-11 18:16:48 +01002911 {(char_u *)"folds,options,cursor,curdir",
2912 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002913#else
2914 (char_u *)NULL, PV_NONE,
2915 {(char_u *)0L, (char_u *)0L}
2916#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002917 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002918 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002919#ifdef FEAT_VIMINFO
2920 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002921#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002922 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002923#else
2924# ifdef AMIGA
2925 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002926 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002927# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002928 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002929# endif
2930#endif
2931#else
2932 (char_u *)NULL, PV_NONE,
2933 {(char_u *)0L, (char_u *)0L}
2934#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002935 SCTX_INIT},
Bram Moolenaarc229e542018-07-08 21:46:56 +02002936 {"viminfofile", "vif", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP
2937 |P_SECURE|P_VI_DEF,
Bram Moolenaarc4da1132017-07-15 19:39:43 +02002938#ifdef FEAT_VIMINFO
2939 (char_u *)&p_viminfofile, PV_NONE,
2940 {(char_u *)"", (char_u *)0L}
2941#else
2942 (char_u *)NULL, PV_NONE,
2943 {(char_u *)0L, (char_u *)0L}
2944#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002945 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002946 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2947 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002948 (char_u *)&p_ve, PV_NONE,
2949 {(char_u *)"", (char_u *)""}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002950 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002951 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2952 (char_u *)&p_vb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002953 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002954 {"w300", NULL, P_NUM|P_VI_DEF,
2955 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002956 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002957 {"w1200", NULL, P_NUM|P_VI_DEF,
2958 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002959 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002960 {"w9600", NULL, P_NUM|P_VI_DEF,
2961 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002962 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002963 {"warn", NULL, P_BOOL|P_VI_DEF,
2964 (char_u *)&p_warn, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002965 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002966 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2967 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002968 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002969 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002970 (char_u *)&p_ww, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002971 {(char_u *)"", (char_u *)"b,s"} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002972 {"wildchar", "wc", P_NUM|P_VIM,
2973 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002974 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002975 SCTX_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002976 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002977 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002978 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002979 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002980#ifdef FEAT_WILDIGN
2981 (char_u *)&p_wig, PV_NONE,
2982#else
2983 (char_u *)NULL, PV_NONE,
2984#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002985 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002986 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2987 (char_u *)&p_wic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002988 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002989 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2990#ifdef FEAT_WILDMENU
2991 (char_u *)&p_wmnu, PV_NONE,
2992#else
2993 (char_u *)NULL, PV_NONE,
2994#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002995 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002996 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002997 (char_u *)&p_wim, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002998 {(char_u *)"full", (char_u *)0L} SCTX_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002999 {"wildoptions", "wop", P_STRING|P_VI_DEF,
3000#ifdef FEAT_CMDL_COMPL
3001 (char_u *)&p_wop, PV_NONE,
3002 {(char_u *)"", (char_u *)0L}
3003#else
3004 (char_u *)NULL, PV_NONE,
3005 {(char_u *)NULL, (char_u *)0L}
3006#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003007 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003008 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3009#ifdef FEAT_WAK
3010 (char_u *)&p_wak, PV_NONE,
3011 {(char_u *)"menu", (char_u *)0L}
3012#else
3013 (char_u *)NULL, PV_NONE,
3014 {(char_u *)NULL, (char_u *)0L}
3015#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003016 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003017 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003018 (char_u *)&p_window, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003019 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003020 {"winheight", "wh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003021 (char_u *)&p_wh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003022 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003023 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003024 (char_u *)VAR_WIN, PV_WFH,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003025 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003026 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003027 (char_u *)VAR_WIN, PV_WFW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003028 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003029 {"winminheight", "wmh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003030 (char_u *)&p_wmh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003031 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003032 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003033 (char_u *)&p_wmw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003034 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003035 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar4f974752019-02-17 17:44:42 +01003036#if defined(MSWIN) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003037 (char_u *)&p_winptydll, PV_NONE, {
3038# ifdef _WIN64
3039 (char_u *)"winpty64.dll",
3040# else
3041 (char_u *)"winpty32.dll",
3042# endif
3043 (char_u *)0L}
3044#else
3045 (char_u *)NULL, PV_NONE,
3046 {(char_u *)0L, (char_u *)0L}
3047#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003048 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003049 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003050 (char_u *)&p_wiw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003051 {(char_u *)20L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003052 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3053 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003054 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003055 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3056 (char_u *)&p_wm, PV_WM,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003057 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003058 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3059 (char_u *)&p_ws, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003060 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003061 {"write", NULL, P_BOOL|P_VI_DEF,
3062 (char_u *)&p_write, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003063 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003064 {"writeany", "wa", P_BOOL|P_VI_DEF,
3065 (char_u *)&p_wa, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003066 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003067 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3068 (char_u *)&p_wb, PV_NONE,
3069 {
3070#ifdef FEAT_WRITEBACKUP
3071 (char_u *)TRUE,
3072#else
3073 (char_u *)FALSE,
3074#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003075 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003076 {"writedelay", "wd", P_NUM|P_VI_DEF,
3077 (char_u *)&p_wd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003078 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003079
3080/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003081#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003082 (char_u *)&vvv, PV_NONE, \
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003083 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003084
3085 p_term("t_AB", T_CAB)
3086 p_term("t_AF", T_CAF)
3087 p_term("t_AL", T_CAL)
3088 p_term("t_al", T_AL)
3089 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003090 p_term("t_BE", T_BE)
3091 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003092 p_term("t_cd", T_CD)
3093 p_term("t_ce", T_CE)
3094 p_term("t_cl", T_CL)
3095 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003096 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003097 p_term("t_Co", T_CCO)
3098 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003099 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003100 p_term("t_cs", T_CS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003101 p_term("t_CV", T_CSV)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003102 p_term("t_da", T_DA)
3103 p_term("t_db", T_DB)
3104 p_term("t_DL", T_CDL)
3105 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003106 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003107 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003108 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003109 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003110 p_term("t_IE", T_CIE)
3111 p_term("t_IS", T_CIS)
3112 p_term("t_ke", T_KE)
3113 p_term("t_ks", T_KS)
3114 p_term("t_le", T_LE)
3115 p_term("t_mb", T_MB)
3116 p_term("t_md", T_MD)
3117 p_term("t_me", T_ME)
3118 p_term("t_mr", T_MR)
3119 p_term("t_ms", T_MS)
3120 p_term("t_nd", T_ND)
3121 p_term("t_op", T_OP)
Bram Moolenaara20f83d2017-10-15 13:35:01 +02003122 p_term("t_RF", T_RFG)
Bram Moolenaare5401222015-06-25 19:16:56 +02003123 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003124 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003125 p_term("t_RI", T_CRI)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003126 p_term("t_Ri", T_SRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003127 p_term("t_RS", T_CRS)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003128 p_term("t_RT", T_CRT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003129 p_term("t_RV", T_CRV)
3130 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003131 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003132 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003133 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003134 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003135 p_term("t_SI", T_CSI)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003136 p_term("t_Si", T_SSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003137 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003138 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003139 p_term("t_sr", T_SR)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003140 p_term("t_ST", T_CST)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003141 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003142 p_term("t_te", T_TE)
3143 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003144 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003145 p_term("t_ts", T_TS)
3146 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003147 p_term("t_ue", T_UE)
3148 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003149 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003150 p_term("t_vb", T_VB)
3151 p_term("t_ve", T_VE)
3152 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003153 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003154 p_term("t_vs", T_VS)
3155 p_term("t_WP", T_CWP)
3156 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003157 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003158 p_term("t_xs", T_XS)
3159 p_term("t_ZH", T_CZH)
3160 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003161 p_term("t_8f", T_8F)
3162 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003163
3164/* terminal key codes are not in here */
3165
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003166 /* end marker */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003167 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCTX_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003168};
3169
3170#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3171
Bram Moolenaar071d4272004-06-13 20:20:40 +00003172static char *(p_ambw_values[]) = {"single", "double", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003173static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003174static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003175static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003176#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003177static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003178#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003179#ifdef FEAT_CMDL_COMPL
3180static char *(p_wop_values[]) = {"tagfile", NULL};
3181#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003182#ifdef FEAT_WAK
3183static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3184#endif
3185static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003186static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3187static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003188static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003189#ifdef FEAT_BROWSE
3190static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3191#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003192static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
Bram Moolenaar57657d82006-04-21 22:12:41 +00003193static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003194static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
Bram Moolenaarf2732452018-06-03 14:47:35 +02003195static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", "prompt", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003196static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003197static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3198#ifdef FEAT_FOLDING
3199static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003200# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003201 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003202# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003203 NULL};
3204static char *(p_fcl_values[]) = {"all", NULL};
3205#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003206#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003207static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003208#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003209#ifdef FEAT_SIGNS
3210static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3211#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01003212#if defined(MSWIN) && defined(FEAT_TERMINAL)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01003213static char *(p_twt_values[]) = {"winpty", "conpty", "", NULL};
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01003214#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003215
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003216static void set_options_default(int opt_flags);
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003217static void set_string_default_esc(char *name, char_u *val, int escape);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003218static char_u *term_bg_default(void);
Bram Moolenaar916a8182018-11-25 02:18:29 +01003219static void did_set_option(int opt_idx, int opt_flags, int new_value, int value_checked);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003220static char_u *option_expand(int opt_idx, char_u *val);
3221static void didset_options(void);
3222static void didset_options2(void);
3223static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003224#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003225static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003226#else
3227# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3228#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003229static void set_string_option_global(int opt_idx, char_u **varp);
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003230static 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);
3231static char *set_chars_option(char_u **varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003232#ifdef FEAT_CLIPBOARD
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003233static char *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003234#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003235#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003236static char *did_set_spell_option(int is_spellfile);
3237static char *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003238#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003239#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003240static void set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003241#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003242static char *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3243static 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 +01003244static void check_redraw(long_u flags);
3245static int findoption(char_u *);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02003246static int find_key_option(char_u *arg_arg, int has_lt);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003247static void showoptions(int all, int opt_flags);
3248static int optval_default(struct vimoption *, char_u *varp);
3249static void showoneopt(struct vimoption *, int opt_flags);
Bram Moolenaared18f2c2019-01-24 20:30:52 +01003250static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, long_u flags);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003251static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3252static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3253static int istermoption(struct vimoption *);
3254static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3255static char_u *get_varp(struct vimoption *);
3256static void option_value2string(struct vimoption *, int opt_flags);
3257static void check_winopt(winopt_T *wop);
3258static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003259#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003260static void langmap_init(void);
3261static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003262#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003263static void paste_option_changed(void);
3264static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003265#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003266static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003267#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003268static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3269static int check_opt_strings(char_u *val, char **values, int);
3270static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003271#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003272static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003273#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003274
3275/*
3276 * Initialize the options, first part.
3277 *
3278 * Called only once from main(), just after creating the first buffer.
Bram Moolenaar07268702018-03-01 21:57:32 +01003279 * If "clean_arg" is TRUE Vim was started with --clean.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003280 */
3281 void
Bram Moolenaar07268702018-03-01 21:57:32 +01003282set_init_1(int clean_arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003283{
3284 char_u *p;
3285 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003286 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003287
3288#ifdef FEAT_LANGMAP
3289 langmap_init();
3290#endif
3291
3292 /* Be Vi compatible by default */
3293 p_cp = TRUE;
3294
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003295 /* Use POSIX compatibility when $VIM_POSIX is set. */
3296 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003297 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003298 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003299 set_string_default("shm", (char_u *)"A");
3300 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003301
Bram Moolenaar071d4272004-06-13 20:20:40 +00003302 /*
3303 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003304 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003305 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003306 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003307#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003308 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar4f974752019-02-17 17:44:42 +01003309# ifdef MSWIN
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003310 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003311# endif
3312#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003313 )
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003314 set_string_default_esc("sh", p, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003315
3316#ifdef FEAT_WILDIGN
3317 /*
3318 * Set the default for 'backupskip' to include environment variables for
3319 * temp files.
3320 */
3321 {
3322# ifdef UNIX
3323 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3324# else
3325 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3326# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003327 int len;
3328 garray_T ga;
3329 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003330
3331 ga_init2(&ga, 1, 100);
3332 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3333 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003334 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003335# ifdef UNIX
3336 if (*names[n] == NUL)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003337# ifdef MACOS_X
3338 p = (char_u *)"/private/tmp";
3339# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003340 p = (char_u *)"/tmp";
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003341# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003342 else
3343# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003344 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003345 if (p != NULL && *p != NUL)
3346 {
3347 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003348 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003349 if (ga_grow(&ga, len) == OK)
3350 {
3351 if (ga.ga_len > 0)
3352 STRCAT(ga.ga_data, ",");
3353 STRCAT(ga.ga_data, p);
3354 add_pathsep(ga.ga_data);
3355 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003356 ga.ga_len += len;
3357 }
3358 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003359 if (mustfree)
3360 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003361 }
3362 if (ga.ga_data != NULL)
3363 {
3364 set_string_default("bsk", ga.ga_data);
3365 vim_free(ga.ga_data);
3366 }
3367 }
3368#endif
3369
3370 /*
3371 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3372 */
3373 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003374 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003375 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003376#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3377 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3378#endif
3379 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003380#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003381 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003382 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003383#else
3384# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003385 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003386 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003387# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003388 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003389# endif
3390#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003391 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003392 opt_idx = findoption((char_u *)"maxmem");
3393 if (opt_idx >= 0)
3394 {
3395#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003396 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3397 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003398#endif
3399 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3400 }
3401 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003402 }
3403
Bram Moolenaar071d4272004-06-13 20:20:40 +00003404#ifdef FEAT_SEARCHPATH
3405 {
3406 char_u *cdpath;
3407 char_u *buf;
3408 int i;
3409 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003410 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003411
3412 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003413 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003414 if (cdpath != NULL)
3415 {
3416 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3417 if (buf != NULL)
3418 {
3419 buf[0] = ','; /* start with ",", current dir first */
3420 j = 1;
3421 for (i = 0; cdpath[i] != NUL; ++i)
3422 {
3423 if (vim_ispathlistsep(cdpath[i]))
3424 buf[j++] = ',';
3425 else
3426 {
3427 if (cdpath[i] == ' ' || cdpath[i] == ',')
3428 buf[j++] = '\\';
3429 buf[j++] = cdpath[i];
3430 }
3431 }
3432 buf[j] = NUL;
3433 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003434 if (opt_idx >= 0)
3435 {
3436 options[opt_idx].def_val[VI_DEFAULT] = buf;
3437 options[opt_idx].flags |= P_DEF_ALLOCED;
3438 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003439 else
3440 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003441 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003442 if (mustfree)
3443 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003444 }
3445 }
3446#endif
3447
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003448#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003449 /* Set print encoding on platforms that don't default to latin1 */
3450 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003451# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003452 (char_u *)"cp1252"
3453# else
3454# ifdef VMS
3455 (char_u *)"dec-mcs"
3456# else
3457# ifdef EBCDIC
3458 (char_u *)"ebcdic-uk"
3459# else
3460# ifdef MAC
3461 (char_u *)"mac-roman"
3462# else /* HPUX */
3463 (char_u *)"hp-roman8"
3464# endif
3465# endif
3466# endif
3467# endif
3468 );
3469#endif
3470
3471#ifdef FEAT_POSTSCRIPT
3472 /* 'printexpr' must be allocated to be able to evaluate it. */
3473 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003474# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003475 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003476# else
3477# ifdef VMS
3478 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3479
3480# else
3481 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3482# endif
3483# endif
3484 );
3485#endif
3486
3487 /*
3488 * Set all the options (except the terminal options) to their default
3489 * value. Also set the global value for local options.
3490 */
3491 set_options_default(0);
3492
Bram Moolenaar07268702018-03-01 21:57:32 +01003493#ifdef CLEAN_RUNTIMEPATH
3494 if (clean_arg)
3495 {
3496 opt_idx = findoption((char_u *)"runtimepath");
3497 if (opt_idx >= 0)
3498 {
3499 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3500 p_rtp = (char_u *)CLEAN_RUNTIMEPATH;
3501 }
3502 opt_idx = findoption((char_u *)"packpath");
3503 if (opt_idx >= 0)
3504 {
3505 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3506 p_pp = (char_u *)CLEAN_RUNTIMEPATH;
3507 }
3508 }
3509#endif
3510
Bram Moolenaar071d4272004-06-13 20:20:40 +00003511#ifdef FEAT_GUI
3512 if (found_reverse_arg)
3513 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3514#endif
3515
3516 curbuf->b_p_initialized = TRUE;
3517 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003518 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003519 check_buf_options(curbuf);
3520 check_win_options(curwin);
3521 check_options();
3522
3523 /* Must be before option_expand(), because that one needs vim_isIDc() */
3524 didset_options();
3525
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003526#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003527 /* Use the current chartab for the generic chartab. This is not in
3528 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003529 init_spell_chartab();
3530#endif
3531
Bram Moolenaar071d4272004-06-13 20:20:40 +00003532 /*
3533 * Expand environment variables and things like "~" for the defaults.
3534 * If option_expand() returns non-NULL the variable is expanded. This can
3535 * only happen for non-indirect options.
3536 * Also set the default to the expanded value, so ":set" does not list
3537 * them.
3538 * Don't set the P_ALLOCED flag, because we don't want to free the
3539 * default.
3540 */
3541 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3542 {
3543 if ((options[opt_idx].flags & P_GETTEXT)
3544 && options[opt_idx].var != NULL)
3545 p = (char_u *)_(*(char **)options[opt_idx].var);
3546 else
3547 p = option_expand(opt_idx, NULL);
3548 if (p != NULL && (p = vim_strsave(p)) != NULL)
3549 {
3550 *(char_u **)options[opt_idx].var = p;
3551 /* VIMEXP
3552 * Defaults for all expanded options are currently the same for Vi
3553 * and Vim. When this changes, add some code here! Also need to
3554 * split P_DEF_ALLOCED in two.
3555 */
3556 if (options[opt_idx].flags & P_DEF_ALLOCED)
3557 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3558 options[opt_idx].def_val[VI_DEFAULT] = p;
3559 options[opt_idx].flags |= P_DEF_ALLOCED;
3560 }
3561 }
3562
Bram Moolenaar071d4272004-06-13 20:20:40 +00003563 save_file_ff(curbuf); /* Buffer is unchanged */
3564
Bram Moolenaar071d4272004-06-13 20:20:40 +00003565#if defined(FEAT_ARABIC)
3566 /* Detect use of mlterm.
3567 * Mlterm is a terminal emulator akin to xterm that has some special
3568 * abilities (bidi namely).
3569 * NOTE: mlterm's author is being asked to 'set' a variable
3570 * instead of an environment variable due to inheritance.
3571 */
3572 if (mch_getenv((char_u *)"MLTERM") != NULL)
3573 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3574#endif
3575
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003576 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003577
Bram Moolenaar4f974752019-02-17 17:44:42 +01003578# if defined(MSWIN) && defined(FEAT_GETTEXT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003579 /*
3580 * If $LANG isn't set, try to get a good value for it. This makes the
3581 * right language be used automatically. Don't do this for English.
3582 */
3583 if (mch_getenv((char_u *)"LANG") == NULL)
3584 {
3585 char buf[20];
3586
3587 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3588 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3589 * only the first two. */
3590 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3591 (LPTSTR)buf, 20);
3592 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3593 {
3594 /* There are a few exceptions (probably more) */
3595 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3596 STRCPY(buf, "zh_TW");
3597 else if (STRNICMP(buf, "chs", 3) == 0
3598 || STRNICMP(buf, "zhc", 3) == 0)
3599 STRCPY(buf, "zh_CN");
3600 else if (STRNICMP(buf, "jp", 2) == 0)
3601 STRCPY(buf, "ja");
3602 else
3603 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003604 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003605 }
3606 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003607# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003608# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003609 /* Moved to os_mac_conv.c to avoid dependency problems. */
3610 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003611# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003612# endif
3613
3614 /* enc_locale() will try to find the encoding of the current locale. */
3615 p = enc_locale();
3616 if (p != NULL)
3617 {
3618 char_u *save_enc;
3619
3620 /* Try setting 'encoding' and check if the value is valid.
3621 * If not, go back to the default "latin1". */
3622 save_enc = p_enc;
3623 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003624 if (STRCMP(p_enc, "gb18030") == 0)
3625 {
3626 /* We don't support "gb18030", but "cp936" is a good substitute
3627 * for practical purposes, thus use that. It's not an alias to
3628 * still support conversion between gb18030 and utf-8. */
3629 p_enc = vim_strsave((char_u *)"cp936");
3630 vim_free(p);
3631 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003632 if (mb_init() == NULL)
3633 {
3634 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003635 if (opt_idx >= 0)
3636 {
3637 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3638 options[opt_idx].flags |= P_DEF_ALLOCED;
3639 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003640
Bram Moolenaard0573012017-10-28 21:11:06 +02003641#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003642 if (STRCMP(p_enc, "latin1") == 0 || enc_utf8)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003643 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003644 /* Adjust the default for 'isprint' and 'iskeyword' to match
3645 * latin1. Also set the defaults for when 'nocompatible' is
3646 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003647 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003648 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003649 set_string_option_direct((char_u *)"isk", -1,
3650 ISK_LATIN1, OPT_FREE, SID_NONE);
3651 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003652 if (opt_idx >= 0)
3653 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003654 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003655 if (opt_idx >= 0)
3656 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003657 (void)init_chartab();
3658 }
3659#endif
3660
Bram Moolenaar4f974752019-02-17 17:44:42 +01003661#if defined(MSWIN) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003662 /* Win32 console: When GetACP() returns a different value from
3663 * GetConsoleCP() set 'termencoding'. */
3664 if (GetACP() != GetConsoleCP())
3665 {
3666 char buf[50];
3667
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01003668 /* Win32 console: In ConPTY, GetConsoleCP() returns zero.
3669 * Use an alternative value. */
3670 if (GetConsoleCP() == 0)
3671 sprintf(buf, "cp%ld", (long)GetACP());
3672 else
3673 sprintf(buf, "cp%ld", (long)GetConsoleCP());
Bram Moolenaar071d4272004-06-13 20:20:40 +00003674 p_tenc = vim_strsave((char_u *)buf);
3675 if (p_tenc != NULL)
3676 {
3677 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003678 if (opt_idx >= 0)
3679 {
3680 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3681 options[opt_idx].flags |= P_DEF_ALLOCED;
3682 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003683 convert_setup(&input_conv, p_tenc, p_enc);
3684 convert_setup(&output_conv, p_enc, p_tenc);
3685 }
3686 else
3687 p_tenc = empty_option;
3688 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003689#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01003690#if defined(MSWIN)
Bram Moolenaar05159a02005-02-26 23:04:13 +00003691 /* $HOME may have characters in active code page. */
3692 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003693#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003694 }
3695 else
3696 {
3697 vim_free(p_enc);
3698 p_enc = save_enc;
3699 }
3700 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003701
3702#ifdef FEAT_MULTI_LANG
3703 /* Set the default for 'helplang'. */
3704 set_helplang_default(get_mess_lang());
3705#endif
3706}
3707
3708/*
3709 * Set an option to its default value.
3710 * This does not take care of side effects!
3711 */
3712 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003713set_option_default(
3714 int opt_idx,
3715 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3716 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003717{
3718 char_u *varp; /* pointer to variable for current option */
3719 int dvi; /* index in def_val[] */
3720 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003721 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003722 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3723
3724 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3725 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003726 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003727 {
3728 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3729 if (flags & P_STRING)
3730 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003731 /* Use set_string_option_direct() for local options to handle
3732 * freeing and allocating the value. */
3733 if (options[opt_idx].indir != PV_NONE)
3734 set_string_option_direct(NULL, opt_idx,
3735 options[opt_idx].def_val[dvi], opt_flags, 0);
3736 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003737 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003738 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3739 free_string_option(*(char_u **)(varp));
3740 *(char_u **)varp = options[opt_idx].def_val[dvi];
3741 options[opt_idx].flags &= ~P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003742 }
3743 }
3744 else if (flags & P_NUM)
3745 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003746 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003747 win_comp_scroll(curwin);
3748 else
3749 {
Bram Moolenaar375e3392019-01-31 18:26:10 +01003750 long def_val = (long)(long_i)options[opt_idx].def_val[dvi];
3751
3752 if ((long *)varp == &curwin->w_p_so
3753 || (long *)varp == &curwin->w_p_siso)
3754 // 'scrolloff' and 'sidescrolloff' local values have a
3755 // different default value than the global default.
3756 *(long *)varp = -1;
3757 else
3758 *(long *)varp = def_val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003759 /* May also set global value for local option. */
3760 if (both)
3761 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
Bram Moolenaar375e3392019-01-31 18:26:10 +01003762 def_val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003763 }
3764 }
3765 else /* P_BOOL */
3766 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003767 /* the cast to long is required for Manx C, long_i is needed for
3768 * MSVC */
3769 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003770#ifdef UNIX
3771 /* 'modeline' defaults to off for root */
3772 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3773 *(int *)varp = FALSE;
3774#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003775 /* May also set global value for local option. */
3776 if (both)
3777 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3778 *(int *)varp;
3779 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003780
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003781 /* The default value is not insecure. */
3782 flagsp = insecure_flag(opt_idx, opt_flags);
3783 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003784 }
3785
3786#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003787 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003788#endif
3789}
3790
3791/*
3792 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003793 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003794 */
3795 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003796set_options_default(
3797 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003798{
3799 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003800 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003801 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003802
3803 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003804 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003805 && (opt_flags == 0
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003806 || (options[i].var != (char_u *)&p_enc
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003807# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003808 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003809 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003810# endif
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003811 )))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003812 set_option_default(i, opt_flags, p_cp);
3813
Bram Moolenaar071d4272004-06-13 20:20:40 +00003814 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003815 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003816 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003817#ifdef FEAT_CINDENT
3818 parse_cino(curbuf);
3819#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003820}
3821
3822/*
3823 * Set the Vi-default value of a string option.
3824 * Used for 'sh', 'backupskip' and 'term'.
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003825 * When "escape" is TRUE escape spaces with a backslash.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003826 */
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003827 static void
3828set_string_default_esc(char *name, char_u *val, int escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003829{
3830 char_u *p;
3831 int opt_idx;
3832
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003833 if (escape && vim_strchr(val, ' ') != NULL)
3834 p = vim_strsave_escaped(val, (char_u *)" ");
3835 else
3836 p = vim_strsave(val);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003837 if (p != NULL) /* we don't want a NULL */
3838 {
3839 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003840 if (opt_idx >= 0)
3841 {
3842 if (options[opt_idx].flags & P_DEF_ALLOCED)
3843 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3844 options[opt_idx].def_val[VI_DEFAULT] = p;
3845 options[opt_idx].flags |= P_DEF_ALLOCED;
3846 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003847 }
3848}
3849
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003850 void
3851set_string_default(char *name, char_u *val)
3852{
3853 set_string_default_esc(name, val, FALSE);
3854}
3855
Bram Moolenaar071d4272004-06-13 20:20:40 +00003856/*
3857 * Set the Vi-default value of a number option.
3858 * Used for 'lines' and 'columns'.
3859 */
3860 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003861set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003862{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003863 int opt_idx;
3864
3865 opt_idx = findoption((char_u *)name);
3866 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003867 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003868}
3869
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003870#if defined(EXITFREE) || defined(PROTO)
3871/*
3872 * Free all options.
3873 */
3874 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003875free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003876{
3877 int i;
3878
3879 for (i = 0; !istermoption(&options[i]); i++)
3880 {
3881 if (options[i].indir == PV_NONE)
3882 {
3883 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003884 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003885 free_string_option(*(char_u **)options[i].var);
3886 if (options[i].flags & P_DEF_ALLOCED)
3887 free_string_option(options[i].def_val[VI_DEFAULT]);
3888 }
3889 else if (options[i].var != VAR_WIN
3890 && (options[i].flags & P_STRING))
3891 /* buffer-local option: free global value */
3892 free_string_option(*(char_u **)options[i].var);
3893 }
3894}
3895#endif
3896
3897
Bram Moolenaar071d4272004-06-13 20:20:40 +00003898/*
3899 * Initialize the options, part two: After getting Rows and Columns and
3900 * setting 'term'.
3901 */
3902 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003903set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003904{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003905 int idx;
3906
Bram Moolenaar071d4272004-06-13 20:20:40 +00003907 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003908 * 'scroll' defaults to half the window height. The stored default is zero,
3909 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003910 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003911 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003912 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003913 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003914 comp_col();
3915
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003916 /*
3917 * 'window' is only for backwards compatibility with Vi.
3918 * Default is Rows - 1.
3919 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003920 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003921 p_window = Rows - 1;
3922 set_number_default("window", Rows - 1);
3923
Bram Moolenaarf740b292006-02-16 22:11:02 +00003924 /* For DOS console the default is always black. */
Bram Moolenaar4f974752019-02-17 17:44:42 +01003925#if !((defined(MSWIN)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003926 /*
3927 * If 'background' wasn't set by the user, try guessing the value,
3928 * depending on the terminal name. Only need to check for terminals
3929 * with a dark background, that can handle color.
3930 */
3931 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003932 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3933 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003934 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003935 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003936 /* don't mark it as set, when starting the GUI it may be
3937 * changed again */
3938 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003939 }
3940#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003941
3942#ifdef CURSOR_SHAPE
3943 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3944#endif
3945#ifdef FEAT_MOUSESHAPE
3946 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3947#endif
3948#ifdef FEAT_PRINTER
3949 (void)parse_printoptions(); /* parse 'printoptions' default value */
3950#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003951}
3952
3953/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003954 * Return "dark" or "light" depending on the kind of terminal.
3955 * This is just guessing! Recognized are:
3956 * "linux" Linux console
3957 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003958 * "cygwin.*" Cygwin shell
3959 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00003960 * We also check the COLORFGBG environment variable, which is set by
3961 * rxvt and derivatives. This variable contains either two or three
3962 * values separated by semicolons; we want the last value in either
3963 * case. If this value is 0-6 or 8, our background is dark.
3964 */
3965 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003966term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003967{
Bram Moolenaar4f974752019-02-17 17:44:42 +01003968#if defined(MSWIN)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003969 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003970 return (char_u *)"dark";
3971#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003972 char_u *p;
3973
Bram Moolenaarf740b292006-02-16 22:11:02 +00003974 if (STRCMP(T_NAME, "linux") == 0
3975 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003976 || STRNCMP(T_NAME, "cygwin", 6) == 0
3977 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00003978 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3979 && (p = vim_strrchr(p, ';')) != NULL
3980 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3981 && p[2] == NUL))
3982 return (char_u *)"dark";
3983 return (char_u *)"light";
3984#endif
3985}
3986
3987/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003988 * Initialize the options, part three: After reading the .vimrc
3989 */
3990 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003991set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003992{
Bram Moolenaar4f974752019-02-17 17:44:42 +01003993#if defined(UNIX) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003994/*
3995 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3996 * This is done after other initializations, where 'shell' might have been
3997 * set, but only if they have not been set before.
3998 */
3999 char_u *p;
4000 int idx_srr;
4001 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004002# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004003 int idx_sp;
4004 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004005# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004006
4007 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004008 if (idx_srr < 0)
4009 do_srr = FALSE;
4010 else
4011 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004012# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004013 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004014 if (idx_sp < 0)
4015 do_sp = FALSE;
4016 else
4017 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004018# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004019 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004020 if (p != NULL)
4021 {
4022 /*
4023 * Default for p_sp is "| tee", for p_srr is ">".
4024 * For known shells it is changed here to include stderr.
4025 */
4026 if ( fnamecmp(p, "csh") == 0
4027 || fnamecmp(p, "tcsh") == 0
Bram Moolenaar4f974752019-02-17 17:44:42 +01004028# if defined(MSWIN) // also check with .exe extension
Bram Moolenaar071d4272004-06-13 20:20:40 +00004029 || fnamecmp(p, "csh.exe") == 0
4030 || fnamecmp(p, "tcsh.exe") == 0
4031# endif
4032 )
4033 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004034# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004035 if (do_sp)
4036 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01004037# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004038 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004039# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004040 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004041# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004042 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4043 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004044# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004045 if (do_srr)
4046 {
4047 p_srr = (char_u *)">&";
4048 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4049 }
4050 }
4051 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004052 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004053 if ( fnamecmp(p, "sh") == 0
4054 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004055 || fnamecmp(p, "mksh") == 0
4056 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004057 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004058 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004059 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004060 || fnamecmp(p, "fish") == 0
Bram Moolenaar4f974752019-02-17 17:44:42 +01004061# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004062 || fnamecmp(p, "cmd") == 0
4063 || fnamecmp(p, "sh.exe") == 0
4064 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004065 || fnamecmp(p, "mksh.exe") == 0
4066 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004067 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004068 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004069 || fnamecmp(p, "bash.exe") == 0
4070 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004071# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004072 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004073 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004074# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004075 if (do_sp)
4076 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01004077# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004078 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004079# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004080 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004081# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004082 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4083 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004084# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004085 if (do_srr)
4086 {
4087 p_srr = (char_u *)">%s 2>&1";
4088 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4089 }
4090 }
4091 vim_free(p);
4092 }
4093#endif
4094
Bram Moolenaar4f974752019-02-17 17:44:42 +01004095#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004096 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004097 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4098 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004099 * This is done after other initializations, where 'shell' might have been
4100 * set, but only if they have not been set before. Default for p_shcf is
4101 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004102 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004103 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004104 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004105 {
4106 int idx3;
4107
4108 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004109 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004110 {
4111 p_shcf = (char_u *)"-c";
4112 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4113 }
4114
Bram Moolenaar071d4272004-06-13 20:20:40 +00004115 /* Somehow Win32 requires the quotes around the redirection too */
4116 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004117 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004118 {
4119 p_sxq = (char_u *)"\"";
4120 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4121 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004122 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004123 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4124 {
4125 int idx3;
4126
4127 /*
4128 * cmd.exe on Windows will strip the first and last double quote given
4129 * on the command line, e.g. most of the time things like:
4130 * cmd /c "my path/to/echo" "my args to echo"
4131 * become:
4132 * my path/to/echo" "my args to echo
4133 * when executed.
4134 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004135 * To avoid this, set shellxquote to surround the command in
4136 * parenthesis. This appears to make most commands work, without
4137 * breaking commands that worked previously, such as
4138 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004139 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004140 idx3 = findoption((char_u *)"sxq");
4141 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4142 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004143 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004144 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4145 }
4146
Bram Moolenaara64ba222012-02-12 23:23:31 +01004147 idx3 = findoption((char_u *)"shcf");
4148 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4149 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004150 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004151 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4152 }
4153 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004154#endif
4155
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004156 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004157 {
4158 int idx_ffs = findoption((char_u *)"ffs");
4159
4160 /* Apply the first entry of 'fileformats' to the initial buffer. */
4161 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4162 set_fileformat(default_fileformat(), OPT_LOCAL);
4163 }
4164
Bram Moolenaar071d4272004-06-13 20:20:40 +00004165#ifdef FEAT_TITLE
4166 set_title_defaults();
4167#endif
4168}
4169
4170#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4171/*
4172 * When 'helplang' is still at its default value, set it to "lang".
4173 * Only the first two characters of "lang" are used.
4174 */
4175 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004176set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004177{
4178 int idx;
4179
4180 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4181 return;
4182 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004183 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004184 {
4185 if (options[idx].flags & P_ALLOCED)
4186 free_string_option(p_hlg);
4187 p_hlg = vim_strsave(lang);
4188 if (p_hlg == NULL)
4189 p_hlg = empty_option;
4190 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004191 {
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004192 // zh_CN becomes "cn", zh_TW becomes "tw"
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004193 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4194 {
4195 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4196 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4197 }
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004198 // any C like setting, such as C.UTF-8, becomes "en"
4199 else if (STRLEN(p_hlg) >= 1 && *p_hlg == 'C')
4200 {
4201 p_hlg[0] = 'e';
4202 p_hlg[1] = 'n';
4203 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004204 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004205 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004206 options[idx].flags |= P_ALLOCED;
4207 }
4208}
4209#endif
4210
4211#ifdef FEAT_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00004212 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004213gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004214{
4215 if (gui_get_lightness(gui.back_pixel) < 127)
4216 return (char_u *)"dark";
4217 return (char_u *)"light";
4218}
4219
4220/*
4221 * Option initializations that can only be done after opening the GUI window.
4222 */
4223 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004224init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004225{
4226 /* Set the 'background' option according to the lightness of the
4227 * background color, unless the user has set it already. */
4228 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4229 {
4230 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4231 highlight_changed();
4232 }
4233}
4234#endif
4235
4236#ifdef FEAT_TITLE
4237/*
4238 * 'title' and 'icon' only default to true if they have not been set or reset
4239 * in .vimrc and we can read the old value.
4240 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4241 * they can be reset. This reduces startup time when using X on a remote
4242 * machine.
4243 */
4244 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004245set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004246{
4247 int idx1;
4248 long val;
4249
4250 /*
4251 * If GUI is (going to be) used, we can always set the window title and
4252 * icon name. Saves a bit of time, because the X11 display server does
4253 * not need to be contacted.
4254 */
4255 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004256 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004257 {
4258#ifdef FEAT_GUI
4259 if (gui.starting || gui.in_use)
4260 val = TRUE;
4261 else
4262#endif
4263 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004264 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004265 p_title = val;
4266 }
4267 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004268 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004269 {
4270#ifdef FEAT_GUI
4271 if (gui.starting || gui.in_use)
4272 val = TRUE;
4273 else
4274#endif
4275 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004276 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004277 p_icon = val;
4278 }
4279}
4280#endif
4281
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004282#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004283 static void
4284trigger_optionsset_string(
4285 int opt_idx,
4286 int opt_flags,
4287 char_u *oldval,
4288 char_u *newval)
4289{
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02004290 // Don't do this recursively.
4291 if (oldval != NULL && newval != NULL
4292 && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004293 {
4294 char_u buf_type[7];
4295
4296 sprintf((char *)buf_type, "%s",
4297 (opt_flags & OPT_LOCAL) ? "local" : "global");
4298 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4299 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4300 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4301 apply_autocmds(EVENT_OPTIONSET,
4302 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4303 reset_v_option_vars();
4304 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004305}
4306#endif
4307
Bram Moolenaar071d4272004-06-13 20:20:40 +00004308/*
4309 * Parse 'arg' for option settings.
4310 *
4311 * 'arg' may be IObuff, but only when no errors can be present and option
4312 * does not need to be expanded with option_expand().
4313 * "opt_flags":
4314 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004315 * OPT_GLOBAL for ":setglobal"
4316 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004317 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004318 * OPT_WINONLY to only set window-local options
4319 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004320 *
4321 * returns FAIL if an error is detected, OK otherwise
4322 */
4323 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004324do_set(
4325 char_u *arg, /* option string (may be written to!) */
4326 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004327{
4328 int opt_idx;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004329 char *errmsg;
4330 char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00004331 char_u *startarg;
4332 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4333 int nextchar; /* next non-white char after option name */
4334 int afterchar; /* character just after option name */
4335 int len;
4336 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004337 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004338 int key;
4339 long_u flags; /* flags for current option */
4340 char_u *varp = NULL; /* pointer to variable for current option */
4341 int did_show = FALSE; /* already showed one value */
4342 int adding; /* "opt+=arg" */
4343 int prepending; /* "opt^=arg" */
4344 int removing; /* "opt-=arg" */
4345 int cp_val = 0;
4346 char_u key_name[2];
4347
4348 if (*arg == NUL)
4349 {
4350 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004351 did_show = TRUE;
4352 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004353 }
4354
4355 while (*arg != NUL) /* loop to process all options */
4356 {
4357 errmsg = NULL;
4358 startarg = arg; /* remember for error message */
4359
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004360 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4361 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004362 {
4363 /*
4364 * ":set all" show all options.
4365 * ":set all&" set all options to their default value.
4366 */
4367 arg += 3;
4368 if (*arg == '&')
4369 {
4370 ++arg;
4371 /* Only for :set command set global value of local options. */
4372 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004373 didset_options();
4374 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004375 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004376 }
4377 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004378 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004379 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004380 did_show = TRUE;
4381 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004382 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004383 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004384 {
4385 showoptions(2, opt_flags);
4386 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004387 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004388 arg += 7;
4389 }
4390 else
4391 {
4392 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004393 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004394 {
4395 prefix = 0;
4396 arg += 2;
4397 }
4398 else if (STRNCMP(arg, "inv", 3) == 0)
4399 {
4400 prefix = 2;
4401 arg += 3;
4402 }
4403
4404 /* find end of name */
4405 key = 0;
4406 if (*arg == '<')
4407 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004408 opt_idx = -1;
4409 /* look out for <t_>;> */
4410 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4411 len = 5;
4412 else
4413 {
4414 len = 1;
4415 while (arg[len] != NUL && arg[len] != '>')
4416 ++len;
4417 }
4418 if (arg[len] != '>')
4419 {
4420 errmsg = e_invarg;
4421 goto skip;
4422 }
4423 arg[len] = NUL; /* put NUL after name */
4424 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4425 opt_idx = findoption(arg + 1);
4426 arg[len++] = '>'; /* restore '>' */
4427 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004428 key = find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004429 }
4430 else
4431 {
4432 len = 0;
4433 /*
4434 * The two characters after "t_" may not be alphanumeric.
4435 */
4436 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4437 len = 4;
4438 else
4439 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4440 ++len;
4441 nextchar = arg[len];
4442 arg[len] = NUL; /* put NUL after name */
4443 opt_idx = findoption(arg);
4444 arg[len] = nextchar; /* restore nextchar */
4445 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004446 key = find_key_option(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004447 }
4448
4449 /* remember character after option name */
4450 afterchar = arg[len];
4451
4452 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004453 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004454 ++len;
4455
4456 adding = FALSE;
4457 prepending = FALSE;
4458 removing = FALSE;
4459 if (arg[len] != NUL && arg[len + 1] == '=')
4460 {
4461 if (arg[len] == '+')
4462 {
4463 adding = TRUE; /* "+=" */
4464 ++len;
4465 }
4466 else if (arg[len] == '^')
4467 {
4468 prepending = TRUE; /* "^=" */
4469 ++len;
4470 }
4471 else if (arg[len] == '-')
4472 {
4473 removing = TRUE; /* "-=" */
4474 ++len;
4475 }
4476 }
4477 nextchar = arg[len];
4478
4479 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4480 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004481 errmsg = N_("E518: Unknown option");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004482 goto skip;
4483 }
4484
4485 if (opt_idx >= 0)
4486 {
4487 if (options[opt_idx].var == NULL) /* hidden option: skip */
4488 {
4489 /* Only give an error message when requesting the value of
4490 * a hidden option, ignore setting it. */
4491 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4492 && (!(options[opt_idx].flags & P_BOOL)
4493 || nextchar == '?'))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004494 errmsg = N_("E519: Option not supported");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004495 goto skip;
4496 }
4497
4498 flags = options[opt_idx].flags;
4499 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4500 }
4501 else
4502 {
4503 flags = P_STRING;
4504 if (key < 0)
4505 {
4506 key_name[0] = KEY2TERMCAP0(key);
4507 key_name[1] = KEY2TERMCAP1(key);
4508 }
4509 else
4510 {
4511 key_name[0] = KS_KEY;
4512 key_name[1] = (key & 0xff);
4513 }
4514 }
4515
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004516 /* Skip all options that are not window-local (used when showing
4517 * an already loaded buffer in a window). */
4518 if ((opt_flags & OPT_WINONLY)
4519 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4520 goto skip;
4521
Bram Moolenaara3227e22006-03-08 21:32:40 +00004522 /* Skip all options that are window-local (used for :vimgrep). */
4523 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4524 && options[opt_idx].var == VAR_WIN)
4525 goto skip;
4526
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004527 /* Disallow changing some options from modelines. */
4528 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004529 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004530 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004531 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004532 errmsg = _("E520: Not allowed in a modeline");
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004533 goto skip;
4534 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004535#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004536 /* In diff mode some options are overruled. This avoids that
4537 * 'foldmethod' becomes "marker" instead of "diff" and that
4538 * "wrap" gets set. */
4539 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004540 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004541 && (
4542#ifdef FEAT_FOLDING
4543 options[opt_idx].indir == PV_FDM ||
4544#endif
4545 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004546 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004547#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004548 }
4549
4550#ifdef HAVE_SANDBOX
4551 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004552 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004553 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004554 errmsg = _(e_sandbox);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004555 goto skip;
4556 }
4557#endif
4558
4559 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4560 {
4561 arg += len;
4562 cp_val = p_cp;
4563 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4564 {
4565 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4566 {
4567 cp_val = FALSE;
4568 arg += 3;
4569 }
4570 else /* "opt&vi": set to Vi default */
4571 {
4572 cp_val = TRUE;
4573 arg += 2;
4574 }
4575 }
4576 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004577 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004578 {
4579 errmsg = e_trailing;
4580 goto skip;
4581 }
4582 }
4583
4584 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004585 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4586 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004587 */
4588 if (nextchar == '?'
4589 || (prefix == 1
4590 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4591 && !(flags & P_BOOL)))
4592 {
4593 /*
4594 * print value
4595 */
4596 if (did_show)
4597 msg_putchar('\n'); /* cursor below last one */
4598 else
4599 {
4600 gotocmdline(TRUE); /* cursor at status line */
4601 did_show = TRUE; /* remember that we did a line */
4602 }
4603 if (opt_idx >= 0)
4604 {
4605 showoneopt(&options[opt_idx], opt_flags);
4606#ifdef FEAT_EVAL
4607 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004608 {
4609 /* Mention where the option was last set. */
4610 if (varp == options[opt_idx].var)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004611 last_set_msg(options[opt_idx].script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004612 else if ((int)options[opt_idx].indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004613 last_set_msg(curwin->w_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004614 (int)options[opt_idx].indir & PV_MASK]);
4615 else if ((int)options[opt_idx].indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004616 last_set_msg(curbuf->b_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004617 (int)options[opt_idx].indir & PV_MASK]);
4618 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004619#endif
4620 }
4621 else
4622 {
4623 char_u *p;
4624
4625 p = find_termcode(key_name);
4626 if (p == NULL)
4627 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004628 errmsg = N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004629 goto skip;
4630 }
4631 else
4632 (void)show_one_termcode(key_name, p, TRUE);
4633 }
4634 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004635 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004636 errmsg = e_trailing;
4637 }
4638 else
4639 {
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004640 int value_is_replaced = !prepending && !adding && !removing;
Bram Moolenaar916a8182018-11-25 02:18:29 +01004641 int value_checked = FALSE;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004642
Bram Moolenaar071d4272004-06-13 20:20:40 +00004643 if (flags & P_BOOL) /* boolean */
4644 {
4645 if (nextchar == '=' || nextchar == ':')
4646 {
4647 errmsg = e_invarg;
4648 goto skip;
4649 }
4650
4651 /*
4652 * ":set opt!": invert
4653 * ":set opt&": reset to default value
4654 * ":set opt<": reset to global value
4655 */
4656 if (nextchar == '!')
4657 value = *(int *)(varp) ^ 1;
4658 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004659 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004660 ((flags & P_VI_DEF) || cp_val)
4661 ? VI_DEFAULT : VIM_DEFAULT];
4662 else if (nextchar == '<')
4663 {
4664 /* For 'autoread' -1 means to use global value. */
4665 if ((int *)varp == &curbuf->b_p_ar
4666 && opt_flags == OPT_LOCAL)
4667 value = -1;
4668 else
4669 value = *(int *)get_varp_scope(&(options[opt_idx]),
4670 OPT_GLOBAL);
4671 }
4672 else
4673 {
4674 /*
4675 * ":set invopt": invert
4676 * ":set opt" or ":set noopt": set or reset
4677 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004678 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004679 {
4680 errmsg = e_trailing;
4681 goto skip;
4682 }
4683 if (prefix == 2) /* inv */
4684 value = *(int *)(varp) ^ 1;
4685 else
4686 value = prefix;
4687 }
4688
4689 errmsg = set_bool_option(opt_idx, varp, (int)value,
4690 opt_flags);
4691 }
4692 else /* numeric or string */
4693 {
4694 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4695 || prefix != 1)
4696 {
4697 errmsg = e_invarg;
4698 goto skip;
4699 }
4700
4701 if (flags & P_NUM) /* numeric */
4702 {
4703 /*
4704 * Different ways to set a number option:
4705 * & set to default value
4706 * < set to global value
4707 * <xx> accept special key codes for 'wildchar'
4708 * c accept any non-digit for 'wildchar'
4709 * [-]0-9 set number
4710 * other error
4711 */
4712 ++arg;
4713 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004714 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004715 ((flags & P_VI_DEF) || cp_val)
4716 ? VI_DEFAULT : VIM_DEFAULT];
4717 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004718 {
4719 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4720 * use the global value. */
4721 if ((long *)varp == &curbuf->b_p_ul
4722 && opt_flags == OPT_LOCAL)
4723 value = NO_LOCAL_UNDOLEVEL;
4724 else
4725 value = *(long *)get_varp_scope(
4726 &(options[opt_idx]), OPT_GLOBAL);
4727 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004728 else if (((long *)varp == &p_wc
4729 || (long *)varp == &p_wcm)
4730 && (*arg == '<'
4731 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004732 || (*arg != NUL
4733 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004734 && !VIM_ISDIGIT(*arg))))
4735 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004736 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004737 if (value == 0 && (long *)varp != &p_wcm)
4738 {
4739 errmsg = e_invarg;
4740 goto skip;
4741 }
4742 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004743 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4744 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004745 /* Allow negative (for 'undolevels'), octal and
4746 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004747 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4748 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004749 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004750 {
4751 errmsg = e_invarg;
4752 goto skip;
4753 }
4754 }
4755 else
4756 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004757 errmsg = N_("E521: Number required after =");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004758 goto skip;
4759 }
4760
4761 if (adding)
4762 value = *(long *)varp + value;
4763 if (prepending)
4764 value = *(long *)varp * value;
4765 if (removing)
4766 value = *(long *)varp - value;
4767 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004768 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004769 }
4770 else if (opt_idx >= 0) /* string */
4771 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004772 char_u *save_arg = NULL;
4773 char_u *s = NULL;
4774 char_u *oldval = NULL; /* previous value if *varp */
4775 char_u *newval;
4776 char_u *origval = NULL;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004777#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004778 char_u *saved_origval = NULL;
4779 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004780#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004781 unsigned newlen;
4782 int comma;
4783 int bs;
4784 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004785 was allocated */
4786
4787 /* When using ":set opt=val" for a global option
4788 * with a local value the local value will be
4789 * reset, use the global value here. */
4790 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004791 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004792 varp = options[opt_idx].var;
4793
4794 /* The old value is kept until we are sure that the
4795 * new value is valid. */
4796 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004797
4798 /* When setting the local value of a global
4799 * option, the old value may be the global value. */
4800 if (((int)options[opt_idx].indir & PV_BOTH)
4801 && (opt_flags & OPT_LOCAL))
4802 origval = *(char_u **)get_varp(
4803 &options[opt_idx]);
4804 else
4805 origval = oldval;
4806
Bram Moolenaar071d4272004-06-13 20:20:40 +00004807 if (nextchar == '&') /* set to default val */
4808 {
4809 newval = options[opt_idx].def_val[
4810 ((flags & P_VI_DEF) || cp_val)
4811 ? VI_DEFAULT : VIM_DEFAULT];
4812 if ((char_u **)varp == &p_bg)
4813 {
4814 /* guess the value of 'background' */
4815#ifdef FEAT_GUI
4816 if (gui.in_use)
4817 newval = gui_bg_default();
4818 else
4819#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004820 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004821 }
4822
4823 /* expand environment variables and ~ (since the
4824 * default value was already expanded, only
4825 * required when an environment variable was set
4826 * later */
4827 if (newval == NULL)
4828 newval = empty_option;
4829 else
4830 {
4831 s = option_expand(opt_idx, newval);
4832 if (s == NULL)
4833 s = newval;
4834 newval = vim_strsave(s);
4835 }
4836 new_value_alloced = TRUE;
4837 }
4838 else if (nextchar == '<') /* set to global val */
4839 {
4840 newval = vim_strsave(*(char_u **)get_varp_scope(
4841 &(options[opt_idx]), OPT_GLOBAL));
4842 new_value_alloced = TRUE;
4843 }
4844 else
4845 {
4846 ++arg; /* jump to after the '=' or ':' */
4847
4848 /*
4849 * Set 'keywordprg' to ":help" if an empty
4850 * value was passed to :set by the user.
4851 * Misuse errbuf[] for the resulting string.
4852 */
4853 if (varp == (char_u *)&p_kp
4854 && (*arg == NUL || *arg == ' '))
4855 {
4856 STRCPY(errbuf, ":help");
4857 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004858 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004859 }
4860 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004861 * Convert 'backspace' number to string, for
4862 * adding, prepending and removing string.
4863 */
4864 else if (varp == (char_u *)&p_bs
4865 && VIM_ISDIGIT(**(char_u **)varp))
4866 {
4867 i = getdigits((char_u **)varp);
4868 switch (i)
4869 {
4870 case 0:
4871 *(char_u **)varp = empty_option;
4872 break;
4873 case 1:
4874 *(char_u **)varp = vim_strsave(
4875 (char_u *)"indent,eol");
4876 break;
4877 case 2:
4878 *(char_u **)varp = vim_strsave(
4879 (char_u *)"indent,eol,start");
4880 break;
4881 }
4882 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004883 if (origval == oldval)
4884 origval = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004885 oldval = *(char_u **)varp;
4886 }
4887 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004888 * Convert 'whichwrap' number to string, for
4889 * backwards compatibility with Vim 3.0.
4890 * Misuse errbuf[] for the resulting string.
4891 */
4892 else if (varp == (char_u *)&p_ww
4893 && VIM_ISDIGIT(*arg))
4894 {
4895 *errbuf = NUL;
4896 i = getdigits(&arg);
4897 if (i & 1)
4898 STRCAT(errbuf, "b,");
4899 if (i & 2)
4900 STRCAT(errbuf, "s,");
4901 if (i & 4)
4902 STRCAT(errbuf, "h,l,");
4903 if (i & 8)
4904 STRCAT(errbuf, "<,>,");
4905 if (i & 16)
4906 STRCAT(errbuf, "[,],");
4907 if (*errbuf != NUL) /* remove trailing , */
4908 errbuf[STRLEN(errbuf) - 1] = NUL;
4909 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004910 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004911 }
4912 /*
4913 * Remove '>' before 'dir' and 'bdir', for
4914 * backwards compatibility with version 3.0
4915 */
4916 else if ( *arg == '>'
4917 && (varp == (char_u *)&p_dir
4918 || varp == (char_u *)&p_bdir))
4919 {
4920 ++arg;
4921 }
4922
Bram Moolenaar071d4272004-06-13 20:20:40 +00004923 /*
4924 * Copy the new string into allocated memory.
4925 * Can't use set_string_option_direct(), because
4926 * we need to remove the backslashes.
4927 */
4928 /* get a bit too much */
4929 newlen = (unsigned)STRLEN(arg) + 1;
4930 if (adding || prepending || removing)
4931 newlen += (unsigned)STRLEN(origval) + 1;
4932 newval = alloc(newlen);
4933 if (newval == NULL) /* out of mem, don't change */
4934 break;
4935 s = newval;
4936
4937 /*
4938 * Copy the string, skip over escaped chars.
4939 * For MS-DOS and WIN32 backslashes before normal
4940 * file name characters are not removed, and keep
4941 * backslash at start, for "\\machine\path", but
4942 * do remove it for "\\\\machine\\path".
4943 * The reverse is found in ExpandOldSetting().
4944 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004945 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004946 {
4947 if (*arg == '\\' && arg[1] != NUL
4948#ifdef BACKSLASH_IN_FILENAME
4949 && !((flags & P_EXPAND)
4950 && vim_isfilec(arg[1])
4951 && (arg[1] != '\\'
4952 || (s == newval
4953 && arg[2] != '\\')))
4954#endif
4955 )
4956 ++arg; /* remove backslash */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004957 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004958 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004959 {
4960 /* copy multibyte char */
4961 mch_memmove(s, arg, (size_t)i);
4962 arg += i;
4963 s += i;
4964 }
4965 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004966 *s++ = *arg++;
4967 }
4968 *s = NUL;
4969
4970 /*
4971 * Expand environment variables and ~.
4972 * Don't do it when adding without inserting a
4973 * comma.
4974 */
4975 if (!(adding || prepending || removing)
4976 || (flags & P_COMMA))
4977 {
4978 s = option_expand(opt_idx, newval);
4979 if (s != NULL)
4980 {
4981 vim_free(newval);
4982 newlen = (unsigned)STRLEN(s) + 1;
4983 if (adding || prepending || removing)
4984 newlen += (unsigned)STRLEN(origval) + 1;
4985 newval = alloc(newlen);
4986 if (newval == NULL)
4987 break;
4988 STRCPY(newval, s);
4989 }
4990 }
4991
4992 /* locate newval[] in origval[] when removing it
4993 * and when adding to avoid duplicates */
4994 i = 0; /* init for GCC */
4995 if (removing || (flags & P_NODUP))
4996 {
4997 i = (int)STRLEN(newval);
4998 bs = 0;
4999 for (s = origval; *s; ++s)
5000 {
5001 if ((!(flags & P_COMMA)
5002 || s == origval
5003 || (s[-1] == ',' && !(bs & 1)))
5004 && STRNCMP(s, newval, i) == 0
5005 && (!(flags & P_COMMA)
5006 || s[i] == ','
5007 || s[i] == NUL))
5008 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005009 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005010 * even number of backslashes or a single
5011 * backslash preceded by a comma before it
5012 * is recognized as a separator */
5013 if ((s > origval + 1
5014 && s[-1] == '\\'
5015 && s[-2] != ',')
5016 || (s == origval + 1
5017 && s[-1] == '\\'))
5018
Bram Moolenaar071d4272004-06-13 20:20:40 +00005019 ++bs;
5020 else
5021 bs = 0;
5022 }
5023
5024 /* do not add if already there */
5025 if ((adding || prepending) && *s)
5026 {
5027 prepending = FALSE;
5028 adding = FALSE;
5029 STRCPY(newval, origval);
5030 }
5031 }
5032
5033 /* concatenate the two strings; add a ',' if
5034 * needed */
5035 if (adding || prepending)
5036 {
5037 comma = ((flags & P_COMMA) && *origval != NUL
5038 && *newval != NUL);
5039 if (adding)
5040 {
5041 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005042 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005043 if (comma && i > 1
5044 && (flags & P_ONECOMMA) == P_ONECOMMA
5045 && origval[i - 1] == ','
5046 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005047 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005048 mch_memmove(newval + i + comma, newval,
5049 STRLEN(newval) + 1);
5050 mch_memmove(newval, origval, (size_t)i);
5051 }
5052 else
5053 {
5054 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005055 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005056 }
5057 if (comma)
5058 newval[i] = ',';
5059 }
5060
5061 /* Remove newval[] from origval[]. (Note: "i" has
5062 * been set above and is used here). */
5063 if (removing)
5064 {
5065 STRCPY(newval, origval);
5066 if (*s)
5067 {
5068 /* may need to remove a comma */
5069 if (flags & P_COMMA)
5070 {
5071 if (s == origval)
5072 {
5073 /* include comma after string */
5074 if (s[i] == ',')
5075 ++i;
5076 }
5077 else
5078 {
5079 /* include comma before string */
5080 --s;
5081 ++i;
5082 }
5083 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005084 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005085 }
5086 }
5087
5088 if (flags & P_FLAGLIST)
5089 {
5090 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005091 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005092 {
5093 /* if options have P_FLAGLIST and
5094 * P_ONECOMMA such as 'whichwrap' */
5095 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005096 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005097 if (*s != ',' && *(s + 1) == ','
5098 && vim_strchr(s + 2, *s) != NULL)
5099 {
5100 /* Remove the duplicated value and
5101 * the next comma. */
5102 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005103 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005104 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005105 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005106 else
5107 {
5108 if ((!(flags & P_COMMA) || *s != ',')
5109 && vim_strchr(s + 1, *s) != NULL)
5110 {
5111 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005112 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005113 }
5114 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005115 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005116 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005117 }
5118
5119 if (save_arg != NULL) /* number for 'whichwrap' */
5120 arg = save_arg;
5121 new_value_alloced = TRUE;
5122 }
5123
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005124 /*
5125 * Set the new value.
5126 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005127 *(char_u **)(varp) = newval;
5128
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005129#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005130 if (!starting
5131# ifdef FEAT_CRYPT
5132 && options[opt_idx].indir != PV_KEY
5133# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005134 && origval != NULL && newval != NULL)
5135 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005136 /* origval may be freed by
5137 * did_set_string_option(), make a copy. */
5138 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005139 /* newval (and varp) may become invalid if the
5140 * buffer is closed by autocommands. */
5141 saved_newval = vim_strsave(newval);
5142 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005143#endif
5144
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005145 {
5146 long_u *p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005147 int secure_saved = secure;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005148
5149 // When an option is set in the sandbox, from a
5150 // modeline or in secure mode, then deal with side
5151 // effects in secure mode. Also when the value was
5152 // set with the P_INSECURE flag and is not
5153 // completely replaced.
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005154 if ((opt_flags & OPT_MODELINE)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005155#ifdef HAVE_SANDBOX
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005156 || sandbox != 0
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005157#endif
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005158 || (!value_is_replaced && (*p & P_INSECURE)))
5159 secure = 1;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005160
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005161 // Handle side effects, and set the global value
5162 // for ":set" on local options. Note: when setting
5163 // 'syntax' or 'filetype' autocommands may be
5164 // triggered that can cause havoc.
5165 errmsg = did_set_string_option(
5166 opt_idx, (char_u **)varp,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005167 new_value_alloced, oldval, errbuf,
5168 opt_flags, &value_checked);
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005169
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005170 secure = secure_saved;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005171 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005172
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005173#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005174 if (errmsg == NULL)
5175 trigger_optionsset_string(opt_idx, opt_flags,
5176 saved_origval, saved_newval);
5177 vim_free(saved_origval);
5178 vim_free(saved_newval);
5179#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005180 /* If error detected, print the error message. */
5181 if (errmsg != NULL)
5182 goto skip;
5183 }
5184 else /* key code option */
5185 {
5186 char_u *p;
5187
5188 if (nextchar == '&')
5189 {
5190 if (add_termcap_entry(key_name, TRUE) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005191 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005192 }
5193 else
5194 {
5195 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005196 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005197 if (*p == '\\' && p[1] != NUL)
5198 ++p;
5199 nextchar = *p;
5200 *p = NUL;
5201 add_termcode(key_name, arg, FALSE);
5202 *p = nextchar;
5203 }
5204 if (full_screen)
5205 ttest(FALSE);
5206 redraw_all_later(CLEAR);
5207 }
5208 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005209
Bram Moolenaar071d4272004-06-13 20:20:40 +00005210 if (opt_idx >= 0)
Bram Moolenaar916a8182018-11-25 02:18:29 +01005211 did_set_option(
5212 opt_idx, opt_flags, value_is_replaced, value_checked);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005213 }
5214
5215skip:
5216 /*
5217 * Advance to next argument.
5218 * - skip until a blank found, taking care of backslashes
5219 * - skip blanks
5220 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5221 */
5222 for (i = 0; i < 2 ; ++i)
5223 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005224 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005225 if (*arg++ == '\\' && *arg != NUL)
5226 ++arg;
5227 arg = skipwhite(arg);
5228 if (*arg != '=')
5229 break;
5230 }
5231 }
5232
5233 if (errmsg != NULL)
5234 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005235 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005236 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005237 if (i + (arg - startarg) < IOSIZE)
5238 {
5239 /* append the argument with the error */
5240 STRCAT(IObuff, ": ");
5241 mch_memmove(IObuff + i, startarg, (arg - startarg));
5242 IObuff[i + (arg - startarg)] = NUL;
5243 }
5244 /* make sure all characters are printable */
5245 trans_characters(IObuff, IOSIZE);
5246
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005247 ++no_wait_return; // wait_return done later
5248 emsg((char *)IObuff); // show error highlighted
Bram Moolenaar071d4272004-06-13 20:20:40 +00005249 --no_wait_return;
5250
5251 return FAIL;
5252 }
5253
5254 arg = skipwhite(arg);
5255 }
5256
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005257theend:
5258 if (silent_mode && did_show)
5259 {
5260 /* After displaying option values in silent mode. */
5261 silent_mode = FALSE;
5262 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5263 msg_putchar('\n');
5264 cursor_on(); /* msg_start() switches it off */
5265 out_flush();
5266 silent_mode = TRUE;
5267 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5268 }
5269
Bram Moolenaar071d4272004-06-13 20:20:40 +00005270 return OK;
5271}
5272
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005273/*
5274 * Call this when an option has been given a new value through a user command.
5275 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5276 */
5277 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005278did_set_option(
5279 int opt_idx,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005280 int opt_flags, // possibly with OPT_MODELINE
5281 int new_value, // value was replaced completely
5282 int value_checked) // value was checked to be safe, no need to set the
5283 // P_INSECURE flag.
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005284{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005285 long_u *p;
5286
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005287 options[opt_idx].flags |= P_WAS_SET;
5288
5289 /* When an option is set in the sandbox, from a modeline or in secure mode
5290 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005291 * flag. */
5292 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar916a8182018-11-25 02:18:29 +01005293 if (!value_checked && (secure
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005294#ifdef HAVE_SANDBOX
5295 || sandbox != 0
5296#endif
Bram Moolenaar916a8182018-11-25 02:18:29 +01005297 || (opt_flags & OPT_MODELINE)))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005298 *p = *p | P_INSECURE;
5299 else if (new_value)
5300 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005301}
5302
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005303 static char *
5304illegal_char(char *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005305{
5306 if (errbuf == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005307 return "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00005308 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005309 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005310 return errbuf;
5311}
5312
5313/*
5314 * Convert a key name or string into a key value.
5315 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005316 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005317 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005318 int
5319string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005320{
5321 if (*arg == '<')
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02005322 return find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005323 if (*arg == '^')
5324 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005325 if (multi_byte)
5326 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005327 return *arg;
5328}
5329
5330#ifdef FEAT_CMDWIN
5331/*
5332 * Check value of 'cedit' and set cedit_key.
5333 * Returns NULL if value is OK, error message otherwise.
5334 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005335 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005336check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005337{
5338 int n;
5339
5340 if (*p_cedit == NUL)
5341 cedit_key = -1;
5342 else
5343 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005344 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005345 if (vim_isprintc(n))
5346 return e_invarg;
5347 cedit_key = n;
5348 }
5349 return NULL;
5350}
5351#endif
5352
5353#ifdef FEAT_TITLE
5354/*
5355 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5356 * maketitle() to create and display it.
5357 * When switching the title or icon off, call mch_restore_title() to get
5358 * the old value back.
5359 */
5360 static void
Bram Moolenaar84a93082018-06-16 22:58:15 +02005361did_set_title(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005362{
5363 if (starting != NO_SCREEN
5364#ifdef FEAT_GUI
5365 && !gui.starting
5366#endif
5367 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00005368 maketitle();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005369}
5370#endif
5371
5372/*
5373 * set_options_bin - called when 'bin' changes value.
5374 */
5375 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005376set_options_bin(
5377 int oldval,
5378 int newval,
5379 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005380{
5381 /*
5382 * The option values that are changed when 'bin' changes are
5383 * copied when 'bin is set and restored when 'bin' is reset.
5384 */
5385 if (newval)
5386 {
5387 if (!oldval) /* switched on */
5388 {
5389 if (!(opt_flags & OPT_GLOBAL))
5390 {
5391 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5392 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5393 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5394 curbuf->b_p_et_nobin = curbuf->b_p_et;
5395 }
5396 if (!(opt_flags & OPT_LOCAL))
5397 {
5398 p_tw_nobin = p_tw;
5399 p_wm_nobin = p_wm;
5400 p_ml_nobin = p_ml;
5401 p_et_nobin = p_et;
5402 }
5403 }
5404
5405 if (!(opt_flags & OPT_GLOBAL))
5406 {
5407 curbuf->b_p_tw = 0; /* no automatic line wrap */
5408 curbuf->b_p_wm = 0; /* no automatic line wrap */
5409 curbuf->b_p_ml = 0; /* no modelines */
5410 curbuf->b_p_et = 0; /* no expandtab */
5411 }
5412 if (!(opt_flags & OPT_LOCAL))
5413 {
5414 p_tw = 0;
5415 p_wm = 0;
5416 p_ml = FALSE;
5417 p_et = FALSE;
5418 p_bin = TRUE; /* needed when called for the "-b" argument */
5419 }
5420 }
5421 else if (oldval) /* switched off */
5422 {
5423 if (!(opt_flags & OPT_GLOBAL))
5424 {
5425 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5426 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5427 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5428 curbuf->b_p_et = curbuf->b_p_et_nobin;
5429 }
5430 if (!(opt_flags & OPT_LOCAL))
5431 {
5432 p_tw = p_tw_nobin;
5433 p_wm = p_wm_nobin;
5434 p_ml = p_ml_nobin;
5435 p_et = p_et_nobin;
5436 }
5437 }
5438}
5439
5440#ifdef FEAT_VIMINFO
5441/*
5442 * Find the parameter represented by the given character (eg ', :, ", or /),
5443 * and return its associated value in the 'viminfo' string.
5444 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005445 * If the parameter is not specified in the string or there is no following
5446 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005447 */
5448 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005449get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005450{
5451 char_u *p;
5452
5453 p = find_viminfo_parameter(type);
5454 if (p != NULL && VIM_ISDIGIT(*p))
5455 return atoi((char *)p);
5456 return -1;
5457}
5458
5459/*
5460 * Find the parameter represented by the given character (eg ''', ':', '"', or
5461 * '/') in the 'viminfo' option and return a pointer to the string after it.
5462 * Return NULL if the parameter is not specified in the string.
5463 */
5464 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005465find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005466{
5467 char_u *p;
5468
5469 for (p = p_viminfo; *p; ++p)
5470 {
5471 if (*p == type)
5472 return p + 1;
5473 if (*p == 'n') /* 'n' is always the last one */
5474 break;
5475 p = vim_strchr(p, ','); /* skip until next ',' */
5476 if (p == NULL) /* hit the end without finding parameter */
5477 break;
5478 }
5479 return NULL;
5480}
5481#endif
5482
5483/*
5484 * Expand environment variables for some string options.
5485 * These string options cannot be indirect!
5486 * If "val" is NULL expand the current value of the option.
5487 * Return pointer to NameBuff, or NULL when not expanded.
5488 */
5489 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005490option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005491{
5492 /* if option doesn't need expansion nothing to do */
5493 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5494 return NULL;
5495
5496 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5497 * expand_env() would truncate the string. */
5498 if (val != NULL && STRLEN(val) > MAXPATHL)
5499 return NULL;
5500
5501 if (val == NULL)
5502 val = *(char_u **)options[opt_idx].var;
5503
5504 /*
5505 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5506 * Escape spaces when expanding 'tags', they are used to separate file
5507 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005508 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005509 */
5510 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005511 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005512#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005513 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5514#endif
5515 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005516 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5517 return NULL;
5518
5519 return NameBuff;
5520}
5521
5522/*
5523 * After setting various option values: recompute variables that depend on
5524 * option values.
5525 */
5526 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005527didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005528{
5529 /* initialize the table for 'iskeyword' et.al. */
5530 (void)init_chartab();
5531
5532 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
5533 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005534 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005535#ifdef FEAT_SESSION
5536 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5537 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5538#endif
5539#ifdef FEAT_FOLDING
5540 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5541#endif
5542 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005543 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005544 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005545#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5546 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5547#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005548#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005549 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005550 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005551 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005552 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005553#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01005554#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005555 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5556#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005557#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005558 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5559#endif
5560#ifdef FEAT_CMDWIN
5561 /* set cedit_key */
5562 (void)check_cedit();
5563#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005564#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005565 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005566#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005567#ifdef FEAT_LINEBREAK
5568 /* initialize the table for 'breakat'. */
5569 fill_breakat_flags();
5570#endif
5571
5572}
5573
5574/*
5575 * More side effects of setting options.
5576 */
5577 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005578didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005579{
5580 /* Initialize the highlight_attr[] table. */
5581 (void)highlight_changed();
5582
5583 /* Parse default for 'wildmode' */
5584 check_opt_wim();
5585
5586 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005587 /* Parse default for 'fillchars'. */
5588 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005589
5590#ifdef FEAT_CLIPBOARD
5591 /* Parse default for 'clipboard' */
5592 (void)check_clipboard_option();
5593#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005594#ifdef FEAT_VARTABS
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01005595 vim_free(curbuf->b_p_vsts_array);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005596 tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_array);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01005597 vim_free(curbuf->b_p_vts_array);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005598 tabstop_set(curbuf->b_p_vts, &curbuf->b_p_vts_array);
5599#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005600}
5601
5602/*
5603 * Check for string options that are NULL (normally only termcap options).
5604 */
5605 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005606check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005607{
5608 int opt_idx;
5609
5610 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5611 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5612 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5613}
5614
5615/*
5616 * Check string options in a buffer for NULL value.
5617 */
5618 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005619check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005620{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005621 check_string_option(&buf->b_p_bh);
5622 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005623 check_string_option(&buf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005624 check_string_option(&buf->b_p_ff);
5625#ifdef FEAT_FIND_ID
5626 check_string_option(&buf->b_p_def);
5627 check_string_option(&buf->b_p_inc);
5628# ifdef FEAT_EVAL
5629 check_string_option(&buf->b_p_inex);
5630# endif
5631#endif
5632#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5633 check_string_option(&buf->b_p_inde);
5634 check_string_option(&buf->b_p_indk);
5635#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005636#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5637 check_string_option(&buf->b_p_bexpr);
5638#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005639#if defined(FEAT_CRYPT)
5640 check_string_option(&buf->b_p_cm);
5641#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005642 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005643#if defined(FEAT_EVAL)
5644 check_string_option(&buf->b_p_fex);
5645#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005646#ifdef FEAT_CRYPT
5647 check_string_option(&buf->b_p_key);
5648#endif
5649 check_string_option(&buf->b_p_kp);
5650 check_string_option(&buf->b_p_mps);
5651 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005652 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005653 check_string_option(&buf->b_p_isk);
5654#ifdef FEAT_COMMENTS
5655 check_string_option(&buf->b_p_com);
5656#endif
5657#ifdef FEAT_FOLDING
5658 check_string_option(&buf->b_p_cms);
5659#endif
5660 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005661#ifdef FEAT_TEXTOBJ
5662 check_string_option(&buf->b_p_qe);
5663#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005664#ifdef FEAT_SYN_HL
5665 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005666 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005667#endif
5668#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005669 check_string_option(&buf->b_s.b_p_spc);
5670 check_string_option(&buf->b_s.b_p_spf);
5671 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005672#endif
5673#ifdef FEAT_SEARCHPATH
5674 check_string_option(&buf->b_p_sua);
5675#endif
5676#ifdef FEAT_CINDENT
5677 check_string_option(&buf->b_p_cink);
5678 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005679 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005680#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005681 check_string_option(&buf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005682#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5683 check_string_option(&buf->b_p_cinw);
5684#endif
5685#ifdef FEAT_INS_EXPAND
5686 check_string_option(&buf->b_p_cpt);
5687#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005688#ifdef FEAT_COMPL_FUNC
5689 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005690 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005691#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005692#ifdef FEAT_KEYMAP
5693 check_string_option(&buf->b_p_keymap);
5694#endif
5695#ifdef FEAT_QUICKFIX
5696 check_string_option(&buf->b_p_gp);
5697 check_string_option(&buf->b_p_mp);
5698 check_string_option(&buf->b_p_efm);
5699#endif
5700 check_string_option(&buf->b_p_ep);
5701 check_string_option(&buf->b_p_path);
5702 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005703 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005704#ifdef FEAT_INS_EXPAND
5705 check_string_option(&buf->b_p_dict);
5706 check_string_option(&buf->b_p_tsr);
5707#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005708#ifdef FEAT_LISP
5709 check_string_option(&buf->b_p_lw);
5710#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005711 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005712 check_string_option(&buf->b_p_menc);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005713#ifdef FEAT_VARTABS
5714 check_string_option(&buf->b_p_vsts);
5715 check_string_option(&buf->b_p_vts);
5716#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005717}
5718
5719/*
5720 * Free the string allocated for an option.
5721 * Checks for the string being empty_option. This may happen if we're out of
5722 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5723 * check_options().
5724 * Does NOT check for P_ALLOCED flag!
5725 */
5726 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005727free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005728{
5729 if (p != empty_option)
5730 vim_free(p);
5731}
5732
5733 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005734clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005735{
5736 if (*pp != empty_option)
5737 vim_free(*pp);
5738 *pp = empty_option;
5739}
5740
5741 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005742check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005743{
5744 if (*pp == NULL)
5745 *pp = empty_option;
5746}
5747
5748/*
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005749 * Return the option index found by a pointer into term_strings[].
5750 * Return -1 if not found.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005751 */
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005752 int
5753get_term_opt_idx(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005754{
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005755 int opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005756
5757 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5758 if (options[opt_idx].var == (char_u *)p)
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005759 return opt_idx;
5760 return -1; // cannot happen: didn't find it!
5761}
5762
5763/*
5764 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5765 * Return the option index or -1 if not found.
5766 */
5767 int
5768set_term_option_alloced(char_u **p)
5769{
5770 int opt_idx = get_term_opt_idx(p);
5771
5772 if (opt_idx >= 0)
5773 options[opt_idx].flags |= P_ALLOCED;
5774 return opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005775}
5776
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005777#if defined(FEAT_EVAL) || defined(PROTO)
5778/*
5779 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5780 * Return FALSE when it wasn't.
5781 * Return -1 for an unknown option.
5782 */
5783 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005784was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005785{
5786 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005787 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005788
5789 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005790 {
5791 flagp = insecure_flag(idx, opt_flags);
5792 return (*flagp & P_INSECURE) != 0;
5793 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005794 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005795 return -1;
5796}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005797
5798/*
5799 * Get a pointer to the flags used for the P_INSECURE flag of option
5800 * "opt_idx". For some local options a local flags field is used.
5801 */
5802 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005803insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005804{
5805 if (opt_flags & OPT_LOCAL)
5806 switch ((int)options[opt_idx].indir)
5807 {
5808#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005809 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005810#endif
5811#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005812# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005813 case PV_FDE: return &curwin->w_p_fde_flags;
5814 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005815# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005816# ifdef FEAT_BEVAL
5817 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5818# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005819# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005820 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005821# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005822 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005823# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005824 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005825# endif
5826#endif
5827 }
5828
5829 /* Nothing special, return global flags field. */
5830 return &options[opt_idx].flags;
5831}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005832#endif
5833
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005834#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005835/*
5836 * Redraw the window title and/or tab page text later.
5837 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005838static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005839{
5840 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005841 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005842}
5843#endif
5844
Bram Moolenaar071d4272004-06-13 20:20:40 +00005845/*
5846 * Set a string option to a new value (without checking the effect).
5847 * The string is copied into allocated memory.
5848 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005849 * When "set_sid" is zero set the scriptID to current_sctx.sc_sid. When
5850 * "set_sid" is SID_NONE don't set the scriptID. Otherwise set the scriptID to
5851 * "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005852 */
5853 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005854set_string_option_direct(
5855 char_u *name,
5856 int opt_idx,
5857 char_u *val,
5858 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5859 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005860{
5861 char_u *s;
5862 char_u **varp;
5863 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005864 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005865
Bram Moolenaar89d40322006-08-29 15:30:07 +00005866 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005867 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005868 idx = findoption(name);
5869 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005870 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005871 semsg(_(e_intern2), "set_string_option_direct()");
5872 siemsg(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005873 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005874 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005875 }
5876
Bram Moolenaar89d40322006-08-29 15:30:07 +00005877 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005878 return;
5879
5880 s = vim_strsave(val);
5881 if (s != NULL)
5882 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005883 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005884 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005885 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005886 free_string_option(*varp);
5887 *varp = s;
5888
5889 /* For buffer/window local option may also set the global value. */
5890 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005891 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005892
Bram Moolenaar89d40322006-08-29 15:30:07 +00005893 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005894
5895 /* When setting both values of a global option with a local value,
5896 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005897 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005898 {
5899 free_string_option(*varp);
5900 *varp = empty_option;
5901 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005902# ifdef FEAT_EVAL
5903 if (set_sid != SID_NONE)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005904 {
5905 sctx_T script_ctx;
5906
5907 if (set_sid == 0)
5908 script_ctx = current_sctx;
5909 else
5910 {
5911 script_ctx.sc_sid = set_sid;
Bram Moolenaarded5f1b2018-11-10 17:33:29 +01005912 script_ctx.sc_seq = 0;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005913 script_ctx.sc_lnum = 0;
Bram Moolenaar558ca4a2019-04-04 18:15:38 +02005914 script_ctx.sc_version = 1;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005915 }
5916 set_option_sctx_idx(idx, opt_flags, script_ctx);
5917 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005918# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005919 }
5920}
5921
5922/*
5923 * Set global value for string option when it's a local option.
5924 */
5925 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005926set_string_option_global(
5927 int opt_idx, /* option index */
5928 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005929{
5930 char_u **p, *s;
5931
5932 /* the global value is always allocated */
5933 if (options[opt_idx].var == VAR_WIN)
5934 p = (char_u **)GLOBAL_WO(varp);
5935 else
5936 p = (char_u **)options[opt_idx].var;
5937 if (options[opt_idx].indir != PV_NONE
5938 && p != varp
5939 && (s = vim_strsave(*varp)) != NULL)
5940 {
5941 free_string_option(*p);
5942 *p = s;
5943 }
5944}
5945
5946/*
5947 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005948 *
5949 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005950 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005951 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005952set_string_option(
5953 int opt_idx,
5954 char_u *value,
5955 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005956{
5957 char_u *s;
5958 char_u **varp;
5959 char_u *oldval;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005960#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02005961 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005962 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02005963#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005964 char *r = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01005965 int value_checked = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005966
5967 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005968 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005969
5970 s = vim_strsave(value);
5971 if (s != NULL)
5972 {
5973 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5974 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005975 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005976 ? OPT_GLOBAL : OPT_LOCAL)
5977 : opt_flags);
5978 oldval = *varp;
5979 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005980
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005981#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005982 if (!starting
5983# ifdef FEAT_CRYPT
5984 && options[opt_idx].indir != PV_KEY
5985# endif
5986 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005987 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005988 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005989 saved_newval = vim_strsave(s);
5990 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005991#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005992 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005993 opt_flags, &value_checked)) == NULL)
5994 did_set_option(opt_idx, opt_flags, TRUE, value_checked);
Bram Moolenaar53744302015-07-17 17:38:22 +02005995
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005996#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005997 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005998 if (r == NULL)
5999 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006000 saved_oldval, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006001 vim_free(saved_oldval);
6002 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02006003#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006004 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006005 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006006}
6007
6008/*
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006009 * Return TRUE if "val" is a valid name: only consists of alphanumeric ASCII
6010 * characters or characters in "allowed".
6011 */
6012 static int
6013valid_name(char_u *val, char *allowed)
6014{
6015 char_u *s;
6016
6017 for (s = val; *s != NUL; ++s)
6018 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)allowed, *s) == NULL)
6019 return FALSE;
6020 return TRUE;
6021}
6022
6023/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01006024 * Return TRUE if "val" is a valid 'filetype' name.
6025 * Also used for 'syntax' and 'keymap'.
6026 */
6027 static int
6028valid_filetype(char_u *val)
6029{
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006030 return valid_name(val, ".-_");
6031}
Bram Moolenaard0b51382016-11-04 15:23:45 +01006032
Bram Moolenaara7be0f22019-04-11 11:19:32 +02006033#if defined(FEAT_SPELL) || defined(PROTO)
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006034/*
6035 * Return TRUE if "val" is a valid 'spellang' value.
6036 */
6037 int
6038valid_spellang(char_u *val)
6039{
6040 return valid_name(val, ".-_,");
Bram Moolenaard0b51382016-11-04 15:23:45 +01006041}
6042
6043/*
Bram Moolenaar862f1e12019-04-10 22:33:41 +02006044 * Return TRUE if "val" is a valid 'spellfile' value.
6045 */
6046 static int
6047valid_spellfile(char_u *val)
6048{
6049 char_u *s;
6050
6051 for (s = val; *s != NUL; ++s)
6052 if (!vim_isfilec(*s) && *s != ',')
6053 return FALSE;
6054 return TRUE;
6055}
Bram Moolenaara7be0f22019-04-11 11:19:32 +02006056#endif
Bram Moolenaar862f1e12019-04-10 22:33:41 +02006057
6058/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006059 * Handle string options that need some action to perform when changed.
6060 * Returns NULL for success, or an error message for an error.
6061 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006062 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006063did_set_string_option(
Bram Moolenaar916a8182018-11-25 02:18:29 +01006064 int opt_idx, // index in options[] table
6065 char_u **varp, // pointer to the option variable
6066 int new_value_alloced, // new value was allocated
6067 char_u *oldval, // previous value of the option
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006068 char *errbuf, // buffer for errors, or NULL
Bram Moolenaar916a8182018-11-25 02:18:29 +01006069 int opt_flags, // OPT_LOCAL and/or OPT_GLOBAL
6070 int *value_checked) // value was checked to be save, no
6071 // need to set P_INSECURE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006072{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006073 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006074 char_u *s, *p;
6075 int did_chartab = FALSE;
6076 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006077 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006078#ifdef FEAT_GUI
6079 /* set when changing an option that only requires a redraw in the GUI */
6080 int redraw_gui_only = FALSE;
6081#endif
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02006082 int value_changed = FALSE;
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006083#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6084 int did_swaptcap = FALSE;
6085#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006086
6087 /* Get the global option to compare with, otherwise we would have to check
6088 * two values for all local options. */
6089 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6090
6091 /* Disallow changing some options from secure mode */
6092 if ((secure
6093#ifdef HAVE_SANDBOX
6094 || sandbox != 0
6095#endif
6096 ) && (options[opt_idx].flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006097 errmsg = e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006098
Bram Moolenaar916a8182018-11-25 02:18:29 +01006099 // Check for a "normal" directory or file name in some options. Disallow a
6100 // path separator (slash and/or backslash), wildcards and characters that
6101 // are often illegal in a file name. Be more permissive if "secure" is off.
Bram Moolenaar7554da42016-11-25 22:04:13 +01006102 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006103 && vim_strpbrk(*varp, (char_u *)(secure
6104 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006105 || ((options[opt_idx].flags & P_NDNAME)
6106 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006107 errmsg = e_invarg;
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006108
Bram Moolenaar071d4272004-06-13 20:20:40 +00006109 /* 'term' */
6110 else if (varp == &T_NAME)
6111 {
6112 if (T_NAME[0] == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006113 errmsg = N_("E529: Cannot set 'term' to empty string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006114#ifdef FEAT_GUI
6115 if (gui.in_use)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006116 errmsg = N_("E530: Cannot change term in GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006117 else if (term_is_gui(T_NAME))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006118 errmsg = N_("E531: Use \":gui\" to start the GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006119#endif
6120 else if (set_termname(T_NAME) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006121 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006122 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006123 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006124 /* Screen colors may have changed. */
6125 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006126
6127 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6128 * P_ALLOCED flag on 'term'. */
6129 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006130 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006131 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006132 }
6133
6134 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006135 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006136 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006137 char_u *bkc = p_bkc;
6138 unsigned int *flags = &bkc_flags;
6139
6140 if (opt_flags & OPT_LOCAL)
6141 {
6142 bkc = curbuf->b_p_bkc;
6143 flags = &curbuf->b_bkc_flags;
6144 }
6145
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006146 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6147 /* make the local value empty: use the global value */
6148 *flags = 0;
6149 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006150 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006151 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6152 errmsg = e_invarg;
6153 if ((((int)*flags & BKC_AUTO) != 0)
6154 + (((int)*flags & BKC_YES) != 0)
6155 + (((int)*flags & BKC_NO) != 0) != 1)
6156 {
6157 /* Must have exactly one of "auto", "yes" and "no". */
6158 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6159 errmsg = e_invarg;
6160 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006161 }
6162 }
6163
6164 /* 'backupext' and 'patchmode' */
6165 else if (varp == &p_bex || varp == &p_pm)
6166 {
6167 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6168 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006169 errmsg = N_("E589: 'backupext' and 'patchmode' are equal");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006170 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006171#ifdef FEAT_LINEBREAK
6172 /* 'breakindentopt' */
6173 else if (varp == &curwin->w_p_briopt)
6174 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006175 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006176 errmsg = e_invarg;
6177 }
6178#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006179
6180 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006181 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006182 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006183 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006184 */
6185 else if ( varp == &p_isi
6186 || varp == &(curbuf->b_p_isk)
6187 || varp == &p_isp
6188 || varp == &p_isf)
6189 {
6190 if (init_chartab() == FAIL)
6191 {
6192 did_chartab = TRUE; /* need to restore it below */
6193 errmsg = e_invarg; /* error in value */
6194 }
6195 }
6196
6197 /* 'helpfile' */
6198 else if (varp == &p_hf)
6199 {
6200 /* May compute new values for $VIM and $VIMRUNTIME */
6201 if (didset_vim)
6202 {
6203 vim_setenv((char_u *)"VIM", (char_u *)"");
6204 didset_vim = FALSE;
6205 }
6206 if (didset_vimruntime)
6207 {
6208 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6209 didset_vimruntime = FALSE;
6210 }
6211 }
6212
Bram Moolenaar1a384422010-07-14 19:53:30 +02006213#ifdef FEAT_SYN_HL
6214 /* 'colorcolumn' */
6215 else if (varp == &curwin->w_p_cc)
6216 errmsg = check_colorcolumn(curwin);
6217#endif
6218
Bram Moolenaar071d4272004-06-13 20:20:40 +00006219#ifdef FEAT_MULTI_LANG
6220 /* 'helplang' */
6221 else if (varp == &p_hlg)
6222 {
6223 /* Check for "", "ab", "ab,cd", etc. */
6224 for (s = p_hlg; *s != NUL; s += 3)
6225 {
6226 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6227 {
6228 errmsg = e_invarg;
6229 break;
6230 }
6231 if (s[2] == NUL)
6232 break;
6233 }
6234 }
6235#endif
6236
6237 /* 'highlight' */
6238 else if (varp == &p_hl)
6239 {
6240 if (highlight_changed() == FAIL)
6241 errmsg = e_invarg; /* invalid flags */
6242 }
6243
6244 /* 'nrformats' */
6245 else if (gvarp == &p_nf)
6246 {
6247 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6248 errmsg = e_invarg;
6249 }
6250
6251#ifdef FEAT_SESSION
6252 /* 'sessionoptions' */
6253 else if (varp == &p_ssop)
6254 {
6255 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6256 errmsg = e_invarg;
6257 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6258 {
6259 /* Don't allow both "sesdir" and "curdir". */
6260 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6261 errmsg = e_invarg;
6262 }
6263 }
6264 /* 'viewoptions' */
6265 else if (varp == &p_vop)
6266 {
6267 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6268 errmsg = e_invarg;
6269 }
6270#endif
6271
6272 /* 'scrollopt' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006273 else if (varp == &p_sbo)
6274 {
6275 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6276 errmsg = e_invarg;
6277 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006278
6279 /* 'ambiwidth' */
Bram Moolenaar3848e002016-03-19 18:42:29 +01006280 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006281 {
6282 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6283 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006284 else if (set_chars_option(&p_lcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006285 errmsg = _("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006286 else if (set_chars_option(&p_fcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006287 errmsg = _("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006288 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006289
6290 /* 'background' */
6291 else if (varp == &p_bg)
6292 {
6293 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6294 {
6295#ifdef FEAT_EVAL
6296 int dark = (*p_bg == 'd');
6297#endif
6298
6299 init_highlight(FALSE, FALSE);
6300
6301#ifdef FEAT_EVAL
6302 if (dark != (*p_bg == 'd')
6303 && get_var_value((char_u *)"g:colors_name") != NULL)
6304 {
6305 /* The color scheme must have set 'background' back to another
6306 * value, that's not what we want here. Disable the color
6307 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006308 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006309 free_string_option(p_bg);
6310 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6311 check_string_option(&p_bg);
6312 init_highlight(FALSE, FALSE);
6313 }
6314#endif
6315 }
6316 else
6317 errmsg = e_invarg;
6318 }
6319
6320 /* 'wildmode' */
6321 else if (varp == &p_wim)
6322 {
6323 if (check_opt_wim() == FAIL)
6324 errmsg = e_invarg;
6325 }
6326
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006327#ifdef FEAT_CMDL_COMPL
6328 /* 'wildoptions' */
6329 else if (varp == &p_wop)
6330 {
6331 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6332 errmsg = e_invarg;
6333 }
6334#endif
6335
Bram Moolenaar071d4272004-06-13 20:20:40 +00006336#ifdef FEAT_WAK
6337 /* 'winaltkeys' */
6338 else if (varp == &p_wak)
6339 {
6340 if (*p_wak == NUL
6341 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6342 errmsg = e_invarg;
6343# ifdef FEAT_MENU
6344# ifdef FEAT_GUI_MOTIF
6345 else if (gui.in_use)
6346 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6347# else
6348# ifdef FEAT_GUI_GTK
6349 else if (gui.in_use)
6350 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6351# endif
6352# endif
6353# endif
6354 }
6355#endif
6356
Bram Moolenaar071d4272004-06-13 20:20:40 +00006357 /* 'eventignore' */
6358 else if (varp == &p_ei)
6359 {
6360 if (check_ei() == FAIL)
6361 errmsg = e_invarg;
6362 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006363
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006364 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6365 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6366 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006367 {
6368 if (gvarp == &p_fenc)
6369 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006370 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006371 errmsg = e_modifiable;
6372 else if (vim_strchr(*varp, ',') != NULL)
6373 /* No comma allowed in 'fileencoding'; catches confusing it
6374 * with 'fileencodings'. */
6375 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006376 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006377 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006378#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006379 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006380 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006381#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006382 /* Add 'fileencoding' to the swap file. */
6383 ml_setflags(curbuf);
6384 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006385 }
6386 if (errmsg == NULL)
6387 {
6388 /* canonize the value, so that STRCMP() can be used on it */
6389 p = enc_canonize(*varp);
6390 if (p != NULL)
6391 {
6392 vim_free(*varp);
6393 *varp = p;
6394 }
6395 if (varp == &p_enc)
6396 {
6397 errmsg = mb_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006398#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006399 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006400#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006401 }
6402 }
6403
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006404#if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006405 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6406 {
6407 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6408 if (STRCMP(p_tenc, "utf-8") != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006409 errmsg = N_("E617: Cannot be changed in the GTK+ 2 GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006410 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006411#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006412
6413 if (errmsg == NULL)
6414 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006415#ifdef FEAT_KEYMAP
Bram Moolenaar071d4272004-06-13 20:20:40 +00006416 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6417 * (with another encoding). */
6418 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6419 (void)keymap_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006420#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006421
6422 /* When 'termencoding' is not empty and 'encoding' changes or when
6423 * 'termencoding' changes, need to setup for keyboard input and
6424 * display output conversion. */
6425 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6426 {
Bram Moolenaar17471e82017-11-26 23:47:18 +01006427 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6428 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6429 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006430 semsg(_("E950: Cannot convert between %s and %s"),
Bram Moolenaar17471e82017-11-26 23:47:18 +01006431 p_tenc, p_enc);
6432 errmsg = e_invarg;
6433 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006434 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006435
Bram Moolenaar4f974752019-02-17 17:44:42 +01006436#if defined(MSWIN)
Bram Moolenaar05159a02005-02-26 23:04:13 +00006437 /* $HOME may have characters in active code page. */
6438 if (varp == &p_enc)
6439 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006440#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006441 }
6442 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006443
6444#if defined(FEAT_POSTSCRIPT)
6445 else if (varp == &p_penc)
6446 {
6447 /* Canonize printencoding if VIM standard one */
6448 p = enc_canonize(p_penc);
6449 if (p != NULL)
6450 {
6451 vim_free(p_penc);
6452 p_penc = p;
6453 }
6454 else
6455 {
6456 /* Ensure lower case and '-' for '_' */
6457 for (s = p_penc; *s != NUL; s++)
6458 {
6459 if (*s == '_')
6460 *s = '-';
6461 else
6462 *s = TOLOWER_ASC(*s);
6463 }
6464 }
6465 }
6466#endif
6467
Bram Moolenaar9372a112005-12-06 19:59:18 +00006468#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006469 else if (varp == &p_imak)
6470 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006471 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006472 errmsg = e_invarg;
6473 }
6474#endif
6475
6476#ifdef FEAT_KEYMAP
6477 else if (varp == &curbuf->b_p_keymap)
6478 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006479 if (!valid_filetype(*varp))
6480 errmsg = e_invarg;
6481 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01006482 {
6483 int secure_save = secure;
6484
6485 // Reset the secure flag, since the value of 'keymap' has
6486 // been checked to be safe.
6487 secure = 0;
6488
6489 // load or unload key mapping tables
Bram Moolenaard0b51382016-11-04 15:23:45 +01006490 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006491
Bram Moolenaar916a8182018-11-25 02:18:29 +01006492 secure = secure_save;
6493
6494 // Since we check the value, there is no need to set P_INSECURE,
6495 // even when the value comes from a modeline.
6496 *value_checked = TRUE;
6497 }
6498
Bram Moolenaarfab06232009-03-04 03:13:35 +00006499 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006500 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006501 if (*curbuf->b_p_keymap != NUL)
6502 {
6503 /* Installed a new keymap, switch on using it. */
6504 curbuf->b_p_iminsert = B_IMODE_LMAP;
6505 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6506 curbuf->b_p_imsearch = B_IMODE_LMAP;
6507 }
6508 else
6509 {
6510 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6511 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6512 curbuf->b_p_iminsert = B_IMODE_NONE;
6513 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6514 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6515 }
6516 if ((opt_flags & OPT_LOCAL) == 0)
6517 {
6518 set_iminsert_global();
6519 set_imsearch_global();
6520 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006521 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006522 }
6523 }
6524#endif
6525
6526 /* 'fileformat' */
6527 else if (gvarp == &p_ff)
6528 {
6529 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6530 errmsg = e_modifiable;
6531 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6532 errmsg = e_invarg;
6533 else
6534 {
6535 /* may also change 'textmode' */
6536 if (get_fileformat(curbuf) == EOL_DOS)
6537 curbuf->b_p_tx = TRUE;
6538 else
6539 curbuf->b_p_tx = FALSE;
6540#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006541 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006542#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006543 /* update flag in swap file */
6544 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006545 /* Redraw needed when switching to/from "mac": a CR in the text
6546 * will be displayed differently. */
6547 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6548 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006549 }
6550 }
6551
6552 /* 'fileformats' */
6553 else if (varp == &p_ffs)
6554 {
6555 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6556 errmsg = e_invarg;
6557 else
6558 {
6559 /* also change 'textauto' */
6560 if (*p_ffs == NUL)
6561 p_ta = FALSE;
6562 else
6563 p_ta = TRUE;
6564 }
6565 }
6566
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006567#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006568 /* 'cryptkey' */
6569 else if (gvarp == &p_key)
6570 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006571# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006572 /* Make sure the ":set" command doesn't show the new value in the
6573 * history. */
6574 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006575# endif
6576 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6577 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006578 ml_set_crypt_key(curbuf, oldval,
6579 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006580 }
6581
6582 else if (gvarp == &p_cm)
6583 {
6584 if (opt_flags & OPT_LOCAL)
6585 p = curbuf->b_p_cm;
6586 else
6587 p = p_cm;
6588 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6589 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006590 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006591 errmsg = e_invarg;
6592 else
6593 {
6594 /* When setting the global value to empty, make it "zip". */
6595 if (*p_cm == NUL)
6596 {
6597 if (new_value_alloced)
6598 free_string_option(p_cm);
6599 p_cm = vim_strsave((char_u *)"zip");
6600 new_value_alloced = TRUE;
6601 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006602 /* When using ":set cm=name" the local value is going to be empty.
6603 * Do that here, otherwise the crypt functions will still use the
6604 * local value. */
6605 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6606 {
6607 free_string_option(curbuf->b_p_cm);
6608 curbuf->b_p_cm = empty_option;
6609 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006610
6611 /* Need to update the swapfile when the effective method changed.
6612 * Set "s" to the effective old value, "p" to the effective new
6613 * method and compare. */
6614 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6615 s = p_cm; /* was previously using the global value */
6616 else
6617 s = oldval;
6618 if (*curbuf->b_p_cm == NUL)
6619 p = p_cm; /* is now using the global value */
6620 else
6621 p = curbuf->b_p_cm;
6622 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006623 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006624
6625 /* If the global value changes need to update the swapfile for all
6626 * buffers using that value. */
6627 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6628 {
6629 buf_T *buf;
6630
Bram Moolenaar29323592016-07-24 22:04:11 +02006631 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006632 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006633 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006634 }
6635 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006636 }
6637#endif
6638
6639 /* 'matchpairs' */
6640 else if (gvarp == &p_mps)
6641 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006642 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006643 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006644 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006645 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006646 int x2 = -1;
6647 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006648
6649 if (*p != NUL)
6650 p += mb_ptr2len(p);
6651 if (*p != NUL)
6652 x2 = *p++;
6653 if (*p != NUL)
6654 {
6655 x3 = mb_ptr2char(p);
6656 p += mb_ptr2len(p);
6657 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006658 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006659 {
6660 errmsg = e_invarg;
6661 break;
6662 }
6663 if (*p == NUL)
6664 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006665 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006666 }
6667 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006668 {
6669 /* Check for "x:y,x:y" */
6670 for (p = *varp; *p != NUL; p += 4)
6671 {
6672 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6673 {
6674 errmsg = e_invarg;
6675 break;
6676 }
6677 if (p[3] == NUL)
6678 break;
6679 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006680 }
6681 }
6682
6683#ifdef FEAT_COMMENTS
6684 /* 'comments' */
6685 else if (gvarp == &p_com)
6686 {
6687 for (s = *varp; *s; )
6688 {
6689 while (*s && *s != ':')
6690 {
6691 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6692 && !VIM_ISDIGIT(*s) && *s != '-')
6693 {
6694 errmsg = illegal_char(errbuf, *s);
6695 break;
6696 }
6697 ++s;
6698 }
6699 if (*s++ == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006700 errmsg = N_("E524: Missing colon");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006701 else if (*s == ',' || *s == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006702 errmsg = N_("E525: Zero length string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006703 if (errmsg != NULL)
6704 break;
6705 while (*s && *s != ',')
6706 {
6707 if (*s == '\\' && s[1] != NUL)
6708 ++s;
6709 ++s;
6710 }
6711 s = skip_to_option_part(s);
6712 }
6713 }
6714#endif
6715
6716 /* 'listchars' */
6717 else if (varp == &p_lcs)
6718 {
6719 errmsg = set_chars_option(varp);
6720 }
6721
Bram Moolenaar071d4272004-06-13 20:20:40 +00006722 /* 'fillchars' */
6723 else if (varp == &p_fcs)
6724 {
6725 errmsg = set_chars_option(varp);
6726 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006727
6728#ifdef FEAT_CMDWIN
6729 /* 'cedit' */
6730 else if (varp == &p_cedit)
6731 {
6732 errmsg = check_cedit();
6733 }
6734#endif
6735
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006736 /* 'verbosefile' */
6737 else if (varp == &p_vfile)
6738 {
6739 verbose_stop();
6740 if (*p_vfile != NUL && verbose_open() == FAIL)
6741 errmsg = e_invarg;
6742 }
6743
Bram Moolenaar071d4272004-06-13 20:20:40 +00006744#ifdef FEAT_VIMINFO
6745 /* 'viminfo' */
6746 else if (varp == &p_viminfo)
6747 {
6748 for (s = p_viminfo; *s;)
6749 {
6750 /* Check it's a valid character */
6751 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6752 {
6753 errmsg = illegal_char(errbuf, *s);
6754 break;
6755 }
6756 if (*s == 'n') /* name is always last one */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006757 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006758 else if (*s == 'r') /* skip until next ',' */
6759 {
6760 while (*++s && *s != ',')
6761 ;
6762 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006763 else if (*s == '%')
6764 {
6765 /* optional number */
6766 while (vim_isdigit(*++s))
6767 ;
6768 }
6769 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006770 ++s; /* no extra chars */
6771 else /* must have a number */
6772 {
6773 while (vim_isdigit(*++s))
6774 ;
6775
6776 if (!VIM_ISDIGIT(*(s - 1)))
6777 {
6778 if (errbuf != NULL)
6779 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006780 sprintf(errbuf, _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006781 transchar_byte(*(s - 1)));
6782 errmsg = errbuf;
6783 }
6784 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006785 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006786 break;
6787 }
6788 }
6789 if (*s == ',')
6790 ++s;
6791 else if (*s)
6792 {
6793 if (errbuf != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006794 errmsg = N_("E527: Missing comma");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006795 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006796 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006797 break;
6798 }
6799 }
6800 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006801 errmsg = N_("E528: Must specify a ' value");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006802 }
6803#endif /* FEAT_VIMINFO */
6804
6805 /* terminal options */
6806 else if (istermoption(&options[opt_idx]) && full_screen)
6807 {
6808 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6809 if (varp == &T_CCO)
6810 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006811 int colors = atoi((char *)T_CCO);
6812
6813 /* Only reinitialize colors if t_Co value has really changed to
6814 * avoid expensive reload of colorscheme if t_Co is set to the
6815 * same value multiple times. */
6816 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006817 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006818 t_colors = colors;
6819 if (t_colors <= 1)
6820 {
6821 if (new_value_alloced)
6822 vim_free(T_CCO);
6823 T_CCO = empty_option;
6824 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006825#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6826 if (is_term_win32())
6827 {
6828 swap_tcap();
6829 did_swaptcap = TRUE;
6830 }
6831#endif
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006832 /* We now have a different color setup, initialize it again. */
6833 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006834 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006835 }
6836 ttest(FALSE);
6837 if (varp == &T_ME)
6838 {
6839 out_str(T_ME);
6840 redraw_later(CLEAR);
Bram Moolenaar4f974752019-02-17 17:44:42 +01006841#if defined(MSWIN) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006842 /* Since t_me has been set, this probably means that the user
6843 * wants to use this as default colors. Need to reset default
6844 * background/foreground colors. */
6845 mch_set_normal_colors();
6846#endif
6847 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006848 if (varp == &T_BE && termcap_active)
6849 {
6850 if (*T_BE == NUL)
6851 /* When clearing t_BE we assume the user no longer wants
6852 * bracketed paste, thus disable it by writing t_BD. */
6853 out_str(T_BD);
6854 else
6855 out_str(T_BE);
6856 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006857 }
6858
6859#ifdef FEAT_LINEBREAK
6860 /* 'showbreak' */
6861 else if (varp == &p_sbr)
6862 {
6863 for (s = p_sbr; *s; )
6864 {
6865 if (ptr2cells(s) != 1)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006866 errmsg = N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006867 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006868 }
6869 }
6870#endif
6871
6872#ifdef FEAT_GUI
6873 /* 'guifont' */
6874 else if (varp == &p_guifont)
6875 {
6876 if (gui.in_use)
6877 {
6878 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006879# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006880 /*
6881 * Put up a font dialog and let the user select a new value.
6882 * If this is cancelled go back to the old value but don't
6883 * give an error message.
6884 */
6885 if (STRCMP(p, "*") == 0)
6886 {
6887 p = gui_mch_font_dialog(oldval);
6888
6889 if (new_value_alloced)
6890 free_string_option(p_guifont);
6891
6892 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6893 new_value_alloced = TRUE;
6894 }
6895# endif
6896 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6897 {
6898# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6899 if (STRCMP(p_guifont, "*") == 0)
6900 {
6901 /* Dialog was cancelled: Keep the old value without giving
6902 * an error message. */
6903 if (new_value_alloced)
6904 free_string_option(p_guifont);
6905 p_guifont = vim_strsave(oldval);
6906 new_value_alloced = TRUE;
6907 }
6908 else
6909# endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006910 errmsg = N_("E596: Invalid font(s)");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006911 }
6912 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006913 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006914 }
6915# ifdef FEAT_XFONTSET
6916 else if (varp == &p_guifontset)
6917 {
6918 if (STRCMP(p_guifontset, "*") == 0)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01006919 errmsg = N_("E597: can't select fontset");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006920 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01006921 errmsg = N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006922 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006923 }
6924# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006925 else if (varp == &p_guifontwide)
6926 {
6927 if (STRCMP(p_guifontwide, "*") == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006928 errmsg = N_("E533: can't select wide font");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006929 else if (gui_get_wide_font() == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006930 errmsg = N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006931 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006932 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006933#endif
6934
6935#ifdef CURSOR_SHAPE
6936 /* 'guicursor' */
6937 else if (varp == &p_guicursor)
6938 errmsg = parse_shape_opt(SHAPE_CURSOR);
6939#endif
6940
6941#ifdef FEAT_MOUSESHAPE
6942 /* 'mouseshape' */
6943 else if (varp == &p_mouseshape)
6944 {
6945 errmsg = parse_shape_opt(SHAPE_MOUSE);
6946 update_mouseshape(-1);
6947 }
6948#endif
6949
6950#ifdef FEAT_PRINTER
6951 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006952 errmsg = parse_printoptions();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006953# if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006954 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006955 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006956# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006957#endif
6958
6959#ifdef FEAT_LANGMAP
6960 /* 'langmap' */
6961 else if (varp == &p_langmap)
6962 langmap_set();
6963#endif
6964
6965#ifdef FEAT_LINEBREAK
6966 /* 'breakat' */
6967 else if (varp == &p_breakat)
6968 fill_breakat_flags();
6969#endif
6970
6971#ifdef FEAT_TITLE
6972 /* 'titlestring' and 'iconstring' */
6973 else if (varp == &p_titlestring || varp == &p_iconstring)
6974 {
6975# ifdef FEAT_STL_OPT
6976 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6977
6978 /* NULL => statusline syntax */
6979 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6980 stl_syntax |= flagval;
6981 else
6982 stl_syntax &= ~flagval;
6983# endif
Bram Moolenaar84a93082018-06-16 22:58:15 +02006984 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006985 }
6986#endif
6987
6988#ifdef FEAT_GUI
6989 /* 'guioptions' */
6990 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006991 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006992 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006993 redraw_gui_only = TRUE;
6994 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006995#endif
6996
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006997#if defined(FEAT_GUI_TABLINE)
6998 /* 'guitablabel' */
6999 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007000 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00007001 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007002 redraw_gui_only = TRUE;
7003 }
7004 /* 'guitabtooltip' */
7005 else if (varp == &p_gtt)
7006 {
7007 redraw_gui_only = TRUE;
7008 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00007009#endif
7010
Bram Moolenaar071d4272004-06-13 20:20:40 +00007011#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
7012 /* 'ttymouse' */
7013 else if (varp == &p_ttym)
7014 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007015 /* Switch the mouse off before changing the escape sequences used for
7016 * that. */
7017 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007018 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
7019 errmsg = e_invarg;
7020 else
7021 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00007022 if (termcap_active)
7023 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007024 }
7025#endif
7026
Bram Moolenaar071d4272004-06-13 20:20:40 +00007027 /* 'selection' */
7028 else if (varp == &p_sel)
7029 {
7030 if (*p_sel == NUL
7031 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
7032 errmsg = e_invarg;
7033 }
7034
7035 /* 'selectmode' */
7036 else if (varp == &p_slm)
7037 {
7038 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
7039 errmsg = e_invarg;
7040 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007041
7042#ifdef FEAT_BROWSE
7043 /* 'browsedir' */
7044 else if (varp == &p_bsdir)
7045 {
7046 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7047 && !mch_isdir(p_bsdir))
7048 errmsg = e_invarg;
7049 }
7050#endif
7051
Bram Moolenaar071d4272004-06-13 20:20:40 +00007052 /* 'keymodel' */
7053 else if (varp == &p_km)
7054 {
7055 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7056 errmsg = e_invarg;
7057 else
7058 {
7059 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7060 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7061 }
7062 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007063
7064 /* 'mousemodel' */
7065 else if (varp == &p_mousem)
7066 {
7067 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7068 errmsg = e_invarg;
7069#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7070 else if (*p_mousem != *oldval)
7071 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7072 * to create or delete the popup menus. */
7073 gui_motif_update_mousemodel(root_menu);
7074#endif
7075 }
7076
7077 /* 'switchbuf' */
7078 else if (varp == &p_swb)
7079 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007080 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007081 errmsg = e_invarg;
7082 }
7083
7084 /* 'debug' */
7085 else if (varp == &p_debug)
7086 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007087 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007088 errmsg = e_invarg;
7089 }
7090
7091 /* 'display' */
7092 else if (varp == &p_dy)
7093 {
7094 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7095 errmsg = e_invarg;
7096 else
7097 (void)init_chartab();
7098
7099 }
7100
Bram Moolenaar071d4272004-06-13 20:20:40 +00007101 /* 'eadirection' */
7102 else if (varp == &p_ead)
7103 {
7104 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7105 errmsg = e_invarg;
7106 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007107
7108#ifdef FEAT_CLIPBOARD
7109 /* 'clipboard' */
7110 else if (varp == &p_cb)
7111 errmsg = check_clipboard_option();
7112#endif
7113
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007114#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007115 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7116 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007117 else if (varp == &(curwin->w_s->b_p_spl)
7118 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007119 {
Bram Moolenaar862f1e12019-04-10 22:33:41 +02007120 int is_spellfile = varp == &(curwin->w_s->b_p_spf);
7121
7122 if ((is_spellfile && !valid_spellfile(*varp))
7123 || (!is_spellfile && !valid_spellang(*varp)))
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02007124 errmsg = e_invarg;
7125 else
Bram Moolenaar862f1e12019-04-10 22:33:41 +02007126 errmsg = did_set_spell_option(is_spellfile);
Bram Moolenaar217ad922005-03-20 22:37:15 +00007127 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007128 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007129 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007130 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007131 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007132 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007133 /* 'spellsuggest' */
7134 else if (varp == &p_sps)
7135 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007136 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007137 errmsg = e_invarg;
7138 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007139 /* 'mkspellmem' */
7140 else if (varp == &p_msm)
7141 {
7142 if (spell_check_msm() != OK)
7143 errmsg = e_invarg;
7144 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007145#endif
7146
Bram Moolenaar071d4272004-06-13 20:20:40 +00007147 /* When 'bufhidden' is set, check for valid value. */
7148 else if (gvarp == &p_bh)
7149 {
7150 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7151 errmsg = e_invarg;
7152 }
7153
7154 /* When 'buftype' is set, check for valid value. */
7155 else if (gvarp == &p_bt)
7156 {
7157 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7158 errmsg = e_invarg;
7159 else
7160 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007161 if (curwin->w_status_height)
7162 {
7163 curwin->w_redr_status = TRUE;
7164 redraw_later(VALID);
7165 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007166 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007167#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007168 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007169#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007170 }
7171 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007172
7173#ifdef FEAT_STL_OPT
7174 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007175 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007176 {
7177 int wid;
7178
7179 if (varp == &p_ruf) /* reset ru_wid first */
7180 ru_wid = 0;
7181 s = *varp;
7182 if (varp == &p_ruf && *s == '%')
7183 {
7184 /* set ru_wid if 'ruf' starts with "%99(" */
7185 if (*++s == '-') /* ignore a '-' */
7186 s++;
7187 wid = getdigits(&s);
7188 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7189 ru_wid = wid;
7190 else
7191 errmsg = check_stl_option(p_ruf);
7192 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007193 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007194 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007195 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007196 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007197 comp_col();
7198 }
7199#endif
7200
7201#ifdef FEAT_INS_EXPAND
7202 /* check if it is a valid value for 'complete' -- Acevedo */
7203 else if (gvarp == &p_cpt)
7204 {
7205 for (s = *varp; *s;)
7206 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007207 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007208 s++;
7209 if (!*s)
7210 break;
7211 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7212 {
7213 errmsg = illegal_char(errbuf, *s);
7214 break;
7215 }
7216 if (*++s != NUL && *s != ',' && *s != ' ')
7217 {
7218 if (s[-1] == 'k' || s[-1] == 's')
7219 {
7220 /* skip optional filename after 'k' and 's' */
7221 while (*s && *s != ',' && *s != ' ')
7222 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007223 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007224 ++s;
7225 ++s;
7226 }
7227 }
7228 else
7229 {
7230 if (errbuf != NULL)
7231 {
7232 sprintf((char *)errbuf,
7233 _("E535: Illegal character after <%c>"),
7234 *--s);
7235 errmsg = errbuf;
7236 }
7237 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007238 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00007239 break;
7240 }
7241 }
7242 }
7243 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007244
7245 /* 'completeopt' */
7246 else if (varp == &p_cot)
7247 {
7248 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7249 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007250 else
7251 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007252 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007253#endif /* FEAT_INS_EXPAND */
7254
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007255#ifdef FEAT_SIGNS
7256 /* 'signcolumn' */
7257 else if (varp == &curwin->w_p_scl)
7258 {
7259 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7260 errmsg = e_invarg;
7261 }
7262#endif
7263
Bram Moolenaar071d4272004-06-13 20:20:40 +00007264
Bram Moolenaar4f974752019-02-17 17:44:42 +01007265#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007266 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007267 else if (varp == &p_toolbar)
7268 {
7269 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7270 &toolbar_flags, TRUE) != OK)
7271 errmsg = e_invarg;
7272 else
7273 {
7274 out_flush();
7275 gui_mch_show_toolbar((toolbar_flags &
7276 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7277 }
7278 }
7279#endif
7280
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007281#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007282 /* 'toolbariconsize': GTK+ 2 only */
7283 else if (varp == &p_tbis)
7284 {
7285 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7286 errmsg = e_invarg;
7287 else
7288 {
7289 out_flush();
7290 gui_mch_show_toolbar((toolbar_flags &
7291 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7292 }
7293 }
7294#endif
7295
7296 /* 'pastetoggle': translate key codes like in a mapping */
7297 else if (varp == &p_pt)
7298 {
7299 if (*p_pt)
7300 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007301 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007302 if (p != NULL)
7303 {
7304 if (new_value_alloced)
7305 free_string_option(p_pt);
7306 p_pt = p;
7307 new_value_alloced = TRUE;
7308 }
7309 }
7310 }
7311
7312 /* 'backspace' */
7313 else if (varp == &p_bs)
7314 {
7315 if (VIM_ISDIGIT(*p_bs))
7316 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007317 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007318 errmsg = e_invarg;
7319 }
7320 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7321 errmsg = e_invarg;
7322 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007323 else if (varp == &p_bo)
7324 {
7325 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7326 errmsg = e_invarg;
7327 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007328
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007329 /* 'tagcase' */
7330 else if (gvarp == &p_tc)
7331 {
7332 unsigned int *flags;
7333
7334 if (opt_flags & OPT_LOCAL)
7335 {
7336 p = curbuf->b_p_tc;
7337 flags = &curbuf->b_tc_flags;
7338 }
7339 else
7340 {
7341 p = p_tc;
7342 flags = &tc_flags;
7343 }
7344
7345 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7346 /* make the local value empty: use the global value */
7347 *flags = 0;
7348 else if (*p == NUL
7349 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7350 errmsg = e_invarg;
7351 }
7352
Bram Moolenaar071d4272004-06-13 20:20:40 +00007353 /* 'casemap' */
7354 else if (varp == &p_cmp)
7355 {
7356 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7357 errmsg = e_invarg;
7358 }
7359
7360#ifdef FEAT_DIFF
7361 /* 'diffopt' */
7362 else if (varp == &p_dip)
7363 {
7364 if (diffopt_changed() == FAIL)
7365 errmsg = e_invarg;
7366 }
7367#endif
7368
7369#ifdef FEAT_FOLDING
7370 /* 'foldmethod' */
7371 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7372 {
7373 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7374 || *curwin->w_p_fdm == NUL)
7375 errmsg = e_invarg;
7376 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007377 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007378 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007379 if (foldmethodIsDiff(curwin))
7380 newFoldLevel();
7381 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007382 }
7383# ifdef FEAT_EVAL
7384 /* 'foldexpr' */
7385 else if (varp == &curwin->w_p_fde)
7386 {
7387 if (foldmethodIsExpr(curwin))
7388 foldUpdateAll(curwin);
7389 }
7390# endif
7391 /* 'foldmarker' */
7392 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7393 {
7394 p = vim_strchr(*varp, ',');
7395 if (p == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007396 errmsg = N_("E536: comma required");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007397 else if (p == *varp || p[1] == NUL)
7398 errmsg = e_invarg;
7399 else if (foldmethodIsMarker(curwin))
7400 foldUpdateAll(curwin);
7401 }
7402 /* 'commentstring' */
7403 else if (gvarp == &p_cms)
7404 {
7405 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007406 errmsg = N_("E537: 'commentstring' must be empty or contain %s");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007407 }
7408 /* 'foldopen' */
7409 else if (varp == &p_fdo)
7410 {
7411 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7412 errmsg = e_invarg;
7413 }
7414 /* 'foldclose' */
7415 else if (varp == &p_fcl)
7416 {
7417 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7418 errmsg = e_invarg;
7419 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007420 /* 'foldignore' */
7421 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7422 {
7423 if (foldmethodIsIndent(curwin))
7424 foldUpdateAll(curwin);
7425 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007426#endif
7427
Bram Moolenaar071d4272004-06-13 20:20:40 +00007428 /* 'virtualedit' */
7429 else if (varp == &p_ve)
7430 {
7431 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7432 errmsg = e_invarg;
7433 else if (STRCMP(p_ve, oldval) != 0)
7434 {
7435 /* Recompute cursor position in case the new 've' setting
7436 * changes something. */
7437 validate_virtcol();
7438 coladvance(curwin->w_virtcol);
7439 }
7440 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007441
7442#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7443 else if (varp == &p_csqf)
7444 {
7445 if (p_csqf != NULL)
7446 {
7447 p = p_csqf;
7448 while (*p != NUL)
7449 {
7450 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7451 || p[1] == NUL
7452 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7453 || (p[2] != NUL && p[2] != ','))
7454 {
7455 errmsg = e_invarg;
7456 break;
7457 }
7458 else if (p[2] == NUL)
7459 break;
7460 else
7461 p += 3;
7462 }
7463 }
7464 }
7465#endif
7466
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007467#ifdef FEAT_CINDENT
7468 /* 'cinoptions' */
7469 else if (gvarp == &p_cino)
7470 {
7471 /* TODO: recognize errors */
7472 parse_cino(curbuf);
7473 }
7474#endif
7475
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007476#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007477 /* 'renderoptions' */
Bram Moolenaar3767c6e2017-12-05 16:57:56 +01007478 else if (varp == &p_rop)
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007479 {
7480 if (!gui_mch_set_rendering_options(p_rop))
7481 errmsg = e_invarg;
7482 }
7483#endif
7484
Bram Moolenaard0b51382016-11-04 15:23:45 +01007485 else if (gvarp == &p_ft)
7486 {
7487 if (!valid_filetype(*varp))
7488 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007489 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007490 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007491 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007492
7493 // Since we check the value, there is no need to set P_INSECURE,
7494 // even when the value comes from a modeline.
7495 *value_checked = TRUE;
7496 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007497 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007498
7499#ifdef FEAT_SYN_HL
7500 else if (gvarp == &p_syn)
7501 {
7502 if (!valid_filetype(*varp))
7503 errmsg = e_invarg;
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007504 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007505 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007506 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007507
7508 // Since we check the value, there is no need to set P_INSECURE,
7509 // even when the value comes from a modeline.
7510 *value_checked = TRUE;
7511 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007512 }
7513#endif
7514
Bram Moolenaar825680f2017-07-22 17:04:02 +02007515#ifdef FEAT_TERMINAL
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007516 // 'termwinkey'
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007517 else if (varp == &curwin->w_p_twk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007518 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007519 if (*curwin->w_p_twk != NUL
7520 && string_to_key(curwin->w_p_twk, TRUE) == 0)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007521 errmsg = e_invarg;
7522 }
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007523 // 'termwinsize'
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007524 else if (varp == &curwin->w_p_tws)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007525 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007526 if (*curwin->w_p_tws != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007527 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007528 p = skipdigits(curwin->w_p_tws);
7529 if (p == curwin->w_p_tws
Bram Moolenaar498c2562018-04-15 23:45:15 +02007530 || (*p != 'x' && *p != '*')
7531 || *skipdigits(p + 1) != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007532 errmsg = e_invarg;
7533 }
7534 }
Bram Moolenaar4f974752019-02-17 17:44:42 +01007535# if defined(MSWIN)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007536 // 'termwintype'
7537 else if (varp == &p_twt)
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007538 {
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007539 if (check_opt_strings(*varp, p_twt_values, FALSE) != OK)
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007540 errmsg = e_invarg;
7541 }
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007542# endif
Bram Moolenaar825680f2017-07-22 17:04:02 +02007543#endif
7544
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007545#ifdef FEAT_VARTABS
7546 /* 'varsofttabstop' */
7547 else if (varp == &(curbuf->b_p_vsts))
7548 {
7549 char_u *cp;
7550
7551 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7552 {
7553 if (curbuf->b_p_vsts_array)
7554 {
7555 vim_free(curbuf->b_p_vsts_array);
7556 curbuf->b_p_vsts_array = 0;
7557 }
7558 }
7559 else
7560 {
7561 for (cp = *varp; *cp; ++cp)
7562 {
7563 if (vim_isdigit(*cp))
7564 continue;
7565 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7566 continue;
7567 errmsg = e_invarg;
7568 break;
7569 }
7570 if (errmsg == NULL)
7571 {
7572 int *oldarray = curbuf->b_p_vsts_array;
7573 if (tabstop_set(*varp, &(curbuf->b_p_vsts_array)))
7574 {
7575 if (oldarray)
7576 vim_free(oldarray);
7577 }
7578 else
7579 errmsg = e_invarg;
7580 }
7581 }
7582 }
7583
7584 /* 'vartabstop' */
7585 else if (varp == &(curbuf->b_p_vts))
7586 {
7587 char_u *cp;
7588
7589 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7590 {
7591 if (curbuf->b_p_vts_array)
7592 {
7593 vim_free(curbuf->b_p_vts_array);
7594 curbuf->b_p_vts_array = NULL;
7595 }
7596 }
7597 else
7598 {
7599 for (cp = *varp; *cp; ++cp)
7600 {
7601 if (vim_isdigit(*cp))
7602 continue;
7603 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7604 continue;
7605 errmsg = e_invarg;
7606 break;
7607 }
7608 if (errmsg == NULL)
7609 {
7610 int *oldarray = curbuf->b_p_vts_array;
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007611
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007612 if (tabstop_set(*varp, &(curbuf->b_p_vts_array)))
7613 {
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007614 vim_free(oldarray);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007615#ifdef FEAT_FOLDING
7616 if (foldmethodIsIndent(curwin))
7617 foldUpdateAll(curwin);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007618#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007619 }
7620 else
7621 errmsg = e_invarg;
7622 }
7623 }
7624 }
7625#endif
7626
Bram Moolenaar071d4272004-06-13 20:20:40 +00007627 /* Options that are a list of flags. */
7628 else
7629 {
7630 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007631 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007632 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007633 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007634 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007635 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007636 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007637 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007638 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007639#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007640 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007641 p = (char_u *)COCU_ALL;
7642#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007643 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007644 {
7645#ifdef FEAT_MOUSE
7646 p = (char_u *)MOUSE_ALL;
7647#else
7648 if (*p_mouse != NUL)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007649 errmsg = N_("E538: No mouse support");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007650#endif
7651 }
7652#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007653 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007654 p = (char_u *)GO_ALL;
7655#endif
7656 if (p != NULL)
7657 {
7658 for (s = *varp; *s; ++s)
7659 if (vim_strchr(p, *s) == NULL)
7660 {
7661 errmsg = illegal_char(errbuf, *s);
7662 break;
7663 }
7664 }
7665 }
7666
7667 /*
7668 * If error detected, restore the previous value.
7669 */
7670 if (errmsg != NULL)
7671 {
7672 if (new_value_alloced)
7673 free_string_option(*varp);
7674 *varp = oldval;
7675 /*
7676 * When resetting some values, need to act on it.
7677 */
7678 if (did_chartab)
7679 (void)init_chartab();
7680 if (varp == &p_hl)
7681 (void)highlight_changed();
7682 }
7683 else
7684 {
7685#ifdef FEAT_EVAL
7686 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02007687 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007688#endif
7689 /*
7690 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007691 * Use "free_oldval", because recursiveness may change the flags under
7692 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007693 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007694 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007695 free_string_option(oldval);
7696 if (new_value_alloced)
7697 options[opt_idx].flags |= P_ALLOCED;
7698 else
7699 options[opt_idx].flags &= ~P_ALLOCED;
7700
7701 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007702 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007703 {
7704 /* global option with local value set to use global value; free
7705 * the local value and make it empty */
7706 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7707 free_string_option(*(char_u **)p);
7708 *(char_u **)p = empty_option;
7709 }
7710
7711 /* May set global value for local option. */
7712 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7713 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007714
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007715 /*
7716 * Trigger the autocommand only after setting the flags.
7717 */
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007718#ifdef FEAT_SYN_HL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007719 /* When 'syntax' is set, load the syntax of that name */
7720 if (varp == &(curbuf->b_p_syn))
7721 {
Bram Moolenaara5616b02018-06-17 19:08:30 +02007722 static int syn_recursive = 0;
7723
7724 ++syn_recursive;
7725 // Only pass TRUE for "force" when the value changed or not used
7726 // recursively, to avoid endless recurrence.
7727 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname,
7728 value_changed || syn_recursive == 1, curbuf);
7729 --syn_recursive;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007730 }
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007731#endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007732 else if (varp == &(curbuf->b_p_ft))
7733 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007734 /* 'filetype' is set, trigger the FileType autocommand.
7735 * Skip this when called from a modeline and the filetype was
Bram Moolenaara5616b02018-06-17 19:08:30 +02007736 * already set to this value. */
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007737 if (!(opt_flags & OPT_MODELINE) || value_changed)
Bram Moolenaar90492982017-06-22 14:16:31 +02007738 {
Bram Moolenaar916a8182018-11-25 02:18:29 +01007739 static int ft_recursive = 0;
7740 int secure_save = secure;
7741
7742 // Reset the secure flag, since the value of 'filetype' has
7743 // been checked to be safe.
7744 secure = 0;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007745
7746 ++ft_recursive;
Bram Moolenaar90492982017-06-22 14:16:31 +02007747 did_filetype = TRUE;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007748 // Only pass TRUE for "force" when the value changed or not
7749 // used recursively, to avoid endless recurrence.
7750 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname,
7751 value_changed || ft_recursive == 1, curbuf);
7752 --ft_recursive;
Bram Moolenaar163095f2017-07-09 15:41:53 +02007753 /* Just in case the old "curbuf" is now invalid. */
7754 if (varp != &(curbuf->b_p_ft))
7755 varp = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007756
7757 secure = secure_save;
Bram Moolenaar90492982017-06-22 14:16:31 +02007758 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007759 }
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007760#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007761 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007762 {
7763 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007764 char_u *q = curwin->w_s->b_p_spl;
7765
7766 /* Skip the first name if it is "cjk". */
7767 if (STRNCMP(q, "cjk,", 4) == 0)
7768 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007769
7770 /*
7771 * Source the spell/LANG.vim in 'runtimepath'.
7772 * They could set 'spellcapcheck' depending on the language.
7773 * Use the first name in 'spelllang' up to '_region' or
7774 * '.encoding'.
7775 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007776 for (p = q; *p != NUL; ++p)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01007777 if (!ASCII_ISALNUM(*p) && *p != '-')
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007778 break;
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007779 if (p > q)
7780 {
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02007781 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
7782 (int)(p - q), q);
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007783 source_runtime(fname, DIP_ALL);
7784 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007785 }
7786#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007787 }
7788
7789#ifdef FEAT_MOUSE
7790 if (varp == &p_mouse)
7791 {
7792# ifdef FEAT_MOUSE_TTY
7793 if (*p_mouse == NUL)
7794 mch_setmouse(FALSE); /* switch mouse off */
7795 else
7796# endif
7797 setmouse(); /* in case 'mouse' changed */
7798 }
7799#endif
7800
Bram Moolenaar913077c2012-03-28 19:59:04 +02007801 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007802 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007803 curwin->w_set_curswant = TRUE;
7804
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007805#ifdef FEAT_GUI
7806 /* check redraw when it's not a GUI option or the GUI is active. */
7807 if (!redraw_gui_only || gui.in_use)
7808#endif
7809 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007810
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007811#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
7812 if (did_swaptcap)
7813 {
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007814 set_termname((char_u *)"win32");
7815 init_highlight(TRUE, FALSE);
7816 }
7817#endif
7818
Bram Moolenaar071d4272004-06-13 20:20:40 +00007819 return errmsg;
7820}
7821
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007822#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007823/*
7824 * Simple int comparison function for use with qsort()
7825 */
7826 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007827int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007828{
7829 return *(const int *)a - *(const int *)b;
7830}
7831
7832/*
7833 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7834 * Returns error message, NULL if it's OK.
7835 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007836 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007837check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007838{
7839 char_u *s;
7840 int col;
7841 int count = 0;
7842 int color_cols[256];
7843 int i;
7844 int j = 0;
7845
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007846 if (wp->w_buffer == NULL)
7847 return NULL; /* buffer was closed */
7848
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007849 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007850 {
7851 if (*s == '-' || *s == '+')
7852 {
7853 /* -N and +N: add to 'textwidth' */
7854 col = (*s == '-') ? -1 : 1;
7855 ++s;
7856 if (!VIM_ISDIGIT(*s))
7857 return e_invarg;
7858 col = col * getdigits(&s);
7859 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007860 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007861 col += wp->w_buffer->b_p_tw;
7862 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007863 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007864 }
7865 else if (VIM_ISDIGIT(*s))
7866 col = getdigits(&s);
7867 else
7868 return e_invarg;
7869 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007870skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007871 if (*s == NUL)
7872 break;
7873 if (*s != ',')
7874 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007875 if (*++s == NUL)
7876 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007877 }
7878
7879 vim_free(wp->w_p_cc_cols);
7880 if (count == 0)
7881 wp->w_p_cc_cols = NULL;
7882 else
7883 {
7884 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7885 if (wp->w_p_cc_cols != NULL)
7886 {
7887 /* sort the columns for faster usage on screen redraw inside
7888 * win_line() */
7889 qsort(color_cols, count, sizeof(int), int_cmp);
7890
7891 for (i = 0; i < count; ++i)
7892 /* skip duplicates */
7893 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7894 wp->w_p_cc_cols[j++] = color_cols[i];
7895 wp->w_p_cc_cols[j] = -1; /* end marker */
7896 }
7897 }
7898
7899 return NULL; /* no error */
7900}
7901#endif
7902
Bram Moolenaar071d4272004-06-13 20:20:40 +00007903/*
7904 * Handle setting 'listchars' or 'fillchars'.
7905 * Returns error message, NULL if it's OK.
7906 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007907 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007908set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007909{
7910 int round, i, len, entries;
7911 char_u *p, *s;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007912 int c1 = 0, c2 = 0, c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007913 struct charstab
7914 {
7915 int *cp;
7916 char *name;
7917 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007918 static struct charstab filltab[] =
7919 {
7920 {&fill_stl, "stl"},
7921 {&fill_stlnc, "stlnc"},
7922 {&fill_vert, "vert"},
7923 {&fill_fold, "fold"},
7924 {&fill_diff, "diff"},
7925 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007926 static struct charstab lcstab[] =
7927 {
7928 {&lcs_eol, "eol"},
7929 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007930 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007931 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007932 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007933 {&lcs_tab2, "tab"},
7934 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007935#ifdef FEAT_CONCEAL
7936 {&lcs_conceal, "conceal"},
7937#else
7938 {NULL, "conceal"},
7939#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007940 };
7941 struct charstab *tab;
7942
Bram Moolenaar071d4272004-06-13 20:20:40 +00007943 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007944 {
7945 tab = lcstab;
7946 entries = sizeof(lcstab) / sizeof(struct charstab);
7947 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007948 else
7949 {
7950 tab = filltab;
7951 entries = sizeof(filltab) / sizeof(struct charstab);
7952 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007953
7954 /* first round: check for valid value, second round: assign values */
7955 for (round = 0; round <= 1; ++round)
7956 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007957 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007958 {
7959 /* After checking that the value is valid: set defaults: space for
7960 * 'fillchars', NUL for 'listchars' */
7961 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007962 if (tab[i].cp != NULL)
7963 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar83a52172019-01-16 22:41:54 +01007964
Bram Moolenaar071d4272004-06-13 20:20:40 +00007965 if (varp == &p_lcs)
Bram Moolenaar83a52172019-01-16 22:41:54 +01007966 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007967 lcs_tab1 = NUL;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007968 lcs_tab3 = NUL;
7969 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007970 else
7971 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007972 }
7973 p = *varp;
7974 while (*p)
7975 {
7976 for (i = 0; i < entries; ++i)
7977 {
7978 len = (int)STRLEN(tab[i].name);
7979 if (STRNCMP(p, tab[i].name, len) == 0
7980 && p[len] == ':'
7981 && p[len + 1] != NUL)
7982 {
Bram Moolenaar2c519cf2019-03-21 21:45:34 +01007983 c2 = c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007984 s = p + len + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007985 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007986 if (mb_char2cells(c1) > 1)
7987 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007988 if (tab[i].cp == &lcs_tab2)
7989 {
7990 if (*s == NUL)
7991 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007992 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007993 if (mb_char2cells(c2) > 1)
7994 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007995 if (!(*s == ',' || *s == NUL))
7996 {
Bram Moolenaar83a52172019-01-16 22:41:54 +01007997 c3 = mb_ptr2char_adv(&s);
7998 if (mb_char2cells(c3) > 1)
7999 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008000 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008001 }
Bram Moolenaar83a52172019-01-16 22:41:54 +01008002
Bram Moolenaar071d4272004-06-13 20:20:40 +00008003 if (*s == ',' || *s == NUL)
8004 {
8005 if (round)
8006 {
8007 if (tab[i].cp == &lcs_tab2)
8008 {
8009 lcs_tab1 = c1;
8010 lcs_tab2 = c2;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008011 lcs_tab3 = c3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008012 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008013 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008014 *(tab[i].cp) = c1;
8015
8016 }
8017 p = s;
8018 break;
8019 }
8020 }
8021 }
8022
8023 if (i == entries)
8024 return e_invarg;
8025 if (*p == ',')
8026 ++p;
8027 }
8028 }
8029
8030 return NULL; /* no error */
8031}
8032
8033#ifdef FEAT_STL_OPT
8034/*
8035 * Check validity of options with the 'statusline' format.
8036 * Return error message or NULL.
8037 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008038 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008039check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008040{
8041 int itemcnt = 0;
8042 int groupdepth = 0;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008043 static char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00008044
8045 while (*s && itemcnt < STL_MAX_ITEM)
8046 {
8047 /* Check for valid keys after % sequences */
8048 while (*s && *s != '%')
8049 s++;
8050 if (!*s)
8051 break;
8052 s++;
8053 if (*s != '%' && *s != ')')
8054 ++itemcnt;
8055 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
8056 {
8057 s++;
8058 continue;
8059 }
8060 if (*s == ')')
8061 {
8062 s++;
8063 if (--groupdepth < 0)
8064 break;
8065 continue;
8066 }
8067 if (*s == '-')
8068 s++;
8069 while (VIM_ISDIGIT(*s))
8070 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00008071 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008072 continue;
8073 if (*s == '.')
8074 {
8075 s++;
8076 while (*s && VIM_ISDIGIT(*s))
8077 s++;
8078 }
8079 if (*s == '(')
8080 {
8081 groupdepth++;
8082 continue;
8083 }
8084 if (vim_strchr(STL_ALL, *s) == NULL)
8085 {
8086 return illegal_char(errbuf, *s);
8087 }
8088 if (*s == '{')
8089 {
8090 s++;
8091 while (*s != '}' && *s)
8092 s++;
8093 if (*s != '}')
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008094 return N_("E540: Unclosed expression sequence");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008095 }
8096 }
8097 if (itemcnt >= STL_MAX_ITEM)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008098 return N_("E541: too many items");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008099 if (groupdepth != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008100 return N_("E542: unbalanced groups");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008101 return NULL;
8102}
8103#endif
8104
8105#ifdef FEAT_CLIPBOARD
8106/*
8107 * Extract the items in the 'clipboard' option and set global values.
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008108 * Return an error message or NULL for success.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008109 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008110 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008111check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008112{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008113 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008114 int new_autoselect_star = FALSE;
8115 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008116 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008117 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008118 regprog_T *new_exclude_prog = NULL;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008119 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008120 char_u *p;
8121
8122 for (p = p_cb; *p != NUL; )
8123 {
8124 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
8125 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008126 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008127 p += 7;
8128 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02008129 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008130 && (p[11] == ',' || p[11] == NUL))
8131 {
8132 new_unnamed |= CLIP_UNNAMED_PLUS;
8133 p += 11;
8134 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008135 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008136 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008137 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02008138 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008139 p += 10;
8140 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02008141 else if (STRNCMP(p, "autoselectplus", 14) == 0
8142 && (p[14] == ',' || p[14] == NUL))
8143 {
8144 new_autoselect_plus = TRUE;
8145 p += 14;
8146 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008147 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008148 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008149 {
8150 new_autoselectml = TRUE;
8151 p += 12;
8152 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008153 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
8154 {
8155 new_html = TRUE;
8156 p += 4;
8157 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008158 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
8159 {
8160 p += 8;
8161 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
8162 if (new_exclude_prog == NULL)
8163 errmsg = e_invarg;
8164 break;
8165 }
8166 else
8167 {
8168 errmsg = e_invarg;
8169 break;
8170 }
8171 if (*p == ',')
8172 ++p;
8173 }
8174 if (errmsg == NULL)
8175 {
8176 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008177 clip_autoselect_star = new_autoselect_star;
8178 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008179 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008180 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008181 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008182 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008183#ifdef FEAT_GUI_GTK
8184 if (gui.in_use)
8185 {
8186 gui_gtk_set_selection_targets();
8187 gui_gtk_set_dnd_targets();
8188 }
8189#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008190 }
8191 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008192 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008193
8194 return errmsg;
8195}
8196#endif
8197
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008198#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008199/*
8200 * Handle side effects of setting 'spell'.
8201 * Return an error message or NULL for success.
8202 */
8203 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008204did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008205{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008206 char *errmsg = NULL;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008207 win_T *wp;
8208 int l;
8209
8210 if (is_spellfile)
8211 {
8212 l = (int)STRLEN(curwin->w_s->b_p_spf);
8213 if (l > 0 && (l < 4
8214 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8215 errmsg = e_invarg;
8216 }
8217
8218 if (errmsg == NULL)
8219 {
8220 FOR_ALL_WINDOWS(wp)
8221 if (wp->w_buffer == curbuf && wp->w_p_spell)
8222 {
8223 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008224 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008225 }
8226 }
8227 return errmsg;
8228}
8229
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008230/*
8231 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8232 * Return error message when failed, NULL when OK.
8233 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008234 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008235compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008236{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008237 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008238 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008239
Bram Moolenaar860cae12010-06-05 23:22:07 +02008240 if (*synblock->b_p_spc == NUL)
8241 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008242 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008243 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008244 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008245 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008246 if (re != NULL)
8247 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008248 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008249 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008250 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008251 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008252 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008253 return e_invarg;
8254 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008255 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008256 }
8257
Bram Moolenaar473de612013-06-08 18:19:48 +02008258 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008259 return NULL;
8260}
8261#endif
8262
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008263#if defined(FEAT_EVAL) || defined(PROTO)
8264/*
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008265 * Set the script_ctx for an option, taking care of setting the buffer- or
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008266 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008267 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008268 static void
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008269set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008270{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008271 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8272 int indir = (int)options[opt_idx].indir;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008273 sctx_T new_script_ctx = script_ctx;
8274
8275 new_script_ctx.sc_lnum += sourcing_lnum;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008276
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008277 /* Remember where the option was set. For local options need to do that
8278 * in the buffer or window structure. */
8279 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008280 options[opt_idx].script_ctx = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008281 if (both || (opt_flags & OPT_LOCAL))
8282 {
8283 if (indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008284 curbuf->b_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008285 else if (indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008286 curwin->w_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008287 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008288}
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02008289
8290/*
8291 * Set the script_ctx for a termcap option.
8292 * "name" must be the two character code, e.g. "RV".
8293 * When "name" is NULL use "opt_idx".
8294 */
8295 void
8296set_term_option_sctx_idx(char *name, int opt_idx)
8297{
8298 char_u buf[5];
8299 int idx;
8300
8301 if (name == NULL)
8302 idx = opt_idx;
8303 else
8304 {
8305 buf[0] = 't';
8306 buf[1] = '_';
8307 buf[2] = name[0];
8308 buf[3] = name[1];
8309 buf[4] = 0;
8310 idx = findoption(buf);
8311 }
8312 if (idx >= 0)
8313 set_option_sctx_idx(idx, OPT_GLOBAL, current_sctx);
8314}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008315#endif
8316
Bram Moolenaar071d4272004-06-13 20:20:40 +00008317/*
8318 * Set the value of a boolean option, and take care of side effects.
8319 * Returns NULL for success, or an error message for an error.
8320 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008321 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008322set_bool_option(
8323 int opt_idx, /* index in options[] table */
8324 char_u *varp, /* pointer to the option variable */
8325 int value, /* new value */
8326 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008327{
8328 int old_value = *(int *)varp;
8329
Bram Moolenaar071d4272004-06-13 20:20:40 +00008330 /* Disallow changing some options from secure mode */
8331 if ((secure
8332#ifdef HAVE_SANDBOX
8333 || sandbox != 0
8334#endif
8335 ) && (options[opt_idx].flags & P_SECURE))
8336 return e_secure;
8337
8338 *(int *)varp = value; /* set the new value */
8339#ifdef FEAT_EVAL
8340 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008341 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008342#endif
8343
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008344#ifdef FEAT_GUI
8345 need_mouse_correct = TRUE;
8346#endif
8347
Bram Moolenaar071d4272004-06-13 20:20:40 +00008348 /* May set global value for local option. */
8349 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8350 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8351
8352 /*
8353 * Handle side effects of changing a bool option.
8354 */
8355
8356 /* 'compatible' */
8357 if ((int *)varp == &p_cp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008358 compatible_set();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008359
Bram Moolenaar920694c2016-08-21 17:45:02 +02008360#ifdef FEAT_LANGMAP
8361 if ((int *)varp == &p_lrm)
8362 /* 'langremap' -> !'langnoremap' */
8363 p_lnr = !p_lrm;
8364 else if ((int *)varp == &p_lnr)
8365 /* 'langnoremap' -> !'langremap' */
8366 p_lrm = !p_lnr;
8367#endif
8368
Bram Moolenaar8c63e0e2018-09-25 22:17:54 +02008369#ifdef FEAT_SYN_HL
8370 else if ((int *)varp == &curwin->w_p_cul && !value && old_value)
8371 reset_cursorline();
8372#endif
8373
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008374#ifdef FEAT_PERSISTENT_UNDO
8375 /* 'undofile' */
8376 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8377 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008378 /* Only take action when the option was set. When reset we do not
8379 * delete the undo file, the option may be set again without making
8380 * any changes in between. */
8381 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008382 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008383 char_u hash[UNDO_HASH_SIZE];
8384 buf_T *save_curbuf = curbuf;
8385
Bram Moolenaar29323592016-07-24 22:04:11 +02008386 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008387 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008388 /* When 'undofile' is set globally: for every buffer, otherwise
8389 * only for the current buffer: Try to read in the undofile,
8390 * if one exists, the buffer wasn't changed and the buffer was
8391 * loaded */
8392 if ((curbuf == save_curbuf
8393 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8394 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8395 {
8396 u_compute_hash(hash);
8397 u_read_undo(NULL, hash, curbuf->b_fname);
8398 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008399 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008400 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008401 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008402 }
8403#endif
8404
Bram Moolenaar071d4272004-06-13 20:20:40 +00008405 else if ((int *)varp == &curbuf->b_p_ro)
8406 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008407 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008408 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8409 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008410
8411 /* when 'readonly' is set may give W10 again */
8412 if (curbuf->b_p_ro)
8413 curbuf->b_did_warn = FALSE;
8414
Bram Moolenaar071d4272004-06-13 20:20:40 +00008415#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008416 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008417#endif
8418 }
8419
Bram Moolenaar9c449722010-07-20 18:44:27 +02008420#ifdef FEAT_GUI
8421 else if ((int *)varp == &p_mh)
8422 {
8423 if (!p_mh)
8424 gui_mch_mousehide(FALSE);
8425 }
8426#endif
8427
Bram Moolenaara539df02010-08-01 14:35:05 +02008428 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008429 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008430 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008431# ifdef FEAT_TERMINAL
8432 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaard7db27b2018-03-07 23:02:33 +01008433 if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf)
8434 && curbuf->b_term != NULL && !term_is_finished(curbuf))))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008435 {
8436 curbuf->b_p_ma = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008437 return N_("E946: Cannot make a terminal with running job modifiable");
Bram Moolenaar423802d2017-07-30 16:52:24 +02008438 }
8439# endif
8440# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008441 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008442# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008443 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008444#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008445 /* when 'endofline' is changed, redraw the window title */
8446 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008447 {
8448 redraw_titles();
8449 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008450 /* when 'fixeol' is changed, redraw the window title */
8451 else if ((int *)varp == &curbuf->b_p_fixeol)
8452 {
8453 redraw_titles();
8454 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008455 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008456 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008457 {
8458 redraw_titles();
8459 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008460#endif
8461
8462 /* when 'bin' is set also set some other options */
8463 else if ((int *)varp == &curbuf->b_p_bin)
8464 {
8465 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8466#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008467 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008468#endif
8469 }
8470
Bram Moolenaar071d4272004-06-13 20:20:40 +00008471 /* when 'buflisted' changes, trigger autocommands */
8472 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8473 {
8474 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8475 NULL, NULL, TRUE, curbuf);
8476 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008477
8478 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8479 else if ((int *)varp == &curbuf->b_p_swf)
8480 {
8481 if (curbuf->b_p_swf && p_uc)
8482 ml_open_file(curbuf); /* create the swap file */
8483 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008484 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8485 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008486 mf_close_file(curbuf, TRUE); /* remove the swap file */
8487 }
8488
8489 /* when 'terse' is set change 'shortmess' */
8490 else if ((int *)varp == &p_terse)
8491 {
8492 char_u *p;
8493
8494 p = vim_strchr(p_shm, SHM_SEARCH);
8495
8496 /* insert 's' in p_shm */
8497 if (p_terse && p == NULL)
8498 {
8499 STRCPY(IObuff, p_shm);
8500 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008501 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008502 }
8503 /* remove 's' from p_shm */
8504 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008505 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008506 }
8507
8508 /* when 'paste' is set or reset also change other options */
8509 else if ((int *)varp == &p_paste)
8510 {
8511 paste_option_changed();
8512 }
8513
8514 /* when 'insertmode' is set from an autocommand need to do work here */
8515 else if ((int *)varp == &p_im)
8516 {
8517 if (p_im)
8518 {
8519 if ((State & INSERT) == 0)
8520 need_start_insertmode = TRUE;
8521 stop_insert_mode = FALSE;
8522 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008523 /* only reset if it was set previously */
8524 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008525 {
8526 need_start_insertmode = FALSE;
8527 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008528 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008529 clear_cmdline = TRUE; /* remove "(insert)" */
8530 restart_edit = 0;
8531 }
8532 }
8533
8534 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8535 else if ((int *)varp == &p_ic && p_hls)
8536 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008537 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008538 }
8539
8540#ifdef FEAT_SEARCH_EXTRA
8541 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8542 else if ((int *)varp == &p_hls)
8543 {
Bram Moolenaar451fc7b2018-04-27 22:53:07 +02008544 set_no_hlsearch(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008545 }
8546#endif
8547
Bram Moolenaar071d4272004-06-13 20:20:40 +00008548 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8549 * at the end of normal_cmd() */
8550 else if ((int *)varp == &curwin->w_p_scb)
8551 {
8552 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008553 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008554 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008555 curwin->w_scbind_pos = curwin->w_topline;
8556 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008557 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008558
Bram Moolenaar4033c552017-09-16 20:54:51 +02008559#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008560 /* There can be only one window with 'previewwindow' set. */
8561 else if ((int *)varp == &curwin->w_p_pvw)
8562 {
8563 if (curwin->w_p_pvw)
8564 {
8565 win_T *win;
8566
Bram Moolenaar29323592016-07-24 22:04:11 +02008567 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008568 if (win->w_p_pvw && win != curwin)
8569 {
8570 curwin->w_p_pvw = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008571 return N_("E590: A preview window already exists");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008572 }
8573 }
8574 }
8575#endif
8576
8577 /* when 'textmode' is set or reset also change 'fileformat' */
8578 else if ((int *)varp == &curbuf->b_p_tx)
8579 {
8580 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8581 }
8582
8583 /* when 'textauto' is set or reset also change 'fileformats' */
8584 else if ((int *)varp == &p_ta)
Bram Moolenaarabab0b02019-03-30 18:47:01 +01008585 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008586 set_string_option_direct((char_u *)"ffs", -1,
8587 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008588 OPT_FREE | opt_flags, 0);
Bram Moolenaarabab0b02019-03-30 18:47:01 +01008589 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008590
8591 /*
8592 * When 'lisp' option changes include/exclude '-' in
8593 * keyword characters.
8594 */
8595#ifdef FEAT_LISP
8596 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8597 {
8598 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8599 }
8600#endif
8601
8602#ifdef FEAT_TITLE
8603 /* when 'title' changed, may need to change the title; same for 'icon' */
Bram Moolenaar84a93082018-06-16 22:58:15 +02008604 else if ((int *)varp == &p_title || (int *)varp == &p_icon)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008605 {
Bram Moolenaar84a93082018-06-16 22:58:15 +02008606 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008607 }
8608#endif
8609
8610 else if ((int *)varp == &curbuf->b_changed)
8611 {
8612 if (!value)
8613 save_file_ff(curbuf); /* Buffer is unchanged */
8614#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008615 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008616#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008617 modified_was_set = value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008618 }
8619
8620#ifdef BACKSLASH_IN_FILENAME
8621 else if ((int *)varp == &p_ssl)
8622 {
8623 if (p_ssl)
8624 {
8625 psepc = '/';
8626 psepcN = '\\';
8627 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008628 }
8629 else
8630 {
8631 psepc = '\\';
8632 psepcN = '/';
8633 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008634 }
8635
8636 /* need to adjust the file name arguments and buffer names. */
8637 buflist_slash_adjust();
8638 alist_slash_adjust();
8639# ifdef FEAT_EVAL
8640 scriptnames_slash_adjust();
8641# endif
8642 }
8643#endif
8644
8645 /* If 'wrap' is set, set w_leftcol to zero. */
8646 else if ((int *)varp == &curwin->w_p_wrap)
8647 {
8648 if (curwin->w_p_wrap)
8649 curwin->w_leftcol = 0;
8650 }
8651
Bram Moolenaar071d4272004-06-13 20:20:40 +00008652 else if ((int *)varp == &p_ea)
8653 {
8654 if (p_ea && !old_value)
8655 win_equal(curwin, FALSE, 0);
8656 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008657
8658 else if ((int *)varp == &p_wiv)
8659 {
8660 /*
8661 * When 'weirdinvert' changed, set/reset 't_xs'.
8662 * Then set 'weirdinvert' according to value of 't_xs'.
8663 */
8664 if (p_wiv && !old_value)
8665 T_XS = (char_u *)"y";
8666 else if (!p_wiv && old_value)
8667 T_XS = empty_option;
8668 p_wiv = (*T_XS != NUL);
8669 }
8670
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008671#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008672 else if ((int *)varp == &p_beval)
8673 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008674 if (!balloonEvalForTerm)
8675 {
8676 if (p_beval && !old_value)
8677 gui_mch_enable_beval_area(balloonEval);
8678 else if (!p_beval && old_value)
8679 gui_mch_disable_beval_area(balloonEval);
8680 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008681 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008682#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008683#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008684 else if ((int *)varp == &p_bevalterm)
8685 {
8686 mch_bevalterm_changed();
8687 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008688#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008689
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008690#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008691 else if ((int *)varp == &p_acd)
8692 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008693 /* Change directories when the 'acd' option is set now. */
Bram Moolenaar6f470022018-04-10 18:47:20 +02008694 DO_AUTOCHDIR;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008695 }
8696#endif
8697
8698#ifdef FEAT_DIFF
8699 /* 'diff' */
8700 else if ((int *)varp == &curwin->w_p_diff)
8701 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008702 /* May add or remove the buffer from the list of diff buffers. */
8703 diff_buf_adjust(curwin);
8704# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008705 if (foldmethodIsDiff(curwin))
8706 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008707# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008708 }
8709#endif
8710
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008711#ifdef HAVE_INPUT_METHOD
Bram Moolenaar071d4272004-06-13 20:20:40 +00008712 /* 'imdisable' */
8713 else if ((int *)varp == &p_imdisable)
8714 {
8715 /* Only de-activate it here, it will be enabled when changing mode. */
8716 if (p_imdisable)
8717 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008718 else if (State & INSERT)
8719 /* When the option is set from an autocommand, it may need to take
8720 * effect right away. */
8721 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008722 }
8723#endif
8724
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008725#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008726 /* 'spell' */
8727 else if ((int *)varp == &curwin->w_p_spell)
8728 {
8729 if (curwin->w_p_spell)
8730 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008731 char *errmsg = did_set_spelllang(curwin);
8732
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008733 if (errmsg != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008734 emsg(_(errmsg));
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008735 }
8736 }
8737#endif
8738
Bram Moolenaar071d4272004-06-13 20:20:40 +00008739#ifdef FEAT_ARABIC
8740 if ((int *)varp == &curwin->w_p_arab)
8741 {
8742 if (curwin->w_p_arab)
8743 {
8744 /*
8745 * 'arabic' is set, handle various sub-settings.
8746 */
8747 if (!p_tbidi)
8748 {
8749 /* set rightleft mode */
8750 if (!curwin->w_p_rl)
8751 {
8752 curwin->w_p_rl = TRUE;
8753 changed_window_setting();
8754 }
8755
8756 /* Enable Arabic shaping (major part of what Arabic requires) */
8757 if (!p_arshape)
8758 {
8759 p_arshape = TRUE;
8760 redraw_later_clear();
8761 }
8762 }
8763
8764 /* Arabic requires a utf-8 encoding, inform the user if its not
8765 * set. */
8766 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008767 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008768 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8769
Bram Moolenaar8820b482017-03-16 17:23:31 +01008770 msg_source(HL_ATTR(HLF_W));
Bram Moolenaar32526b32019-01-19 17:43:09 +01008771 msg_attr(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008772#ifdef FEAT_EVAL
8773 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8774#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008775 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008776
Bram Moolenaar071d4272004-06-13 20:20:40 +00008777 /* set 'delcombine' */
8778 p_deco = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008779
8780# ifdef FEAT_KEYMAP
8781 /* Force-set the necessary keymap for arabic */
8782 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8783 OPT_LOCAL);
8784# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008785 }
8786 else
8787 {
8788 /*
8789 * 'arabic' is reset, handle various sub-settings.
8790 */
8791 if (!p_tbidi)
8792 {
8793 /* reset rightleft mode */
8794 if (curwin->w_p_rl)
8795 {
8796 curwin->w_p_rl = FALSE;
8797 changed_window_setting();
8798 }
8799
8800 /* 'arabicshape' isn't reset, it is a global option and
8801 * another window may still need it "on". */
8802 }
8803
8804 /* 'delcombine' isn't reset, it is a global option and another
8805 * window may still want it "on". */
8806
8807# ifdef FEAT_KEYMAP
8808 /* Revert to the default keymap */
8809 curbuf->b_p_iminsert = B_IMODE_NONE;
8810 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8811# endif
8812 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008813 }
8814
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008815#endif
8816
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008817#ifdef FEAT_TERMGUICOLORS
8818 /* 'termguicolors' */
8819 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008820 {
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008821# ifdef FEAT_VTP
8822 /* Do not turn on 'tgc' when 24-bit colors are not supported. */
8823 if (!has_vtp_working())
8824 {
8825 p_tgc = 0;
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01008826 return N_("E954: 24-bit colors are not supported on this environment");
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008827 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008828 if (is_term_win32())
8829 swap_tcap();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008830# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008831# ifdef FEAT_GUI
8832 if (!gui.in_use && !gui.starting)
8833# endif
8834 highlight_gui_started();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008835# ifdef FEAT_VTP
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008836 /* reset t_Co */
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008837 if (is_term_win32())
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02008838 {
8839 control_console_color_rgb();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008840 set_termname(T_NAME);
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02008841 init_highlight(TRUE, FALSE);
8842 }
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008843# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008844 }
8845#endif
8846
Bram Moolenaar071d4272004-06-13 20:20:40 +00008847 /*
8848 * End of handling side effects for bool options.
8849 */
8850
Bram Moolenaar53744302015-07-17 17:38:22 +02008851 /* after handling side effects, call autocommand */
8852
Bram Moolenaar071d4272004-06-13 20:20:40 +00008853 options[opt_idx].flags |= P_WAS_SET;
8854
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008855#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02008856 // Don't do this while starting up or recursively.
8857 if (!starting && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02008858 {
8859 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02008860
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008861 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8862 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8863 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008864 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8865 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8866 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8867 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8868 reset_v_option_vars();
8869 }
8870#endif
8871
Bram Moolenaar071d4272004-06-13 20:20:40 +00008872 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008873 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008874 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008875 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008876 check_redraw(options[opt_idx].flags);
8877
8878 return NULL;
8879}
8880
8881/*
8882 * Set the value of a number option, and take care of side effects.
8883 * Returns NULL for success, or an error message for an error.
8884 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008885 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008886set_num_option(
8887 int opt_idx, /* index in options[] table */
8888 char_u *varp, /* pointer to the option variable */
8889 long value, /* new value */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008890 char *errbuf, /* buffer for error messages */
Bram Moolenaar9b578142016-01-30 19:39:49 +01008891 size_t errbuflen, /* length of "errbuf" */
8892 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008893 OPT_MODELINE */
8894{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008895 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008896 long old_value = *(long *)varp;
8897 long old_Rows = Rows; /* remember old Rows */
8898 long old_Columns = Columns; /* remember old Columns */
8899 long *pp = (long *)varp;
8900
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008901 /* Disallow changing some options from secure mode. */
8902 if ((secure
8903#ifdef HAVE_SANDBOX
8904 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008905#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008906 ) && (options[opt_idx].flags & P_SECURE))
8907 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008908
8909 *pp = value;
8910#ifdef FEAT_EVAL
8911 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008912 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008913#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008914#ifdef FEAT_GUI
8915 need_mouse_correct = TRUE;
8916#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008917
Bram Moolenaar14f24742012-08-08 18:01:05 +02008918 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008919 {
8920 errmsg = e_positive;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02008921#ifdef FEAT_VARTABS
8922 // Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use.
8923 curbuf->b_p_sw = tabstop_count(curbuf->b_p_vts_array) > 0
8924 ? tabstop_first(curbuf->b_p_vts_array)
8925 : curbuf->b_p_ts;
8926#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00008927 curbuf->b_p_sw = curbuf->b_p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02008928#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008929 }
8930
8931 /*
8932 * Number options that need some action when changed
8933 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008934 if (pp == &p_wh || pp == &p_hh)
8935 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008936 // 'winheight' and 'helpheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008937 if (p_wh < 1)
8938 {
8939 errmsg = e_positive;
8940 p_wh = 1;
8941 }
8942 if (p_wmh > p_wh)
8943 {
8944 errmsg = e_winheight;
8945 p_wh = p_wmh;
8946 }
8947 if (p_hh < 0)
8948 {
8949 errmsg = e_positive;
8950 p_hh = 0;
8951 }
8952
8953 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008954 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008955 {
8956 if (pp == &p_wh && curwin->w_height < p_wh)
8957 win_setheight((int)p_wh);
8958 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8959 win_setheight((int)p_hh);
8960 }
8961 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008962 else if (pp == &p_wmh)
8963 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008964 // 'winminheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008965 if (p_wmh < 0)
8966 {
8967 errmsg = e_positive;
8968 p_wmh = 0;
8969 }
8970 if (p_wmh > p_wh)
8971 {
8972 errmsg = e_winheight;
8973 p_wmh = p_wh;
8974 }
8975 win_setminheight();
8976 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008977 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008978 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008979 // 'winwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008980 if (p_wiw < 1)
8981 {
8982 errmsg = e_positive;
8983 p_wiw = 1;
8984 }
8985 if (p_wmw > p_wiw)
8986 {
8987 errmsg = e_winwidth;
8988 p_wiw = p_wmw;
8989 }
8990
8991 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008992 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008993 win_setwidth((int)p_wiw);
8994 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008995 else if (pp == &p_wmw)
8996 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008997 // 'winminwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008998 if (p_wmw < 0)
8999 {
9000 errmsg = e_positive;
9001 p_wmw = 0;
9002 }
9003 if (p_wmw > p_wiw)
9004 {
9005 errmsg = e_winwidth;
9006 p_wmw = p_wiw;
9007 }
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009008 win_setminwidth();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009009 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009010
Bram Moolenaar071d4272004-06-13 20:20:40 +00009011 /* (re)set last window status line */
9012 else if (pp == &p_ls)
9013 {
9014 last_status(FALSE);
9015 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009016
9017 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00009018 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009019 {
9020 shell_new_rows(); /* recompute window positions and heights */
9021 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009022
9023#ifdef FEAT_GUI
9024 else if (pp == &p_linespace)
9025 {
Bram Moolenaar02743632005-07-25 20:42:36 +00009026 /* Recompute gui.char_height and resize the Vim window to keep the
9027 * same number of lines. */
9028 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00009029 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009030 }
9031#endif
9032
9033#ifdef FEAT_FOLDING
9034 /* 'foldlevel' */
9035 else if (pp == &curwin->w_p_fdl)
9036 {
9037 if (curwin->w_p_fdl < 0)
9038 curwin->w_p_fdl = 0;
9039 newFoldLevel();
9040 }
9041
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00009042 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009043 else if (pp == &curwin->w_p_fml)
9044 {
9045 foldUpdateAll(curwin);
9046 }
9047
9048 /* 'foldnestmax' */
9049 else if (pp == &curwin->w_p_fdn)
9050 {
9051 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
9052 foldUpdateAll(curwin);
9053 }
9054
9055 /* 'foldcolumn' */
9056 else if (pp == &curwin->w_p_fdc)
9057 {
9058 if (curwin->w_p_fdc < 0)
9059 {
9060 errmsg = e_positive;
9061 curwin->w_p_fdc = 0;
9062 }
9063 else if (curwin->w_p_fdc > 12)
9064 {
9065 errmsg = e_invarg;
9066 curwin->w_p_fdc = 12;
9067 }
9068 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009069#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009070
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009071#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009072 /* 'shiftwidth' or 'tabstop' */
9073 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
9074 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009075# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00009076 if (foldmethodIsIndent(curwin))
9077 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009078# endif
9079# ifdef FEAT_CINDENT
9080 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
9081 * parse 'cinoptions'. */
9082 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
9083 parse_cino(curbuf);
9084# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009085 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009086#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009087
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009088 /* 'maxcombine' */
9089 else if (pp == &p_mco)
9090 {
9091 if (p_mco > MAX_MCO)
9092 p_mco = MAX_MCO;
9093 else if (p_mco < 0)
9094 p_mco = 0;
9095 screenclear(); /* will re-allocate the screen */
9096 }
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009097
Bram Moolenaar071d4272004-06-13 20:20:40 +00009098 else if (pp == &curbuf->b_p_iminsert)
9099 {
9100 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
9101 {
9102 errmsg = e_invarg;
9103 curbuf->b_p_iminsert = B_IMODE_NONE;
9104 }
9105 p_iminsert = curbuf->b_p_iminsert;
9106 if (termcap_active) /* don't do this in the alternate screen */
9107 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02009108#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009109 /* Show/unshow value of 'keymap' in status lines. */
9110 status_redraw_curbuf();
9111#endif
9112 }
9113
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02009114#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
9115 /* 'imstyle' */
9116 else if (pp == &p_imst)
9117 {
9118 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
9119 errmsg = e_invarg;
9120 }
9121#endif
9122
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009123 else if (pp == &p_window)
9124 {
9125 if (p_window < 1)
9126 p_window = 1;
9127 else if (p_window >= Rows)
9128 p_window = Rows - 1;
9129 }
9130
Bram Moolenaar071d4272004-06-13 20:20:40 +00009131 else if (pp == &curbuf->b_p_imsearch)
9132 {
9133 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
9134 {
9135 errmsg = e_invarg;
9136 curbuf->b_p_imsearch = B_IMODE_NONE;
9137 }
9138 p_imsearch = curbuf->b_p_imsearch;
9139 }
9140
9141#ifdef FEAT_TITLE
9142 /* if 'titlelen' has changed, redraw the title */
9143 else if (pp == &p_titlelen)
9144 {
9145 if (p_titlelen < 0)
9146 {
9147 errmsg = e_positive;
9148 p_titlelen = 85;
9149 }
9150 if (starting != NO_SCREEN && old_value != p_titlelen)
9151 need_maketitle = TRUE;
9152 }
9153#endif
9154
9155 /* if p_ch changed value, change the command line height */
9156 else if (pp == &p_ch)
9157 {
9158 if (p_ch < 1)
9159 {
9160 errmsg = e_positive;
9161 p_ch = 1;
9162 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009163 if (p_ch > Rows - min_rows() + 1)
9164 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009165
9166 /* Only compute the new window layout when startup has been
9167 * completed. Otherwise the frame sizes may be wrong. */
9168 if (p_ch != old_value && full_screen
9169#ifdef FEAT_GUI
9170 && !gui.starting
9171#endif
9172 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009173 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009174 }
9175
9176 /* when 'updatecount' changes from zero to non-zero, open swap files */
9177 else if (pp == &p_uc)
9178 {
9179 if (p_uc < 0)
9180 {
9181 errmsg = e_positive;
9182 p_uc = 100;
9183 }
9184 if (p_uc && !old_value)
9185 ml_open_files();
9186 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009187#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009188 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009189 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009190 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009191 {
9192 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009193 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009194 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009195 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009196 {
9197 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009198 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009199 }
9200 }
9201#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009202#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009203 else if (pp == &p_mzq)
9204 mzvim_reset_timer();
9205#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009206
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009207#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9208 /* 'pyxversion' */
9209 else if (pp == &p_pyx)
9210 {
9211 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9212 errmsg = e_invarg;
9213 }
9214#endif
9215
Bram Moolenaar071d4272004-06-13 20:20:40 +00009216 /* sync undo before 'undolevels' changes */
9217 else if (pp == &p_ul)
9218 {
9219 /* use the old value, otherwise u_sync() may not work properly */
9220 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009221 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009222 p_ul = value;
9223 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009224 else if (pp == &curbuf->b_p_ul)
9225 {
9226 /* use the old value, otherwise u_sync() may not work properly */
9227 curbuf->b_p_ul = old_value;
9228 u_sync(TRUE);
9229 curbuf->b_p_ul = value;
9230 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009231
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009232#ifdef FEAT_LINEBREAK
9233 /* 'numberwidth' must be positive */
9234 else if (pp == &curwin->w_p_nuw)
9235 {
9236 if (curwin->w_p_nuw < 1)
9237 {
9238 errmsg = e_positive;
9239 curwin->w_p_nuw = 1;
9240 }
9241 if (curwin->w_p_nuw > 10)
9242 {
9243 errmsg = e_invarg;
9244 curwin->w_p_nuw = 10;
9245 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009246 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009247 }
9248#endif
9249
Bram Moolenaar1a384422010-07-14 19:53:30 +02009250 else if (pp == &curbuf->b_p_tw)
9251 {
9252 if (curbuf->b_p_tw < 0)
9253 {
9254 errmsg = e_positive;
9255 curbuf->b_p_tw = 0;
9256 }
9257#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009258 {
9259 win_T *wp;
9260 tabpage_T *tp;
9261
9262 FOR_ALL_TAB_WINDOWS(tp, wp)
9263 check_colorcolumn(wp);
9264 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009265#endif
9266 }
9267
Bram Moolenaar071d4272004-06-13 20:20:40 +00009268 /*
9269 * Check the bounds for numeric options here
9270 */
9271 if (Rows < min_rows() && full_screen)
9272 {
9273 if (errbuf != NULL)
9274 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009275 vim_snprintf((char *)errbuf, errbuflen,
9276 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009277 errmsg = errbuf;
9278 }
9279 Rows = min_rows();
9280 }
9281 if (Columns < MIN_COLUMNS && full_screen)
9282 {
9283 if (errbuf != NULL)
9284 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009285 vim_snprintf((char *)errbuf, errbuflen,
9286 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009287 errmsg = errbuf;
9288 }
9289 Columns = MIN_COLUMNS;
9290 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009291 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009292
Bram Moolenaar071d4272004-06-13 20:20:40 +00009293 /*
9294 * If the screen (shell) height has been changed, assume it is the
9295 * physical screenheight.
9296 */
9297 if (old_Rows != Rows || old_Columns != Columns)
9298 {
9299 /* Changing the screen size is not allowed while updating the screen. */
9300 if (updating_screen)
9301 *pp = old_value;
9302 else if (full_screen
9303#ifdef FEAT_GUI
9304 && !gui.starting
9305#endif
9306 )
9307 set_shellsize((int)Columns, (int)Rows, TRUE);
9308 else
9309 {
9310 /* Postpone the resizing; check the size and cmdline position for
9311 * messages. */
9312 check_shellsize();
9313 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9314 cmdline_row = Rows - p_ch;
9315 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009316 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009317 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009318 }
9319
Bram Moolenaar071d4272004-06-13 20:20:40 +00009320 if (curbuf->b_p_ts <= 0)
9321 {
9322 errmsg = e_positive;
9323 curbuf->b_p_ts = 8;
9324 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009325 if (p_tm < 0)
9326 {
9327 errmsg = e_positive;
9328 p_tm = 0;
9329 }
9330 if ((curwin->w_p_scr <= 0
9331 || (curwin->w_p_scr > curwin->w_height
9332 && curwin->w_height > 0))
9333 && full_screen)
9334 {
9335 if (pp == &(curwin->w_p_scr))
9336 {
9337 if (curwin->w_p_scr != 0)
9338 errmsg = e_scroll;
9339 win_comp_scroll(curwin);
9340 }
9341 /* If 'scroll' became invalid because of a side effect silently adjust
9342 * it. */
9343 else if (curwin->w_p_scr <= 0)
9344 curwin->w_p_scr = 1;
9345 else /* curwin->w_p_scr > curwin->w_height */
9346 curwin->w_p_scr = curwin->w_height;
9347 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009348 if (p_hi < 0)
9349 {
9350 errmsg = e_positive;
9351 p_hi = 0;
9352 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009353 else if (p_hi > 10000)
9354 {
9355 errmsg = e_invarg;
9356 p_hi = 10000;
9357 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009358 if (p_re < 0 || p_re > 2)
9359 {
9360 errmsg = e_invarg;
9361 p_re = 0;
9362 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009363 if (p_report < 0)
9364 {
9365 errmsg = e_positive;
9366 p_report = 1;
9367 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009368 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009369 {
9370 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9371 p_sj = Rows / 2;
9372 else
9373 {
9374 errmsg = e_scroll;
9375 p_sj = 1;
9376 }
9377 }
9378 if (p_so < 0 && full_screen)
9379 {
Bram Moolenaar375e3392019-01-31 18:26:10 +01009380 errmsg = e_positive;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009381 p_so = 0;
9382 }
9383 if (p_siso < 0 && full_screen)
9384 {
9385 errmsg = e_positive;
9386 p_siso = 0;
9387 }
9388#ifdef FEAT_CMDWIN
9389 if (p_cwh < 1)
9390 {
9391 errmsg = e_positive;
9392 p_cwh = 1;
9393 }
9394#endif
9395 if (p_ut < 0)
9396 {
9397 errmsg = e_positive;
9398 p_ut = 2000;
9399 }
9400 if (p_ss < 0)
9401 {
9402 errmsg = e_positive;
9403 p_ss = 0;
9404 }
9405
9406 /* May set global value for local option. */
9407 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9408 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9409
9410 options[opt_idx].flags |= P_WAS_SET;
9411
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009412#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009413 // Don't do this while starting up, failure or recursively.
9414 if (!starting && errmsg == NULL && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009415 {
9416 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaar2c519cf2019-03-21 21:45:34 +01009417
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009418 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9419 vim_snprintf((char *)buf_new, 10, "%ld", value);
9420 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009421 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9422 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9423 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9424 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9425 reset_v_option_vars();
9426 }
9427#endif
9428
Bram Moolenaar071d4272004-06-13 20:20:40 +00009429 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009430 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009431 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009432 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009433 check_redraw(options[opt_idx].flags);
9434
9435 return errmsg;
9436}
9437
9438/*
9439 * Called after an option changed: check if something needs to be redrawn.
9440 */
9441 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009442check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009443{
9444 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009445 int doclear = (flags & P_RCLR) == P_RCLR;
9446 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009447
Bram Moolenaar071d4272004-06-13 20:20:40 +00009448 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9449 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009450
9451 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9452 changed_window_setting();
9453 if (flags & P_RBUF)
9454 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009455 if (flags & P_RWINONLY)
9456 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009457 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009458 redraw_all_later(CLEAR);
9459 else if (all)
9460 redraw_all_later(NOT_VALID);
9461}
9462
9463/*
9464 * Find index for option 'arg'.
9465 * Return -1 if not found.
9466 */
9467 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009468findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009469{
9470 int opt_idx;
9471 char *s, *p;
9472 static short quick_tab[27] = {0, 0}; /* quick access table */
9473 int is_term_opt;
9474
9475 /*
9476 * For first call: Initialize the quick-access table.
9477 * It contains the index for the first option that starts with a certain
9478 * letter. There are 26 letters, plus the first "t_" option.
9479 */
9480 if (quick_tab[1] == 0)
9481 {
9482 p = options[0].fullname;
9483 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9484 {
9485 if (s[0] != p[0])
9486 {
9487 if (s[0] == 't' && s[1] == '_')
9488 quick_tab[26] = opt_idx;
9489 else
9490 quick_tab[CharOrdLow(s[0])] = opt_idx;
9491 }
9492 p = s;
9493 }
9494 }
9495
9496 /*
9497 * Check for name starting with an illegal character.
9498 */
9499#ifdef EBCDIC
9500 if (!islower(arg[0]))
9501#else
9502 if (arg[0] < 'a' || arg[0] > 'z')
9503#endif
9504 return -1;
9505
9506 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9507 if (is_term_opt)
9508 opt_idx = quick_tab[26];
9509 else
9510 opt_idx = quick_tab[CharOrdLow(arg[0])];
9511 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9512 {
9513 if (STRCMP(arg, s) == 0) /* match full name */
9514 break;
9515 }
9516 if (s == NULL && !is_term_opt)
9517 {
9518 opt_idx = quick_tab[CharOrdLow(arg[0])];
9519 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9520 {
9521 s = options[opt_idx].shortname;
9522 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9523 break;
9524 s = NULL;
9525 }
9526 }
9527 if (s == NULL)
9528 opt_idx = -1;
9529 return opt_idx;
9530}
9531
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009532#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009533/*
9534 * Get the value for an option.
9535 *
9536 * Returns:
9537 * Number or Toggle option: 1, *numval gets value.
9538 * String option: 0, *stringval gets allocated string.
9539 * Hidden Number or Toggle option: -1.
9540 * hidden String option: -2.
9541 * unknown option: -3.
9542 */
9543 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009544get_option_value(
9545 char_u *name,
9546 long *numval,
9547 char_u **stringval, /* NULL when only checking existence */
9548 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009549{
9550 int opt_idx;
9551 char_u *varp;
9552
9553 opt_idx = findoption(name);
9554 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009555 {
9556 int key;
9557
9558 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009559 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009560 {
9561 char_u key_name[2];
9562 char_u *p;
9563
9564 if (key < 0)
9565 {
9566 key_name[0] = KEY2TERMCAP0(key);
9567 key_name[1] = KEY2TERMCAP1(key);
9568 }
9569 else
9570 {
9571 key_name[0] = KS_KEY;
9572 key_name[1] = (key & 0xff);
9573 }
9574 p = find_termcode(key_name);
9575 if (p != NULL)
9576 {
9577 if (stringval != NULL)
9578 *stringval = vim_strsave(p);
9579 return 0;
9580 }
9581 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009582 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009583 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009584
9585 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9586
9587 if (options[opt_idx].flags & P_STRING)
9588 {
9589 if (varp == NULL) /* hidden option */
9590 return -2;
9591 if (stringval != NULL)
9592 {
9593#ifdef FEAT_CRYPT
9594 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009595 if ((char_u **)varp == &curbuf->b_p_key
9596 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009597 *stringval = vim_strsave((char_u *)"*****");
9598 else
9599#endif
9600 *stringval = vim_strsave(*(char_u **)(varp));
9601 }
9602 return 0;
9603 }
9604
9605 if (varp == NULL) /* hidden option */
9606 return -1;
9607 if (options[opt_idx].flags & P_NUM)
9608 *numval = *(long *)varp;
9609 else
9610 {
9611 /* Special case: 'modified' is b_changed, but we also want to consider
9612 * it set when 'ff' or 'fenc' changed. */
9613 if ((int *)varp == &curbuf->b_changed)
9614 *numval = curbufIsChanged();
9615 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009616 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009617 }
9618 return 1;
9619}
9620#endif
9621
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009622#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009623/*
9624 * Returns the option attributes and its value. Unlike the above function it
9625 * will return either global value or local value of the option depending on
9626 * what was requested, but it will never return global value if it was
9627 * requested to return local one and vice versa. Neither it will return
9628 * buffer-local value if it was requested to return window-local one.
9629 *
9630 * Pretends that option is absent if it is not present in the requested scope
9631 * (i.e. has no global, window-local or buffer-local value depending on
9632 * opt_type). Uses
9633 *
9634 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009635 * 0 hidden or unknown option, also option that does not have requested
9636 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009637 * see SOPT_* in vim.h for other flags
9638 *
9639 * Possible opt_type values: see SREQ_* in vim.h
9640 */
9641 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009642get_option_value_strict(
9643 char_u *name,
9644 long *numval,
9645 char_u **stringval, /* NULL when only obtaining attributes */
9646 int opt_type,
9647 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009648{
9649 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009650 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009651 struct vimoption *p;
9652 int r = 0;
9653
9654 opt_idx = findoption(name);
9655 if (opt_idx < 0)
9656 return 0;
9657
9658 p = &(options[opt_idx]);
9659
9660 /* Hidden option */
9661 if (p->var == NULL)
9662 return 0;
9663
9664 if (p->flags & P_BOOL)
9665 r |= SOPT_BOOL;
9666 else if (p->flags & P_NUM)
9667 r |= SOPT_NUM;
9668 else if (p->flags & P_STRING)
9669 r |= SOPT_STRING;
9670
9671 if (p->indir == PV_NONE)
9672 {
9673 if (opt_type == SREQ_GLOBAL)
9674 r |= SOPT_GLOBAL;
9675 else
9676 return 0; /* Did not request global-only option */
9677 }
9678 else
9679 {
9680 if (p->indir & PV_BOTH)
9681 r |= SOPT_GLOBAL;
9682 else if (opt_type == SREQ_GLOBAL)
9683 return 0; /* Requested global option */
9684
9685 if (p->indir & PV_WIN)
9686 {
9687 if (opt_type == SREQ_BUF)
9688 return 0; /* Did not request window-local option */
9689 else
9690 r |= SOPT_WIN;
9691 }
9692 else if (p->indir & PV_BUF)
9693 {
9694 if (opt_type == SREQ_WIN)
9695 return 0; /* Did not request buffer-local option */
9696 else
9697 r |= SOPT_BUF;
9698 }
9699 }
9700
9701 if (stringval == NULL)
9702 return r;
9703
9704 if (opt_type == SREQ_GLOBAL)
9705 varp = p->var;
9706 else
9707 {
9708 if (opt_type == SREQ_BUF)
9709 {
9710 /* Special case: 'modified' is b_changed, but we also want to
9711 * consider it set when 'ff' or 'fenc' changed. */
9712 if (p->indir == PV_MOD)
9713 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009714 *numval = bufIsChanged((buf_T *)from);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009715 varp = NULL;
9716 }
9717#ifdef FEAT_CRYPT
9718 else if (p->indir == PV_KEY)
9719 {
9720 /* never return the value of the crypt key */
9721 *stringval = NULL;
9722 varp = NULL;
9723 }
9724#endif
9725 else
9726 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009727 buf_T *save_curbuf = curbuf;
9728
9729 // only getting a pointer, no need to use aucmd_prepbuf()
9730 curbuf = (buf_T *)from;
9731 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009732 varp = get_varp(p);
Bram Moolenaardefe6422018-06-24 15:14:07 +02009733 curbuf = save_curbuf;
9734 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009735 }
9736 }
9737 else if (opt_type == SREQ_WIN)
9738 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009739 win_T *save_curwin = curwin;
9740
9741 curwin = (win_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009742 curbuf = curwin->w_buffer;
9743 varp = get_varp(p);
9744 curwin = save_curwin;
9745 curbuf = curwin->w_buffer;
9746 }
9747 if (varp == p->var)
9748 return (r | SOPT_UNSET);
9749 }
9750
9751 if (varp != NULL)
9752 {
9753 if (p->flags & P_STRING)
9754 *stringval = vim_strsave(*(char_u **)(varp));
9755 else if (p->flags & P_NUM)
9756 *numval = *(long *) varp;
9757 else
9758 *numval = *(int *)varp;
9759 }
9760
9761 return r;
9762}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009763
9764/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009765 * Iterate over options. First argument is a pointer to a pointer to a
9766 * structure inside options[] array, second is option type like in the above
9767 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009768 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009769 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009770 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009771 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009772 * first argument to NULL.
9773 *
9774 * Returns full option name for current option on each call.
9775 */
9776 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009777option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009778{
9779 struct vimoption *ret = NULL;
9780 do
9781 {
9782 if (*option == NULL)
9783 *option = (void *) options;
9784 else if (((struct vimoption *) (*option))->fullname == NULL)
9785 {
9786 *option = NULL;
9787 return NULL;
9788 }
9789 else
9790 *option = (void *) (((struct vimoption *) (*option)) + 1);
9791
9792 ret = ((struct vimoption *) (*option));
9793
9794 /* Hidden option */
9795 if (ret->var == NULL)
9796 {
9797 ret = NULL;
9798 continue;
9799 }
9800
9801 switch (opt_type)
9802 {
9803 case SREQ_GLOBAL:
9804 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9805 ret = NULL;
9806 break;
9807 case SREQ_BUF:
9808 if (!(ret->indir & PV_BUF))
9809 ret = NULL;
9810 break;
9811 case SREQ_WIN:
9812 if (!(ret->indir & PV_WIN))
9813 ret = NULL;
9814 break;
9815 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009816 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009817 return NULL;
9818 }
9819 }
9820 while (ret == NULL);
9821
9822 return (char_u *)ret->fullname;
9823}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009824#endif
9825
Bram Moolenaar071d4272004-06-13 20:20:40 +00009826/*
9827 * Set the value of option "name".
9828 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009829 *
9830 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009831 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009832 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009833set_option_value(
9834 char_u *name,
9835 long number,
9836 char_u *string,
9837 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009838{
9839 int opt_idx;
9840 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009841 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009842
9843 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009844 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009845 {
9846 int key;
9847
9848 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009849 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009850 {
9851 char_u key_name[2];
9852
9853 if (key < 0)
9854 {
9855 key_name[0] = KEY2TERMCAP0(key);
9856 key_name[1] = KEY2TERMCAP1(key);
9857 }
9858 else
9859 {
9860 key_name[0] = KS_KEY;
9861 key_name[1] = (key & 0xff);
9862 }
9863 add_termcode(key_name, string, FALSE);
9864 if (full_screen)
9865 ttest(FALSE);
9866 redraw_all_later(CLEAR);
9867 return NULL;
9868 }
9869
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009870 semsg(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009871 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009872 else
9873 {
9874 flags = options[opt_idx].flags;
9875#ifdef HAVE_SANDBOX
9876 /* Disallow changing some options in the sandbox */
9877 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009878 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009879 emsg(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009880 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009881 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009882#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009883 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009884 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009885 else
9886 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009887 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009888 if (varp != NULL) /* hidden option is not changed */
9889 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009890 if (number == 0 && string != NULL)
9891 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009892 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009893
9894 /* Either we are given a string or we are setting option
9895 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009896 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009897 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009898 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009899 {
9900 /* There's another character after zeros or the string
9901 * is empty. In both cases, we are trying to set a
9902 * num option using a string. */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009903 semsg(_("E521: Number required: &%s = '%s'"),
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009904 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009905 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009906
9907 }
9908 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009909 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009910 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009911 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009912 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009913 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009914 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009915 }
9916 }
9917 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009918 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009919}
9920
9921/*
9922 * Get the terminal code for a terminal option.
9923 * Returns NULL when not found.
9924 */
9925 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009926get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009927{
9928 int opt_idx;
9929 char_u *varp;
9930
9931 if (tname[0] != 't' || tname[1] != '_' ||
9932 tname[2] == NUL || tname[3] == NUL)
9933 return NULL;
9934 if ((opt_idx = findoption(tname)) >= 0)
9935 {
9936 varp = get_varp(&(options[opt_idx]));
9937 if (varp != NULL)
9938 varp = *(char_u **)(varp);
9939 return varp;
9940 }
9941 return find_termcode(tname + 2);
9942}
9943
9944 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009945get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009946{
9947 int i;
9948
9949 i = findoption((char_u *)"hl");
9950 if (i >= 0)
9951 return options[i].def_val[VI_DEFAULT];
9952 return (char_u *)NULL;
9953}
9954
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009955 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009956get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009957{
9958 int i;
9959
9960 i = findoption((char_u *)"enc");
9961 if (i >= 0)
9962 return options[i].def_val[VI_DEFAULT];
9963 return (char_u *)NULL;
9964}
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009965
Bram Moolenaar071d4272004-06-13 20:20:40 +00009966/*
9967 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009968 * When "has_lt" is true there is a '<' before "*arg_arg".
9969 * Returns 0 when the key is not recognized.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009970 */
9971 static int
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009972find_key_option(char_u *arg_arg, int has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009973{
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009974 int key = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009975 int modifiers;
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009976 char_u *arg = arg_arg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009977
9978 /*
9979 * Don't use get_special_key_code() for t_xx, we don't want it to call
9980 * add_termcap_entry().
9981 */
9982 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9983 key = TERMCAP2KEY(arg[2], arg[3]);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009984 else if (has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009985 {
9986 --arg; /* put arg at the '<' */
9987 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009988 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009989 if (modifiers) /* can't handle modifiers here */
9990 key = 0;
9991 }
9992 return key;
9993}
9994
9995/*
9996 * if 'all' == 0: show changed options
9997 * if 'all' == 1: show all normal options
9998 * if 'all' == 2: show all terminal options
9999 */
10000 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010001showoptions(
10002 int all,
10003 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010004{
10005 struct vimoption *p;
10006 int col;
10007 int isterm;
10008 char_u *varp;
10009 struct vimoption **items;
10010 int item_count;
10011 int run;
10012 int row, rows;
10013 int cols;
10014 int i;
10015 int len;
10016
10017#define INC 20
10018#define GAP 3
10019
10020 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
10021 PARAM_COUNT));
10022 if (items == NULL)
10023 return;
10024
10025 /* Highlight title */
10026 if (all == 2)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010027 msg_puts_title(_("\n--- Terminal codes ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010028 else if (opt_flags & OPT_GLOBAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010029 msg_puts_title(_("\n--- Global option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010030 else if (opt_flags & OPT_LOCAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010031 msg_puts_title(_("\n--- Local option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010032 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010033 msg_puts_title(_("\n--- Options ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010034
10035 /*
10036 * do the loop two times:
10037 * 1. display the short items
10038 * 2. display the long items (only strings and numbers)
10039 */
10040 for (run = 1; run <= 2 && !got_int; ++run)
10041 {
10042 /*
10043 * collect the items in items[]
10044 */
10045 item_count = 0;
10046 for (p = &options[0]; p->fullname != NULL; p++)
10047 {
Bram Moolenaarf86db782018-10-25 13:31:37 +020010048 // apply :filter /pat/
10049 if (message_filtered((char_u *) p->fullname))
10050 continue;
10051
Bram Moolenaar071d4272004-06-13 20:20:40 +000010052 varp = NULL;
10053 isterm = istermoption(p);
10054 if (opt_flags != 0)
10055 {
10056 if (p->indir != PV_NONE && !isterm)
10057 varp = get_varp_scope(p, opt_flags);
10058 }
10059 else
10060 varp = get_varp(p);
10061 if (varp != NULL
10062 && ((all == 2 && isterm)
10063 || (all == 1 && !isterm)
10064 || (all == 0 && !optval_default(p, varp))))
10065 {
10066 if (p->flags & P_BOOL)
10067 len = 1; /* a toggle option fits always */
10068 else
10069 {
10070 option_value2string(p, opt_flags);
10071 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
10072 }
10073 if ((len <= INC - GAP && run == 1) ||
10074 (len > INC - GAP && run == 2))
10075 items[item_count++] = p;
10076 }
10077 }
10078
10079 /*
10080 * display the items
10081 */
10082 if (run == 1)
10083 {
10084 cols = (Columns + GAP - 3) / INC;
10085 if (cols == 0)
10086 cols = 1;
10087 rows = (item_count + cols - 1) / cols;
10088 }
10089 else /* run == 2 */
10090 rows = item_count;
10091 for (row = 0; row < rows && !got_int; ++row)
10092 {
10093 msg_putchar('\n'); /* go to next line */
10094 if (got_int) /* 'q' typed in more */
10095 break;
10096 col = 0;
10097 for (i = row; i < item_count; i += rows)
10098 {
10099 msg_col = col; /* make columns */
10100 showoneopt(items[i], opt_flags);
10101 col += INC;
10102 }
10103 out_flush();
10104 ui_breakcheck();
10105 }
10106 }
10107 vim_free(items);
10108}
10109
10110/*
10111 * Return TRUE if option "p" has its default value.
10112 */
10113 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010114optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010115{
10116 int dvi;
10117
10118 if (varp == NULL)
10119 return TRUE; /* hidden option is always at default */
10120 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
10121 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010122 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010123 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010124 /* the cast to long is required for Manx C, long_i is
10125 * needed for MSVC */
10126 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010127 /* P_STRING */
10128 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
10129}
10130
10131/*
10132 * showoneopt: show the value of one option
10133 * must not be called with a hidden option!
10134 */
10135 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010136showoneopt(
10137 struct vimoption *p,
10138 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010139{
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010140 char_u *varp;
10141 int save_silent = silent_mode;
10142
10143 silent_mode = FALSE;
10144 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010145
10146 varp = get_varp_scope(p, opt_flags);
10147
10148 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
10149 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
10150 ? !curbufIsChanged() : !*(int *)varp))
Bram Moolenaar32526b32019-01-19 17:43:09 +010010151 msg_puts("no");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010152 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010153 msg_puts("--");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010154 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010155 msg_puts(" ");
10156 msg_puts(p->fullname);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010157 if (!(p->flags & P_BOOL))
10158 {
10159 msg_putchar('=');
10160 /* put value string in NameBuff */
10161 option_value2string(p, opt_flags);
10162 msg_outtrans(NameBuff);
10163 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010164
10165 silent_mode = save_silent;
10166 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010167}
10168
10169/*
10170 * Write modified options as ":set" commands to a file.
10171 *
10172 * There are three values for "opt_flags":
10173 * OPT_GLOBAL: Write global option values and fresh values of
10174 * buffer-local options (used for start of a session
10175 * file).
10176 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10177 * curwin (used for a vimrc file).
10178 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10179 * and local values for window-local options of
10180 * curwin. Local values are also written when at the
10181 * default value, because a modeline or autocommand
10182 * may have set them when doing ":edit file" and the
10183 * user has set them back at the default or fresh
10184 * value.
10185 * When "local_only" is TRUE, don't write fresh
10186 * values, only local values (for ":mkview").
10187 * (fresh value = value used for a new buffer or window for a local option).
10188 *
10189 * Return FAIL on error, OK otherwise.
10190 */
10191 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010192makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010193{
10194 struct vimoption *p;
10195 char_u *varp; /* currently used value */
10196 char_u *varp_fresh; /* local value */
10197 char_u *varp_local = NULL; /* fresh value */
10198 char *cmd;
10199 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010200 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010201
10202 /*
10203 * The options that don't have a default (terminal name, columns, lines)
10204 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010205 * Do the loop over "options[]" twice: once for options with the
10206 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010207 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010208 for (pri = 1; pri >= 0; --pri)
10209 {
10210 for (p = &options[0]; !istermoption(p); p++)
10211 if (!(p->flags & P_NO_MKRC)
10212 && !istermoption(p)
10213 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010214 {
10215 /* skip global option when only doing locals */
10216 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10217 continue;
10218
10219 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10220 * file, they are always buffer-specific. */
10221 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10222 continue;
10223
10224 /* Global values are only written when not at the default value. */
10225 varp = get_varp_scope(p, opt_flags);
10226 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10227 continue;
10228
10229 round = 2;
10230 if (p->indir != PV_NONE)
10231 {
10232 if (p->var == VAR_WIN)
10233 {
10234 /* skip window-local option when only doing globals */
10235 if (!(opt_flags & OPT_LOCAL))
10236 continue;
10237 /* When fresh value of window-local option is not at the
10238 * default, need to write it too. */
10239 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10240 {
10241 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10242 if (!optval_default(p, varp_fresh))
10243 {
10244 round = 1;
10245 varp_local = varp;
10246 varp = varp_fresh;
10247 }
10248 }
10249 }
10250 }
10251
10252 /* Round 1: fresh value for window-local options.
10253 * Round 2: other values */
10254 for ( ; round <= 2; varp = varp_local, ++round)
10255 {
10256 if (round == 1 || (opt_flags & OPT_GLOBAL))
10257 cmd = "set";
10258 else
10259 cmd = "setlocal";
10260
10261 if (p->flags & P_BOOL)
10262 {
10263 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10264 return FAIL;
10265 }
10266 else if (p->flags & P_NUM)
10267 {
10268 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10269 return FAIL;
10270 }
10271 else /* P_STRING */
10272 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010273 int do_endif = FALSE;
10274
Bram Moolenaar071d4272004-06-13 20:20:40 +000010275 /* Don't set 'syntax' and 'filetype' again if the value is
10276 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010277 if (
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +010010278#if defined(FEAT_SYN_HL)
10279 p->indir == PV_SYN ||
10280#endif
10281 p->indir == PV_FT)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010282 {
10283 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10284 *(char_u **)(varp)) < 0
10285 || put_eol(fd) < 0)
10286 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010287 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010288 }
10289 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010290 p->flags) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010291 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010292 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010293 {
10294 if (put_line(fd, "endif") == FAIL)
10295 return FAIL;
10296 }
10297 }
10298 }
10299 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010300 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010301 return OK;
10302}
10303
10304#if defined(FEAT_FOLDING) || defined(PROTO)
10305/*
10306 * Generate set commands for the local fold options only. Used when
10307 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10308 */
10309 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010310makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010311{
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010312 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, 0) == FAIL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010313# ifdef FEAT_EVAL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010314 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010315 == FAIL
10316# endif
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010317 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010318 == FAIL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010319 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010320 == FAIL
10321 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10322 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10323 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10324 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10325 )
10326 return FAIL;
10327
10328 return OK;
10329}
10330#endif
10331
10332 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010333put_setstring(
10334 FILE *fd,
10335 char *cmd,
10336 char *name,
10337 char_u **valuep,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010338 long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010339{
10340 char_u *s;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010341 char_u *buf = NULL;
10342 char_u *part = NULL;
10343 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010344
10345 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10346 return FAIL;
10347 if (*valuep != NULL)
10348 {
10349 /* Output 'pastetoggle' as key names. For other
10350 * options some characters have to be escaped with
10351 * CTRL-V or backslash */
10352 if (valuep == &p_pt)
10353 {
10354 s = *valuep;
10355 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010356 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010357 return FAIL;
10358 }
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010359 // expand the option value, replace $HOME by ~
10360 else if ((flags & P_EXPAND) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010361 {
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010362 int size = (int)STRLEN(*valuep) + 1;
10363
10364 // replace home directory in the whole option value into "buf"
10365 buf = alloc(size);
Bram Moolenaarf8441472011-04-28 17:24:58 +020010366 if (buf == NULL)
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010367 goto fail;
10368 home_replace(NULL, *valuep, buf, size, FALSE);
10369
10370 // If the option value is longer than MAXPATHL, we need to append
10371 // earch comma separated part of the option separately, so that it
10372 // can be expanded when read back.
10373 if (size >= MAXPATHL && (flags & P_COMMA) != 0
10374 && vim_strchr(*valuep, ',') != NULL)
10375 {
10376 part = alloc(size);
10377 if (part == NULL)
10378 goto fail;
10379
10380 // write line break to clear the option, e.g. ':set rtp='
10381 if (put_eol(fd) == FAIL)
10382 goto fail;
10383
10384 p = buf;
10385 while (*p != NUL)
10386 {
10387 // for each comma separated option part, append value to
10388 // the option, :set rtp+=value
10389 if (fprintf(fd, "%s %s+=", cmd, name) < 0)
10390 goto fail;
10391 (void)copy_option_part(&p, part, size, ",");
10392 if (put_escstr(fd, part, 2) == FAIL || put_eol(fd) == FAIL)
10393 goto fail;
10394 }
10395 vim_free(buf);
10396 vim_free(part);
10397 return OK;
10398 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010399 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010400 {
10401 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010402 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010403 }
10404 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010405 }
10406 else if (put_escstr(fd, *valuep, 2) == FAIL)
10407 return FAIL;
10408 }
10409 if (put_eol(fd) < 0)
10410 return FAIL;
10411 return OK;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010412fail:
10413 vim_free(buf);
10414 vim_free(part);
10415 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010416}
10417
10418 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010419put_setnum(
10420 FILE *fd,
10421 char *cmd,
10422 char *name,
10423 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010424{
10425 long wc;
10426
10427 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10428 return FAIL;
10429 if (wc_use_keyname((char_u *)valuep, &wc))
10430 {
10431 /* print 'wildchar' and 'wildcharm' as a key name */
10432 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10433 return FAIL;
10434 }
10435 else if (fprintf(fd, "%ld", *valuep) < 0)
10436 return FAIL;
10437 if (put_eol(fd) < 0)
10438 return FAIL;
10439 return OK;
10440}
10441
10442 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010443put_setbool(
10444 FILE *fd,
10445 char *cmd,
10446 char *name,
10447 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010448{
Bram Moolenaar893de922007-10-02 18:40:57 +000010449 if (value < 0) /* global/local option using global value */
10450 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010451 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10452 || put_eol(fd) < 0)
10453 return FAIL;
10454 return OK;
10455}
10456
10457/*
10458 * Clear all the terminal options.
10459 * If the option has been allocated, free the memory.
10460 * Terminal options are never hidden or indirect.
10461 */
10462 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010463clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010464{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010465 /*
10466 * Reset a few things before clearing the old options. This may cause
10467 * outputting a few things that the terminal doesn't understand, but the
10468 * screen will be cleared later, so this is OK.
10469 */
10470#ifdef FEAT_MOUSE_TTY
10471 mch_setmouse(FALSE); /* switch mouse off */
10472#endif
10473#ifdef FEAT_TITLE
Bram Moolenaar40385db2018-08-07 22:31:44 +020010474 mch_restore_title(SAVE_RESTORE_BOTH); /* restore window titles */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010475#endif
10476#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10477 /* When starting the GUI close the display opened for the clipboard.
10478 * After restoring the title, because that will need the display. */
10479 if (gui.starting)
10480 clear_xterm_clip();
10481#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010482 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010483
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010484 free_termoptions();
10485}
10486
10487 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010488free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010489{
10490 struct vimoption *p;
10491
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010492 for (p = options; p->fullname != NULL; p++)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010493 if (istermoption(p))
10494 {
10495 if (p->flags & P_ALLOCED)
10496 free_string_option(*(char_u **)(p->var));
10497 if (p->flags & P_DEF_ALLOCED)
10498 free_string_option(p->def_val[VI_DEFAULT]);
10499 *(char_u **)(p->var) = empty_option;
10500 p->def_val[VI_DEFAULT] = empty_option;
10501 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010502#ifdef FEAT_EVAL
10503 // remember where the option was cleared
10504 set_option_sctx_idx((int)(p - options), OPT_GLOBAL, current_sctx);
10505#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010506 }
10507 clear_termcodes();
10508}
10509
10510/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010511 * Free the string for one term option, if it was allocated.
10512 * Set the string to empty_option and clear allocated flag.
10513 * "var" points to the option value.
10514 */
10515 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010516free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010517{
10518 struct vimoption *p;
10519
10520 for (p = &options[0]; p->fullname != NULL; p++)
10521 if (p->var == var)
10522 {
10523 if (p->flags & P_ALLOCED)
10524 free_string_option(*(char_u **)(p->var));
10525 *(char_u **)(p->var) = empty_option;
10526 p->flags &= ~P_ALLOCED;
10527 break;
10528 }
10529}
10530
10531/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010532 * Set the terminal option defaults to the current value.
10533 * Used after setting the terminal name.
10534 */
10535 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010536set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010537{
10538 struct vimoption *p;
10539
10540 for (p = &options[0]; p->fullname != NULL; p++)
10541 {
10542 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10543 {
10544 if (p->flags & P_DEF_ALLOCED)
10545 {
10546 free_string_option(p->def_val[VI_DEFAULT]);
10547 p->flags &= ~P_DEF_ALLOCED;
10548 }
10549 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10550 if (p->flags & P_ALLOCED)
10551 {
10552 p->flags |= P_DEF_ALLOCED;
10553 p->flags &= ~P_ALLOCED; /* don't free the value now */
10554 }
10555 }
10556 }
10557}
10558
10559/*
10560 * return TRUE if 'p' starts with 't_'
10561 */
10562 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010563istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010564{
10565 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10566}
10567
10568/*
10569 * Compute columns for ruler and shown command. 'sc_col' is also used to
10570 * decide what the maximum length of a message on the status line can be.
10571 * If there is a status line for the last window, 'sc_col' is independent
10572 * of 'ru_col'.
10573 */
10574
10575#define COL_RULER 17 /* columns needed by standard ruler */
10576
10577 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010578comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010579{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010580#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010581 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010582
10583 sc_col = 0;
10584 ru_col = 0;
10585 if (p_ru)
10586 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010587# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010588 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010589# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010590 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010591# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010592 /* no last status line, adjust sc_col */
10593 if (!last_has_status)
10594 sc_col = ru_col;
10595 }
10596 if (p_sc)
10597 {
10598 sc_col += SHOWCMD_COLS;
10599 if (!p_ru || last_has_status) /* no need for separating space */
10600 ++sc_col;
10601 }
10602 sc_col = Columns - sc_col;
10603 ru_col = Columns - ru_col;
10604 if (sc_col <= 0) /* screen too narrow, will become a mess */
10605 sc_col = 1;
10606 if (ru_col <= 0)
10607 ru_col = 1;
10608#else
10609 sc_col = Columns;
10610 ru_col = Columns;
10611#endif
10612}
10613
Bram Moolenaar113e1072019-01-20 15:30:40 +010010614#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010615/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010616 * Unset local option value, similar to ":set opt<".
10617 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010618 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010619unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010620{
10621 struct vimoption *p;
10622 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010623 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010624
10625 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010626 if (opt_idx < 0)
10627 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010628 p = &(options[opt_idx]);
10629
10630 switch ((int)p->indir)
10631 {
10632 /* global option with local value: use local value if it's been set */
10633 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010634 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010635 break;
10636 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010637 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010638 break;
10639 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010640 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010641 break;
10642 case PV_AR:
10643 buf->b_p_ar = -1;
10644 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010645 case PV_BKC:
10646 clear_string_option(&buf->b_p_bkc);
10647 buf->b_bkc_flags = 0;
10648 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010649 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010650 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010651 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010652 case PV_TC:
10653 clear_string_option(&buf->b_p_tc);
10654 buf->b_tc_flags = 0;
10655 break;
Bram Moolenaar375e3392019-01-31 18:26:10 +010010656 case PV_SISO:
10657 curwin->w_p_siso = -1;
10658 break;
10659 case PV_SO:
10660 curwin->w_p_so = -1;
10661 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010662#ifdef FEAT_FIND_ID
10663 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010664 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010665 break;
10666 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010667 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010668 break;
10669#endif
10670#ifdef FEAT_INS_EXPAND
10671 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010672 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010673 break;
10674 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010675 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010676 break;
10677#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010678 case PV_FP:
10679 clear_string_option(&buf->b_p_fp);
10680 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010681#ifdef FEAT_QUICKFIX
10682 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010683 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010684 break;
10685 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010686 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010687 break;
10688 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010689 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010690 break;
10691#endif
10692#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10693 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010694 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010695 break;
10696#endif
10697#if defined(FEAT_CRYPT)
10698 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010699 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010700 break;
10701#endif
10702#ifdef FEAT_STL_OPT
10703 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010704 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010705 break;
10706#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010707 case PV_UL:
10708 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10709 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010710#ifdef FEAT_LISP
10711 case PV_LW:
10712 clear_string_option(&buf->b_p_lw);
10713 break;
10714#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010715 case PV_MENC:
10716 clear_string_option(&buf->b_p_menc);
10717 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010718 }
10719}
Bram Moolenaar113e1072019-01-20 15:30:40 +010010720#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010721
10722/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010723 * Get pointer to option variable, depending on local or global scope.
10724 */
10725 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010726get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010727{
10728 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10729 {
10730 if (p->var == VAR_WIN)
10731 return (char_u *)GLOBAL_WO(get_varp(p));
10732 return p->var;
10733 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010734 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010735 {
10736 switch ((int)p->indir)
10737 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010738 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010739#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010740 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10741 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10742 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010743#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010744 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10745 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10746 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010747 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010748 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010749 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar375e3392019-01-31 18:26:10 +010010750 case PV_SISO: return (char_u *)&(curwin->w_p_siso);
10751 case PV_SO: return (char_u *)&(curwin->w_p_so);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010752#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010753 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10754 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010755#endif
10756#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010757 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10758 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010759#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010760#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10761 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10762#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010763#if defined(FEAT_CRYPT)
10764 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10765#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010766#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010767 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010768#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010769 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010770#ifdef FEAT_LISP
10771 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10772#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010773 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010774 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010775 }
10776 return NULL; /* "cannot happen" */
10777 }
10778 return get_varp(p);
10779}
10780
10781/*
10782 * Get pointer to option variable.
10783 */
10784 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010785get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010786{
10787 /* hidden option, always return NULL */
10788 if (p->var == NULL)
10789 return NULL;
10790
10791 switch ((int)p->indir)
10792 {
10793 case PV_NONE: return p->var;
10794
10795 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010796 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010797 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010798 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010799 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010800 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010801 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010802 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010803 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010804 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010805 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010806 case PV_TC: return *curbuf->b_p_tc != NUL
10807 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010808 case PV_BKC: return *curbuf->b_p_bkc != NUL
10809 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar375e3392019-01-31 18:26:10 +010010810 case PV_SISO: return curwin->w_p_siso >= 0
10811 ? (char_u *)&(curwin->w_p_siso) : p->var;
10812 case PV_SO: return curwin->w_p_so >= 0
10813 ? (char_u *)&(curwin->w_p_so) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010814#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010815 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010816 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010817 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010818 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10819#endif
10820#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010821 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010822 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010823 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010824 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10825#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010826 case PV_FP: return *curbuf->b_p_fp != NUL
10827 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010828#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010829 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010830 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010831 case PV_GP: return *curbuf->b_p_gp != NUL
10832 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10833 case PV_MP: return *curbuf->b_p_mp != NUL
10834 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010835#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010836#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10837 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10838 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10839#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010840#if defined(FEAT_CRYPT)
10841 case PV_CM: return *curbuf->b_p_cm != NUL
10842 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10843#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010844#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010845 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010846 ? (char_u *)&(curwin->w_p_stl) : p->var;
10847#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010848 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10849 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010850#ifdef FEAT_LISP
10851 case PV_LW: return *curbuf->b_p_lw != NUL
10852 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10853#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010854 case PV_MENC: return *curbuf->b_p_menc != NUL
10855 ? (char_u *)&(curbuf->b_p_menc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010856
10857#ifdef FEAT_ARABIC
10858 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10859#endif
10860 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010861#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010862 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10863#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010864#ifdef FEAT_SYN_HL
10865 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10866 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010867 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010868#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010869#ifdef FEAT_DIFF
10870 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10871#endif
10872#ifdef FEAT_FOLDING
10873 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10874 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10875 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10876 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10877 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10878 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10879 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10880# ifdef FEAT_EVAL
10881 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10882 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10883# endif
10884 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10885#endif
10886 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010887 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010888#ifdef FEAT_LINEBREAK
10889 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10890#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010891 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010892 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020010893#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010894 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10895#endif
10896#ifdef FEAT_RIGHTLEFT
10897 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10898 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10899#endif
10900 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10901 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10902#ifdef FEAT_LINEBREAK
10903 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010904 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10905 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010906#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010907 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010908 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010909#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010910 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10911 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10912#endif
10913#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020010914 case PV_TWK: return (char_u *)&(curwin->w_p_twk);
10915 case PV_TWS: return (char_u *)&(curwin->w_p_tws);
10916 case PV_TWSL: return (char_u *)&(curbuf->b_p_twsl);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010917#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010918
10919 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10920 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010921 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010922 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10923 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010924 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10925 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10926#ifdef FEAT_CINDENT
10927 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10928 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10929 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10930#endif
10931#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10932 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10933#endif
10934#ifdef FEAT_COMMENTS
10935 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10936#endif
10937#ifdef FEAT_FOLDING
10938 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10939#endif
10940#ifdef FEAT_INS_EXPAND
10941 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10942#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010943#ifdef FEAT_COMPL_FUNC
10944 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010945 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010946#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010947 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010948 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010949 case PV_ET: return (char_u *)&(curbuf->b_p_et);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010950 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010951 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010952 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010953 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010954 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010955 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10956 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10957 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10958 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10959#ifdef FEAT_FIND_ID
10960# ifdef FEAT_EVAL
10961 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10962# endif
10963#endif
10964#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10965 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10966 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10967#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010968#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010969 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10970#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010971#ifdef FEAT_CRYPT
10972 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10973#endif
10974#ifdef FEAT_LISP
10975 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10976#endif
10977 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10978 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10979 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10980 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10981 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010982 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010983#ifdef FEAT_TEXTOBJ
10984 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10985#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010986 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10987#ifdef FEAT_SMARTINDENT
10988 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10989#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010990 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010991 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10992#ifdef FEAT_SEARCHPATH
10993 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10994#endif
10995 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10996#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010997 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010998 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10999#endif
11000#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020011001 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
11002 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
11003 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011004#endif
11005 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
11006 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
11007 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
11008 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011009#ifdef FEAT_PERSISTENT_UNDO
11010 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
11011#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011012 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
11013#ifdef FEAT_KEYMAP
11014 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
11015#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011016#ifdef FEAT_SIGNS
11017 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
11018#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011019#ifdef FEAT_VARTABS
11020 case PV_VSTS: return (char_u *)&(curbuf->b_p_vsts);
11021 case PV_VTS: return (char_u *)&(curbuf->b_p_vts);
11022#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010011023 default: iemsg(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011024 }
11025 /* always return a valid pointer to avoid a crash! */
11026 return (char_u *)&(curbuf->b_p_wm);
11027}
11028
11029/*
11030 * Get the value of 'equalprg', either the buffer-local one or the global one.
11031 */
11032 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011033get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011034{
11035 if (*curbuf->b_p_ep == NUL)
11036 return p_ep;
11037 return curbuf->b_p_ep;
11038}
11039
Bram Moolenaar071d4272004-06-13 20:20:40 +000011040/*
11041 * Copy options from one window to another.
11042 * Used when splitting a window.
11043 */
11044 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011045win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011046{
11047 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
11048 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020011049#if defined(FEAT_LINEBREAK)
11050 briopt_check(wp_to);
11051#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011052}
Bram Moolenaar071d4272004-06-13 20:20:40 +000011053
11054/*
11055 * Copy the options from one winopt_T to another.
11056 * Doesn't free the old option values in "to", use clear_winopt() for that.
11057 * The 'scroll' option is not copied, because it depends on the window height.
11058 * The 'previewwindow' option is reset, there can be only one preview window.
11059 */
11060 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011061copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011062{
11063#ifdef FEAT_ARABIC
11064 to->wo_arab = from->wo_arab;
11065#endif
11066 to->wo_list = from->wo_list;
11067 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020011068 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011069#ifdef FEAT_LINEBREAK
11070 to->wo_nuw = from->wo_nuw;
11071#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011072#ifdef FEAT_RIGHTLEFT
11073 to->wo_rl = from->wo_rl;
11074 to->wo_rlc = vim_strsave(from->wo_rlc);
11075#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011076#ifdef FEAT_STL_OPT
11077 to->wo_stl = vim_strsave(from->wo_stl);
11078#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011079 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011080#ifdef FEAT_DIFF
11081 to->wo_wrap_save = from->wo_wrap_save;
11082#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011083#ifdef FEAT_LINEBREAK
11084 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020011085 to->wo_bri = from->wo_bri;
11086 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011087#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011088 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011089 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010011090 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011091 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011092#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000011093 to->wo_spell = from->wo_spell;
11094#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011095#ifdef FEAT_SYN_HL
11096 to->wo_cuc = from->wo_cuc;
11097 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020011098 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011099#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011100#ifdef FEAT_DIFF
11101 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011102 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011103#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011104#ifdef FEAT_CONCEAL
11105 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020011106 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011107#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011108#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011109 to->wo_twk = vim_strsave(from->wo_twk);
11110 to->wo_tws = vim_strsave(from->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011111#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011112#ifdef FEAT_FOLDING
11113 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011114 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011115 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011116 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011117 to->wo_fdi = vim_strsave(from->wo_fdi);
11118 to->wo_fml = from->wo_fml;
11119 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011120 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011121 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011122 to->wo_fdm_save = from->wo_diff_saved
11123 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011124 to->wo_fdn = from->wo_fdn;
11125# ifdef FEAT_EVAL
11126 to->wo_fde = vim_strsave(from->wo_fde);
11127 to->wo_fdt = vim_strsave(from->wo_fdt);
11128# endif
11129 to->wo_fmr = vim_strsave(from->wo_fmr);
11130#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011131#ifdef FEAT_SIGNS
11132 to->wo_scl = vim_strsave(from->wo_scl);
11133#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011134 check_winopt(to); /* don't want NULL pointers */
11135}
11136
11137/*
11138 * Check string options in a window for a NULL value.
11139 */
11140 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011141check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011142{
11143 check_winopt(&win->w_onebuf_opt);
11144 check_winopt(&win->w_allbuf_opt);
11145}
11146
11147/*
11148 * Check for NULL pointers in a winopt_T and replace them with empty_option.
11149 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020011150 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011151check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011152{
11153#ifdef FEAT_FOLDING
11154 check_string_option(&wop->wo_fdi);
11155 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011156 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011157# ifdef FEAT_EVAL
11158 check_string_option(&wop->wo_fde);
11159 check_string_option(&wop->wo_fdt);
11160# endif
11161 check_string_option(&wop->wo_fmr);
11162#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011163#ifdef FEAT_SIGNS
11164 check_string_option(&wop->wo_scl);
11165#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011166#ifdef FEAT_RIGHTLEFT
11167 check_string_option(&wop->wo_rlc);
11168#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011169#ifdef FEAT_STL_OPT
11170 check_string_option(&wop->wo_stl);
11171#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011172#ifdef FEAT_SYN_HL
11173 check_string_option(&wop->wo_cc);
11174#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011175#ifdef FEAT_CONCEAL
11176 check_string_option(&wop->wo_cocu);
11177#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011178#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011179 check_string_option(&wop->wo_twk);
11180 check_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011181#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011182#ifdef FEAT_LINEBREAK
11183 check_string_option(&wop->wo_briopt);
11184#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011185}
11186
11187/*
11188 * Free the allocated memory inside a winopt_T.
11189 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011190 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011191clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011192{
11193#ifdef FEAT_FOLDING
11194 clear_string_option(&wop->wo_fdi);
11195 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011196 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011197# ifdef FEAT_EVAL
11198 clear_string_option(&wop->wo_fde);
11199 clear_string_option(&wop->wo_fdt);
11200# endif
11201 clear_string_option(&wop->wo_fmr);
11202#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011203#ifdef FEAT_SIGNS
11204 clear_string_option(&wop->wo_scl);
11205#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011206#ifdef FEAT_LINEBREAK
11207 clear_string_option(&wop->wo_briopt);
11208#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011209#ifdef FEAT_RIGHTLEFT
11210 clear_string_option(&wop->wo_rlc);
11211#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011212#ifdef FEAT_STL_OPT
11213 clear_string_option(&wop->wo_stl);
11214#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011215#ifdef FEAT_SYN_HL
11216 clear_string_option(&wop->wo_cc);
11217#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011218#ifdef FEAT_CONCEAL
11219 clear_string_option(&wop->wo_cocu);
11220#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011221#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011222 clear_string_option(&wop->wo_twk);
11223 clear_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011224#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011225}
11226
11227/*
11228 * Copy global option values to local options for one buffer.
11229 * Used when creating a new buffer and sometimes when entering a buffer.
11230 * flags:
11231 * BCO_ENTER We will enter the buf buffer.
11232 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11233 * appropriate.
11234 * BCO_NOHELP Don't copy the values to a help buffer.
11235 */
11236 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011237buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011238{
11239 int should_copy = TRUE;
11240 char_u *save_p_isk = NULL; /* init for GCC */
11241 int dont_do_help;
11242 int did_isk = FALSE;
11243
11244 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011245 * Skip this when the option defaults have not been set yet. Happens when
11246 * main() allocates the first buffer.
11247 */
11248 if (p_cpo != NULL)
11249 {
11250 /*
11251 * Always copy when entering and 'cpo' contains 'S'.
11252 * Don't copy when already initialized.
11253 * Don't copy when 'cpo' contains 's' and not entering.
11254 * 'S' BCO_ENTER initialized 's' should_copy
11255 * yes yes X X TRUE
11256 * yes no yes X FALSE
11257 * no X yes X FALSE
11258 * X no no yes FALSE
11259 * X no no no TRUE
11260 * no yes no X TRUE
11261 */
11262 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11263 && (buf->b_p_initialized
11264 || (!(flags & BCO_ENTER)
11265 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11266 should_copy = FALSE;
11267
11268 if (should_copy || (flags & BCO_ALWAYS))
11269 {
11270 /* Don't copy the options specific to a help buffer when
11271 * BCO_NOHELP is given or the options were initialized already
11272 * (jumping back to a help file with CTRL-T or CTRL-O) */
11273 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11274 || buf->b_p_initialized;
11275 if (dont_do_help) /* don't free b_p_isk */
11276 {
11277 save_p_isk = buf->b_p_isk;
11278 buf->b_p_isk = NULL;
11279 }
11280 /*
Bram Moolenaar40385db2018-08-07 22:31:44 +020011281 * Always free the allocated strings. If not already initialized,
11282 * reset 'readonly' and copy 'fileformat'.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011283 */
11284 if (!buf->b_p_initialized)
11285 {
11286 free_buf_options(buf, TRUE);
11287 buf->b_p_ro = FALSE; /* don't copy readonly */
11288 buf->b_p_tx = p_tx;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011289 buf->b_p_fenc = vim_strsave(p_fenc);
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011290 switch (*p_ffs)
11291 {
11292 case 'm':
11293 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11294 case 'd':
11295 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11296 case 'u':
11297 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11298 default:
11299 buf->b_p_ff = vim_strsave(p_ff);
11300 }
11301 if (buf->b_p_ff != NULL)
11302 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011303 buf->b_p_bh = empty_option;
11304 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011305 }
11306 else
11307 free_buf_options(buf, FALSE);
11308
11309 buf->b_p_ai = p_ai;
11310 buf->b_p_ai_nopaste = p_ai_nopaste;
11311 buf->b_p_sw = p_sw;
11312 buf->b_p_tw = p_tw;
11313 buf->b_p_tw_nopaste = p_tw_nopaste;
11314 buf->b_p_tw_nobin = p_tw_nobin;
11315 buf->b_p_wm = p_wm;
11316 buf->b_p_wm_nopaste = p_wm_nopaste;
11317 buf->b_p_wm_nobin = p_wm_nobin;
11318 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011319 buf->b_p_bomb = p_bomb;
Bram Moolenaarb388be02015-07-22 22:19:38 +020011320 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011321 buf->b_p_et = p_et;
11322 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011323 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011324 buf->b_p_ml = p_ml;
11325 buf->b_p_ml_nobin = p_ml_nobin;
11326 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011327 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011328#ifdef FEAT_INS_EXPAND
11329 buf->b_p_cpt = vim_strsave(p_cpt);
11330#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011331#ifdef FEAT_COMPL_FUNC
11332 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011333 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011334#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011335 buf->b_p_sts = p_sts;
11336 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011337#ifdef FEAT_VARTABS
11338 buf->b_p_vsts = vim_strsave(p_vsts);
11339 if (p_vsts && p_vsts != empty_option)
11340 tabstop_set(p_vsts, &buf->b_p_vsts_array);
11341 else
11342 buf->b_p_vsts_array = 0;
11343 buf->b_p_vsts_nopaste = p_vsts_nopaste
11344 ? vim_strsave(p_vsts_nopaste) : NULL;
11345#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011346 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011347#ifdef FEAT_COMMENTS
11348 buf->b_p_com = vim_strsave(p_com);
11349#endif
11350#ifdef FEAT_FOLDING
11351 buf->b_p_cms = vim_strsave(p_cms);
11352#endif
11353 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011354 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011355 buf->b_p_nf = vim_strsave(p_nf);
11356 buf->b_p_mps = vim_strsave(p_mps);
11357#ifdef FEAT_SMARTINDENT
11358 buf->b_p_si = p_si;
11359#endif
11360 buf->b_p_ci = p_ci;
11361#ifdef FEAT_CINDENT
11362 buf->b_p_cin = p_cin;
11363 buf->b_p_cink = vim_strsave(p_cink);
11364 buf->b_p_cino = vim_strsave(p_cino);
11365#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011366 /* Don't copy 'filetype', it must be detected */
11367 buf->b_p_ft = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011368 buf->b_p_pi = p_pi;
11369#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11370 buf->b_p_cinw = vim_strsave(p_cinw);
11371#endif
11372#ifdef FEAT_LISP
11373 buf->b_p_lisp = p_lisp;
11374#endif
11375#ifdef FEAT_SYN_HL
11376 /* Don't copy 'syntax', it must be set */
11377 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011378 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011379 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011380#endif
11381#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011382 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011383 (void)compile_cap_prog(&buf->b_s);
11384 buf->b_s.b_p_spf = vim_strsave(p_spf);
11385 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011386#endif
11387#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11388 buf->b_p_inde = vim_strsave(p_inde);
11389 buf->b_p_indk = vim_strsave(p_indk);
11390#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011391 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011392#if defined(FEAT_EVAL)
11393 buf->b_p_fex = vim_strsave(p_fex);
11394#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011395#ifdef FEAT_CRYPT
11396 buf->b_p_key = vim_strsave(p_key);
11397#endif
11398#ifdef FEAT_SEARCHPATH
11399 buf->b_p_sua = vim_strsave(p_sua);
11400#endif
11401#ifdef FEAT_KEYMAP
11402 buf->b_p_keymap = vim_strsave(p_keymap);
11403 buf->b_kmap_state |= KEYMAP_INIT;
11404#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011405#ifdef FEAT_TERMINAL
11406 buf->b_p_twsl = p_twsl;
11407#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011408 /* This isn't really an option, but copying the langmap and IME
11409 * state from the current buffer is better than resetting it. */
11410 buf->b_p_iminsert = p_iminsert;
11411 buf->b_p_imsearch = p_imsearch;
11412
11413 /* options that are normally global but also have a local value
11414 * are not copied, start using the global value */
11415 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011416 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011417 buf->b_p_bkc = empty_option;
11418 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011419#ifdef FEAT_QUICKFIX
11420 buf->b_p_gp = empty_option;
11421 buf->b_p_mp = empty_option;
11422 buf->b_p_efm = empty_option;
11423#endif
11424 buf->b_p_ep = empty_option;
11425 buf->b_p_kp = empty_option;
11426 buf->b_p_path = empty_option;
11427 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011428 buf->b_p_tc = empty_option;
11429 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011430#ifdef FEAT_FIND_ID
11431 buf->b_p_def = empty_option;
11432 buf->b_p_inc = empty_option;
11433# ifdef FEAT_EVAL
11434 buf->b_p_inex = vim_strsave(p_inex);
11435# endif
11436#endif
11437#ifdef FEAT_INS_EXPAND
11438 buf->b_p_dict = empty_option;
11439 buf->b_p_tsr = empty_option;
11440#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011441#ifdef FEAT_TEXTOBJ
11442 buf->b_p_qe = vim_strsave(p_qe);
11443#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011444#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11445 buf->b_p_bexpr = empty_option;
11446#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011447#if defined(FEAT_CRYPT)
11448 buf->b_p_cm = empty_option;
11449#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011450#ifdef FEAT_PERSISTENT_UNDO
11451 buf->b_p_udf = p_udf;
11452#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011453#ifdef FEAT_LISP
11454 buf->b_p_lw = empty_option;
11455#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011456 buf->b_p_menc = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011457
11458 /*
11459 * Don't copy the options set by ex_help(), use the saved values,
11460 * when going from a help buffer to a non-help buffer.
11461 * Don't touch these at all when BCO_NOHELP is used and going from
11462 * or to a help buffer.
11463 */
11464 if (dont_do_help)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011465 {
Bram Moolenaar071d4272004-06-13 20:20:40 +000011466 buf->b_p_isk = save_p_isk;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011467#ifdef FEAT_VARTABS
11468 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11469 tabstop_set(p_vts, &buf->b_p_vts_array);
11470 else
11471 buf->b_p_vts_array = NULL;
11472#endif
11473 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011474 else
11475 {
11476 buf->b_p_isk = vim_strsave(p_isk);
11477 did_isk = TRUE;
11478 buf->b_p_ts = p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011479#ifdef FEAT_VARTABS
11480 buf->b_p_vts = vim_strsave(p_vts);
11481 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11482 tabstop_set(p_vts, &buf->b_p_vts_array);
11483 else
11484 buf->b_p_vts_array = NULL;
11485#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011486 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011487 if (buf->b_p_bt[0] == 'h')
11488 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011489 buf->b_p_ma = p_ma;
11490 }
11491 }
11492
11493 /*
11494 * When the options should be copied (ignoring BCO_ALWAYS), set the
11495 * flag that indicates that the options have been initialized.
11496 */
11497 if (should_copy)
11498 buf->b_p_initialized = TRUE;
11499 }
11500
11501 check_buf_options(buf); /* make sure we don't have NULLs */
11502 if (did_isk)
11503 (void)buf_init_chartab(buf, FALSE);
11504}
11505
11506/*
11507 * Reset the 'modifiable' option and its default value.
11508 */
11509 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011510reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011511{
11512 int opt_idx;
11513
11514 curbuf->b_p_ma = FALSE;
11515 p_ma = FALSE;
11516 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011517 if (opt_idx >= 0)
11518 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011519}
11520
11521/*
11522 * Set the global value for 'iminsert' to the local value.
11523 */
11524 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011525set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011526{
11527 p_iminsert = curbuf->b_p_iminsert;
11528}
11529
11530/*
11531 * Set the global value for 'imsearch' to the local value.
11532 */
11533 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011534set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011535{
11536 p_imsearch = curbuf->b_p_imsearch;
11537}
11538
11539#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11540static int expand_option_idx = -1;
11541static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11542static int expand_option_flags = 0;
11543
11544 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011545set_context_in_set_cmd(
11546 expand_T *xp,
11547 char_u *arg,
11548 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011549{
11550 int nextchar;
11551 long_u flags = 0; /* init for GCC */
11552 int opt_idx = 0; /* init for GCC */
11553 char_u *p;
11554 char_u *s;
11555 int is_term_option = FALSE;
11556 int key;
11557
11558 expand_option_flags = opt_flags;
11559
11560 xp->xp_context = EXPAND_SETTINGS;
11561 if (*arg == NUL)
11562 {
11563 xp->xp_pattern = arg;
11564 return;
11565 }
11566 p = arg + STRLEN(arg) - 1;
11567 if (*p == ' ' && *(p - 1) != '\\')
11568 {
11569 xp->xp_pattern = p + 1;
11570 return;
11571 }
11572 while (p > arg)
11573 {
11574 s = p;
11575 /* count number of backslashes before ' ' or ',' */
11576 if (*p == ' ' || *p == ',')
11577 {
11578 while (s > arg && *(s - 1) == '\\')
11579 --s;
11580 }
11581 /* break at a space with an even number of backslashes */
11582 if (*p == ' ' && ((p - s) & 1) == 0)
11583 {
11584 ++p;
11585 break;
11586 }
11587 --p;
11588 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011589 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011590 {
11591 xp->xp_context = EXPAND_BOOL_SETTINGS;
11592 p += 2;
11593 }
11594 if (STRNCMP(p, "inv", 3) == 0)
11595 {
11596 xp->xp_context = EXPAND_BOOL_SETTINGS;
11597 p += 3;
11598 }
11599 xp->xp_pattern = arg = p;
11600 if (*arg == '<')
11601 {
11602 while (*p != '>')
11603 if (*p++ == NUL) /* expand terminal option name */
11604 return;
11605 key = get_special_key_code(arg + 1);
11606 if (key == 0) /* unknown name */
11607 {
11608 xp->xp_context = EXPAND_NOTHING;
11609 return;
11610 }
11611 nextchar = *++p;
11612 is_term_option = TRUE;
11613 expand_option_name[2] = KEY2TERMCAP0(key);
11614 expand_option_name[3] = KEY2TERMCAP1(key);
11615 }
11616 else
11617 {
11618 if (p[0] == 't' && p[1] == '_')
11619 {
11620 p += 2;
11621 if (*p != NUL)
11622 ++p;
11623 if (*p == NUL)
11624 return; /* expand option name */
11625 nextchar = *++p;
11626 is_term_option = TRUE;
11627 expand_option_name[2] = p[-2];
11628 expand_option_name[3] = p[-1];
11629 }
11630 else
11631 {
11632 /* Allow * wildcard */
11633 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11634 p++;
11635 if (*p == NUL)
11636 return;
11637 nextchar = *p;
11638 *p = NUL;
11639 opt_idx = findoption(arg);
11640 *p = nextchar;
11641 if (opt_idx == -1 || options[opt_idx].var == NULL)
11642 {
11643 xp->xp_context = EXPAND_NOTHING;
11644 return;
11645 }
11646 flags = options[opt_idx].flags;
11647 if (flags & P_BOOL)
11648 {
11649 xp->xp_context = EXPAND_NOTHING;
11650 return;
11651 }
11652 }
11653 }
11654 /* handle "-=" and "+=" */
11655 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11656 {
11657 ++p;
11658 nextchar = '=';
11659 }
11660 if ((nextchar != '=' && nextchar != ':')
11661 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11662 {
11663 xp->xp_context = EXPAND_UNSUCCESSFUL;
11664 return;
11665 }
11666 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11667 {
11668 xp->xp_context = EXPAND_OLD_SETTING;
11669 if (is_term_option)
11670 expand_option_idx = -1;
11671 else
11672 expand_option_idx = opt_idx;
11673 xp->xp_pattern = p + 1;
11674 return;
11675 }
11676 xp->xp_context = EXPAND_NOTHING;
11677 if (is_term_option || (flags & P_NUM))
11678 return;
11679
11680 xp->xp_pattern = p + 1;
11681
11682 if (flags & P_EXPAND)
11683 {
11684 p = options[opt_idx].var;
11685 if (p == (char_u *)&p_bdir
11686 || p == (char_u *)&p_dir
11687 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011688 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011689 || p == (char_u *)&p_rtp
11690#ifdef FEAT_SEARCHPATH
11691 || p == (char_u *)&p_cdpath
11692#endif
11693#ifdef FEAT_SESSION
11694 || p == (char_u *)&p_vdir
11695#endif
11696 )
11697 {
11698 xp->xp_context = EXPAND_DIRECTORIES;
11699 if (p == (char_u *)&p_path
11700#ifdef FEAT_SEARCHPATH
11701 || p == (char_u *)&p_cdpath
11702#endif
11703 )
11704 xp->xp_backslash = XP_BS_THREE;
11705 else
11706 xp->xp_backslash = XP_BS_ONE;
11707 }
11708 else
11709 {
11710 xp->xp_context = EXPAND_FILES;
11711 /* for 'tags' need three backslashes for a space */
11712 if (p == (char_u *)&p_tags)
11713 xp->xp_backslash = XP_BS_THREE;
11714 else
11715 xp->xp_backslash = XP_BS_ONE;
11716 }
11717 }
11718
11719 /* For an option that is a list of file names, find the start of the
11720 * last file name. */
11721 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11722 {
11723 /* count number of backslashes before ' ' or ',' */
11724 if (*p == ' ' || *p == ',')
11725 {
11726 s = p;
11727 while (s > xp->xp_pattern && *(s - 1) == '\\')
11728 --s;
11729 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11730 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11731 {
11732 xp->xp_pattern = p + 1;
11733 break;
11734 }
11735 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011736
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011737#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011738 /* for 'spellsuggest' start at "file:" */
11739 if (options[opt_idx].var == (char_u *)&p_sps
11740 && STRNCMP(p, "file:", 5) == 0)
11741 {
11742 xp->xp_pattern = p + 5;
11743 break;
11744 }
11745#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011746 }
11747
11748 return;
11749}
11750
11751 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011752ExpandSettings(
11753 expand_T *xp,
11754 regmatch_T *regmatch,
11755 int *num_file,
11756 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011757{
11758 int num_normal = 0; /* Nr of matching non-term-code settings */
11759 int num_term = 0; /* Nr of matching terminal code settings */
11760 int opt_idx;
11761 int match;
11762 int count = 0;
11763 char_u *str;
11764 int loop;
11765 int is_term_opt;
11766 char_u name_buf[MAX_KEY_NAME_LEN];
11767 static char *(names[]) = {"all", "termcap"};
11768 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11769
11770 /* do this loop twice:
11771 * loop == 0: count the number of matching options
11772 * loop == 1: copy the matching options into allocated memory
11773 */
11774 for (loop = 0; loop <= 1; ++loop)
11775 {
11776 regmatch->rm_ic = ic;
11777 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11778 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011779 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11780 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011781 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11782 {
11783 if (loop == 0)
11784 num_normal++;
11785 else
11786 (*file)[count++] = vim_strsave((char_u *)names[match]);
11787 }
11788 }
11789 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11790 opt_idx++)
11791 {
11792 if (options[opt_idx].var == NULL)
11793 continue;
11794 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11795 && !(options[opt_idx].flags & P_BOOL))
11796 continue;
11797 is_term_opt = istermoption(&options[opt_idx]);
11798 if (is_term_opt && num_normal > 0)
11799 continue;
11800 match = FALSE;
11801 if (vim_regexec(regmatch, str, (colnr_T)0)
11802 || (options[opt_idx].shortname != NULL
11803 && vim_regexec(regmatch,
11804 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11805 match = TRUE;
11806 else if (is_term_opt)
11807 {
11808 name_buf[0] = '<';
11809 name_buf[1] = 't';
11810 name_buf[2] = '_';
11811 name_buf[3] = str[2];
11812 name_buf[4] = str[3];
11813 name_buf[5] = '>';
11814 name_buf[6] = NUL;
11815 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11816 {
11817 match = TRUE;
11818 str = name_buf;
11819 }
11820 }
11821 if (match)
11822 {
11823 if (loop == 0)
11824 {
11825 if (is_term_opt)
11826 num_term++;
11827 else
11828 num_normal++;
11829 }
11830 else
11831 (*file)[count++] = vim_strsave(str);
11832 }
11833 }
11834 /*
11835 * Check terminal key codes, these are not in the option table
11836 */
11837 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11838 {
11839 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11840 {
11841 if (!isprint(str[0]) || !isprint(str[1]))
11842 continue;
11843
11844 name_buf[0] = 't';
11845 name_buf[1] = '_';
11846 name_buf[2] = str[0];
11847 name_buf[3] = str[1];
11848 name_buf[4] = NUL;
11849
11850 match = FALSE;
11851 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11852 match = TRUE;
11853 else
11854 {
11855 name_buf[0] = '<';
11856 name_buf[1] = 't';
11857 name_buf[2] = '_';
11858 name_buf[3] = str[0];
11859 name_buf[4] = str[1];
11860 name_buf[5] = '>';
11861 name_buf[6] = NUL;
11862
11863 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11864 match = TRUE;
11865 }
11866 if (match)
11867 {
11868 if (loop == 0)
11869 num_term++;
11870 else
11871 (*file)[count++] = vim_strsave(name_buf);
11872 }
11873 }
11874
11875 /*
11876 * Check special key names.
11877 */
11878 regmatch->rm_ic = TRUE; /* ignore case here */
11879 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11880 {
11881 name_buf[0] = '<';
11882 STRCPY(name_buf + 1, str);
11883 STRCAT(name_buf, ">");
11884
11885 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11886 {
11887 if (loop == 0)
11888 num_term++;
11889 else
11890 (*file)[count++] = vim_strsave(name_buf);
11891 }
11892 }
11893 }
11894 if (loop == 0)
11895 {
11896 if (num_normal > 0)
11897 *num_file = num_normal;
11898 else if (num_term > 0)
11899 *num_file = num_term;
11900 else
11901 return OK;
11902 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11903 if (*file == NULL)
11904 {
11905 *file = (char_u **)"";
11906 return FAIL;
11907 }
11908 }
11909 }
11910 return OK;
11911}
11912
11913 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011914ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011915{
11916 char_u *var = NULL; /* init for GCC */
11917 char_u *buf;
11918
11919 *num_file = 0;
11920 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11921 if (*file == NULL)
11922 return FAIL;
11923
11924 /*
11925 * For a terminal key code expand_option_idx is < 0.
11926 */
11927 if (expand_option_idx < 0)
11928 {
11929 var = find_termcode(expand_option_name + 2);
11930 if (var == NULL)
11931 expand_option_idx = findoption(expand_option_name);
11932 }
11933
11934 if (expand_option_idx >= 0)
11935 {
11936 /* put string of option value in NameBuff */
11937 option_value2string(&options[expand_option_idx], expand_option_flags);
11938 var = NameBuff;
11939 }
11940 else if (var == NULL)
11941 var = (char_u *)"";
11942
11943 /* A backslash is required before some characters. This is the reverse of
11944 * what happens in do_set(). */
11945 buf = vim_strsave_escaped(var, escape_chars);
11946
11947 if (buf == NULL)
11948 {
Bram Moolenaard23a8232018-02-10 18:45:26 +010011949 VIM_CLEAR(*file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011950 return FAIL;
11951 }
11952
11953#ifdef BACKSLASH_IN_FILENAME
11954 /* For MS-Windows et al. we don't double backslashes at the start and
11955 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011956 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011957 if (var[0] == '\\' && var[1] == '\\'
11958 && expand_option_idx >= 0
11959 && (options[expand_option_idx].flags & P_EXPAND)
11960 && vim_isfilec(var[2])
11961 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011962 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011963#endif
11964
11965 *file[0] = buf;
11966 *num_file = 1;
11967 return OK;
11968}
11969#endif
11970
11971/*
11972 * Get the value for the numeric or string option *opp in a nice format into
11973 * NameBuff[]. Must not be called with a hidden option!
11974 */
11975 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011976option_value2string(
11977 struct vimoption *opp,
11978 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011979{
11980 char_u *varp;
11981
11982 varp = get_varp_scope(opp, opt_flags);
11983
11984 if (opp->flags & P_NUM)
11985 {
11986 long wc = 0;
11987
11988 if (wc_use_keyname(varp, &wc))
11989 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11990 else if (wc != 0)
11991 STRCPY(NameBuff, transchar((int)wc));
11992 else
11993 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11994 }
11995 else /* P_STRING */
11996 {
11997 varp = *(char_u **)(varp);
11998 if (varp == NULL) /* just in case */
11999 NameBuff[0] = NUL;
12000#ifdef FEAT_CRYPT
12001 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000012002 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012003 STRCPY(NameBuff, "*****");
12004#endif
12005 else if (opp->flags & P_EXPAND)
12006 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
12007 /* Translate 'pastetoggle' into special key names */
12008 else if ((char_u **)opp->var == &p_pt)
12009 str2specialbuf(p_pt, NameBuff, MAXPATHL);
12010 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000012011 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012012 }
12013}
12014
12015/*
12016 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
12017 * printed as a keyname.
12018 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
12019 */
12020 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012021wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012022{
12023 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
12024 {
12025 *wcp = *(long *)varp;
12026 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
12027 return TRUE;
12028 }
12029 return FALSE;
12030}
12031
Bram Moolenaar01615492015-02-03 13:00:38 +010012032#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012033/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012034 * Any character has an equivalent 'langmap' character. This is used for
12035 * keyboards that have a special language mode that sends characters above
12036 * 128 (although other characters can be translated too). The "to" field is a
12037 * Vim command character. This avoids having to switch the keyboard back to
12038 * ASCII mode when leaving Insert mode.
12039 *
12040 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
12041 * commands.
Bram Moolenaarfc3abf42019-01-24 15:54:21 +010012042 * langmap_mapga.ga_data is a sorted table of langmap_entry_T. This does the
12043 * same as langmap_mapchar[] for characters >= 256.
12044 *
12045 * Use growarray for 'langmap' chars >= 256
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012046 */
12047typedef struct
12048{
12049 int from;
12050 int to;
12051} langmap_entry_T;
12052
12053static garray_T langmap_mapga;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012054
12055/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012056 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
12057 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012058 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012059 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012060langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012061{
12062 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020012063 int a = 0;
12064 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012065
12066 /* Do a binary search for an existing entry. */
12067 while (a != b)
12068 {
12069 int i = (a + b) / 2;
12070 int d = entries[i].from - from;
12071
12072 if (d == 0)
12073 {
12074 entries[i].to = to;
12075 return;
12076 }
12077 if (d < 0)
12078 a = i + 1;
12079 else
12080 b = i;
12081 }
12082
12083 if (ga_grow(&langmap_mapga, 1) != OK)
12084 return; /* out of memory */
12085
12086 /* insert new entry at position "a" */
12087 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
12088 mch_memmove(entries + 1, entries,
12089 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
12090 ++langmap_mapga.ga_len;
12091 entries[0].from = from;
12092 entries[0].to = to;
12093}
12094
12095/*
12096 * Apply 'langmap' to multi-byte character "c" and return the result.
12097 */
12098 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012099langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012100{
12101 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
12102 int a = 0;
12103 int b = langmap_mapga.ga_len;
12104
12105 while (a != b)
12106 {
12107 int i = (a + b) / 2;
12108 int d = entries[i].from - c;
12109
12110 if (d == 0)
12111 return entries[i].to; /* found matching entry */
12112 if (d < 0)
12113 a = i + 1;
12114 else
12115 b = i;
12116 }
12117 return c; /* no entry found, return "c" unmodified */
12118}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012119
12120 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012121langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012122{
12123 int i;
12124
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012125 for (i = 0; i < 256; i++)
12126 langmap_mapchar[i] = i; /* we init with a one-to-one map */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012127 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012128}
12129
12130/*
12131 * Called when langmap option is set; the language map can be
12132 * changed at any time!
12133 */
12134 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012135langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012136{
12137 char_u *p;
12138 char_u *p2;
12139 int from, to;
12140
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012141 ga_clear(&langmap_mapga); /* clear the previous map first */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012142 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012143
12144 for (p = p_langmap; p[0] != NUL; )
12145 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000012146 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012147 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012148 {
12149 if (p2[0] == '\\' && p2[1] != NUL)
12150 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012151 }
12152 if (p2[0] == ';')
12153 ++p2; /* abcd;ABCD form, p2 points to A */
12154 else
12155 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
12156 while (p[0])
12157 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012158 if (p[0] == ',')
12159 {
12160 ++p;
12161 break;
12162 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012163 if (p[0] == '\\' && p[1] != NUL)
12164 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012165 from = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012166 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012167 if (p2 == NULL)
12168 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012169 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012170 if (p[0] != ',')
12171 {
12172 if (p[0] == '\\')
12173 ++p;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012174 to = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012175 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012176 }
12177 else
12178 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012179 if (p2[0] != ',')
12180 {
12181 if (p2[0] == '\\')
12182 ++p2;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012183 to = (*mb_ptr2char)(p2);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012184 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012185 }
12186 if (to == NUL)
12187 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012188 semsg(_("E357: 'langmap': Matching character missing for %s"),
Bram Moolenaar071d4272004-06-13 20:20:40 +000012189 transchar(from));
12190 return;
12191 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012192
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012193 if (from >= 256)
12194 langmap_set_entry(from, to);
12195 else
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012196 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012197
12198 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012199 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012200 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012201 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012202 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012203 if (*p == ';')
12204 {
12205 p = p2;
12206 if (p[0] != NUL)
12207 {
12208 if (p[0] != ',')
12209 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012210 semsg(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012211 return;
12212 }
12213 ++p;
12214 }
12215 break;
12216 }
12217 }
12218 }
12219 }
12220}
12221#endif
12222
12223/*
12224 * Return TRUE if format option 'x' is in effect.
12225 * Take care of no formatting when 'paste' is set.
12226 */
12227 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012228has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012229{
12230 if (p_paste)
12231 return FALSE;
12232 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12233}
12234
12235/*
12236 * Return TRUE if "x" is present in 'shortmess' option, or
12237 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12238 */
12239 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012240shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012241{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012242 return p_shm != NULL &&
12243 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012244 || (vim_strchr(p_shm, 'a') != NULL
12245 && vim_strchr((char_u *)SHM_A, x) != NULL));
12246}
12247
12248/*
12249 * paste_option_changed() - Called after p_paste was set or reset.
12250 */
12251 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012252paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012253{
12254 static int old_p_paste = FALSE;
12255 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012256 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012257#ifdef FEAT_CMDL_INFO
12258 static int save_ru = 0;
12259#endif
12260#ifdef FEAT_RIGHTLEFT
12261 static int save_ri = 0;
12262 static int save_hkmap = 0;
12263#endif
12264 buf_T *buf;
12265
12266 if (p_paste)
12267 {
12268 /*
12269 * Paste switched from off to on.
12270 * Save the current values, so they can be restored later.
12271 */
12272 if (!old_p_paste)
12273 {
12274 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012275 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012276 {
12277 buf->b_p_tw_nopaste = buf->b_p_tw;
12278 buf->b_p_wm_nopaste = buf->b_p_wm;
12279 buf->b_p_sts_nopaste = buf->b_p_sts;
12280 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012281 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012282#ifdef FEAT_VARTABS
12283 if (buf->b_p_vsts_nopaste)
12284 vim_free(buf->b_p_vsts_nopaste);
12285 buf->b_p_vsts_nopaste = buf->b_p_vsts && buf->b_p_vsts != empty_option
12286 ? vim_strsave(buf->b_p_vsts) : NULL;
12287#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012288 }
12289
12290 /* save global options */
12291 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012292 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012293#ifdef FEAT_CMDL_INFO
12294 save_ru = p_ru;
12295#endif
12296#ifdef FEAT_RIGHTLEFT
12297 save_ri = p_ri;
12298 save_hkmap = p_hkmap;
12299#endif
12300 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012301 p_ai_nopaste = p_ai;
12302 p_et_nopaste = p_et;
12303 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012304 p_tw_nopaste = p_tw;
12305 p_wm_nopaste = p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012306#ifdef FEAT_VARTABS
12307 if (p_vsts_nopaste)
12308 vim_free(p_vsts_nopaste);
12309 p_vsts_nopaste = p_vsts && p_vsts != empty_option ? vim_strsave(p_vsts) : NULL;
12310#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012311 }
12312
12313 /*
12314 * Always set the option values, also when 'paste' is set when it is
12315 * already on.
12316 */
12317 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012318 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012319 {
12320 buf->b_p_tw = 0; /* textwidth is 0 */
12321 buf->b_p_wm = 0; /* wrapmargin is 0 */
12322 buf->b_p_sts = 0; /* softtabstop is 0 */
12323 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012324 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012325#ifdef FEAT_VARTABS
12326 if (buf->b_p_vsts)
12327 free_string_option(buf->b_p_vsts);
12328 buf->b_p_vsts = empty_option;
12329 if (buf->b_p_vsts_array)
12330 vim_free(buf->b_p_vsts_array);
12331 buf->b_p_vsts_array = 0;
12332#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012333 }
12334
12335 /* set global options */
12336 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012337 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012338#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012339 if (p_ru)
12340 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012341 p_ru = 0; /* no ruler */
12342#endif
12343#ifdef FEAT_RIGHTLEFT
12344 p_ri = 0; /* no reverse insert */
12345 p_hkmap = 0; /* no Hebrew keyboard */
12346#endif
12347 /* set global values for local buffer options */
12348 p_tw = 0;
12349 p_wm = 0;
12350 p_sts = 0;
12351 p_ai = 0;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012352#ifdef FEAT_VARTABS
12353 if (p_vsts)
12354 free_string_option(p_vsts);
12355 p_vsts = empty_option;
12356#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012357 }
12358
12359 /*
12360 * Paste switched from on to off: Restore saved values.
12361 */
12362 else if (old_p_paste)
12363 {
12364 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012365 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012366 {
12367 buf->b_p_tw = buf->b_p_tw_nopaste;
12368 buf->b_p_wm = buf->b_p_wm_nopaste;
12369 buf->b_p_sts = buf->b_p_sts_nopaste;
12370 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012371 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012372#ifdef FEAT_VARTABS
12373 if (buf->b_p_vsts)
12374 free_string_option(buf->b_p_vsts);
12375 buf->b_p_vsts = buf->b_p_vsts_nopaste
12376 ? vim_strsave(buf->b_p_vsts_nopaste) : empty_option;
12377 if (buf->b_p_vsts_array)
12378 vim_free(buf->b_p_vsts_array);
12379 if (buf->b_p_vsts && buf->b_p_vsts != empty_option)
12380 tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array);
12381 else
12382 buf->b_p_vsts_array = 0;
12383#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012384 }
12385
12386 /* restore global options */
12387 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012388 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012389#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012390 if (p_ru != save_ru)
12391 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012392 p_ru = save_ru;
12393#endif
12394#ifdef FEAT_RIGHTLEFT
12395 p_ri = save_ri;
12396 p_hkmap = save_hkmap;
12397#endif
12398 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012399 p_ai = p_ai_nopaste;
12400 p_et = p_et_nopaste;
12401 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012402 p_tw = p_tw_nopaste;
12403 p_wm = p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012404#ifdef FEAT_VARTABS
12405 if (p_vsts)
12406 free_string_option(p_vsts);
12407 p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option;
12408#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012409 }
12410
12411 old_p_paste = p_paste;
12412}
12413
12414/*
12415 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12416 *
12417 * Reset 'compatible' and set the values for options that didn't get set yet
12418 * to the Vim defaults.
12419 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012420 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012421 */
12422 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012423vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012424{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012425 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012426 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012427 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012428
12429 if (!option_was_set((char_u *)"cp"))
12430 {
12431 p_cp = FALSE;
12432 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12433 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12434 set_option_default(opt_idx, OPT_FREE, FALSE);
12435 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012436 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012437 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012438
12439 if (fname != NULL)
12440 {
12441 p = vim_getenv(envname, &dofree);
12442 if (p == NULL)
12443 {
12444 /* Set $MYVIMRC to the first vimrc file found. */
12445 p = FullName_save(fname, FALSE);
12446 if (p != NULL)
12447 {
12448 vim_setenv(envname, p);
12449 vim_free(p);
12450 }
12451 }
12452 else if (dofree)
12453 vim_free(p);
12454 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012455}
12456
12457/*
12458 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12459 */
12460 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012461change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012462{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012463 int opt_idx;
12464
Bram Moolenaar071d4272004-06-13 20:20:40 +000012465 if (p_cp != on)
12466 {
12467 p_cp = on;
12468 compatible_set();
12469 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012470 opt_idx = findoption((char_u *)"cp");
12471 if (opt_idx >= 0)
12472 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012473}
12474
12475/*
12476 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012477 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012478 */
12479 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012480option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012481{
12482 int idx;
12483
12484 idx = findoption(name);
12485 if (idx < 0) /* unknown option */
12486 return FALSE;
12487 if (options[idx].flags & P_WAS_SET)
12488 return TRUE;
12489 return FALSE;
12490}
12491
12492/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012493 * Reset the flag indicating option "name" was set.
12494 */
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012495 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012496reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012497{
12498 int idx = findoption(name);
12499
12500 if (idx >= 0)
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012501 {
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012502 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012503 return OK;
12504 }
12505 return FAIL;
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012506}
12507
12508/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012509 * compatible_set() - Called when 'compatible' has been set or unset.
12510 *
12511 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12512 * flag) to a Vi compatible value.
12513 * When 'compatible' is unset: Set all options that have a different default
12514 * for Vim (without the P_VI_DEF flag) to that default.
12515 */
12516 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012517compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012518{
12519 int opt_idx;
12520
12521 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12522 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12523 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12524 set_option_default(opt_idx, OPT_FREE, p_cp);
12525 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012526 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012527}
12528
12529#ifdef FEAT_LINEBREAK
12530
12531# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12532 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012533 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012534# endif
12535
12536/*
12537 * fill_breakat_flags() -- called when 'breakat' changes value.
12538 */
12539 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012540fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012541{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012542 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012543 int i;
12544
12545 for (i = 0; i < 256; i++)
12546 breakat_flags[i] = FALSE;
12547
12548 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012549 for (p = p_breakat; *p; p++)
12550 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012551}
12552
12553# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012554 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012555# endif
12556
12557#endif
12558
12559/*
12560 * Check an option that can be a range of string values.
12561 *
12562 * Return OK for correct value, FAIL otherwise.
12563 * Empty is always OK.
12564 */
12565 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012566check_opt_strings(
12567 char_u *val,
12568 char **values,
12569 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012570{
12571 return opt_strings_flags(val, values, NULL, list);
12572}
12573
12574/*
12575 * Handle an option that can be a range of string values.
12576 * Set a flag in "*flagp" for each string present.
12577 *
12578 * Return OK for correct value, FAIL otherwise.
12579 * Empty is always OK.
12580 */
12581 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012582opt_strings_flags(
12583 char_u *val, /* new value */
12584 char **values, /* array of valid string values */
12585 unsigned *flagp,
12586 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012587{
12588 int i;
12589 int len;
12590 unsigned new_flags = 0;
12591
12592 while (*val)
12593 {
12594 for (i = 0; ; ++i)
12595 {
12596 if (values[i] == NULL) /* val not found in values[] */
12597 return FAIL;
12598
12599 len = (int)STRLEN(values[i]);
12600 if (STRNCMP(values[i], val, len) == 0
12601 && ((list && val[len] == ',') || val[len] == NUL))
12602 {
12603 val += len + (val[len] == ',');
12604 new_flags |= (1 << i);
12605 break; /* check next item in val list */
12606 }
12607 }
12608 }
12609 if (flagp != NULL)
12610 *flagp = new_flags;
12611
12612 return OK;
12613}
12614
12615/*
12616 * Read the 'wildmode' option, fill wim_flags[].
12617 */
12618 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012619check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012620{
12621 char_u new_wim_flags[4];
12622 char_u *p;
12623 int i;
12624 int idx = 0;
12625
12626 for (i = 0; i < 4; ++i)
12627 new_wim_flags[i] = 0;
12628
12629 for (p = p_wim; *p; ++p)
12630 {
12631 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12632 ;
12633 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12634 return FAIL;
12635 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12636 new_wim_flags[idx] |= WIM_LONGEST;
12637 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12638 new_wim_flags[idx] |= WIM_FULL;
12639 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12640 new_wim_flags[idx] |= WIM_LIST;
12641 else
12642 return FAIL;
12643 p += i;
12644 if (*p == NUL)
12645 break;
12646 if (*p == ',')
12647 {
12648 if (idx == 3)
12649 return FAIL;
12650 ++idx;
12651 }
12652 }
12653
12654 /* fill remaining entries with last flag */
12655 while (idx < 3)
12656 {
12657 new_wim_flags[idx + 1] = new_wim_flags[idx];
12658 ++idx;
12659 }
12660
12661 /* only when there are no errors, wim_flags[] is changed */
12662 for (i = 0; i < 4; ++i)
12663 wim_flags[i] = new_wim_flags[i];
12664 return OK;
12665}
12666
12667/*
12668 * Check if backspacing over something is allowed.
12669 */
12670 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012671can_bs(
12672 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012673{
Bram Moolenaar6b810d92018-06-04 17:28:44 +020012674#ifdef FEAT_JOB_CHANNEL
12675 if (what == BS_START && bt_prompt(curbuf))
12676 return FALSE;
12677#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012678 switch (*p_bs)
12679 {
12680 case '2': return TRUE;
12681 case '1': return (what != BS_START);
12682 case '0': return FALSE;
12683 }
12684 return vim_strchr(p_bs, what) != NULL;
12685}
12686
12687/*
12688 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12689 * the file must be considered changed when the value is different.
12690 */
12691 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012692save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012693{
12694 buf->b_start_ffc = *buf->b_p_ff;
12695 buf->b_start_eol = buf->b_p_eol;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012696 buf->b_start_bomb = buf->b_p_bomb;
12697
Bram Moolenaar071d4272004-06-13 20:20:40 +000012698 /* Only use free/alloc when necessary, they take time. */
12699 if (buf->b_start_fenc == NULL
12700 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12701 {
12702 vim_free(buf->b_start_fenc);
12703 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12704 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012705}
12706
12707/*
12708 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12709 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012710 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12711 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012712 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012713 * When "ignore_empty" is true don't consider a new, empty buffer to be
12714 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012715 */
12716 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012717file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012718{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012719 /* In a buffer that was never loaded the options are not valid. */
12720 if (buf->b_flags & BF_NEVERLOADED)
12721 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012722 if (ignore_empty
12723 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012724 && buf->b_ml.ml_line_count == 1
12725 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12726 return FALSE;
12727 if (buf->b_start_ffc != *buf->b_p_ff)
12728 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012729 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012730 return TRUE;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012731 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12732 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012733 if (buf->b_start_fenc == NULL)
12734 return (*buf->b_p_fenc != NUL);
12735 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012736}
12737
12738/*
12739 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12740 */
12741 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012742check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012743{
12744 return check_opt_strings(p, p_ff_values, FALSE);
12745}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012746
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010012747#if defined(FEAT_VARTABS) || defined(PROTO)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012748
12749/*
12750 * Set the integer values corresponding to the string setting of 'vartabstop'.
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010012751 * "array" will be set, caller must free it if needed.
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012752 */
12753 int
12754tabstop_set(char_u *var, int **array)
12755{
12756 int valcount = 1;
12757 int t;
12758 char_u *cp;
12759
Bram Moolenaar64f41072018-10-15 22:51:50 +020012760 if (var[0] == NUL || (var[0] == '0' && var[1] == NUL))
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012761 {
12762 *array = NULL;
12763 return TRUE;
12764 }
12765
Bram Moolenaar64f41072018-10-15 22:51:50 +020012766 for (cp = var; *cp != NUL; ++cp)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012767 {
Bram Moolenaar64f41072018-10-15 22:51:50 +020012768 if (cp == var || cp[-1] == ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012769 {
12770 char_u *end;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012771
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012772 if (strtol((char *)cp, (char **)&end, 10) <= 0)
12773 {
12774 if (cp != end)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012775 emsg(_(e_positive));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012776 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012777 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012778 return FALSE;
12779 }
12780 }
12781
12782 if (VIM_ISDIGIT(*cp))
12783 continue;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012784 if (cp[0] == ',' && cp > var && cp[-1] != ',' && cp[1] != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012785 {
12786 ++valcount;
12787 continue;
12788 }
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012789 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012790 return FALSE;
12791 }
12792
Bram Moolenaar64f41072018-10-15 22:51:50 +020012793 *array = (int *)alloc((unsigned) ((valcount + 1) * sizeof(int)));
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010012794 if (*array == NULL)
12795 return FALSE;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012796 (*array)[0] = valcount;
12797
12798 t = 1;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012799 for (cp = var; *cp != NUL;)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012800 {
12801 (*array)[t++] = atoi((char *)cp);
Bram Moolenaar64f41072018-10-15 22:51:50 +020012802 while (*cp != NUL && *cp != ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012803 ++cp;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012804 if (*cp != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012805 ++cp;
12806 }
12807
12808 return TRUE;
12809}
12810
12811/*
12812 * Calculate the number of screen spaces a tab will occupy.
12813 * If "vts" is set then the tab widths are taken from that array,
12814 * otherwise the value of ts is used.
12815 */
12816 int
12817tabstop_padding(colnr_T col, int ts_arg, int *vts)
12818{
12819 int ts = ts_arg == 0 ? 8 : ts_arg;
12820 int tabcount;
12821 colnr_T tabcol = 0;
12822 int t;
12823 int padding = 0;
12824
12825 if (vts == NULL || vts[0] == 0)
12826 return ts - (col % ts);
12827
12828 tabcount = vts[0];
12829
12830 for (t = 1; t <= tabcount; ++t)
12831 {
12832 tabcol += vts[t];
12833 if (tabcol > col)
12834 {
12835 padding = (int)(tabcol - col);
12836 break;
12837 }
12838 }
12839 if (t > tabcount)
12840 padding = vts[tabcount] - (int)((col - tabcol) % vts[tabcount]);
12841
12842 return padding;
12843}
12844
12845/*
12846 * Find the size of the tab that covers a particular column.
12847 */
12848 int
12849tabstop_at(colnr_T col, int ts, int *vts)
12850{
12851 int tabcount;
12852 colnr_T tabcol = 0;
12853 int t;
12854 int tab_size = 0;
12855
12856 if (vts == 0 || vts[0] == 0)
12857 return ts;
12858
12859 tabcount = vts[0];
12860 for (t = 1; t <= tabcount; ++t)
12861 {
12862 tabcol += vts[t];
12863 if (tabcol > col)
12864 {
12865 tab_size = vts[t];
12866 break;
12867 }
12868 }
12869 if (t > tabcount)
12870 tab_size = vts[tabcount];
12871
12872 return tab_size;
12873}
12874
12875/*
12876 * Find the column on which a tab starts.
12877 */
12878 colnr_T
12879tabstop_start(colnr_T col, int ts, int *vts)
12880{
12881 int tabcount;
12882 colnr_T tabcol = 0;
12883 int t;
12884 int excess;
12885
Bram Moolenaar0119a592018-06-24 23:53:28 +020012886 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012887 return (col / ts) * ts;
12888
12889 tabcount = vts[0];
12890 for (t = 1; t <= tabcount; ++t)
12891 {
12892 tabcol += vts[t];
12893 if (tabcol > col)
12894 return tabcol - vts[t];
12895 }
12896
12897 excess = tabcol % vts[tabcount];
12898 return excess + ((col - excess) / vts[tabcount]) * vts[tabcount];
12899}
12900
12901/*
12902 * Find the number of tabs and spaces necessary to get from one column
12903 * to another.
12904 */
12905 void
12906tabstop_fromto(
12907 colnr_T start_col,
12908 colnr_T end_col,
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012909 int ts_arg,
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012910 int *vts,
12911 int *ntabs,
12912 int *nspcs)
12913{
12914 int spaces = end_col - start_col;
12915 colnr_T tabcol = 0;
12916 int padding = 0;
12917 int tabcount;
12918 int t;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012919 int ts = ts_arg == 0 ? curbuf->b_p_ts : ts_arg;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012920
Bram Moolenaar0119a592018-06-24 23:53:28 +020012921 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012922 {
12923 int tabs = 0;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012924 int initspc = 0;
Bram Moolenaar0119a592018-06-24 23:53:28 +020012925
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012926 initspc = ts - (start_col % ts);
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012927 if (spaces >= initspc)
12928 {
12929 spaces -= initspc;
12930 tabs++;
12931 }
12932 tabs += spaces / ts;
12933 spaces -= (spaces / ts) * ts;
12934
12935 *ntabs = tabs;
12936 *nspcs = spaces;
12937 return;
12938 }
12939
12940 /* Find the padding needed to reach the next tabstop. */
12941 tabcount = vts[0];
12942 for (t = 1; t <= tabcount; ++t)
12943 {
12944 tabcol += vts[t];
12945 if (tabcol > start_col)
12946 {
12947 padding = (int)(tabcol - start_col);
12948 break;
12949 }
12950 }
12951 if (t > tabcount)
12952 padding = vts[tabcount] - (int)((start_col - tabcol) % vts[tabcount]);
12953
12954 /* If the space needed is less than the padding no tabs can be used. */
12955 if (spaces < padding)
12956 {
12957 *ntabs = 0;
12958 *nspcs = spaces;
12959 return;
12960 }
12961
12962 *ntabs = 1;
12963 spaces -= padding;
12964
12965 /* At least one tab has been used. See if any more will fit. */
12966 while (spaces != 0 && ++t <= tabcount)
12967 {
12968 padding = vts[t];
12969 if (spaces < padding)
12970 {
12971 *nspcs = spaces;
12972 return;
12973 }
12974 ++*ntabs;
12975 spaces -= padding;
12976 }
12977
12978 *ntabs += spaces / vts[tabcount];
12979 *nspcs = spaces % vts[tabcount];
12980}
12981
12982/*
12983 * See if two tabstop arrays contain the same values.
12984 */
12985 int
12986tabstop_eq(int *ts1, int *ts2)
12987{
12988 int t;
12989
12990 if ((ts1 == 0 && ts2) || (ts1 && ts2 == 0))
12991 return FALSE;
12992 if (ts1 == ts2)
12993 return TRUE;
12994 if (ts1[0] != ts2[0])
12995 return FALSE;
12996
12997 for (t = 1; t <= ts1[0]; ++t)
12998 if (ts1[t] != ts2[t])
12999 return FALSE;
13000
13001 return TRUE;
13002}
13003
Bram Moolenaar113e1072019-01-20 15:30:40 +010013004#if defined(FEAT_BEVAL) || defined(PROTO)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013005/*
13006 * Copy a tabstop array, allocating space for the new array.
13007 */
13008 int *
13009tabstop_copy(int *oldts)
13010{
13011 int *newts;
13012 int t;
13013
Bram Moolenaar6ee96582019-04-27 22:06:37 +020013014 if (oldts == NULL)
13015 return NULL;
13016 newts = (int *)alloc((unsigned)((oldts[0] + 1) * sizeof(int)));
13017 if (newts != NULL)
13018 for (t = 0; t <= oldts[0]; ++t)
13019 newts[t] = oldts[t];
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013020 return newts;
13021}
Bram Moolenaar113e1072019-01-20 15:30:40 +010013022#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013023
13024/*
13025 * Return a count of the number of tabstops.
13026 */
13027 int
13028tabstop_count(int *ts)
13029{
13030 return ts != NULL ? ts[0] : 0;
13031}
13032
13033/*
13034 * Return the first tabstop, or 8 if there are no tabstops defined.
13035 */
13036 int
13037tabstop_first(int *ts)
13038{
13039 return ts != NULL ? ts[1] : 8;
13040}
13041
13042#endif
13043
Bram Moolenaar14f24742012-08-08 18:01:05 +020013044/*
13045 * Return the effective shiftwidth value for current buffer, using the
13046 * 'tabstop' value when 'shiftwidth' is zero.
13047 */
13048 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013049get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020013050{
Bram Moolenaarf9514162018-11-22 03:08:29 +010013051 return get_sw_value_col(buf, 0);
13052}
13053
13054/*
13055 * Idem, using the first non-black in the current line.
13056 */
13057 long
13058get_sw_value_indent(buf_T *buf)
13059{
13060 pos_T pos = curwin->w_cursor;
13061
13062 pos.col = getwhitecols_curline();
13063 return get_sw_value_pos(buf, &pos);
13064}
13065
13066/*
13067 * Idem, using "pos".
13068 */
13069 long
13070get_sw_value_pos(buf_T *buf, pos_T *pos)
13071{
13072 pos_T save_cursor = curwin->w_cursor;
13073 long sw_value;
13074
13075 curwin->w_cursor = *pos;
13076 sw_value = get_sw_value_col(buf, get_nolist_virtcol());
13077 curwin->w_cursor = save_cursor;
13078 return sw_value;
13079}
13080
13081/*
13082 * Idem, using virtual column "col".
13083 */
13084 long
13085get_sw_value_col(buf_T *buf, colnr_T col UNUSED)
13086{
13087 return buf->b_p_sw ? buf->b_p_sw :
13088 #ifdef FEAT_VARTABS
13089 tabstop_at(col, buf->b_p_ts, buf->b_p_vts_array);
13090 #else
13091 buf->b_p_ts;
13092 #endif
Bram Moolenaar14f24742012-08-08 18:01:05 +020013093}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013094
13095/*
13096 * Return the effective softtabstop value for the current buffer, using the
Bram Moolenaar33d5ab32018-07-02 20:51:24 +020013097 * 'shiftwidth' value when 'softtabstop' is negative.
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013098 */
13099 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013100get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013101{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010013102 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013103}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013104
13105/*
Bram Moolenaar375e3392019-01-31 18:26:10 +010013106 * Return the effective 'scrolloff' value for the current window, using the
13107 * global value when appropriate.
13108 */
13109 long
13110get_scrolloff_value(void)
13111{
13112 return curwin->w_p_so < 0 ? p_so : curwin->w_p_so;
13113}
13114
13115/*
13116 * Return the effective 'sidescrolloff' value for the current window, using the
13117 * global value when appropriate.
13118 */
13119 long
13120get_sidescrolloff_value(void)
13121{
13122 return curwin->w_p_siso < 0 ? p_siso : curwin->w_p_siso;
13123}
13124
13125/*
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013126 * Check matchpairs option for "*initc".
13127 * If there is a match set "*initc" to the matching character and "*findc" to
13128 * the opposite character. Set "*backwards" to the direction.
13129 * When "switchit" is TRUE swap the direction.
13130 */
13131 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010013132find_mps_values(
13133 int *initc,
13134 int *findc,
13135 int *backwards,
13136 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013137{
13138 char_u *ptr;
13139
13140 ptr = curbuf->b_p_mps;
13141 while (*ptr != NUL)
13142 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013143 if (has_mbyte)
13144 {
13145 char_u *prev;
13146
13147 if (mb_ptr2char(ptr) == *initc)
13148 {
13149 if (switchit)
13150 {
13151 *findc = *initc;
13152 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13153 *backwards = TRUE;
13154 }
13155 else
13156 {
13157 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13158 *backwards = FALSE;
13159 }
13160 return;
13161 }
13162 prev = ptr;
13163 ptr += mb_ptr2len(ptr) + 1;
13164 if (mb_ptr2char(ptr) == *initc)
13165 {
13166 if (switchit)
13167 {
13168 *findc = *initc;
13169 *initc = mb_ptr2char(prev);
13170 *backwards = FALSE;
13171 }
13172 else
13173 {
13174 *findc = mb_ptr2char(prev);
13175 *backwards = TRUE;
13176 }
13177 return;
13178 }
13179 ptr += mb_ptr2len(ptr);
13180 }
13181 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013182 {
13183 if (*ptr == *initc)
13184 {
13185 if (switchit)
13186 {
13187 *backwards = TRUE;
13188 *findc = *initc;
13189 *initc = ptr[2];
13190 }
13191 else
13192 {
13193 *backwards = FALSE;
13194 *findc = ptr[2];
13195 }
13196 return;
13197 }
13198 ptr += 2;
13199 if (*ptr == *initc)
13200 {
13201 if (switchit)
13202 {
13203 *backwards = FALSE;
13204 *findc = *initc;
13205 *initc = ptr[-2];
13206 }
13207 else
13208 {
13209 *backwards = TRUE;
13210 *findc = ptr[-2];
13211 }
13212 return;
13213 }
13214 ++ptr;
13215 }
13216 if (*ptr == ',')
13217 ++ptr;
13218 }
13219}
Bram Moolenaar597a4222014-06-25 14:39:50 +020013220
13221#if defined(FEAT_LINEBREAK) || defined(PROTO)
13222/*
13223 * This is called when 'breakindentopt' is changed and when a window is
13224 * initialized.
13225 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013226 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013227briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020013228{
13229 char_u *p;
13230 int bri_shift = 0;
13231 long bri_min = 20;
13232 int bri_sbr = FALSE;
13233
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013234 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013235 while (*p != NUL)
13236 {
13237 if (STRNCMP(p, "shift:", 6) == 0
13238 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
13239 {
13240 p += 6;
13241 bri_shift = getdigits(&p);
13242 }
13243 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
13244 {
13245 p += 4;
13246 bri_min = getdigits(&p);
13247 }
13248 else if (STRNCMP(p, "sbr", 3) == 0)
13249 {
13250 p += 3;
13251 bri_sbr = TRUE;
13252 }
13253 if (*p != ',' && *p != NUL)
13254 return FAIL;
13255 if (*p == ',')
13256 ++p;
13257 }
13258
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013259 wp->w_p_brishift = bri_shift;
13260 wp->w_p_brimin = bri_min;
13261 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013262
13263 return OK;
13264}
13265#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013266
13267/*
13268 * Get the local or global value of 'backupcopy'.
13269 */
13270 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013271get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013272{
13273 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
13274}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020013275
13276#if defined(FEAT_SIGNS) || defined(PROTO)
13277/*
13278 * Return TRUE when window "wp" has a column to draw signs in.
13279 */
13280 int
13281signcolumn_on(win_T *wp)
13282{
13283 if (*wp->w_p_scl == 'n')
13284 return FALSE;
13285 if (*wp->w_p_scl == 'y')
13286 return TRUE;
13287 return (wp->w_buffer->b_signlist != NULL
13288# ifdef FEAT_NETBEANS_INTG
13289 || wp->w_buffer->b_has_sign_column
13290# endif
13291 );
13292}
13293#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013294
13295#if defined(FEAT_EVAL) || defined(PROTO)
13296/*
13297 * Get window or buffer local options.
13298 */
13299 dict_T *
13300get_winbuf_options(int bufopt)
13301{
13302 dict_T *d;
13303 int opt_idx;
13304
13305 d = dict_alloc();
13306 if (d == NULL)
13307 return NULL;
13308
13309 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
13310 {
13311 struct vimoption *opt = &options[opt_idx];
13312
13313 if ((bufopt && (opt->indir & PV_BUF))
13314 || (!bufopt && (opt->indir & PV_WIN)))
13315 {
13316 char_u *varp = get_varp(opt);
13317
13318 if (varp != NULL)
13319 {
13320 if (opt->flags & P_STRING)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013321 dict_add_string(d, opt->fullname, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020013322 else if (opt->flags & P_NUM)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013323 dict_add_number(d, opt->fullname, *(long *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013324 else
Bram Moolenaare0be1672018-07-08 16:50:37 +020013325 dict_add_number(d, opt->fullname, *(int *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013326 }
13327 }
13328 }
13329
13330 return d;
13331}
13332#endif