blob: 2d22c4c9735633efc95e86b0a02602ce53162c2d [file] [log] [blame]
Bram Moolenaaredf3f972016-08-29 22:49:24 +02001/* vi:set ts=8 sts=4 sw=4 noet:
Bram Moolenaar071d4272004-06-13 20:20:40 +00002 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * Code to handle user-settable options. This is all pretty much table-
12 * driven. Checklist for adding a new option:
13 * - Put it in the options array below (copy an existing entry).
14 * - For a global option: Add a variable for it in option.h.
15 * - For a buffer or window local option:
16 * - Add a PV_XX entry to the enum below.
17 * - Add a variable to the window or buffer struct in structs.h.
18 * - For a window option, add some code to copy_winopt().
19 * - For a buffer option, add some code to buf_copy_options().
20 * - For a buffer string option, add code to check_buf_options().
21 * - If it's a numeric option, add any necessary bounds checks to do_set().
22 * - If it's a list of flags, add some code in do_set(), search for WW_ALL.
23 * - When adding an option with expansion (P_EXPAND), but with a different
24 * default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP.
Bram Moolenaarcea912a2016-10-12 14:20:24 +020025 * - Add documentation! One line in doc/quickref.txt, full description in
Bram Moolenaar071d4272004-06-13 20:20:40 +000026 * options.txt, and any other related places.
27 * - Add an entry in runtime/optwin.vim.
28 * When making changes:
29 * - Adjust the help for the option in doc/option.txt.
30 * - When an entry has the P_VIM flag, or is lacking the P_VI_DEF flag, add a
31 * comment at the help for the 'compatible' option.
32 */
33
34#define IN_OPTION_C
35#include "vim.h"
36
37/*
38 * The options that are local to a window or buffer have "indir" set to one of
39 * these values. Special values:
40 * PV_NONE: global option.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000041 * PV_WIN is added: window-local option
42 * PV_BUF is added: buffer-local option
Bram Moolenaar071d4272004-06-13 20:20:40 +000043 * PV_BOTH is added: global option which also has a local value.
44 */
45#define PV_BOTH 0x1000
Bram Moolenaara23ccb82006-02-27 00:08:02 +000046#define PV_WIN 0x2000
47#define PV_BUF 0x4000
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000048#define PV_MASK 0x0fff
Bram Moolenaara23ccb82006-02-27 00:08:02 +000049#define OPT_WIN(x) (idopt_T)(PV_WIN + (int)(x))
50#define OPT_BUF(x) (idopt_T)(PV_BUF + (int)(x))
Bram Moolenaar071d4272004-06-13 20:20:40 +000051#define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
52
Bram Moolenaara23ccb82006-02-27 00:08:02 +000053/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000054 * Definition of the PV_ values for buffer-local options.
55 * The BV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000056 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +000057#define PV_AI OPT_BUF(BV_AI)
58#define PV_AR OPT_BOTH(OPT_BUF(BV_AR))
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020059#define PV_BKC OPT_BOTH(OPT_BUF(BV_BKC))
Bram Moolenaar81bdd6a2017-07-23 22:57:00 +020060#define PV_BH OPT_BUF(BV_BH)
61#define PV_BT OPT_BUF(BV_BT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000062#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000063# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
64# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
65# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000066#endif
67#define PV_BIN OPT_BUF(BV_BIN)
68#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaarfc3abf42019-01-24 15:54:21 +010069#define PV_BOMB OPT_BUF(BV_BOMB)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000070#define PV_CI OPT_BUF(BV_CI)
71#ifdef FEAT_CINDENT
72# define PV_CIN OPT_BUF(BV_CIN)
73# define PV_CINK OPT_BUF(BV_CINK)
74# define PV_CINO OPT_BUF(BV_CINO)
75#endif
76#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
77# define PV_CINW OPT_BUF(BV_CINW)
78#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020079#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000080#ifdef FEAT_FOLDING
81# define PV_CMS OPT_BUF(BV_CMS)
82#endif
83#ifdef FEAT_COMMENTS
84# define PV_COM OPT_BUF(BV_COM)
85#endif
86#ifdef FEAT_INS_EXPAND
87# define PV_CPT OPT_BUF(BV_CPT)
88# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
89# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
90#endif
91#ifdef FEAT_COMPL_FUNC
92# define PV_CFU OPT_BUF(BV_CFU)
93#endif
94#ifdef FEAT_FIND_ID
95# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
96# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
97#endif
98#define PV_EOL OPT_BUF(BV_EOL)
Bram Moolenaar34d72d42015-07-17 14:18:08 +020099#define PV_FIXEOL OPT_BUF(BV_FIXEOL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000100#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
101#define PV_ET OPT_BUF(BV_ET)
Bram Moolenaarfc3abf42019-01-24 15:54:21 +0100102#define PV_FENC OPT_BUF(BV_FENC)
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000103#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
104# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
105#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100106#define PV_FP OPT_BOTH(OPT_BUF(BV_FP))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000107#ifdef FEAT_EVAL
108# define PV_FEX OPT_BUF(BV_FEX)
109#endif
110#define PV_FF OPT_BUF(BV_FF)
111#define PV_FLP OPT_BUF(BV_FLP)
112#define PV_FO OPT_BUF(BV_FO)
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +0100113#define PV_FT OPT_BUF(BV_FT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000114#define PV_IMI OPT_BUF(BV_IMI)
115#define PV_IMS OPT_BUF(BV_IMS)
116#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
117# define PV_INDE OPT_BUF(BV_INDE)
118# define PV_INDK OPT_BUF(BV_INDK)
119#endif
120#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
121# define PV_INEX OPT_BUF(BV_INEX)
122#endif
123#define PV_INF OPT_BUF(BV_INF)
124#define PV_ISK OPT_BUF(BV_ISK)
125#ifdef FEAT_CRYPT
126# define PV_KEY OPT_BUF(BV_KEY)
127#endif
128#ifdef FEAT_KEYMAP
129# define PV_KMAP OPT_BUF(BV_KMAP)
130#endif
131#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
132#ifdef FEAT_LISP
133# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100134# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000135#endif
Bram Moolenaarfc3abf42019-01-24 15:54:21 +0100136#define PV_MENC OPT_BOTH(OPT_BUF(BV_MENC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000137#define PV_MA OPT_BUF(BV_MA)
138#define PV_ML OPT_BUF(BV_ML)
139#define PV_MOD OPT_BUF(BV_MOD)
140#define PV_MPS OPT_BUF(BV_MPS)
141#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000142#ifdef FEAT_COMPL_FUNC
143# define PV_OFU OPT_BUF(BV_OFU)
144#endif
145#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
146#define PV_PI OPT_BUF(BV_PI)
147#ifdef FEAT_TEXTOBJ
148# define PV_QE OPT_BUF(BV_QE)
149#endif
150#define PV_RO OPT_BUF(BV_RO)
151#ifdef FEAT_SMARTINDENT
152# define PV_SI OPT_BUF(BV_SI)
153#endif
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100154#define PV_SN OPT_BUF(BV_SN)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000155#ifdef FEAT_SYN_HL
156# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000157# define PV_SYN OPT_BUF(BV_SYN)
158#endif
159#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000160# define PV_SPC OPT_BUF(BV_SPC)
161# define PV_SPF OPT_BUF(BV_SPF)
162# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000163#endif
164#define PV_STS OPT_BUF(BV_STS)
165#ifdef FEAT_SEARCHPATH
166# define PV_SUA OPT_BUF(BV_SUA)
167#endif
168#define PV_SW OPT_BUF(BV_SW)
169#define PV_SWF OPT_BUF(BV_SWF)
Bram Moolenaar45e18cb2019-04-28 18:05:35 +0200170#ifdef FEAT_EVAL
171# define PV_TFU OPT_BUF(BV_TFU)
172#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000173#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
Bram Moolenaar0f6562e2015-11-24 18:48:14 +0100174#define PV_TC OPT_BOTH(OPT_BUF(BV_TC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000175#define PV_TS OPT_BUF(BV_TS)
176#define PV_TW OPT_BUF(BV_TW)
177#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200178#ifdef FEAT_PERSISTENT_UNDO
179# define PV_UDF OPT_BUF(BV_UDF)
180#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000181#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200182#ifdef FEAT_VARTABS
183# define PV_VSTS OPT_BUF(BV_VSTS)
184# define PV_VTS OPT_BUF(BV_VTS)
185#endif
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000186
187/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000188 * Definition of the PV_ values for window-local options.
189 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000190 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000191#define PV_LIST OPT_WIN(WV_LIST)
192#ifdef FEAT_ARABIC
193# define PV_ARAB OPT_WIN(WV_ARAB)
194#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200195#ifdef FEAT_LINEBREAK
196# define PV_BRI OPT_WIN(WV_BRI)
197# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
198#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200199# define PV_WCR OPT_WIN(WV_WCR)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000200#ifdef FEAT_DIFF
201# define PV_DIFF OPT_WIN(WV_DIFF)
202#endif
203#ifdef FEAT_FOLDING
204# define PV_FDC OPT_WIN(WV_FDC)
205# define PV_FEN OPT_WIN(WV_FEN)
206# define PV_FDI OPT_WIN(WV_FDI)
207# define PV_FDL OPT_WIN(WV_FDL)
208# define PV_FDM OPT_WIN(WV_FDM)
209# define PV_FML OPT_WIN(WV_FML)
210# define PV_FDN OPT_WIN(WV_FDN)
211# ifdef FEAT_EVAL
212# define PV_FDE OPT_WIN(WV_FDE)
213# define PV_FDT OPT_WIN(WV_FDT)
214# endif
215# define PV_FMR OPT_WIN(WV_FMR)
216#endif
217#ifdef FEAT_LINEBREAK
218# define PV_LBR OPT_WIN(WV_LBR)
219#endif
220#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200221#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000222#ifdef FEAT_LINEBREAK
223# define PV_NUW OPT_WIN(WV_NUW)
224#endif
Bram Moolenaar4033c552017-09-16 20:54:51 +0200225#if defined(FEAT_QUICKFIX)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000226# define PV_PVW OPT_WIN(WV_PVW)
227#endif
228#ifdef FEAT_RIGHTLEFT
229# define PV_RL OPT_WIN(WV_RL)
230# define PV_RLC OPT_WIN(WV_RLC)
231#endif
Bram Moolenaar8a3bb562018-03-04 20:14:14 +0100232#define PV_SCBIND OPT_WIN(WV_SCBIND)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000233#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaar375e3392019-01-31 18:26:10 +0100234#define PV_SISO OPT_BOTH(OPT_WIN(WV_SISO))
235#define PV_SO OPT_BOTH(OPT_WIN(WV_SO))
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000236#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000237# define PV_SPELL OPT_WIN(WV_SPELL)
238#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000239#ifdef FEAT_SYN_HL
240# define PV_CUC OPT_WIN(WV_CUC)
241# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200242# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000243#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000244#ifdef FEAT_STL_OPT
245# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
246#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100247#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000248# define PV_WFH OPT_WIN(WV_WFH)
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000249# define PV_WFW OPT_WIN(WV_WFW)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000250#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar8a3bb562018-03-04 20:14:14 +0100251#define PV_CRBIND OPT_WIN(WV_CRBIND)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200252#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200253# define PV_COCU OPT_WIN(WV_COCU)
254# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200255#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200256#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200257# define PV_TWK OPT_WIN(WV_TWK)
258# define PV_TWS OPT_WIN(WV_TWS)
259# define PV_TWSL OPT_BUF(BV_TWSL)
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200260#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200261#ifdef FEAT_SIGNS
262# define PV_SCL OPT_WIN(WV_SCL)
263#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000264
265/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000266typedef enum
267{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000268 PV_NONE = 0,
269 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000270} idopt_T;
271
272/*
273 * Options local to a window have a value local to a buffer and global to all
274 * buffers. Indicate this by setting "var" to VAR_WIN.
275 */
276#define VAR_WIN ((char_u *)-1)
277
278/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000279 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000280 * Only to be used in option.c!
281 */
282static int p_ai;
283static int p_bin;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000284static int p_bomb;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000285static char_u *p_bh;
286static char_u *p_bt;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000287static int p_bl;
288static int p_ci;
289#ifdef FEAT_CINDENT
290static int p_cin;
291static char_u *p_cink;
292static char_u *p_cino;
293#endif
294#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
295static char_u *p_cinw;
296#endif
297#ifdef FEAT_COMMENTS
298static char_u *p_com;
299#endif
300#ifdef FEAT_FOLDING
301static char_u *p_cms;
302#endif
303#ifdef FEAT_INS_EXPAND
304static char_u *p_cpt;
305#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000306#ifdef FEAT_COMPL_FUNC
307static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000308static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000309#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +0200310#ifdef FEAT_EVAL
311static char_u *p_tfu;
312#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000313static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200314static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000315static int p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000316static char_u *p_fenc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000317static char_u *p_ff;
318static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000319static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000320static char_u *p_ft;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000321static long p_iminsert;
322static long p_imsearch;
323#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
324static char_u *p_inex;
325#endif
326#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
327static char_u *p_inde;
328static char_u *p_indk;
329#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000330#if defined(FEAT_EVAL)
331static char_u *p_fex;
332#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000333static int p_inf;
334static char_u *p_isk;
335#ifdef FEAT_CRYPT
336static char_u *p_key;
337#endif
338#ifdef FEAT_LISP
339static int p_lisp;
340#endif
341static int p_ml;
342static int p_ma;
343static int p_mod;
344static char_u *p_mps;
345static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000346static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000347#ifdef FEAT_TEXTOBJ
348static char_u *p_qe;
349#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000350static int p_ro;
351#ifdef FEAT_SMARTINDENT
352static int p_si;
353#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000354static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000355static long p_sts;
356#if defined(FEAT_SEARCHPATH)
357static char_u *p_sua;
358#endif
359static long p_sw;
360static int p_swf;
361#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000362static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000363static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000364#endif
365#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000366static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000367static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000368static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000369#endif
370static long p_ts;
371static long p_tw;
372static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200373#ifdef FEAT_PERSISTENT_UNDO
374static int p_udf;
375#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000376static long p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200377#ifdef FEAT_VARTABS
378static char_u *p_vsts;
379static char_u *p_vts;
380#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000381#ifdef FEAT_KEYMAP
382static char_u *p_keymap;
383#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200384#ifdef FEAT_TERMINAL
Bram Moolenaarb833c1e2018-05-05 16:36:06 +0200385static long p_twsl; /* 'termwinscroll' */
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200386#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000387
388/* Saved values for when 'bin' is set. */
389static int p_et_nobin;
390static int p_ml_nobin;
391static long p_tw_nobin;
392static long p_wm_nobin;
393
394/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200395static int p_ai_nopaste;
396static int p_et_nopaste;
397static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000398static long p_tw_nopaste;
399static long p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200400#ifdef FEAT_VARTABS
401static char_u *p_vsts_nopaste;
402#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000403
404struct vimoption
405{
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200406 char *fullname; // full option name
407 char *shortname; // permissible abbreviation
408 long_u flags; // see below
409 char_u *var; // global option: pointer to variable;
410 // window-local option: VAR_WIN;
411 // buffer-local option: global value
412 idopt_T indir; // global option: PV_NONE;
413 // local option: indirect option index
414 char_u *def_val[2]; // default values for variable (vi and vim)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000415#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200416 sctx_T script_ctx; // script context where the option was last set
Bram Moolenaar558ca4a2019-04-04 18:15:38 +0200417# define SCTX_INIT , {0, 0, 0, 1}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000418#else
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200419# define SCTX_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000420#endif
421};
422
423#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
424#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
425
426/*
427 * Flags
428 */
429#define P_BOOL 0x01 /* the option is boolean */
430#define P_NUM 0x02 /* the option is numeric */
431#define P_STRING 0x04 /* the option is a string */
432#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000433 must use free_string_option() when
434 assigning new value. Not set if default is
435 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000436#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
437 never be used for local or hidden options! */
438#define P_NODEFAULT 0x40 /* don't set to default value */
439#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
440 use vim_free() when assigning new value */
441#define P_WAS_SET 0x100 /* option has been set/reset */
442#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
443#define P_VI_DEF 0x400 /* Use Vi default for Vim */
444#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
445
446 /* when option changed, what to display: */
447#define P_RSTAT 0x1000 /* redraw status lines */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100448#define P_RWIN 0x2000 /* redraw current window and recompute text */
449#define P_RBUF 0x4000 /* redraw current buffer and recompute text */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000450#define P_RALL 0x6000 /* redraw all windows */
451#define P_RCLR 0x7000 /* clear and redraw all */
452
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200453#define P_COMMA 0x8000 /* comma separated list */
454#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
455 * commas */
456#define P_NODUP 0x20000L /* don't allow duplicate strings */
457#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000458
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200459#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
460#define P_GETTEXT 0x100000L /* expand default value with _() */
461#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
462#define P_NFNAME 0x400000L /* only normal file name chars allowed */
463#define P_INSECURE 0x800000L /* option was set from a modeline */
464#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7554da42016-11-25 22:04:13 +0100465 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200466#define P_NO_ML 0x2000000L /* not allowed in modeline */
467#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200468 * there is a redraw flag */
Bram Moolenaar7554da42016-11-25 22:04:13 +0100469#define P_NDNAME 0x8000000L /* only normal dir name chars allowed */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100470#define P_RWINONLY 0x10000000L /* only redraw current window */
Bram Moolenaar110289e2019-05-23 15:38:06 +0200471#define P_MLE 0x20000000L /* under control of 'modelineexpr' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000472
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000473#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
474
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000475/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
476 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100477#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000478# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000479#else
480# define ISP_LATIN1 (char_u *)"@,161-255"
481#endif
482
Bram Moolenaar05fbfdc2017-08-14 22:35:08 +0200483# define HIGHLIGHT_INIT "8:SpecialKey,~:EndOfBuffer,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn,q:QuickFixLine,z:StatusLineTerm,Z:StatusLineTermNC"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000484
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +0100485/* Default python version for pyx* commands */
486#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
487# define DEFAULT_PYTHON_VER 0
488#elif defined(FEAT_PYTHON3)
489# define DEFAULT_PYTHON_VER 3
490#elif defined(FEAT_PYTHON)
491# define DEFAULT_PYTHON_VER 2
492#else
493# define DEFAULT_PYTHON_VER 0
494#endif
495
Bram Moolenaarce655742019-01-31 14:12:57 +0100496// used for 'cinkeys' and 'indentkeys'
497#define INDENTKEYS_DEFAULT (char_u *)"0{,0},0),0],:,0#,!^F,o,O,e"
498
Bram Moolenaar071d4272004-06-13 20:20:40 +0000499/*
500 * options[] is initialized here.
501 * The order of the options MUST be alphabetic for ":set all" and findoption().
502 * All option names MUST start with a lowercase letter (for findoption()).
503 * Exception: "t_" options are at the end.
504 * The options with a NULL variable are 'hidden': a set command for them is
505 * ignored and they are not printed.
506 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100507static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000508{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200509 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000510#ifdef FEAT_RIGHTLEFT
511 (char_u *)&p_aleph, PV_NONE,
512#else
513 (char_u *)NULL, PV_NONE,
514#endif
515 {
Bram Moolenaar4f974752019-02-17 17:44:42 +0100516#if defined(MSWIN) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000517 (char_u *)128L,
518#else
519 (char_u *)224L,
520#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200521 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000522 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
Bram Moolenaard0573012017-10-28 21:11:06 +0200523#if defined(FEAT_GUI_MAC)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000524 (char_u *)&p_antialias, PV_NONE,
525 {(char_u *)FALSE, (char_u *)FALSE}
526#else
527 (char_u *)NULL, PV_NONE,
528 {(char_u *)FALSE, (char_u *)FALSE}
529#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200530 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200531 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000532#ifdef FEAT_ARABIC
533 (char_u *)VAR_WIN, PV_ARAB,
534#else
535 (char_u *)NULL, PV_NONE,
536#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200537 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000538 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
539#ifdef FEAT_ARABIC
540 (char_u *)&p_arshape, PV_NONE,
541#else
542 (char_u *)NULL, PV_NONE,
543#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200544 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000545 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
546#ifdef FEAT_RIGHTLEFT
547 (char_u *)&p_ari, PV_NONE,
548#else
549 (char_u *)NULL, PV_NONE,
550#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200551 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000552 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000553 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200554 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000555 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000556 (char_u *)&p_ambw, PV_NONE,
557 {(char_u *)"single", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200558 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000559 {"autochdir", "acd", P_BOOL|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100560#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000561 (char_u *)&p_acd, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100562 {(char_u *)FALSE, (char_u *)0L}
563#else
564 (char_u *)NULL, PV_NONE,
565 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000566#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200567 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000568 {"autoindent", "ai", P_BOOL|P_VI_DEF,
569 (char_u *)&p_ai, PV_AI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200570 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000571 {"autoprint", "ap", P_BOOL|P_VI_DEF,
572 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200573 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000574 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000575 (char_u *)&p_ar, PV_AR,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200576 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000577 {"autowrite", "aw", P_BOOL|P_VI_DEF,
578 (char_u *)&p_aw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200579 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000580 {"autowriteall","awa", P_BOOL|P_VI_DEF,
581 (char_u *)&p_awa, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200582 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000583 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
584 (char_u *)&p_bg, PV_NONE,
585 {
Bram Moolenaar4f974752019-02-17 17:44:42 +0100586#if (defined(MSWIN)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000587 (char_u *)"dark",
588#else
589 (char_u *)"light",
590#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200591 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200592 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000593 (char_u *)&p_bs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200594 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000595 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
596 (char_u *)&p_bk, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200597 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200598 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200599 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000600#ifdef UNIX
601 {(char_u *)"yes", (char_u *)"auto"}
602#else
603 {(char_u *)"auto", (char_u *)"auto"}
604#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200605 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200606 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
607 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000608 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200609 {(char_u *)DFLT_BDIR, (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000610 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000611 (char_u *)&p_bex, PV_NONE,
612 {
613#ifdef VMS
614 (char_u *)"_",
615#else
616 (char_u *)"~",
617#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200618 (char_u *)0L} SCTX_INIT},
Bram Moolenaar06e2c812019-06-12 19:05:48 +0200619 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000620#ifdef FEAT_WILDIGN
621 (char_u *)&p_bsk, PV_NONE,
622 {(char_u *)"", (char_u *)0L}
623#else
624 (char_u *)NULL, PV_NONE,
625 {(char_u *)0L, (char_u *)0L}
626#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200627 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000628 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100629#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000630 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100631 {(char_u *)600L, (char_u *)0L}
632#else
633 (char_u *)NULL, PV_NONE,
634 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000635#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200636 SCTX_INIT},
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100637 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100638#ifdef FEAT_BEVAL_GUI
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100639 (char_u *)&p_beval, PV_NONE,
640 {(char_u *)FALSE, (char_u *)0L}
641#else
642 (char_u *)NULL, PV_NONE,
643 {(char_u *)0L, (char_u *)0L}
644#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200645 SCTX_INIT},
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100646 {"balloonevalterm", "bevalterm",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100647#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100648 (char_u *)&p_bevalterm, PV_NONE,
649 {(char_u *)FALSE, (char_u *)0L}
650#else
651 (char_u *)NULL, PV_NONE,
652 {(char_u *)0L, (char_u *)0L}
653#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200654 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +0200655 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM|P_MLE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100656#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
657 (char_u *)&p_bexpr, PV_BEXPR,
658 {(char_u *)"", (char_u *)0L}
659#else
660 (char_u *)NULL, PV_NONE,
661 {(char_u *)0L, (char_u *)0L}
662#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200663 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000664 {"beautify", "bf", P_BOOL|P_VI_DEF,
665 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200666 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200667 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
668 (char_u *)&p_bo, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200669 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000670 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
671 (char_u *)&p_bin, PV_BIN,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200672 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000673 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000674 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200675 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000676 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000677 (char_u *)&p_bomb, PV_BOMB,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200678 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000679 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
680#ifdef FEAT_LINEBREAK
681 (char_u *)&p_breakat, PV_NONE,
682 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
683#else
684 (char_u *)NULL, PV_NONE,
685 {(char_u *)0L, (char_u *)0L}
686#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200687 SCTX_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200688 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
689#ifdef FEAT_LINEBREAK
690 (char_u *)VAR_WIN, PV_BRI,
691 {(char_u *)FALSE, (char_u *)0L}
692#else
693 (char_u *)NULL, PV_NONE,
694 {(char_u *)0L, (char_u *)0L}
695#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200696 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200697 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
698 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200699#ifdef FEAT_LINEBREAK
700 (char_u *)VAR_WIN, PV_BRIOPT,
701 {(char_u *)"", (char_u *)NULL}
702#else
703 (char_u *)NULL, PV_NONE,
704 {(char_u *)"", (char_u *)NULL}
705#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200706 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000707 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
708#ifdef FEAT_BROWSE
709 (char_u *)&p_bsdir, PV_NONE,
710 {(char_u *)"last", (char_u *)0L}
711#else
712 (char_u *)NULL, PV_NONE,
713 {(char_u *)0L, (char_u *)0L}
714#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200715 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000716 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000717 (char_u *)&p_bh, PV_BH,
718 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200719 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000720 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
721 (char_u *)&p_bl, PV_BL,
722 {(char_u *)1L, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200723 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000724 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000725 (char_u *)&p_bt, PV_BT,
726 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200727 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200728 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000729 (char_u *)&p_cmp, PV_NONE,
730 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200731 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +0200732 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE|P_COMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000733#ifdef FEAT_SEARCHPATH
734 (char_u *)&p_cdpath, PV_NONE,
735 {(char_u *)",,", (char_u *)0L}
736#else
737 (char_u *)NULL, PV_NONE,
738 {(char_u *)0L, (char_u *)0L}
739#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200740 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000741 {"cedit", NULL, P_STRING,
742#ifdef FEAT_CMDWIN
743 (char_u *)&p_cedit, PV_NONE,
744 {(char_u *)"", (char_u *)CTRL_F_STR}
745#else
746 (char_u *)NULL, PV_NONE,
747 {(char_u *)0L, (char_u *)0L}
748#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200749 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000750 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +0100751#if defined(FEAT_EVAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000752 (char_u *)&p_ccv, PV_NONE,
753 {(char_u *)"", (char_u *)0L}
754#else
755 (char_u *)NULL, PV_NONE,
756 {(char_u *)0L, (char_u *)0L}
757#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200758 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000759 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
760#ifdef FEAT_CINDENT
761 (char_u *)&p_cin, PV_CIN,
762#else
763 (char_u *)NULL, PV_NONE,
764#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200765 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200766 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000767#ifdef FEAT_CINDENT
768 (char_u *)&p_cink, PV_CINK,
Bram Moolenaarce655742019-01-31 14:12:57 +0100769 {INDENTKEYS_DEFAULT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000770#else
771 (char_u *)NULL, PV_NONE,
772 {(char_u *)0L, (char_u *)0L}
773#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200774 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200775 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000776#ifdef FEAT_CINDENT
777 (char_u *)&p_cino, PV_CINO,
778#else
779 (char_u *)NULL, PV_NONE,
780#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200781 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200782 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000783#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
784 (char_u *)&p_cinw, PV_CINW,
785 {(char_u *)"if,else,while,do,for,switch",
786 (char_u *)0L}
787#else
788 (char_u *)NULL, PV_NONE,
789 {(char_u *)0L, (char_u *)0L}
790#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200791 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200792 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000793#ifdef FEAT_CLIPBOARD
794 (char_u *)&p_cb, PV_NONE,
795# ifdef FEAT_XCLIPBOARD
796 {(char_u *)"autoselect,exclude:cons\\|linux",
797 (char_u *)0L}
798# else
799 {(char_u *)"", (char_u *)0L}
800# endif
801#else
802 (char_u *)NULL, PV_NONE,
803 {(char_u *)"", (char_u *)0L}
804#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200805 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000806 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
807 (char_u *)&p_ch, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200808 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000809 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
810#ifdef FEAT_CMDWIN
811 (char_u *)&p_cwh, PV_NONE,
812#else
813 (char_u *)NULL, PV_NONE,
814#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200815 {(char_u *)7L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200816 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200817#ifdef FEAT_SYN_HL
818 (char_u *)VAR_WIN, PV_CC,
819#else
820 (char_u *)NULL, PV_NONE,
821#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200822 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000823 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
824 (char_u *)&Columns, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200825 {(char_u *)80L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200826 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
827 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000828#ifdef FEAT_COMMENTS
829 (char_u *)&p_com, PV_COM,
830 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
831 (char_u *)0L}
832#else
833 (char_u *)NULL, PV_NONE,
834 {(char_u *)0L, (char_u *)0L}
835#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200836 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200837 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000838#ifdef FEAT_FOLDING
839 (char_u *)&p_cms, PV_CMS,
840 {(char_u *)"/*%s*/", (char_u *)0L}
841#else
842 (char_u *)NULL, PV_NONE,
843 {(char_u *)0L, (char_u *)0L}
844#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200845 SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000846 /* P_PRI_MKRC isn't needed here, optval_default()
847 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000848 {"compatible", "cp", P_BOOL|P_RALL,
849 (char_u *)&p_cp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200850 {(char_u *)TRUE, (char_u *)FALSE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200851 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000852#ifdef FEAT_INS_EXPAND
853 (char_u *)&p_cpt, PV_CPT,
854 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
855#else
856 (char_u *)NULL, PV_NONE,
857 {(char_u *)0L, (char_u *)0L}
858#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200859 SCTX_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200860 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200861#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200862 (char_u *)VAR_WIN, PV_COCU,
863 {(char_u *)"", (char_u *)NULL}
864#else
865 (char_u *)NULL, PV_NONE,
866 {(char_u *)NULL, (char_u *)0L}
867#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200868 SCTX_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200869 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
870#ifdef FEAT_CONCEAL
871 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200872#else
873 (char_u *)NULL, PV_NONE,
874#endif
875 {(char_u *)0L, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200876 SCTX_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000877 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
878#ifdef FEAT_COMPL_FUNC
879 (char_u *)&p_cfu, PV_CFU,
880 {(char_u *)"", (char_u *)0L}
881#else
882 (char_u *)NULL, PV_NONE,
883 {(char_u *)0L, (char_u *)0L}
884#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200885 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200886 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000887#ifdef FEAT_INS_EXPAND
888 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000889 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000890#else
891 (char_u *)NULL, PV_NONE,
892 {(char_u *)0L, (char_u *)0L}
893#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200894 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000895 {"confirm", "cf", P_BOOL|P_VI_DEF,
896#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
897 (char_u *)&p_confirm, PV_NONE,
898#else
899 (char_u *)NULL, PV_NONE,
900#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200901 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000902 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000903 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200904 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000905 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
906 (char_u *)&p_ci, PV_CI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200907 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000908 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
909 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000910 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200911 SCTX_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200912 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200913#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200914 (char_u *)&p_cm, PV_CM,
Bram Moolenaara86187b2018-12-16 18:20:00 +0100915 {(char_u *)"blowfish2", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200916#else
917 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200918 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200919#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200920 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000921 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
922#ifdef FEAT_CSCOPE
923 (char_u *)&p_cspc, PV_NONE,
924#else
925 (char_u *)NULL, PV_NONE,
926#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200927 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000928 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
929#ifdef FEAT_CSCOPE
930 (char_u *)&p_csprg, PV_NONE,
931 {(char_u *)"cscope", (char_u *)0L}
932#else
933 (char_u *)NULL, PV_NONE,
934 {(char_u *)0L, (char_u *)0L}
935#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200936 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200937 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000938#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
939 (char_u *)&p_csqf, PV_NONE,
940 {(char_u *)"", (char_u *)0L}
941#else
942 (char_u *)NULL, PV_NONE,
943 {(char_u *)0L, (char_u *)0L}
944#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200945 SCTX_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200946 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
947#ifdef FEAT_CSCOPE
948 (char_u *)&p_csre, PV_NONE,
949#else
950 (char_u *)NULL, PV_NONE,
951#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200952 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000953 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
954#ifdef FEAT_CSCOPE
955 (char_u *)&p_cst, PV_NONE,
956#else
957 (char_u *)NULL, PV_NONE,
958#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200959 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000960 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
961#ifdef FEAT_CSCOPE
962 (char_u *)&p_csto, PV_NONE,
963#else
964 (char_u *)NULL, PV_NONE,
965#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200966 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000967 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
968#ifdef FEAT_CSCOPE
969 (char_u *)&p_csverbose, PV_NONE,
970#else
971 (char_u *)NULL, PV_NONE,
972#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200973 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200974 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200975 (char_u *)VAR_WIN, PV_CRBIND,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200976 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar177ab9e2019-01-15 21:12:57 +0100977 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000978#ifdef FEAT_SYN_HL
979 (char_u *)VAR_WIN, PV_CUC,
980#else
981 (char_u *)NULL, PV_NONE,
982#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200983 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100984 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000985#ifdef FEAT_SYN_HL
986 (char_u *)VAR_WIN, PV_CUL,
987#else
988 (char_u *)NULL, PV_NONE,
989#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200990 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000991 {"debug", NULL, P_STRING|P_VI_DEF,
992 (char_u *)&p_debug, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200993 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200994 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000995#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000996 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000997 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000998#else
999 (char_u *)NULL, PV_NONE,
1000 {(char_u *)NULL, (char_u *)0L}
1001#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001002 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001003 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001004 (char_u *)&p_deco, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001005 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001006 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001007#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001008 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001009#else
1010 (char_u *)NULL, PV_NONE,
1011#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001012 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001013 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1014#ifdef FEAT_DIFF
1015 (char_u *)VAR_WIN, PV_DIFF,
1016#else
1017 (char_u *)NULL, PV_NONE,
1018#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001019 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001020 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001021#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1022 (char_u *)&p_dex, PV_NONE,
1023 {(char_u *)"", (char_u *)0L}
1024#else
1025 (char_u *)NULL, PV_NONE,
1026 {(char_u *)0L, (char_u *)0L}
1027#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001028 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001029 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1030 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001031#ifdef FEAT_DIFF
1032 (char_u *)&p_dip, PV_NONE,
Bram Moolenaarc93262b2018-09-10 21:15:40 +02001033 {(char_u *)"internal,filler", (char_u *)NULL}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001034#else
1035 (char_u *)NULL, PV_NONE,
1036 {(char_u *)"", (char_u *)NULL}
1037#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001038 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001039 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1040#ifdef FEAT_DIGRAPHS
1041 (char_u *)&p_dg, PV_NONE,
1042#else
1043 (char_u *)NULL, PV_NONE,
1044#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001045 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001046 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1047 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001048 (char_u *)&p_dir, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001049 {(char_u *)DFLT_DIR, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001050 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001051 (char_u *)&p_dy, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001052 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001053 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001054 (char_u *)&p_ead, PV_NONE,
1055 {(char_u *)"both", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001056 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001057 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1058 (char_u *)&p_ed, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001059 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001060 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaar3848e002016-03-19 18:42:29 +01001061 (char_u *)&p_emoji, PV_NONE,
1062 {(char_u *)TRUE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001063 SCTX_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001064 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001065 (char_u *)&p_enc, PV_NONE,
1066 {(char_u *)ENC_DFLT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001067 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001068 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1069 (char_u *)&p_eol, PV_EOL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001070 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001071 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1072 (char_u *)&p_ea, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001073 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001074 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001075 (char_u *)&p_ep, PV_EP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001076 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001077 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1078 (char_u *)&p_eb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001079 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001080 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1081#ifdef FEAT_QUICKFIX
1082 (char_u *)&p_ef, PV_NONE,
1083 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1084#else
1085 (char_u *)NULL, PV_NONE,
1086 {(char_u *)NULL, (char_u *)0L}
1087#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001088 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001089 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001090#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001091 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001092 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001093#else
1094 (char_u *)NULL, PV_NONE,
1095 {(char_u *)NULL, (char_u *)0L}
1096#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001097 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001098 {"esckeys", "ek", P_BOOL|P_VIM,
1099 (char_u *)&p_ek, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001100 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001101 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001102 (char_u *)&p_ei, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001103 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001104 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1105 (char_u *)&p_et, PV_ET,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001106 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001107 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1108 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001109 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001110 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1111 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001112 (char_u *)&p_fenc, PV_FENC,
1113 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001114 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001115 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001116 (char_u *)&p_fencs, PV_NONE,
1117 {(char_u *)"ucs-bom", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001118 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001119 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1120 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001121 (char_u *)&p_ff, PV_FF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001122 {(char_u *)DFLT_FF, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001123 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001124 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001125 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001126 SCTX_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001127 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1128 (char_u *)&p_fic, PV_NONE,
1129 {
1130#ifdef CASE_INSENSITIVE_FILENAME
1131 (char_u *)TRUE,
1132#else
1133 (char_u *)FALSE,
1134#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001135 (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001136 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001137 (char_u *)&p_ft, PV_FT,
1138 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001139 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001140 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001141 (char_u *)&p_fcs, PV_NONE,
1142 {(char_u *)"vert:|,fold:-", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001143 SCTX_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001144 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1145 (char_u *)&p_fixeol, PV_FIXEOL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001146 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001147 {"fkmap", "fk", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001148 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001149 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001150 {"flash", "fl", P_BOOL|P_VI_DEF,
1151 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001152 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001153 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001154#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001155 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001156 {(char_u *)"", (char_u *)0L}
1157#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001158 (char_u *)NULL, PV_NONE,
1159 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001160#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001161 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001162 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1163#ifdef FEAT_FOLDING
1164 (char_u *)VAR_WIN, PV_FDC,
1165 {(char_u *)FALSE, (char_u *)0L}
1166#else
1167 (char_u *)NULL, PV_NONE,
1168 {(char_u *)NULL, (char_u *)0L}
1169#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001170 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001171 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1172#ifdef FEAT_FOLDING
1173 (char_u *)VAR_WIN, PV_FEN,
1174 {(char_u *)TRUE, (char_u *)0L}
1175#else
1176 (char_u *)NULL, PV_NONE,
1177 {(char_u *)NULL, (char_u *)0L}
1178#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001179 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001180 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN|P_MLE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001181#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1182 (char_u *)VAR_WIN, PV_FDE,
1183 {(char_u *)"0", (char_u *)NULL}
1184#else
1185 (char_u *)NULL, PV_NONE,
1186 {(char_u *)NULL, (char_u *)0L}
1187#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001188 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001189 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001190#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001191 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001192 {(char_u *)"#", (char_u *)NULL}
1193#else
1194 (char_u *)NULL, PV_NONE,
1195 {(char_u *)NULL, (char_u *)0L}
1196#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001197 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001198 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001199#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001200 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001201 {(char_u *)0L, (char_u *)0L}
1202#else
1203 (char_u *)NULL, PV_NONE,
1204 {(char_u *)NULL, (char_u *)0L}
1205#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001206 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001207 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001208#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001209 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001210 {(char_u *)-1L, (char_u *)0L}
1211#else
1212 (char_u *)NULL, PV_NONE,
1213 {(char_u *)NULL, (char_u *)0L}
1214#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001215 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001216 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001217 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001218#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001219 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001220 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001221#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001222 (char_u *)NULL, PV_NONE,
1223 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001224#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001225 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001226 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1227#ifdef FEAT_FOLDING
1228 (char_u *)VAR_WIN, PV_FDM,
1229 {(char_u *)"manual", (char_u *)NULL}
1230#else
1231 (char_u *)NULL, PV_NONE,
1232 {(char_u *)NULL, (char_u *)0L}
1233#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001234 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001235 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1236#ifdef FEAT_FOLDING
1237 (char_u *)VAR_WIN, PV_FML,
1238 {(char_u *)1L, (char_u *)0L}
1239#else
1240 (char_u *)NULL, PV_NONE,
1241 {(char_u *)NULL, (char_u *)0L}
1242#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001243 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001244 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1245#ifdef FEAT_FOLDING
1246 (char_u *)VAR_WIN, PV_FDN,
1247 {(char_u *)20L, (char_u *)0L}
1248#else
1249 (char_u *)NULL, PV_NONE,
1250 {(char_u *)NULL, (char_u *)0L}
1251#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001252 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001253 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1254#ifdef FEAT_FOLDING
1255 (char_u *)&p_fdo, PV_NONE,
1256 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1257 (char_u *)0L}
1258#else
1259 (char_u *)NULL, PV_NONE,
1260 {(char_u *)NULL, (char_u *)0L}
1261#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001262 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001263 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN|P_MLE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001264#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1265 (char_u *)VAR_WIN, PV_FDT,
1266 {(char_u *)"foldtext()", (char_u *)NULL}
1267#else
1268 (char_u *)NULL, PV_NONE,
1269 {(char_u *)NULL, (char_u *)0L}
1270#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001271 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001272 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM|P_MLE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001273#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001274 (char_u *)&p_fex, PV_FEX,
1275 {(char_u *)"", (char_u *)0L}
1276#else
1277 (char_u *)NULL, PV_NONE,
1278 {(char_u *)0L, (char_u *)0L}
1279#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001280 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001281 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1282 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001283 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001284 SCTX_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001285 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1286 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001287 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001288 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001289 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001290 (char_u *)&p_fp, PV_FP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001291 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001292 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1293#ifdef HAVE_FSYNC
1294 (char_u *)&p_fs, PV_NONE,
1295 {(char_u *)TRUE, (char_u *)0L}
1296#else
1297 (char_u *)NULL, PV_NONE,
1298 {(char_u *)FALSE, (char_u *)0L}
1299#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001300 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001301 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1302 (char_u *)&p_gd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001303 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001304 {"graphic", "gr", P_BOOL|P_VI_DEF,
1305 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001306 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001307 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001308#ifdef FEAT_QUICKFIX
1309 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001310 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001311#else
1312 (char_u *)NULL, PV_NONE,
1313 {(char_u *)NULL, (char_u *)0L}
1314#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001315 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001316 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1317#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001318 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001319 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01001320# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001321 /* may be changed to "grep -n" in os_win32.c */
1322 (char_u *)"findstr /n",
1323# else
1324# ifdef UNIX
1325 /* Add an extra file name so that grep will always
1326 * insert a file name in the match line. */
1327 (char_u *)"grep -n $* /dev/null",
1328# else
1329# ifdef VMS
1330 (char_u *)"SEARCH/NUMBERS ",
1331# else
1332 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001333# endif
1334# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001335# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001336 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001337#else
1338 (char_u *)NULL, PV_NONE,
1339 {(char_u *)NULL, (char_u *)0L}
1340#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001341 SCTX_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001342 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001343#ifdef CURSOR_SHAPE
1344 (char_u *)&p_guicursor, PV_NONE,
1345 {
1346# ifdef FEAT_GUI
1347 (char_u *)"n-v-c:block-Cursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001348# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001349 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1350# endif
1351 (char_u *)0L}
1352#else
1353 (char_u *)NULL, PV_NONE,
1354 {(char_u *)NULL, (char_u *)0L}
1355#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001356 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001357 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001358#ifdef FEAT_GUI
1359 (char_u *)&p_guifont, PV_NONE,
1360 {(char_u *)"", (char_u *)0L}
1361#else
1362 (char_u *)NULL, PV_NONE,
1363 {(char_u *)NULL, (char_u *)0L}
1364#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001365 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001366 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001367#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1368 (char_u *)&p_guifontset, PV_NONE,
1369 {(char_u *)"", (char_u *)0L}
1370#else
1371 (char_u *)NULL, PV_NONE,
1372 {(char_u *)NULL, (char_u *)0L}
1373#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001374 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001375 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001376#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001377 (char_u *)&p_guifontwide, PV_NONE,
1378 {(char_u *)"", (char_u *)0L}
1379#else
1380 (char_u *)NULL, PV_NONE,
1381 {(char_u *)NULL, (char_u *)0L}
1382#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001383 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001384 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001385#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001386 (char_u *)&p_ghr, PV_NONE,
1387#else
1388 (char_u *)NULL, PV_NONE,
1389#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001390 {(char_u *)50L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001391 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001392#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001393 (char_u *)&p_go, PV_NONE,
Bram Moolenaard0573012017-10-28 21:11:06 +02001394# if defined(UNIX) && !defined(FEAT_GUI_MAC)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001395 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001396# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001397 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001398# endif
1399#else
1400 (char_u *)NULL, PV_NONE,
1401 {(char_u *)NULL, (char_u *)0L}
1402#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001403 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001404 {"guipty", NULL, P_BOOL|P_VI_DEF,
1405#if defined(FEAT_GUI)
1406 (char_u *)&p_guipty, PV_NONE,
1407#else
1408 (char_u *)NULL, PV_NONE,
1409#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001410 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001411 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN|P_MLE,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001412#if defined(FEAT_GUI_TABLINE)
1413 (char_u *)&p_gtl, PV_NONE,
1414 {(char_u *)"", (char_u *)0L}
1415#else
1416 (char_u *)NULL, PV_NONE,
1417 {(char_u *)NULL, (char_u *)0L}
1418#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001419 SCTX_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001420 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001421#if defined(FEAT_GUI_TABLINE)
1422 (char_u *)&p_gtt, PV_NONE,
1423 {(char_u *)"", (char_u *)0L}
1424#else
1425 (char_u *)NULL, PV_NONE,
1426 {(char_u *)NULL, (char_u *)0L}
1427#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001428 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001429 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1430 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001431 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001432 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1433 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001434 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001435 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001436 {"helpheight", "hh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001437 (char_u *)&p_hh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001438 {(char_u *)20L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001439 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001440#ifdef FEAT_MULTI_LANG
1441 (char_u *)&p_hlg, PV_NONE,
1442 {(char_u *)"", (char_u *)0L}
1443#else
1444 (char_u *)NULL, PV_NONE,
1445 {(char_u *)0L, (char_u *)0L}
1446#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001447 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001448 {"hidden", "hid", P_BOOL|P_VI_DEF,
1449 (char_u *)&p_hid, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001450 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001451 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001452 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001453 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001454 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001455 {"history", "hi", P_NUM|P_VIM,
1456 (char_u *)&p_hi, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001457 {(char_u *)0L, (char_u *)50L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001458 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1459#ifdef FEAT_RIGHTLEFT
1460 (char_u *)&p_hkmap, PV_NONE,
1461#else
1462 (char_u *)NULL, PV_NONE,
1463#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001464 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001465 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1466#ifdef FEAT_RIGHTLEFT
1467 (char_u *)&p_hkmapp, PV_NONE,
1468#else
1469 (char_u *)NULL, PV_NONE,
1470#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001471 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001472 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1473 (char_u *)&p_hls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001474 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001475 {"icon", NULL, P_BOOL|P_VI_DEF,
1476#ifdef FEAT_TITLE
1477 (char_u *)&p_icon, PV_NONE,
1478#else
1479 (char_u *)NULL, PV_NONE,
1480#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001481 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001482 {"iconstring", NULL, P_STRING|P_VI_DEF|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001483#ifdef FEAT_TITLE
1484 (char_u *)&p_iconstring, PV_NONE,
1485#else
1486 (char_u *)NULL, PV_NONE,
1487#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001488 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001489 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1490 (char_u *)&p_ic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001491 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001492 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001493#if defined(FEAT_EVAL)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001494 (char_u *)&p_imaf, PV_NONE,
1495 {(char_u *)"", (char_u *)NULL}
1496# else
1497 (char_u *)NULL, PV_NONE,
1498 {(char_u *)NULL, (char_u *)0L}
1499# endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001500 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001501 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001502#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001503 (char_u *)&p_imak, PV_NONE,
1504#else
1505 (char_u *)NULL, PV_NONE,
1506#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001507 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001508 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001509 (char_u *)&p_imcmdline, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001510 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001511 {"imdisable", "imd", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001512 (char_u *)&p_imdisable, PV_NONE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001513#ifdef __sgi
1514 {(char_u *)TRUE, (char_u *)0L}
1515#else
1516 {(char_u *)FALSE, (char_u *)0L}
1517#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001518 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001519 {"iminsert", "imi", P_NUM|P_VI_DEF,
1520 (char_u *)&p_iminsert, PV_IMI,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001521 {(char_u *)B_IMODE_NONE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001522 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001523 {"imsearch", "ims", P_NUM|P_VI_DEF,
1524 (char_u *)&p_imsearch, PV_IMS,
Bram Moolenaar4cf56bb2017-09-16 15:50:32 +02001525 {(char_u *)B_IMODE_USE_INSERT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001526 SCTX_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001527 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001528#if defined(FEAT_EVAL)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001529 (char_u *)&p_imsf, PV_NONE,
1530 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001531#else
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001532 (char_u *)NULL, PV_NONE,
1533 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001534#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001535 SCTX_INIT},
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001536 {"imstyle", "imst", P_NUM|P_VI_DEF|P_SECURE,
1537#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1538 (char_u *)&p_imst, PV_NONE,
1539 {(char_u *)IM_OVER_THE_SPOT, (char_u *)0L}
1540#else
1541 (char_u *)NULL, PV_NONE,
1542 {(char_u *)0L, (char_u *)0L}
1543#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001544 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001545 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1546#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001547 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001548 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1549#else
1550 (char_u *)NULL, PV_NONE,
1551 {(char_u *)0L, (char_u *)0L}
1552#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001553 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001554 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001555#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1556 (char_u *)&p_inex, PV_INEX,
1557 {(char_u *)"", (char_u *)0L}
1558#else
1559 (char_u *)NULL, PV_NONE,
1560 {(char_u *)0L, (char_u *)0L}
1561#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001562 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001563 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1564 (char_u *)&p_is, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001565 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001566 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001567#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1568 (char_u *)&p_inde, PV_INDE,
1569 {(char_u *)"", (char_u *)0L}
1570#else
1571 (char_u *)NULL, PV_NONE,
1572 {(char_u *)0L, (char_u *)0L}
1573#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001574 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001575 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001576#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1577 (char_u *)&p_indk, PV_INDK,
Bram Moolenaarce655742019-01-31 14:12:57 +01001578 {INDENTKEYS_DEFAULT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001579#else
1580 (char_u *)NULL, PV_NONE,
1581 {(char_u *)0L, (char_u *)0L}
1582#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001583 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001584 {"infercase", "inf", P_BOOL|P_VI_DEF,
1585 (char_u *)&p_inf, PV_INF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001586 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001587 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1588 (char_u *)&p_im, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001589 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001590 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1591 (char_u *)&p_isf, PV_NONE,
1592 {
1593#ifdef BACKSLASH_IN_FILENAME
1594 /* Excluded are: & and ^ are special in cmd.exe
1595 * ( and ) are used in text separating fnames */
1596 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1597#else
1598# ifdef AMIGA
1599 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1600# else
1601# ifdef VMS
1602 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1603# else /* UNIX et al. */
1604# ifdef EBCDIC
1605 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1606# else
1607 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1608# endif
1609# endif
1610# endif
1611#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001612 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001613 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1614 (char_u *)&p_isi, PV_NONE,
1615 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001616#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001617 (char_u *)"@,48-57,_,128-167,224-235",
1618#else
1619# ifdef EBCDIC
1620 /* TODO: EBCDIC Check this! @ == isalpha()*/
1621 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1622 "112-120,128,140-142,156,158,172,"
1623 "174,186,191,203-207,219-225,235-239,"
1624 "251-254",
1625# else
1626 (char_u *)"@,48-57,_,192-255",
1627# endif
1628#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001629 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001630 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1631 (char_u *)&p_isk, PV_ISK,
1632 {
1633#ifdef EBCDIC
1634 (char_u *)"@,240-249,_",
1635 /* TODO: EBCDIC Check this! @ == isalpha()*/
1636 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1637 "112-120,128,140-142,156,158,172,"
1638 "174,186,191,203-207,219-225,235-239,"
1639 "251-254",
1640#else
1641 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001642# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001643 (char_u *)"@,48-57,_,128-167,224-235"
1644# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001645 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001646# endif
1647#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001648 } SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001649 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1650 (char_u *)&p_isp, PV_NONE,
1651 {
Bram Moolenaard0573012017-10-28 21:11:06 +02001652#if defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001653 (char_u *)"@,~-255",
1654#else
1655# ifdef EBCDIC
1656 /* all chars above 63 are printable */
1657 (char_u *)"63-255",
1658# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001659 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001660# endif
1661#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001662 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001663 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1664 (char_u *)&p_js, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001665 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001666 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1667#ifdef FEAT_CRYPT
1668 (char_u *)&p_key, PV_KEY,
1669 {(char_u *)"", (char_u *)0L}
1670#else
1671 (char_u *)NULL, PV_NONE,
1672 {(char_u *)0L, (char_u *)0L}
1673#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001674 SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001675 {"keymap", "kmp", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_RSTAT|P_NFNAME|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001676#ifdef FEAT_KEYMAP
1677 (char_u *)&p_keymap, PV_KMAP,
1678 {(char_u *)"", (char_u *)0L}
1679#else
1680 (char_u *)NULL, PV_NONE,
1681 {(char_u *)"", (char_u *)0L}
1682#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001683 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001684 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001685 (char_u *)&p_km, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001686 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001687 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001688 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001689 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001690#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001691 (char_u *)":help",
1692#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001693# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001694 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001695# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001696# ifdef USEMAN_S
1697 (char_u *)"man -s",
1698# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001699 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001700# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001701# endif
1702#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001703 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001704 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001705#ifdef FEAT_LANGMAP
1706 (char_u *)&p_langmap, PV_NONE,
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001707 {(char_u *)"", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001708#else
1709 (char_u *)NULL, PV_NONE,
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001710 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001711#endif
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001712 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001713 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001714#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1715 (char_u *)&p_lm, PV_NONE,
1716#else
1717 (char_u *)NULL, PV_NONE,
1718#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001719 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001720 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1721#ifdef FEAT_LANGMAP
1722 (char_u *)&p_lnr, PV_NONE,
1723#else
1724 (char_u *)NULL, PV_NONE,
1725#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001726 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001727 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1728#ifdef FEAT_LANGMAP
1729 (char_u *)&p_lrm, PV_NONE,
1730#else
1731 (char_u *)NULL, PV_NONE,
1732#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001733 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001734 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001735 (char_u *)&p_ls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001736 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001737 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1738 (char_u *)&p_lz, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001739 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001740 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1741#ifdef FEAT_LINEBREAK
1742 (char_u *)VAR_WIN, PV_LBR,
1743#else
1744 (char_u *)NULL, PV_NONE,
1745#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001746 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001747 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1748 (char_u *)&Rows, PV_NONE,
1749 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01001750#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001751 (char_u *)25L,
1752#else
1753 (char_u *)24L,
1754#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001755 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001756 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1757#ifdef FEAT_GUI
1758 (char_u *)&p_linespace, PV_NONE,
1759#else
1760 (char_u *)NULL, PV_NONE,
1761#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01001762#ifdef FEAT_GUI_MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001763 {(char_u *)1L, (char_u *)0L}
1764#else
1765 {(char_u *)0L, (char_u *)0L}
1766#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001767 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001768 {"lisp", NULL, P_BOOL|P_VI_DEF,
1769#ifdef FEAT_LISP
1770 (char_u *)&p_lisp, PV_LISP,
1771#else
1772 (char_u *)NULL, PV_NONE,
1773#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001774 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001775 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001776#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001777 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001778 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1779#else
1780 (char_u *)NULL, PV_NONE,
1781 {(char_u *)"", (char_u *)0L}
1782#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001783 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001784 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1785 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001786 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001787 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001788 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001789 {(char_u *)"eol:$", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001790 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1791 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001792 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001793 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001794#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001795 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001796 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001797#else
1798 (char_u *)NULL, PV_NONE,
1799 {(char_u *)"", (char_u *)0L}
1800#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001801 SCTX_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001802 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001803#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001804 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001805 {(char_u *)TRUE, (char_u *)0L}
1806#else
1807 (char_u *)NULL, PV_NONE,
1808 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001809#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001810 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001811 {"magic", NULL, P_BOOL|P_VI_DEF,
1812 (char_u *)&p_magic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001813 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001814 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001815#ifdef FEAT_QUICKFIX
1816 (char_u *)&p_mef, PV_NONE,
1817 {(char_u *)"", (char_u *)0L}
1818#else
1819 (char_u *)NULL, PV_NONE,
1820 {(char_u *)NULL, (char_u *)0L}
1821#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001822 SCTX_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001823 {"makeencoding","menc", P_STRING|P_VI_DEF,
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001824 (char_u *)&p_menc, PV_MENC,
1825 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001826 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001827 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1828#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001829 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001830# ifdef VMS
1831 {(char_u *)"MMS", (char_u *)0L}
1832# else
1833 {(char_u *)"make", (char_u *)0L}
1834# endif
1835#else
1836 (char_u *)NULL, PV_NONE,
1837 {(char_u *)NULL, (char_u *)0L}
1838#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001839 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001840 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001841 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001842 {(char_u *)"(:),{:},[:]", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001843 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001844 {"matchtime", "mat", P_NUM|P_VI_DEF,
1845 (char_u *)&p_mat, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001846 {(char_u *)5L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001847 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001848 (char_u *)&p_mco, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001849 {(char_u *)2, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001850 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1851#ifdef FEAT_EVAL
1852 (char_u *)&p_mfd, PV_NONE,
1853#else
1854 (char_u *)NULL, PV_NONE,
1855#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001856 {(char_u *)100L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001857 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1858 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001859 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001860 {"maxmem", "mm", P_NUM|P_VI_DEF,
1861 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001862 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001863 SCTX_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001864 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1865 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001866 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001867 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1868 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001869 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001870 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001871 {"menuitems", "mis", P_NUM|P_VI_DEF,
1872#ifdef FEAT_MENU
1873 (char_u *)&p_mis, PV_NONE,
1874#else
1875 (char_u *)NULL, PV_NONE,
1876#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001877 {(char_u *)25L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001878 {"mesg", NULL, P_BOOL|P_VI_DEF,
1879 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001880 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001881 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001882#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001883 (char_u *)&p_msm, PV_NONE,
1884 {(char_u *)"460000,2000,500", (char_u *)0L}
1885#else
1886 (char_u *)NULL, PV_NONE,
1887 {(char_u *)0L, (char_u *)0L}
1888#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001889 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001890 {"modeline", "ml", P_BOOL|P_VIM,
1891 (char_u *)&p_ml, PV_ML,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001892 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar7e800c62019-05-23 17:08:49 +02001893 {"modelineexpr", "mle", P_BOOL|P_VI_DEF|P_SECURE,
Bram Moolenaar110289e2019-05-23 15:38:06 +02001894 (char_u *)&p_mle, PV_NONE,
1895 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001896 {"modelines", "mls", P_NUM|P_VI_DEF,
1897 (char_u *)&p_mls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001898 {(char_u *)5L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001899 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1900 (char_u *)&p_ma, PV_MA,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001901 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001902 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1903 (char_u *)&p_mod, PV_MOD,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001904 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001905 {"more", NULL, P_BOOL|P_VIM,
1906 (char_u *)&p_more, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001907 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001908 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1909 (char_u *)&p_mouse, PV_NONE,
1910 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01001911#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001912 (char_u *)"a",
1913#else
1914 (char_u *)"",
1915#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001916 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001917 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1918#ifdef FEAT_GUI
1919 (char_u *)&p_mousef, PV_NONE,
1920#else
1921 (char_u *)NULL, PV_NONE,
1922#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001923 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001924 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1925#ifdef FEAT_GUI
1926 (char_u *)&p_mh, PV_NONE,
1927#else
1928 (char_u *)NULL, PV_NONE,
1929#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001930 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001931 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1932 (char_u *)&p_mousem, PV_NONE,
1933 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001934#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001935 (char_u *)"popup",
1936#else
Bram Moolenaard0573012017-10-28 21:11:06 +02001937# if defined(MACOS_X)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001938 (char_u *)"popup_setpos",
1939# else
1940 (char_u *)"extend",
1941# endif
1942#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001943 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001944 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001945#ifdef FEAT_MOUSESHAPE
1946 (char_u *)&p_mouseshape, PV_NONE,
1947 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1948#else
1949 (char_u *)NULL, PV_NONE,
1950 {(char_u *)NULL, (char_u *)0L}
1951#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001952 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001953 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1954 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001955 {(char_u *)500L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02001956 {"mzschemedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1957#if defined(DYNAMIC_MZSCHEME)
1958 (char_u *)&p_mzschemedll, PV_NONE,
1959 {(char_u *)DYNAMIC_MZSCH_DLL, (char_u *)0L}
1960#else
1961 (char_u *)NULL, PV_NONE,
1962 {(char_u *)"", (char_u *)0L}
1963#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001964 SCTX_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02001965 {"mzschemegcdll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1966#if defined(DYNAMIC_MZSCHEME)
1967 (char_u *)&p_mzschemegcdll, PV_NONE,
1968 {(char_u *)DYNAMIC_MZGC_DLL, (char_u *)0L}
1969#else
1970 (char_u *)NULL, PV_NONE,
1971 {(char_u *)"", (char_u *)0L}
1972#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001973 SCTX_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001974 {"mzquantum", "mzq", P_NUM,
1975#ifdef FEAT_MZSCHEME
1976 (char_u *)&p_mzq, PV_NONE,
1977#else
1978 (char_u *)NULL, PV_NONE,
1979#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001980 {(char_u *)100L, (char_u *)100L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001981 {"novice", NULL, P_BOOL|P_VI_DEF,
1982 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001983 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001984 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001985 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01001986 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001987 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001988 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1989 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001990 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001991 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1992#ifdef FEAT_LINEBREAK
1993 (char_u *)VAR_WIN, PV_NUW,
1994#else
1995 (char_u *)NULL, PV_NONE,
1996#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001997 {(char_u *)8L, (char_u *)4L} SCTX_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001998 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001999#ifdef FEAT_COMPL_FUNC
2000 (char_u *)&p_ofu, PV_OFU,
2001 {(char_u *)"", (char_u *)0L}
2002#else
2003 (char_u *)NULL, PV_NONE,
2004 {(char_u *)0L, (char_u *)0L}
2005#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002006 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002007 {"open", NULL, P_BOOL|P_VI_DEF,
2008 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002009 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002010 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002011#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002012 (char_u *)&p_odev, PV_NONE,
2013#else
2014 (char_u *)NULL, PV_NONE,
2015#endif
2016 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002017 SCTX_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002018 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2019 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002020 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002021 {"optimize", "opt", P_BOOL|P_VI_DEF,
2022 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002023 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002024 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002025 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002026 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002027 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2028 |P_SECURE,
2029 (char_u *)&p_pp, PV_NONE,
2030 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002031 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002032 {"paragraphs", "para", P_STRING|P_VI_DEF,
2033 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002034 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002035 (char_u *)0L} SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002036 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002037 (char_u *)&p_paste, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002038 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002039 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2040 (char_u *)&p_pt, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002041 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002042 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2043#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2044 (char_u *)&p_pex, PV_NONE,
2045 {(char_u *)"", (char_u *)0L}
2046#else
2047 (char_u *)NULL, PV_NONE,
2048 {(char_u *)0L, (char_u *)0L}
2049#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002050 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002051 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002052 (char_u *)&p_pm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002053 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002054 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002055 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002056 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002057#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002058 (char_u *)".,,",
2059#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002060 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002061#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002062 (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002063 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002064#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002065 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002066 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002067#else
2068 (char_u *)NULL, PV_NONE,
2069 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002070#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002071 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002072 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2073 (char_u *)&p_pi, PV_PI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002074 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002075 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002076#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002077 (char_u *)&p_pvh, PV_NONE,
2078#else
2079 (char_u *)NULL, PV_NONE,
2080#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002081 {(char_u *)12L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002082 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002083#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002084 (char_u *)VAR_WIN, PV_PVW,
2085#else
2086 (char_u *)NULL, PV_NONE,
2087#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002088 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002089 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002090#ifdef FEAT_PRINTER
2091 (char_u *)&p_pdev, PV_NONE,
2092 {(char_u *)"", (char_u *)0L}
2093#else
2094 (char_u *)NULL, PV_NONE,
2095 {(char_u *)NULL, (char_u *)0L}
2096#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002097 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002098 {"printencoding", "penc", P_STRING|P_VI_DEF,
2099#ifdef FEAT_POSTSCRIPT
2100 (char_u *)&p_penc, PV_NONE,
2101 {(char_u *)"", (char_u *)0L}
2102#else
2103 (char_u *)NULL, PV_NONE,
2104 {(char_u *)NULL, (char_u *)0L}
2105#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002106 SCTX_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002107 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002108#ifdef FEAT_POSTSCRIPT
2109 (char_u *)&p_pexpr, PV_NONE,
2110 {(char_u *)"", (char_u *)0L}
2111#else
2112 (char_u *)NULL, PV_NONE,
2113 {(char_u *)NULL, (char_u *)0L}
2114#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002115 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002116 {"printfont", "pfn", P_STRING|P_VI_DEF,
2117#ifdef FEAT_PRINTER
2118 (char_u *)&p_pfn, PV_NONE,
2119 {
2120# ifdef MSWIN
2121 (char_u *)"Courier_New:h10",
2122# else
2123 (char_u *)"courier",
2124# endif
2125 (char_u *)0L}
2126#else
2127 (char_u *)NULL, PV_NONE,
2128 {(char_u *)NULL, (char_u *)0L}
2129#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002130 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002131 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2132#ifdef FEAT_PRINTER
2133 (char_u *)&p_header, PV_NONE,
Bram Moolenaar0903d562017-08-26 22:30:15 +02002134 /* untranslated to avoid problems when 'encoding'
2135 * is changed */
2136 {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002137#else
2138 (char_u *)NULL, PV_NONE,
2139 {(char_u *)NULL, (char_u *)0L}
2140#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002141 SCTX_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002142 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01002143#if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002144 (char_u *)&p_pmcs, PV_NONE,
2145 {(char_u *)"", (char_u *)0L}
2146#else
2147 (char_u *)NULL, PV_NONE,
2148 {(char_u *)NULL, (char_u *)0L}
2149#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002150 SCTX_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002151 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01002152#if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002153 (char_u *)&p_pmfn, PV_NONE,
2154 {(char_u *)"", (char_u *)0L}
2155#else
2156 (char_u *)NULL, PV_NONE,
2157 {(char_u *)NULL, (char_u *)0L}
2158#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002159 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002160 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002161#ifdef FEAT_PRINTER
2162 (char_u *)&p_popt, PV_NONE,
2163 {(char_u *)"", (char_u *)0L}
2164#else
2165 (char_u *)NULL, PV_NONE,
2166 {(char_u *)NULL, (char_u *)0L}
2167#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002168 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002169 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002170 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002171 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002172 {"pumheight", "ph", P_NUM|P_VI_DEF,
2173#ifdef FEAT_INS_EXPAND
2174 (char_u *)&p_ph, PV_NONE,
2175#else
2176 (char_u *)NULL, PV_NONE,
2177#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002178 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaara8f04aa2018-02-10 15:36:55 +01002179 {"pumwidth", "pw", P_NUM|P_VI_DEF,
2180#ifdef FEAT_INS_EXPAND
2181 (char_u *)&p_pw, PV_NONE,
2182#else
2183 (char_u *)NULL, PV_NONE,
2184#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002185 {(char_u *)15L, (char_u *)15L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002186 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002187#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002188 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002189 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002190#else
2191 (char_u *)NULL, PV_NONE,
2192 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002193#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002194 SCTX_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002195 {"pythonthreehome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2196#if defined(FEAT_PYTHON3)
2197 (char_u *)&p_py3home, PV_NONE,
2198 {(char_u *)"", (char_u *)0L}
2199#else
2200 (char_u *)NULL, PV_NONE,
2201 {(char_u *)NULL, (char_u *)0L}
2202#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002203 SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002204 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002205#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002206 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002207 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002208#else
2209 (char_u *)NULL, PV_NONE,
2210 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002211#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002212 SCTX_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002213 {"pythonhome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2214#if defined(FEAT_PYTHON)
2215 (char_u *)&p_pyhome, PV_NONE,
2216 {(char_u *)"", (char_u *)0L}
2217#else
2218 (char_u *)NULL, PV_NONE,
2219 {(char_u *)NULL, (char_u *)0L}
2220#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002221 SCTX_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002222 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2223#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2224 (char_u *)&p_pyx, PV_NONE,
2225#else
2226 (char_u *)NULL, PV_NONE,
2227#endif
2228 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002229 SCTX_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002230 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2231#ifdef FEAT_TEXTOBJ
2232 (char_u *)&p_qe, PV_QE,
2233 {(char_u *)"\\", (char_u *)0L}
2234#else
2235 (char_u *)NULL, PV_NONE,
2236 {(char_u *)NULL, (char_u *)0L}
2237#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002238 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002239 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2240 (char_u *)&p_ro, PV_RO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002241 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002242 {"redraw", NULL, P_BOOL|P_VI_DEF,
2243 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002244 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002245 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2246#ifdef FEAT_RELTIME
2247 (char_u *)&p_rdt, PV_NONE,
2248#else
2249 (char_u *)NULL, PV_NONE,
2250#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002251 {(char_u *)2000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002252 {"regexpengine", "re", P_NUM|P_VI_DEF,
2253 (char_u *)&p_re, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002254 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002255 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2256 (char_u *)VAR_WIN, PV_RNU,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002257 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002258 {"remap", NULL, P_BOOL|P_VI_DEF,
2259 (char_u *)&p_remap, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002260 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002261 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002262#ifdef FEAT_RENDER_OPTIONS
2263 (char_u *)&p_rop, PV_NONE,
2264 {(char_u *)"", (char_u *)0L}
2265#else
2266 (char_u *)NULL, PV_NONE,
2267 {(char_u *)NULL, (char_u *)0L}
2268#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002269 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002270 {"report", NULL, P_NUM|P_VI_DEF,
2271 (char_u *)&p_report, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002272 {(char_u *)2L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002273 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
Bram Moolenaar4f974752019-02-17 17:44:42 +01002274#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00002275 (char_u *)&p_rs, PV_NONE,
2276#else
2277 (char_u *)NULL, PV_NONE,
2278#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002279 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002280 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2281#ifdef FEAT_RIGHTLEFT
2282 (char_u *)&p_ri, PV_NONE,
2283#else
2284 (char_u *)NULL, PV_NONE,
2285#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002286 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002287 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2288#ifdef FEAT_RIGHTLEFT
2289 (char_u *)VAR_WIN, PV_RL,
2290#else
2291 (char_u *)NULL, PV_NONE,
2292#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002293 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002294 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2295#ifdef FEAT_RIGHTLEFT
2296 (char_u *)VAR_WIN, PV_RLC,
2297 {(char_u *)"search", (char_u *)NULL}
2298#else
2299 (char_u *)NULL, PV_NONE,
2300 {(char_u *)NULL, (char_u *)0L}
2301#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002302 SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002303 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002304#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002305 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002306 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002307#else
2308 (char_u *)NULL, PV_NONE,
2309 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002310#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002311 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002312 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2313#ifdef FEAT_CMDL_INFO
2314 (char_u *)&p_ru, PV_NONE,
2315#else
2316 (char_u *)NULL, PV_NONE,
2317#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002318 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02002319 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002320#ifdef FEAT_STL_OPT
2321 (char_u *)&p_ruf, PV_NONE,
2322#else
2323 (char_u *)NULL, PV_NONE,
2324#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002325 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002326 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2327 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002328 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002329 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002330 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002331 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2332 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002333 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002334 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002335 (char_u *)VAR_WIN, PV_SCBIND,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002336 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002337 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2338 (char_u *)&p_sj, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002339 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002340 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
Bram Moolenaar375e3392019-01-31 18:26:10 +01002341 (char_u *)&p_so, PV_SO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002342 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002343 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002344 (char_u *)&p_sbo, PV_NONE,
2345 {(char_u *)"ver,jump", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002346 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002347 {"sections", "sect", P_STRING|P_VI_DEF,
2348 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002349 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002350 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002351 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2352 (char_u *)&p_secure, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002353 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002354 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002355 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002356 {(char_u *)"inclusive", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002357 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002358 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002359 (char_u *)&p_slm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002360 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002361 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002362#ifdef FEAT_SESSION
2363 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar4d8bac82018-03-09 21:33:34 +01002364 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize,terminal",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002365 (char_u *)0L}
2366#else
2367 (char_u *)NULL, PV_NONE,
2368 {(char_u *)0L, (char_u *)0L}
2369#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002370 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002371 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2372 (char_u *)&p_sh, PV_NONE,
2373 {
2374#ifdef VMS
2375 (char_u *)"-",
2376#else
Bram Moolenaar4f974752019-02-17 17:44:42 +01002377# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002378 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002379# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002380 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002381# endif
2382#endif /* VMS */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002383 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002384 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2385 (char_u *)&p_shcf, PV_NONE,
2386 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002387#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002388 (char_u *)"/c",
2389#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002390 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002391#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002392 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002393 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2394#ifdef FEAT_QUICKFIX
2395 (char_u *)&p_sp, PV_NONE,
2396 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002397#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002398 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002399#else
2400 (char_u *)">",
2401#endif
2402 (char_u *)0L}
2403#else
2404 (char_u *)NULL, PV_NONE,
2405 {(char_u *)0L, (char_u *)0L}
2406#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002407 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002408 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2409 (char_u *)&p_shq, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002410 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002411 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2412 (char_u *)&p_srr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002413 {(char_u *)">", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002414 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2415#ifdef BACKSLASH_IN_FILENAME
2416 (char_u *)&p_ssl, PV_NONE,
2417#else
2418 (char_u *)NULL, PV_NONE,
2419#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002420 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002421 {"shelltemp", "stmp", P_BOOL,
2422 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002423 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002424 {"shelltype", "st", P_NUM|P_VI_DEF,
2425#ifdef AMIGA
2426 (char_u *)&p_st, PV_NONE,
2427#else
2428 (char_u *)NULL, PV_NONE,
2429#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002430 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002431 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2432 (char_u *)&p_sxq, PV_NONE,
2433 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002434#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002435 (char_u *)"\"",
2436#else
2437 (char_u *)"",
2438#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002439 (char_u *)0L} SCTX_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002440 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2441 (char_u *)&p_sxe, PV_NONE,
2442 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01002443#if defined(MSWIN)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002444 (char_u *)"\"&|<>()@^",
2445#else
2446 (char_u *)"",
2447#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002448 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002449 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2450 (char_u *)&p_sr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002451 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002452 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2453 (char_u *)&p_sw, PV_SW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002454 {(char_u *)8L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002455 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2456 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar9dfa3132019-05-04 21:08:40 +02002457 {(char_u *)"S", (char_u *)"filnxtToOS"}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002458 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002459 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002460 (char_u *)&p_sn, PV_SN,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002461 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002462 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2463#ifdef FEAT_LINEBREAK
2464 (char_u *)&p_sbr, PV_NONE,
2465#else
2466 (char_u *)NULL, PV_NONE,
2467#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002468 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002469 {"showcmd", "sc", P_BOOL|P_VIM,
2470#ifdef FEAT_CMDL_INFO
2471 (char_u *)&p_sc, PV_NONE,
2472#else
2473 (char_u *)NULL, PV_NONE,
2474#endif
2475 {(char_u *)FALSE,
2476#ifdef UNIX
2477 (char_u *)FALSE
2478#else
2479 (char_u *)TRUE
2480#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002481 } SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002482 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2483 (char_u *)&p_sft, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002484 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002485 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2486 (char_u *)&p_sm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002487 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002488 {"showmode", "smd", P_BOOL|P_VIM,
2489 (char_u *)&p_smd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002490 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002491 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002492 (char_u *)&p_stal, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002493 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002494 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2495 (char_u *)&p_ss, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002496 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002497 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar375e3392019-01-31 18:26:10 +01002498 (char_u *)&p_siso, PV_SISO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002499 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002500 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2501#ifdef FEAT_SIGNS
2502 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002503 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002504#else
2505 (char_u *)NULL, PV_NONE,
2506 {(char_u *)NULL, (char_u *)0L}
2507#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002508 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002509 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2510 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002511 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002512 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2513 (char_u *)&p_scs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002514 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002515 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2516#ifdef FEAT_SMARTINDENT
2517 (char_u *)&p_si, PV_SI,
2518#else
2519 (char_u *)NULL, PV_NONE,
2520#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002521 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002522 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2523 (char_u *)&p_sta, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002524 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002525 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2526 (char_u *)&p_sts, PV_STS,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002527 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002528 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2529 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002530 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002531 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002532#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002533 (char_u *)VAR_WIN, PV_SPELL,
2534#else
2535 (char_u *)NULL, PV_NONE,
2536#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002537 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002538 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002539#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002540 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002541 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002542#else
2543 (char_u *)NULL, PV_NONE,
2544 {(char_u *)0L, (char_u *)0L}
2545#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002546 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002547 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2548 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002549#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002550 (char_u *)&p_spf, PV_SPF,
2551 {(char_u *)"", (char_u *)0L}
2552#else
2553 (char_u *)NULL, PV_NONE,
2554 {(char_u *)0L, (char_u *)0L}
2555#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002556 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002557 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2558 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002559#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002560 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002561 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002562#else
2563 (char_u *)NULL, PV_NONE,
2564 {(char_u *)0L, (char_u *)0L}
2565#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002566 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002567 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002568#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002569 (char_u *)&p_sps, PV_NONE,
2570 {(char_u *)"best", (char_u *)0L}
2571#else
2572 (char_u *)NULL, PV_NONE,
2573 {(char_u *)0L, (char_u *)0L}
2574#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002575 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002576 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002577 (char_u *)&p_sb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002578 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002579 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002580 (char_u *)&p_spr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002581 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002582 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2583 (char_u *)&p_sol, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002584 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02002585 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002586#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002587 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002588#else
2589 (char_u *)NULL, PV_NONE,
2590#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002591 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002592 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002593 (char_u *)&p_su, PV_NONE,
2594 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002595 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002596 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002597#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002598 (char_u *)&p_sua, PV_SUA,
2599 {(char_u *)"", (char_u *)0L}
2600#else
2601 (char_u *)NULL, PV_NONE,
2602 {(char_u *)0L, (char_u *)0L}
2603#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002604 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002605 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2606 (char_u *)&p_swf, PV_SWF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002607 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002608 {"swapsync", "sws", P_STRING|P_VI_DEF,
2609 (char_u *)&p_sws, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002610 {(char_u *)"fsync", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002611 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002612 (char_u *)&p_swb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002613 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002614 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2615#ifdef FEAT_SYN_HL
2616 (char_u *)&p_smc, PV_SMC,
2617 {(char_u *)3000L, (char_u *)0L}
2618#else
2619 (char_u *)NULL, PV_NONE,
2620 {(char_u *)0L, (char_u *)0L}
2621#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002622 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002623 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002624#ifdef FEAT_SYN_HL
2625 (char_u *)&p_syn, PV_SYN,
2626 {(char_u *)"", (char_u *)0L}
2627#else
2628 (char_u *)NULL, PV_NONE,
2629 {(char_u *)0L, (char_u *)0L}
2630#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002631 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02002632 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL|P_MLE,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002633#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002634 (char_u *)&p_tal, PV_NONE,
2635#else
2636 (char_u *)NULL, PV_NONE,
2637#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002638 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002639 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002640 (char_u *)&p_tpm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002641 {(char_u *)10L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002642 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2643 (char_u *)&p_ts, PV_TS,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002644 {(char_u *)8L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002645 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2646 (char_u *)&p_tbs, PV_NONE,
2647#ifdef VMS /* binary searching doesn't appear to work on VMS */
2648 {(char_u *)0L, (char_u *)0L}
2649#else
2650 {(char_u *)TRUE, (char_u *)0L}
2651#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002652 SCTX_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002653 {"tagcase", "tc", P_STRING|P_VIM,
2654 (char_u *)&p_tc, PV_TC,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002655 {(char_u *)"followic", (char_u *)"followic"} SCTX_INIT},
Bram Moolenaar45e18cb2019-04-28 18:05:35 +02002656 {"tagfunc", "tfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
2657#ifdef FEAT_EVAL
2658 (char_u *)&p_tfu, PV_TFU,
2659 {(char_u *)"", (char_u *)0L}
2660#else
2661 (char_u *)NULL, PV_NONE,
2662 {(char_u *)0L, (char_u *)0L}
2663#endif
2664 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002665 {"taglength", "tl", P_NUM|P_VI_DEF,
2666 (char_u *)&p_tl, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002667 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002668 {"tagrelative", "tr", P_BOOL|P_VIM,
2669 (char_u *)&p_tr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002670 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002671 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002672 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002673 {
2674#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2675 (char_u *)"./tags,./TAGS,tags,TAGS",
2676#else
2677 (char_u *)"./tags,tags",
2678#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002679 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002680 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2681 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002682 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002683 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002684#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002685 (char_u *)&p_tcldll, PV_NONE,
2686 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002687#else
2688 (char_u *)NULL, PV_NONE,
2689 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002690#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002691 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002692 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2693 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002694 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002695 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2696#ifdef FEAT_ARABIC
2697 (char_u *)&p_tbidi, PV_NONE,
2698#else
2699 (char_u *)NULL, PV_NONE,
2700#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002701 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002702 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002703 (char_u *)&p_tenc, PV_NONE,
2704 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002705 SCTX_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002706 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2707#ifdef FEAT_TERMGUICOLORS
2708 (char_u *)&p_tgc, PV_NONE,
2709 {(char_u *)FALSE, (char_u *)FALSE}
2710#else
2711 (char_u*)NULL, PV_NONE,
2712 {(char_u *)FALSE, (char_u *)FALSE}
2713#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002714 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002715 {"termwinkey", "twk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2716#ifdef FEAT_TERMINAL
2717 (char_u *)VAR_WIN, PV_TWK,
2718 {(char_u *)"", (char_u *)NULL}
2719#else
2720 (char_u *)NULL, PV_NONE,
2721 {(char_u *)NULL, (char_u *)0L}
2722#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002723 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002724 {"termwinscroll", "twsl", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2725#ifdef FEAT_TERMINAL
2726 (char_u *)&p_twsl, PV_TWSL,
2727 {(char_u *)10000L, (char_u *)10000L}
2728#else
2729 (char_u *)NULL, PV_NONE,
2730 {(char_u *)NULL, (char_u *)0L}
2731#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002732 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002733 {"termwinsize", "tws", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2734#ifdef FEAT_TERMINAL
2735 (char_u *)VAR_WIN, PV_TWS,
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002736 {(char_u *)"", (char_u *)NULL}
2737#else
2738 (char_u *)NULL, PV_NONE,
2739 {(char_u *)NULL, (char_u *)0L}
2740#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002741 SCTX_INIT},
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01002742 {"termwintype", "twt", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar4f974752019-02-17 17:44:42 +01002743#if defined(MSWIN) && defined(FEAT_TERMINAL)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01002744 (char_u *)&p_twt, PV_NONE,
2745 {(char_u *)"", (char_u *)NULL}
2746#else
2747 (char_u *)NULL, PV_NONE,
2748 {(char_u *)NULL, (char_u *)0L}
2749#endif
2750 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002751 {"terse", NULL, P_BOOL|P_VI_DEF,
2752 (char_u *)&p_terse, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002753 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002754 {"textauto", "ta", P_BOOL|P_VIM,
2755 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002756 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002757 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002758 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2759 (char_u *)&p_tx, PV_TX,
2760 {
2761#ifdef USE_CRNL
2762 (char_u *)TRUE,
2763#else
2764 (char_u *)FALSE,
2765#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002766 (char_u *)0L} SCTX_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002767 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002768 (char_u *)&p_tw, PV_TW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002769 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002770 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002771#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002772 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002773#else
2774 (char_u *)NULL, PV_NONE,
2775#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002776 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002777 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2778 (char_u *)&p_to, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002779 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002780 {"timeout", "to", P_BOOL|P_VI_DEF,
2781 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002782 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002783 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2784 (char_u *)&p_tm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002785 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002786 {"title", NULL, P_BOOL|P_VI_DEF,
2787#ifdef FEAT_TITLE
2788 (char_u *)&p_title, PV_NONE,
2789#else
2790 (char_u *)NULL, PV_NONE,
2791#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002792 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002793 {"titlelen", NULL, P_NUM|P_VI_DEF,
2794#ifdef FEAT_TITLE
2795 (char_u *)&p_titlelen, PV_NONE,
2796#else
2797 (char_u *)NULL, PV_NONE,
2798#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002799 {(char_u *)85L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002800 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002801#ifdef FEAT_TITLE
2802 (char_u *)&p_titleold, PV_NONE,
2803 {(char_u *)N_("Thanks for flying Vim"),
2804 (char_u *)0L}
2805#else
2806 (char_u *)NULL, PV_NONE,
2807 {(char_u *)0L, (char_u *)0L}
2808#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002809 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02002810 {"titlestring", NULL, P_STRING|P_VI_DEF|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002811#ifdef FEAT_TITLE
2812 (char_u *)&p_titlestring, PV_NONE,
2813#else
2814 (char_u *)NULL, PV_NONE,
2815#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002816 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002817 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar4f974752019-02-17 17:44:42 +01002818#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002819 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002820 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002821#else
2822 (char_u *)NULL, PV_NONE,
2823 {(char_u *)0L, (char_u *)0L}
2824#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002825 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002826 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002827#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002828 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002829 {(char_u *)"small", (char_u *)0L}
2830#else
2831 (char_u *)NULL, PV_NONE,
2832 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002833#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002834 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002835 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2836 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002837 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002838 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2839 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002840 {(char_u *)-1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002841 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2842 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002843 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002844 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2845 (char_u *)&p_tf, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002846 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002847 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2848#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2849 (char_u *)&p_ttym, PV_NONE,
2850#else
2851 (char_u *)NULL, PV_NONE,
2852#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002853 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002854 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2855 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002856 {(char_u *)999L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002857 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2858 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002859 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002860 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2861 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002862#ifdef FEAT_PERSISTENT_UNDO
2863 (char_u *)&p_udir, PV_NONE,
2864 {(char_u *)".", (char_u *)0L}
2865#else
2866 (char_u *)NULL, PV_NONE,
2867 {(char_u *)0L, (char_u *)0L}
2868#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002869 SCTX_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002870 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2871#ifdef FEAT_PERSISTENT_UNDO
2872 (char_u *)&p_udf, PV_UDF,
2873#else
2874 (char_u *)NULL, PV_NONE,
2875#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002876 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002877 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002878 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002879 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01002880#if defined(UNIX) || defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002881 (char_u *)1000L,
2882#else
2883 (char_u *)100L,
2884#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002885 (char_u *)0L} SCTX_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002886 {"undoreload", "ur", P_NUM|P_VI_DEF,
2887 (char_u *)&p_ur, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002888 { (char_u *)10000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002889 {"updatecount", "uc", P_NUM|P_VI_DEF,
2890 (char_u *)&p_uc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002891 {(char_u *)200L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002892 {"updatetime", "ut", P_NUM|P_VI_DEF,
2893 (char_u *)&p_ut, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002894 {(char_u *)4000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar04958cb2018-06-23 19:23:02 +02002895 {"varsofttabstop", "vsts", P_STRING|P_VI_DEF|P_VIM|P_COMMA,
2896#ifdef FEAT_VARTABS
2897 (char_u *)&p_vsts, PV_VSTS,
2898 {(char_u *)"", (char_u *)0L}
2899#else
2900 (char_u *)NULL, PV_NONE,
2901 {(char_u *)"", (char_u *)NULL}
2902#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002903 SCTX_INIT},
Bram Moolenaar04958cb2018-06-23 19:23:02 +02002904 {"vartabstop", "vts", P_STRING|P_VI_DEF|P_VIM|P_RBUF|P_COMMA,
2905#ifdef FEAT_VARTABS
2906 (char_u *)&p_vts, PV_VTS,
2907 {(char_u *)"", (char_u *)0L}
2908#else
2909 (char_u *)NULL, PV_NONE,
2910 {(char_u *)"", (char_u *)NULL}
2911#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002912 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002913 {"verbose", "vbs", P_NUM|P_VI_DEF,
2914 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002915 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002916 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2917 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002918 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002919 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2920#ifdef FEAT_SESSION
2921 (char_u *)&p_vdir, PV_NONE,
2922 {(char_u *)DFLT_VDIR, (char_u *)0L}
2923#else
2924 (char_u *)NULL, PV_NONE,
2925 {(char_u *)0L, (char_u *)0L}
2926#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002927 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002928 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002929#ifdef FEAT_SESSION
2930 (char_u *)&p_vop, PV_NONE,
Bram Moolenaar13e90412017-11-11 18:16:48 +01002931 {(char_u *)"folds,options,cursor,curdir",
2932 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002933#else
2934 (char_u *)NULL, PV_NONE,
2935 {(char_u *)0L, (char_u *)0L}
2936#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002937 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002938 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002939#ifdef FEAT_VIMINFO
2940 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002941#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002942 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002943#else
2944# ifdef AMIGA
2945 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002946 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002947# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002948 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002949# endif
2950#endif
2951#else
2952 (char_u *)NULL, PV_NONE,
2953 {(char_u *)0L, (char_u *)0L}
2954#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002955 SCTX_INIT},
Bram Moolenaarc229e542018-07-08 21:46:56 +02002956 {"viminfofile", "vif", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP
2957 |P_SECURE|P_VI_DEF,
Bram Moolenaarc4da1132017-07-15 19:39:43 +02002958#ifdef FEAT_VIMINFO
2959 (char_u *)&p_viminfofile, PV_NONE,
2960 {(char_u *)"", (char_u *)0L}
2961#else
2962 (char_u *)NULL, PV_NONE,
2963 {(char_u *)0L, (char_u *)0L}
2964#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002965 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002966 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2967 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002968 (char_u *)&p_ve, PV_NONE,
2969 {(char_u *)"", (char_u *)""}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002970 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002971 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2972 (char_u *)&p_vb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002973 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002974 {"w300", NULL, P_NUM|P_VI_DEF,
2975 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002976 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002977 {"w1200", NULL, P_NUM|P_VI_DEF,
2978 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002979 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002980 {"w9600", NULL, P_NUM|P_VI_DEF,
2981 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002982 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002983 {"warn", NULL, P_BOOL|P_VI_DEF,
2984 (char_u *)&p_warn, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002985 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002986 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2987 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002988 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002989 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002990 (char_u *)&p_ww, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002991 {(char_u *)"", (char_u *)"b,s"} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002992 {"wildchar", "wc", P_NUM|P_VIM,
2993 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002994 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002995 SCTX_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002996 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002997 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002998 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002999 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003000#ifdef FEAT_WILDIGN
3001 (char_u *)&p_wig, PV_NONE,
3002#else
3003 (char_u *)NULL, PV_NONE,
3004#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003005 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003006 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3007 (char_u *)&p_wic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003008 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003009 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
3010#ifdef FEAT_WILDMENU
3011 (char_u *)&p_wmnu, PV_NONE,
3012#else
3013 (char_u *)NULL, PV_NONE,
3014#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003015 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003016 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003017 (char_u *)&p_wim, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003018 {(char_u *)"full", (char_u *)0L} SCTX_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003019 {"wildoptions", "wop", P_STRING|P_VI_DEF,
3020#ifdef FEAT_CMDL_COMPL
3021 (char_u *)&p_wop, PV_NONE,
3022 {(char_u *)"", (char_u *)0L}
3023#else
3024 (char_u *)NULL, PV_NONE,
3025 {(char_u *)NULL, (char_u *)0L}
3026#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003027 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003028 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3029#ifdef FEAT_WAK
3030 (char_u *)&p_wak, PV_NONE,
3031 {(char_u *)"menu", (char_u *)0L}
3032#else
3033 (char_u *)NULL, PV_NONE,
3034 {(char_u *)NULL, (char_u *)0L}
3035#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003036 SCTX_INIT},
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003037 {"wincolor", "wcr", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
3038 (char_u *)VAR_WIN, PV_WCR,
3039 {(char_u *)"", (char_u *)NULL}
3040 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003041 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003042 (char_u *)&p_window, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003043 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003044 {"winheight", "wh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003045 (char_u *)&p_wh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003046 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003047 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003048 (char_u *)VAR_WIN, PV_WFH,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003049 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003050 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003051 (char_u *)VAR_WIN, PV_WFW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003052 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003053 {"winminheight", "wmh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003054 (char_u *)&p_wmh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003055 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003056 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003057 (char_u *)&p_wmw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003058 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003059 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar4f974752019-02-17 17:44:42 +01003060#if defined(MSWIN) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003061 (char_u *)&p_winptydll, PV_NONE, {
3062# ifdef _WIN64
3063 (char_u *)"winpty64.dll",
3064# else
3065 (char_u *)"winpty32.dll",
3066# endif
3067 (char_u *)0L}
3068#else
3069 (char_u *)NULL, PV_NONE,
3070 {(char_u *)0L, (char_u *)0L}
3071#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003072 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003073 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003074 (char_u *)&p_wiw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003075 {(char_u *)20L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003076 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3077 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003078 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003079 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3080 (char_u *)&p_wm, PV_WM,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003081 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003082 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3083 (char_u *)&p_ws, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003084 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003085 {"write", NULL, P_BOOL|P_VI_DEF,
3086 (char_u *)&p_write, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003087 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003088 {"writeany", "wa", P_BOOL|P_VI_DEF,
3089 (char_u *)&p_wa, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003090 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003091 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3092 (char_u *)&p_wb, PV_NONE,
3093 {
3094#ifdef FEAT_WRITEBACKUP
3095 (char_u *)TRUE,
3096#else
3097 (char_u *)FALSE,
3098#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003099 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003100 {"writedelay", "wd", P_NUM|P_VI_DEF,
3101 (char_u *)&p_wd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003102 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003103
3104/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003105#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003106 (char_u *)&vvv, PV_NONE, \
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003107 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003108
3109 p_term("t_AB", T_CAB)
3110 p_term("t_AF", T_CAF)
3111 p_term("t_AL", T_CAL)
3112 p_term("t_al", T_AL)
3113 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003114 p_term("t_BE", T_BE)
3115 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003116 p_term("t_cd", T_CD)
3117 p_term("t_ce", T_CE)
3118 p_term("t_cl", T_CL)
3119 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003120 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003121 p_term("t_Co", T_CCO)
3122 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003123 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003124 p_term("t_cs", T_CS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003125 p_term("t_CV", T_CSV)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003126 p_term("t_da", T_DA)
3127 p_term("t_db", T_DB)
3128 p_term("t_DL", T_CDL)
3129 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003130 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003131 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003132 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003133 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003134 p_term("t_IE", T_CIE)
3135 p_term("t_IS", T_CIS)
3136 p_term("t_ke", T_KE)
3137 p_term("t_ks", T_KS)
3138 p_term("t_le", T_LE)
3139 p_term("t_mb", T_MB)
3140 p_term("t_md", T_MD)
3141 p_term("t_me", T_ME)
3142 p_term("t_mr", T_MR)
3143 p_term("t_ms", T_MS)
3144 p_term("t_nd", T_ND)
3145 p_term("t_op", T_OP)
Bram Moolenaara20f83d2017-10-15 13:35:01 +02003146 p_term("t_RF", T_RFG)
Bram Moolenaare5401222015-06-25 19:16:56 +02003147 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003148 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003149 p_term("t_RI", T_CRI)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003150 p_term("t_Ri", T_SRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003151 p_term("t_RS", T_CRS)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003152 p_term("t_RT", T_CRT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003153 p_term("t_RV", T_CRV)
3154 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003155 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003156 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003157 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003158 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003159 p_term("t_SI", T_CSI)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003160 p_term("t_Si", T_SSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003161 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003162 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003163 p_term("t_sr", T_SR)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003164 p_term("t_ST", T_CST)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003165 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003166 p_term("t_te", T_TE)
3167 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003168 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003169 p_term("t_ts", T_TS)
3170 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003171 p_term("t_ue", T_UE)
3172 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003173 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003174 p_term("t_vb", T_VB)
3175 p_term("t_ve", T_VE)
3176 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003177 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003178 p_term("t_vs", T_VS)
3179 p_term("t_WP", T_CWP)
3180 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003181 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003182 p_term("t_xs", T_XS)
3183 p_term("t_ZH", T_CZH)
3184 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003185 p_term("t_8f", T_8F)
3186 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003187
3188/* terminal key codes are not in here */
3189
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003190 /* end marker */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003191 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCTX_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003192};
3193
3194#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3195
Bram Moolenaar071d4272004-06-13 20:20:40 +00003196static char *(p_ambw_values[]) = {"single", "double", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003197static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003198static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003199static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003200#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003201static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003202#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003203#ifdef FEAT_CMDL_COMPL
3204static char *(p_wop_values[]) = {"tagfile", NULL};
3205#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003206#ifdef FEAT_WAK
3207static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3208#endif
3209static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003210static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3211static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003212static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003213#ifdef FEAT_BROWSE
3214static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3215#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003216static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
Bram Moolenaar57657d82006-04-21 22:12:41 +00003217static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003218static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003219static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", "prompt", "popup", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003220static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003221static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3222#ifdef FEAT_FOLDING
3223static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003224# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003225 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003226# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003227 NULL};
3228static char *(p_fcl_values[]) = {"all", NULL};
3229#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003230#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003231static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003232#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003233#ifdef FEAT_SIGNS
3234static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3235#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01003236#if defined(MSWIN) && defined(FEAT_TERMINAL)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01003237static char *(p_twt_values[]) = {"winpty", "conpty", "", NULL};
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01003238#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003239
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003240static void set_options_default(int opt_flags);
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003241static void set_string_default_esc(char *name, char_u *val, int escape);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003242static char_u *term_bg_default(void);
Bram Moolenaar916a8182018-11-25 02:18:29 +01003243static void did_set_option(int opt_idx, int opt_flags, int new_value, int value_checked);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003244static char_u *option_expand(int opt_idx, char_u *val);
3245static void didset_options(void);
3246static void didset_options2(void);
3247static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003248#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003249static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003250#else
3251# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3252#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003253static void set_string_option_global(int opt_idx, char_u **varp);
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003254static char *did_set_string_option(int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char *errbuf, int opt_flags, int *value_checked);
3255static char *set_chars_option(char_u **varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003256#ifdef FEAT_CLIPBOARD
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003257static char *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003258#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003259#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003260static char *did_set_spell_option(int is_spellfile);
3261static char *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003262#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003263#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003264static void set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003265#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003266static char *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3267static char *set_num_option(int opt_idx, char_u *varp, long value, char *errbuf, size_t errbuflen, int opt_flags);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003268static void check_redraw(long_u flags);
3269static int findoption(char_u *);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02003270static int find_key_option(char_u *arg_arg, int has_lt);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003271static void showoptions(int all, int opt_flags);
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02003272static int optval_default(struct vimoption *, char_u *varp, int compatible);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003273static void showoneopt(struct vimoption *, int opt_flags);
Bram Moolenaared18f2c2019-01-24 20:30:52 +01003274static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, long_u flags);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003275static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3276static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3277static int istermoption(struct vimoption *);
3278static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3279static char_u *get_varp(struct vimoption *);
3280static void option_value2string(struct vimoption *, int opt_flags);
3281static void check_winopt(winopt_T *wop);
3282static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003283#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003284static void langmap_init(void);
3285static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003286#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003287static void paste_option_changed(void);
3288static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003289#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003290static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003291#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003292static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3293static int check_opt_strings(char_u *val, char **values, int);
3294static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003295#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003296static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003297#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003298
3299/*
3300 * Initialize the options, first part.
3301 *
3302 * Called only once from main(), just after creating the first buffer.
Bram Moolenaar07268702018-03-01 21:57:32 +01003303 * If "clean_arg" is TRUE Vim was started with --clean.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003304 */
3305 void
Bram Moolenaar07268702018-03-01 21:57:32 +01003306set_init_1(int clean_arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003307{
3308 char_u *p;
3309 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003310 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003311
3312#ifdef FEAT_LANGMAP
3313 langmap_init();
3314#endif
3315
3316 /* Be Vi compatible by default */
3317 p_cp = TRUE;
3318
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003319 /* Use POSIX compatibility when $VIM_POSIX is set. */
3320 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003321 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003322 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar9dfa3132019-05-04 21:08:40 +02003323 set_string_default("shm", (char_u *)SHM_POSIX);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003324 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003325
Bram Moolenaar071d4272004-06-13 20:20:40 +00003326 /*
3327 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003328 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003329 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003330 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003331#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003332 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003333 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003334#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003335 )
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003336 set_string_default_esc("sh", p, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003337
3338#ifdef FEAT_WILDIGN
3339 /*
3340 * Set the default for 'backupskip' to include environment variables for
3341 * temp files.
3342 */
3343 {
3344# ifdef UNIX
3345 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3346# else
3347 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3348# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003349 int len;
3350 garray_T ga;
3351 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003352
3353 ga_init2(&ga, 1, 100);
3354 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3355 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003356 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003357# ifdef UNIX
3358 if (*names[n] == NUL)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003359# ifdef MACOS_X
3360 p = (char_u *)"/private/tmp";
3361# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003362 p = (char_u *)"/tmp";
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003363# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003364 else
3365# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003366 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003367 if (p != NULL && *p != NUL)
3368 {
3369 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003370 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003371 if (ga_grow(&ga, len) == OK)
3372 {
3373 if (ga.ga_len > 0)
3374 STRCAT(ga.ga_data, ",");
3375 STRCAT(ga.ga_data, p);
3376 add_pathsep(ga.ga_data);
3377 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003378 ga.ga_len += len;
3379 }
3380 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003381 if (mustfree)
3382 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003383 }
3384 if (ga.ga_data != NULL)
3385 {
3386 set_string_default("bsk", ga.ga_data);
3387 vim_free(ga.ga_data);
3388 }
3389 }
3390#endif
3391
3392 /*
3393 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3394 */
3395 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003396 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003397 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003398#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3399 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3400#endif
3401 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003402#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003403 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003404 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003405#else
3406# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003407 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003408 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003409# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003410 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003411# endif
3412#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003413 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003414 opt_idx = findoption((char_u *)"maxmem");
3415 if (opt_idx >= 0)
3416 {
3417#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003418 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3419 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003420#endif
3421 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3422 }
3423 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003424 }
3425
Bram Moolenaar071d4272004-06-13 20:20:40 +00003426#ifdef FEAT_SEARCHPATH
3427 {
3428 char_u *cdpath;
3429 char_u *buf;
3430 int i;
3431 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003432 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003433
3434 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003435 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003436 if (cdpath != NULL)
3437 {
Bram Moolenaar964b3742019-05-24 18:54:09 +02003438 buf = alloc((STRLEN(cdpath) << 1) + 2);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003439 if (buf != NULL)
3440 {
3441 buf[0] = ','; /* start with ",", current dir first */
3442 j = 1;
3443 for (i = 0; cdpath[i] != NUL; ++i)
3444 {
3445 if (vim_ispathlistsep(cdpath[i]))
3446 buf[j++] = ',';
3447 else
3448 {
3449 if (cdpath[i] == ' ' || cdpath[i] == ',')
3450 buf[j++] = '\\';
3451 buf[j++] = cdpath[i];
3452 }
3453 }
3454 buf[j] = NUL;
3455 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003456 if (opt_idx >= 0)
3457 {
3458 options[opt_idx].def_val[VI_DEFAULT] = buf;
3459 options[opt_idx].flags |= P_DEF_ALLOCED;
3460 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003461 else
3462 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003463 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003464 if (mustfree)
3465 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003466 }
3467 }
3468#endif
3469
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003470#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003471 /* Set print encoding on platforms that don't default to latin1 */
3472 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003473# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003474 (char_u *)"cp1252"
3475# else
3476# ifdef VMS
3477 (char_u *)"dec-mcs"
3478# else
3479# ifdef EBCDIC
3480 (char_u *)"ebcdic-uk"
3481# else
3482# ifdef MAC
3483 (char_u *)"mac-roman"
3484# else /* HPUX */
3485 (char_u *)"hp-roman8"
3486# endif
3487# endif
3488# endif
3489# endif
3490 );
3491#endif
3492
3493#ifdef FEAT_POSTSCRIPT
3494 /* 'printexpr' must be allocated to be able to evaluate it. */
3495 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003496# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003497 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003498# else
3499# ifdef VMS
3500 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3501
3502# else
3503 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3504# endif
3505# endif
3506 );
3507#endif
3508
3509 /*
3510 * Set all the options (except the terminal options) to their default
3511 * value. Also set the global value for local options.
3512 */
3513 set_options_default(0);
3514
Bram Moolenaar07268702018-03-01 21:57:32 +01003515#ifdef CLEAN_RUNTIMEPATH
3516 if (clean_arg)
3517 {
3518 opt_idx = findoption((char_u *)"runtimepath");
3519 if (opt_idx >= 0)
3520 {
3521 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3522 p_rtp = (char_u *)CLEAN_RUNTIMEPATH;
3523 }
3524 opt_idx = findoption((char_u *)"packpath");
3525 if (opt_idx >= 0)
3526 {
3527 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3528 p_pp = (char_u *)CLEAN_RUNTIMEPATH;
3529 }
3530 }
3531#endif
3532
Bram Moolenaar071d4272004-06-13 20:20:40 +00003533#ifdef FEAT_GUI
3534 if (found_reverse_arg)
3535 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3536#endif
3537
3538 curbuf->b_p_initialized = TRUE;
3539 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003540 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003541 check_buf_options(curbuf);
3542 check_win_options(curwin);
3543 check_options();
3544
3545 /* Must be before option_expand(), because that one needs vim_isIDc() */
3546 didset_options();
3547
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003548#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003549 /* Use the current chartab for the generic chartab. This is not in
3550 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003551 init_spell_chartab();
3552#endif
3553
Bram Moolenaar071d4272004-06-13 20:20:40 +00003554 /*
3555 * Expand environment variables and things like "~" for the defaults.
3556 * If option_expand() returns non-NULL the variable is expanded. This can
3557 * only happen for non-indirect options.
3558 * Also set the default to the expanded value, so ":set" does not list
3559 * them.
3560 * Don't set the P_ALLOCED flag, because we don't want to free the
3561 * default.
3562 */
3563 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3564 {
3565 if ((options[opt_idx].flags & P_GETTEXT)
3566 && options[opt_idx].var != NULL)
3567 p = (char_u *)_(*(char **)options[opt_idx].var);
3568 else
3569 p = option_expand(opt_idx, NULL);
3570 if (p != NULL && (p = vim_strsave(p)) != NULL)
3571 {
3572 *(char_u **)options[opt_idx].var = p;
3573 /* VIMEXP
3574 * Defaults for all expanded options are currently the same for Vi
3575 * and Vim. When this changes, add some code here! Also need to
3576 * split P_DEF_ALLOCED in two.
3577 */
3578 if (options[opt_idx].flags & P_DEF_ALLOCED)
3579 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3580 options[opt_idx].def_val[VI_DEFAULT] = p;
3581 options[opt_idx].flags |= P_DEF_ALLOCED;
3582 }
3583 }
3584
Bram Moolenaar071d4272004-06-13 20:20:40 +00003585 save_file_ff(curbuf); /* Buffer is unchanged */
3586
Bram Moolenaar071d4272004-06-13 20:20:40 +00003587#if defined(FEAT_ARABIC)
3588 /* Detect use of mlterm.
3589 * Mlterm is a terminal emulator akin to xterm that has some special
3590 * abilities (bidi namely).
3591 * NOTE: mlterm's author is being asked to 'set' a variable
3592 * instead of an environment variable due to inheritance.
3593 */
3594 if (mch_getenv((char_u *)"MLTERM") != NULL)
3595 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3596#endif
3597
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003598 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003599
Bram Moolenaar4f974752019-02-17 17:44:42 +01003600# if defined(MSWIN) && defined(FEAT_GETTEXT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003601 /*
3602 * If $LANG isn't set, try to get a good value for it. This makes the
3603 * right language be used automatically. Don't do this for English.
3604 */
3605 if (mch_getenv((char_u *)"LANG") == NULL)
3606 {
3607 char buf[20];
3608
3609 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3610 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3611 * only the first two. */
3612 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3613 (LPTSTR)buf, 20);
3614 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3615 {
3616 /* There are a few exceptions (probably more) */
3617 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3618 STRCPY(buf, "zh_TW");
3619 else if (STRNICMP(buf, "chs", 3) == 0
3620 || STRNICMP(buf, "zhc", 3) == 0)
3621 STRCPY(buf, "zh_CN");
3622 else if (STRNICMP(buf, "jp", 2) == 0)
3623 STRCPY(buf, "ja");
3624 else
3625 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003626 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003627 }
3628 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003629# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003630# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003631 /* Moved to os_mac_conv.c to avoid dependency problems. */
3632 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003633# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003634# endif
3635
3636 /* enc_locale() will try to find the encoding of the current locale. */
3637 p = enc_locale();
3638 if (p != NULL)
3639 {
3640 char_u *save_enc;
3641
3642 /* Try setting 'encoding' and check if the value is valid.
3643 * If not, go back to the default "latin1". */
3644 save_enc = p_enc;
3645 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003646 if (STRCMP(p_enc, "gb18030") == 0)
3647 {
3648 /* We don't support "gb18030", but "cp936" is a good substitute
3649 * for practical purposes, thus use that. It's not an alias to
3650 * still support conversion between gb18030 and utf-8. */
3651 p_enc = vim_strsave((char_u *)"cp936");
3652 vim_free(p);
3653 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003654 if (mb_init() == NULL)
3655 {
3656 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003657 if (opt_idx >= 0)
3658 {
3659 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3660 options[opt_idx].flags |= P_DEF_ALLOCED;
3661 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003662
Bram Moolenaard0573012017-10-28 21:11:06 +02003663#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003664 if (STRCMP(p_enc, "latin1") == 0 || enc_utf8)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003665 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003666 /* Adjust the default for 'isprint' and 'iskeyword' to match
3667 * latin1. Also set the defaults for when 'nocompatible' is
3668 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003669 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003670 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003671 set_string_option_direct((char_u *)"isk", -1,
3672 ISK_LATIN1, OPT_FREE, SID_NONE);
3673 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003674 if (opt_idx >= 0)
3675 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003676 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003677 if (opt_idx >= 0)
3678 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003679 (void)init_chartab();
3680 }
3681#endif
3682
Bram Moolenaarafde13b2019-04-28 19:46:49 +02003683#if defined(MSWIN) && (!defined(FEAT_GUI) || defined(VIMDLL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003684 /* Win32 console: When GetACP() returns a different value from
3685 * GetConsoleCP() set 'termencoding'. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02003686 if (
3687# ifdef VIMDLL
3688 (!gui.in_use && !gui.starting) &&
3689# endif
3690 GetACP() != GetConsoleCP())
Bram Moolenaar071d4272004-06-13 20:20:40 +00003691 {
3692 char buf[50];
3693
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01003694 /* Win32 console: In ConPTY, GetConsoleCP() returns zero.
3695 * Use an alternative value. */
3696 if (GetConsoleCP() == 0)
3697 sprintf(buf, "cp%ld", (long)GetACP());
3698 else
3699 sprintf(buf, "cp%ld", (long)GetConsoleCP());
Bram Moolenaar071d4272004-06-13 20:20:40 +00003700 p_tenc = vim_strsave((char_u *)buf);
3701 if (p_tenc != NULL)
3702 {
3703 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003704 if (opt_idx >= 0)
3705 {
3706 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3707 options[opt_idx].flags |= P_DEF_ALLOCED;
3708 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003709 convert_setup(&input_conv, p_tenc, p_enc);
3710 convert_setup(&output_conv, p_enc, p_tenc);
3711 }
3712 else
3713 p_tenc = empty_option;
3714 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003715#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01003716#if defined(MSWIN)
Bram Moolenaar05159a02005-02-26 23:04:13 +00003717 /* $HOME may have characters in active code page. */
3718 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003719#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003720 }
3721 else
3722 {
3723 vim_free(p_enc);
3724 p_enc = save_enc;
3725 }
3726 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003727
3728#ifdef FEAT_MULTI_LANG
3729 /* Set the default for 'helplang'. */
3730 set_helplang_default(get_mess_lang());
3731#endif
3732}
3733
3734/*
3735 * Set an option to its default value.
3736 * This does not take care of side effects!
3737 */
3738 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003739set_option_default(
3740 int opt_idx,
3741 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3742 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003743{
3744 char_u *varp; /* pointer to variable for current option */
3745 int dvi; /* index in def_val[] */
3746 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003747 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003748 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3749
3750 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3751 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003752 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003753 {
3754 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3755 if (flags & P_STRING)
3756 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003757 /* Use set_string_option_direct() for local options to handle
3758 * freeing and allocating the value. */
3759 if (options[opt_idx].indir != PV_NONE)
3760 set_string_option_direct(NULL, opt_idx,
3761 options[opt_idx].def_val[dvi], opt_flags, 0);
3762 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003763 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003764 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3765 free_string_option(*(char_u **)(varp));
3766 *(char_u **)varp = options[opt_idx].def_val[dvi];
3767 options[opt_idx].flags &= ~P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003768 }
3769 }
3770 else if (flags & P_NUM)
3771 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003772 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003773 win_comp_scroll(curwin);
3774 else
3775 {
Bram Moolenaar375e3392019-01-31 18:26:10 +01003776 long def_val = (long)(long_i)options[opt_idx].def_val[dvi];
3777
3778 if ((long *)varp == &curwin->w_p_so
3779 || (long *)varp == &curwin->w_p_siso)
3780 // 'scrolloff' and 'sidescrolloff' local values have a
3781 // different default value than the global default.
3782 *(long *)varp = -1;
3783 else
3784 *(long *)varp = def_val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003785 /* May also set global value for local option. */
3786 if (both)
3787 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
Bram Moolenaar375e3392019-01-31 18:26:10 +01003788 def_val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003789 }
3790 }
3791 else /* P_BOOL */
3792 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003793 /* the cast to long is required for Manx C, long_i is needed for
3794 * MSVC */
3795 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003796#ifdef UNIX
3797 /* 'modeline' defaults to off for root */
3798 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3799 *(int *)varp = FALSE;
3800#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003801 /* May also set global value for local option. */
3802 if (both)
3803 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3804 *(int *)varp;
3805 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003806
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003807 /* The default value is not insecure. */
3808 flagsp = insecure_flag(opt_idx, opt_flags);
3809 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003810 }
3811
3812#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003813 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003814#endif
3815}
3816
3817/*
3818 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003819 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003820 */
3821 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003822set_options_default(
3823 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003824{
3825 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003826 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003827 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003828
3829 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003830 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003831 && (opt_flags == 0
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003832 || (options[i].var != (char_u *)&p_enc
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003833# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003834 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003835 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003836# endif
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003837 )))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003838 set_option_default(i, opt_flags, p_cp);
3839
Bram Moolenaar071d4272004-06-13 20:20:40 +00003840 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003841 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003842 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003843#ifdef FEAT_CINDENT
3844 parse_cino(curbuf);
3845#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003846}
3847
3848/*
3849 * Set the Vi-default value of a string option.
3850 * Used for 'sh', 'backupskip' and 'term'.
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003851 * When "escape" is TRUE escape spaces with a backslash.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003852 */
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003853 static void
3854set_string_default_esc(char *name, char_u *val, int escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003855{
3856 char_u *p;
3857 int opt_idx;
3858
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003859 if (escape && vim_strchr(val, ' ') != NULL)
3860 p = vim_strsave_escaped(val, (char_u *)" ");
3861 else
3862 p = vim_strsave(val);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003863 if (p != NULL) /* we don't want a NULL */
3864 {
3865 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003866 if (opt_idx >= 0)
3867 {
3868 if (options[opt_idx].flags & P_DEF_ALLOCED)
3869 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3870 options[opt_idx].def_val[VI_DEFAULT] = p;
3871 options[opt_idx].flags |= P_DEF_ALLOCED;
3872 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003873 }
3874}
3875
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003876 void
3877set_string_default(char *name, char_u *val)
3878{
3879 set_string_default_esc(name, val, FALSE);
3880}
3881
Bram Moolenaar071d4272004-06-13 20:20:40 +00003882/*
3883 * Set the Vi-default value of a number option.
3884 * Used for 'lines' and 'columns'.
3885 */
3886 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003887set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003888{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003889 int opt_idx;
3890
3891 opt_idx = findoption((char_u *)name);
3892 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003893 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003894}
3895
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02003896/*
3897 * Set all window-local and buffer-local options to the Vim default.
3898 * local-global options will use the global value.
3899 */
3900 void
3901set_local_options_default(win_T *wp)
3902{
3903 win_T *save_curwin = curwin;
3904 int i;
3905
3906 curwin = wp;
3907 curbuf = curwin->w_buffer;
3908 block_autocmds();
3909
3910 for (i = 0; !istermoption(&options[i]); i++)
3911 {
3912 struct vimoption *p = &(options[i]);
3913 char_u *varp = get_varp_scope(p, OPT_LOCAL);
3914
3915 if (p->indir != PV_NONE
3916 && !(options[i].flags & P_NODEFAULT)
3917 && !optval_default(p, varp, FALSE))
3918 set_option_default(i, OPT_LOCAL, FALSE);
3919 }
3920
3921 unblock_autocmds();
3922 curwin = save_curwin;
3923 curbuf = curwin->w_buffer;
3924}
3925
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003926#if defined(EXITFREE) || defined(PROTO)
3927/*
3928 * Free all options.
3929 */
3930 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003931free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003932{
3933 int i;
3934
3935 for (i = 0; !istermoption(&options[i]); i++)
3936 {
3937 if (options[i].indir == PV_NONE)
3938 {
3939 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003940 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003941 free_string_option(*(char_u **)options[i].var);
3942 if (options[i].flags & P_DEF_ALLOCED)
3943 free_string_option(options[i].def_val[VI_DEFAULT]);
3944 }
3945 else if (options[i].var != VAR_WIN
3946 && (options[i].flags & P_STRING))
3947 /* buffer-local option: free global value */
3948 free_string_option(*(char_u **)options[i].var);
3949 }
3950}
3951#endif
3952
3953
Bram Moolenaar071d4272004-06-13 20:20:40 +00003954/*
3955 * Initialize the options, part two: After getting Rows and Columns and
3956 * setting 'term'.
3957 */
3958 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003959set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003960{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003961 int idx;
3962
Bram Moolenaar071d4272004-06-13 20:20:40 +00003963 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003964 * 'scroll' defaults to half the window height. The stored default is zero,
3965 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003966 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003967 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003968 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003969 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003970 comp_col();
3971
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003972 /*
3973 * 'window' is only for backwards compatibility with Vi.
3974 * Default is Rows - 1.
3975 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003976 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003977 p_window = Rows - 1;
3978 set_number_default("window", Rows - 1);
3979
Bram Moolenaarf740b292006-02-16 22:11:02 +00003980 /* For DOS console the default is always black. */
Bram Moolenaar4f974752019-02-17 17:44:42 +01003981#if !((defined(MSWIN)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003982 /*
3983 * If 'background' wasn't set by the user, try guessing the value,
3984 * depending on the terminal name. Only need to check for terminals
3985 * with a dark background, that can handle color.
3986 */
3987 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003988 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3989 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003990 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003991 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003992 /* don't mark it as set, when starting the GUI it may be
3993 * changed again */
3994 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003995 }
3996#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003997
3998#ifdef CURSOR_SHAPE
3999 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
4000#endif
4001#ifdef FEAT_MOUSESHAPE
4002 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
4003#endif
4004#ifdef FEAT_PRINTER
4005 (void)parse_printoptions(); /* parse 'printoptions' default value */
4006#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004007}
4008
4009/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00004010 * Return "dark" or "light" depending on the kind of terminal.
4011 * This is just guessing! Recognized are:
4012 * "linux" Linux console
4013 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004014 * "cygwin.*" Cygwin shell
4015 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00004016 * We also check the COLORFGBG environment variable, which is set by
4017 * rxvt and derivatives. This variable contains either two or three
4018 * values separated by semicolons; we want the last value in either
4019 * case. If this value is 0-6 or 8, our background is dark.
4020 */
4021 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004022term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00004023{
Bram Moolenaar4f974752019-02-17 17:44:42 +01004024#if defined(MSWIN)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004025 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00004026 return (char_u *)"dark";
4027#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00004028 char_u *p;
4029
Bram Moolenaarf740b292006-02-16 22:11:02 +00004030 if (STRCMP(T_NAME, "linux") == 0
4031 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004032 || STRNCMP(T_NAME, "cygwin", 6) == 0
4033 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00004034 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
4035 && (p = vim_strrchr(p, ';')) != NULL
4036 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
4037 && p[2] == NUL))
4038 return (char_u *)"dark";
4039 return (char_u *)"light";
4040#endif
4041}
4042
4043/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004044 * Initialize the options, part three: After reading the .vimrc
4045 */
4046 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004047set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004048{
Bram Moolenaar4f974752019-02-17 17:44:42 +01004049#if defined(UNIX) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004050/*
4051 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4052 * This is done after other initializations, where 'shell' might have been
4053 * set, but only if they have not been set before.
4054 */
4055 char_u *p;
4056 int idx_srr;
4057 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004058# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004059 int idx_sp;
4060 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004061# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004062
4063 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004064 if (idx_srr < 0)
4065 do_srr = FALSE;
4066 else
4067 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004068# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004069 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004070 if (idx_sp < 0)
4071 do_sp = FALSE;
4072 else
4073 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004074# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004075 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004076 if (p != NULL)
4077 {
4078 /*
4079 * Default for p_sp is "| tee", for p_srr is ">".
4080 * For known shells it is changed here to include stderr.
4081 */
4082 if ( fnamecmp(p, "csh") == 0
4083 || fnamecmp(p, "tcsh") == 0
Bram Moolenaar4f974752019-02-17 17:44:42 +01004084# if defined(MSWIN) // also check with .exe extension
Bram Moolenaar071d4272004-06-13 20:20:40 +00004085 || fnamecmp(p, "csh.exe") == 0
4086 || fnamecmp(p, "tcsh.exe") == 0
4087# endif
4088 )
4089 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004090# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004091 if (do_sp)
4092 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01004093# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004094 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004095# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004096 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004097# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004098 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4099 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004100# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004101 if (do_srr)
4102 {
4103 p_srr = (char_u *)">&";
4104 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4105 }
4106 }
4107 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004108 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004109 if ( fnamecmp(p, "sh") == 0
4110 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004111 || fnamecmp(p, "mksh") == 0
4112 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004113 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004114 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004115 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004116 || fnamecmp(p, "fish") == 0
Bram Moolenaar4f974752019-02-17 17:44:42 +01004117# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004118 || fnamecmp(p, "cmd") == 0
4119 || fnamecmp(p, "sh.exe") == 0
4120 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004121 || fnamecmp(p, "mksh.exe") == 0
4122 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004123 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004124 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004125 || fnamecmp(p, "bash.exe") == 0
4126 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004127# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004128 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004129 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004130# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004131 if (do_sp)
4132 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01004133# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004134 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004135# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004136 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004137# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004138 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4139 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004140# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004141 if (do_srr)
4142 {
4143 p_srr = (char_u *)">%s 2>&1";
4144 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4145 }
4146 }
4147 vim_free(p);
4148 }
4149#endif
4150
Bram Moolenaar4f974752019-02-17 17:44:42 +01004151#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004152 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004153 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4154 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004155 * This is done after other initializations, where 'shell' might have been
4156 * set, but only if they have not been set before. Default for p_shcf is
4157 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004158 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004159 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004160 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004161 {
4162 int idx3;
4163
4164 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004165 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004166 {
4167 p_shcf = (char_u *)"-c";
4168 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4169 }
4170
Bram Moolenaar071d4272004-06-13 20:20:40 +00004171 /* Somehow Win32 requires the quotes around the redirection too */
4172 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004173 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004174 {
4175 p_sxq = (char_u *)"\"";
4176 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4177 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004178 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004179 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4180 {
4181 int idx3;
4182
4183 /*
4184 * cmd.exe on Windows will strip the first and last double quote given
4185 * on the command line, e.g. most of the time things like:
4186 * cmd /c "my path/to/echo" "my args to echo"
4187 * become:
4188 * my path/to/echo" "my args to echo
4189 * when executed.
4190 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004191 * To avoid this, set shellxquote to surround the command in
4192 * parenthesis. This appears to make most commands work, without
4193 * breaking commands that worked previously, such as
4194 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004195 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004196 idx3 = findoption((char_u *)"sxq");
4197 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4198 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004199 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004200 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4201 }
4202
Bram Moolenaara64ba222012-02-12 23:23:31 +01004203 idx3 = findoption((char_u *)"shcf");
4204 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4205 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004206 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004207 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4208 }
4209 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004210#endif
4211
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004212 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004213 {
4214 int idx_ffs = findoption((char_u *)"ffs");
4215
4216 /* Apply the first entry of 'fileformats' to the initial buffer. */
4217 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4218 set_fileformat(default_fileformat(), OPT_LOCAL);
4219 }
4220
Bram Moolenaar071d4272004-06-13 20:20:40 +00004221#ifdef FEAT_TITLE
4222 set_title_defaults();
4223#endif
4224}
4225
4226#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4227/*
4228 * When 'helplang' is still at its default value, set it to "lang".
4229 * Only the first two characters of "lang" are used.
4230 */
4231 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004232set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004233{
4234 int idx;
4235
4236 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4237 return;
4238 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004239 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004240 {
4241 if (options[idx].flags & P_ALLOCED)
4242 free_string_option(p_hlg);
4243 p_hlg = vim_strsave(lang);
4244 if (p_hlg == NULL)
4245 p_hlg = empty_option;
4246 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004247 {
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004248 // zh_CN becomes "cn", zh_TW becomes "tw"
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004249 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4250 {
4251 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4252 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4253 }
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004254 // any C like setting, such as C.UTF-8, becomes "en"
4255 else if (STRLEN(p_hlg) >= 1 && *p_hlg == 'C')
4256 {
4257 p_hlg[0] = 'e';
4258 p_hlg[1] = 'n';
4259 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004260 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004261 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004262 options[idx].flags |= P_ALLOCED;
4263 }
4264}
4265#endif
4266
4267#ifdef FEAT_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00004268 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004269gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004270{
4271 if (gui_get_lightness(gui.back_pixel) < 127)
4272 return (char_u *)"dark";
4273 return (char_u *)"light";
4274}
4275
4276/*
4277 * Option initializations that can only be done after opening the GUI window.
4278 */
4279 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004280init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004281{
4282 /* Set the 'background' option according to the lightness of the
4283 * background color, unless the user has set it already. */
4284 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4285 {
4286 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4287 highlight_changed();
4288 }
4289}
4290#endif
4291
4292#ifdef FEAT_TITLE
4293/*
4294 * 'title' and 'icon' only default to true if they have not been set or reset
4295 * in .vimrc and we can read the old value.
4296 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4297 * they can be reset. This reduces startup time when using X on a remote
4298 * machine.
4299 */
4300 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004301set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004302{
4303 int idx1;
4304 long val;
4305
4306 /*
4307 * If GUI is (going to be) used, we can always set the window title and
4308 * icon name. Saves a bit of time, because the X11 display server does
4309 * not need to be contacted.
4310 */
4311 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004312 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004313 {
4314#ifdef FEAT_GUI
4315 if (gui.starting || gui.in_use)
4316 val = TRUE;
4317 else
4318#endif
4319 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004320 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004321 p_title = val;
4322 }
4323 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004324 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004325 {
4326#ifdef FEAT_GUI
4327 if (gui.starting || gui.in_use)
4328 val = TRUE;
4329 else
4330#endif
4331 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004332 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004333 p_icon = val;
4334 }
4335}
4336#endif
4337
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004338#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004339 static void
4340trigger_optionsset_string(
4341 int opt_idx,
4342 int opt_flags,
4343 char_u *oldval,
4344 char_u *newval)
4345{
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02004346 // Don't do this recursively.
4347 if (oldval != NULL && newval != NULL
4348 && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004349 {
4350 char_u buf_type[7];
4351
4352 sprintf((char *)buf_type, "%s",
4353 (opt_flags & OPT_LOCAL) ? "local" : "global");
4354 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4355 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4356 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4357 apply_autocmds(EVENT_OPTIONSET,
4358 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4359 reset_v_option_vars();
4360 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004361}
4362#endif
4363
Bram Moolenaar071d4272004-06-13 20:20:40 +00004364/*
4365 * Parse 'arg' for option settings.
4366 *
4367 * 'arg' may be IObuff, but only when no errors can be present and option
4368 * does not need to be expanded with option_expand().
4369 * "opt_flags":
4370 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004371 * OPT_GLOBAL for ":setglobal"
4372 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004373 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004374 * OPT_WINONLY to only set window-local options
4375 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004376 *
4377 * returns FAIL if an error is detected, OK otherwise
4378 */
4379 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004380do_set(
4381 char_u *arg, /* option string (may be written to!) */
4382 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004383{
4384 int opt_idx;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004385 char *errmsg;
4386 char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00004387 char_u *startarg;
4388 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4389 int nextchar; /* next non-white char after option name */
4390 int afterchar; /* character just after option name */
4391 int len;
4392 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004393 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004394 int key;
4395 long_u flags; /* flags for current option */
4396 char_u *varp = NULL; /* pointer to variable for current option */
4397 int did_show = FALSE; /* already showed one value */
4398 int adding; /* "opt+=arg" */
4399 int prepending; /* "opt^=arg" */
4400 int removing; /* "opt-=arg" */
4401 int cp_val = 0;
4402 char_u key_name[2];
4403
4404 if (*arg == NUL)
4405 {
4406 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004407 did_show = TRUE;
4408 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004409 }
4410
4411 while (*arg != NUL) /* loop to process all options */
4412 {
4413 errmsg = NULL;
4414 startarg = arg; /* remember for error message */
4415
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004416 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4417 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004418 {
4419 /*
4420 * ":set all" show all options.
4421 * ":set all&" set all options to their default value.
4422 */
4423 arg += 3;
4424 if (*arg == '&')
4425 {
4426 ++arg;
4427 /* Only for :set command set global value of local options. */
4428 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004429 didset_options();
4430 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004431 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004432 }
4433 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004434 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004435 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004436 did_show = TRUE;
4437 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004438 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004439 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004440 {
4441 showoptions(2, opt_flags);
4442 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004443 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004444 arg += 7;
4445 }
4446 else
4447 {
4448 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004449 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004450 {
4451 prefix = 0;
4452 arg += 2;
4453 }
4454 else if (STRNCMP(arg, "inv", 3) == 0)
4455 {
4456 prefix = 2;
4457 arg += 3;
4458 }
4459
4460 /* find end of name */
4461 key = 0;
4462 if (*arg == '<')
4463 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004464 opt_idx = -1;
4465 /* look out for <t_>;> */
4466 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4467 len = 5;
4468 else
4469 {
4470 len = 1;
4471 while (arg[len] != NUL && arg[len] != '>')
4472 ++len;
4473 }
4474 if (arg[len] != '>')
4475 {
4476 errmsg = e_invarg;
4477 goto skip;
4478 }
4479 arg[len] = NUL; /* put NUL after name */
4480 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4481 opt_idx = findoption(arg + 1);
4482 arg[len++] = '>'; /* restore '>' */
4483 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004484 key = find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004485 }
4486 else
4487 {
4488 len = 0;
4489 /*
4490 * The two characters after "t_" may not be alphanumeric.
4491 */
4492 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4493 len = 4;
4494 else
4495 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4496 ++len;
4497 nextchar = arg[len];
4498 arg[len] = NUL; /* put NUL after name */
4499 opt_idx = findoption(arg);
4500 arg[len] = nextchar; /* restore nextchar */
4501 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004502 key = find_key_option(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004503 }
4504
4505 /* remember character after option name */
4506 afterchar = arg[len];
4507
4508 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004509 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004510 ++len;
4511
4512 adding = FALSE;
4513 prepending = FALSE;
4514 removing = FALSE;
4515 if (arg[len] != NUL && arg[len + 1] == '=')
4516 {
4517 if (arg[len] == '+')
4518 {
4519 adding = TRUE; /* "+=" */
4520 ++len;
4521 }
4522 else if (arg[len] == '^')
4523 {
4524 prepending = TRUE; /* "^=" */
4525 ++len;
4526 }
4527 else if (arg[len] == '-')
4528 {
4529 removing = TRUE; /* "-=" */
4530 ++len;
4531 }
4532 }
4533 nextchar = arg[len];
4534
4535 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4536 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004537 errmsg = N_("E518: Unknown option");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004538 goto skip;
4539 }
4540
4541 if (opt_idx >= 0)
4542 {
4543 if (options[opt_idx].var == NULL) /* hidden option: skip */
4544 {
4545 /* Only give an error message when requesting the value of
4546 * a hidden option, ignore setting it. */
4547 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4548 && (!(options[opt_idx].flags & P_BOOL)
4549 || nextchar == '?'))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004550 errmsg = N_("E519: Option not supported");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004551 goto skip;
4552 }
4553
4554 flags = options[opt_idx].flags;
4555 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4556 }
4557 else
4558 {
4559 flags = P_STRING;
4560 if (key < 0)
4561 {
4562 key_name[0] = KEY2TERMCAP0(key);
4563 key_name[1] = KEY2TERMCAP1(key);
4564 }
4565 else
4566 {
4567 key_name[0] = KS_KEY;
4568 key_name[1] = (key & 0xff);
4569 }
4570 }
4571
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004572 /* Skip all options that are not window-local (used when showing
4573 * an already loaded buffer in a window). */
4574 if ((opt_flags & OPT_WINONLY)
4575 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4576 goto skip;
4577
Bram Moolenaara3227e22006-03-08 21:32:40 +00004578 /* Skip all options that are window-local (used for :vimgrep). */
4579 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4580 && options[opt_idx].var == VAR_WIN)
4581 goto skip;
4582
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004583 /* Disallow changing some options from modelines. */
4584 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004585 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004586 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004587 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004588 errmsg = _("E520: Not allowed in a modeline");
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004589 goto skip;
4590 }
Bram Moolenaar110289e2019-05-23 15:38:06 +02004591 if ((flags & P_MLE) && !p_mle)
4592 {
4593 errmsg = _("E992: Not allowed in a modeline when 'modelineexpr' is off");
4594 goto skip;
4595 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004596#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004597 /* In diff mode some options are overruled. This avoids that
4598 * 'foldmethod' becomes "marker" instead of "diff" and that
4599 * "wrap" gets set. */
4600 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004601 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004602 && (
4603#ifdef FEAT_FOLDING
4604 options[opt_idx].indir == PV_FDM ||
4605#endif
4606 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004607 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004608#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004609 }
4610
4611#ifdef HAVE_SANDBOX
4612 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004613 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004614 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004615 errmsg = _(e_sandbox);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004616 goto skip;
4617 }
4618#endif
4619
4620 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4621 {
4622 arg += len;
4623 cp_val = p_cp;
4624 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4625 {
4626 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4627 {
4628 cp_val = FALSE;
4629 arg += 3;
4630 }
4631 else /* "opt&vi": set to Vi default */
4632 {
4633 cp_val = TRUE;
4634 arg += 2;
4635 }
4636 }
4637 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004638 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004639 {
4640 errmsg = e_trailing;
4641 goto skip;
4642 }
4643 }
4644
4645 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004646 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4647 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004648 */
4649 if (nextchar == '?'
4650 || (prefix == 1
4651 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4652 && !(flags & P_BOOL)))
4653 {
4654 /*
4655 * print value
4656 */
4657 if (did_show)
4658 msg_putchar('\n'); /* cursor below last one */
4659 else
4660 {
4661 gotocmdline(TRUE); /* cursor at status line */
4662 did_show = TRUE; /* remember that we did a line */
4663 }
4664 if (opt_idx >= 0)
4665 {
4666 showoneopt(&options[opt_idx], opt_flags);
4667#ifdef FEAT_EVAL
4668 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004669 {
4670 /* Mention where the option was last set. */
4671 if (varp == options[opt_idx].var)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004672 last_set_msg(options[opt_idx].script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004673 else if ((int)options[opt_idx].indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004674 last_set_msg(curwin->w_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004675 (int)options[opt_idx].indir & PV_MASK]);
4676 else if ((int)options[opt_idx].indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004677 last_set_msg(curbuf->b_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004678 (int)options[opt_idx].indir & PV_MASK]);
4679 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004680#endif
4681 }
4682 else
4683 {
4684 char_u *p;
4685
4686 p = find_termcode(key_name);
4687 if (p == NULL)
4688 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004689 errmsg = N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004690 goto skip;
4691 }
4692 else
4693 (void)show_one_termcode(key_name, p, TRUE);
4694 }
4695 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004696 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004697 errmsg = e_trailing;
4698 }
4699 else
4700 {
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004701 int value_is_replaced = !prepending && !adding && !removing;
Bram Moolenaar916a8182018-11-25 02:18:29 +01004702 int value_checked = FALSE;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004703
Bram Moolenaar071d4272004-06-13 20:20:40 +00004704 if (flags & P_BOOL) /* boolean */
4705 {
4706 if (nextchar == '=' || nextchar == ':')
4707 {
4708 errmsg = e_invarg;
4709 goto skip;
4710 }
4711
4712 /*
4713 * ":set opt!": invert
4714 * ":set opt&": reset to default value
4715 * ":set opt<": reset to global value
4716 */
4717 if (nextchar == '!')
4718 value = *(int *)(varp) ^ 1;
4719 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004720 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004721 ((flags & P_VI_DEF) || cp_val)
4722 ? VI_DEFAULT : VIM_DEFAULT];
4723 else if (nextchar == '<')
4724 {
4725 /* For 'autoread' -1 means to use global value. */
4726 if ((int *)varp == &curbuf->b_p_ar
4727 && opt_flags == OPT_LOCAL)
4728 value = -1;
4729 else
4730 value = *(int *)get_varp_scope(&(options[opt_idx]),
4731 OPT_GLOBAL);
4732 }
4733 else
4734 {
4735 /*
4736 * ":set invopt": invert
4737 * ":set opt" or ":set noopt": set or reset
4738 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004739 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004740 {
4741 errmsg = e_trailing;
4742 goto skip;
4743 }
4744 if (prefix == 2) /* inv */
4745 value = *(int *)(varp) ^ 1;
4746 else
4747 value = prefix;
4748 }
4749
4750 errmsg = set_bool_option(opt_idx, varp, (int)value,
4751 opt_flags);
4752 }
4753 else /* numeric or string */
4754 {
4755 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4756 || prefix != 1)
4757 {
4758 errmsg = e_invarg;
4759 goto skip;
4760 }
4761
4762 if (flags & P_NUM) /* numeric */
4763 {
4764 /*
4765 * Different ways to set a number option:
4766 * & set to default value
4767 * < set to global value
4768 * <xx> accept special key codes for 'wildchar'
4769 * c accept any non-digit for 'wildchar'
4770 * [-]0-9 set number
4771 * other error
4772 */
4773 ++arg;
4774 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004775 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004776 ((flags & P_VI_DEF) || cp_val)
4777 ? VI_DEFAULT : VIM_DEFAULT];
4778 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004779 {
4780 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4781 * use the global value. */
4782 if ((long *)varp == &curbuf->b_p_ul
4783 && opt_flags == OPT_LOCAL)
4784 value = NO_LOCAL_UNDOLEVEL;
4785 else
4786 value = *(long *)get_varp_scope(
4787 &(options[opt_idx]), OPT_GLOBAL);
4788 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004789 else if (((long *)varp == &p_wc
4790 || (long *)varp == &p_wcm)
4791 && (*arg == '<'
4792 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004793 || (*arg != NUL
4794 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004795 && !VIM_ISDIGIT(*arg))))
4796 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004797 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004798 if (value == 0 && (long *)varp != &p_wcm)
4799 {
4800 errmsg = e_invarg;
4801 goto skip;
4802 }
4803 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004804 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4805 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004806 /* Allow negative (for 'undolevels'), octal and
4807 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004808 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
Bram Moolenaar16e9b852019-05-19 19:59:35 +02004809 &value, NULL, 0, TRUE);
Bram Moolenaar06e2c812019-06-12 19:05:48 +02004810 if (i == 0 || (arg[i] != NUL
4811 && !VIM_ISWHITE(arg[i])))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004812 {
Bram Moolenaar16e9b852019-05-19 19:59:35 +02004813 errmsg = N_("E521: Number required after =");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004814 goto skip;
4815 }
4816 }
4817 else
4818 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004819 errmsg = N_("E521: Number required after =");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004820 goto skip;
4821 }
4822
4823 if (adding)
4824 value = *(long *)varp + value;
4825 if (prepending)
4826 value = *(long *)varp * value;
4827 if (removing)
4828 value = *(long *)varp - value;
4829 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004830 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004831 }
4832 else if (opt_idx >= 0) /* string */
4833 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004834 char_u *save_arg = NULL;
4835 char_u *s = NULL;
4836 char_u *oldval = NULL; /* previous value if *varp */
4837 char_u *newval;
4838 char_u *origval = NULL;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004839#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004840 char_u *saved_origval = NULL;
4841 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004842#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004843 unsigned newlen;
4844 int comma;
4845 int bs;
4846 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004847 was allocated */
4848
4849 /* When using ":set opt=val" for a global option
4850 * with a local value the local value will be
4851 * reset, use the global value here. */
4852 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004853 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004854 varp = options[opt_idx].var;
4855
4856 /* The old value is kept until we are sure that the
4857 * new value is valid. */
4858 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004859
4860 /* When setting the local value of a global
4861 * option, the old value may be the global value. */
4862 if (((int)options[opt_idx].indir & PV_BOTH)
4863 && (opt_flags & OPT_LOCAL))
4864 origval = *(char_u **)get_varp(
4865 &options[opt_idx]);
4866 else
4867 origval = oldval;
4868
Bram Moolenaar071d4272004-06-13 20:20:40 +00004869 if (nextchar == '&') /* set to default val */
4870 {
4871 newval = options[opt_idx].def_val[
4872 ((flags & P_VI_DEF) || cp_val)
4873 ? VI_DEFAULT : VIM_DEFAULT];
4874 if ((char_u **)varp == &p_bg)
4875 {
4876 /* guess the value of 'background' */
4877#ifdef FEAT_GUI
4878 if (gui.in_use)
4879 newval = gui_bg_default();
4880 else
4881#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004882 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004883 }
4884
4885 /* expand environment variables and ~ (since the
4886 * default value was already expanded, only
4887 * required when an environment variable was set
4888 * later */
4889 if (newval == NULL)
4890 newval = empty_option;
4891 else
4892 {
4893 s = option_expand(opt_idx, newval);
4894 if (s == NULL)
4895 s = newval;
4896 newval = vim_strsave(s);
4897 }
4898 new_value_alloced = TRUE;
4899 }
4900 else if (nextchar == '<') /* set to global val */
4901 {
4902 newval = vim_strsave(*(char_u **)get_varp_scope(
4903 &(options[opt_idx]), OPT_GLOBAL));
4904 new_value_alloced = TRUE;
4905 }
4906 else
4907 {
4908 ++arg; /* jump to after the '=' or ':' */
4909
4910 /*
4911 * Set 'keywordprg' to ":help" if an empty
4912 * value was passed to :set by the user.
4913 * Misuse errbuf[] for the resulting string.
4914 */
4915 if (varp == (char_u *)&p_kp
4916 && (*arg == NUL || *arg == ' '))
4917 {
4918 STRCPY(errbuf, ":help");
4919 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004920 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004921 }
4922 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004923 * Convert 'backspace' number to string, for
4924 * adding, prepending and removing string.
4925 */
4926 else if (varp == (char_u *)&p_bs
4927 && VIM_ISDIGIT(**(char_u **)varp))
4928 {
4929 i = getdigits((char_u **)varp);
4930 switch (i)
4931 {
4932 case 0:
4933 *(char_u **)varp = empty_option;
4934 break;
4935 case 1:
4936 *(char_u **)varp = vim_strsave(
4937 (char_u *)"indent,eol");
4938 break;
4939 case 2:
4940 *(char_u **)varp = vim_strsave(
4941 (char_u *)"indent,eol,start");
4942 break;
4943 }
4944 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004945 if (origval == oldval)
4946 origval = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004947 oldval = *(char_u **)varp;
4948 }
4949 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004950 * Convert 'whichwrap' number to string, for
4951 * backwards compatibility with Vim 3.0.
4952 * Misuse errbuf[] for the resulting string.
4953 */
4954 else if (varp == (char_u *)&p_ww
4955 && VIM_ISDIGIT(*arg))
4956 {
4957 *errbuf = NUL;
4958 i = getdigits(&arg);
4959 if (i & 1)
4960 STRCAT(errbuf, "b,");
4961 if (i & 2)
4962 STRCAT(errbuf, "s,");
4963 if (i & 4)
4964 STRCAT(errbuf, "h,l,");
4965 if (i & 8)
4966 STRCAT(errbuf, "<,>,");
4967 if (i & 16)
4968 STRCAT(errbuf, "[,],");
4969 if (*errbuf != NUL) /* remove trailing , */
4970 errbuf[STRLEN(errbuf) - 1] = NUL;
4971 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004972 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004973 }
4974 /*
4975 * Remove '>' before 'dir' and 'bdir', for
4976 * backwards compatibility with version 3.0
4977 */
4978 else if ( *arg == '>'
4979 && (varp == (char_u *)&p_dir
4980 || varp == (char_u *)&p_bdir))
4981 {
4982 ++arg;
4983 }
4984
Bram Moolenaar071d4272004-06-13 20:20:40 +00004985 /*
4986 * Copy the new string into allocated memory.
4987 * Can't use set_string_option_direct(), because
4988 * we need to remove the backslashes.
4989 */
4990 /* get a bit too much */
4991 newlen = (unsigned)STRLEN(arg) + 1;
4992 if (adding || prepending || removing)
4993 newlen += (unsigned)STRLEN(origval) + 1;
4994 newval = alloc(newlen);
4995 if (newval == NULL) /* out of mem, don't change */
4996 break;
4997 s = newval;
4998
4999 /*
5000 * Copy the string, skip over escaped chars.
5001 * For MS-DOS and WIN32 backslashes before normal
5002 * file name characters are not removed, and keep
5003 * backslash at start, for "\\machine\path", but
5004 * do remove it for "\\\\machine\\path".
5005 * The reverse is found in ExpandOldSetting().
5006 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005007 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005008 {
5009 if (*arg == '\\' && arg[1] != NUL
5010#ifdef BACKSLASH_IN_FILENAME
5011 && !((flags & P_EXPAND)
5012 && vim_isfilec(arg[1])
5013 && (arg[1] != '\\'
5014 || (s == newval
5015 && arg[2] != '\\')))
5016#endif
5017 )
5018 ++arg; /* remove backslash */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005019 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00005020 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005021 {
5022 /* copy multibyte char */
5023 mch_memmove(s, arg, (size_t)i);
5024 arg += i;
5025 s += i;
5026 }
5027 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005028 *s++ = *arg++;
5029 }
5030 *s = NUL;
5031
5032 /*
5033 * Expand environment variables and ~.
5034 * Don't do it when adding without inserting a
5035 * comma.
5036 */
5037 if (!(adding || prepending || removing)
5038 || (flags & P_COMMA))
5039 {
5040 s = option_expand(opt_idx, newval);
5041 if (s != NULL)
5042 {
5043 vim_free(newval);
5044 newlen = (unsigned)STRLEN(s) + 1;
5045 if (adding || prepending || removing)
5046 newlen += (unsigned)STRLEN(origval) + 1;
5047 newval = alloc(newlen);
5048 if (newval == NULL)
5049 break;
5050 STRCPY(newval, s);
5051 }
5052 }
5053
5054 /* locate newval[] in origval[] when removing it
5055 * and when adding to avoid duplicates */
5056 i = 0; /* init for GCC */
5057 if (removing || (flags & P_NODUP))
5058 {
5059 i = (int)STRLEN(newval);
5060 bs = 0;
5061 for (s = origval; *s; ++s)
5062 {
5063 if ((!(flags & P_COMMA)
5064 || s == origval
5065 || (s[-1] == ',' && !(bs & 1)))
5066 && STRNCMP(s, newval, i) == 0
5067 && (!(flags & P_COMMA)
5068 || s[i] == ','
5069 || s[i] == NUL))
5070 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005071 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005072 * even number of backslashes or a single
5073 * backslash preceded by a comma before it
5074 * is recognized as a separator */
5075 if ((s > origval + 1
5076 && s[-1] == '\\'
5077 && s[-2] != ',')
5078 || (s == origval + 1
5079 && s[-1] == '\\'))
5080
Bram Moolenaar071d4272004-06-13 20:20:40 +00005081 ++bs;
5082 else
5083 bs = 0;
5084 }
5085
5086 /* do not add if already there */
5087 if ((adding || prepending) && *s)
5088 {
5089 prepending = FALSE;
5090 adding = FALSE;
5091 STRCPY(newval, origval);
5092 }
5093 }
5094
5095 /* concatenate the two strings; add a ',' if
5096 * needed */
5097 if (adding || prepending)
5098 {
5099 comma = ((flags & P_COMMA) && *origval != NUL
5100 && *newval != NUL);
5101 if (adding)
5102 {
5103 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005104 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005105 if (comma && i > 1
5106 && (flags & P_ONECOMMA) == P_ONECOMMA
5107 && origval[i - 1] == ','
5108 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005109 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005110 mch_memmove(newval + i + comma, newval,
5111 STRLEN(newval) + 1);
5112 mch_memmove(newval, origval, (size_t)i);
5113 }
5114 else
5115 {
5116 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005117 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005118 }
5119 if (comma)
5120 newval[i] = ',';
5121 }
5122
5123 /* Remove newval[] from origval[]. (Note: "i" has
5124 * been set above and is used here). */
5125 if (removing)
5126 {
5127 STRCPY(newval, origval);
5128 if (*s)
5129 {
5130 /* may need to remove a comma */
5131 if (flags & P_COMMA)
5132 {
5133 if (s == origval)
5134 {
5135 /* include comma after string */
5136 if (s[i] == ',')
5137 ++i;
5138 }
5139 else
5140 {
5141 /* include comma before string */
5142 --s;
5143 ++i;
5144 }
5145 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005146 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005147 }
5148 }
5149
5150 if (flags & P_FLAGLIST)
5151 {
5152 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005153 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005154 {
5155 /* if options have P_FLAGLIST and
5156 * P_ONECOMMA such as 'whichwrap' */
5157 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005158 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005159 if (*s != ',' && *(s + 1) == ','
5160 && vim_strchr(s + 2, *s) != NULL)
5161 {
5162 /* Remove the duplicated value and
5163 * the next comma. */
5164 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005165 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005166 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005167 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005168 else
5169 {
5170 if ((!(flags & P_COMMA) || *s != ',')
5171 && vim_strchr(s + 1, *s) != NULL)
5172 {
5173 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005174 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005175 }
5176 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005177 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005178 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005179 }
5180
5181 if (save_arg != NULL) /* number for 'whichwrap' */
5182 arg = save_arg;
5183 new_value_alloced = TRUE;
5184 }
5185
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005186 /*
5187 * Set the new value.
5188 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005189 *(char_u **)(varp) = newval;
5190
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005191#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005192 if (!starting
5193# ifdef FEAT_CRYPT
5194 && options[opt_idx].indir != PV_KEY
5195# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005196 && origval != NULL && newval != NULL)
5197 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005198 /* origval may be freed by
5199 * did_set_string_option(), make a copy. */
5200 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005201 /* newval (and varp) may become invalid if the
5202 * buffer is closed by autocommands. */
5203 saved_newval = vim_strsave(newval);
5204 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005205#endif
5206
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005207 {
5208 long_u *p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005209 int secure_saved = secure;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005210
5211 // When an option is set in the sandbox, from a
5212 // modeline or in secure mode, then deal with side
5213 // effects in secure mode. Also when the value was
5214 // set with the P_INSECURE flag and is not
5215 // completely replaced.
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005216 if ((opt_flags & OPT_MODELINE)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005217#ifdef HAVE_SANDBOX
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005218 || sandbox != 0
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005219#endif
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005220 || (!value_is_replaced && (*p & P_INSECURE)))
5221 secure = 1;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005222
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005223 // Handle side effects, and set the global value
5224 // for ":set" on local options. Note: when setting
5225 // 'syntax' or 'filetype' autocommands may be
5226 // triggered that can cause havoc.
5227 errmsg = did_set_string_option(
5228 opt_idx, (char_u **)varp,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005229 new_value_alloced, oldval, errbuf,
5230 opt_flags, &value_checked);
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005231
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005232 secure = secure_saved;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005233 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005234
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005235#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005236 if (errmsg == NULL)
5237 trigger_optionsset_string(opt_idx, opt_flags,
5238 saved_origval, saved_newval);
5239 vim_free(saved_origval);
5240 vim_free(saved_newval);
5241#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005242 /* If error detected, print the error message. */
5243 if (errmsg != NULL)
5244 goto skip;
5245 }
5246 else /* key code option */
5247 {
5248 char_u *p;
5249
5250 if (nextchar == '&')
5251 {
5252 if (add_termcap_entry(key_name, TRUE) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005253 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005254 }
5255 else
5256 {
5257 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005258 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005259 if (*p == '\\' && p[1] != NUL)
5260 ++p;
5261 nextchar = *p;
5262 *p = NUL;
5263 add_termcode(key_name, arg, FALSE);
5264 *p = nextchar;
5265 }
5266 if (full_screen)
5267 ttest(FALSE);
5268 redraw_all_later(CLEAR);
5269 }
5270 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005271
Bram Moolenaar071d4272004-06-13 20:20:40 +00005272 if (opt_idx >= 0)
Bram Moolenaar916a8182018-11-25 02:18:29 +01005273 did_set_option(
5274 opt_idx, opt_flags, value_is_replaced, value_checked);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005275 }
5276
5277skip:
5278 /*
5279 * Advance to next argument.
5280 * - skip until a blank found, taking care of backslashes
5281 * - skip blanks
5282 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5283 */
5284 for (i = 0; i < 2 ; ++i)
5285 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005286 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005287 if (*arg++ == '\\' && *arg != NUL)
5288 ++arg;
5289 arg = skipwhite(arg);
5290 if (*arg != '=')
5291 break;
5292 }
5293 }
5294
5295 if (errmsg != NULL)
5296 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005297 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005298 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005299 if (i + (arg - startarg) < IOSIZE)
5300 {
5301 /* append the argument with the error */
5302 STRCAT(IObuff, ": ");
5303 mch_memmove(IObuff + i, startarg, (arg - startarg));
5304 IObuff[i + (arg - startarg)] = NUL;
5305 }
5306 /* make sure all characters are printable */
5307 trans_characters(IObuff, IOSIZE);
5308
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005309 ++no_wait_return; // wait_return done later
5310 emsg((char *)IObuff); // show error highlighted
Bram Moolenaar071d4272004-06-13 20:20:40 +00005311 --no_wait_return;
5312
5313 return FAIL;
5314 }
5315
5316 arg = skipwhite(arg);
5317 }
5318
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005319theend:
5320 if (silent_mode && did_show)
5321 {
5322 /* After displaying option values in silent mode. */
5323 silent_mode = FALSE;
5324 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5325 msg_putchar('\n');
5326 cursor_on(); /* msg_start() switches it off */
5327 out_flush();
5328 silent_mode = TRUE;
5329 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5330 }
5331
Bram Moolenaar071d4272004-06-13 20:20:40 +00005332 return OK;
5333}
5334
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005335/*
5336 * Call this when an option has been given a new value through a user command.
5337 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5338 */
5339 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005340did_set_option(
5341 int opt_idx,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005342 int opt_flags, // possibly with OPT_MODELINE
5343 int new_value, // value was replaced completely
5344 int value_checked) // value was checked to be safe, no need to set the
5345 // P_INSECURE flag.
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005346{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005347 long_u *p;
5348
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005349 options[opt_idx].flags |= P_WAS_SET;
5350
5351 /* When an option is set in the sandbox, from a modeline or in secure mode
5352 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005353 * flag. */
5354 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar916a8182018-11-25 02:18:29 +01005355 if (!value_checked && (secure
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005356#ifdef HAVE_SANDBOX
5357 || sandbox != 0
5358#endif
Bram Moolenaar916a8182018-11-25 02:18:29 +01005359 || (opt_flags & OPT_MODELINE)))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005360 *p = *p | P_INSECURE;
5361 else if (new_value)
5362 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005363}
5364
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005365 static char *
5366illegal_char(char *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005367{
5368 if (errbuf == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005369 return "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00005370 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005371 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005372 return errbuf;
5373}
5374
5375/*
5376 * Convert a key name or string into a key value.
5377 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005378 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005379 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005380 int
5381string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005382{
5383 if (*arg == '<')
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02005384 return find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005385 if (*arg == '^')
5386 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005387 if (multi_byte)
5388 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005389 return *arg;
5390}
5391
5392#ifdef FEAT_CMDWIN
5393/*
5394 * Check value of 'cedit' and set cedit_key.
5395 * Returns NULL if value is OK, error message otherwise.
5396 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005397 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005398check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005399{
5400 int n;
5401
5402 if (*p_cedit == NUL)
5403 cedit_key = -1;
5404 else
5405 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005406 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005407 if (vim_isprintc(n))
5408 return e_invarg;
5409 cedit_key = n;
5410 }
5411 return NULL;
5412}
5413#endif
5414
5415#ifdef FEAT_TITLE
5416/*
5417 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5418 * maketitle() to create and display it.
5419 * When switching the title or icon off, call mch_restore_title() to get
5420 * the old value back.
5421 */
5422 static void
Bram Moolenaar84a93082018-06-16 22:58:15 +02005423did_set_title(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005424{
5425 if (starting != NO_SCREEN
5426#ifdef FEAT_GUI
5427 && !gui.starting
5428#endif
5429 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00005430 maketitle();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005431}
5432#endif
5433
5434/*
5435 * set_options_bin - called when 'bin' changes value.
5436 */
5437 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005438set_options_bin(
5439 int oldval,
5440 int newval,
5441 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005442{
5443 /*
5444 * The option values that are changed when 'bin' changes are
5445 * copied when 'bin is set and restored when 'bin' is reset.
5446 */
5447 if (newval)
5448 {
5449 if (!oldval) /* switched on */
5450 {
5451 if (!(opt_flags & OPT_GLOBAL))
5452 {
5453 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5454 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5455 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5456 curbuf->b_p_et_nobin = curbuf->b_p_et;
5457 }
5458 if (!(opt_flags & OPT_LOCAL))
5459 {
5460 p_tw_nobin = p_tw;
5461 p_wm_nobin = p_wm;
5462 p_ml_nobin = p_ml;
5463 p_et_nobin = p_et;
5464 }
5465 }
5466
5467 if (!(opt_flags & OPT_GLOBAL))
5468 {
5469 curbuf->b_p_tw = 0; /* no automatic line wrap */
5470 curbuf->b_p_wm = 0; /* no automatic line wrap */
5471 curbuf->b_p_ml = 0; /* no modelines */
5472 curbuf->b_p_et = 0; /* no expandtab */
5473 }
5474 if (!(opt_flags & OPT_LOCAL))
5475 {
5476 p_tw = 0;
5477 p_wm = 0;
5478 p_ml = FALSE;
5479 p_et = FALSE;
5480 p_bin = TRUE; /* needed when called for the "-b" argument */
5481 }
5482 }
5483 else if (oldval) /* switched off */
5484 {
5485 if (!(opt_flags & OPT_GLOBAL))
5486 {
5487 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5488 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5489 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5490 curbuf->b_p_et = curbuf->b_p_et_nobin;
5491 }
5492 if (!(opt_flags & OPT_LOCAL))
5493 {
5494 p_tw = p_tw_nobin;
5495 p_wm = p_wm_nobin;
5496 p_ml = p_ml_nobin;
5497 p_et = p_et_nobin;
5498 }
5499 }
5500}
5501
5502#ifdef FEAT_VIMINFO
5503/*
5504 * Find the parameter represented by the given character (eg ', :, ", or /),
5505 * and return its associated value in the 'viminfo' string.
5506 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005507 * If the parameter is not specified in the string or there is no following
5508 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005509 */
5510 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005511get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005512{
5513 char_u *p;
5514
5515 p = find_viminfo_parameter(type);
5516 if (p != NULL && VIM_ISDIGIT(*p))
5517 return atoi((char *)p);
5518 return -1;
5519}
5520
5521/*
5522 * Find the parameter represented by the given character (eg ''', ':', '"', or
5523 * '/') in the 'viminfo' option and return a pointer to the string after it.
5524 * Return NULL if the parameter is not specified in the string.
5525 */
5526 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005527find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005528{
5529 char_u *p;
5530
5531 for (p = p_viminfo; *p; ++p)
5532 {
5533 if (*p == type)
5534 return p + 1;
5535 if (*p == 'n') /* 'n' is always the last one */
5536 break;
5537 p = vim_strchr(p, ','); /* skip until next ',' */
5538 if (p == NULL) /* hit the end without finding parameter */
5539 break;
5540 }
5541 return NULL;
5542}
5543#endif
5544
5545/*
5546 * Expand environment variables for some string options.
5547 * These string options cannot be indirect!
5548 * If "val" is NULL expand the current value of the option.
5549 * Return pointer to NameBuff, or NULL when not expanded.
5550 */
5551 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005552option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005553{
5554 /* if option doesn't need expansion nothing to do */
5555 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5556 return NULL;
5557
5558 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5559 * expand_env() would truncate the string. */
5560 if (val != NULL && STRLEN(val) > MAXPATHL)
5561 return NULL;
5562
5563 if (val == NULL)
5564 val = *(char_u **)options[opt_idx].var;
5565
5566 /*
5567 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5568 * Escape spaces when expanding 'tags', they are used to separate file
5569 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005570 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005571 */
5572 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005573 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005574#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005575 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5576#endif
5577 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005578 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5579 return NULL;
5580
5581 return NameBuff;
5582}
5583
5584/*
5585 * After setting various option values: recompute variables that depend on
5586 * option values.
5587 */
5588 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005589didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005590{
5591 /* initialize the table for 'iskeyword' et.al. */
5592 (void)init_chartab();
5593
5594 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
5595 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005596 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005597#ifdef FEAT_SESSION
5598 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5599 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5600#endif
5601#ifdef FEAT_FOLDING
5602 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5603#endif
5604 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005605 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005606 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005607#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5608 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5609#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005610#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005611 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005612 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005613 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005614 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005615#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01005616#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005617 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5618#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005619#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005620 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5621#endif
5622#ifdef FEAT_CMDWIN
5623 /* set cedit_key */
5624 (void)check_cedit();
5625#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005626#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005627 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005628#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005629#ifdef FEAT_LINEBREAK
5630 /* initialize the table for 'breakat'. */
5631 fill_breakat_flags();
5632#endif
5633
5634}
5635
5636/*
5637 * More side effects of setting options.
5638 */
5639 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005640didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005641{
5642 /* Initialize the highlight_attr[] table. */
5643 (void)highlight_changed();
5644
5645 /* Parse default for 'wildmode' */
5646 check_opt_wim();
5647
5648 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005649 /* Parse default for 'fillchars'. */
5650 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005651
5652#ifdef FEAT_CLIPBOARD
5653 /* Parse default for 'clipboard' */
5654 (void)check_clipboard_option();
5655#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005656#ifdef FEAT_VARTABS
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01005657 vim_free(curbuf->b_p_vsts_array);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005658 tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_array);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01005659 vim_free(curbuf->b_p_vts_array);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005660 tabstop_set(curbuf->b_p_vts, &curbuf->b_p_vts_array);
5661#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005662}
5663
5664/*
5665 * Check for string options that are NULL (normally only termcap options).
5666 */
5667 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005668check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005669{
5670 int opt_idx;
5671
5672 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5673 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5674 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5675}
5676
5677/*
5678 * Check string options in a buffer for NULL value.
5679 */
5680 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005681check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005682{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005683 check_string_option(&buf->b_p_bh);
5684 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005685 check_string_option(&buf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005686 check_string_option(&buf->b_p_ff);
5687#ifdef FEAT_FIND_ID
5688 check_string_option(&buf->b_p_def);
5689 check_string_option(&buf->b_p_inc);
5690# ifdef FEAT_EVAL
5691 check_string_option(&buf->b_p_inex);
5692# endif
5693#endif
5694#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5695 check_string_option(&buf->b_p_inde);
5696 check_string_option(&buf->b_p_indk);
5697#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005698#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5699 check_string_option(&buf->b_p_bexpr);
5700#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005701#if defined(FEAT_CRYPT)
5702 check_string_option(&buf->b_p_cm);
5703#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005704 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005705#if defined(FEAT_EVAL)
5706 check_string_option(&buf->b_p_fex);
5707#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005708#ifdef FEAT_CRYPT
5709 check_string_option(&buf->b_p_key);
5710#endif
5711 check_string_option(&buf->b_p_kp);
5712 check_string_option(&buf->b_p_mps);
5713 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005714 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005715 check_string_option(&buf->b_p_isk);
5716#ifdef FEAT_COMMENTS
5717 check_string_option(&buf->b_p_com);
5718#endif
5719#ifdef FEAT_FOLDING
5720 check_string_option(&buf->b_p_cms);
5721#endif
5722 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005723#ifdef FEAT_TEXTOBJ
5724 check_string_option(&buf->b_p_qe);
5725#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005726#ifdef FEAT_SYN_HL
5727 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005728 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005729#endif
5730#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005731 check_string_option(&buf->b_s.b_p_spc);
5732 check_string_option(&buf->b_s.b_p_spf);
5733 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005734#endif
5735#ifdef FEAT_SEARCHPATH
5736 check_string_option(&buf->b_p_sua);
5737#endif
5738#ifdef FEAT_CINDENT
5739 check_string_option(&buf->b_p_cink);
5740 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005741 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005742#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005743 check_string_option(&buf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005744#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5745 check_string_option(&buf->b_p_cinw);
5746#endif
5747#ifdef FEAT_INS_EXPAND
5748 check_string_option(&buf->b_p_cpt);
5749#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005750#ifdef FEAT_COMPL_FUNC
5751 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005752 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005753#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +02005754#ifdef FEAT_EVAL
5755 check_string_option(&buf->b_p_tfu);
5756#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005757#ifdef FEAT_KEYMAP
5758 check_string_option(&buf->b_p_keymap);
5759#endif
5760#ifdef FEAT_QUICKFIX
5761 check_string_option(&buf->b_p_gp);
5762 check_string_option(&buf->b_p_mp);
5763 check_string_option(&buf->b_p_efm);
5764#endif
5765 check_string_option(&buf->b_p_ep);
5766 check_string_option(&buf->b_p_path);
5767 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005768 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005769#ifdef FEAT_INS_EXPAND
5770 check_string_option(&buf->b_p_dict);
5771 check_string_option(&buf->b_p_tsr);
5772#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005773#ifdef FEAT_LISP
5774 check_string_option(&buf->b_p_lw);
5775#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005776 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005777 check_string_option(&buf->b_p_menc);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005778#ifdef FEAT_VARTABS
5779 check_string_option(&buf->b_p_vsts);
5780 check_string_option(&buf->b_p_vts);
5781#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005782}
5783
5784/*
5785 * Free the string allocated for an option.
5786 * Checks for the string being empty_option. This may happen if we're out of
5787 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5788 * check_options().
5789 * Does NOT check for P_ALLOCED flag!
5790 */
5791 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005792free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005793{
5794 if (p != empty_option)
5795 vim_free(p);
5796}
5797
5798 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005799clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005800{
5801 if (*pp != empty_option)
5802 vim_free(*pp);
5803 *pp = empty_option;
5804}
5805
5806 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005807check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005808{
5809 if (*pp == NULL)
5810 *pp = empty_option;
5811}
5812
5813/*
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005814 * Return the option index found by a pointer into term_strings[].
5815 * Return -1 if not found.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005816 */
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005817 int
5818get_term_opt_idx(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005819{
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005820 int opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005821
5822 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5823 if (options[opt_idx].var == (char_u *)p)
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005824 return opt_idx;
5825 return -1; // cannot happen: didn't find it!
5826}
5827
5828/*
5829 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5830 * Return the option index or -1 if not found.
5831 */
5832 int
5833set_term_option_alloced(char_u **p)
5834{
5835 int opt_idx = get_term_opt_idx(p);
5836
5837 if (opt_idx >= 0)
5838 options[opt_idx].flags |= P_ALLOCED;
5839 return opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005840}
5841
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005842#if defined(FEAT_EVAL) || defined(PROTO)
5843/*
5844 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5845 * Return FALSE when it wasn't.
5846 * Return -1 for an unknown option.
5847 */
5848 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005849was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005850{
5851 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005852 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005853
5854 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005855 {
5856 flagp = insecure_flag(idx, opt_flags);
5857 return (*flagp & P_INSECURE) != 0;
5858 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005859 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005860 return -1;
5861}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005862
5863/*
5864 * Get a pointer to the flags used for the P_INSECURE flag of option
5865 * "opt_idx". For some local options a local flags field is used.
5866 */
5867 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005868insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005869{
5870 if (opt_flags & OPT_LOCAL)
5871 switch ((int)options[opt_idx].indir)
5872 {
5873#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005874 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005875#endif
5876#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005877# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005878 case PV_FDE: return &curwin->w_p_fde_flags;
5879 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005880# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005881# ifdef FEAT_BEVAL
5882 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5883# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005884# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005885 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005886# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005887 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005888# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005889 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005890# endif
5891#endif
5892 }
5893
5894 /* Nothing special, return global flags field. */
5895 return &options[opt_idx].flags;
5896}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005897#endif
5898
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005899#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005900/*
5901 * Redraw the window title and/or tab page text later.
5902 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005903static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005904{
5905 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005906 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005907}
5908#endif
5909
Bram Moolenaar071d4272004-06-13 20:20:40 +00005910/*
5911 * Set a string option to a new value (without checking the effect).
5912 * The string is copied into allocated memory.
5913 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005914 * When "set_sid" is zero set the scriptID to current_sctx.sc_sid. When
5915 * "set_sid" is SID_NONE don't set the scriptID. Otherwise set the scriptID to
5916 * "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005917 */
5918 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005919set_string_option_direct(
5920 char_u *name,
5921 int opt_idx,
5922 char_u *val,
5923 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5924 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005925{
5926 char_u *s;
5927 char_u **varp;
5928 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005929 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005930
Bram Moolenaar89d40322006-08-29 15:30:07 +00005931 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005932 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005933 idx = findoption(name);
5934 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005935 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005936 semsg(_(e_intern2), "set_string_option_direct()");
5937 siemsg(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005938 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005939 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005940 }
5941
Bram Moolenaar89d40322006-08-29 15:30:07 +00005942 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005943 return;
5944
5945 s = vim_strsave(val);
5946 if (s != NULL)
5947 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005948 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005949 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005950 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005951 free_string_option(*varp);
5952 *varp = s;
5953
5954 /* For buffer/window local option may also set the global value. */
5955 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005956 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005957
Bram Moolenaar89d40322006-08-29 15:30:07 +00005958 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005959
5960 /* When setting both values of a global option with a local value,
5961 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005962 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005963 {
5964 free_string_option(*varp);
5965 *varp = empty_option;
5966 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005967# ifdef FEAT_EVAL
5968 if (set_sid != SID_NONE)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005969 {
5970 sctx_T script_ctx;
5971
5972 if (set_sid == 0)
5973 script_ctx = current_sctx;
5974 else
5975 {
5976 script_ctx.sc_sid = set_sid;
Bram Moolenaarded5f1b2018-11-10 17:33:29 +01005977 script_ctx.sc_seq = 0;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005978 script_ctx.sc_lnum = 0;
Bram Moolenaar558ca4a2019-04-04 18:15:38 +02005979 script_ctx.sc_version = 1;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005980 }
5981 set_option_sctx_idx(idx, opt_flags, script_ctx);
5982 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005983# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005984 }
5985}
5986
5987/*
Bram Moolenaar20c023a2019-05-26 21:03:24 +02005988 * Like set_string_option_direct(), but for a window-local option in "wp".
5989 * Blocks autocommands to avoid the old curwin becoming invalid.
5990 */
5991 void
5992set_string_option_direct_in_win(
5993 win_T *wp,
5994 char_u *name,
5995 int opt_idx,
5996 char_u *val,
5997 int opt_flags,
5998 int set_sid)
5999{
6000 win_T *save_curwin = curwin;
6001
6002 block_autocmds();
6003 curwin = wp;
6004 curbuf = curwin->w_buffer;
6005 set_string_option_direct(name, opt_idx, val, opt_flags, set_sid);
6006 curwin = save_curwin;
6007 curbuf = curwin->w_buffer;
6008 unblock_autocmds();
6009}
6010
6011/*
6012 * Like set_string_option_direct(), but for a buffer-local option in "buf".
6013 * Blocks autocommands to avoid the old curbuf becoming invalid.
6014 */
6015 void
6016set_string_option_direct_in_buf(
6017 buf_T *buf,
6018 char_u *name,
6019 int opt_idx,
6020 char_u *val,
6021 int opt_flags,
6022 int set_sid)
6023{
6024 buf_T *save_curbuf = curbuf;
6025
6026 block_autocmds();
6027 curbuf = buf;
6028 curwin->w_buffer = curbuf;
6029 set_string_option_direct(name, opt_idx, val, opt_flags, set_sid);
6030 curbuf = save_curbuf;
6031 curwin->w_buffer = curbuf;
6032 unblock_autocmds();
6033}
6034
6035/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006036 * Set global value for string option when it's a local option.
6037 */
6038 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01006039set_string_option_global(
6040 int opt_idx, /* option index */
6041 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006042{
6043 char_u **p, *s;
6044
6045 /* the global value is always allocated */
6046 if (options[opt_idx].var == VAR_WIN)
6047 p = (char_u **)GLOBAL_WO(varp);
6048 else
6049 p = (char_u **)options[opt_idx].var;
6050 if (options[opt_idx].indir != PV_NONE
6051 && p != varp
6052 && (s = vim_strsave(*varp)) != NULL)
6053 {
6054 free_string_option(*p);
6055 *p = s;
6056 }
6057}
6058
6059/*
6060 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006061 *
6062 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006063 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006064 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006065set_string_option(
6066 int opt_idx,
6067 char_u *value,
6068 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006069{
6070 char_u *s;
6071 char_u **varp;
6072 char_u *oldval;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006073#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02006074 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006075 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02006076#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006077 char *r = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01006078 int value_checked = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006079
6080 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006081 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006082
6083 s = vim_strsave(value);
6084 if (s != NULL)
6085 {
6086 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
6087 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006088 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006089 ? OPT_GLOBAL : OPT_LOCAL)
6090 : opt_flags);
6091 oldval = *varp;
6092 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02006093
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006094#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02006095 if (!starting
6096# ifdef FEAT_CRYPT
6097 && options[opt_idx].indir != PV_KEY
6098# endif
6099 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006100 {
Bram Moolenaar53744302015-07-17 17:38:22 +02006101 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006102 saved_newval = vim_strsave(s);
6103 }
Bram Moolenaar53744302015-07-17 17:38:22 +02006104#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006105 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
Bram Moolenaar916a8182018-11-25 02:18:29 +01006106 opt_flags, &value_checked)) == NULL)
6107 did_set_option(opt_idx, opt_flags, TRUE, value_checked);
Bram Moolenaar53744302015-07-17 17:38:22 +02006108
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006109#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006110 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006111 if (r == NULL)
6112 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006113 saved_oldval, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006114 vim_free(saved_oldval);
6115 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02006116#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006117 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006118 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006119}
6120
6121/*
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006122 * Return TRUE if "val" is a valid name: only consists of alphanumeric ASCII
6123 * characters or characters in "allowed".
6124 */
6125 static int
6126valid_name(char_u *val, char *allowed)
6127{
6128 char_u *s;
6129
6130 for (s = val; *s != NUL; ++s)
6131 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)allowed, *s) == NULL)
6132 return FALSE;
6133 return TRUE;
6134}
6135
6136/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01006137 * Return TRUE if "val" is a valid 'filetype' name.
6138 * Also used for 'syntax' and 'keymap'.
6139 */
6140 static int
6141valid_filetype(char_u *val)
6142{
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006143 return valid_name(val, ".-_");
6144}
Bram Moolenaard0b51382016-11-04 15:23:45 +01006145
Bram Moolenaara7be0f22019-04-11 11:19:32 +02006146#if defined(FEAT_SPELL) || defined(PROTO)
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006147/*
6148 * Return TRUE if "val" is a valid 'spellang' value.
6149 */
6150 int
6151valid_spellang(char_u *val)
6152{
Bram Moolenaar9a061cb2019-05-05 16:55:03 +02006153 return valid_name(val, ".-_,@");
Bram Moolenaard0b51382016-11-04 15:23:45 +01006154}
6155
6156/*
Bram Moolenaar862f1e12019-04-10 22:33:41 +02006157 * Return TRUE if "val" is a valid 'spellfile' value.
6158 */
6159 static int
6160valid_spellfile(char_u *val)
6161{
6162 char_u *s;
6163
6164 for (s = val; *s != NUL; ++s)
6165 if (!vim_isfilec(*s) && *s != ',')
6166 return FALSE;
6167 return TRUE;
6168}
Bram Moolenaara7be0f22019-04-11 11:19:32 +02006169#endif
Bram Moolenaar862f1e12019-04-10 22:33:41 +02006170
6171/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006172 * Handle string options that need some action to perform when changed.
6173 * Returns NULL for success, or an error message for an error.
6174 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006175 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006176did_set_string_option(
Bram Moolenaar916a8182018-11-25 02:18:29 +01006177 int opt_idx, // index in options[] table
6178 char_u **varp, // pointer to the option variable
6179 int new_value_alloced, // new value was allocated
6180 char_u *oldval, // previous value of the option
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006181 char *errbuf, // buffer for errors, or NULL
Bram Moolenaar916a8182018-11-25 02:18:29 +01006182 int opt_flags, // OPT_LOCAL and/or OPT_GLOBAL
6183 int *value_checked) // value was checked to be save, no
6184 // need to set P_INSECURE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006185{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006186 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006187 char_u *s, *p;
6188 int did_chartab = FALSE;
6189 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006190 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006191#ifdef FEAT_GUI
6192 /* set when changing an option that only requires a redraw in the GUI */
6193 int redraw_gui_only = FALSE;
6194#endif
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02006195 int value_changed = FALSE;
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006196#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6197 int did_swaptcap = FALSE;
6198#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006199
6200 /* Get the global option to compare with, otherwise we would have to check
6201 * two values for all local options. */
6202 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6203
6204 /* Disallow changing some options from secure mode */
6205 if ((secure
6206#ifdef HAVE_SANDBOX
6207 || sandbox != 0
6208#endif
6209 ) && (options[opt_idx].flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006210 errmsg = e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006211
Bram Moolenaar916a8182018-11-25 02:18:29 +01006212 // Check for a "normal" directory or file name in some options. Disallow a
6213 // path separator (slash and/or backslash), wildcards and characters that
6214 // are often illegal in a file name. Be more permissive if "secure" is off.
Bram Moolenaar7554da42016-11-25 22:04:13 +01006215 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006216 && vim_strpbrk(*varp, (char_u *)(secure
6217 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006218 || ((options[opt_idx].flags & P_NDNAME)
6219 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006220 errmsg = e_invarg;
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006221
Bram Moolenaar071d4272004-06-13 20:20:40 +00006222 /* 'term' */
6223 else if (varp == &T_NAME)
6224 {
6225 if (T_NAME[0] == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006226 errmsg = N_("E529: Cannot set 'term' to empty string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006227#ifdef FEAT_GUI
6228 if (gui.in_use)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006229 errmsg = N_("E530: Cannot change term in GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006230 else if (term_is_gui(T_NAME))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006231 errmsg = N_("E531: Use \":gui\" to start the GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006232#endif
6233 else if (set_termname(T_NAME) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006234 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006235 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006236 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006237 /* Screen colors may have changed. */
6238 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006239
6240 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6241 * P_ALLOCED flag on 'term'. */
6242 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006243 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006244 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006245 }
6246
6247 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006248 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006249 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006250 char_u *bkc = p_bkc;
6251 unsigned int *flags = &bkc_flags;
6252
6253 if (opt_flags & OPT_LOCAL)
6254 {
6255 bkc = curbuf->b_p_bkc;
6256 flags = &curbuf->b_bkc_flags;
6257 }
6258
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006259 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6260 /* make the local value empty: use the global value */
6261 *flags = 0;
6262 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006263 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006264 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6265 errmsg = e_invarg;
6266 if ((((int)*flags & BKC_AUTO) != 0)
6267 + (((int)*flags & BKC_YES) != 0)
6268 + (((int)*flags & BKC_NO) != 0) != 1)
6269 {
6270 /* Must have exactly one of "auto", "yes" and "no". */
6271 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6272 errmsg = e_invarg;
6273 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006274 }
6275 }
6276
6277 /* 'backupext' and 'patchmode' */
6278 else if (varp == &p_bex || varp == &p_pm)
6279 {
6280 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6281 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006282 errmsg = N_("E589: 'backupext' and 'patchmode' are equal");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006283 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006284#ifdef FEAT_LINEBREAK
6285 /* 'breakindentopt' */
6286 else if (varp == &curwin->w_p_briopt)
6287 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006288 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006289 errmsg = e_invarg;
6290 }
6291#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006292
6293 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006294 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006295 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006296 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006297 */
6298 else if ( varp == &p_isi
6299 || varp == &(curbuf->b_p_isk)
6300 || varp == &p_isp
6301 || varp == &p_isf)
6302 {
6303 if (init_chartab() == FAIL)
6304 {
6305 did_chartab = TRUE; /* need to restore it below */
6306 errmsg = e_invarg; /* error in value */
6307 }
6308 }
6309
6310 /* 'helpfile' */
6311 else if (varp == &p_hf)
6312 {
6313 /* May compute new values for $VIM and $VIMRUNTIME */
6314 if (didset_vim)
6315 {
6316 vim_setenv((char_u *)"VIM", (char_u *)"");
6317 didset_vim = FALSE;
6318 }
6319 if (didset_vimruntime)
6320 {
6321 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6322 didset_vimruntime = FALSE;
6323 }
6324 }
6325
Bram Moolenaar1a384422010-07-14 19:53:30 +02006326#ifdef FEAT_SYN_HL
6327 /* 'colorcolumn' */
6328 else if (varp == &curwin->w_p_cc)
6329 errmsg = check_colorcolumn(curwin);
6330#endif
6331
Bram Moolenaar071d4272004-06-13 20:20:40 +00006332#ifdef FEAT_MULTI_LANG
6333 /* 'helplang' */
6334 else if (varp == &p_hlg)
6335 {
6336 /* Check for "", "ab", "ab,cd", etc. */
6337 for (s = p_hlg; *s != NUL; s += 3)
6338 {
6339 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6340 {
6341 errmsg = e_invarg;
6342 break;
6343 }
6344 if (s[2] == NUL)
6345 break;
6346 }
6347 }
6348#endif
6349
6350 /* 'highlight' */
6351 else if (varp == &p_hl)
6352 {
6353 if (highlight_changed() == FAIL)
6354 errmsg = e_invarg; /* invalid flags */
6355 }
6356
6357 /* 'nrformats' */
6358 else if (gvarp == &p_nf)
6359 {
6360 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6361 errmsg = e_invarg;
6362 }
6363
6364#ifdef FEAT_SESSION
6365 /* 'sessionoptions' */
6366 else if (varp == &p_ssop)
6367 {
6368 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6369 errmsg = e_invarg;
6370 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6371 {
6372 /* Don't allow both "sesdir" and "curdir". */
6373 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6374 errmsg = e_invarg;
6375 }
6376 }
6377 /* 'viewoptions' */
6378 else if (varp == &p_vop)
6379 {
6380 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6381 errmsg = e_invarg;
6382 }
6383#endif
6384
6385 /* 'scrollopt' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006386 else if (varp == &p_sbo)
6387 {
6388 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6389 errmsg = e_invarg;
6390 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006391
6392 /* 'ambiwidth' */
Bram Moolenaar3848e002016-03-19 18:42:29 +01006393 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006394 {
6395 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6396 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006397 else if (set_chars_option(&p_lcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006398 errmsg = _("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006399 else if (set_chars_option(&p_fcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006400 errmsg = _("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006401 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006402
6403 /* 'background' */
6404 else if (varp == &p_bg)
6405 {
6406 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6407 {
6408#ifdef FEAT_EVAL
6409 int dark = (*p_bg == 'd');
6410#endif
6411
6412 init_highlight(FALSE, FALSE);
6413
6414#ifdef FEAT_EVAL
6415 if (dark != (*p_bg == 'd')
6416 && get_var_value((char_u *)"g:colors_name") != NULL)
6417 {
6418 /* The color scheme must have set 'background' back to another
6419 * value, that's not what we want here. Disable the color
6420 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006421 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006422 free_string_option(p_bg);
6423 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6424 check_string_option(&p_bg);
6425 init_highlight(FALSE, FALSE);
6426 }
6427#endif
6428 }
6429 else
6430 errmsg = e_invarg;
6431 }
6432
6433 /* 'wildmode' */
6434 else if (varp == &p_wim)
6435 {
6436 if (check_opt_wim() == FAIL)
6437 errmsg = e_invarg;
6438 }
6439
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006440#ifdef FEAT_CMDL_COMPL
6441 /* 'wildoptions' */
6442 else if (varp == &p_wop)
6443 {
6444 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6445 errmsg = e_invarg;
6446 }
6447#endif
6448
Bram Moolenaar071d4272004-06-13 20:20:40 +00006449#ifdef FEAT_WAK
6450 /* 'winaltkeys' */
6451 else if (varp == &p_wak)
6452 {
6453 if (*p_wak == NUL
6454 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6455 errmsg = e_invarg;
6456# ifdef FEAT_MENU
6457# ifdef FEAT_GUI_MOTIF
6458 else if (gui.in_use)
6459 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6460# else
6461# ifdef FEAT_GUI_GTK
6462 else if (gui.in_use)
6463 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6464# endif
6465# endif
6466# endif
6467 }
6468#endif
6469
Bram Moolenaar071d4272004-06-13 20:20:40 +00006470 /* 'eventignore' */
6471 else if (varp == &p_ei)
6472 {
6473 if (check_ei() == FAIL)
6474 errmsg = e_invarg;
6475 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006476
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006477 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6478 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6479 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006480 {
6481 if (gvarp == &p_fenc)
6482 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006483 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006484 errmsg = e_modifiable;
6485 else if (vim_strchr(*varp, ',') != NULL)
6486 /* No comma allowed in 'fileencoding'; catches confusing it
6487 * with 'fileencodings'. */
6488 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006489 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006490 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006491#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006492 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006493 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006494#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006495 /* Add 'fileencoding' to the swap file. */
6496 ml_setflags(curbuf);
6497 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006498 }
6499 if (errmsg == NULL)
6500 {
6501 /* canonize the value, so that STRCMP() can be used on it */
6502 p = enc_canonize(*varp);
6503 if (p != NULL)
6504 {
6505 vim_free(*varp);
6506 *varp = p;
6507 }
6508 if (varp == &p_enc)
6509 {
6510 errmsg = mb_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006511#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006512 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006513#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006514 }
6515 }
6516
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006517#if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006518 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6519 {
6520 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6521 if (STRCMP(p_tenc, "utf-8") != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006522 errmsg = N_("E617: Cannot be changed in the GTK+ 2 GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006523 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006524#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006525
6526 if (errmsg == NULL)
6527 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006528#ifdef FEAT_KEYMAP
Bram Moolenaar071d4272004-06-13 20:20:40 +00006529 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6530 * (with another encoding). */
6531 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6532 (void)keymap_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006533#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006534
6535 /* When 'termencoding' is not empty and 'encoding' changes or when
6536 * 'termencoding' changes, need to setup for keyboard input and
6537 * display output conversion. */
6538 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6539 {
Bram Moolenaar17471e82017-11-26 23:47:18 +01006540 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6541 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6542 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006543 semsg(_("E950: Cannot convert between %s and %s"),
Bram Moolenaar17471e82017-11-26 23:47:18 +01006544 p_tenc, p_enc);
6545 errmsg = e_invarg;
6546 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006547 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006548
Bram Moolenaar4f974752019-02-17 17:44:42 +01006549#if defined(MSWIN)
Bram Moolenaar05159a02005-02-26 23:04:13 +00006550 /* $HOME may have characters in active code page. */
6551 if (varp == &p_enc)
6552 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006553#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006554 }
6555 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006556
6557#if defined(FEAT_POSTSCRIPT)
6558 else if (varp == &p_penc)
6559 {
6560 /* Canonize printencoding if VIM standard one */
6561 p = enc_canonize(p_penc);
6562 if (p != NULL)
6563 {
6564 vim_free(p_penc);
6565 p_penc = p;
6566 }
6567 else
6568 {
6569 /* Ensure lower case and '-' for '_' */
6570 for (s = p_penc; *s != NUL; s++)
6571 {
6572 if (*s == '_')
6573 *s = '-';
6574 else
6575 *s = TOLOWER_ASC(*s);
6576 }
6577 }
6578 }
6579#endif
6580
Bram Moolenaar9372a112005-12-06 19:59:18 +00006581#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006582 else if (varp == &p_imak)
6583 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006584 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006585 errmsg = e_invarg;
6586 }
6587#endif
6588
6589#ifdef FEAT_KEYMAP
6590 else if (varp == &curbuf->b_p_keymap)
6591 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006592 if (!valid_filetype(*varp))
6593 errmsg = e_invarg;
6594 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01006595 {
6596 int secure_save = secure;
6597
6598 // Reset the secure flag, since the value of 'keymap' has
6599 // been checked to be safe.
6600 secure = 0;
6601
6602 // load or unload key mapping tables
Bram Moolenaard0b51382016-11-04 15:23:45 +01006603 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006604
Bram Moolenaar916a8182018-11-25 02:18:29 +01006605 secure = secure_save;
6606
6607 // Since we check the value, there is no need to set P_INSECURE,
6608 // even when the value comes from a modeline.
6609 *value_checked = TRUE;
6610 }
6611
Bram Moolenaarfab06232009-03-04 03:13:35 +00006612 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006613 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006614 if (*curbuf->b_p_keymap != NUL)
6615 {
6616 /* Installed a new keymap, switch on using it. */
6617 curbuf->b_p_iminsert = B_IMODE_LMAP;
6618 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6619 curbuf->b_p_imsearch = B_IMODE_LMAP;
6620 }
6621 else
6622 {
6623 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6624 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6625 curbuf->b_p_iminsert = B_IMODE_NONE;
6626 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6627 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6628 }
6629 if ((opt_flags & OPT_LOCAL) == 0)
6630 {
6631 set_iminsert_global();
6632 set_imsearch_global();
6633 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006634 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006635 }
6636 }
6637#endif
6638
6639 /* 'fileformat' */
6640 else if (gvarp == &p_ff)
6641 {
6642 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6643 errmsg = e_modifiable;
6644 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6645 errmsg = e_invarg;
6646 else
6647 {
6648 /* may also change 'textmode' */
6649 if (get_fileformat(curbuf) == EOL_DOS)
6650 curbuf->b_p_tx = TRUE;
6651 else
6652 curbuf->b_p_tx = FALSE;
6653#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006654 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006655#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006656 /* update flag in swap file */
6657 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006658 /* Redraw needed when switching to/from "mac": a CR in the text
6659 * will be displayed differently. */
6660 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6661 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006662 }
6663 }
6664
6665 /* 'fileformats' */
6666 else if (varp == &p_ffs)
6667 {
6668 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6669 errmsg = e_invarg;
6670 else
6671 {
6672 /* also change 'textauto' */
6673 if (*p_ffs == NUL)
6674 p_ta = FALSE;
6675 else
6676 p_ta = TRUE;
6677 }
6678 }
6679
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006680#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006681 /* 'cryptkey' */
6682 else if (gvarp == &p_key)
6683 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006684# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006685 /* Make sure the ":set" command doesn't show the new value in the
6686 * history. */
6687 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006688# endif
6689 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6690 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006691 ml_set_crypt_key(curbuf, oldval,
6692 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006693 }
6694
6695 else if (gvarp == &p_cm)
6696 {
6697 if (opt_flags & OPT_LOCAL)
6698 p = curbuf->b_p_cm;
6699 else
6700 p = p_cm;
6701 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6702 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006703 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006704 errmsg = e_invarg;
6705 else
6706 {
6707 /* When setting the global value to empty, make it "zip". */
6708 if (*p_cm == NUL)
6709 {
6710 if (new_value_alloced)
6711 free_string_option(p_cm);
6712 p_cm = vim_strsave((char_u *)"zip");
6713 new_value_alloced = TRUE;
6714 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006715 /* When using ":set cm=name" the local value is going to be empty.
6716 * Do that here, otherwise the crypt functions will still use the
6717 * local value. */
6718 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6719 {
6720 free_string_option(curbuf->b_p_cm);
6721 curbuf->b_p_cm = empty_option;
6722 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006723
6724 /* Need to update the swapfile when the effective method changed.
6725 * Set "s" to the effective old value, "p" to the effective new
6726 * method and compare. */
6727 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6728 s = p_cm; /* was previously using the global value */
6729 else
6730 s = oldval;
6731 if (*curbuf->b_p_cm == NUL)
6732 p = p_cm; /* is now using the global value */
6733 else
6734 p = curbuf->b_p_cm;
6735 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006736 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006737
6738 /* If the global value changes need to update the swapfile for all
6739 * buffers using that value. */
6740 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6741 {
6742 buf_T *buf;
6743
Bram Moolenaar29323592016-07-24 22:04:11 +02006744 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006745 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006746 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006747 }
6748 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006749 }
6750#endif
6751
6752 /* 'matchpairs' */
6753 else if (gvarp == &p_mps)
6754 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006755 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006756 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006757 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006758 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006759 int x2 = -1;
6760 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006761
6762 if (*p != NUL)
6763 p += mb_ptr2len(p);
6764 if (*p != NUL)
6765 x2 = *p++;
6766 if (*p != NUL)
6767 {
6768 x3 = mb_ptr2char(p);
6769 p += mb_ptr2len(p);
6770 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006771 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006772 {
6773 errmsg = e_invarg;
6774 break;
6775 }
6776 if (*p == NUL)
6777 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006778 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006779 }
6780 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006781 {
6782 /* Check for "x:y,x:y" */
6783 for (p = *varp; *p != NUL; p += 4)
6784 {
6785 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6786 {
6787 errmsg = e_invarg;
6788 break;
6789 }
6790 if (p[3] == NUL)
6791 break;
6792 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006793 }
6794 }
6795
6796#ifdef FEAT_COMMENTS
6797 /* 'comments' */
6798 else if (gvarp == &p_com)
6799 {
6800 for (s = *varp; *s; )
6801 {
6802 while (*s && *s != ':')
6803 {
6804 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6805 && !VIM_ISDIGIT(*s) && *s != '-')
6806 {
6807 errmsg = illegal_char(errbuf, *s);
6808 break;
6809 }
6810 ++s;
6811 }
6812 if (*s++ == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006813 errmsg = N_("E524: Missing colon");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006814 else if (*s == ',' || *s == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006815 errmsg = N_("E525: Zero length string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006816 if (errmsg != NULL)
6817 break;
6818 while (*s && *s != ',')
6819 {
6820 if (*s == '\\' && s[1] != NUL)
6821 ++s;
6822 ++s;
6823 }
6824 s = skip_to_option_part(s);
6825 }
6826 }
6827#endif
6828
6829 /* 'listchars' */
6830 else if (varp == &p_lcs)
6831 {
6832 errmsg = set_chars_option(varp);
6833 }
6834
Bram Moolenaar071d4272004-06-13 20:20:40 +00006835 /* 'fillchars' */
6836 else if (varp == &p_fcs)
6837 {
6838 errmsg = set_chars_option(varp);
6839 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006840
6841#ifdef FEAT_CMDWIN
6842 /* 'cedit' */
6843 else if (varp == &p_cedit)
6844 {
6845 errmsg = check_cedit();
6846 }
6847#endif
6848
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006849 /* 'verbosefile' */
6850 else if (varp == &p_vfile)
6851 {
6852 verbose_stop();
6853 if (*p_vfile != NUL && verbose_open() == FAIL)
6854 errmsg = e_invarg;
6855 }
6856
Bram Moolenaar071d4272004-06-13 20:20:40 +00006857#ifdef FEAT_VIMINFO
6858 /* 'viminfo' */
6859 else if (varp == &p_viminfo)
6860 {
6861 for (s = p_viminfo; *s;)
6862 {
6863 /* Check it's a valid character */
6864 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6865 {
6866 errmsg = illegal_char(errbuf, *s);
6867 break;
6868 }
6869 if (*s == 'n') /* name is always last one */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006870 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006871 else if (*s == 'r') /* skip until next ',' */
6872 {
6873 while (*++s && *s != ',')
6874 ;
6875 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006876 else if (*s == '%')
6877 {
6878 /* optional number */
6879 while (vim_isdigit(*++s))
6880 ;
6881 }
6882 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006883 ++s; /* no extra chars */
6884 else /* must have a number */
6885 {
6886 while (vim_isdigit(*++s))
6887 ;
6888
6889 if (!VIM_ISDIGIT(*(s - 1)))
6890 {
6891 if (errbuf != NULL)
6892 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006893 sprintf(errbuf, _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006894 transchar_byte(*(s - 1)));
6895 errmsg = errbuf;
6896 }
6897 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006898 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006899 break;
6900 }
6901 }
6902 if (*s == ',')
6903 ++s;
6904 else if (*s)
6905 {
6906 if (errbuf != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006907 errmsg = N_("E527: Missing comma");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006908 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006909 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006910 break;
6911 }
6912 }
6913 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006914 errmsg = N_("E528: Must specify a ' value");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006915 }
6916#endif /* FEAT_VIMINFO */
6917
6918 /* terminal options */
6919 else if (istermoption(&options[opt_idx]) && full_screen)
6920 {
6921 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6922 if (varp == &T_CCO)
6923 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006924 int colors = atoi((char *)T_CCO);
6925
6926 /* Only reinitialize colors if t_Co value has really changed to
6927 * avoid expensive reload of colorscheme if t_Co is set to the
6928 * same value multiple times. */
6929 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006930 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006931 t_colors = colors;
6932 if (t_colors <= 1)
6933 {
6934 if (new_value_alloced)
6935 vim_free(T_CCO);
6936 T_CCO = empty_option;
6937 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006938#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6939 if (is_term_win32())
6940 {
6941 swap_tcap();
6942 did_swaptcap = TRUE;
6943 }
6944#endif
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006945 /* We now have a different color setup, initialize it again. */
6946 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006947 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006948 }
6949 ttest(FALSE);
6950 if (varp == &T_ME)
6951 {
6952 out_str(T_ME);
6953 redraw_later(CLEAR);
Bram Moolenaarafde13b2019-04-28 19:46:49 +02006954#if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006955 /* Since t_me has been set, this probably means that the user
6956 * wants to use this as default colors. Need to reset default
6957 * background/foreground colors. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02006958# ifdef VIMDLL
6959 if (!gui.in_use && !gui.starting)
6960# endif
6961 mch_set_normal_colors();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006962#endif
6963 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006964 if (varp == &T_BE && termcap_active)
6965 {
6966 if (*T_BE == NUL)
6967 /* When clearing t_BE we assume the user no longer wants
6968 * bracketed paste, thus disable it by writing t_BD. */
6969 out_str(T_BD);
6970 else
6971 out_str(T_BE);
6972 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006973 }
6974
6975#ifdef FEAT_LINEBREAK
6976 /* 'showbreak' */
6977 else if (varp == &p_sbr)
6978 {
6979 for (s = p_sbr; *s; )
6980 {
6981 if (ptr2cells(s) != 1)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006982 errmsg = N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006983 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006984 }
6985 }
6986#endif
6987
6988#ifdef FEAT_GUI
6989 /* 'guifont' */
6990 else if (varp == &p_guifont)
6991 {
6992 if (gui.in_use)
6993 {
6994 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006995# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006996 /*
6997 * Put up a font dialog and let the user select a new value.
6998 * If this is cancelled go back to the old value but don't
6999 * give an error message.
7000 */
7001 if (STRCMP(p, "*") == 0)
7002 {
7003 p = gui_mch_font_dialog(oldval);
7004
7005 if (new_value_alloced)
7006 free_string_option(p_guifont);
7007
7008 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
7009 new_value_alloced = TRUE;
7010 }
7011# endif
7012 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
7013 {
7014# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
7015 if (STRCMP(p_guifont, "*") == 0)
7016 {
7017 /* Dialog was cancelled: Keep the old value without giving
7018 * an error message. */
7019 if (new_value_alloced)
7020 free_string_option(p_guifont);
7021 p_guifont = vim_strsave(oldval);
7022 new_value_alloced = TRUE;
7023 }
7024 else
7025# endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007026 errmsg = N_("E596: Invalid font(s)");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007027 }
7028 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007029 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007030 }
7031# ifdef FEAT_XFONTSET
7032 else if (varp == &p_guifontset)
7033 {
7034 if (STRCMP(p_guifontset, "*") == 0)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007035 errmsg = N_("E597: can't select fontset");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007036 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007037 errmsg = N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007038 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007039 }
7040# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007041 else if (varp == &p_guifontwide)
7042 {
7043 if (STRCMP(p_guifontwide, "*") == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007044 errmsg = N_("E533: can't select wide font");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007045 else if (gui_get_wide_font() == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007046 errmsg = N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007047 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007048 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007049#endif
7050
7051#ifdef CURSOR_SHAPE
7052 /* 'guicursor' */
7053 else if (varp == &p_guicursor)
7054 errmsg = parse_shape_opt(SHAPE_CURSOR);
7055#endif
7056
7057#ifdef FEAT_MOUSESHAPE
7058 /* 'mouseshape' */
7059 else if (varp == &p_mouseshape)
7060 {
7061 errmsg = parse_shape_opt(SHAPE_MOUSE);
7062 update_mouseshape(-1);
7063 }
7064#endif
7065
7066#ifdef FEAT_PRINTER
7067 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00007068 errmsg = parse_printoptions();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01007069# if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00007070 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00007071 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00007072# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007073#endif
7074
7075#ifdef FEAT_LANGMAP
7076 /* 'langmap' */
7077 else if (varp == &p_langmap)
7078 langmap_set();
7079#endif
7080
7081#ifdef FEAT_LINEBREAK
7082 /* 'breakat' */
7083 else if (varp == &p_breakat)
7084 fill_breakat_flags();
7085#endif
7086
7087#ifdef FEAT_TITLE
7088 /* 'titlestring' and 'iconstring' */
7089 else if (varp == &p_titlestring || varp == &p_iconstring)
7090 {
7091# ifdef FEAT_STL_OPT
7092 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
7093
7094 /* NULL => statusline syntax */
7095 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
7096 stl_syntax |= flagval;
7097 else
7098 stl_syntax &= ~flagval;
7099# endif
Bram Moolenaar84a93082018-06-16 22:58:15 +02007100 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007101 }
7102#endif
7103
7104#ifdef FEAT_GUI
7105 /* 'guioptions' */
7106 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007107 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007108 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007109 redraw_gui_only = TRUE;
7110 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007111#endif
7112
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00007113#if defined(FEAT_GUI_TABLINE)
7114 /* 'guitablabel' */
7115 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007116 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00007117 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007118 redraw_gui_only = TRUE;
7119 }
7120 /* 'guitabtooltip' */
7121 else if (varp == &p_gtt)
7122 {
7123 redraw_gui_only = TRUE;
7124 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00007125#endif
7126
Bram Moolenaar071d4272004-06-13 20:20:40 +00007127#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
7128 /* 'ttymouse' */
7129 else if (varp == &p_ttym)
7130 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007131 /* Switch the mouse off before changing the escape sequences used for
7132 * that. */
7133 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007134 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
7135 errmsg = e_invarg;
7136 else
7137 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00007138 if (termcap_active)
7139 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007140 }
7141#endif
7142
Bram Moolenaar071d4272004-06-13 20:20:40 +00007143 /* 'selection' */
7144 else if (varp == &p_sel)
7145 {
7146 if (*p_sel == NUL
7147 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
7148 errmsg = e_invarg;
7149 }
7150
7151 /* 'selectmode' */
7152 else if (varp == &p_slm)
7153 {
7154 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
7155 errmsg = e_invarg;
7156 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007157
7158#ifdef FEAT_BROWSE
7159 /* 'browsedir' */
7160 else if (varp == &p_bsdir)
7161 {
7162 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7163 && !mch_isdir(p_bsdir))
7164 errmsg = e_invarg;
7165 }
7166#endif
7167
Bram Moolenaar071d4272004-06-13 20:20:40 +00007168 /* 'keymodel' */
7169 else if (varp == &p_km)
7170 {
7171 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7172 errmsg = e_invarg;
7173 else
7174 {
7175 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7176 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7177 }
7178 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007179
7180 /* 'mousemodel' */
7181 else if (varp == &p_mousem)
7182 {
7183 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7184 errmsg = e_invarg;
7185#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7186 else if (*p_mousem != *oldval)
7187 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7188 * to create or delete the popup menus. */
7189 gui_motif_update_mousemodel(root_menu);
7190#endif
7191 }
7192
7193 /* 'switchbuf' */
7194 else if (varp == &p_swb)
7195 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007196 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007197 errmsg = e_invarg;
7198 }
7199
7200 /* 'debug' */
7201 else if (varp == &p_debug)
7202 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007203 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007204 errmsg = e_invarg;
7205 }
7206
7207 /* 'display' */
7208 else if (varp == &p_dy)
7209 {
7210 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7211 errmsg = e_invarg;
7212 else
7213 (void)init_chartab();
7214
7215 }
7216
Bram Moolenaar071d4272004-06-13 20:20:40 +00007217 /* 'eadirection' */
7218 else if (varp == &p_ead)
7219 {
7220 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7221 errmsg = e_invarg;
7222 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007223
7224#ifdef FEAT_CLIPBOARD
7225 /* 'clipboard' */
7226 else if (varp == &p_cb)
7227 errmsg = check_clipboard_option();
7228#endif
7229
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007230#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007231 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7232 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007233 else if (varp == &(curwin->w_s->b_p_spl)
7234 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007235 {
Bram Moolenaar862f1e12019-04-10 22:33:41 +02007236 int is_spellfile = varp == &(curwin->w_s->b_p_spf);
7237
7238 if ((is_spellfile && !valid_spellfile(*varp))
7239 || (!is_spellfile && !valid_spellang(*varp)))
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02007240 errmsg = e_invarg;
7241 else
Bram Moolenaar862f1e12019-04-10 22:33:41 +02007242 errmsg = did_set_spell_option(is_spellfile);
Bram Moolenaar217ad922005-03-20 22:37:15 +00007243 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007244 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007245 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007246 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007247 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007248 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007249 /* 'spellsuggest' */
7250 else if (varp == &p_sps)
7251 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007252 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007253 errmsg = e_invarg;
7254 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007255 /* 'mkspellmem' */
7256 else if (varp == &p_msm)
7257 {
7258 if (spell_check_msm() != OK)
7259 errmsg = e_invarg;
7260 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007261#endif
7262
Bram Moolenaar071d4272004-06-13 20:20:40 +00007263 /* When 'bufhidden' is set, check for valid value. */
7264 else if (gvarp == &p_bh)
7265 {
7266 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7267 errmsg = e_invarg;
7268 }
7269
7270 /* When 'buftype' is set, check for valid value. */
7271 else if (gvarp == &p_bt)
7272 {
7273 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7274 errmsg = e_invarg;
7275 else
7276 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007277 if (curwin->w_status_height)
7278 {
7279 curwin->w_redr_status = TRUE;
7280 redraw_later(VALID);
7281 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007282 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007283#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007284 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007285#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007286 }
7287 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007288
7289#ifdef FEAT_STL_OPT
7290 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007291 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007292 {
7293 int wid;
7294
7295 if (varp == &p_ruf) /* reset ru_wid first */
7296 ru_wid = 0;
7297 s = *varp;
7298 if (varp == &p_ruf && *s == '%')
7299 {
7300 /* set ru_wid if 'ruf' starts with "%99(" */
7301 if (*++s == '-') /* ignore a '-' */
7302 s++;
7303 wid = getdigits(&s);
7304 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7305 ru_wid = wid;
7306 else
7307 errmsg = check_stl_option(p_ruf);
7308 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007309 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007310 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007311 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007312 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007313 comp_col();
7314 }
7315#endif
7316
7317#ifdef FEAT_INS_EXPAND
7318 /* check if it is a valid value for 'complete' -- Acevedo */
7319 else if (gvarp == &p_cpt)
7320 {
7321 for (s = *varp; *s;)
7322 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007323 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007324 s++;
7325 if (!*s)
7326 break;
7327 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7328 {
7329 errmsg = illegal_char(errbuf, *s);
7330 break;
7331 }
7332 if (*++s != NUL && *s != ',' && *s != ' ')
7333 {
7334 if (s[-1] == 'k' || s[-1] == 's')
7335 {
7336 /* skip optional filename after 'k' and 's' */
7337 while (*s && *s != ',' && *s != ' ')
7338 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007339 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007340 ++s;
7341 ++s;
7342 }
7343 }
7344 else
7345 {
7346 if (errbuf != NULL)
7347 {
7348 sprintf((char *)errbuf,
7349 _("E535: Illegal character after <%c>"),
7350 *--s);
7351 errmsg = errbuf;
7352 }
7353 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007354 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00007355 break;
7356 }
7357 }
7358 }
7359 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007360
7361 /* 'completeopt' */
7362 else if (varp == &p_cot)
7363 {
7364 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7365 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007366 else
7367 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007368 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007369#endif /* FEAT_INS_EXPAND */
7370
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007371#ifdef FEAT_SIGNS
7372 /* 'signcolumn' */
7373 else if (varp == &curwin->w_p_scl)
7374 {
7375 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7376 errmsg = e_invarg;
7377 }
7378#endif
7379
Bram Moolenaar071d4272004-06-13 20:20:40 +00007380
Bram Moolenaar4f974752019-02-17 17:44:42 +01007381#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007382 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007383 else if (varp == &p_toolbar)
7384 {
7385 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7386 &toolbar_flags, TRUE) != OK)
7387 errmsg = e_invarg;
7388 else
7389 {
7390 out_flush();
7391 gui_mch_show_toolbar((toolbar_flags &
7392 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7393 }
7394 }
7395#endif
7396
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007397#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007398 /* 'toolbariconsize': GTK+ 2 only */
7399 else if (varp == &p_tbis)
7400 {
7401 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7402 errmsg = e_invarg;
7403 else
7404 {
7405 out_flush();
7406 gui_mch_show_toolbar((toolbar_flags &
7407 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7408 }
7409 }
7410#endif
7411
7412 /* 'pastetoggle': translate key codes like in a mapping */
7413 else if (varp == &p_pt)
7414 {
7415 if (*p_pt)
7416 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007417 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007418 if (p != NULL)
7419 {
7420 if (new_value_alloced)
7421 free_string_option(p_pt);
7422 p_pt = p;
7423 new_value_alloced = TRUE;
7424 }
7425 }
7426 }
7427
7428 /* 'backspace' */
7429 else if (varp == &p_bs)
7430 {
7431 if (VIM_ISDIGIT(*p_bs))
7432 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007433 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007434 errmsg = e_invarg;
7435 }
7436 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7437 errmsg = e_invarg;
7438 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007439 else if (varp == &p_bo)
7440 {
7441 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7442 errmsg = e_invarg;
7443 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007444
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007445 /* 'tagcase' */
7446 else if (gvarp == &p_tc)
7447 {
7448 unsigned int *flags;
7449
7450 if (opt_flags & OPT_LOCAL)
7451 {
7452 p = curbuf->b_p_tc;
7453 flags = &curbuf->b_tc_flags;
7454 }
7455 else
7456 {
7457 p = p_tc;
7458 flags = &tc_flags;
7459 }
7460
7461 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7462 /* make the local value empty: use the global value */
7463 *flags = 0;
7464 else if (*p == NUL
7465 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7466 errmsg = e_invarg;
7467 }
7468
Bram Moolenaar071d4272004-06-13 20:20:40 +00007469 /* 'casemap' */
7470 else if (varp == &p_cmp)
7471 {
7472 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7473 errmsg = e_invarg;
7474 }
7475
7476#ifdef FEAT_DIFF
7477 /* 'diffopt' */
7478 else if (varp == &p_dip)
7479 {
7480 if (diffopt_changed() == FAIL)
7481 errmsg = e_invarg;
7482 }
7483#endif
7484
7485#ifdef FEAT_FOLDING
7486 /* 'foldmethod' */
7487 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7488 {
7489 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7490 || *curwin->w_p_fdm == NUL)
7491 errmsg = e_invarg;
7492 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007493 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007494 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007495 if (foldmethodIsDiff(curwin))
7496 newFoldLevel();
7497 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007498 }
7499# ifdef FEAT_EVAL
7500 /* 'foldexpr' */
7501 else if (varp == &curwin->w_p_fde)
7502 {
7503 if (foldmethodIsExpr(curwin))
7504 foldUpdateAll(curwin);
7505 }
7506# endif
7507 /* 'foldmarker' */
7508 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7509 {
7510 p = vim_strchr(*varp, ',');
7511 if (p == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007512 errmsg = N_("E536: comma required");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007513 else if (p == *varp || p[1] == NUL)
7514 errmsg = e_invarg;
7515 else if (foldmethodIsMarker(curwin))
7516 foldUpdateAll(curwin);
7517 }
7518 /* 'commentstring' */
7519 else if (gvarp == &p_cms)
7520 {
7521 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007522 errmsg = N_("E537: 'commentstring' must be empty or contain %s");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007523 }
7524 /* 'foldopen' */
7525 else if (varp == &p_fdo)
7526 {
7527 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7528 errmsg = e_invarg;
7529 }
7530 /* 'foldclose' */
7531 else if (varp == &p_fcl)
7532 {
7533 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7534 errmsg = e_invarg;
7535 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007536 /* 'foldignore' */
7537 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7538 {
7539 if (foldmethodIsIndent(curwin))
7540 foldUpdateAll(curwin);
7541 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007542#endif
7543
Bram Moolenaar071d4272004-06-13 20:20:40 +00007544 /* 'virtualedit' */
7545 else if (varp == &p_ve)
7546 {
7547 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7548 errmsg = e_invarg;
7549 else if (STRCMP(p_ve, oldval) != 0)
7550 {
7551 /* Recompute cursor position in case the new 've' setting
7552 * changes something. */
7553 validate_virtcol();
7554 coladvance(curwin->w_virtcol);
7555 }
7556 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007557
7558#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7559 else if (varp == &p_csqf)
7560 {
7561 if (p_csqf != NULL)
7562 {
7563 p = p_csqf;
7564 while (*p != NUL)
7565 {
7566 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7567 || p[1] == NUL
7568 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7569 || (p[2] != NUL && p[2] != ','))
7570 {
7571 errmsg = e_invarg;
7572 break;
7573 }
7574 else if (p[2] == NUL)
7575 break;
7576 else
7577 p += 3;
7578 }
7579 }
7580 }
7581#endif
7582
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007583#ifdef FEAT_CINDENT
7584 /* 'cinoptions' */
7585 else if (gvarp == &p_cino)
7586 {
7587 /* TODO: recognize errors */
7588 parse_cino(curbuf);
7589 }
7590#endif
7591
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007592#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007593 /* 'renderoptions' */
Bram Moolenaar3767c6e2017-12-05 16:57:56 +01007594 else if (varp == &p_rop)
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007595 {
7596 if (!gui_mch_set_rendering_options(p_rop))
7597 errmsg = e_invarg;
7598 }
7599#endif
7600
Bram Moolenaard0b51382016-11-04 15:23:45 +01007601 else if (gvarp == &p_ft)
7602 {
7603 if (!valid_filetype(*varp))
7604 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007605 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007606 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007607 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007608
7609 // Since we check the value, there is no need to set P_INSECURE,
7610 // even when the value comes from a modeline.
7611 *value_checked = TRUE;
7612 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007613 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007614
7615#ifdef FEAT_SYN_HL
7616 else if (gvarp == &p_syn)
7617 {
7618 if (!valid_filetype(*varp))
7619 errmsg = e_invarg;
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007620 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007621 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007622 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007623
7624 // Since we check the value, there is no need to set P_INSECURE,
7625 // even when the value comes from a modeline.
7626 *value_checked = TRUE;
7627 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007628 }
7629#endif
7630
Bram Moolenaar825680f2017-07-22 17:04:02 +02007631#ifdef FEAT_TERMINAL
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007632 // 'termwinkey'
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007633 else if (varp == &curwin->w_p_twk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007634 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007635 if (*curwin->w_p_twk != NUL
7636 && string_to_key(curwin->w_p_twk, TRUE) == 0)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007637 errmsg = e_invarg;
7638 }
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007639 // 'termwinsize'
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007640 else if (varp == &curwin->w_p_tws)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007641 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007642 if (*curwin->w_p_tws != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007643 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007644 p = skipdigits(curwin->w_p_tws);
7645 if (p == curwin->w_p_tws
Bram Moolenaar498c2562018-04-15 23:45:15 +02007646 || (*p != 'x' && *p != '*')
7647 || *skipdigits(p + 1) != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007648 errmsg = e_invarg;
7649 }
7650 }
Bram Moolenaar4f974752019-02-17 17:44:42 +01007651# if defined(MSWIN)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007652 // 'termwintype'
7653 else if (varp == &p_twt)
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007654 {
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007655 if (check_opt_strings(*varp, p_twt_values, FALSE) != OK)
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007656 errmsg = e_invarg;
7657 }
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007658# endif
Bram Moolenaar825680f2017-07-22 17:04:02 +02007659#endif
7660
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007661#ifdef FEAT_VARTABS
7662 /* 'varsofttabstop' */
7663 else if (varp == &(curbuf->b_p_vsts))
7664 {
7665 char_u *cp;
7666
7667 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7668 {
7669 if (curbuf->b_p_vsts_array)
7670 {
7671 vim_free(curbuf->b_p_vsts_array);
7672 curbuf->b_p_vsts_array = 0;
7673 }
7674 }
7675 else
7676 {
7677 for (cp = *varp; *cp; ++cp)
7678 {
7679 if (vim_isdigit(*cp))
7680 continue;
7681 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7682 continue;
7683 errmsg = e_invarg;
7684 break;
7685 }
7686 if (errmsg == NULL)
7687 {
7688 int *oldarray = curbuf->b_p_vsts_array;
7689 if (tabstop_set(*varp, &(curbuf->b_p_vsts_array)))
7690 {
7691 if (oldarray)
7692 vim_free(oldarray);
7693 }
7694 else
7695 errmsg = e_invarg;
7696 }
7697 }
7698 }
7699
7700 /* 'vartabstop' */
7701 else if (varp == &(curbuf->b_p_vts))
7702 {
7703 char_u *cp;
7704
7705 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7706 {
7707 if (curbuf->b_p_vts_array)
7708 {
7709 vim_free(curbuf->b_p_vts_array);
7710 curbuf->b_p_vts_array = NULL;
7711 }
7712 }
7713 else
7714 {
7715 for (cp = *varp; *cp; ++cp)
7716 {
7717 if (vim_isdigit(*cp))
7718 continue;
7719 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7720 continue;
7721 errmsg = e_invarg;
7722 break;
7723 }
7724 if (errmsg == NULL)
7725 {
7726 int *oldarray = curbuf->b_p_vts_array;
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007727
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007728 if (tabstop_set(*varp, &(curbuf->b_p_vts_array)))
7729 {
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007730 vim_free(oldarray);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007731#ifdef FEAT_FOLDING
7732 if (foldmethodIsIndent(curwin))
7733 foldUpdateAll(curwin);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007734#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007735 }
7736 else
7737 errmsg = e_invarg;
7738 }
7739 }
7740 }
7741#endif
7742
Bram Moolenaar071d4272004-06-13 20:20:40 +00007743 /* Options that are a list of flags. */
7744 else
7745 {
7746 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007747 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007748 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007749 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007750 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007751 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007752 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007753 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007754 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007755#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007756 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007757 p = (char_u *)COCU_ALL;
7758#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007759 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007760 {
7761#ifdef FEAT_MOUSE
7762 p = (char_u *)MOUSE_ALL;
7763#else
7764 if (*p_mouse != NUL)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007765 errmsg = N_("E538: No mouse support");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007766#endif
7767 }
7768#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007769 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007770 p = (char_u *)GO_ALL;
7771#endif
7772 if (p != NULL)
7773 {
7774 for (s = *varp; *s; ++s)
7775 if (vim_strchr(p, *s) == NULL)
7776 {
7777 errmsg = illegal_char(errbuf, *s);
7778 break;
7779 }
7780 }
7781 }
7782
7783 /*
7784 * If error detected, restore the previous value.
7785 */
7786 if (errmsg != NULL)
7787 {
7788 if (new_value_alloced)
7789 free_string_option(*varp);
7790 *varp = oldval;
7791 /*
7792 * When resetting some values, need to act on it.
7793 */
7794 if (did_chartab)
7795 (void)init_chartab();
7796 if (varp == &p_hl)
7797 (void)highlight_changed();
7798 }
7799 else
7800 {
7801#ifdef FEAT_EVAL
7802 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02007803 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007804#endif
7805 /*
7806 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007807 * Use "free_oldval", because recursiveness may change the flags under
7808 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007809 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007810 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007811 free_string_option(oldval);
7812 if (new_value_alloced)
7813 options[opt_idx].flags |= P_ALLOCED;
7814 else
7815 options[opt_idx].flags &= ~P_ALLOCED;
7816
7817 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007818 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007819 {
7820 /* global option with local value set to use global value; free
7821 * the local value and make it empty */
7822 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7823 free_string_option(*(char_u **)p);
7824 *(char_u **)p = empty_option;
7825 }
7826
7827 /* May set global value for local option. */
7828 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7829 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007830
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007831 /*
7832 * Trigger the autocommand only after setting the flags.
7833 */
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007834#ifdef FEAT_SYN_HL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007835 /* When 'syntax' is set, load the syntax of that name */
7836 if (varp == &(curbuf->b_p_syn))
7837 {
Bram Moolenaara5616b02018-06-17 19:08:30 +02007838 static int syn_recursive = 0;
7839
7840 ++syn_recursive;
7841 // Only pass TRUE for "force" when the value changed or not used
7842 // recursively, to avoid endless recurrence.
7843 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname,
7844 value_changed || syn_recursive == 1, curbuf);
7845 --syn_recursive;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007846 }
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007847#endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007848 else if (varp == &(curbuf->b_p_ft))
7849 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007850 /* 'filetype' is set, trigger the FileType autocommand.
7851 * Skip this when called from a modeline and the filetype was
Bram Moolenaara5616b02018-06-17 19:08:30 +02007852 * already set to this value. */
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007853 if (!(opt_flags & OPT_MODELINE) || value_changed)
Bram Moolenaar90492982017-06-22 14:16:31 +02007854 {
Bram Moolenaar916a8182018-11-25 02:18:29 +01007855 static int ft_recursive = 0;
7856 int secure_save = secure;
7857
7858 // Reset the secure flag, since the value of 'filetype' has
7859 // been checked to be safe.
7860 secure = 0;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007861
7862 ++ft_recursive;
Bram Moolenaar90492982017-06-22 14:16:31 +02007863 did_filetype = TRUE;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007864 // Only pass TRUE for "force" when the value changed or not
7865 // used recursively, to avoid endless recurrence.
7866 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname,
7867 value_changed || ft_recursive == 1, curbuf);
7868 --ft_recursive;
Bram Moolenaar163095f2017-07-09 15:41:53 +02007869 /* Just in case the old "curbuf" is now invalid. */
7870 if (varp != &(curbuf->b_p_ft))
7871 varp = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007872
7873 secure = secure_save;
Bram Moolenaar90492982017-06-22 14:16:31 +02007874 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007875 }
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007876#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007877 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007878 {
7879 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007880 char_u *q = curwin->w_s->b_p_spl;
7881
7882 /* Skip the first name if it is "cjk". */
7883 if (STRNCMP(q, "cjk,", 4) == 0)
7884 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007885
7886 /*
7887 * Source the spell/LANG.vim in 'runtimepath'.
7888 * They could set 'spellcapcheck' depending on the language.
7889 * Use the first name in 'spelllang' up to '_region' or
7890 * '.encoding'.
7891 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007892 for (p = q; *p != NUL; ++p)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01007893 if (!ASCII_ISALNUM(*p) && *p != '-')
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007894 break;
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007895 if (p > q)
7896 {
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02007897 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
7898 (int)(p - q), q);
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007899 source_runtime(fname, DIP_ALL);
7900 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007901 }
7902#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007903 }
7904
7905#ifdef FEAT_MOUSE
7906 if (varp == &p_mouse)
7907 {
7908# ifdef FEAT_MOUSE_TTY
7909 if (*p_mouse == NUL)
7910 mch_setmouse(FALSE); /* switch mouse off */
7911 else
7912# endif
7913 setmouse(); /* in case 'mouse' changed */
7914 }
7915#endif
7916
Bram Moolenaar913077c2012-03-28 19:59:04 +02007917 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007918 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007919 curwin->w_set_curswant = TRUE;
7920
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007921#ifdef FEAT_GUI
7922 /* check redraw when it's not a GUI option or the GUI is active. */
7923 if (!redraw_gui_only || gui.in_use)
7924#endif
7925 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007926
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007927#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
7928 if (did_swaptcap)
7929 {
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007930 set_termname((char_u *)"win32");
7931 init_highlight(TRUE, FALSE);
7932 }
7933#endif
7934
Bram Moolenaar071d4272004-06-13 20:20:40 +00007935 return errmsg;
7936}
7937
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007938#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007939/*
7940 * Simple int comparison function for use with qsort()
7941 */
7942 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007943int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007944{
7945 return *(const int *)a - *(const int *)b;
7946}
7947
7948/*
7949 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7950 * Returns error message, NULL if it's OK.
7951 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007952 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007953check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007954{
7955 char_u *s;
7956 int col;
7957 int count = 0;
7958 int color_cols[256];
7959 int i;
7960 int j = 0;
7961
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007962 if (wp->w_buffer == NULL)
7963 return NULL; /* buffer was closed */
7964
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007965 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007966 {
7967 if (*s == '-' || *s == '+')
7968 {
7969 /* -N and +N: add to 'textwidth' */
7970 col = (*s == '-') ? -1 : 1;
7971 ++s;
7972 if (!VIM_ISDIGIT(*s))
7973 return e_invarg;
7974 col = col * getdigits(&s);
7975 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007976 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007977 col += wp->w_buffer->b_p_tw;
7978 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007979 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007980 }
7981 else if (VIM_ISDIGIT(*s))
7982 col = getdigits(&s);
7983 else
7984 return e_invarg;
7985 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007986skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007987 if (*s == NUL)
7988 break;
7989 if (*s != ',')
7990 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007991 if (*++s == NUL)
7992 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007993 }
7994
7995 vim_free(wp->w_p_cc_cols);
7996 if (count == 0)
7997 wp->w_p_cc_cols = NULL;
7998 else
7999 {
Bram Moolenaarc799fe22019-05-28 23:08:19 +02008000 wp->w_p_cc_cols = ALLOC_MULT(int, count + 1);
Bram Moolenaar1a384422010-07-14 19:53:30 +02008001 if (wp->w_p_cc_cols != NULL)
8002 {
8003 /* sort the columns for faster usage on screen redraw inside
8004 * win_line() */
8005 qsort(color_cols, count, sizeof(int), int_cmp);
8006
8007 for (i = 0; i < count; ++i)
8008 /* skip duplicates */
8009 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
8010 wp->w_p_cc_cols[j++] = color_cols[i];
8011 wp->w_p_cc_cols[j] = -1; /* end marker */
8012 }
8013 }
8014
8015 return NULL; /* no error */
8016}
8017#endif
8018
Bram Moolenaar071d4272004-06-13 20:20:40 +00008019/*
8020 * Handle setting 'listchars' or 'fillchars'.
8021 * Returns error message, NULL if it's OK.
8022 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008023 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008024set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008025{
8026 int round, i, len, entries;
8027 char_u *p, *s;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008028 int c1 = 0, c2 = 0, c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008029 struct charstab
8030 {
8031 int *cp;
8032 char *name;
8033 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00008034 static struct charstab filltab[] =
8035 {
8036 {&fill_stl, "stl"},
8037 {&fill_stlnc, "stlnc"},
8038 {&fill_vert, "vert"},
8039 {&fill_fold, "fold"},
8040 {&fill_diff, "diff"},
8041 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00008042 static struct charstab lcstab[] =
8043 {
8044 {&lcs_eol, "eol"},
8045 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008046 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00008047 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02008048 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00008049 {&lcs_tab2, "tab"},
8050 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02008051#ifdef FEAT_CONCEAL
8052 {&lcs_conceal, "conceal"},
8053#else
8054 {NULL, "conceal"},
8055#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008056 };
8057 struct charstab *tab;
8058
Bram Moolenaar071d4272004-06-13 20:20:40 +00008059 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008060 {
8061 tab = lcstab;
8062 entries = sizeof(lcstab) / sizeof(struct charstab);
8063 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008064 else
8065 {
8066 tab = filltab;
8067 entries = sizeof(filltab) / sizeof(struct charstab);
8068 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008069
8070 /* first round: check for valid value, second round: assign values */
8071 for (round = 0; round <= 1; ++round)
8072 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008073 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008074 {
8075 /* After checking that the value is valid: set defaults: space for
8076 * 'fillchars', NUL for 'listchars' */
8077 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008078 if (tab[i].cp != NULL)
8079 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar83a52172019-01-16 22:41:54 +01008080
Bram Moolenaar071d4272004-06-13 20:20:40 +00008081 if (varp == &p_lcs)
Bram Moolenaar83a52172019-01-16 22:41:54 +01008082 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008083 lcs_tab1 = NUL;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008084 lcs_tab3 = NUL;
8085 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008086 else
8087 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008088 }
8089 p = *varp;
8090 while (*p)
8091 {
8092 for (i = 0; i < entries; ++i)
8093 {
8094 len = (int)STRLEN(tab[i].name);
8095 if (STRNCMP(p, tab[i].name, len) == 0
8096 && p[len] == ':'
8097 && p[len + 1] != NUL)
8098 {
Bram Moolenaar2c519cf2019-03-21 21:45:34 +01008099 c2 = c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008100 s = p + len + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008101 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00008102 if (mb_char2cells(c1) > 1)
8103 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008104 if (tab[i].cp == &lcs_tab2)
8105 {
8106 if (*s == NUL)
8107 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008108 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00008109 if (mb_char2cells(c2) > 1)
8110 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008111 if (!(*s == ',' || *s == NUL))
8112 {
Bram Moolenaar83a52172019-01-16 22:41:54 +01008113 c3 = mb_ptr2char_adv(&s);
8114 if (mb_char2cells(c3) > 1)
8115 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008116 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008117 }
Bram Moolenaar83a52172019-01-16 22:41:54 +01008118
Bram Moolenaar071d4272004-06-13 20:20:40 +00008119 if (*s == ',' || *s == NUL)
8120 {
8121 if (round)
8122 {
8123 if (tab[i].cp == &lcs_tab2)
8124 {
8125 lcs_tab1 = c1;
8126 lcs_tab2 = c2;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008127 lcs_tab3 = c3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008128 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008129 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008130 *(tab[i].cp) = c1;
8131
8132 }
8133 p = s;
8134 break;
8135 }
8136 }
8137 }
8138
8139 if (i == entries)
8140 return e_invarg;
8141 if (*p == ',')
8142 ++p;
8143 }
8144 }
8145
8146 return NULL; /* no error */
8147}
8148
8149#ifdef FEAT_STL_OPT
8150/*
8151 * Check validity of options with the 'statusline' format.
8152 * Return error message or NULL.
8153 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008154 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008155check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008156{
8157 int itemcnt = 0;
8158 int groupdepth = 0;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008159 static char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00008160
8161 while (*s && itemcnt < STL_MAX_ITEM)
8162 {
8163 /* Check for valid keys after % sequences */
8164 while (*s && *s != '%')
8165 s++;
8166 if (!*s)
8167 break;
8168 s++;
8169 if (*s != '%' && *s != ')')
8170 ++itemcnt;
8171 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
8172 {
8173 s++;
8174 continue;
8175 }
8176 if (*s == ')')
8177 {
8178 s++;
8179 if (--groupdepth < 0)
8180 break;
8181 continue;
8182 }
8183 if (*s == '-')
8184 s++;
8185 while (VIM_ISDIGIT(*s))
8186 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00008187 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008188 continue;
8189 if (*s == '.')
8190 {
8191 s++;
8192 while (*s && VIM_ISDIGIT(*s))
8193 s++;
8194 }
8195 if (*s == '(')
8196 {
8197 groupdepth++;
8198 continue;
8199 }
8200 if (vim_strchr(STL_ALL, *s) == NULL)
8201 {
8202 return illegal_char(errbuf, *s);
8203 }
8204 if (*s == '{')
8205 {
8206 s++;
8207 while (*s != '}' && *s)
8208 s++;
8209 if (*s != '}')
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008210 return N_("E540: Unclosed expression sequence");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008211 }
8212 }
8213 if (itemcnt >= STL_MAX_ITEM)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008214 return N_("E541: too many items");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008215 if (groupdepth != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008216 return N_("E542: unbalanced groups");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008217 return NULL;
8218}
8219#endif
8220
8221#ifdef FEAT_CLIPBOARD
8222/*
8223 * Extract the items in the 'clipboard' option and set global values.
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008224 * Return an error message or NULL for success.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008225 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008226 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008227check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008228{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008229 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008230 int new_autoselect_star = FALSE;
8231 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008232 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008233 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008234 regprog_T *new_exclude_prog = NULL;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008235 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008236 char_u *p;
8237
8238 for (p = p_cb; *p != NUL; )
8239 {
8240 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
8241 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008242 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008243 p += 7;
8244 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02008245 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008246 && (p[11] == ',' || p[11] == NUL))
8247 {
8248 new_unnamed |= CLIP_UNNAMED_PLUS;
8249 p += 11;
8250 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008251 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008252 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008253 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02008254 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008255 p += 10;
8256 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02008257 else if (STRNCMP(p, "autoselectplus", 14) == 0
8258 && (p[14] == ',' || p[14] == NUL))
8259 {
8260 new_autoselect_plus = TRUE;
8261 p += 14;
8262 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008263 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008264 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008265 {
8266 new_autoselectml = TRUE;
8267 p += 12;
8268 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008269 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
8270 {
8271 new_html = TRUE;
8272 p += 4;
8273 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008274 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
8275 {
8276 p += 8;
8277 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
8278 if (new_exclude_prog == NULL)
8279 errmsg = e_invarg;
8280 break;
8281 }
8282 else
8283 {
8284 errmsg = e_invarg;
8285 break;
8286 }
8287 if (*p == ',')
8288 ++p;
8289 }
8290 if (errmsg == NULL)
8291 {
8292 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008293 clip_autoselect_star = new_autoselect_star;
8294 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008295 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008296 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008297 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008298 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008299#ifdef FEAT_GUI_GTK
8300 if (gui.in_use)
8301 {
8302 gui_gtk_set_selection_targets();
8303 gui_gtk_set_dnd_targets();
8304 }
8305#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008306 }
8307 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008308 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008309
8310 return errmsg;
8311}
8312#endif
8313
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008314#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008315/*
8316 * Handle side effects of setting 'spell'.
8317 * Return an error message or NULL for success.
8318 */
8319 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008320did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008321{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008322 char *errmsg = NULL;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008323 win_T *wp;
8324 int l;
8325
8326 if (is_spellfile)
8327 {
8328 l = (int)STRLEN(curwin->w_s->b_p_spf);
8329 if (l > 0 && (l < 4
8330 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8331 errmsg = e_invarg;
8332 }
8333
8334 if (errmsg == NULL)
8335 {
8336 FOR_ALL_WINDOWS(wp)
8337 if (wp->w_buffer == curbuf && wp->w_p_spell)
8338 {
8339 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008340 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008341 }
8342 }
8343 return errmsg;
8344}
8345
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008346/*
8347 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8348 * Return error message when failed, NULL when OK.
8349 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008350 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008351compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008352{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008353 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008354 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008355
Bram Moolenaar860cae12010-06-05 23:22:07 +02008356 if (*synblock->b_p_spc == NUL)
8357 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008358 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008359 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008360 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008361 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008362 if (re != NULL)
8363 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008364 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008365 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008366 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008367 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008368 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008369 return e_invarg;
8370 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008371 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008372 }
8373
Bram Moolenaar473de612013-06-08 18:19:48 +02008374 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008375 return NULL;
8376}
8377#endif
8378
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008379#if defined(FEAT_EVAL) || defined(PROTO)
8380/*
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008381 * Set the script_ctx for an option, taking care of setting the buffer- or
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008382 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008383 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008384 static void
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008385set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008386{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008387 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8388 int indir = (int)options[opt_idx].indir;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008389 sctx_T new_script_ctx = script_ctx;
8390
8391 new_script_ctx.sc_lnum += sourcing_lnum;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008392
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008393 /* Remember where the option was set. For local options need to do that
8394 * in the buffer or window structure. */
8395 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008396 options[opt_idx].script_ctx = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008397 if (both || (opt_flags & OPT_LOCAL))
8398 {
8399 if (indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008400 curbuf->b_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008401 else if (indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008402 curwin->w_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008403 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008404}
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02008405
8406/*
8407 * Set the script_ctx for a termcap option.
8408 * "name" must be the two character code, e.g. "RV".
8409 * When "name" is NULL use "opt_idx".
8410 */
8411 void
8412set_term_option_sctx_idx(char *name, int opt_idx)
8413{
8414 char_u buf[5];
8415 int idx;
8416
8417 if (name == NULL)
8418 idx = opt_idx;
8419 else
8420 {
8421 buf[0] = 't';
8422 buf[1] = '_';
8423 buf[2] = name[0];
8424 buf[3] = name[1];
8425 buf[4] = 0;
8426 idx = findoption(buf);
8427 }
8428 if (idx >= 0)
8429 set_option_sctx_idx(idx, OPT_GLOBAL, current_sctx);
8430}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008431#endif
8432
Bram Moolenaar071d4272004-06-13 20:20:40 +00008433/*
8434 * Set the value of a boolean option, and take care of side effects.
8435 * Returns NULL for success, or an error message for an error.
8436 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008437 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008438set_bool_option(
8439 int opt_idx, /* index in options[] table */
8440 char_u *varp, /* pointer to the option variable */
8441 int value, /* new value */
8442 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008443{
8444 int old_value = *(int *)varp;
8445
Bram Moolenaar071d4272004-06-13 20:20:40 +00008446 /* Disallow changing some options from secure mode */
8447 if ((secure
8448#ifdef HAVE_SANDBOX
8449 || sandbox != 0
8450#endif
8451 ) && (options[opt_idx].flags & P_SECURE))
8452 return e_secure;
8453
8454 *(int *)varp = value; /* set the new value */
8455#ifdef FEAT_EVAL
8456 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008457 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008458#endif
8459
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008460#ifdef FEAT_GUI
8461 need_mouse_correct = TRUE;
8462#endif
8463
Bram Moolenaar071d4272004-06-13 20:20:40 +00008464 /* May set global value for local option. */
8465 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8466 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8467
8468 /*
8469 * Handle side effects of changing a bool option.
8470 */
8471
8472 /* 'compatible' */
8473 if ((int *)varp == &p_cp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008474 compatible_set();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008475
Bram Moolenaar920694c2016-08-21 17:45:02 +02008476#ifdef FEAT_LANGMAP
8477 if ((int *)varp == &p_lrm)
8478 /* 'langremap' -> !'langnoremap' */
8479 p_lnr = !p_lrm;
8480 else if ((int *)varp == &p_lnr)
8481 /* 'langnoremap' -> !'langremap' */
8482 p_lrm = !p_lnr;
8483#endif
8484
Bram Moolenaar8c63e0e2018-09-25 22:17:54 +02008485#ifdef FEAT_SYN_HL
8486 else if ((int *)varp == &curwin->w_p_cul && !value && old_value)
8487 reset_cursorline();
8488#endif
8489
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008490#ifdef FEAT_PERSISTENT_UNDO
8491 /* 'undofile' */
8492 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8493 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008494 /* Only take action when the option was set. When reset we do not
8495 * delete the undo file, the option may be set again without making
8496 * any changes in between. */
8497 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008498 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008499 char_u hash[UNDO_HASH_SIZE];
8500 buf_T *save_curbuf = curbuf;
8501
Bram Moolenaar29323592016-07-24 22:04:11 +02008502 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008503 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008504 /* When 'undofile' is set globally: for every buffer, otherwise
8505 * only for the current buffer: Try to read in the undofile,
8506 * if one exists, the buffer wasn't changed and the buffer was
8507 * loaded */
8508 if ((curbuf == save_curbuf
8509 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8510 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8511 {
8512 u_compute_hash(hash);
8513 u_read_undo(NULL, hash, curbuf->b_fname);
8514 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008515 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008516 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008517 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008518 }
8519#endif
8520
Bram Moolenaar071d4272004-06-13 20:20:40 +00008521 else if ((int *)varp == &curbuf->b_p_ro)
8522 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008523 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008524 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8525 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008526
8527 /* when 'readonly' is set may give W10 again */
8528 if (curbuf->b_p_ro)
8529 curbuf->b_did_warn = FALSE;
8530
Bram Moolenaar071d4272004-06-13 20:20:40 +00008531#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008532 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008533#endif
8534 }
8535
Bram Moolenaar9c449722010-07-20 18:44:27 +02008536#ifdef FEAT_GUI
8537 else if ((int *)varp == &p_mh)
8538 {
8539 if (!p_mh)
8540 gui_mch_mousehide(FALSE);
8541 }
8542#endif
8543
Bram Moolenaara539df02010-08-01 14:35:05 +02008544 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008545 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008546 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008547# ifdef FEAT_TERMINAL
8548 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaard7db27b2018-03-07 23:02:33 +01008549 if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf)
8550 && curbuf->b_term != NULL && !term_is_finished(curbuf))))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008551 {
8552 curbuf->b_p_ma = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008553 return N_("E946: Cannot make a terminal with running job modifiable");
Bram Moolenaar423802d2017-07-30 16:52:24 +02008554 }
8555# endif
8556# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008557 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008558# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008559 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008560#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008561 /* when 'endofline' is changed, redraw the window title */
8562 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008563 {
8564 redraw_titles();
8565 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008566 /* when 'fixeol' is changed, redraw the window title */
8567 else if ((int *)varp == &curbuf->b_p_fixeol)
8568 {
8569 redraw_titles();
8570 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008571 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008572 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008573 {
8574 redraw_titles();
8575 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008576#endif
8577
8578 /* when 'bin' is set also set some other options */
8579 else if ((int *)varp == &curbuf->b_p_bin)
8580 {
8581 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8582#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008583 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008584#endif
8585 }
8586
Bram Moolenaar071d4272004-06-13 20:20:40 +00008587 /* when 'buflisted' changes, trigger autocommands */
8588 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8589 {
8590 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8591 NULL, NULL, TRUE, curbuf);
8592 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008593
8594 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8595 else if ((int *)varp == &curbuf->b_p_swf)
8596 {
8597 if (curbuf->b_p_swf && p_uc)
8598 ml_open_file(curbuf); /* create the swap file */
8599 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008600 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8601 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008602 mf_close_file(curbuf, TRUE); /* remove the swap file */
8603 }
8604
8605 /* when 'terse' is set change 'shortmess' */
8606 else if ((int *)varp == &p_terse)
8607 {
8608 char_u *p;
8609
8610 p = vim_strchr(p_shm, SHM_SEARCH);
8611
8612 /* insert 's' in p_shm */
8613 if (p_terse && p == NULL)
8614 {
8615 STRCPY(IObuff, p_shm);
8616 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008617 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008618 }
8619 /* remove 's' from p_shm */
8620 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008621 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008622 }
8623
8624 /* when 'paste' is set or reset also change other options */
8625 else if ((int *)varp == &p_paste)
8626 {
8627 paste_option_changed();
8628 }
8629
8630 /* when 'insertmode' is set from an autocommand need to do work here */
8631 else if ((int *)varp == &p_im)
8632 {
8633 if (p_im)
8634 {
8635 if ((State & INSERT) == 0)
8636 need_start_insertmode = TRUE;
8637 stop_insert_mode = FALSE;
8638 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008639 /* only reset if it was set previously */
8640 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008641 {
8642 need_start_insertmode = FALSE;
8643 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008644 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008645 clear_cmdline = TRUE; /* remove "(insert)" */
8646 restart_edit = 0;
8647 }
8648 }
8649
8650 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8651 else if ((int *)varp == &p_ic && p_hls)
8652 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008653 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008654 }
8655
8656#ifdef FEAT_SEARCH_EXTRA
8657 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8658 else if ((int *)varp == &p_hls)
8659 {
Bram Moolenaar451fc7b2018-04-27 22:53:07 +02008660 set_no_hlsearch(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008661 }
8662#endif
8663
Bram Moolenaar071d4272004-06-13 20:20:40 +00008664 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8665 * at the end of normal_cmd() */
8666 else if ((int *)varp == &curwin->w_p_scb)
8667 {
8668 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008669 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008670 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008671 curwin->w_scbind_pos = curwin->w_topline;
8672 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008673 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008674
Bram Moolenaar4033c552017-09-16 20:54:51 +02008675#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008676 /* There can be only one window with 'previewwindow' set. */
8677 else if ((int *)varp == &curwin->w_p_pvw)
8678 {
8679 if (curwin->w_p_pvw)
8680 {
8681 win_T *win;
8682
Bram Moolenaar29323592016-07-24 22:04:11 +02008683 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008684 if (win->w_p_pvw && win != curwin)
8685 {
8686 curwin->w_p_pvw = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008687 return N_("E590: A preview window already exists");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008688 }
8689 }
8690 }
8691#endif
8692
8693 /* when 'textmode' is set or reset also change 'fileformat' */
8694 else if ((int *)varp == &curbuf->b_p_tx)
8695 {
8696 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8697 }
8698
8699 /* when 'textauto' is set or reset also change 'fileformats' */
8700 else if ((int *)varp == &p_ta)
Bram Moolenaarabab0b02019-03-30 18:47:01 +01008701 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008702 set_string_option_direct((char_u *)"ffs", -1,
8703 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008704 OPT_FREE | opt_flags, 0);
Bram Moolenaarabab0b02019-03-30 18:47:01 +01008705 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008706
8707 /*
8708 * When 'lisp' option changes include/exclude '-' in
8709 * keyword characters.
8710 */
8711#ifdef FEAT_LISP
8712 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8713 {
8714 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8715 }
8716#endif
8717
8718#ifdef FEAT_TITLE
8719 /* when 'title' changed, may need to change the title; same for 'icon' */
Bram Moolenaar84a93082018-06-16 22:58:15 +02008720 else if ((int *)varp == &p_title || (int *)varp == &p_icon)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008721 {
Bram Moolenaar84a93082018-06-16 22:58:15 +02008722 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008723 }
8724#endif
8725
8726 else if ((int *)varp == &curbuf->b_changed)
8727 {
8728 if (!value)
8729 save_file_ff(curbuf); /* Buffer is unchanged */
8730#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008731 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008732#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008733 modified_was_set = value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008734 }
8735
8736#ifdef BACKSLASH_IN_FILENAME
8737 else if ((int *)varp == &p_ssl)
8738 {
8739 if (p_ssl)
8740 {
8741 psepc = '/';
8742 psepcN = '\\';
8743 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008744 }
8745 else
8746 {
8747 psepc = '\\';
8748 psepcN = '/';
8749 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008750 }
8751
8752 /* need to adjust the file name arguments and buffer names. */
8753 buflist_slash_adjust();
8754 alist_slash_adjust();
8755# ifdef FEAT_EVAL
8756 scriptnames_slash_adjust();
8757# endif
8758 }
8759#endif
8760
8761 /* If 'wrap' is set, set w_leftcol to zero. */
8762 else if ((int *)varp == &curwin->w_p_wrap)
8763 {
8764 if (curwin->w_p_wrap)
8765 curwin->w_leftcol = 0;
8766 }
8767
Bram Moolenaar071d4272004-06-13 20:20:40 +00008768 else if ((int *)varp == &p_ea)
8769 {
8770 if (p_ea && !old_value)
8771 win_equal(curwin, FALSE, 0);
8772 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008773
8774 else if ((int *)varp == &p_wiv)
8775 {
8776 /*
8777 * When 'weirdinvert' changed, set/reset 't_xs'.
8778 * Then set 'weirdinvert' according to value of 't_xs'.
8779 */
8780 if (p_wiv && !old_value)
8781 T_XS = (char_u *)"y";
8782 else if (!p_wiv && old_value)
8783 T_XS = empty_option;
8784 p_wiv = (*T_XS != NUL);
8785 }
8786
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008787#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008788 else if ((int *)varp == &p_beval)
8789 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008790 if (!balloonEvalForTerm)
8791 {
8792 if (p_beval && !old_value)
8793 gui_mch_enable_beval_area(balloonEval);
8794 else if (!p_beval && old_value)
8795 gui_mch_disable_beval_area(balloonEval);
8796 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008797 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008798#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008799#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008800 else if ((int *)varp == &p_bevalterm)
8801 {
8802 mch_bevalterm_changed();
8803 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008804#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008805
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008806#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008807 else if ((int *)varp == &p_acd)
8808 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008809 /* Change directories when the 'acd' option is set now. */
Bram Moolenaar6f470022018-04-10 18:47:20 +02008810 DO_AUTOCHDIR;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008811 }
8812#endif
8813
8814#ifdef FEAT_DIFF
8815 /* 'diff' */
8816 else if ((int *)varp == &curwin->w_p_diff)
8817 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008818 /* May add or remove the buffer from the list of diff buffers. */
8819 diff_buf_adjust(curwin);
8820# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008821 if (foldmethodIsDiff(curwin))
8822 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008823# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008824 }
8825#endif
8826
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008827#ifdef HAVE_INPUT_METHOD
Bram Moolenaar071d4272004-06-13 20:20:40 +00008828 /* 'imdisable' */
8829 else if ((int *)varp == &p_imdisable)
8830 {
8831 /* Only de-activate it here, it will be enabled when changing mode. */
8832 if (p_imdisable)
8833 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008834 else if (State & INSERT)
8835 /* When the option is set from an autocommand, it may need to take
8836 * effect right away. */
8837 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008838 }
8839#endif
8840
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008841#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008842 /* 'spell' */
8843 else if ((int *)varp == &curwin->w_p_spell)
8844 {
8845 if (curwin->w_p_spell)
8846 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008847 char *errmsg = did_set_spelllang(curwin);
8848
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008849 if (errmsg != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008850 emsg(_(errmsg));
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008851 }
8852 }
8853#endif
8854
Bram Moolenaar071d4272004-06-13 20:20:40 +00008855#ifdef FEAT_ARABIC
8856 if ((int *)varp == &curwin->w_p_arab)
8857 {
8858 if (curwin->w_p_arab)
8859 {
8860 /*
8861 * 'arabic' is set, handle various sub-settings.
8862 */
8863 if (!p_tbidi)
8864 {
8865 /* set rightleft mode */
8866 if (!curwin->w_p_rl)
8867 {
8868 curwin->w_p_rl = TRUE;
8869 changed_window_setting();
8870 }
8871
8872 /* Enable Arabic shaping (major part of what Arabic requires) */
8873 if (!p_arshape)
8874 {
8875 p_arshape = TRUE;
8876 redraw_later_clear();
8877 }
8878 }
8879
8880 /* Arabic requires a utf-8 encoding, inform the user if its not
8881 * set. */
8882 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008883 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008884 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8885
Bram Moolenaar8820b482017-03-16 17:23:31 +01008886 msg_source(HL_ATTR(HLF_W));
Bram Moolenaar32526b32019-01-19 17:43:09 +01008887 msg_attr(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008888#ifdef FEAT_EVAL
8889 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8890#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008891 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008892
Bram Moolenaar071d4272004-06-13 20:20:40 +00008893 /* set 'delcombine' */
8894 p_deco = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008895
8896# ifdef FEAT_KEYMAP
8897 /* Force-set the necessary keymap for arabic */
8898 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8899 OPT_LOCAL);
8900# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008901 }
8902 else
8903 {
8904 /*
8905 * 'arabic' is reset, handle various sub-settings.
8906 */
8907 if (!p_tbidi)
8908 {
8909 /* reset rightleft mode */
8910 if (curwin->w_p_rl)
8911 {
8912 curwin->w_p_rl = FALSE;
8913 changed_window_setting();
8914 }
8915
8916 /* 'arabicshape' isn't reset, it is a global option and
8917 * another window may still need it "on". */
8918 }
8919
8920 /* 'delcombine' isn't reset, it is a global option and another
8921 * window may still want it "on". */
8922
8923# ifdef FEAT_KEYMAP
8924 /* Revert to the default keymap */
8925 curbuf->b_p_iminsert = B_IMODE_NONE;
8926 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8927# endif
8928 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008929 }
8930
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008931#endif
8932
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008933#ifdef FEAT_TERMGUICOLORS
8934 /* 'termguicolors' */
8935 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008936 {
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008937# ifdef FEAT_VTP
8938 /* Do not turn on 'tgc' when 24-bit colors are not supported. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02008939 if (
8940# ifdef VIMDLL
8941 !gui.in_use && !gui.starting &&
8942# endif
8943 !has_vtp_working())
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008944 {
8945 p_tgc = 0;
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01008946 return N_("E954: 24-bit colors are not supported on this environment");
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008947 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008948 if (is_term_win32())
8949 swap_tcap();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008950# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008951# ifdef FEAT_GUI
8952 if (!gui.in_use && !gui.starting)
8953# endif
8954 highlight_gui_started();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008955# ifdef FEAT_VTP
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008956 /* reset t_Co */
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008957 if (is_term_win32())
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02008958 {
8959 control_console_color_rgb();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008960 set_termname(T_NAME);
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02008961 init_highlight(TRUE, FALSE);
8962 }
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008963# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008964 }
8965#endif
8966
Bram Moolenaar071d4272004-06-13 20:20:40 +00008967 /*
8968 * End of handling side effects for bool options.
8969 */
8970
Bram Moolenaar53744302015-07-17 17:38:22 +02008971 /* after handling side effects, call autocommand */
8972
Bram Moolenaar071d4272004-06-13 20:20:40 +00008973 options[opt_idx].flags |= P_WAS_SET;
8974
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008975#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02008976 // Don't do this while starting up or recursively.
8977 if (!starting && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02008978 {
8979 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02008980
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008981 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8982 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8983 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008984 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8985 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8986 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8987 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8988 reset_v_option_vars();
8989 }
8990#endif
8991
Bram Moolenaar071d4272004-06-13 20:20:40 +00008992 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008993 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008994 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008995 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008996 check_redraw(options[opt_idx].flags);
8997
8998 return NULL;
8999}
9000
9001/*
9002 * Set the value of a number option, and take care of side effects.
9003 * Returns NULL for success, or an error message for an error.
9004 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009005 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009006set_num_option(
9007 int opt_idx, /* index in options[] table */
9008 char_u *varp, /* pointer to the option variable */
9009 long value, /* new value */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009010 char *errbuf, /* buffer for error messages */
Bram Moolenaar9b578142016-01-30 19:39:49 +01009011 size_t errbuflen, /* length of "errbuf" */
9012 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00009013 OPT_MODELINE */
9014{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009015 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009016 long old_value = *(long *)varp;
9017 long old_Rows = Rows; /* remember old Rows */
9018 long old_Columns = Columns; /* remember old Columns */
9019 long *pp = (long *)varp;
9020
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009021 /* Disallow changing some options from secure mode. */
9022 if ((secure
9023#ifdef HAVE_SANDBOX
9024 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00009025#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009026 ) && (options[opt_idx].flags & P_SECURE))
9027 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009028
9029 *pp = value;
9030#ifdef FEAT_EVAL
9031 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02009032 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009033#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009034#ifdef FEAT_GUI
9035 need_mouse_correct = TRUE;
9036#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009037
Bram Moolenaar14f24742012-08-08 18:01:05 +02009038 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009039 {
9040 errmsg = e_positive;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02009041#ifdef FEAT_VARTABS
9042 // Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use.
9043 curbuf->b_p_sw = tabstop_count(curbuf->b_p_vts_array) > 0
9044 ? tabstop_first(curbuf->b_p_vts_array)
9045 : curbuf->b_p_ts;
9046#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00009047 curbuf->b_p_sw = curbuf->b_p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02009048#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009049 }
9050
9051 /*
9052 * Number options that need some action when changed
9053 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009054 if (pp == &p_wh || pp == &p_hh)
9055 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009056 // 'winheight' and 'helpheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009057 if (p_wh < 1)
9058 {
9059 errmsg = e_positive;
9060 p_wh = 1;
9061 }
9062 if (p_wmh > p_wh)
9063 {
9064 errmsg = e_winheight;
9065 p_wh = p_wmh;
9066 }
9067 if (p_hh < 0)
9068 {
9069 errmsg = e_positive;
9070 p_hh = 0;
9071 }
9072
9073 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01009074 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009075 {
9076 if (pp == &p_wh && curwin->w_height < p_wh)
9077 win_setheight((int)p_wh);
9078 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
9079 win_setheight((int)p_hh);
9080 }
9081 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009082 else if (pp == &p_wmh)
9083 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009084 // 'winminheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009085 if (p_wmh < 0)
9086 {
9087 errmsg = e_positive;
9088 p_wmh = 0;
9089 }
9090 if (p_wmh > p_wh)
9091 {
9092 errmsg = e_winheight;
9093 p_wmh = p_wh;
9094 }
9095 win_setminheight();
9096 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009097 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009098 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009099 // 'winwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009100 if (p_wiw < 1)
9101 {
9102 errmsg = e_positive;
9103 p_wiw = 1;
9104 }
9105 if (p_wmw > p_wiw)
9106 {
9107 errmsg = e_winwidth;
9108 p_wiw = p_wmw;
9109 }
9110
9111 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01009112 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009113 win_setwidth((int)p_wiw);
9114 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009115 else if (pp == &p_wmw)
9116 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009117 // 'winminwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009118 if (p_wmw < 0)
9119 {
9120 errmsg = e_positive;
9121 p_wmw = 0;
9122 }
9123 if (p_wmw > p_wiw)
9124 {
9125 errmsg = e_winwidth;
9126 p_wmw = p_wiw;
9127 }
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009128 win_setminwidth();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009129 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009130
Bram Moolenaar071d4272004-06-13 20:20:40 +00009131 /* (re)set last window status line */
9132 else if (pp == &p_ls)
9133 {
9134 last_status(FALSE);
9135 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009136
9137 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00009138 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009139 {
9140 shell_new_rows(); /* recompute window positions and heights */
9141 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009142
9143#ifdef FEAT_GUI
9144 else if (pp == &p_linespace)
9145 {
Bram Moolenaar02743632005-07-25 20:42:36 +00009146 /* Recompute gui.char_height and resize the Vim window to keep the
9147 * same number of lines. */
9148 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00009149 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009150 }
9151#endif
9152
9153#ifdef FEAT_FOLDING
9154 /* 'foldlevel' */
9155 else if (pp == &curwin->w_p_fdl)
9156 {
9157 if (curwin->w_p_fdl < 0)
9158 curwin->w_p_fdl = 0;
9159 newFoldLevel();
9160 }
9161
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00009162 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009163 else if (pp == &curwin->w_p_fml)
9164 {
9165 foldUpdateAll(curwin);
9166 }
9167
9168 /* 'foldnestmax' */
9169 else if (pp == &curwin->w_p_fdn)
9170 {
9171 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
9172 foldUpdateAll(curwin);
9173 }
9174
9175 /* 'foldcolumn' */
9176 else if (pp == &curwin->w_p_fdc)
9177 {
9178 if (curwin->w_p_fdc < 0)
9179 {
9180 errmsg = e_positive;
9181 curwin->w_p_fdc = 0;
9182 }
9183 else if (curwin->w_p_fdc > 12)
9184 {
9185 errmsg = e_invarg;
9186 curwin->w_p_fdc = 12;
9187 }
9188 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009189#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009190
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009191#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009192 /* 'shiftwidth' or 'tabstop' */
9193 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
9194 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009195# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00009196 if (foldmethodIsIndent(curwin))
9197 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009198# endif
9199# ifdef FEAT_CINDENT
9200 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
9201 * parse 'cinoptions'. */
9202 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
9203 parse_cino(curbuf);
9204# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009205 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009206#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009207
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009208 /* 'maxcombine' */
9209 else if (pp == &p_mco)
9210 {
9211 if (p_mco > MAX_MCO)
9212 p_mco = MAX_MCO;
9213 else if (p_mco < 0)
9214 p_mco = 0;
9215 screenclear(); /* will re-allocate the screen */
9216 }
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009217
Bram Moolenaar071d4272004-06-13 20:20:40 +00009218 else if (pp == &curbuf->b_p_iminsert)
9219 {
9220 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
9221 {
9222 errmsg = e_invarg;
9223 curbuf->b_p_iminsert = B_IMODE_NONE;
9224 }
9225 p_iminsert = curbuf->b_p_iminsert;
9226 if (termcap_active) /* don't do this in the alternate screen */
9227 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02009228#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009229 /* Show/unshow value of 'keymap' in status lines. */
9230 status_redraw_curbuf();
9231#endif
9232 }
9233
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02009234#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
9235 /* 'imstyle' */
9236 else if (pp == &p_imst)
9237 {
9238 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
9239 errmsg = e_invarg;
9240 }
9241#endif
9242
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009243 else if (pp == &p_window)
9244 {
9245 if (p_window < 1)
9246 p_window = 1;
9247 else if (p_window >= Rows)
9248 p_window = Rows - 1;
9249 }
9250
Bram Moolenaar071d4272004-06-13 20:20:40 +00009251 else if (pp == &curbuf->b_p_imsearch)
9252 {
9253 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
9254 {
9255 errmsg = e_invarg;
9256 curbuf->b_p_imsearch = B_IMODE_NONE;
9257 }
9258 p_imsearch = curbuf->b_p_imsearch;
9259 }
9260
9261#ifdef FEAT_TITLE
9262 /* if 'titlelen' has changed, redraw the title */
9263 else if (pp == &p_titlelen)
9264 {
9265 if (p_titlelen < 0)
9266 {
9267 errmsg = e_positive;
9268 p_titlelen = 85;
9269 }
9270 if (starting != NO_SCREEN && old_value != p_titlelen)
9271 need_maketitle = TRUE;
9272 }
9273#endif
9274
9275 /* if p_ch changed value, change the command line height */
9276 else if (pp == &p_ch)
9277 {
9278 if (p_ch < 1)
9279 {
9280 errmsg = e_positive;
9281 p_ch = 1;
9282 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009283 if (p_ch > Rows - min_rows() + 1)
9284 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009285
9286 /* Only compute the new window layout when startup has been
9287 * completed. Otherwise the frame sizes may be wrong. */
9288 if (p_ch != old_value && full_screen
9289#ifdef FEAT_GUI
9290 && !gui.starting
9291#endif
9292 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009293 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009294 }
9295
9296 /* when 'updatecount' changes from zero to non-zero, open swap files */
9297 else if (pp == &p_uc)
9298 {
9299 if (p_uc < 0)
9300 {
9301 errmsg = e_positive;
9302 p_uc = 100;
9303 }
9304 if (p_uc && !old_value)
9305 ml_open_files();
9306 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009307#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009308 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009309 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009310 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009311 {
9312 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009313 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009314 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009315 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009316 {
9317 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009318 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009319 }
9320 }
9321#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009322#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009323 else if (pp == &p_mzq)
9324 mzvim_reset_timer();
9325#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009326
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009327#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9328 /* 'pyxversion' */
9329 else if (pp == &p_pyx)
9330 {
9331 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9332 errmsg = e_invarg;
9333 }
9334#endif
9335
Bram Moolenaar071d4272004-06-13 20:20:40 +00009336 /* sync undo before 'undolevels' changes */
9337 else if (pp == &p_ul)
9338 {
9339 /* use the old value, otherwise u_sync() may not work properly */
9340 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009341 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009342 p_ul = value;
9343 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009344 else if (pp == &curbuf->b_p_ul)
9345 {
9346 /* use the old value, otherwise u_sync() may not work properly */
9347 curbuf->b_p_ul = old_value;
9348 u_sync(TRUE);
9349 curbuf->b_p_ul = value;
9350 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009351
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009352#ifdef FEAT_LINEBREAK
9353 /* 'numberwidth' must be positive */
9354 else if (pp == &curwin->w_p_nuw)
9355 {
9356 if (curwin->w_p_nuw < 1)
9357 {
9358 errmsg = e_positive;
9359 curwin->w_p_nuw = 1;
9360 }
9361 if (curwin->w_p_nuw > 10)
9362 {
9363 errmsg = e_invarg;
9364 curwin->w_p_nuw = 10;
9365 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009366 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009367 }
9368#endif
9369
Bram Moolenaar1a384422010-07-14 19:53:30 +02009370 else if (pp == &curbuf->b_p_tw)
9371 {
9372 if (curbuf->b_p_tw < 0)
9373 {
9374 errmsg = e_positive;
9375 curbuf->b_p_tw = 0;
9376 }
9377#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009378 {
9379 win_T *wp;
9380 tabpage_T *tp;
9381
9382 FOR_ALL_TAB_WINDOWS(tp, wp)
9383 check_colorcolumn(wp);
9384 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009385#endif
9386 }
9387
Bram Moolenaar071d4272004-06-13 20:20:40 +00009388 /*
9389 * Check the bounds for numeric options here
9390 */
9391 if (Rows < min_rows() && full_screen)
9392 {
9393 if (errbuf != NULL)
9394 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009395 vim_snprintf((char *)errbuf, errbuflen,
9396 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009397 errmsg = errbuf;
9398 }
9399 Rows = min_rows();
9400 }
9401 if (Columns < MIN_COLUMNS && full_screen)
9402 {
9403 if (errbuf != NULL)
9404 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009405 vim_snprintf((char *)errbuf, errbuflen,
9406 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009407 errmsg = errbuf;
9408 }
9409 Columns = MIN_COLUMNS;
9410 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009411 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009412
Bram Moolenaar071d4272004-06-13 20:20:40 +00009413 /*
9414 * If the screen (shell) height has been changed, assume it is the
9415 * physical screenheight.
9416 */
9417 if (old_Rows != Rows || old_Columns != Columns)
9418 {
9419 /* Changing the screen size is not allowed while updating the screen. */
9420 if (updating_screen)
9421 *pp = old_value;
9422 else if (full_screen
9423#ifdef FEAT_GUI
9424 && !gui.starting
9425#endif
9426 )
9427 set_shellsize((int)Columns, (int)Rows, TRUE);
9428 else
9429 {
9430 /* Postpone the resizing; check the size and cmdline position for
9431 * messages. */
9432 check_shellsize();
9433 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9434 cmdline_row = Rows - p_ch;
9435 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009436 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009437 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009438 }
9439
Bram Moolenaar071d4272004-06-13 20:20:40 +00009440 if (curbuf->b_p_ts <= 0)
9441 {
9442 errmsg = e_positive;
9443 curbuf->b_p_ts = 8;
9444 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009445 if (p_tm < 0)
9446 {
9447 errmsg = e_positive;
9448 p_tm = 0;
9449 }
9450 if ((curwin->w_p_scr <= 0
9451 || (curwin->w_p_scr > curwin->w_height
9452 && curwin->w_height > 0))
9453 && full_screen)
9454 {
9455 if (pp == &(curwin->w_p_scr))
9456 {
9457 if (curwin->w_p_scr != 0)
9458 errmsg = e_scroll;
9459 win_comp_scroll(curwin);
9460 }
9461 /* If 'scroll' became invalid because of a side effect silently adjust
9462 * it. */
9463 else if (curwin->w_p_scr <= 0)
9464 curwin->w_p_scr = 1;
9465 else /* curwin->w_p_scr > curwin->w_height */
9466 curwin->w_p_scr = curwin->w_height;
9467 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009468 if (p_hi < 0)
9469 {
9470 errmsg = e_positive;
9471 p_hi = 0;
9472 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009473 else if (p_hi > 10000)
9474 {
9475 errmsg = e_invarg;
9476 p_hi = 10000;
9477 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009478 if (p_re < 0 || p_re > 2)
9479 {
9480 errmsg = e_invarg;
9481 p_re = 0;
9482 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009483 if (p_report < 0)
9484 {
9485 errmsg = e_positive;
9486 p_report = 1;
9487 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009488 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009489 {
9490 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9491 p_sj = Rows / 2;
9492 else
9493 {
9494 errmsg = e_scroll;
9495 p_sj = 1;
9496 }
9497 }
9498 if (p_so < 0 && full_screen)
9499 {
Bram Moolenaar375e3392019-01-31 18:26:10 +01009500 errmsg = e_positive;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009501 p_so = 0;
9502 }
9503 if (p_siso < 0 && full_screen)
9504 {
9505 errmsg = e_positive;
9506 p_siso = 0;
9507 }
9508#ifdef FEAT_CMDWIN
9509 if (p_cwh < 1)
9510 {
9511 errmsg = e_positive;
9512 p_cwh = 1;
9513 }
9514#endif
9515 if (p_ut < 0)
9516 {
9517 errmsg = e_positive;
9518 p_ut = 2000;
9519 }
9520 if (p_ss < 0)
9521 {
9522 errmsg = e_positive;
9523 p_ss = 0;
9524 }
9525
9526 /* May set global value for local option. */
9527 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9528 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9529
9530 options[opt_idx].flags |= P_WAS_SET;
9531
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009532#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009533 // Don't do this while starting up, failure or recursively.
9534 if (!starting && errmsg == NULL && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009535 {
9536 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaar2c519cf2019-03-21 21:45:34 +01009537
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009538 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9539 vim_snprintf((char *)buf_new, 10, "%ld", value);
9540 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009541 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9542 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9543 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9544 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9545 reset_v_option_vars();
9546 }
9547#endif
9548
Bram Moolenaar071d4272004-06-13 20:20:40 +00009549 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009550 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009551 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009552 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009553 check_redraw(options[opt_idx].flags);
9554
9555 return errmsg;
9556}
9557
9558/*
9559 * Called after an option changed: check if something needs to be redrawn.
9560 */
9561 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009562check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009563{
9564 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009565 int doclear = (flags & P_RCLR) == P_RCLR;
9566 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009567
Bram Moolenaar071d4272004-06-13 20:20:40 +00009568 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9569 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009570
9571 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9572 changed_window_setting();
9573 if (flags & P_RBUF)
9574 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009575 if (flags & P_RWINONLY)
9576 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009577 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009578 redraw_all_later(CLEAR);
9579 else if (all)
9580 redraw_all_later(NOT_VALID);
9581}
9582
9583/*
9584 * Find index for option 'arg'.
9585 * Return -1 if not found.
9586 */
9587 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009588findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009589{
9590 int opt_idx;
9591 char *s, *p;
9592 static short quick_tab[27] = {0, 0}; /* quick access table */
9593 int is_term_opt;
9594
9595 /*
9596 * For first call: Initialize the quick-access table.
9597 * It contains the index for the first option that starts with a certain
9598 * letter. There are 26 letters, plus the first "t_" option.
9599 */
9600 if (quick_tab[1] == 0)
9601 {
9602 p = options[0].fullname;
9603 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9604 {
9605 if (s[0] != p[0])
9606 {
9607 if (s[0] == 't' && s[1] == '_')
9608 quick_tab[26] = opt_idx;
9609 else
9610 quick_tab[CharOrdLow(s[0])] = opt_idx;
9611 }
9612 p = s;
9613 }
9614 }
9615
9616 /*
9617 * Check for name starting with an illegal character.
9618 */
9619#ifdef EBCDIC
9620 if (!islower(arg[0]))
9621#else
9622 if (arg[0] < 'a' || arg[0] > 'z')
9623#endif
9624 return -1;
9625
9626 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9627 if (is_term_opt)
9628 opt_idx = quick_tab[26];
9629 else
9630 opt_idx = quick_tab[CharOrdLow(arg[0])];
9631 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9632 {
9633 if (STRCMP(arg, s) == 0) /* match full name */
9634 break;
9635 }
9636 if (s == NULL && !is_term_opt)
9637 {
9638 opt_idx = quick_tab[CharOrdLow(arg[0])];
9639 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9640 {
9641 s = options[opt_idx].shortname;
9642 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9643 break;
9644 s = NULL;
9645 }
9646 }
9647 if (s == NULL)
9648 opt_idx = -1;
9649 return opt_idx;
9650}
9651
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009652#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009653/*
9654 * Get the value for an option.
9655 *
9656 * Returns:
9657 * Number or Toggle option: 1, *numval gets value.
9658 * String option: 0, *stringval gets allocated string.
9659 * Hidden Number or Toggle option: -1.
9660 * hidden String option: -2.
9661 * unknown option: -3.
9662 */
9663 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009664get_option_value(
9665 char_u *name,
9666 long *numval,
9667 char_u **stringval, /* NULL when only checking existence */
9668 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009669{
9670 int opt_idx;
9671 char_u *varp;
9672
9673 opt_idx = findoption(name);
9674 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009675 {
9676 int key;
9677
9678 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009679 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009680 {
9681 char_u key_name[2];
9682 char_u *p;
9683
9684 if (key < 0)
9685 {
9686 key_name[0] = KEY2TERMCAP0(key);
9687 key_name[1] = KEY2TERMCAP1(key);
9688 }
9689 else
9690 {
9691 key_name[0] = KS_KEY;
9692 key_name[1] = (key & 0xff);
9693 }
9694 p = find_termcode(key_name);
9695 if (p != NULL)
9696 {
9697 if (stringval != NULL)
9698 *stringval = vim_strsave(p);
9699 return 0;
9700 }
9701 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009702 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009703 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009704
9705 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9706
9707 if (options[opt_idx].flags & P_STRING)
9708 {
9709 if (varp == NULL) /* hidden option */
9710 return -2;
9711 if (stringval != NULL)
9712 {
9713#ifdef FEAT_CRYPT
9714 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009715 if ((char_u **)varp == &curbuf->b_p_key
9716 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009717 *stringval = vim_strsave((char_u *)"*****");
9718 else
9719#endif
9720 *stringval = vim_strsave(*(char_u **)(varp));
9721 }
9722 return 0;
9723 }
9724
9725 if (varp == NULL) /* hidden option */
9726 return -1;
9727 if (options[opt_idx].flags & P_NUM)
9728 *numval = *(long *)varp;
9729 else
9730 {
9731 /* Special case: 'modified' is b_changed, but we also want to consider
9732 * it set when 'ff' or 'fenc' changed. */
9733 if ((int *)varp == &curbuf->b_changed)
9734 *numval = curbufIsChanged();
9735 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009736 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009737 }
9738 return 1;
9739}
9740#endif
9741
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009742#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009743/*
9744 * Returns the option attributes and its value. Unlike the above function it
9745 * will return either global value or local value of the option depending on
9746 * what was requested, but it will never return global value if it was
9747 * requested to return local one and vice versa. Neither it will return
9748 * buffer-local value if it was requested to return window-local one.
9749 *
9750 * Pretends that option is absent if it is not present in the requested scope
9751 * (i.e. has no global, window-local or buffer-local value depending on
9752 * opt_type). Uses
9753 *
9754 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009755 * 0 hidden or unknown option, also option that does not have requested
9756 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009757 * see SOPT_* in vim.h for other flags
9758 *
9759 * Possible opt_type values: see SREQ_* in vim.h
9760 */
9761 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009762get_option_value_strict(
9763 char_u *name,
9764 long *numval,
9765 char_u **stringval, /* NULL when only obtaining attributes */
9766 int opt_type,
9767 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009768{
9769 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009770 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009771 struct vimoption *p;
9772 int r = 0;
9773
9774 opt_idx = findoption(name);
9775 if (opt_idx < 0)
9776 return 0;
9777
9778 p = &(options[opt_idx]);
9779
9780 /* Hidden option */
9781 if (p->var == NULL)
9782 return 0;
9783
9784 if (p->flags & P_BOOL)
9785 r |= SOPT_BOOL;
9786 else if (p->flags & P_NUM)
9787 r |= SOPT_NUM;
9788 else if (p->flags & P_STRING)
9789 r |= SOPT_STRING;
9790
9791 if (p->indir == PV_NONE)
9792 {
9793 if (opt_type == SREQ_GLOBAL)
9794 r |= SOPT_GLOBAL;
9795 else
9796 return 0; /* Did not request global-only option */
9797 }
9798 else
9799 {
9800 if (p->indir & PV_BOTH)
9801 r |= SOPT_GLOBAL;
9802 else if (opt_type == SREQ_GLOBAL)
9803 return 0; /* Requested global option */
9804
9805 if (p->indir & PV_WIN)
9806 {
9807 if (opt_type == SREQ_BUF)
9808 return 0; /* Did not request window-local option */
9809 else
9810 r |= SOPT_WIN;
9811 }
9812 else if (p->indir & PV_BUF)
9813 {
9814 if (opt_type == SREQ_WIN)
9815 return 0; /* Did not request buffer-local option */
9816 else
9817 r |= SOPT_BUF;
9818 }
9819 }
9820
9821 if (stringval == NULL)
9822 return r;
9823
9824 if (opt_type == SREQ_GLOBAL)
9825 varp = p->var;
9826 else
9827 {
9828 if (opt_type == SREQ_BUF)
9829 {
9830 /* Special case: 'modified' is b_changed, but we also want to
9831 * consider it set when 'ff' or 'fenc' changed. */
9832 if (p->indir == PV_MOD)
9833 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009834 *numval = bufIsChanged((buf_T *)from);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009835 varp = NULL;
9836 }
9837#ifdef FEAT_CRYPT
9838 else if (p->indir == PV_KEY)
9839 {
9840 /* never return the value of the crypt key */
9841 *stringval = NULL;
9842 varp = NULL;
9843 }
9844#endif
9845 else
9846 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009847 buf_T *save_curbuf = curbuf;
9848
9849 // only getting a pointer, no need to use aucmd_prepbuf()
9850 curbuf = (buf_T *)from;
9851 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009852 varp = get_varp(p);
Bram Moolenaardefe6422018-06-24 15:14:07 +02009853 curbuf = save_curbuf;
9854 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009855 }
9856 }
9857 else if (opt_type == SREQ_WIN)
9858 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009859 win_T *save_curwin = curwin;
9860
9861 curwin = (win_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009862 curbuf = curwin->w_buffer;
9863 varp = get_varp(p);
9864 curwin = save_curwin;
9865 curbuf = curwin->w_buffer;
9866 }
9867 if (varp == p->var)
9868 return (r | SOPT_UNSET);
9869 }
9870
9871 if (varp != NULL)
9872 {
9873 if (p->flags & P_STRING)
9874 *stringval = vim_strsave(*(char_u **)(varp));
9875 else if (p->flags & P_NUM)
9876 *numval = *(long *) varp;
9877 else
9878 *numval = *(int *)varp;
9879 }
9880
9881 return r;
9882}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009883
9884/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009885 * Iterate over options. First argument is a pointer to a pointer to a
9886 * structure inside options[] array, second is option type like in the above
9887 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009888 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009889 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009890 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009891 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009892 * first argument to NULL.
9893 *
9894 * Returns full option name for current option on each call.
9895 */
9896 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009897option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009898{
9899 struct vimoption *ret = NULL;
9900 do
9901 {
9902 if (*option == NULL)
9903 *option = (void *) options;
9904 else if (((struct vimoption *) (*option))->fullname == NULL)
9905 {
9906 *option = NULL;
9907 return NULL;
9908 }
9909 else
9910 *option = (void *) (((struct vimoption *) (*option)) + 1);
9911
9912 ret = ((struct vimoption *) (*option));
9913
9914 /* Hidden option */
9915 if (ret->var == NULL)
9916 {
9917 ret = NULL;
9918 continue;
9919 }
9920
9921 switch (opt_type)
9922 {
9923 case SREQ_GLOBAL:
9924 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9925 ret = NULL;
9926 break;
9927 case SREQ_BUF:
9928 if (!(ret->indir & PV_BUF))
9929 ret = NULL;
9930 break;
9931 case SREQ_WIN:
9932 if (!(ret->indir & PV_WIN))
9933 ret = NULL;
9934 break;
9935 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009936 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009937 return NULL;
9938 }
9939 }
9940 while (ret == NULL);
9941
9942 return (char_u *)ret->fullname;
9943}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009944#endif
9945
Bram Moolenaar071d4272004-06-13 20:20:40 +00009946/*
9947 * Set the value of option "name".
9948 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009949 *
9950 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009951 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009952 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009953set_option_value(
9954 char_u *name,
9955 long number,
9956 char_u *string,
9957 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009958{
9959 int opt_idx;
9960 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009961 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009962
9963 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009964 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009965 {
9966 int key;
9967
9968 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009969 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009970 {
9971 char_u key_name[2];
9972
9973 if (key < 0)
9974 {
9975 key_name[0] = KEY2TERMCAP0(key);
9976 key_name[1] = KEY2TERMCAP1(key);
9977 }
9978 else
9979 {
9980 key_name[0] = KS_KEY;
9981 key_name[1] = (key & 0xff);
9982 }
9983 add_termcode(key_name, string, FALSE);
9984 if (full_screen)
9985 ttest(FALSE);
9986 redraw_all_later(CLEAR);
9987 return NULL;
9988 }
9989
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009990 semsg(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009991 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009992 else
9993 {
9994 flags = options[opt_idx].flags;
9995#ifdef HAVE_SANDBOX
9996 /* Disallow changing some options in the sandbox */
9997 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009998 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009999 emsg(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010000 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010001 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010002#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010003 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010004 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010005 else
10006 {
Bram Moolenaarb3163762008-07-08 15:15:08 +000010007 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010008 if (varp != NULL) /* hidden option is not changed */
10009 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010010 if (number == 0 && string != NULL)
10011 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +000010012 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010013
10014 /* Either we are given a string or we are setting option
10015 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +000010016 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010017 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +000010018 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010019 {
10020 /* There's another character after zeros or the string
10021 * is empty. In both cases, we are trying to set a
10022 * num option using a string. */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010023 semsg(_("E521: Number required: &%s = '%s'"),
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010024 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010025 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010026
10027 }
10028 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010029 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010030 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +000010031 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010032 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010033 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010034 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010035 }
10036 }
10037 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010038 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010039}
10040
10041/*
10042 * Get the terminal code for a terminal option.
10043 * Returns NULL when not found.
10044 */
10045 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010046get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010047{
10048 int opt_idx;
10049 char_u *varp;
10050
10051 if (tname[0] != 't' || tname[1] != '_' ||
10052 tname[2] == NUL || tname[3] == NUL)
10053 return NULL;
10054 if ((opt_idx = findoption(tname)) >= 0)
10055 {
10056 varp = get_varp(&(options[opt_idx]));
10057 if (varp != NULL)
10058 varp = *(char_u **)(varp);
10059 return varp;
10060 }
10061 return find_termcode(tname + 2);
10062}
10063
10064 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010065get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010066{
10067 int i;
10068
10069 i = findoption((char_u *)"hl");
10070 if (i >= 0)
10071 return options[i].def_val[VI_DEFAULT];
10072 return (char_u *)NULL;
10073}
10074
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010075 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010076get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010077{
10078 int i;
10079
10080 i = findoption((char_u *)"enc");
10081 if (i >= 0)
10082 return options[i].def_val[VI_DEFAULT];
10083 return (char_u *)NULL;
10084}
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010085
Bram Moolenaar071d4272004-06-13 20:20:40 +000010086/*
10087 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010088 * When "has_lt" is true there is a '<' before "*arg_arg".
10089 * Returns 0 when the key is not recognized.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010090 */
10091 static int
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010092find_key_option(char_u *arg_arg, int has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010093{
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010094 int key = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010095 int modifiers;
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010096 char_u *arg = arg_arg;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010097
10098 /*
10099 * Don't use get_special_key_code() for t_xx, we don't want it to call
10100 * add_termcap_entry().
10101 */
10102 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
10103 key = TERMCAP2KEY(arg[2], arg[3]);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010104 else if (has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010105 {
10106 --arg; /* put arg at the '<' */
10107 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +020010108 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010109 if (modifiers) /* can't handle modifiers here */
10110 key = 0;
10111 }
10112 return key;
10113}
10114
10115/*
10116 * if 'all' == 0: show changed options
10117 * if 'all' == 1: show all normal options
10118 * if 'all' == 2: show all terminal options
10119 */
10120 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010121showoptions(
10122 int all,
10123 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010124{
10125 struct vimoption *p;
10126 int col;
10127 int isterm;
10128 char_u *varp;
10129 struct vimoption **items;
10130 int item_count;
10131 int run;
10132 int row, rows;
10133 int cols;
10134 int i;
10135 int len;
10136
10137#define INC 20
10138#define GAP 3
10139
Bram Moolenaarc799fe22019-05-28 23:08:19 +020010140 items = ALLOC_MULT(struct vimoption *, PARAM_COUNT);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010141 if (items == NULL)
10142 return;
10143
10144 /* Highlight title */
10145 if (all == 2)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010146 msg_puts_title(_("\n--- Terminal codes ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010147 else if (opt_flags & OPT_GLOBAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010148 msg_puts_title(_("\n--- Global option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010149 else if (opt_flags & OPT_LOCAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010150 msg_puts_title(_("\n--- Local option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010151 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010152 msg_puts_title(_("\n--- Options ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010153
10154 /*
10155 * do the loop two times:
10156 * 1. display the short items
10157 * 2. display the long items (only strings and numbers)
10158 */
10159 for (run = 1; run <= 2 && !got_int; ++run)
10160 {
10161 /*
10162 * collect the items in items[]
10163 */
10164 item_count = 0;
10165 for (p = &options[0]; p->fullname != NULL; p++)
10166 {
Bram Moolenaarf86db782018-10-25 13:31:37 +020010167 // apply :filter /pat/
10168 if (message_filtered((char_u *) p->fullname))
10169 continue;
10170
Bram Moolenaar071d4272004-06-13 20:20:40 +000010171 varp = NULL;
10172 isterm = istermoption(p);
10173 if (opt_flags != 0)
10174 {
10175 if (p->indir != PV_NONE && !isterm)
10176 varp = get_varp_scope(p, opt_flags);
10177 }
10178 else
10179 varp = get_varp(p);
10180 if (varp != NULL
10181 && ((all == 2 && isterm)
10182 || (all == 1 && !isterm)
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010183 || (all == 0 && !optval_default(p, varp, p_cp))))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010184 {
10185 if (p->flags & P_BOOL)
10186 len = 1; /* a toggle option fits always */
10187 else
10188 {
10189 option_value2string(p, opt_flags);
10190 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
10191 }
10192 if ((len <= INC - GAP && run == 1) ||
10193 (len > INC - GAP && run == 2))
10194 items[item_count++] = p;
10195 }
10196 }
10197
10198 /*
10199 * display the items
10200 */
10201 if (run == 1)
10202 {
10203 cols = (Columns + GAP - 3) / INC;
10204 if (cols == 0)
10205 cols = 1;
10206 rows = (item_count + cols - 1) / cols;
10207 }
10208 else /* run == 2 */
10209 rows = item_count;
10210 for (row = 0; row < rows && !got_int; ++row)
10211 {
10212 msg_putchar('\n'); /* go to next line */
10213 if (got_int) /* 'q' typed in more */
10214 break;
10215 col = 0;
10216 for (i = row; i < item_count; i += rows)
10217 {
10218 msg_col = col; /* make columns */
10219 showoneopt(items[i], opt_flags);
10220 col += INC;
10221 }
10222 out_flush();
10223 ui_breakcheck();
10224 }
10225 }
10226 vim_free(items);
10227}
10228
10229/*
10230 * Return TRUE if option "p" has its default value.
10231 */
10232 static int
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010233optval_default(struct vimoption *p, char_u *varp, int compatible)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010234{
10235 int dvi;
10236
10237 if (varp == NULL)
10238 return TRUE; /* hidden option is always at default */
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010239 dvi = ((p->flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010240 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010241 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010242 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010243 /* the cast to long is required for Manx C, long_i is
10244 * needed for MSVC */
10245 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010246 /* P_STRING */
10247 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
10248}
10249
10250/*
10251 * showoneopt: show the value of one option
10252 * must not be called with a hidden option!
10253 */
10254 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010255showoneopt(
10256 struct vimoption *p,
10257 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010258{
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010259 char_u *varp;
10260 int save_silent = silent_mode;
10261
10262 silent_mode = FALSE;
10263 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010264
10265 varp = get_varp_scope(p, opt_flags);
10266
10267 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
10268 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
10269 ? !curbufIsChanged() : !*(int *)varp))
Bram Moolenaar32526b32019-01-19 17:43:09 +010010270 msg_puts("no");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010271 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010272 msg_puts("--");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010273 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010274 msg_puts(" ");
10275 msg_puts(p->fullname);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010276 if (!(p->flags & P_BOOL))
10277 {
10278 msg_putchar('=');
10279 /* put value string in NameBuff */
10280 option_value2string(p, opt_flags);
10281 msg_outtrans(NameBuff);
10282 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010283
10284 silent_mode = save_silent;
10285 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010286}
10287
10288/*
10289 * Write modified options as ":set" commands to a file.
10290 *
10291 * There are three values for "opt_flags":
10292 * OPT_GLOBAL: Write global option values and fresh values of
10293 * buffer-local options (used for start of a session
10294 * file).
10295 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10296 * curwin (used for a vimrc file).
10297 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10298 * and local values for window-local options of
10299 * curwin. Local values are also written when at the
10300 * default value, because a modeline or autocommand
10301 * may have set them when doing ":edit file" and the
10302 * user has set them back at the default or fresh
10303 * value.
10304 * When "local_only" is TRUE, don't write fresh
10305 * values, only local values (for ":mkview").
10306 * (fresh value = value used for a new buffer or window for a local option).
10307 *
10308 * Return FAIL on error, OK otherwise.
10309 */
10310 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010311makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010312{
10313 struct vimoption *p;
10314 char_u *varp; /* currently used value */
10315 char_u *varp_fresh; /* local value */
10316 char_u *varp_local = NULL; /* fresh value */
10317 char *cmd;
10318 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010319 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010320
10321 /*
10322 * The options that don't have a default (terminal name, columns, lines)
10323 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010324 * Do the loop over "options[]" twice: once for options with the
10325 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010326 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010327 for (pri = 1; pri >= 0; --pri)
10328 {
10329 for (p = &options[0]; !istermoption(p); p++)
10330 if (!(p->flags & P_NO_MKRC)
10331 && !istermoption(p)
10332 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010333 {
10334 /* skip global option when only doing locals */
10335 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10336 continue;
10337
10338 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10339 * file, they are always buffer-specific. */
10340 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10341 continue;
10342
10343 /* Global values are only written when not at the default value. */
10344 varp = get_varp_scope(p, opt_flags);
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010345 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp, p_cp))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010346 continue;
10347
10348 round = 2;
10349 if (p->indir != PV_NONE)
10350 {
10351 if (p->var == VAR_WIN)
10352 {
10353 /* skip window-local option when only doing globals */
10354 if (!(opt_flags & OPT_LOCAL))
10355 continue;
10356 /* When fresh value of window-local option is not at the
10357 * default, need to write it too. */
10358 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10359 {
10360 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010361 if (!optval_default(p, varp_fresh, p_cp))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010362 {
10363 round = 1;
10364 varp_local = varp;
10365 varp = varp_fresh;
10366 }
10367 }
10368 }
10369 }
10370
10371 /* Round 1: fresh value for window-local options.
10372 * Round 2: other values */
10373 for ( ; round <= 2; varp = varp_local, ++round)
10374 {
10375 if (round == 1 || (opt_flags & OPT_GLOBAL))
10376 cmd = "set";
10377 else
10378 cmd = "setlocal";
10379
10380 if (p->flags & P_BOOL)
10381 {
10382 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10383 return FAIL;
10384 }
10385 else if (p->flags & P_NUM)
10386 {
10387 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10388 return FAIL;
10389 }
10390 else /* P_STRING */
10391 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010392 int do_endif = FALSE;
10393
Bram Moolenaar071d4272004-06-13 20:20:40 +000010394 /* Don't set 'syntax' and 'filetype' again if the value is
10395 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010396 if (
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +010010397#if defined(FEAT_SYN_HL)
10398 p->indir == PV_SYN ||
10399#endif
10400 p->indir == PV_FT)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010401 {
10402 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10403 *(char_u **)(varp)) < 0
10404 || put_eol(fd) < 0)
10405 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010406 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010407 }
10408 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010409 p->flags) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010410 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010411 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010412 {
10413 if (put_line(fd, "endif") == FAIL)
10414 return FAIL;
10415 }
10416 }
10417 }
10418 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010419 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010420 return OK;
10421}
10422
10423#if defined(FEAT_FOLDING) || defined(PROTO)
10424/*
10425 * Generate set commands for the local fold options only. Used when
10426 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10427 */
10428 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010429makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010430{
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010431 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, 0) == FAIL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010432# ifdef FEAT_EVAL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010433 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010434 == FAIL
10435# endif
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010436 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010437 == FAIL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010438 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010439 == FAIL
10440 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10441 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10442 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10443 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10444 )
10445 return FAIL;
10446
10447 return OK;
10448}
10449#endif
10450
10451 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010452put_setstring(
10453 FILE *fd,
10454 char *cmd,
10455 char *name,
10456 char_u **valuep,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010457 long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010458{
10459 char_u *s;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010460 char_u *buf = NULL;
10461 char_u *part = NULL;
10462 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010463
10464 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10465 return FAIL;
10466 if (*valuep != NULL)
10467 {
10468 /* Output 'pastetoggle' as key names. For other
10469 * options some characters have to be escaped with
10470 * CTRL-V or backslash */
10471 if (valuep == &p_pt)
10472 {
10473 s = *valuep;
10474 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010475 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010476 return FAIL;
10477 }
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010478 // expand the option value, replace $HOME by ~
10479 else if ((flags & P_EXPAND) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010480 {
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010481 int size = (int)STRLEN(*valuep) + 1;
10482
10483 // replace home directory in the whole option value into "buf"
10484 buf = alloc(size);
Bram Moolenaarf8441472011-04-28 17:24:58 +020010485 if (buf == NULL)
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010486 goto fail;
10487 home_replace(NULL, *valuep, buf, size, FALSE);
10488
10489 // If the option value is longer than MAXPATHL, we need to append
10490 // earch comma separated part of the option separately, so that it
10491 // can be expanded when read back.
10492 if (size >= MAXPATHL && (flags & P_COMMA) != 0
10493 && vim_strchr(*valuep, ',') != NULL)
10494 {
10495 part = alloc(size);
10496 if (part == NULL)
10497 goto fail;
10498
10499 // write line break to clear the option, e.g. ':set rtp='
10500 if (put_eol(fd) == FAIL)
10501 goto fail;
10502
10503 p = buf;
10504 while (*p != NUL)
10505 {
10506 // for each comma separated option part, append value to
10507 // the option, :set rtp+=value
10508 if (fprintf(fd, "%s %s+=", cmd, name) < 0)
10509 goto fail;
10510 (void)copy_option_part(&p, part, size, ",");
10511 if (put_escstr(fd, part, 2) == FAIL || put_eol(fd) == FAIL)
10512 goto fail;
10513 }
10514 vim_free(buf);
10515 vim_free(part);
10516 return OK;
10517 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010518 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010519 {
10520 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010521 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010522 }
10523 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010524 }
10525 else if (put_escstr(fd, *valuep, 2) == FAIL)
10526 return FAIL;
10527 }
10528 if (put_eol(fd) < 0)
10529 return FAIL;
10530 return OK;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010531fail:
10532 vim_free(buf);
10533 vim_free(part);
10534 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010535}
10536
10537 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010538put_setnum(
10539 FILE *fd,
10540 char *cmd,
10541 char *name,
10542 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010543{
10544 long wc;
10545
10546 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10547 return FAIL;
10548 if (wc_use_keyname((char_u *)valuep, &wc))
10549 {
10550 /* print 'wildchar' and 'wildcharm' as a key name */
10551 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10552 return FAIL;
10553 }
10554 else if (fprintf(fd, "%ld", *valuep) < 0)
10555 return FAIL;
10556 if (put_eol(fd) < 0)
10557 return FAIL;
10558 return OK;
10559}
10560
10561 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010562put_setbool(
10563 FILE *fd,
10564 char *cmd,
10565 char *name,
10566 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010567{
Bram Moolenaar893de922007-10-02 18:40:57 +000010568 if (value < 0) /* global/local option using global value */
10569 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010570 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10571 || put_eol(fd) < 0)
10572 return FAIL;
10573 return OK;
10574}
10575
10576/*
10577 * Clear all the terminal options.
10578 * If the option has been allocated, free the memory.
10579 * Terminal options are never hidden or indirect.
10580 */
10581 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010582clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010583{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010584 /*
10585 * Reset a few things before clearing the old options. This may cause
10586 * outputting a few things that the terminal doesn't understand, but the
10587 * screen will be cleared later, so this is OK.
10588 */
10589#ifdef FEAT_MOUSE_TTY
10590 mch_setmouse(FALSE); /* switch mouse off */
10591#endif
10592#ifdef FEAT_TITLE
Bram Moolenaar40385db2018-08-07 22:31:44 +020010593 mch_restore_title(SAVE_RESTORE_BOTH); /* restore window titles */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010594#endif
10595#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10596 /* When starting the GUI close the display opened for the clipboard.
10597 * After restoring the title, because that will need the display. */
10598 if (gui.starting)
10599 clear_xterm_clip();
10600#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010601 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010602
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010603 free_termoptions();
10604}
10605
10606 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010607free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010608{
10609 struct vimoption *p;
10610
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010611 for (p = options; p->fullname != NULL; p++)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010612 if (istermoption(p))
10613 {
10614 if (p->flags & P_ALLOCED)
10615 free_string_option(*(char_u **)(p->var));
10616 if (p->flags & P_DEF_ALLOCED)
10617 free_string_option(p->def_val[VI_DEFAULT]);
10618 *(char_u **)(p->var) = empty_option;
10619 p->def_val[VI_DEFAULT] = empty_option;
10620 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010621#ifdef FEAT_EVAL
10622 // remember where the option was cleared
10623 set_option_sctx_idx((int)(p - options), OPT_GLOBAL, current_sctx);
10624#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010625 }
10626 clear_termcodes();
10627}
10628
10629/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010630 * Free the string for one term option, if it was allocated.
10631 * Set the string to empty_option and clear allocated flag.
10632 * "var" points to the option value.
10633 */
10634 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010635free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010636{
10637 struct vimoption *p;
10638
10639 for (p = &options[0]; p->fullname != NULL; p++)
10640 if (p->var == var)
10641 {
10642 if (p->flags & P_ALLOCED)
10643 free_string_option(*(char_u **)(p->var));
10644 *(char_u **)(p->var) = empty_option;
10645 p->flags &= ~P_ALLOCED;
10646 break;
10647 }
10648}
10649
10650/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010651 * Set the terminal option defaults to the current value.
10652 * Used after setting the terminal name.
10653 */
10654 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010655set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010656{
10657 struct vimoption *p;
10658
10659 for (p = &options[0]; p->fullname != NULL; p++)
10660 {
10661 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10662 {
10663 if (p->flags & P_DEF_ALLOCED)
10664 {
10665 free_string_option(p->def_val[VI_DEFAULT]);
10666 p->flags &= ~P_DEF_ALLOCED;
10667 }
10668 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10669 if (p->flags & P_ALLOCED)
10670 {
10671 p->flags |= P_DEF_ALLOCED;
10672 p->flags &= ~P_ALLOCED; /* don't free the value now */
10673 }
10674 }
10675 }
10676}
10677
10678/*
10679 * return TRUE if 'p' starts with 't_'
10680 */
10681 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010682istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010683{
10684 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10685}
10686
10687/*
10688 * Compute columns for ruler and shown command. 'sc_col' is also used to
10689 * decide what the maximum length of a message on the status line can be.
10690 * If there is a status line for the last window, 'sc_col' is independent
10691 * of 'ru_col'.
10692 */
10693
10694#define COL_RULER 17 /* columns needed by standard ruler */
10695
10696 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010697comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010698{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010699#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010700 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010701
10702 sc_col = 0;
10703 ru_col = 0;
10704 if (p_ru)
10705 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010706# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010707 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010708# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010709 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010710# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010711 /* no last status line, adjust sc_col */
10712 if (!last_has_status)
10713 sc_col = ru_col;
10714 }
10715 if (p_sc)
10716 {
10717 sc_col += SHOWCMD_COLS;
10718 if (!p_ru || last_has_status) /* no need for separating space */
10719 ++sc_col;
10720 }
10721 sc_col = Columns - sc_col;
10722 ru_col = Columns - ru_col;
10723 if (sc_col <= 0) /* screen too narrow, will become a mess */
10724 sc_col = 1;
10725 if (ru_col <= 0)
10726 ru_col = 1;
10727#else
10728 sc_col = Columns;
10729 ru_col = Columns;
10730#endif
10731}
10732
Bram Moolenaar113e1072019-01-20 15:30:40 +010010733#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010734/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010735 * Unset local option value, similar to ":set opt<".
10736 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010737 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010738unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010739{
10740 struct vimoption *p;
10741 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010742 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010743
10744 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010745 if (opt_idx < 0)
10746 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010747 p = &(options[opt_idx]);
10748
10749 switch ((int)p->indir)
10750 {
10751 /* global option with local value: use local value if it's been set */
10752 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010753 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010754 break;
10755 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010756 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010757 break;
10758 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010759 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010760 break;
10761 case PV_AR:
10762 buf->b_p_ar = -1;
10763 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010764 case PV_BKC:
10765 clear_string_option(&buf->b_p_bkc);
10766 buf->b_bkc_flags = 0;
10767 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010768 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010769 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010770 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010771 case PV_TC:
10772 clear_string_option(&buf->b_p_tc);
10773 buf->b_tc_flags = 0;
10774 break;
Bram Moolenaar375e3392019-01-31 18:26:10 +010010775 case PV_SISO:
10776 curwin->w_p_siso = -1;
10777 break;
10778 case PV_SO:
10779 curwin->w_p_so = -1;
10780 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010781#ifdef FEAT_FIND_ID
10782 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010783 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010784 break;
10785 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010786 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010787 break;
10788#endif
10789#ifdef FEAT_INS_EXPAND
10790 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010791 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010792 break;
10793 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010794 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010795 break;
10796#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010797 case PV_FP:
10798 clear_string_option(&buf->b_p_fp);
10799 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010800#ifdef FEAT_QUICKFIX
10801 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010802 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010803 break;
10804 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010805 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010806 break;
10807 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010808 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010809 break;
10810#endif
10811#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10812 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010813 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010814 break;
10815#endif
10816#if defined(FEAT_CRYPT)
10817 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010818 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010819 break;
10820#endif
10821#ifdef FEAT_STL_OPT
10822 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010823 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010824 break;
10825#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010826 case PV_UL:
10827 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10828 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010829#ifdef FEAT_LISP
10830 case PV_LW:
10831 clear_string_option(&buf->b_p_lw);
10832 break;
10833#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010834 case PV_MENC:
10835 clear_string_option(&buf->b_p_menc);
10836 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010837 }
10838}
Bram Moolenaar113e1072019-01-20 15:30:40 +010010839#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010840
10841/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010842 * Get pointer to option variable, depending on local or global scope.
10843 */
10844 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010845get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010846{
10847 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10848 {
10849 if (p->var == VAR_WIN)
10850 return (char_u *)GLOBAL_WO(get_varp(p));
10851 return p->var;
10852 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010853 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010854 {
10855 switch ((int)p->indir)
10856 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010857 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010858#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010859 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10860 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10861 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010862#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010863 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10864 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10865 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010866 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010867 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010868 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar375e3392019-01-31 18:26:10 +010010869 case PV_SISO: return (char_u *)&(curwin->w_p_siso);
10870 case PV_SO: return (char_u *)&(curwin->w_p_so);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010871#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010872 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10873 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010874#endif
10875#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010876 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10877 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010878#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010879#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10880 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10881#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010882#if defined(FEAT_CRYPT)
10883 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10884#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010885#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010886 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010887#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010888 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010889#ifdef FEAT_LISP
10890 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10891#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010892 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010893 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010894 }
10895 return NULL; /* "cannot happen" */
10896 }
10897 return get_varp(p);
10898}
10899
10900/*
10901 * Get pointer to option variable.
10902 */
10903 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010904get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010905{
10906 /* hidden option, always return NULL */
10907 if (p->var == NULL)
10908 return NULL;
10909
10910 switch ((int)p->indir)
10911 {
10912 case PV_NONE: return p->var;
10913
10914 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010915 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010916 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010917 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010918 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010919 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010920 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010921 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010922 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010923 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010924 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010925 case PV_TC: return *curbuf->b_p_tc != NUL
10926 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010927 case PV_BKC: return *curbuf->b_p_bkc != NUL
10928 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar375e3392019-01-31 18:26:10 +010010929 case PV_SISO: return curwin->w_p_siso >= 0
10930 ? (char_u *)&(curwin->w_p_siso) : p->var;
10931 case PV_SO: return curwin->w_p_so >= 0
10932 ? (char_u *)&(curwin->w_p_so) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010933#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010934 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010935 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010936 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010937 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10938#endif
10939#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010940 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010941 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010942 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010943 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10944#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010945 case PV_FP: return *curbuf->b_p_fp != NUL
10946 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010947#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010948 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010949 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010950 case PV_GP: return *curbuf->b_p_gp != NUL
10951 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10952 case PV_MP: return *curbuf->b_p_mp != NUL
10953 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010954#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010955#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10956 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10957 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10958#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010959#if defined(FEAT_CRYPT)
10960 case PV_CM: return *curbuf->b_p_cm != NUL
10961 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10962#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010963#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010964 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010965 ? (char_u *)&(curwin->w_p_stl) : p->var;
10966#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010967 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10968 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010969#ifdef FEAT_LISP
10970 case PV_LW: return *curbuf->b_p_lw != NUL
10971 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10972#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010973 case PV_MENC: return *curbuf->b_p_menc != NUL
10974 ? (char_u *)&(curbuf->b_p_menc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010975
10976#ifdef FEAT_ARABIC
10977 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10978#endif
10979 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010980#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010981 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10982#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010983#ifdef FEAT_SYN_HL
10984 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10985 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010986 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010987#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010988#ifdef FEAT_DIFF
10989 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10990#endif
10991#ifdef FEAT_FOLDING
10992 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10993 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10994 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10995 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10996 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10997 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10998 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10999# ifdef FEAT_EVAL
11000 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
11001 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
11002# endif
11003 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
11004#endif
11005 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020011006 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011007#ifdef FEAT_LINEBREAK
11008 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
11009#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011010 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000011011 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020011012#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011013 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
11014#endif
11015#ifdef FEAT_RIGHTLEFT
11016 case PV_RL: return (char_u *)&(curwin->w_p_rl);
11017 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
11018#endif
11019 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
11020 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
11021#ifdef FEAT_LINEBREAK
11022 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020011023 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
11024 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011025#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011026 case PV_WCR: return (char_u *)&(curwin->w_p_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011027 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011028 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011029#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011030 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
11031 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
11032#endif
11033#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011034 case PV_TWK: return (char_u *)&(curwin->w_p_twk);
11035 case PV_TWS: return (char_u *)&(curwin->w_p_tws);
11036 case PV_TWSL: return (char_u *)&(curbuf->b_p_twsl);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011037#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011038
11039 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
11040 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011041 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011042 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
11043 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011044 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
11045 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
11046#ifdef FEAT_CINDENT
11047 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
11048 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
11049 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
11050#endif
11051#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11052 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
11053#endif
11054#ifdef FEAT_COMMENTS
11055 case PV_COM: return (char_u *)&(curbuf->b_p_com);
11056#endif
11057#ifdef FEAT_FOLDING
11058 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
11059#endif
11060#ifdef FEAT_INS_EXPAND
11061 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
11062#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011063#ifdef FEAT_COMPL_FUNC
11064 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011065 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011066#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +020011067#ifdef FEAT_EVAL
11068 case PV_TFU: return (char_u *)&(curbuf->b_p_tfu);
11069#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011070 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020011071 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011072 case PV_ET: return (char_u *)&(curbuf->b_p_et);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011073 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011074 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011075 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011076 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011077 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011078 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
11079 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
11080 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
11081 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
11082#ifdef FEAT_FIND_ID
11083# ifdef FEAT_EVAL
11084 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
11085# endif
11086#endif
11087#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11088 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
11089 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
11090#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011091#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011092 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
11093#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011094#ifdef FEAT_CRYPT
11095 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
11096#endif
11097#ifdef FEAT_LISP
11098 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
11099#endif
11100 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
11101 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
11102 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
11103 case PV_MOD: return (char_u *)&(curbuf->b_changed);
11104 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011105 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011106#ifdef FEAT_TEXTOBJ
11107 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
11108#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011109 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
11110#ifdef FEAT_SMARTINDENT
11111 case PV_SI: return (char_u *)&(curbuf->b_p_si);
11112#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011113 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011114 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
11115#ifdef FEAT_SEARCHPATH
11116 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
11117#endif
11118 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
11119#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011120 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011121 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
11122#endif
11123#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020011124 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
11125 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
11126 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011127#endif
11128 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
11129 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
11130 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
11131 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011132#ifdef FEAT_PERSISTENT_UNDO
11133 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
11134#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011135 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
11136#ifdef FEAT_KEYMAP
11137 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
11138#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011139#ifdef FEAT_SIGNS
11140 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
11141#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011142#ifdef FEAT_VARTABS
11143 case PV_VSTS: return (char_u *)&(curbuf->b_p_vsts);
11144 case PV_VTS: return (char_u *)&(curbuf->b_p_vts);
11145#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010011146 default: iemsg(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011147 }
11148 /* always return a valid pointer to avoid a crash! */
11149 return (char_u *)&(curbuf->b_p_wm);
11150}
11151
11152/*
11153 * Get the value of 'equalprg', either the buffer-local one or the global one.
11154 */
11155 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011156get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011157{
11158 if (*curbuf->b_p_ep == NUL)
11159 return p_ep;
11160 return curbuf->b_p_ep;
11161}
11162
Bram Moolenaar071d4272004-06-13 20:20:40 +000011163/*
11164 * Copy options from one window to another.
11165 * Used when splitting a window.
11166 */
11167 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011168win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011169{
11170 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
11171 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020011172#if defined(FEAT_LINEBREAK)
11173 briopt_check(wp_to);
11174#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011175}
Bram Moolenaar071d4272004-06-13 20:20:40 +000011176
11177/*
11178 * Copy the options from one winopt_T to another.
11179 * Doesn't free the old option values in "to", use clear_winopt() for that.
11180 * The 'scroll' option is not copied, because it depends on the window height.
11181 * The 'previewwindow' option is reset, there can be only one preview window.
11182 */
11183 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011184copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011185{
11186#ifdef FEAT_ARABIC
11187 to->wo_arab = from->wo_arab;
11188#endif
11189 to->wo_list = from->wo_list;
11190 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020011191 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011192#ifdef FEAT_LINEBREAK
11193 to->wo_nuw = from->wo_nuw;
11194#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011195#ifdef FEAT_RIGHTLEFT
11196 to->wo_rl = from->wo_rl;
11197 to->wo_rlc = vim_strsave(from->wo_rlc);
11198#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011199#ifdef FEAT_STL_OPT
11200 to->wo_stl = vim_strsave(from->wo_stl);
11201#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011202 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011203#ifdef FEAT_DIFF
11204 to->wo_wrap_save = from->wo_wrap_save;
11205#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011206#ifdef FEAT_LINEBREAK
11207 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020011208 to->wo_bri = from->wo_bri;
11209 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011210#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011211 to->wo_wcr = vim_strsave(from->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011212 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011213 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010011214 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011215 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011216#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000011217 to->wo_spell = from->wo_spell;
11218#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011219#ifdef FEAT_SYN_HL
11220 to->wo_cuc = from->wo_cuc;
11221 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020011222 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011223#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011224#ifdef FEAT_DIFF
11225 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011226 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011227#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011228#ifdef FEAT_CONCEAL
11229 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020011230 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011231#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011232#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011233 to->wo_twk = vim_strsave(from->wo_twk);
11234 to->wo_tws = vim_strsave(from->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011235#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011236#ifdef FEAT_FOLDING
11237 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011238 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011239 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011240 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011241 to->wo_fdi = vim_strsave(from->wo_fdi);
11242 to->wo_fml = from->wo_fml;
11243 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011244 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011245 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011246 to->wo_fdm_save = from->wo_diff_saved
11247 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011248 to->wo_fdn = from->wo_fdn;
11249# ifdef FEAT_EVAL
11250 to->wo_fde = vim_strsave(from->wo_fde);
11251 to->wo_fdt = vim_strsave(from->wo_fdt);
11252# endif
11253 to->wo_fmr = vim_strsave(from->wo_fmr);
11254#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011255#ifdef FEAT_SIGNS
11256 to->wo_scl = vim_strsave(from->wo_scl);
11257#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011258 check_winopt(to); /* don't want NULL pointers */
11259}
11260
11261/*
11262 * Check string options in a window for a NULL value.
11263 */
11264 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011265check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011266{
11267 check_winopt(&win->w_onebuf_opt);
11268 check_winopt(&win->w_allbuf_opt);
11269}
11270
11271/*
11272 * Check for NULL pointers in a winopt_T and replace them with empty_option.
11273 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020011274 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011275check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011276{
11277#ifdef FEAT_FOLDING
11278 check_string_option(&wop->wo_fdi);
11279 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011280 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011281# ifdef FEAT_EVAL
11282 check_string_option(&wop->wo_fde);
11283 check_string_option(&wop->wo_fdt);
11284# endif
11285 check_string_option(&wop->wo_fmr);
11286#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011287#ifdef FEAT_SIGNS
11288 check_string_option(&wop->wo_scl);
11289#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011290#ifdef FEAT_RIGHTLEFT
11291 check_string_option(&wop->wo_rlc);
11292#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011293#ifdef FEAT_STL_OPT
11294 check_string_option(&wop->wo_stl);
11295#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011296#ifdef FEAT_SYN_HL
11297 check_string_option(&wop->wo_cc);
11298#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011299#ifdef FEAT_CONCEAL
11300 check_string_option(&wop->wo_cocu);
11301#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011302#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011303 check_string_option(&wop->wo_twk);
11304 check_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011305#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011306#ifdef FEAT_LINEBREAK
11307 check_string_option(&wop->wo_briopt);
11308#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011309 check_string_option(&wop->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011310}
11311
11312/*
11313 * Free the allocated memory inside a winopt_T.
11314 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011315 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011316clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011317{
11318#ifdef FEAT_FOLDING
11319 clear_string_option(&wop->wo_fdi);
11320 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011321 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011322# ifdef FEAT_EVAL
11323 clear_string_option(&wop->wo_fde);
11324 clear_string_option(&wop->wo_fdt);
11325# endif
11326 clear_string_option(&wop->wo_fmr);
11327#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011328#ifdef FEAT_SIGNS
11329 clear_string_option(&wop->wo_scl);
11330#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011331#ifdef FEAT_LINEBREAK
11332 clear_string_option(&wop->wo_briopt);
11333#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011334 clear_string_option(&wop->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011335#ifdef FEAT_RIGHTLEFT
11336 clear_string_option(&wop->wo_rlc);
11337#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011338#ifdef FEAT_STL_OPT
11339 clear_string_option(&wop->wo_stl);
11340#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011341#ifdef FEAT_SYN_HL
11342 clear_string_option(&wop->wo_cc);
11343#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011344#ifdef FEAT_CONCEAL
11345 clear_string_option(&wop->wo_cocu);
11346#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011347#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011348 clear_string_option(&wop->wo_twk);
11349 clear_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011350#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011351}
11352
11353/*
11354 * Copy global option values to local options for one buffer.
11355 * Used when creating a new buffer and sometimes when entering a buffer.
11356 * flags:
11357 * BCO_ENTER We will enter the buf buffer.
11358 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11359 * appropriate.
11360 * BCO_NOHELP Don't copy the values to a help buffer.
11361 */
11362 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011363buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011364{
11365 int should_copy = TRUE;
11366 char_u *save_p_isk = NULL; /* init for GCC */
11367 int dont_do_help;
11368 int did_isk = FALSE;
11369
11370 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011371 * Skip this when the option defaults have not been set yet. Happens when
11372 * main() allocates the first buffer.
11373 */
11374 if (p_cpo != NULL)
11375 {
11376 /*
11377 * Always copy when entering and 'cpo' contains 'S'.
11378 * Don't copy when already initialized.
11379 * Don't copy when 'cpo' contains 's' and not entering.
11380 * 'S' BCO_ENTER initialized 's' should_copy
11381 * yes yes X X TRUE
11382 * yes no yes X FALSE
11383 * no X yes X FALSE
11384 * X no no yes FALSE
11385 * X no no no TRUE
11386 * no yes no X TRUE
11387 */
11388 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11389 && (buf->b_p_initialized
11390 || (!(flags & BCO_ENTER)
11391 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11392 should_copy = FALSE;
11393
11394 if (should_copy || (flags & BCO_ALWAYS))
11395 {
11396 /* Don't copy the options specific to a help buffer when
11397 * BCO_NOHELP is given or the options were initialized already
11398 * (jumping back to a help file with CTRL-T or CTRL-O) */
11399 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11400 || buf->b_p_initialized;
11401 if (dont_do_help) /* don't free b_p_isk */
11402 {
11403 save_p_isk = buf->b_p_isk;
11404 buf->b_p_isk = NULL;
11405 }
11406 /*
Bram Moolenaar40385db2018-08-07 22:31:44 +020011407 * Always free the allocated strings. If not already initialized,
11408 * reset 'readonly' and copy 'fileformat'.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011409 */
11410 if (!buf->b_p_initialized)
11411 {
11412 free_buf_options(buf, TRUE);
11413 buf->b_p_ro = FALSE; /* don't copy readonly */
11414 buf->b_p_tx = p_tx;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011415 buf->b_p_fenc = vim_strsave(p_fenc);
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011416 switch (*p_ffs)
11417 {
11418 case 'm':
11419 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11420 case 'd':
11421 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11422 case 'u':
11423 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11424 default:
11425 buf->b_p_ff = vim_strsave(p_ff);
11426 }
11427 if (buf->b_p_ff != NULL)
11428 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011429 buf->b_p_bh = empty_option;
11430 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011431 }
11432 else
11433 free_buf_options(buf, FALSE);
11434
11435 buf->b_p_ai = p_ai;
11436 buf->b_p_ai_nopaste = p_ai_nopaste;
11437 buf->b_p_sw = p_sw;
11438 buf->b_p_tw = p_tw;
11439 buf->b_p_tw_nopaste = p_tw_nopaste;
11440 buf->b_p_tw_nobin = p_tw_nobin;
11441 buf->b_p_wm = p_wm;
11442 buf->b_p_wm_nopaste = p_wm_nopaste;
11443 buf->b_p_wm_nobin = p_wm_nobin;
11444 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011445 buf->b_p_bomb = p_bomb;
Bram Moolenaarb388be02015-07-22 22:19:38 +020011446 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011447 buf->b_p_et = p_et;
11448 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011449 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011450 buf->b_p_ml = p_ml;
11451 buf->b_p_ml_nobin = p_ml_nobin;
11452 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011453 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011454#ifdef FEAT_INS_EXPAND
11455 buf->b_p_cpt = vim_strsave(p_cpt);
11456#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011457#ifdef FEAT_COMPL_FUNC
11458 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011459 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011460#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +020011461#ifdef FEAT_EVAL
11462 buf->b_p_tfu = vim_strsave(p_tfu);
11463#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011464 buf->b_p_sts = p_sts;
11465 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011466#ifdef FEAT_VARTABS
11467 buf->b_p_vsts = vim_strsave(p_vsts);
11468 if (p_vsts && p_vsts != empty_option)
11469 tabstop_set(p_vsts, &buf->b_p_vsts_array);
11470 else
11471 buf->b_p_vsts_array = 0;
11472 buf->b_p_vsts_nopaste = p_vsts_nopaste
11473 ? vim_strsave(p_vsts_nopaste) : NULL;
11474#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011475 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011476#ifdef FEAT_COMMENTS
11477 buf->b_p_com = vim_strsave(p_com);
11478#endif
11479#ifdef FEAT_FOLDING
11480 buf->b_p_cms = vim_strsave(p_cms);
11481#endif
11482 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011483 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011484 buf->b_p_nf = vim_strsave(p_nf);
11485 buf->b_p_mps = vim_strsave(p_mps);
11486#ifdef FEAT_SMARTINDENT
11487 buf->b_p_si = p_si;
11488#endif
11489 buf->b_p_ci = p_ci;
11490#ifdef FEAT_CINDENT
11491 buf->b_p_cin = p_cin;
11492 buf->b_p_cink = vim_strsave(p_cink);
11493 buf->b_p_cino = vim_strsave(p_cino);
11494#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011495 /* Don't copy 'filetype', it must be detected */
11496 buf->b_p_ft = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011497 buf->b_p_pi = p_pi;
11498#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11499 buf->b_p_cinw = vim_strsave(p_cinw);
11500#endif
11501#ifdef FEAT_LISP
11502 buf->b_p_lisp = p_lisp;
11503#endif
11504#ifdef FEAT_SYN_HL
11505 /* Don't copy 'syntax', it must be set */
11506 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011507 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011508 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011509#endif
11510#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011511 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011512 (void)compile_cap_prog(&buf->b_s);
11513 buf->b_s.b_p_spf = vim_strsave(p_spf);
11514 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011515#endif
11516#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11517 buf->b_p_inde = vim_strsave(p_inde);
11518 buf->b_p_indk = vim_strsave(p_indk);
11519#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011520 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011521#if defined(FEAT_EVAL)
11522 buf->b_p_fex = vim_strsave(p_fex);
11523#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011524#ifdef FEAT_CRYPT
11525 buf->b_p_key = vim_strsave(p_key);
11526#endif
11527#ifdef FEAT_SEARCHPATH
11528 buf->b_p_sua = vim_strsave(p_sua);
11529#endif
11530#ifdef FEAT_KEYMAP
11531 buf->b_p_keymap = vim_strsave(p_keymap);
11532 buf->b_kmap_state |= KEYMAP_INIT;
11533#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011534#ifdef FEAT_TERMINAL
11535 buf->b_p_twsl = p_twsl;
11536#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011537 /* This isn't really an option, but copying the langmap and IME
11538 * state from the current buffer is better than resetting it. */
11539 buf->b_p_iminsert = p_iminsert;
11540 buf->b_p_imsearch = p_imsearch;
11541
11542 /* options that are normally global but also have a local value
11543 * are not copied, start using the global value */
11544 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011545 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011546 buf->b_p_bkc = empty_option;
11547 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011548#ifdef FEAT_QUICKFIX
11549 buf->b_p_gp = empty_option;
11550 buf->b_p_mp = empty_option;
11551 buf->b_p_efm = empty_option;
11552#endif
11553 buf->b_p_ep = empty_option;
11554 buf->b_p_kp = empty_option;
11555 buf->b_p_path = empty_option;
11556 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011557 buf->b_p_tc = empty_option;
11558 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011559#ifdef FEAT_FIND_ID
11560 buf->b_p_def = empty_option;
11561 buf->b_p_inc = empty_option;
11562# ifdef FEAT_EVAL
11563 buf->b_p_inex = vim_strsave(p_inex);
11564# endif
11565#endif
11566#ifdef FEAT_INS_EXPAND
11567 buf->b_p_dict = empty_option;
11568 buf->b_p_tsr = empty_option;
11569#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011570#ifdef FEAT_TEXTOBJ
11571 buf->b_p_qe = vim_strsave(p_qe);
11572#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011573#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11574 buf->b_p_bexpr = empty_option;
11575#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011576#if defined(FEAT_CRYPT)
11577 buf->b_p_cm = empty_option;
11578#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011579#ifdef FEAT_PERSISTENT_UNDO
11580 buf->b_p_udf = p_udf;
11581#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011582#ifdef FEAT_LISP
11583 buf->b_p_lw = empty_option;
11584#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011585 buf->b_p_menc = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011586
11587 /*
11588 * Don't copy the options set by ex_help(), use the saved values,
11589 * when going from a help buffer to a non-help buffer.
11590 * Don't touch these at all when BCO_NOHELP is used and going from
11591 * or to a help buffer.
11592 */
11593 if (dont_do_help)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011594 {
Bram Moolenaar071d4272004-06-13 20:20:40 +000011595 buf->b_p_isk = save_p_isk;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011596#ifdef FEAT_VARTABS
11597 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11598 tabstop_set(p_vts, &buf->b_p_vts_array);
11599 else
11600 buf->b_p_vts_array = NULL;
11601#endif
11602 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011603 else
11604 {
11605 buf->b_p_isk = vim_strsave(p_isk);
11606 did_isk = TRUE;
11607 buf->b_p_ts = p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011608#ifdef FEAT_VARTABS
11609 buf->b_p_vts = vim_strsave(p_vts);
11610 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11611 tabstop_set(p_vts, &buf->b_p_vts_array);
11612 else
11613 buf->b_p_vts_array = NULL;
11614#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011615 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011616 if (buf->b_p_bt[0] == 'h')
11617 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011618 buf->b_p_ma = p_ma;
11619 }
11620 }
11621
11622 /*
11623 * When the options should be copied (ignoring BCO_ALWAYS), set the
11624 * flag that indicates that the options have been initialized.
11625 */
11626 if (should_copy)
11627 buf->b_p_initialized = TRUE;
11628 }
11629
11630 check_buf_options(buf); /* make sure we don't have NULLs */
11631 if (did_isk)
11632 (void)buf_init_chartab(buf, FALSE);
11633}
11634
11635/*
11636 * Reset the 'modifiable' option and its default value.
11637 */
11638 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011639reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011640{
11641 int opt_idx;
11642
11643 curbuf->b_p_ma = FALSE;
11644 p_ma = FALSE;
11645 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011646 if (opt_idx >= 0)
11647 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011648}
11649
11650/*
11651 * Set the global value for 'iminsert' to the local value.
11652 */
11653 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011654set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011655{
11656 p_iminsert = curbuf->b_p_iminsert;
11657}
11658
11659/*
11660 * Set the global value for 'imsearch' to the local value.
11661 */
11662 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011663set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011664{
11665 p_imsearch = curbuf->b_p_imsearch;
11666}
11667
11668#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11669static int expand_option_idx = -1;
11670static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11671static int expand_option_flags = 0;
11672
11673 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011674set_context_in_set_cmd(
11675 expand_T *xp,
11676 char_u *arg,
11677 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011678{
11679 int nextchar;
11680 long_u flags = 0; /* init for GCC */
11681 int opt_idx = 0; /* init for GCC */
11682 char_u *p;
11683 char_u *s;
11684 int is_term_option = FALSE;
11685 int key;
11686
11687 expand_option_flags = opt_flags;
11688
11689 xp->xp_context = EXPAND_SETTINGS;
11690 if (*arg == NUL)
11691 {
11692 xp->xp_pattern = arg;
11693 return;
11694 }
11695 p = arg + STRLEN(arg) - 1;
11696 if (*p == ' ' && *(p - 1) != '\\')
11697 {
11698 xp->xp_pattern = p + 1;
11699 return;
11700 }
11701 while (p > arg)
11702 {
11703 s = p;
11704 /* count number of backslashes before ' ' or ',' */
11705 if (*p == ' ' || *p == ',')
11706 {
11707 while (s > arg && *(s - 1) == '\\')
11708 --s;
11709 }
11710 /* break at a space with an even number of backslashes */
11711 if (*p == ' ' && ((p - s) & 1) == 0)
11712 {
11713 ++p;
11714 break;
11715 }
11716 --p;
11717 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011718 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011719 {
11720 xp->xp_context = EXPAND_BOOL_SETTINGS;
11721 p += 2;
11722 }
11723 if (STRNCMP(p, "inv", 3) == 0)
11724 {
11725 xp->xp_context = EXPAND_BOOL_SETTINGS;
11726 p += 3;
11727 }
11728 xp->xp_pattern = arg = p;
11729 if (*arg == '<')
11730 {
11731 while (*p != '>')
11732 if (*p++ == NUL) /* expand terminal option name */
11733 return;
11734 key = get_special_key_code(arg + 1);
11735 if (key == 0) /* unknown name */
11736 {
11737 xp->xp_context = EXPAND_NOTHING;
11738 return;
11739 }
11740 nextchar = *++p;
11741 is_term_option = TRUE;
11742 expand_option_name[2] = KEY2TERMCAP0(key);
11743 expand_option_name[3] = KEY2TERMCAP1(key);
11744 }
11745 else
11746 {
11747 if (p[0] == 't' && p[1] == '_')
11748 {
11749 p += 2;
11750 if (*p != NUL)
11751 ++p;
11752 if (*p == NUL)
11753 return; /* expand option name */
11754 nextchar = *++p;
11755 is_term_option = TRUE;
11756 expand_option_name[2] = p[-2];
11757 expand_option_name[3] = p[-1];
11758 }
11759 else
11760 {
11761 /* Allow * wildcard */
11762 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11763 p++;
11764 if (*p == NUL)
11765 return;
11766 nextchar = *p;
11767 *p = NUL;
11768 opt_idx = findoption(arg);
11769 *p = nextchar;
11770 if (opt_idx == -1 || options[opt_idx].var == NULL)
11771 {
11772 xp->xp_context = EXPAND_NOTHING;
11773 return;
11774 }
11775 flags = options[opt_idx].flags;
11776 if (flags & P_BOOL)
11777 {
11778 xp->xp_context = EXPAND_NOTHING;
11779 return;
11780 }
11781 }
11782 }
11783 /* handle "-=" and "+=" */
11784 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11785 {
11786 ++p;
11787 nextchar = '=';
11788 }
11789 if ((nextchar != '=' && nextchar != ':')
11790 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11791 {
11792 xp->xp_context = EXPAND_UNSUCCESSFUL;
11793 return;
11794 }
11795 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11796 {
11797 xp->xp_context = EXPAND_OLD_SETTING;
11798 if (is_term_option)
11799 expand_option_idx = -1;
11800 else
11801 expand_option_idx = opt_idx;
11802 xp->xp_pattern = p + 1;
11803 return;
11804 }
11805 xp->xp_context = EXPAND_NOTHING;
11806 if (is_term_option || (flags & P_NUM))
11807 return;
11808
11809 xp->xp_pattern = p + 1;
11810
11811 if (flags & P_EXPAND)
11812 {
11813 p = options[opt_idx].var;
11814 if (p == (char_u *)&p_bdir
11815 || p == (char_u *)&p_dir
11816 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011817 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011818 || p == (char_u *)&p_rtp
11819#ifdef FEAT_SEARCHPATH
11820 || p == (char_u *)&p_cdpath
11821#endif
11822#ifdef FEAT_SESSION
11823 || p == (char_u *)&p_vdir
11824#endif
11825 )
11826 {
11827 xp->xp_context = EXPAND_DIRECTORIES;
11828 if (p == (char_u *)&p_path
11829#ifdef FEAT_SEARCHPATH
11830 || p == (char_u *)&p_cdpath
11831#endif
11832 )
11833 xp->xp_backslash = XP_BS_THREE;
11834 else
11835 xp->xp_backslash = XP_BS_ONE;
11836 }
11837 else
11838 {
11839 xp->xp_context = EXPAND_FILES;
11840 /* for 'tags' need three backslashes for a space */
11841 if (p == (char_u *)&p_tags)
11842 xp->xp_backslash = XP_BS_THREE;
11843 else
11844 xp->xp_backslash = XP_BS_ONE;
11845 }
11846 }
11847
11848 /* For an option that is a list of file names, find the start of the
11849 * last file name. */
11850 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11851 {
11852 /* count number of backslashes before ' ' or ',' */
11853 if (*p == ' ' || *p == ',')
11854 {
11855 s = p;
11856 while (s > xp->xp_pattern && *(s - 1) == '\\')
11857 --s;
11858 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11859 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11860 {
11861 xp->xp_pattern = p + 1;
11862 break;
11863 }
11864 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011865
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011866#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011867 /* for 'spellsuggest' start at "file:" */
11868 if (options[opt_idx].var == (char_u *)&p_sps
11869 && STRNCMP(p, "file:", 5) == 0)
11870 {
11871 xp->xp_pattern = p + 5;
11872 break;
11873 }
11874#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011875 }
11876
11877 return;
11878}
11879
11880 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011881ExpandSettings(
11882 expand_T *xp,
11883 regmatch_T *regmatch,
11884 int *num_file,
11885 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011886{
11887 int num_normal = 0; /* Nr of matching non-term-code settings */
11888 int num_term = 0; /* Nr of matching terminal code settings */
11889 int opt_idx;
11890 int match;
11891 int count = 0;
11892 char_u *str;
11893 int loop;
11894 int is_term_opt;
11895 char_u name_buf[MAX_KEY_NAME_LEN];
11896 static char *(names[]) = {"all", "termcap"};
11897 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11898
11899 /* do this loop twice:
11900 * loop == 0: count the number of matching options
11901 * loop == 1: copy the matching options into allocated memory
11902 */
11903 for (loop = 0; loop <= 1; ++loop)
11904 {
11905 regmatch->rm_ic = ic;
11906 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11907 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011908 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11909 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011910 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11911 {
11912 if (loop == 0)
11913 num_normal++;
11914 else
11915 (*file)[count++] = vim_strsave((char_u *)names[match]);
11916 }
11917 }
11918 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11919 opt_idx++)
11920 {
11921 if (options[opt_idx].var == NULL)
11922 continue;
11923 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11924 && !(options[opt_idx].flags & P_BOOL))
11925 continue;
11926 is_term_opt = istermoption(&options[opt_idx]);
11927 if (is_term_opt && num_normal > 0)
11928 continue;
11929 match = FALSE;
11930 if (vim_regexec(regmatch, str, (colnr_T)0)
11931 || (options[opt_idx].shortname != NULL
11932 && vim_regexec(regmatch,
11933 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11934 match = TRUE;
11935 else if (is_term_opt)
11936 {
11937 name_buf[0] = '<';
11938 name_buf[1] = 't';
11939 name_buf[2] = '_';
11940 name_buf[3] = str[2];
11941 name_buf[4] = str[3];
11942 name_buf[5] = '>';
11943 name_buf[6] = NUL;
11944 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11945 {
11946 match = TRUE;
11947 str = name_buf;
11948 }
11949 }
11950 if (match)
11951 {
11952 if (loop == 0)
11953 {
11954 if (is_term_opt)
11955 num_term++;
11956 else
11957 num_normal++;
11958 }
11959 else
11960 (*file)[count++] = vim_strsave(str);
11961 }
11962 }
11963 /*
11964 * Check terminal key codes, these are not in the option table
11965 */
11966 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11967 {
11968 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11969 {
11970 if (!isprint(str[0]) || !isprint(str[1]))
11971 continue;
11972
11973 name_buf[0] = 't';
11974 name_buf[1] = '_';
11975 name_buf[2] = str[0];
11976 name_buf[3] = str[1];
11977 name_buf[4] = NUL;
11978
11979 match = FALSE;
11980 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11981 match = TRUE;
11982 else
11983 {
11984 name_buf[0] = '<';
11985 name_buf[1] = 't';
11986 name_buf[2] = '_';
11987 name_buf[3] = str[0];
11988 name_buf[4] = str[1];
11989 name_buf[5] = '>';
11990 name_buf[6] = NUL;
11991
11992 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11993 match = TRUE;
11994 }
11995 if (match)
11996 {
11997 if (loop == 0)
11998 num_term++;
11999 else
12000 (*file)[count++] = vim_strsave(name_buf);
12001 }
12002 }
12003
12004 /*
12005 * Check special key names.
12006 */
12007 regmatch->rm_ic = TRUE; /* ignore case here */
12008 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
12009 {
12010 name_buf[0] = '<';
12011 STRCPY(name_buf + 1, str);
12012 STRCAT(name_buf, ">");
12013
12014 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12015 {
12016 if (loop == 0)
12017 num_term++;
12018 else
12019 (*file)[count++] = vim_strsave(name_buf);
12020 }
12021 }
12022 }
12023 if (loop == 0)
12024 {
12025 if (num_normal > 0)
12026 *num_file = num_normal;
12027 else if (num_term > 0)
12028 *num_file = num_term;
12029 else
12030 return OK;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020012031 *file = ALLOC_MULT(char_u *, *num_file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012032 if (*file == NULL)
12033 {
12034 *file = (char_u **)"";
12035 return FAIL;
12036 }
12037 }
12038 }
12039 return OK;
12040}
12041
12042 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012043ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012044{
12045 char_u *var = NULL; /* init for GCC */
12046 char_u *buf;
12047
12048 *num_file = 0;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020012049 *file = ALLOC_ONE(char_u *);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012050 if (*file == NULL)
12051 return FAIL;
12052
12053 /*
12054 * For a terminal key code expand_option_idx is < 0.
12055 */
12056 if (expand_option_idx < 0)
12057 {
12058 var = find_termcode(expand_option_name + 2);
12059 if (var == NULL)
12060 expand_option_idx = findoption(expand_option_name);
12061 }
12062
12063 if (expand_option_idx >= 0)
12064 {
12065 /* put string of option value in NameBuff */
12066 option_value2string(&options[expand_option_idx], expand_option_flags);
12067 var = NameBuff;
12068 }
12069 else if (var == NULL)
12070 var = (char_u *)"";
12071
12072 /* A backslash is required before some characters. This is the reverse of
12073 * what happens in do_set(). */
12074 buf = vim_strsave_escaped(var, escape_chars);
12075
12076 if (buf == NULL)
12077 {
Bram Moolenaard23a8232018-02-10 18:45:26 +010012078 VIM_CLEAR(*file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012079 return FAIL;
12080 }
12081
12082#ifdef BACKSLASH_IN_FILENAME
12083 /* For MS-Windows et al. we don't double backslashes at the start and
12084 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012085 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012086 if (var[0] == '\\' && var[1] == '\\'
12087 && expand_option_idx >= 0
12088 && (options[expand_option_idx].flags & P_EXPAND)
12089 && vim_isfilec(var[2])
12090 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000012091 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012092#endif
12093
12094 *file[0] = buf;
12095 *num_file = 1;
12096 return OK;
12097}
12098#endif
12099
12100/*
12101 * Get the value for the numeric or string option *opp in a nice format into
12102 * NameBuff[]. Must not be called with a hidden option!
12103 */
12104 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012105option_value2string(
12106 struct vimoption *opp,
12107 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012108{
12109 char_u *varp;
12110
12111 varp = get_varp_scope(opp, opt_flags);
12112
12113 if (opp->flags & P_NUM)
12114 {
12115 long wc = 0;
12116
12117 if (wc_use_keyname(varp, &wc))
12118 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
12119 else if (wc != 0)
12120 STRCPY(NameBuff, transchar((int)wc));
12121 else
12122 sprintf((char *)NameBuff, "%ld", *(long *)varp);
12123 }
12124 else /* P_STRING */
12125 {
12126 varp = *(char_u **)(varp);
12127 if (varp == NULL) /* just in case */
12128 NameBuff[0] = NUL;
12129#ifdef FEAT_CRYPT
12130 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000012131 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012132 STRCPY(NameBuff, "*****");
12133#endif
12134 else if (opp->flags & P_EXPAND)
12135 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
12136 /* Translate 'pastetoggle' into special key names */
12137 else if ((char_u **)opp->var == &p_pt)
12138 str2specialbuf(p_pt, NameBuff, MAXPATHL);
12139 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000012140 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012141 }
12142}
12143
12144/*
12145 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
12146 * printed as a keyname.
12147 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
12148 */
12149 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012150wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012151{
12152 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
12153 {
12154 *wcp = *(long *)varp;
12155 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
12156 return TRUE;
12157 }
12158 return FALSE;
12159}
12160
Bram Moolenaar01615492015-02-03 13:00:38 +010012161#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012162/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012163 * Any character has an equivalent 'langmap' character. This is used for
12164 * keyboards that have a special language mode that sends characters above
12165 * 128 (although other characters can be translated too). The "to" field is a
12166 * Vim command character. This avoids having to switch the keyboard back to
12167 * ASCII mode when leaving Insert mode.
12168 *
12169 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
12170 * commands.
Bram Moolenaarfc3abf42019-01-24 15:54:21 +010012171 * langmap_mapga.ga_data is a sorted table of langmap_entry_T. This does the
12172 * same as langmap_mapchar[] for characters >= 256.
12173 *
12174 * Use growarray for 'langmap' chars >= 256
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012175 */
12176typedef struct
12177{
12178 int from;
12179 int to;
12180} langmap_entry_T;
12181
12182static garray_T langmap_mapga;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012183
12184/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012185 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
12186 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012187 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012188 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012189langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012190{
12191 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020012192 int a = 0;
12193 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012194
12195 /* Do a binary search for an existing entry. */
12196 while (a != b)
12197 {
12198 int i = (a + b) / 2;
12199 int d = entries[i].from - from;
12200
12201 if (d == 0)
12202 {
12203 entries[i].to = to;
12204 return;
12205 }
12206 if (d < 0)
12207 a = i + 1;
12208 else
12209 b = i;
12210 }
12211
12212 if (ga_grow(&langmap_mapga, 1) != OK)
12213 return; /* out of memory */
12214
12215 /* insert new entry at position "a" */
12216 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
12217 mch_memmove(entries + 1, entries,
12218 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
12219 ++langmap_mapga.ga_len;
12220 entries[0].from = from;
12221 entries[0].to = to;
12222}
12223
12224/*
12225 * Apply 'langmap' to multi-byte character "c" and return the result.
12226 */
12227 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012228langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012229{
12230 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
12231 int a = 0;
12232 int b = langmap_mapga.ga_len;
12233
12234 while (a != b)
12235 {
12236 int i = (a + b) / 2;
12237 int d = entries[i].from - c;
12238
12239 if (d == 0)
12240 return entries[i].to; /* found matching entry */
12241 if (d < 0)
12242 a = i + 1;
12243 else
12244 b = i;
12245 }
12246 return c; /* no entry found, return "c" unmodified */
12247}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012248
12249 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012250langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012251{
12252 int i;
12253
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012254 for (i = 0; i < 256; i++)
12255 langmap_mapchar[i] = i; /* we init with a one-to-one map */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012256 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012257}
12258
12259/*
12260 * Called when langmap option is set; the language map can be
12261 * changed at any time!
12262 */
12263 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012264langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012265{
12266 char_u *p;
12267 char_u *p2;
12268 int from, to;
12269
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012270 ga_clear(&langmap_mapga); /* clear the previous map first */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012271 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012272
12273 for (p = p_langmap; p[0] != NUL; )
12274 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000012275 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012276 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012277 {
12278 if (p2[0] == '\\' && p2[1] != NUL)
12279 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012280 }
12281 if (p2[0] == ';')
12282 ++p2; /* abcd;ABCD form, p2 points to A */
12283 else
12284 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
12285 while (p[0])
12286 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012287 if (p[0] == ',')
12288 {
12289 ++p;
12290 break;
12291 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012292 if (p[0] == '\\' && p[1] != NUL)
12293 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012294 from = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012295 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012296 if (p2 == NULL)
12297 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012298 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012299 if (p[0] != ',')
12300 {
12301 if (p[0] == '\\')
12302 ++p;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012303 to = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012304 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012305 }
12306 else
12307 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012308 if (p2[0] != ',')
12309 {
12310 if (p2[0] == '\\')
12311 ++p2;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012312 to = (*mb_ptr2char)(p2);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012313 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012314 }
12315 if (to == NUL)
12316 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012317 semsg(_("E357: 'langmap': Matching character missing for %s"),
Bram Moolenaar071d4272004-06-13 20:20:40 +000012318 transchar(from));
12319 return;
12320 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012321
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012322 if (from >= 256)
12323 langmap_set_entry(from, to);
12324 else
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012325 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012326
12327 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012328 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012329 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012330 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012331 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012332 if (*p == ';')
12333 {
12334 p = p2;
12335 if (p[0] != NUL)
12336 {
12337 if (p[0] != ',')
12338 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012339 semsg(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012340 return;
12341 }
12342 ++p;
12343 }
12344 break;
12345 }
12346 }
12347 }
12348 }
12349}
12350#endif
12351
12352/*
12353 * Return TRUE if format option 'x' is in effect.
12354 * Take care of no formatting when 'paste' is set.
12355 */
12356 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012357has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012358{
12359 if (p_paste)
12360 return FALSE;
12361 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12362}
12363
12364/*
12365 * Return TRUE if "x" is present in 'shortmess' option, or
12366 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12367 */
12368 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012369shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012370{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012371 return p_shm != NULL &&
12372 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012373 || (vim_strchr(p_shm, 'a') != NULL
12374 && vim_strchr((char_u *)SHM_A, x) != NULL));
12375}
12376
12377/*
12378 * paste_option_changed() - Called after p_paste was set or reset.
12379 */
12380 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012381paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012382{
12383 static int old_p_paste = FALSE;
12384 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012385 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012386#ifdef FEAT_CMDL_INFO
12387 static int save_ru = 0;
12388#endif
12389#ifdef FEAT_RIGHTLEFT
12390 static int save_ri = 0;
12391 static int save_hkmap = 0;
12392#endif
12393 buf_T *buf;
12394
12395 if (p_paste)
12396 {
12397 /*
12398 * Paste switched from off to on.
12399 * Save the current values, so they can be restored later.
12400 */
12401 if (!old_p_paste)
12402 {
12403 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012404 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012405 {
12406 buf->b_p_tw_nopaste = buf->b_p_tw;
12407 buf->b_p_wm_nopaste = buf->b_p_wm;
12408 buf->b_p_sts_nopaste = buf->b_p_sts;
12409 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012410 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012411#ifdef FEAT_VARTABS
12412 if (buf->b_p_vsts_nopaste)
12413 vim_free(buf->b_p_vsts_nopaste);
12414 buf->b_p_vsts_nopaste = buf->b_p_vsts && buf->b_p_vsts != empty_option
12415 ? vim_strsave(buf->b_p_vsts) : NULL;
12416#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012417 }
12418
12419 /* save global options */
12420 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012421 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012422#ifdef FEAT_CMDL_INFO
12423 save_ru = p_ru;
12424#endif
12425#ifdef FEAT_RIGHTLEFT
12426 save_ri = p_ri;
12427 save_hkmap = p_hkmap;
12428#endif
12429 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012430 p_ai_nopaste = p_ai;
12431 p_et_nopaste = p_et;
12432 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012433 p_tw_nopaste = p_tw;
12434 p_wm_nopaste = p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012435#ifdef FEAT_VARTABS
12436 if (p_vsts_nopaste)
12437 vim_free(p_vsts_nopaste);
12438 p_vsts_nopaste = p_vsts && p_vsts != empty_option ? vim_strsave(p_vsts) : NULL;
12439#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012440 }
12441
12442 /*
12443 * Always set the option values, also when 'paste' is set when it is
12444 * already on.
12445 */
12446 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012447 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012448 {
12449 buf->b_p_tw = 0; /* textwidth is 0 */
12450 buf->b_p_wm = 0; /* wrapmargin is 0 */
12451 buf->b_p_sts = 0; /* softtabstop is 0 */
12452 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012453 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012454#ifdef FEAT_VARTABS
12455 if (buf->b_p_vsts)
12456 free_string_option(buf->b_p_vsts);
12457 buf->b_p_vsts = empty_option;
12458 if (buf->b_p_vsts_array)
12459 vim_free(buf->b_p_vsts_array);
12460 buf->b_p_vsts_array = 0;
12461#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012462 }
12463
12464 /* set global options */
12465 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012466 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012467#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012468 if (p_ru)
12469 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012470 p_ru = 0; /* no ruler */
12471#endif
12472#ifdef FEAT_RIGHTLEFT
12473 p_ri = 0; /* no reverse insert */
12474 p_hkmap = 0; /* no Hebrew keyboard */
12475#endif
12476 /* set global values for local buffer options */
12477 p_tw = 0;
12478 p_wm = 0;
12479 p_sts = 0;
12480 p_ai = 0;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012481#ifdef FEAT_VARTABS
12482 if (p_vsts)
12483 free_string_option(p_vsts);
12484 p_vsts = empty_option;
12485#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012486 }
12487
12488 /*
12489 * Paste switched from on to off: Restore saved values.
12490 */
12491 else if (old_p_paste)
12492 {
12493 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012494 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012495 {
12496 buf->b_p_tw = buf->b_p_tw_nopaste;
12497 buf->b_p_wm = buf->b_p_wm_nopaste;
12498 buf->b_p_sts = buf->b_p_sts_nopaste;
12499 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012500 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012501#ifdef FEAT_VARTABS
12502 if (buf->b_p_vsts)
12503 free_string_option(buf->b_p_vsts);
12504 buf->b_p_vsts = buf->b_p_vsts_nopaste
12505 ? vim_strsave(buf->b_p_vsts_nopaste) : empty_option;
12506 if (buf->b_p_vsts_array)
12507 vim_free(buf->b_p_vsts_array);
12508 if (buf->b_p_vsts && buf->b_p_vsts != empty_option)
12509 tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array);
12510 else
12511 buf->b_p_vsts_array = 0;
12512#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012513 }
12514
12515 /* restore global options */
12516 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012517 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012518#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012519 if (p_ru != save_ru)
12520 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012521 p_ru = save_ru;
12522#endif
12523#ifdef FEAT_RIGHTLEFT
12524 p_ri = save_ri;
12525 p_hkmap = save_hkmap;
12526#endif
12527 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012528 p_ai = p_ai_nopaste;
12529 p_et = p_et_nopaste;
12530 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012531 p_tw = p_tw_nopaste;
12532 p_wm = p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012533#ifdef FEAT_VARTABS
12534 if (p_vsts)
12535 free_string_option(p_vsts);
12536 p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option;
12537#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012538 }
12539
12540 old_p_paste = p_paste;
12541}
12542
12543/*
12544 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12545 *
12546 * Reset 'compatible' and set the values for options that didn't get set yet
12547 * to the Vim defaults.
12548 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012549 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012550 */
12551 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012552vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012553{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012554 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012555 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012556 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012557
12558 if (!option_was_set((char_u *)"cp"))
12559 {
12560 p_cp = FALSE;
12561 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12562 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12563 set_option_default(opt_idx, OPT_FREE, FALSE);
12564 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012565 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012566 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012567
12568 if (fname != NULL)
12569 {
12570 p = vim_getenv(envname, &dofree);
12571 if (p == NULL)
12572 {
12573 /* Set $MYVIMRC to the first vimrc file found. */
12574 p = FullName_save(fname, FALSE);
12575 if (p != NULL)
12576 {
12577 vim_setenv(envname, p);
12578 vim_free(p);
12579 }
12580 }
12581 else if (dofree)
12582 vim_free(p);
12583 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012584}
12585
12586/*
12587 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12588 */
12589 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012590change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012591{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012592 int opt_idx;
12593
Bram Moolenaar071d4272004-06-13 20:20:40 +000012594 if (p_cp != on)
12595 {
12596 p_cp = on;
12597 compatible_set();
12598 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012599 opt_idx = findoption((char_u *)"cp");
12600 if (opt_idx >= 0)
12601 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012602}
12603
12604/*
12605 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012606 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012607 */
12608 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012609option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012610{
12611 int idx;
12612
12613 idx = findoption(name);
12614 if (idx < 0) /* unknown option */
12615 return FALSE;
12616 if (options[idx].flags & P_WAS_SET)
12617 return TRUE;
12618 return FALSE;
12619}
12620
12621/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012622 * Reset the flag indicating option "name" was set.
12623 */
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012624 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012625reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012626{
12627 int idx = findoption(name);
12628
12629 if (idx >= 0)
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012630 {
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012631 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012632 return OK;
12633 }
12634 return FAIL;
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012635}
12636
12637/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012638 * compatible_set() - Called when 'compatible' has been set or unset.
12639 *
12640 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12641 * flag) to a Vi compatible value.
12642 * When 'compatible' is unset: Set all options that have a different default
12643 * for Vim (without the P_VI_DEF flag) to that default.
12644 */
12645 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012646compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012647{
12648 int opt_idx;
12649
12650 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12651 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12652 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12653 set_option_default(opt_idx, OPT_FREE, p_cp);
12654 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012655 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012656}
12657
12658#ifdef FEAT_LINEBREAK
12659
Bram Moolenaar071d4272004-06-13 20:20:40 +000012660/*
12661 * fill_breakat_flags() -- called when 'breakat' changes value.
12662 */
12663 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012664fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012665{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012666 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012667 int i;
12668
12669 for (i = 0; i < 256; i++)
12670 breakat_flags[i] = FALSE;
12671
12672 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012673 for (p = p_breakat; *p; p++)
12674 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012675}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012676#endif
12677
12678/*
12679 * Check an option that can be a range of string values.
12680 *
12681 * Return OK for correct value, FAIL otherwise.
12682 * Empty is always OK.
12683 */
12684 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012685check_opt_strings(
12686 char_u *val,
12687 char **values,
12688 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012689{
12690 return opt_strings_flags(val, values, NULL, list);
12691}
12692
12693/*
12694 * Handle an option that can be a range of string values.
12695 * Set a flag in "*flagp" for each string present.
12696 *
12697 * Return OK for correct value, FAIL otherwise.
12698 * Empty is always OK.
12699 */
12700 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012701opt_strings_flags(
12702 char_u *val, /* new value */
12703 char **values, /* array of valid string values */
12704 unsigned *flagp,
12705 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012706{
12707 int i;
12708 int len;
12709 unsigned new_flags = 0;
12710
12711 while (*val)
12712 {
12713 for (i = 0; ; ++i)
12714 {
12715 if (values[i] == NULL) /* val not found in values[] */
12716 return FAIL;
12717
12718 len = (int)STRLEN(values[i]);
12719 if (STRNCMP(values[i], val, len) == 0
12720 && ((list && val[len] == ',') || val[len] == NUL))
12721 {
12722 val += len + (val[len] == ',');
12723 new_flags |= (1 << i);
12724 break; /* check next item in val list */
12725 }
12726 }
12727 }
12728 if (flagp != NULL)
12729 *flagp = new_flags;
12730
12731 return OK;
12732}
12733
12734/*
12735 * Read the 'wildmode' option, fill wim_flags[].
12736 */
12737 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012738check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012739{
12740 char_u new_wim_flags[4];
12741 char_u *p;
12742 int i;
12743 int idx = 0;
12744
12745 for (i = 0; i < 4; ++i)
12746 new_wim_flags[i] = 0;
12747
12748 for (p = p_wim; *p; ++p)
12749 {
12750 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12751 ;
12752 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12753 return FAIL;
12754 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12755 new_wim_flags[idx] |= WIM_LONGEST;
12756 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12757 new_wim_flags[idx] |= WIM_FULL;
12758 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12759 new_wim_flags[idx] |= WIM_LIST;
12760 else
12761 return FAIL;
12762 p += i;
12763 if (*p == NUL)
12764 break;
12765 if (*p == ',')
12766 {
12767 if (idx == 3)
12768 return FAIL;
12769 ++idx;
12770 }
12771 }
12772
12773 /* fill remaining entries with last flag */
12774 while (idx < 3)
12775 {
12776 new_wim_flags[idx + 1] = new_wim_flags[idx];
12777 ++idx;
12778 }
12779
12780 /* only when there are no errors, wim_flags[] is changed */
12781 for (i = 0; i < 4; ++i)
12782 wim_flags[i] = new_wim_flags[i];
12783 return OK;
12784}
12785
12786/*
12787 * Check if backspacing over something is allowed.
12788 */
12789 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012790can_bs(
12791 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012792{
Bram Moolenaar6b810d92018-06-04 17:28:44 +020012793#ifdef FEAT_JOB_CHANNEL
12794 if (what == BS_START && bt_prompt(curbuf))
12795 return FALSE;
12796#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012797 switch (*p_bs)
12798 {
12799 case '2': return TRUE;
12800 case '1': return (what != BS_START);
12801 case '0': return FALSE;
12802 }
12803 return vim_strchr(p_bs, what) != NULL;
12804}
12805
12806/*
12807 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12808 * the file must be considered changed when the value is different.
12809 */
12810 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012811save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012812{
12813 buf->b_start_ffc = *buf->b_p_ff;
12814 buf->b_start_eol = buf->b_p_eol;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012815 buf->b_start_bomb = buf->b_p_bomb;
12816
Bram Moolenaar071d4272004-06-13 20:20:40 +000012817 /* Only use free/alloc when necessary, they take time. */
12818 if (buf->b_start_fenc == NULL
12819 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12820 {
12821 vim_free(buf->b_start_fenc);
12822 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12823 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012824}
12825
12826/*
12827 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12828 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012829 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12830 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012831 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012832 * When "ignore_empty" is true don't consider a new, empty buffer to be
12833 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012834 */
12835 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012836file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012837{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012838 /* In a buffer that was never loaded the options are not valid. */
12839 if (buf->b_flags & BF_NEVERLOADED)
12840 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012841 if (ignore_empty
12842 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012843 && buf->b_ml.ml_line_count == 1
12844 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12845 return FALSE;
12846 if (buf->b_start_ffc != *buf->b_p_ff)
12847 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012848 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012849 return TRUE;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012850 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12851 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012852 if (buf->b_start_fenc == NULL)
12853 return (*buf->b_p_fenc != NUL);
12854 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012855}
12856
12857/*
12858 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12859 */
12860 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012861check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012862{
12863 return check_opt_strings(p, p_ff_values, FALSE);
12864}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012865
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010012866#if defined(FEAT_VARTABS) || defined(PROTO)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012867
12868/*
12869 * Set the integer values corresponding to the string setting of 'vartabstop'.
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010012870 * "array" will be set, caller must free it if needed.
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012871 */
12872 int
12873tabstop_set(char_u *var, int **array)
12874{
12875 int valcount = 1;
12876 int t;
12877 char_u *cp;
12878
Bram Moolenaar64f41072018-10-15 22:51:50 +020012879 if (var[0] == NUL || (var[0] == '0' && var[1] == NUL))
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012880 {
12881 *array = NULL;
12882 return TRUE;
12883 }
12884
Bram Moolenaar64f41072018-10-15 22:51:50 +020012885 for (cp = var; *cp != NUL; ++cp)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012886 {
Bram Moolenaar64f41072018-10-15 22:51:50 +020012887 if (cp == var || cp[-1] == ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012888 {
12889 char_u *end;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012890
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012891 if (strtol((char *)cp, (char **)&end, 10) <= 0)
12892 {
12893 if (cp != end)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012894 emsg(_(e_positive));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012895 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012896 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012897 return FALSE;
12898 }
12899 }
12900
12901 if (VIM_ISDIGIT(*cp))
12902 continue;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012903 if (cp[0] == ',' && cp > var && cp[-1] != ',' && cp[1] != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012904 {
12905 ++valcount;
12906 continue;
12907 }
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012908 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012909 return FALSE;
12910 }
12911
Bram Moolenaarc799fe22019-05-28 23:08:19 +020012912 *array = ALLOC_MULT(int, valcount + 1);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010012913 if (*array == NULL)
12914 return FALSE;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012915 (*array)[0] = valcount;
12916
12917 t = 1;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012918 for (cp = var; *cp != NUL;)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012919 {
12920 (*array)[t++] = atoi((char *)cp);
Bram Moolenaar64f41072018-10-15 22:51:50 +020012921 while (*cp != NUL && *cp != ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012922 ++cp;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012923 if (*cp != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012924 ++cp;
12925 }
12926
12927 return TRUE;
12928}
12929
12930/*
12931 * Calculate the number of screen spaces a tab will occupy.
12932 * If "vts" is set then the tab widths are taken from that array,
12933 * otherwise the value of ts is used.
12934 */
12935 int
12936tabstop_padding(colnr_T col, int ts_arg, int *vts)
12937{
12938 int ts = ts_arg == 0 ? 8 : ts_arg;
12939 int tabcount;
12940 colnr_T tabcol = 0;
12941 int t;
12942 int padding = 0;
12943
12944 if (vts == NULL || vts[0] == 0)
12945 return ts - (col % ts);
12946
12947 tabcount = vts[0];
12948
12949 for (t = 1; t <= tabcount; ++t)
12950 {
12951 tabcol += vts[t];
12952 if (tabcol > col)
12953 {
12954 padding = (int)(tabcol - col);
12955 break;
12956 }
12957 }
12958 if (t > tabcount)
12959 padding = vts[tabcount] - (int)((col - tabcol) % vts[tabcount]);
12960
12961 return padding;
12962}
12963
12964/*
12965 * Find the size of the tab that covers a particular column.
12966 */
12967 int
12968tabstop_at(colnr_T col, int ts, int *vts)
12969{
12970 int tabcount;
12971 colnr_T tabcol = 0;
12972 int t;
12973 int tab_size = 0;
12974
12975 if (vts == 0 || vts[0] == 0)
12976 return ts;
12977
12978 tabcount = vts[0];
12979 for (t = 1; t <= tabcount; ++t)
12980 {
12981 tabcol += vts[t];
12982 if (tabcol > col)
12983 {
12984 tab_size = vts[t];
12985 break;
12986 }
12987 }
12988 if (t > tabcount)
12989 tab_size = vts[tabcount];
12990
12991 return tab_size;
12992}
12993
12994/*
12995 * Find the column on which a tab starts.
12996 */
12997 colnr_T
12998tabstop_start(colnr_T col, int ts, int *vts)
12999{
13000 int tabcount;
13001 colnr_T tabcol = 0;
13002 int t;
13003 int excess;
13004
Bram Moolenaar0119a592018-06-24 23:53:28 +020013005 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013006 return (col / ts) * ts;
13007
13008 tabcount = vts[0];
13009 for (t = 1; t <= tabcount; ++t)
13010 {
13011 tabcol += vts[t];
13012 if (tabcol > col)
13013 return tabcol - vts[t];
13014 }
13015
13016 excess = tabcol % vts[tabcount];
13017 return excess + ((col - excess) / vts[tabcount]) * vts[tabcount];
13018}
13019
13020/*
13021 * Find the number of tabs and spaces necessary to get from one column
13022 * to another.
13023 */
13024 void
13025tabstop_fromto(
13026 colnr_T start_col,
13027 colnr_T end_col,
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013028 int ts_arg,
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013029 int *vts,
13030 int *ntabs,
13031 int *nspcs)
13032{
13033 int spaces = end_col - start_col;
13034 colnr_T tabcol = 0;
13035 int padding = 0;
13036 int tabcount;
13037 int t;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013038 int ts = ts_arg == 0 ? curbuf->b_p_ts : ts_arg;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013039
Bram Moolenaar0119a592018-06-24 23:53:28 +020013040 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013041 {
13042 int tabs = 0;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013043 int initspc = 0;
Bram Moolenaar0119a592018-06-24 23:53:28 +020013044
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013045 initspc = ts - (start_col % ts);
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013046 if (spaces >= initspc)
13047 {
13048 spaces -= initspc;
13049 tabs++;
13050 }
13051 tabs += spaces / ts;
13052 spaces -= (spaces / ts) * ts;
13053
13054 *ntabs = tabs;
13055 *nspcs = spaces;
13056 return;
13057 }
13058
13059 /* Find the padding needed to reach the next tabstop. */
13060 tabcount = vts[0];
13061 for (t = 1; t <= tabcount; ++t)
13062 {
13063 tabcol += vts[t];
13064 if (tabcol > start_col)
13065 {
13066 padding = (int)(tabcol - start_col);
13067 break;
13068 }
13069 }
13070 if (t > tabcount)
13071 padding = vts[tabcount] - (int)((start_col - tabcol) % vts[tabcount]);
13072
13073 /* If the space needed is less than the padding no tabs can be used. */
13074 if (spaces < padding)
13075 {
13076 *ntabs = 0;
13077 *nspcs = spaces;
13078 return;
13079 }
13080
13081 *ntabs = 1;
13082 spaces -= padding;
13083
13084 /* At least one tab has been used. See if any more will fit. */
13085 while (spaces != 0 && ++t <= tabcount)
13086 {
13087 padding = vts[t];
13088 if (spaces < padding)
13089 {
13090 *nspcs = spaces;
13091 return;
13092 }
13093 ++*ntabs;
13094 spaces -= padding;
13095 }
13096
13097 *ntabs += spaces / vts[tabcount];
13098 *nspcs = spaces % vts[tabcount];
13099}
13100
13101/*
13102 * See if two tabstop arrays contain the same values.
13103 */
13104 int
13105tabstop_eq(int *ts1, int *ts2)
13106{
13107 int t;
13108
13109 if ((ts1 == 0 && ts2) || (ts1 && ts2 == 0))
13110 return FALSE;
13111 if (ts1 == ts2)
13112 return TRUE;
13113 if (ts1[0] != ts2[0])
13114 return FALSE;
13115
13116 for (t = 1; t <= ts1[0]; ++t)
13117 if (ts1[t] != ts2[t])
13118 return FALSE;
13119
13120 return TRUE;
13121}
13122
Bram Moolenaar113e1072019-01-20 15:30:40 +010013123#if defined(FEAT_BEVAL) || defined(PROTO)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013124/*
13125 * Copy a tabstop array, allocating space for the new array.
13126 */
13127 int *
13128tabstop_copy(int *oldts)
13129{
13130 int *newts;
13131 int t;
13132
Bram Moolenaar6ee96582019-04-27 22:06:37 +020013133 if (oldts == NULL)
13134 return NULL;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020013135 newts = ALLOC_MULT(int, oldts[0] + 1);
Bram Moolenaar6ee96582019-04-27 22:06:37 +020013136 if (newts != NULL)
13137 for (t = 0; t <= oldts[0]; ++t)
13138 newts[t] = oldts[t];
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013139 return newts;
13140}
Bram Moolenaar113e1072019-01-20 15:30:40 +010013141#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013142
13143/*
13144 * Return a count of the number of tabstops.
13145 */
13146 int
13147tabstop_count(int *ts)
13148{
13149 return ts != NULL ? ts[0] : 0;
13150}
13151
13152/*
13153 * Return the first tabstop, or 8 if there are no tabstops defined.
13154 */
13155 int
13156tabstop_first(int *ts)
13157{
13158 return ts != NULL ? ts[1] : 8;
13159}
13160
13161#endif
13162
Bram Moolenaar14f24742012-08-08 18:01:05 +020013163/*
13164 * Return the effective shiftwidth value for current buffer, using the
13165 * 'tabstop' value when 'shiftwidth' is zero.
13166 */
13167 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013168get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020013169{
Bram Moolenaarf9514162018-11-22 03:08:29 +010013170 return get_sw_value_col(buf, 0);
13171}
13172
13173/*
13174 * Idem, using the first non-black in the current line.
13175 */
13176 long
13177get_sw_value_indent(buf_T *buf)
13178{
13179 pos_T pos = curwin->w_cursor;
13180
13181 pos.col = getwhitecols_curline();
13182 return get_sw_value_pos(buf, &pos);
13183}
13184
13185/*
13186 * Idem, using "pos".
13187 */
13188 long
13189get_sw_value_pos(buf_T *buf, pos_T *pos)
13190{
13191 pos_T save_cursor = curwin->w_cursor;
13192 long sw_value;
13193
13194 curwin->w_cursor = *pos;
13195 sw_value = get_sw_value_col(buf, get_nolist_virtcol());
13196 curwin->w_cursor = save_cursor;
13197 return sw_value;
13198}
13199
13200/*
13201 * Idem, using virtual column "col".
13202 */
13203 long
13204get_sw_value_col(buf_T *buf, colnr_T col UNUSED)
13205{
13206 return buf->b_p_sw ? buf->b_p_sw :
13207 #ifdef FEAT_VARTABS
13208 tabstop_at(col, buf->b_p_ts, buf->b_p_vts_array);
13209 #else
13210 buf->b_p_ts;
13211 #endif
Bram Moolenaar14f24742012-08-08 18:01:05 +020013212}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013213
13214/*
13215 * Return the effective softtabstop value for the current buffer, using the
Bram Moolenaar33d5ab32018-07-02 20:51:24 +020013216 * 'shiftwidth' value when 'softtabstop' is negative.
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013217 */
13218 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013219get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013220{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010013221 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013222}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013223
13224/*
Bram Moolenaar375e3392019-01-31 18:26:10 +010013225 * Return the effective 'scrolloff' value for the current window, using the
13226 * global value when appropriate.
13227 */
13228 long
13229get_scrolloff_value(void)
13230{
13231 return curwin->w_p_so < 0 ? p_so : curwin->w_p_so;
13232}
13233
13234/*
13235 * Return the effective 'sidescrolloff' value for the current window, using the
13236 * global value when appropriate.
13237 */
13238 long
13239get_sidescrolloff_value(void)
13240{
13241 return curwin->w_p_siso < 0 ? p_siso : curwin->w_p_siso;
13242}
13243
13244/*
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013245 * Check matchpairs option for "*initc".
13246 * If there is a match set "*initc" to the matching character and "*findc" to
13247 * the opposite character. Set "*backwards" to the direction.
13248 * When "switchit" is TRUE swap the direction.
13249 */
13250 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010013251find_mps_values(
13252 int *initc,
13253 int *findc,
13254 int *backwards,
13255 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013256{
13257 char_u *ptr;
13258
13259 ptr = curbuf->b_p_mps;
13260 while (*ptr != NUL)
13261 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013262 if (has_mbyte)
13263 {
13264 char_u *prev;
13265
13266 if (mb_ptr2char(ptr) == *initc)
13267 {
13268 if (switchit)
13269 {
13270 *findc = *initc;
13271 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13272 *backwards = TRUE;
13273 }
13274 else
13275 {
13276 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13277 *backwards = FALSE;
13278 }
13279 return;
13280 }
13281 prev = ptr;
13282 ptr += mb_ptr2len(ptr) + 1;
13283 if (mb_ptr2char(ptr) == *initc)
13284 {
13285 if (switchit)
13286 {
13287 *findc = *initc;
13288 *initc = mb_ptr2char(prev);
13289 *backwards = FALSE;
13290 }
13291 else
13292 {
13293 *findc = mb_ptr2char(prev);
13294 *backwards = TRUE;
13295 }
13296 return;
13297 }
13298 ptr += mb_ptr2len(ptr);
13299 }
13300 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013301 {
13302 if (*ptr == *initc)
13303 {
13304 if (switchit)
13305 {
13306 *backwards = TRUE;
13307 *findc = *initc;
13308 *initc = ptr[2];
13309 }
13310 else
13311 {
13312 *backwards = FALSE;
13313 *findc = ptr[2];
13314 }
13315 return;
13316 }
13317 ptr += 2;
13318 if (*ptr == *initc)
13319 {
13320 if (switchit)
13321 {
13322 *backwards = FALSE;
13323 *findc = *initc;
13324 *initc = ptr[-2];
13325 }
13326 else
13327 {
13328 *backwards = TRUE;
13329 *findc = ptr[-2];
13330 }
13331 return;
13332 }
13333 ++ptr;
13334 }
13335 if (*ptr == ',')
13336 ++ptr;
13337 }
13338}
Bram Moolenaar597a4222014-06-25 14:39:50 +020013339
13340#if defined(FEAT_LINEBREAK) || defined(PROTO)
13341/*
13342 * This is called when 'breakindentopt' is changed and when a window is
13343 * initialized.
13344 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013345 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013346briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020013347{
13348 char_u *p;
13349 int bri_shift = 0;
13350 long bri_min = 20;
13351 int bri_sbr = FALSE;
13352
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013353 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013354 while (*p != NUL)
13355 {
13356 if (STRNCMP(p, "shift:", 6) == 0
13357 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
13358 {
13359 p += 6;
13360 bri_shift = getdigits(&p);
13361 }
13362 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
13363 {
13364 p += 4;
13365 bri_min = getdigits(&p);
13366 }
13367 else if (STRNCMP(p, "sbr", 3) == 0)
13368 {
13369 p += 3;
13370 bri_sbr = TRUE;
13371 }
13372 if (*p != ',' && *p != NUL)
13373 return FAIL;
13374 if (*p == ',')
13375 ++p;
13376 }
13377
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013378 wp->w_p_brishift = bri_shift;
13379 wp->w_p_brimin = bri_min;
13380 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013381
13382 return OK;
13383}
13384#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013385
13386/*
13387 * Get the local or global value of 'backupcopy'.
13388 */
13389 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013390get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013391{
13392 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
13393}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020013394
13395#if defined(FEAT_SIGNS) || defined(PROTO)
13396/*
13397 * Return TRUE when window "wp" has a column to draw signs in.
13398 */
13399 int
13400signcolumn_on(win_T *wp)
13401{
13402 if (*wp->w_p_scl == 'n')
13403 return FALSE;
13404 if (*wp->w_p_scl == 'y')
13405 return TRUE;
13406 return (wp->w_buffer->b_signlist != NULL
13407# ifdef FEAT_NETBEANS_INTG
13408 || wp->w_buffer->b_has_sign_column
13409# endif
13410 );
13411}
13412#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013413
13414#if defined(FEAT_EVAL) || defined(PROTO)
13415/*
13416 * Get window or buffer local options.
13417 */
13418 dict_T *
13419get_winbuf_options(int bufopt)
13420{
13421 dict_T *d;
13422 int opt_idx;
13423
13424 d = dict_alloc();
13425 if (d == NULL)
13426 return NULL;
13427
13428 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
13429 {
13430 struct vimoption *opt = &options[opt_idx];
13431
13432 if ((bufopt && (opt->indir & PV_BUF))
13433 || (!bufopt && (opt->indir & PV_WIN)))
13434 {
13435 char_u *varp = get_varp(opt);
13436
13437 if (varp != NULL)
13438 {
13439 if (opt->flags & P_STRING)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013440 dict_add_string(d, opt->fullname, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020013441 else if (opt->flags & P_NUM)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013442 dict_add_number(d, opt->fullname, *(long *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013443 else
Bram Moolenaare0be1672018-07-08 16:50:37 +020013444 dict_add_number(d, opt->fullname, *(int *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013445 }
13446 }
13447 }
13448
13449 return d;
13450}
13451#endif