blob: abbbaa5873433596f1cfb6f24074816016d2e86f [file] [log] [blame]
Bram Moolenaaredf3f972016-08-29 22:49:24 +02001/* vi:set ts=8 sts=4 sw=4 noet:
Bram Moolenaar071d4272004-06-13 20:20:40 +00002 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * Code to handle user-settable options. This is all pretty much table-
12 * driven. Checklist for adding a new option:
13 * - Put it in the options array below (copy an existing entry).
14 * - For a global option: Add a variable for it in option.h.
15 * - For a buffer or window local option:
16 * - Add a PV_XX entry to the enum below.
17 * - Add a variable to the window or buffer struct in structs.h.
18 * - For a window option, add some code to copy_winopt().
19 * - For a buffer option, add some code to buf_copy_options().
20 * - For a buffer string option, add code to check_buf_options().
21 * - If it's a numeric option, add any necessary bounds checks to do_set().
22 * - If it's a list of flags, add some code in do_set(), search for WW_ALL.
23 * - When adding an option with expansion (P_EXPAND), but with a different
24 * default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP.
Bram Moolenaarcea912a2016-10-12 14:20:24 +020025 * - Add documentation! One line in doc/quickref.txt, full description in
Bram Moolenaar071d4272004-06-13 20:20:40 +000026 * options.txt, and any other related places.
27 * - Add an entry in runtime/optwin.vim.
28 * When making changes:
29 * - Adjust the help for the option in doc/option.txt.
30 * - When an entry has the P_VIM flag, or is lacking the P_VI_DEF flag, add a
31 * comment at the help for the 'compatible' option.
32 */
33
34#define IN_OPTION_C
35#include "vim.h"
36
37/*
38 * The options that are local to a window or buffer have "indir" set to one of
39 * these values. Special values:
40 * PV_NONE: global option.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000041 * PV_WIN is added: window-local option
42 * PV_BUF is added: buffer-local option
Bram Moolenaar071d4272004-06-13 20:20:40 +000043 * PV_BOTH is added: global option which also has a local value.
44 */
45#define PV_BOTH 0x1000
Bram Moolenaara23ccb82006-02-27 00:08:02 +000046#define PV_WIN 0x2000
47#define PV_BUF 0x4000
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000048#define PV_MASK 0x0fff
Bram Moolenaara23ccb82006-02-27 00:08:02 +000049#define OPT_WIN(x) (idopt_T)(PV_WIN + (int)(x))
50#define OPT_BUF(x) (idopt_T)(PV_BUF + (int)(x))
Bram Moolenaar071d4272004-06-13 20:20:40 +000051#define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
52
Bram Moolenaara23ccb82006-02-27 00:08:02 +000053/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000054 * Definition of the PV_ values for buffer-local options.
55 * The BV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000056 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +000057#define PV_AI OPT_BUF(BV_AI)
58#define PV_AR OPT_BOTH(OPT_BUF(BV_AR))
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020059#define PV_BKC OPT_BOTH(OPT_BUF(BV_BKC))
Bram Moolenaar81bdd6a2017-07-23 22:57:00 +020060#define PV_BH OPT_BUF(BV_BH)
61#define PV_BT OPT_BUF(BV_BT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000062#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000063# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
64# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
65# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000066#endif
67#define PV_BIN OPT_BUF(BV_BIN)
68#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaarfc3abf42019-01-24 15:54:21 +010069#define PV_BOMB OPT_BUF(BV_BOMB)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000070#define PV_CI OPT_BUF(BV_CI)
71#ifdef FEAT_CINDENT
72# define PV_CIN OPT_BUF(BV_CIN)
73# define PV_CINK OPT_BUF(BV_CINK)
74# define PV_CINO OPT_BUF(BV_CINO)
75#endif
76#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
77# define PV_CINW OPT_BUF(BV_CINW)
78#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020079#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000080#ifdef FEAT_FOLDING
81# define PV_CMS OPT_BUF(BV_CMS)
82#endif
83#ifdef FEAT_COMMENTS
84# define PV_COM OPT_BUF(BV_COM)
85#endif
86#ifdef FEAT_INS_EXPAND
87# define PV_CPT OPT_BUF(BV_CPT)
88# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
89# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
90#endif
91#ifdef FEAT_COMPL_FUNC
92# define PV_CFU OPT_BUF(BV_CFU)
93#endif
94#ifdef FEAT_FIND_ID
95# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
96# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
97#endif
98#define PV_EOL OPT_BUF(BV_EOL)
Bram Moolenaar34d72d42015-07-17 14:18:08 +020099#define PV_FIXEOL OPT_BUF(BV_FIXEOL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000100#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
101#define PV_ET OPT_BUF(BV_ET)
Bram Moolenaarfc3abf42019-01-24 15:54:21 +0100102#define PV_FENC OPT_BUF(BV_FENC)
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000103#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
104# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
105#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100106#define PV_FP OPT_BOTH(OPT_BUF(BV_FP))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000107#ifdef FEAT_EVAL
108# define PV_FEX OPT_BUF(BV_FEX)
109#endif
110#define PV_FF OPT_BUF(BV_FF)
111#define PV_FLP OPT_BUF(BV_FLP)
112#define PV_FO OPT_BUF(BV_FO)
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +0100113#define PV_FT OPT_BUF(BV_FT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000114#define PV_IMI OPT_BUF(BV_IMI)
115#define PV_IMS OPT_BUF(BV_IMS)
116#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
117# define PV_INDE OPT_BUF(BV_INDE)
118# define PV_INDK OPT_BUF(BV_INDK)
119#endif
120#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
121# define PV_INEX OPT_BUF(BV_INEX)
122#endif
123#define PV_INF OPT_BUF(BV_INF)
124#define PV_ISK OPT_BUF(BV_ISK)
125#ifdef FEAT_CRYPT
126# define PV_KEY OPT_BUF(BV_KEY)
127#endif
128#ifdef FEAT_KEYMAP
129# define PV_KMAP OPT_BUF(BV_KMAP)
130#endif
131#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
132#ifdef FEAT_LISP
133# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100134# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000135#endif
Bram Moolenaarfc3abf42019-01-24 15:54:21 +0100136#define PV_MENC OPT_BOTH(OPT_BUF(BV_MENC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000137#define PV_MA OPT_BUF(BV_MA)
138#define PV_ML OPT_BUF(BV_ML)
139#define PV_MOD OPT_BUF(BV_MOD)
140#define PV_MPS OPT_BUF(BV_MPS)
141#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000142#ifdef FEAT_COMPL_FUNC
143# define PV_OFU OPT_BUF(BV_OFU)
144#endif
145#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
146#define PV_PI OPT_BUF(BV_PI)
147#ifdef FEAT_TEXTOBJ
148# define PV_QE OPT_BUF(BV_QE)
149#endif
150#define PV_RO OPT_BUF(BV_RO)
151#ifdef FEAT_SMARTINDENT
152# define PV_SI OPT_BUF(BV_SI)
153#endif
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100154#define PV_SN OPT_BUF(BV_SN)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000155#ifdef FEAT_SYN_HL
156# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000157# define PV_SYN OPT_BUF(BV_SYN)
158#endif
159#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000160# define PV_SPC OPT_BUF(BV_SPC)
161# define PV_SPF OPT_BUF(BV_SPF)
162# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000163#endif
164#define PV_STS OPT_BUF(BV_STS)
165#ifdef FEAT_SEARCHPATH
166# define PV_SUA OPT_BUF(BV_SUA)
167#endif
168#define PV_SW OPT_BUF(BV_SW)
169#define PV_SWF OPT_BUF(BV_SWF)
170#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
Bram Moolenaar0f6562e2015-11-24 18:48:14 +0100171#define PV_TC OPT_BOTH(OPT_BUF(BV_TC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000172#define PV_TS OPT_BUF(BV_TS)
173#define PV_TW OPT_BUF(BV_TW)
174#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200175#ifdef FEAT_PERSISTENT_UNDO
176# define PV_UDF OPT_BUF(BV_UDF)
177#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000178#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200179#ifdef FEAT_VARTABS
180# define PV_VSTS OPT_BUF(BV_VSTS)
181# define PV_VTS OPT_BUF(BV_VTS)
182#endif
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000183
184/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000185 * Definition of the PV_ values for window-local options.
186 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000187 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000188#define PV_LIST OPT_WIN(WV_LIST)
189#ifdef FEAT_ARABIC
190# define PV_ARAB OPT_WIN(WV_ARAB)
191#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200192#ifdef FEAT_LINEBREAK
193# define PV_BRI OPT_WIN(WV_BRI)
194# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
195#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000196#ifdef FEAT_DIFF
197# define PV_DIFF OPT_WIN(WV_DIFF)
198#endif
199#ifdef FEAT_FOLDING
200# define PV_FDC OPT_WIN(WV_FDC)
201# define PV_FEN OPT_WIN(WV_FEN)
202# define PV_FDI OPT_WIN(WV_FDI)
203# define PV_FDL OPT_WIN(WV_FDL)
204# define PV_FDM OPT_WIN(WV_FDM)
205# define PV_FML OPT_WIN(WV_FML)
206# define PV_FDN OPT_WIN(WV_FDN)
207# ifdef FEAT_EVAL
208# define PV_FDE OPT_WIN(WV_FDE)
209# define PV_FDT OPT_WIN(WV_FDT)
210# endif
211# define PV_FMR OPT_WIN(WV_FMR)
212#endif
213#ifdef FEAT_LINEBREAK
214# define PV_LBR OPT_WIN(WV_LBR)
215#endif
216#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200217#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000218#ifdef FEAT_LINEBREAK
219# define PV_NUW OPT_WIN(WV_NUW)
220#endif
Bram Moolenaar4033c552017-09-16 20:54:51 +0200221#if defined(FEAT_QUICKFIX)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000222# define PV_PVW OPT_WIN(WV_PVW)
223#endif
224#ifdef FEAT_RIGHTLEFT
225# define PV_RL OPT_WIN(WV_RL)
226# define PV_RLC OPT_WIN(WV_RLC)
227#endif
Bram Moolenaar8a3bb562018-03-04 20:14:14 +0100228#define PV_SCBIND OPT_WIN(WV_SCBIND)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000229#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000230#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000231# define PV_SPELL OPT_WIN(WV_SPELL)
232#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000233#ifdef FEAT_SYN_HL
234# define PV_CUC OPT_WIN(WV_CUC)
235# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200236# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000237#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000238#ifdef FEAT_STL_OPT
239# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
240#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100241#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000242# define PV_WFH OPT_WIN(WV_WFH)
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000243# define PV_WFW OPT_WIN(WV_WFW)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000244#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar8a3bb562018-03-04 20:14:14 +0100245#define PV_CRBIND OPT_WIN(WV_CRBIND)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200246#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200247# define PV_COCU OPT_WIN(WV_COCU)
248# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200249#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200250#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200251# define PV_TWK OPT_WIN(WV_TWK)
252# define PV_TWS OPT_WIN(WV_TWS)
253# define PV_TWSL OPT_BUF(BV_TWSL)
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200254#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200255#ifdef FEAT_SIGNS
256# define PV_SCL OPT_WIN(WV_SCL)
257#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000258
259/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000260typedef enum
261{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000262 PV_NONE = 0,
263 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000264} idopt_T;
265
266/*
267 * Options local to a window have a value local to a buffer and global to all
268 * buffers. Indicate this by setting "var" to VAR_WIN.
269 */
270#define VAR_WIN ((char_u *)-1)
271
272/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000273 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000274 * Only to be used in option.c!
275 */
276static int p_ai;
277static int p_bin;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000278static int p_bomb;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000279static char_u *p_bh;
280static char_u *p_bt;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000281static int p_bl;
282static int p_ci;
283#ifdef FEAT_CINDENT
284static int p_cin;
285static char_u *p_cink;
286static char_u *p_cino;
287#endif
288#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
289static char_u *p_cinw;
290#endif
291#ifdef FEAT_COMMENTS
292static char_u *p_com;
293#endif
294#ifdef FEAT_FOLDING
295static char_u *p_cms;
296#endif
297#ifdef FEAT_INS_EXPAND
298static char_u *p_cpt;
299#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000300#ifdef FEAT_COMPL_FUNC
301static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000302static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000303#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000304static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200305static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000306static int p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000307static char_u *p_fenc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000308static char_u *p_ff;
309static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000310static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000311static char_u *p_ft;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000312static long p_iminsert;
313static long p_imsearch;
314#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
315static char_u *p_inex;
316#endif
317#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
318static char_u *p_inde;
319static char_u *p_indk;
320#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000321#if defined(FEAT_EVAL)
322static char_u *p_fex;
323#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000324static int p_inf;
325static char_u *p_isk;
326#ifdef FEAT_CRYPT
327static char_u *p_key;
328#endif
329#ifdef FEAT_LISP
330static int p_lisp;
331#endif
332static int p_ml;
333static int p_ma;
334static int p_mod;
335static char_u *p_mps;
336static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000337static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000338#ifdef FEAT_TEXTOBJ
339static char_u *p_qe;
340#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000341static int p_ro;
342#ifdef FEAT_SMARTINDENT
343static int p_si;
344#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000345static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000346static long p_sts;
347#if defined(FEAT_SEARCHPATH)
348static char_u *p_sua;
349#endif
350static long p_sw;
351static int p_swf;
352#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000353static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000354static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000355#endif
356#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000357static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000358static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000359static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000360#endif
361static long p_ts;
362static long p_tw;
363static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200364#ifdef FEAT_PERSISTENT_UNDO
365static int p_udf;
366#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000367static long p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200368#ifdef FEAT_VARTABS
369static char_u *p_vsts;
370static char_u *p_vts;
371#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000372#ifdef FEAT_KEYMAP
373static char_u *p_keymap;
374#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200375#ifdef FEAT_TERMINAL
Bram Moolenaarb833c1e2018-05-05 16:36:06 +0200376static long p_twsl; /* 'termwinscroll' */
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200377#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000378
379/* Saved values for when 'bin' is set. */
380static int p_et_nobin;
381static int p_ml_nobin;
382static long p_tw_nobin;
383static long p_wm_nobin;
384
385/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200386static int p_ai_nopaste;
387static int p_et_nopaste;
388static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000389static long p_tw_nopaste;
390static long p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200391#ifdef FEAT_VARTABS
392static char_u *p_vsts_nopaste;
393#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000394
395struct vimoption
396{
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200397 char *fullname; // full option name
398 char *shortname; // permissible abbreviation
399 long_u flags; // see below
400 char_u *var; // global option: pointer to variable;
401 // window-local option: VAR_WIN;
402 // buffer-local option: global value
403 idopt_T indir; // global option: PV_NONE;
404 // local option: indirect option index
405 char_u *def_val[2]; // default values for variable (vi and vim)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000406#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200407 sctx_T script_ctx; // script context where the option was last set
Bram Moolenaarded5f1b2018-11-10 17:33:29 +0100408# define SCTX_INIT , {0, 0, 0}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000409#else
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200410# define SCTX_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000411#endif
412};
413
414#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
415#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
416
417/*
418 * Flags
419 */
420#define P_BOOL 0x01 /* the option is boolean */
421#define P_NUM 0x02 /* the option is numeric */
422#define P_STRING 0x04 /* the option is a string */
423#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000424 must use free_string_option() when
425 assigning new value. Not set if default is
426 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000427#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
428 never be used for local or hidden options! */
429#define P_NODEFAULT 0x40 /* don't set to default value */
430#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
431 use vim_free() when assigning new value */
432#define P_WAS_SET 0x100 /* option has been set/reset */
433#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
434#define P_VI_DEF 0x400 /* Use Vi default for Vim */
435#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
436
437 /* when option changed, what to display: */
438#define P_RSTAT 0x1000 /* redraw status lines */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100439#define P_RWIN 0x2000 /* redraw current window and recompute text */
440#define P_RBUF 0x4000 /* redraw current buffer and recompute text */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000441#define P_RALL 0x6000 /* redraw all windows */
442#define P_RCLR 0x7000 /* clear and redraw all */
443
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200444#define P_COMMA 0x8000 /* comma separated list */
445#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
446 * commas */
447#define P_NODUP 0x20000L /* don't allow duplicate strings */
448#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000449
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200450#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
451#define P_GETTEXT 0x100000L /* expand default value with _() */
452#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
453#define P_NFNAME 0x400000L /* only normal file name chars allowed */
454#define P_INSECURE 0x800000L /* option was set from a modeline */
455#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7554da42016-11-25 22:04:13 +0100456 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200457#define P_NO_ML 0x2000000L /* not allowed in modeline */
458#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200459 * there is a redraw flag */
Bram Moolenaar7554da42016-11-25 22:04:13 +0100460#define P_NDNAME 0x8000000L /* only normal dir name chars allowed */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100461#define P_RWINONLY 0x10000000L /* only redraw current window */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000462
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000463#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
464
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000465/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
466 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100467#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000468# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000469#else
470# define ISP_LATIN1 (char_u *)"@,161-255"
471#endif
472
Bram Moolenaar05fbfdc2017-08-14 22:35:08 +0200473# 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 +0000474
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +0100475/* Default python version for pyx* commands */
476#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
477# define DEFAULT_PYTHON_VER 0
478#elif defined(FEAT_PYTHON3)
479# define DEFAULT_PYTHON_VER 3
480#elif defined(FEAT_PYTHON)
481# define DEFAULT_PYTHON_VER 2
482#else
483# define DEFAULT_PYTHON_VER 0
484#endif
485
Bram Moolenaarce655742019-01-31 14:12:57 +0100486// used for 'cinkeys' and 'indentkeys'
487#define INDENTKEYS_DEFAULT (char_u *)"0{,0},0),0],:,0#,!^F,o,O,e"
488
Bram Moolenaar071d4272004-06-13 20:20:40 +0000489/*
490 * options[] is initialized here.
491 * The order of the options MUST be alphabetic for ":set all" and findoption().
492 * All option names MUST start with a lowercase letter (for findoption()).
493 * Exception: "t_" options are at the end.
494 * The options with a NULL variable are 'hidden': a set command for them is
495 * ignored and they are not printed.
496 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100497static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000498{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200499 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000500#ifdef FEAT_RIGHTLEFT
501 (char_u *)&p_aleph, PV_NONE,
502#else
503 (char_u *)NULL, PV_NONE,
504#endif
505 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100506#if (defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000507 (char_u *)128L,
508#else
509 (char_u *)224L,
510#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200511 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000512 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
Bram Moolenaard0573012017-10-28 21:11:06 +0200513#if defined(FEAT_GUI_MAC)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000514 (char_u *)&p_antialias, PV_NONE,
515 {(char_u *)FALSE, (char_u *)FALSE}
516#else
517 (char_u *)NULL, PV_NONE,
518 {(char_u *)FALSE, (char_u *)FALSE}
519#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200520 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200521 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000522#ifdef FEAT_ARABIC
523 (char_u *)VAR_WIN, PV_ARAB,
524#else
525 (char_u *)NULL, PV_NONE,
526#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200527 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000528 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
529#ifdef FEAT_ARABIC
530 (char_u *)&p_arshape, PV_NONE,
531#else
532 (char_u *)NULL, PV_NONE,
533#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200534 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000535 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
536#ifdef FEAT_RIGHTLEFT
537 (char_u *)&p_ari, PV_NONE,
538#else
539 (char_u *)NULL, PV_NONE,
540#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200541 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000542 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
543#ifdef FEAT_FKMAP
544 (char_u *)&p_altkeymap, PV_NONE,
545#else
546 (char_u *)NULL, PV_NONE,
547#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200548 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000549 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000550 (char_u *)&p_ambw, PV_NONE,
551 {(char_u *)"single", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200552 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000553 {"autochdir", "acd", P_BOOL|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100554#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000555 (char_u *)&p_acd, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100556 {(char_u *)FALSE, (char_u *)0L}
557#else
558 (char_u *)NULL, PV_NONE,
559 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000560#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200561 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000562 {"autoindent", "ai", P_BOOL|P_VI_DEF,
563 (char_u *)&p_ai, PV_AI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200564 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000565 {"autoprint", "ap", P_BOOL|P_VI_DEF,
566 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200567 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000568 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000569 (char_u *)&p_ar, PV_AR,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200570 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000571 {"autowrite", "aw", P_BOOL|P_VI_DEF,
572 (char_u *)&p_aw, 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 {"autowriteall","awa", P_BOOL|P_VI_DEF,
575 (char_u *)&p_awa, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200576 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000577 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
578 (char_u *)&p_bg, PV_NONE,
579 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100580#if (defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000581 (char_u *)"dark",
582#else
583 (char_u *)"light",
584#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200585 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200586 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000587 (char_u *)&p_bs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200588 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000589 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
590 (char_u *)&p_bk, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200591 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200592 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200593 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000594#ifdef UNIX
595 {(char_u *)"yes", (char_u *)"auto"}
596#else
597 {(char_u *)"auto", (char_u *)"auto"}
598#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200599 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200600 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
601 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000602 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200603 {(char_u *)DFLT_BDIR, (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000604 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000605 (char_u *)&p_bex, PV_NONE,
606 {
607#ifdef VMS
608 (char_u *)"_",
609#else
610 (char_u *)"~",
611#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200612 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200613 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000614#ifdef FEAT_WILDIGN
615 (char_u *)&p_bsk, PV_NONE,
616 {(char_u *)"", (char_u *)0L}
617#else
618 (char_u *)NULL, PV_NONE,
619 {(char_u *)0L, (char_u *)0L}
620#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200621 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000622 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100623#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000624 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100625 {(char_u *)600L, (char_u *)0L}
626#else
627 (char_u *)NULL, PV_NONE,
628 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000629#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200630 SCTX_INIT},
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100631 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100632#ifdef FEAT_BEVAL_GUI
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100633 (char_u *)&p_beval, PV_NONE,
634 {(char_u *)FALSE, (char_u *)0L}
635#else
636 (char_u *)NULL, PV_NONE,
637 {(char_u *)0L, (char_u *)0L}
638#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200639 SCTX_INIT},
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100640 {"balloonevalterm", "bevalterm",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100641#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100642 (char_u *)&p_bevalterm, PV_NONE,
643 {(char_u *)FALSE, (char_u *)0L}
644#else
645 (char_u *)NULL, PV_NONE,
646 {(char_u *)0L, (char_u *)0L}
647#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200648 SCTX_INIT},
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100649 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
650#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
651 (char_u *)&p_bexpr, PV_BEXPR,
652 {(char_u *)"", (char_u *)0L}
653#else
654 (char_u *)NULL, PV_NONE,
655 {(char_u *)0L, (char_u *)0L}
656#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200657 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000658 {"beautify", "bf", P_BOOL|P_VI_DEF,
659 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200660 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200661 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
662 (char_u *)&p_bo, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200663 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000664 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
665 (char_u *)&p_bin, PV_BIN,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200666 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000667 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000668 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200669 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000670 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000671 (char_u *)&p_bomb, PV_BOMB,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200672 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000673 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
674#ifdef FEAT_LINEBREAK
675 (char_u *)&p_breakat, PV_NONE,
676 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
677#else
678 (char_u *)NULL, PV_NONE,
679 {(char_u *)0L, (char_u *)0L}
680#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200681 SCTX_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200682 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
683#ifdef FEAT_LINEBREAK
684 (char_u *)VAR_WIN, PV_BRI,
685 {(char_u *)FALSE, (char_u *)0L}
686#else
687 (char_u *)NULL, PV_NONE,
688 {(char_u *)0L, (char_u *)0L}
689#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200690 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200691 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
692 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200693#ifdef FEAT_LINEBREAK
694 (char_u *)VAR_WIN, PV_BRIOPT,
695 {(char_u *)"", (char_u *)NULL}
696#else
697 (char_u *)NULL, PV_NONE,
698 {(char_u *)"", (char_u *)NULL}
699#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200700 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000701 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
702#ifdef FEAT_BROWSE
703 (char_u *)&p_bsdir, PV_NONE,
704 {(char_u *)"last", (char_u *)0L}
705#else
706 (char_u *)NULL, PV_NONE,
707 {(char_u *)0L, (char_u *)0L}
708#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200709 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000710 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000711 (char_u *)&p_bh, PV_BH,
712 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200713 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000714 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
715 (char_u *)&p_bl, PV_BL,
716 {(char_u *)1L, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200717 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000718 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000719 (char_u *)&p_bt, PV_BT,
720 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200721 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200722 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000723 (char_u *)&p_cmp, PV_NONE,
724 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200725 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000726 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
727#ifdef FEAT_SEARCHPATH
728 (char_u *)&p_cdpath, PV_NONE,
729 {(char_u *)",,", (char_u *)0L}
730#else
731 (char_u *)NULL, PV_NONE,
732 {(char_u *)0L, (char_u *)0L}
733#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200734 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000735 {"cedit", NULL, P_STRING,
736#ifdef FEAT_CMDWIN
737 (char_u *)&p_cedit, PV_NONE,
738 {(char_u *)"", (char_u *)CTRL_F_STR}
739#else
740 (char_u *)NULL, PV_NONE,
741 {(char_u *)0L, (char_u *)0L}
742#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200743 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000744 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +0100745#if defined(FEAT_EVAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000746 (char_u *)&p_ccv, PV_NONE,
747 {(char_u *)"", (char_u *)0L}
748#else
749 (char_u *)NULL, PV_NONE,
750 {(char_u *)0L, (char_u *)0L}
751#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200752 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000753 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
754#ifdef FEAT_CINDENT
755 (char_u *)&p_cin, PV_CIN,
756#else
757 (char_u *)NULL, PV_NONE,
758#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200759 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200760 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000761#ifdef FEAT_CINDENT
762 (char_u *)&p_cink, PV_CINK,
Bram Moolenaarce655742019-01-31 14:12:57 +0100763 {INDENTKEYS_DEFAULT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000764#else
765 (char_u *)NULL, PV_NONE,
766 {(char_u *)0L, (char_u *)0L}
767#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200768 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200769 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000770#ifdef FEAT_CINDENT
771 (char_u *)&p_cino, PV_CINO,
772#else
773 (char_u *)NULL, PV_NONE,
774#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200775 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200776 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000777#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
778 (char_u *)&p_cinw, PV_CINW,
779 {(char_u *)"if,else,while,do,for,switch",
780 (char_u *)0L}
781#else
782 (char_u *)NULL, PV_NONE,
783 {(char_u *)0L, (char_u *)0L}
784#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200785 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200786 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000787#ifdef FEAT_CLIPBOARD
788 (char_u *)&p_cb, PV_NONE,
789# ifdef FEAT_XCLIPBOARD
790 {(char_u *)"autoselect,exclude:cons\\|linux",
791 (char_u *)0L}
792# else
793 {(char_u *)"", (char_u *)0L}
794# endif
795#else
796 (char_u *)NULL, PV_NONE,
797 {(char_u *)"", (char_u *)0L}
798#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200799 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000800 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
801 (char_u *)&p_ch, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200802 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000803 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
804#ifdef FEAT_CMDWIN
805 (char_u *)&p_cwh, PV_NONE,
806#else
807 (char_u *)NULL, PV_NONE,
808#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200809 {(char_u *)7L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200810 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200811#ifdef FEAT_SYN_HL
812 (char_u *)VAR_WIN, PV_CC,
813#else
814 (char_u *)NULL, PV_NONE,
815#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200816 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000817 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
818 (char_u *)&Columns, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200819 {(char_u *)80L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200820 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
821 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000822#ifdef FEAT_COMMENTS
823 (char_u *)&p_com, PV_COM,
824 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
825 (char_u *)0L}
826#else
827 (char_u *)NULL, PV_NONE,
828 {(char_u *)0L, (char_u *)0L}
829#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200830 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200831 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000832#ifdef FEAT_FOLDING
833 (char_u *)&p_cms, PV_CMS,
834 {(char_u *)"/*%s*/", (char_u *)0L}
835#else
836 (char_u *)NULL, PV_NONE,
837 {(char_u *)0L, (char_u *)0L}
838#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200839 SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000840 /* P_PRI_MKRC isn't needed here, optval_default()
841 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000842 {"compatible", "cp", P_BOOL|P_RALL,
843 (char_u *)&p_cp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200844 {(char_u *)TRUE, (char_u *)FALSE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200845 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000846#ifdef FEAT_INS_EXPAND
847 (char_u *)&p_cpt, PV_CPT,
848 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
849#else
850 (char_u *)NULL, PV_NONE,
851 {(char_u *)0L, (char_u *)0L}
852#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200853 SCTX_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200854 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200855#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200856 (char_u *)VAR_WIN, PV_COCU,
857 {(char_u *)"", (char_u *)NULL}
858#else
859 (char_u *)NULL, PV_NONE,
860 {(char_u *)NULL, (char_u *)0L}
861#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200862 SCTX_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200863 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
864#ifdef FEAT_CONCEAL
865 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200866#else
867 (char_u *)NULL, PV_NONE,
868#endif
869 {(char_u *)0L, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200870 SCTX_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000871 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
872#ifdef FEAT_COMPL_FUNC
873 (char_u *)&p_cfu, PV_CFU,
874 {(char_u *)"", (char_u *)0L}
875#else
876 (char_u *)NULL, PV_NONE,
877 {(char_u *)0L, (char_u *)0L}
878#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200879 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200880 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000881#ifdef FEAT_INS_EXPAND
882 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000883 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000884#else
885 (char_u *)NULL, PV_NONE,
886 {(char_u *)0L, (char_u *)0L}
887#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200888 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000889 {"confirm", "cf", P_BOOL|P_VI_DEF,
890#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
891 (char_u *)&p_confirm, PV_NONE,
892#else
893 (char_u *)NULL, PV_NONE,
894#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200895 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000896 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000897 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200898 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000899 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
900 (char_u *)&p_ci, PV_CI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200901 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000902 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
903 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000904 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200905 SCTX_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200906 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200907#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200908 (char_u *)&p_cm, PV_CM,
Bram Moolenaara86187b2018-12-16 18:20:00 +0100909 {(char_u *)"blowfish2", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200910#else
911 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200912 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200913#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200914 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000915 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
916#ifdef FEAT_CSCOPE
917 (char_u *)&p_cspc, PV_NONE,
918#else
919 (char_u *)NULL, PV_NONE,
920#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200921 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000922 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
923#ifdef FEAT_CSCOPE
924 (char_u *)&p_csprg, PV_NONE,
925 {(char_u *)"cscope", (char_u *)0L}
926#else
927 (char_u *)NULL, PV_NONE,
928 {(char_u *)0L, (char_u *)0L}
929#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200930 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200931 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000932#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
933 (char_u *)&p_csqf, PV_NONE,
934 {(char_u *)"", (char_u *)0L}
935#else
936 (char_u *)NULL, PV_NONE,
937 {(char_u *)0L, (char_u *)0L}
938#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200939 SCTX_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200940 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
941#ifdef FEAT_CSCOPE
942 (char_u *)&p_csre, PV_NONE,
943#else
944 (char_u *)NULL, PV_NONE,
945#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200946 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000947 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
948#ifdef FEAT_CSCOPE
949 (char_u *)&p_cst, PV_NONE,
950#else
951 (char_u *)NULL, PV_NONE,
952#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200953 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000954 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
955#ifdef FEAT_CSCOPE
956 (char_u *)&p_csto, PV_NONE,
957#else
958 (char_u *)NULL, PV_NONE,
959#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200960 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000961 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
962#ifdef FEAT_CSCOPE
963 (char_u *)&p_csverbose, PV_NONE,
964#else
965 (char_u *)NULL, PV_NONE,
966#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200967 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200968 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200969 (char_u *)VAR_WIN, PV_CRBIND,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200970 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar177ab9e2019-01-15 21:12:57 +0100971 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000972#ifdef FEAT_SYN_HL
973 (char_u *)VAR_WIN, PV_CUC,
974#else
975 (char_u *)NULL, PV_NONE,
976#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200977 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100978 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000979#ifdef FEAT_SYN_HL
980 (char_u *)VAR_WIN, PV_CUL,
981#else
982 (char_u *)NULL, PV_NONE,
983#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200984 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000985 {"debug", NULL, P_STRING|P_VI_DEF,
986 (char_u *)&p_debug, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200987 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200988 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000989#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000990 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000991 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000992#else
993 (char_u *)NULL, PV_NONE,
994 {(char_u *)NULL, (char_u *)0L}
995#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200996 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000997 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000998 (char_u *)&p_deco, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200999 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001000 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001001#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001002 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001003#else
1004 (char_u *)NULL, PV_NONE,
1005#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001006 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001007 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1008#ifdef FEAT_DIFF
1009 (char_u *)VAR_WIN, PV_DIFF,
1010#else
1011 (char_u *)NULL, PV_NONE,
1012#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001013 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001014 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001015#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1016 (char_u *)&p_dex, PV_NONE,
1017 {(char_u *)"", (char_u *)0L}
1018#else
1019 (char_u *)NULL, PV_NONE,
1020 {(char_u *)0L, (char_u *)0L}
1021#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001022 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001023 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1024 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001025#ifdef FEAT_DIFF
1026 (char_u *)&p_dip, PV_NONE,
Bram Moolenaarc93262b2018-09-10 21:15:40 +02001027 {(char_u *)"internal,filler", (char_u *)NULL}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001028#else
1029 (char_u *)NULL, PV_NONE,
1030 {(char_u *)"", (char_u *)NULL}
1031#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001032 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001033 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1034#ifdef FEAT_DIGRAPHS
1035 (char_u *)&p_dg, PV_NONE,
1036#else
1037 (char_u *)NULL, PV_NONE,
1038#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001039 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001040 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1041 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001042 (char_u *)&p_dir, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001043 {(char_u *)DFLT_DIR, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001044 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001045 (char_u *)&p_dy, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001046 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001047 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001048 (char_u *)&p_ead, PV_NONE,
1049 {(char_u *)"both", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001050 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001051 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1052 (char_u *)&p_ed, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001053 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001054 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaar3848e002016-03-19 18:42:29 +01001055 (char_u *)&p_emoji, PV_NONE,
1056 {(char_u *)TRUE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001057 SCTX_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001058 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001059 (char_u *)&p_enc, PV_NONE,
1060 {(char_u *)ENC_DFLT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001061 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001062 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1063 (char_u *)&p_eol, PV_EOL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001064 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001065 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1066 (char_u *)&p_ea, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001067 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001068 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001069 (char_u *)&p_ep, PV_EP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001070 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001071 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1072 (char_u *)&p_eb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001073 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001074 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1075#ifdef FEAT_QUICKFIX
1076 (char_u *)&p_ef, PV_NONE,
1077 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1078#else
1079 (char_u *)NULL, PV_NONE,
1080 {(char_u *)NULL, (char_u *)0L}
1081#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001082 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001083 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001084#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001085 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001086 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001087#else
1088 (char_u *)NULL, PV_NONE,
1089 {(char_u *)NULL, (char_u *)0L}
1090#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001091 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001092 {"esckeys", "ek", P_BOOL|P_VIM,
1093 (char_u *)&p_ek, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001094 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001095 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001096 (char_u *)&p_ei, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001097 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001098 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1099 (char_u *)&p_et, PV_ET,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001100 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001101 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1102 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001103 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001104 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1105 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001106 (char_u *)&p_fenc, PV_FENC,
1107 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001108 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001109 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001110 (char_u *)&p_fencs, PV_NONE,
1111 {(char_u *)"ucs-bom", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001112 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001113 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1114 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001115 (char_u *)&p_ff, PV_FF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001116 {(char_u *)DFLT_FF, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001117 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001118 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001119 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001120 SCTX_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001121 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1122 (char_u *)&p_fic, PV_NONE,
1123 {
1124#ifdef CASE_INSENSITIVE_FILENAME
1125 (char_u *)TRUE,
1126#else
1127 (char_u *)FALSE,
1128#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001129 (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001130 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001131 (char_u *)&p_ft, PV_FT,
1132 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001133 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001134 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001135 (char_u *)&p_fcs, PV_NONE,
1136 {(char_u *)"vert:|,fold:-", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001137 SCTX_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001138 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1139 (char_u *)&p_fixeol, PV_FIXEOL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001140 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001141 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1142#ifdef FEAT_FKMAP
1143 (char_u *)&p_fkmap, PV_NONE,
1144#else
1145 (char_u *)NULL, PV_NONE,
1146#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001147 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001148 {"flash", "fl", P_BOOL|P_VI_DEF,
1149 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001150 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001151 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001152#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001153 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001154 {(char_u *)"", (char_u *)0L}
1155#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001156 (char_u *)NULL, PV_NONE,
1157 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001158#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001159 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001160 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1161#ifdef FEAT_FOLDING
1162 (char_u *)VAR_WIN, PV_FDC,
1163 {(char_u *)FALSE, (char_u *)0L}
1164#else
1165 (char_u *)NULL, PV_NONE,
1166 {(char_u *)NULL, (char_u *)0L}
1167#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001168 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001169 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1170#ifdef FEAT_FOLDING
1171 (char_u *)VAR_WIN, PV_FEN,
1172 {(char_u *)TRUE, (char_u *)0L}
1173#else
1174 (char_u *)NULL, PV_NONE,
1175 {(char_u *)NULL, (char_u *)0L}
1176#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001177 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001178 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1179#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1180 (char_u *)VAR_WIN, PV_FDE,
1181 {(char_u *)"0", (char_u *)NULL}
1182#else
1183 (char_u *)NULL, PV_NONE,
1184 {(char_u *)NULL, (char_u *)0L}
1185#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001186 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001187 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001188#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001189 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001190 {(char_u *)"#", (char_u *)NULL}
1191#else
1192 (char_u *)NULL, PV_NONE,
1193 {(char_u *)NULL, (char_u *)0L}
1194#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001195 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001196 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001197#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001198 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001199 {(char_u *)0L, (char_u *)0L}
1200#else
1201 (char_u *)NULL, PV_NONE,
1202 {(char_u *)NULL, (char_u *)0L}
1203#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001204 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001205 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001206#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001207 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001208 {(char_u *)-1L, (char_u *)0L}
1209#else
1210 (char_u *)NULL, PV_NONE,
1211 {(char_u *)NULL, (char_u *)0L}
1212#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001213 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001214 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001215 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001216#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001217 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001218 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001219#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001220 (char_u *)NULL, PV_NONE,
1221 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001222#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001223 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001224 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1225#ifdef FEAT_FOLDING
1226 (char_u *)VAR_WIN, PV_FDM,
1227 {(char_u *)"manual", (char_u *)NULL}
1228#else
1229 (char_u *)NULL, PV_NONE,
1230 {(char_u *)NULL, (char_u *)0L}
1231#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001232 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001233 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1234#ifdef FEAT_FOLDING
1235 (char_u *)VAR_WIN, PV_FML,
1236 {(char_u *)1L, (char_u *)0L}
1237#else
1238 (char_u *)NULL, PV_NONE,
1239 {(char_u *)NULL, (char_u *)0L}
1240#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001241 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001242 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1243#ifdef FEAT_FOLDING
1244 (char_u *)VAR_WIN, PV_FDN,
1245 {(char_u *)20L, (char_u *)0L}
1246#else
1247 (char_u *)NULL, PV_NONE,
1248 {(char_u *)NULL, (char_u *)0L}
1249#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001250 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001251 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1252#ifdef FEAT_FOLDING
1253 (char_u *)&p_fdo, PV_NONE,
1254 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1255 (char_u *)0L}
1256#else
1257 (char_u *)NULL, PV_NONE,
1258 {(char_u *)NULL, (char_u *)0L}
1259#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001260 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001261 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1262#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1263 (char_u *)VAR_WIN, PV_FDT,
1264 {(char_u *)"foldtext()", (char_u *)NULL}
1265#else
1266 (char_u *)NULL, PV_NONE,
1267 {(char_u *)NULL, (char_u *)0L}
1268#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001269 SCTX_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001270 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001271#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001272 (char_u *)&p_fex, PV_FEX,
1273 {(char_u *)"", (char_u *)0L}
1274#else
1275 (char_u *)NULL, PV_NONE,
1276 {(char_u *)0L, (char_u *)0L}
1277#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001278 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001279 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1280 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001281 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001282 SCTX_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001283 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1284 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001285 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001286 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001287 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001288 (char_u *)&p_fp, PV_FP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001289 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001290 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1291#ifdef HAVE_FSYNC
1292 (char_u *)&p_fs, PV_NONE,
1293 {(char_u *)TRUE, (char_u *)0L}
1294#else
1295 (char_u *)NULL, PV_NONE,
1296 {(char_u *)FALSE, (char_u *)0L}
1297#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001298 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001299 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1300 (char_u *)&p_gd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001301 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001302 {"graphic", "gr", P_BOOL|P_VI_DEF,
1303 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001304 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001305 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001306#ifdef FEAT_QUICKFIX
1307 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001308 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001309#else
1310 (char_u *)NULL, PV_NONE,
1311 {(char_u *)NULL, (char_u *)0L}
1312#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001313 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001314 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1315#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001316 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001317 {
1318# ifdef WIN3264
1319 /* may be changed to "grep -n" in os_win32.c */
1320 (char_u *)"findstr /n",
1321# else
1322# ifdef UNIX
1323 /* Add an extra file name so that grep will always
1324 * insert a file name in the match line. */
1325 (char_u *)"grep -n $* /dev/null",
1326# else
1327# ifdef VMS
1328 (char_u *)"SEARCH/NUMBERS ",
1329# else
1330 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001331# endif
1332# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001333# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001334 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001335#else
1336 (char_u *)NULL, PV_NONE,
1337 {(char_u *)NULL, (char_u *)0L}
1338#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001339 SCTX_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001340 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001341#ifdef CURSOR_SHAPE
1342 (char_u *)&p_guicursor, PV_NONE,
1343 {
1344# ifdef FEAT_GUI
1345 (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 +01001346# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001347 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1348# endif
1349 (char_u *)0L}
1350#else
1351 (char_u *)NULL, PV_NONE,
1352 {(char_u *)NULL, (char_u *)0L}
1353#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001354 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001355 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001356#ifdef FEAT_GUI
1357 (char_u *)&p_guifont, PV_NONE,
1358 {(char_u *)"", (char_u *)0L}
1359#else
1360 (char_u *)NULL, PV_NONE,
1361 {(char_u *)NULL, (char_u *)0L}
1362#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001363 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001364 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001365#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1366 (char_u *)&p_guifontset, PV_NONE,
1367 {(char_u *)"", (char_u *)0L}
1368#else
1369 (char_u *)NULL, PV_NONE,
1370 {(char_u *)NULL, (char_u *)0L}
1371#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001372 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001373 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001374#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001375 (char_u *)&p_guifontwide, PV_NONE,
1376 {(char_u *)"", (char_u *)0L}
1377#else
1378 (char_u *)NULL, PV_NONE,
1379 {(char_u *)NULL, (char_u *)0L}
1380#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001381 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001382 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001383#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001384 (char_u *)&p_ghr, PV_NONE,
1385#else
1386 (char_u *)NULL, PV_NONE,
1387#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001388 {(char_u *)50L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001389 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001390#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001391 (char_u *)&p_go, PV_NONE,
Bram Moolenaard0573012017-10-28 21:11:06 +02001392# if defined(UNIX) && !defined(FEAT_GUI_MAC)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001393 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001394# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001395 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001396# endif
1397#else
1398 (char_u *)NULL, PV_NONE,
1399 {(char_u *)NULL, (char_u *)0L}
1400#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001401 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001402 {"guipty", NULL, P_BOOL|P_VI_DEF,
1403#if defined(FEAT_GUI)
1404 (char_u *)&p_guipty, PV_NONE,
1405#else
1406 (char_u *)NULL, PV_NONE,
1407#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001408 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001409 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001410#if defined(FEAT_GUI_TABLINE)
1411 (char_u *)&p_gtl, PV_NONE,
1412 {(char_u *)"", (char_u *)0L}
1413#else
1414 (char_u *)NULL, PV_NONE,
1415 {(char_u *)NULL, (char_u *)0L}
1416#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001417 SCTX_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001418 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001419#if defined(FEAT_GUI_TABLINE)
1420 (char_u *)&p_gtt, PV_NONE,
1421 {(char_u *)"", (char_u *)0L}
1422#else
1423 (char_u *)NULL, PV_NONE,
1424 {(char_u *)NULL, (char_u *)0L}
1425#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001426 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001427 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1428 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001429 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001430 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1431 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001432 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001433 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001434 {"helpheight", "hh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001435 (char_u *)&p_hh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001436 {(char_u *)20L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001437 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001438#ifdef FEAT_MULTI_LANG
1439 (char_u *)&p_hlg, PV_NONE,
1440 {(char_u *)"", (char_u *)0L}
1441#else
1442 (char_u *)NULL, PV_NONE,
1443 {(char_u *)0L, (char_u *)0L}
1444#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001445 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001446 {"hidden", "hid", P_BOOL|P_VI_DEF,
1447 (char_u *)&p_hid, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001448 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001449 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001450 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001451 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001452 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001453 {"history", "hi", P_NUM|P_VIM,
1454 (char_u *)&p_hi, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001455 {(char_u *)0L, (char_u *)50L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001456 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1457#ifdef FEAT_RIGHTLEFT
1458 (char_u *)&p_hkmap, PV_NONE,
1459#else
1460 (char_u *)NULL, PV_NONE,
1461#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001462 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001463 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1464#ifdef FEAT_RIGHTLEFT
1465 (char_u *)&p_hkmapp, PV_NONE,
1466#else
1467 (char_u *)NULL, PV_NONE,
1468#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001469 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001470 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1471 (char_u *)&p_hls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001472 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001473 {"icon", NULL, P_BOOL|P_VI_DEF,
1474#ifdef FEAT_TITLE
1475 (char_u *)&p_icon, PV_NONE,
1476#else
1477 (char_u *)NULL, PV_NONE,
1478#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001479 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001480 {"iconstring", NULL, P_STRING|P_VI_DEF,
1481#ifdef FEAT_TITLE
1482 (char_u *)&p_iconstring, PV_NONE,
1483#else
1484 (char_u *)NULL, PV_NONE,
1485#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001486 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001487 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1488 (char_u *)&p_ic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001489 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001490 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001491#if defined(FEAT_EVAL)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001492 (char_u *)&p_imaf, PV_NONE,
1493 {(char_u *)"", (char_u *)NULL}
1494# else
1495 (char_u *)NULL, PV_NONE,
1496 {(char_u *)NULL, (char_u *)0L}
1497# endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001498 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001499 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001500#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001501 (char_u *)&p_imak, PV_NONE,
1502#else
1503 (char_u *)NULL, PV_NONE,
1504#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001505 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001506 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001507 (char_u *)&p_imcmdline, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001508 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001509 {"imdisable", "imd", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001510 (char_u *)&p_imdisable, PV_NONE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001511#ifdef __sgi
1512 {(char_u *)TRUE, (char_u *)0L}
1513#else
1514 {(char_u *)FALSE, (char_u *)0L}
1515#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001516 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001517 {"iminsert", "imi", P_NUM|P_VI_DEF,
1518 (char_u *)&p_iminsert, PV_IMI,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001519 {(char_u *)B_IMODE_NONE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001520 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001521 {"imsearch", "ims", P_NUM|P_VI_DEF,
1522 (char_u *)&p_imsearch, PV_IMS,
Bram Moolenaar4cf56bb2017-09-16 15:50:32 +02001523 {(char_u *)B_IMODE_USE_INSERT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001524 SCTX_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001525 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001526#if defined(FEAT_EVAL)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001527 (char_u *)&p_imsf, PV_NONE,
1528 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001529#else
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001530 (char_u *)NULL, PV_NONE,
1531 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001532#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001533 SCTX_INIT},
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001534 {"imstyle", "imst", P_NUM|P_VI_DEF|P_SECURE,
1535#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1536 (char_u *)&p_imst, PV_NONE,
1537 {(char_u *)IM_OVER_THE_SPOT, (char_u *)0L}
1538#else
1539 (char_u *)NULL, PV_NONE,
1540 {(char_u *)0L, (char_u *)0L}
1541#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001542 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001543 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1544#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001545 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001546 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1547#else
1548 (char_u *)NULL, PV_NONE,
1549 {(char_u *)0L, (char_u *)0L}
1550#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001551 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001552 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1553#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1554 (char_u *)&p_inex, PV_INEX,
1555 {(char_u *)"", (char_u *)0L}
1556#else
1557 (char_u *)NULL, PV_NONE,
1558 {(char_u *)0L, (char_u *)0L}
1559#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001560 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001561 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1562 (char_u *)&p_is, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001563 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001564 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1565#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1566 (char_u *)&p_inde, PV_INDE,
1567 {(char_u *)"", (char_u *)0L}
1568#else
1569 (char_u *)NULL, PV_NONE,
1570 {(char_u *)0L, (char_u *)0L}
1571#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001572 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001573 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001574#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1575 (char_u *)&p_indk, PV_INDK,
Bram Moolenaarce655742019-01-31 14:12:57 +01001576 {INDENTKEYS_DEFAULT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001577#else
1578 (char_u *)NULL, PV_NONE,
1579 {(char_u *)0L, (char_u *)0L}
1580#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001581 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001582 {"infercase", "inf", P_BOOL|P_VI_DEF,
1583 (char_u *)&p_inf, PV_INF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001584 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001585 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1586 (char_u *)&p_im, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001587 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001588 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1589 (char_u *)&p_isf, PV_NONE,
1590 {
1591#ifdef BACKSLASH_IN_FILENAME
1592 /* Excluded are: & and ^ are special in cmd.exe
1593 * ( and ) are used in text separating fnames */
1594 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1595#else
1596# ifdef AMIGA
1597 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1598# else
1599# ifdef VMS
1600 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1601# else /* UNIX et al. */
1602# ifdef EBCDIC
1603 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1604# else
1605 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1606# endif
1607# endif
1608# endif
1609#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001610 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001611 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1612 (char_u *)&p_isi, PV_NONE,
1613 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001614#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001615 (char_u *)"@,48-57,_,128-167,224-235",
1616#else
1617# ifdef EBCDIC
1618 /* TODO: EBCDIC Check this! @ == isalpha()*/
1619 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1620 "112-120,128,140-142,156,158,172,"
1621 "174,186,191,203-207,219-225,235-239,"
1622 "251-254",
1623# else
1624 (char_u *)"@,48-57,_,192-255",
1625# endif
1626#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001627 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001628 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1629 (char_u *)&p_isk, PV_ISK,
1630 {
1631#ifdef EBCDIC
1632 (char_u *)"@,240-249,_",
1633 /* TODO: EBCDIC Check this! @ == isalpha()*/
1634 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1635 "112-120,128,140-142,156,158,172,"
1636 "174,186,191,203-207,219-225,235-239,"
1637 "251-254",
1638#else
1639 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001640# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001641 (char_u *)"@,48-57,_,128-167,224-235"
1642# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001643 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001644# endif
1645#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001646 } SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001647 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1648 (char_u *)&p_isp, PV_NONE,
1649 {
Bram Moolenaard0573012017-10-28 21:11:06 +02001650#if defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001651 (char_u *)"@,~-255",
1652#else
1653# ifdef EBCDIC
1654 /* all chars above 63 are printable */
1655 (char_u *)"63-255",
1656# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001657 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001658# endif
1659#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001660 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001661 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1662 (char_u *)&p_js, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001663 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001664 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1665#ifdef FEAT_CRYPT
1666 (char_u *)&p_key, PV_KEY,
1667 {(char_u *)"", (char_u *)0L}
1668#else
1669 (char_u *)NULL, PV_NONE,
1670 {(char_u *)0L, (char_u *)0L}
1671#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001672 SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001673 {"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 +00001674#ifdef FEAT_KEYMAP
1675 (char_u *)&p_keymap, PV_KMAP,
1676 {(char_u *)"", (char_u *)0L}
1677#else
1678 (char_u *)NULL, PV_NONE,
1679 {(char_u *)"", (char_u *)0L}
1680#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001681 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001682 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001683 (char_u *)&p_km, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001684 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001685 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001686 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001687 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001688#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001689 (char_u *)":help",
1690#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001691# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001692 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001693# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001694# ifdef USEMAN_S
1695 (char_u *)"man -s",
1696# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001697 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001698# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001699# endif
1700#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001701 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001702 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001703#ifdef FEAT_LANGMAP
1704 (char_u *)&p_langmap, PV_NONE,
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001705 {(char_u *)"", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001706#else
1707 (char_u *)NULL, PV_NONE,
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001708 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001709#endif
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001710 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001711 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001712#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1713 (char_u *)&p_lm, PV_NONE,
1714#else
1715 (char_u *)NULL, PV_NONE,
1716#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001717 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001718 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1719#ifdef FEAT_LANGMAP
1720 (char_u *)&p_lnr, PV_NONE,
1721#else
1722 (char_u *)NULL, PV_NONE,
1723#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001724 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001725 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1726#ifdef FEAT_LANGMAP
1727 (char_u *)&p_lrm, PV_NONE,
1728#else
1729 (char_u *)NULL, PV_NONE,
1730#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001731 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001732 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001733 (char_u *)&p_ls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001734 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001735 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1736 (char_u *)&p_lz, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001737 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001738 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1739#ifdef FEAT_LINEBREAK
1740 (char_u *)VAR_WIN, PV_LBR,
1741#else
1742 (char_u *)NULL, PV_NONE,
1743#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001744 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001745 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1746 (char_u *)&Rows, PV_NONE,
1747 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001748#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001749 (char_u *)25L,
1750#else
1751 (char_u *)24L,
1752#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001753 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001754 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1755#ifdef FEAT_GUI
1756 (char_u *)&p_linespace, PV_NONE,
1757#else
1758 (char_u *)NULL, PV_NONE,
1759#endif
1760#ifdef FEAT_GUI_W32
1761 {(char_u *)1L, (char_u *)0L}
1762#else
1763 {(char_u *)0L, (char_u *)0L}
1764#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001765 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001766 {"lisp", NULL, P_BOOL|P_VI_DEF,
1767#ifdef FEAT_LISP
1768 (char_u *)&p_lisp, PV_LISP,
1769#else
1770 (char_u *)NULL, PV_NONE,
1771#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001772 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001773 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001774#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001775 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001776 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1777#else
1778 (char_u *)NULL, PV_NONE,
1779 {(char_u *)"", (char_u *)0L}
1780#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001781 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001782 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1783 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001784 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001785 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001786 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001787 {(char_u *)"eol:$", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001788 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1789 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001790 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001791 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001792#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001793 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001794 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001795#else
1796 (char_u *)NULL, PV_NONE,
1797 {(char_u *)"", (char_u *)0L}
1798#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001799 SCTX_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001800 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001801#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001802 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001803 {(char_u *)TRUE, (char_u *)0L}
1804#else
1805 (char_u *)NULL, PV_NONE,
1806 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001807#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001808 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001809 {"magic", NULL, P_BOOL|P_VI_DEF,
1810 (char_u *)&p_magic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001811 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001812 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001813#ifdef FEAT_QUICKFIX
1814 (char_u *)&p_mef, PV_NONE,
1815 {(char_u *)"", (char_u *)0L}
1816#else
1817 (char_u *)NULL, PV_NONE,
1818 {(char_u *)NULL, (char_u *)0L}
1819#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001820 SCTX_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001821 {"makeencoding","menc", P_STRING|P_VI_DEF,
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001822 (char_u *)&p_menc, PV_MENC,
1823 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001824 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001825 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1826#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001827 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001828# ifdef VMS
1829 {(char_u *)"MMS", (char_u *)0L}
1830# else
1831 {(char_u *)"make", (char_u *)0L}
1832# endif
1833#else
1834 (char_u *)NULL, PV_NONE,
1835 {(char_u *)NULL, (char_u *)0L}
1836#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001837 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001838 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001839 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001840 {(char_u *)"(:),{:},[:]", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001841 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001842 {"matchtime", "mat", P_NUM|P_VI_DEF,
1843 (char_u *)&p_mat, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001844 {(char_u *)5L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001845 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001846 (char_u *)&p_mco, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001847 {(char_u *)2, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001848 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1849#ifdef FEAT_EVAL
1850 (char_u *)&p_mfd, PV_NONE,
1851#else
1852 (char_u *)NULL, PV_NONE,
1853#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001854 {(char_u *)100L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001855 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1856 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001857 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001858 {"maxmem", "mm", P_NUM|P_VI_DEF,
1859 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001860 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001861 SCTX_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001862 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1863 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001864 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001865 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1866 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001867 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001868 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001869 {"menuitems", "mis", P_NUM|P_VI_DEF,
1870#ifdef FEAT_MENU
1871 (char_u *)&p_mis, PV_NONE,
1872#else
1873 (char_u *)NULL, PV_NONE,
1874#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001875 {(char_u *)25L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001876 {"mesg", NULL, P_BOOL|P_VI_DEF,
1877 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001878 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001879 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001880#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001881 (char_u *)&p_msm, PV_NONE,
1882 {(char_u *)"460000,2000,500", (char_u *)0L}
1883#else
1884 (char_u *)NULL, PV_NONE,
1885 {(char_u *)0L, (char_u *)0L}
1886#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001887 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001888 {"modeline", "ml", P_BOOL|P_VIM,
1889 (char_u *)&p_ml, PV_ML,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001890 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001891 {"modelines", "mls", P_NUM|P_VI_DEF,
1892 (char_u *)&p_mls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001893 {(char_u *)5L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001894 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1895 (char_u *)&p_ma, PV_MA,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001896 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001897 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1898 (char_u *)&p_mod, PV_MOD,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001899 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001900 {"more", NULL, P_BOOL|P_VIM,
1901 (char_u *)&p_more, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001902 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001903 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1904 (char_u *)&p_mouse, PV_NONE,
1905 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001906#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001907 (char_u *)"a",
1908#else
1909 (char_u *)"",
1910#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001911 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001912 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1913#ifdef FEAT_GUI
1914 (char_u *)&p_mousef, PV_NONE,
1915#else
1916 (char_u *)NULL, PV_NONE,
1917#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001918 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001919 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1920#ifdef FEAT_GUI
1921 (char_u *)&p_mh, PV_NONE,
1922#else
1923 (char_u *)NULL, PV_NONE,
1924#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001925 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001926 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1927 (char_u *)&p_mousem, PV_NONE,
1928 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001929#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001930 (char_u *)"popup",
1931#else
Bram Moolenaard0573012017-10-28 21:11:06 +02001932# if defined(MACOS_X)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001933 (char_u *)"popup_setpos",
1934# else
1935 (char_u *)"extend",
1936# endif
1937#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001938 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001939 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001940#ifdef FEAT_MOUSESHAPE
1941 (char_u *)&p_mouseshape, PV_NONE,
1942 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1943#else
1944 (char_u *)NULL, PV_NONE,
1945 {(char_u *)NULL, (char_u *)0L}
1946#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001947 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001948 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1949 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001950 {(char_u *)500L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02001951 {"mzschemedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1952#if defined(DYNAMIC_MZSCHEME)
1953 (char_u *)&p_mzschemedll, PV_NONE,
1954 {(char_u *)DYNAMIC_MZSCH_DLL, (char_u *)0L}
1955#else
1956 (char_u *)NULL, PV_NONE,
1957 {(char_u *)"", (char_u *)0L}
1958#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001959 SCTX_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02001960 {"mzschemegcdll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1961#if defined(DYNAMIC_MZSCHEME)
1962 (char_u *)&p_mzschemegcdll, PV_NONE,
1963 {(char_u *)DYNAMIC_MZGC_DLL, (char_u *)0L}
1964#else
1965 (char_u *)NULL, PV_NONE,
1966 {(char_u *)"", (char_u *)0L}
1967#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001968 SCTX_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001969 {"mzquantum", "mzq", P_NUM,
1970#ifdef FEAT_MZSCHEME
1971 (char_u *)&p_mzq, PV_NONE,
1972#else
1973 (char_u *)NULL, PV_NONE,
1974#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001975 {(char_u *)100L, (char_u *)100L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001976 {"novice", NULL, P_BOOL|P_VI_DEF,
1977 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001978 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001979 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001980 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01001981 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001982 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001983 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1984 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001985 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001986 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1987#ifdef FEAT_LINEBREAK
1988 (char_u *)VAR_WIN, PV_NUW,
1989#else
1990 (char_u *)NULL, PV_NONE,
1991#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001992 {(char_u *)8L, (char_u *)4L} SCTX_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001993 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001994#ifdef FEAT_COMPL_FUNC
1995 (char_u *)&p_ofu, PV_OFU,
1996 {(char_u *)"", (char_u *)0L}
1997#else
1998 (char_u *)NULL, PV_NONE,
1999 {(char_u *)0L, (char_u *)0L}
2000#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002001 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002002 {"open", NULL, P_BOOL|P_VI_DEF,
2003 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002004 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002005 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002006#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002007 (char_u *)&p_odev, PV_NONE,
2008#else
2009 (char_u *)NULL, PV_NONE,
2010#endif
2011 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002012 SCTX_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002013 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2014 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002015 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002016 {"optimize", "opt", P_BOOL|P_VI_DEF,
2017 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002018 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002019 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002020 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002021 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002022 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2023 |P_SECURE,
2024 (char_u *)&p_pp, PV_NONE,
2025 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002026 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002027 {"paragraphs", "para", P_STRING|P_VI_DEF,
2028 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002029 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002030 (char_u *)0L} SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002031 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002032 (char_u *)&p_paste, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002033 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002034 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2035 (char_u *)&p_pt, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002036 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002037 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2038#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2039 (char_u *)&p_pex, PV_NONE,
2040 {(char_u *)"", (char_u *)0L}
2041#else
2042 (char_u *)NULL, PV_NONE,
2043 {(char_u *)0L, (char_u *)0L}
2044#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002045 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002046 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002047 (char_u *)&p_pm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002048 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002049 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002050 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002051 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002052#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002053 (char_u *)".,,",
2054#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002055 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002056#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002057 (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002058 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002059#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002060 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002061 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002062#else
2063 (char_u *)NULL, PV_NONE,
2064 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002065#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002066 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002067 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2068 (char_u *)&p_pi, PV_PI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002069 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002070 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002071#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002072 (char_u *)&p_pvh, PV_NONE,
2073#else
2074 (char_u *)NULL, PV_NONE,
2075#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002076 {(char_u *)12L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002077 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002078#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002079 (char_u *)VAR_WIN, PV_PVW,
2080#else
2081 (char_u *)NULL, PV_NONE,
2082#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002083 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002084 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002085#ifdef FEAT_PRINTER
2086 (char_u *)&p_pdev, PV_NONE,
2087 {(char_u *)"", (char_u *)0L}
2088#else
2089 (char_u *)NULL, PV_NONE,
2090 {(char_u *)NULL, (char_u *)0L}
2091#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002092 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002093 {"printencoding", "penc", P_STRING|P_VI_DEF,
2094#ifdef FEAT_POSTSCRIPT
2095 (char_u *)&p_penc, PV_NONE,
2096 {(char_u *)"", (char_u *)0L}
2097#else
2098 (char_u *)NULL, PV_NONE,
2099 {(char_u *)NULL, (char_u *)0L}
2100#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002101 SCTX_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002102 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002103#ifdef FEAT_POSTSCRIPT
2104 (char_u *)&p_pexpr, PV_NONE,
2105 {(char_u *)"", (char_u *)0L}
2106#else
2107 (char_u *)NULL, PV_NONE,
2108 {(char_u *)NULL, (char_u *)0L}
2109#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002110 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002111 {"printfont", "pfn", P_STRING|P_VI_DEF,
2112#ifdef FEAT_PRINTER
2113 (char_u *)&p_pfn, PV_NONE,
2114 {
2115# ifdef MSWIN
2116 (char_u *)"Courier_New:h10",
2117# else
2118 (char_u *)"courier",
2119# endif
2120 (char_u *)0L}
2121#else
2122 (char_u *)NULL, PV_NONE,
2123 {(char_u *)NULL, (char_u *)0L}
2124#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002125 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002126 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2127#ifdef FEAT_PRINTER
2128 (char_u *)&p_header, PV_NONE,
Bram Moolenaar0903d562017-08-26 22:30:15 +02002129 /* untranslated to avoid problems when 'encoding'
2130 * is changed */
2131 {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002132#else
2133 (char_u *)NULL, PV_NONE,
2134 {(char_u *)NULL, (char_u *)0L}
2135#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002136 SCTX_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002137 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01002138#if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002139 (char_u *)&p_pmcs, PV_NONE,
2140 {(char_u *)"", (char_u *)0L}
2141#else
2142 (char_u *)NULL, PV_NONE,
2143 {(char_u *)NULL, (char_u *)0L}
2144#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002145 SCTX_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002146 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01002147#if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002148 (char_u *)&p_pmfn, PV_NONE,
2149 {(char_u *)"", (char_u *)0L}
2150#else
2151 (char_u *)NULL, PV_NONE,
2152 {(char_u *)NULL, (char_u *)0L}
2153#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002154 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002155 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002156#ifdef FEAT_PRINTER
2157 (char_u *)&p_popt, PV_NONE,
2158 {(char_u *)"", (char_u *)0L}
2159#else
2160 (char_u *)NULL, PV_NONE,
2161 {(char_u *)NULL, (char_u *)0L}
2162#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002163 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002164 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002165 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002166 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002167 {"pumheight", "ph", P_NUM|P_VI_DEF,
2168#ifdef FEAT_INS_EXPAND
2169 (char_u *)&p_ph, PV_NONE,
2170#else
2171 (char_u *)NULL, PV_NONE,
2172#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002173 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaara8f04aa2018-02-10 15:36:55 +01002174 {"pumwidth", "pw", P_NUM|P_VI_DEF,
2175#ifdef FEAT_INS_EXPAND
2176 (char_u *)&p_pw, PV_NONE,
2177#else
2178 (char_u *)NULL, PV_NONE,
2179#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002180 {(char_u *)15L, (char_u *)15L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002181 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002182#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002183 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002184 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002185#else
2186 (char_u *)NULL, PV_NONE,
2187 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002188#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002189 SCTX_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002190 {"pythonthreehome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2191#if defined(FEAT_PYTHON3)
2192 (char_u *)&p_py3home, PV_NONE,
2193 {(char_u *)"", (char_u *)0L}
2194#else
2195 (char_u *)NULL, PV_NONE,
2196 {(char_u *)NULL, (char_u *)0L}
2197#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002198 SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002199 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002200#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002201 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002202 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002203#else
2204 (char_u *)NULL, PV_NONE,
2205 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002206#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002207 SCTX_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002208 {"pythonhome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2209#if defined(FEAT_PYTHON)
2210 (char_u *)&p_pyhome, PV_NONE,
2211 {(char_u *)"", (char_u *)0L}
2212#else
2213 (char_u *)NULL, PV_NONE,
2214 {(char_u *)NULL, (char_u *)0L}
2215#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002216 SCTX_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002217 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2218#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2219 (char_u *)&p_pyx, PV_NONE,
2220#else
2221 (char_u *)NULL, PV_NONE,
2222#endif
2223 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002224 SCTX_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002225 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2226#ifdef FEAT_TEXTOBJ
2227 (char_u *)&p_qe, PV_QE,
2228 {(char_u *)"\\", (char_u *)0L}
2229#else
2230 (char_u *)NULL, PV_NONE,
2231 {(char_u *)NULL, (char_u *)0L}
2232#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002233 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002234 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2235 (char_u *)&p_ro, PV_RO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002236 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002237 {"redraw", NULL, P_BOOL|P_VI_DEF,
2238 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002239 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002240 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2241#ifdef FEAT_RELTIME
2242 (char_u *)&p_rdt, PV_NONE,
2243#else
2244 (char_u *)NULL, PV_NONE,
2245#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002246 {(char_u *)2000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002247 {"regexpengine", "re", P_NUM|P_VI_DEF,
2248 (char_u *)&p_re, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002249 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002250 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2251 (char_u *)VAR_WIN, PV_RNU,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002252 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002253 {"remap", NULL, P_BOOL|P_VI_DEF,
2254 (char_u *)&p_remap, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002255 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002256 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002257#ifdef FEAT_RENDER_OPTIONS
2258 (char_u *)&p_rop, PV_NONE,
2259 {(char_u *)"", (char_u *)0L}
2260#else
2261 (char_u *)NULL, PV_NONE,
2262 {(char_u *)NULL, (char_u *)0L}
2263#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002264 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002265 {"report", NULL, P_NUM|P_VI_DEF,
2266 (char_u *)&p_report, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002267 {(char_u *)2L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002268 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2269#ifdef WIN3264
2270 (char_u *)&p_rs, PV_NONE,
2271#else
2272 (char_u *)NULL, PV_NONE,
2273#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002274 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002275 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2276#ifdef FEAT_RIGHTLEFT
2277 (char_u *)&p_ri, PV_NONE,
2278#else
2279 (char_u *)NULL, PV_NONE,
2280#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002281 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002282 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2283#ifdef FEAT_RIGHTLEFT
2284 (char_u *)VAR_WIN, PV_RL,
2285#else
2286 (char_u *)NULL, PV_NONE,
2287#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002288 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002289 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2290#ifdef FEAT_RIGHTLEFT
2291 (char_u *)VAR_WIN, PV_RLC,
2292 {(char_u *)"search", (char_u *)NULL}
2293#else
2294 (char_u *)NULL, PV_NONE,
2295 {(char_u *)NULL, (char_u *)0L}
2296#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002297 SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002298 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002299#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002300 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002301 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002302#else
2303 (char_u *)NULL, PV_NONE,
2304 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002305#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002306 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002307 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2308#ifdef FEAT_CMDL_INFO
2309 (char_u *)&p_ru, PV_NONE,
2310#else
2311 (char_u *)NULL, PV_NONE,
2312#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002313 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002314 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2315#ifdef FEAT_STL_OPT
2316 (char_u *)&p_ruf, PV_NONE,
2317#else
2318 (char_u *)NULL, PV_NONE,
2319#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002320 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002321 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2322 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002323 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002324 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002325 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002326 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2327 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002328 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002329 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002330 (char_u *)VAR_WIN, PV_SCBIND,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002331 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002332 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2333 (char_u *)&p_sj, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002334 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002335 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2336 (char_u *)&p_so, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002337 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002338 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002339 (char_u *)&p_sbo, PV_NONE,
2340 {(char_u *)"ver,jump", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002341 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002342 {"sections", "sect", P_STRING|P_VI_DEF,
2343 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002344 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002345 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002346 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2347 (char_u *)&p_secure, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002348 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002349 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002350 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002351 {(char_u *)"inclusive", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002352 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002353 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002354 (char_u *)&p_slm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002355 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002356 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002357#ifdef FEAT_SESSION
2358 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar4d8bac82018-03-09 21:33:34 +01002359 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize,terminal",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002360 (char_u *)0L}
2361#else
2362 (char_u *)NULL, PV_NONE,
2363 {(char_u *)0L, (char_u *)0L}
2364#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002365 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002366 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2367 (char_u *)&p_sh, PV_NONE,
2368 {
2369#ifdef VMS
2370 (char_u *)"-",
2371#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002372# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002373 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002374# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002375 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002376# endif
2377#endif /* VMS */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002378 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002379 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2380 (char_u *)&p_shcf, PV_NONE,
2381 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002382#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002383 (char_u *)"/c",
2384#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002385 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002386#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002387 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002388 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2389#ifdef FEAT_QUICKFIX
2390 (char_u *)&p_sp, PV_NONE,
2391 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002392#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002393 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002394#else
2395 (char_u *)">",
2396#endif
2397 (char_u *)0L}
2398#else
2399 (char_u *)NULL, PV_NONE,
2400 {(char_u *)0L, (char_u *)0L}
2401#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002402 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002403 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2404 (char_u *)&p_shq, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002405 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002406 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2407 (char_u *)&p_srr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002408 {(char_u *)">", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002409 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2410#ifdef BACKSLASH_IN_FILENAME
2411 (char_u *)&p_ssl, PV_NONE,
2412#else
2413 (char_u *)NULL, PV_NONE,
2414#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002415 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002416 {"shelltemp", "stmp", P_BOOL,
2417 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002418 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002419 {"shelltype", "st", P_NUM|P_VI_DEF,
2420#ifdef AMIGA
2421 (char_u *)&p_st, PV_NONE,
2422#else
2423 (char_u *)NULL, PV_NONE,
2424#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002425 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002426 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2427 (char_u *)&p_sxq, PV_NONE,
2428 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002429#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002430 (char_u *)"\"",
2431#else
2432 (char_u *)"",
2433#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002434 (char_u *)0L} SCTX_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002435 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2436 (char_u *)&p_sxe, PV_NONE,
2437 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002438#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002439 (char_u *)"\"&|<>()@^",
2440#else
2441 (char_u *)"",
2442#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002443 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002444 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2445 (char_u *)&p_sr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002446 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002447 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2448 (char_u *)&p_sw, PV_SW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002449 {(char_u *)8L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002450 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2451 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002452 {(char_u *)"", (char_u *)"filnxtToO"}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002453 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002454 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002455 (char_u *)&p_sn, PV_SN,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002456 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002457 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2458#ifdef FEAT_LINEBREAK
2459 (char_u *)&p_sbr, PV_NONE,
2460#else
2461 (char_u *)NULL, PV_NONE,
2462#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002463 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002464 {"showcmd", "sc", P_BOOL|P_VIM,
2465#ifdef FEAT_CMDL_INFO
2466 (char_u *)&p_sc, PV_NONE,
2467#else
2468 (char_u *)NULL, PV_NONE,
2469#endif
2470 {(char_u *)FALSE,
2471#ifdef UNIX
2472 (char_u *)FALSE
2473#else
2474 (char_u *)TRUE
2475#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002476 } SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002477 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2478 (char_u *)&p_sft, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002479 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002480 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2481 (char_u *)&p_sm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002482 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002483 {"showmode", "smd", P_BOOL|P_VIM,
2484 (char_u *)&p_smd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002485 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002486 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002487 (char_u *)&p_stal, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002488 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002489 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2490 (char_u *)&p_ss, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002491 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002492 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2493 (char_u *)&p_siso, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002494 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002495 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2496#ifdef FEAT_SIGNS
2497 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002498 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002499#else
2500 (char_u *)NULL, PV_NONE,
2501 {(char_u *)NULL, (char_u *)0L}
2502#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002503 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002504 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2505 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002506 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002507 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2508 (char_u *)&p_scs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002509 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002510 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2511#ifdef FEAT_SMARTINDENT
2512 (char_u *)&p_si, PV_SI,
2513#else
2514 (char_u *)NULL, PV_NONE,
2515#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002516 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002517 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2518 (char_u *)&p_sta, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002519 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002520 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2521 (char_u *)&p_sts, PV_STS,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002522 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002523 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2524 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002525 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002526 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002527#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002528 (char_u *)VAR_WIN, PV_SPELL,
2529#else
2530 (char_u *)NULL, PV_NONE,
2531#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002532 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002533 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002534#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002535 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002536 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002537#else
2538 (char_u *)NULL, PV_NONE,
2539 {(char_u *)0L, (char_u *)0L}
2540#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002541 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002542 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2543 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002544#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002545 (char_u *)&p_spf, PV_SPF,
2546 {(char_u *)"", (char_u *)0L}
2547#else
2548 (char_u *)NULL, PV_NONE,
2549 {(char_u *)0L, (char_u *)0L}
2550#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002551 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002552 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2553 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002554#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002555 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002556 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002557#else
2558 (char_u *)NULL, PV_NONE,
2559 {(char_u *)0L, (char_u *)0L}
2560#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002561 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002562 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002563#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002564 (char_u *)&p_sps, PV_NONE,
2565 {(char_u *)"best", (char_u *)0L}
2566#else
2567 (char_u *)NULL, PV_NONE,
2568 {(char_u *)0L, (char_u *)0L}
2569#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002570 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002571 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002572 (char_u *)&p_sb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002573 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002574 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002575 (char_u *)&p_spr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002576 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002577 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2578 (char_u *)&p_sol, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002579 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002580 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2581#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002582 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002583#else
2584 (char_u *)NULL, PV_NONE,
2585#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002586 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002587 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002588 (char_u *)&p_su, PV_NONE,
2589 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002590 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002591 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002592#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002593 (char_u *)&p_sua, PV_SUA,
2594 {(char_u *)"", (char_u *)0L}
2595#else
2596 (char_u *)NULL, PV_NONE,
2597 {(char_u *)0L, (char_u *)0L}
2598#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002599 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002600 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2601 (char_u *)&p_swf, PV_SWF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002602 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002603 {"swapsync", "sws", P_STRING|P_VI_DEF,
2604 (char_u *)&p_sws, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002605 {(char_u *)"fsync", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002606 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002607 (char_u *)&p_swb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002608 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002609 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2610#ifdef FEAT_SYN_HL
2611 (char_u *)&p_smc, PV_SMC,
2612 {(char_u *)3000L, (char_u *)0L}
2613#else
2614 (char_u *)NULL, PV_NONE,
2615 {(char_u *)0L, (char_u *)0L}
2616#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002617 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002618 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002619#ifdef FEAT_SYN_HL
2620 (char_u *)&p_syn, PV_SYN,
2621 {(char_u *)"", (char_u *)0L}
2622#else
2623 (char_u *)NULL, PV_NONE,
2624 {(char_u *)0L, (char_u *)0L}
2625#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002626 SCTX_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002627 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2628#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002629 (char_u *)&p_tal, PV_NONE,
2630#else
2631 (char_u *)NULL, PV_NONE,
2632#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002633 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002634 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002635 (char_u *)&p_tpm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002636 {(char_u *)10L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002637 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2638 (char_u *)&p_ts, PV_TS,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002639 {(char_u *)8L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002640 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2641 (char_u *)&p_tbs, PV_NONE,
2642#ifdef VMS /* binary searching doesn't appear to work on VMS */
2643 {(char_u *)0L, (char_u *)0L}
2644#else
2645 {(char_u *)TRUE, (char_u *)0L}
2646#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002647 SCTX_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002648 {"tagcase", "tc", P_STRING|P_VIM,
2649 (char_u *)&p_tc, PV_TC,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002650 {(char_u *)"followic", (char_u *)"followic"} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002651 {"taglength", "tl", P_NUM|P_VI_DEF,
2652 (char_u *)&p_tl, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002653 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002654 {"tagrelative", "tr", P_BOOL|P_VIM,
2655 (char_u *)&p_tr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002656 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002657 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002658 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002659 {
2660#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2661 (char_u *)"./tags,./TAGS,tags,TAGS",
2662#else
2663 (char_u *)"./tags,tags",
2664#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002665 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002666 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2667 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002668 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002669 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002670#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002671 (char_u *)&p_tcldll, PV_NONE,
2672 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002673#else
2674 (char_u *)NULL, PV_NONE,
2675 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002676#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002677 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002678 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2679 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002680 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002681 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2682#ifdef FEAT_ARABIC
2683 (char_u *)&p_tbidi, PV_NONE,
2684#else
2685 (char_u *)NULL, PV_NONE,
2686#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002687 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002688 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002689 (char_u *)&p_tenc, PV_NONE,
2690 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002691 SCTX_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002692 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2693#ifdef FEAT_TERMGUICOLORS
2694 (char_u *)&p_tgc, PV_NONE,
2695 {(char_u *)FALSE, (char_u *)FALSE}
2696#else
2697 (char_u*)NULL, PV_NONE,
2698 {(char_u *)FALSE, (char_u *)FALSE}
2699#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002700 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002701 {"termwinkey", "twk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2702#ifdef FEAT_TERMINAL
2703 (char_u *)VAR_WIN, PV_TWK,
2704 {(char_u *)"", (char_u *)NULL}
2705#else
2706 (char_u *)NULL, PV_NONE,
2707 {(char_u *)NULL, (char_u *)0L}
2708#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002709 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002710 {"termwinscroll", "twsl", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2711#ifdef FEAT_TERMINAL
2712 (char_u *)&p_twsl, PV_TWSL,
2713 {(char_u *)10000L, (char_u *)10000L}
2714#else
2715 (char_u *)NULL, PV_NONE,
2716 {(char_u *)NULL, (char_u *)0L}
2717#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002718 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002719 {"termwinsize", "tws", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2720#ifdef FEAT_TERMINAL
2721 (char_u *)VAR_WIN, PV_TWS,
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002722 {(char_u *)"", (char_u *)NULL}
2723#else
2724 (char_u *)NULL, PV_NONE,
2725 {(char_u *)NULL, (char_u *)0L}
2726#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002727 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002728 {"terse", NULL, P_BOOL|P_VI_DEF,
2729 (char_u *)&p_terse, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002730 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002731 {"textauto", "ta", P_BOOL|P_VIM,
2732 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002733 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002734 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002735 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2736 (char_u *)&p_tx, PV_TX,
2737 {
2738#ifdef USE_CRNL
2739 (char_u *)TRUE,
2740#else
2741 (char_u *)FALSE,
2742#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002743 (char_u *)0L} SCTX_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002744 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002745 (char_u *)&p_tw, PV_TW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002746 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002747 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002748#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002749 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002750#else
2751 (char_u *)NULL, PV_NONE,
2752#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002753 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002754 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2755 (char_u *)&p_to, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002756 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002757 {"timeout", "to", P_BOOL|P_VI_DEF,
2758 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002759 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002760 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2761 (char_u *)&p_tm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002762 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002763 {"title", NULL, P_BOOL|P_VI_DEF,
2764#ifdef FEAT_TITLE
2765 (char_u *)&p_title, PV_NONE,
2766#else
2767 (char_u *)NULL, PV_NONE,
2768#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002769 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002770 {"titlelen", NULL, P_NUM|P_VI_DEF,
2771#ifdef FEAT_TITLE
2772 (char_u *)&p_titlelen, PV_NONE,
2773#else
2774 (char_u *)NULL, PV_NONE,
2775#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002776 {(char_u *)85L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002777 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002778#ifdef FEAT_TITLE
2779 (char_u *)&p_titleold, PV_NONE,
2780 {(char_u *)N_("Thanks for flying Vim"),
2781 (char_u *)0L}
2782#else
2783 (char_u *)NULL, PV_NONE,
2784 {(char_u *)0L, (char_u *)0L}
2785#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002786 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002787 {"titlestring", NULL, P_STRING|P_VI_DEF,
2788#ifdef FEAT_TITLE
2789 (char_u *)&p_titlestring, PV_NONE,
2790#else
2791 (char_u *)NULL, PV_NONE,
2792#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002793 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002794 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002795#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002796 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002797 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002798#else
2799 (char_u *)NULL, PV_NONE,
2800 {(char_u *)0L, (char_u *)0L}
2801#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002802 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002803 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002804#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002805 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002806 {(char_u *)"small", (char_u *)0L}
2807#else
2808 (char_u *)NULL, PV_NONE,
2809 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002810#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002811 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002812 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2813 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002814 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002815 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2816 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002817 {(char_u *)-1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002818 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2819 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002820 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002821 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2822 (char_u *)&p_tf, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002823 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002824 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2825#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2826 (char_u *)&p_ttym, PV_NONE,
2827#else
2828 (char_u *)NULL, PV_NONE,
2829#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002830 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002831 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2832 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002833 {(char_u *)999L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002834 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2835 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002836 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002837 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2838 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002839#ifdef FEAT_PERSISTENT_UNDO
2840 (char_u *)&p_udir, PV_NONE,
2841 {(char_u *)".", (char_u *)0L}
2842#else
2843 (char_u *)NULL, PV_NONE,
2844 {(char_u *)0L, (char_u *)0L}
2845#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002846 SCTX_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002847 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2848#ifdef FEAT_PERSISTENT_UNDO
2849 (char_u *)&p_udf, PV_UDF,
2850#else
2851 (char_u *)NULL, PV_NONE,
2852#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002853 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002854 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002855 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002856 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002857#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002858 (char_u *)1000L,
2859#else
2860 (char_u *)100L,
2861#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002862 (char_u *)0L} SCTX_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002863 {"undoreload", "ur", P_NUM|P_VI_DEF,
2864 (char_u *)&p_ur, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002865 { (char_u *)10000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002866 {"updatecount", "uc", P_NUM|P_VI_DEF,
2867 (char_u *)&p_uc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002868 {(char_u *)200L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002869 {"updatetime", "ut", P_NUM|P_VI_DEF,
2870 (char_u *)&p_ut, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002871 {(char_u *)4000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar04958cb2018-06-23 19:23:02 +02002872 {"varsofttabstop", "vsts", P_STRING|P_VI_DEF|P_VIM|P_COMMA,
2873#ifdef FEAT_VARTABS
2874 (char_u *)&p_vsts, PV_VSTS,
2875 {(char_u *)"", (char_u *)0L}
2876#else
2877 (char_u *)NULL, PV_NONE,
2878 {(char_u *)"", (char_u *)NULL}
2879#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002880 SCTX_INIT},
Bram Moolenaar04958cb2018-06-23 19:23:02 +02002881 {"vartabstop", "vts", P_STRING|P_VI_DEF|P_VIM|P_RBUF|P_COMMA,
2882#ifdef FEAT_VARTABS
2883 (char_u *)&p_vts, PV_VTS,
2884 {(char_u *)"", (char_u *)0L}
2885#else
2886 (char_u *)NULL, PV_NONE,
2887 {(char_u *)"", (char_u *)NULL}
2888#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002889 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002890 {"verbose", "vbs", P_NUM|P_VI_DEF,
2891 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002892 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002893 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2894 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002895 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002896 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2897#ifdef FEAT_SESSION
2898 (char_u *)&p_vdir, PV_NONE,
2899 {(char_u *)DFLT_VDIR, (char_u *)0L}
2900#else
2901 (char_u *)NULL, PV_NONE,
2902 {(char_u *)0L, (char_u *)0L}
2903#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002904 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002905 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002906#ifdef FEAT_SESSION
2907 (char_u *)&p_vop, PV_NONE,
Bram Moolenaar13e90412017-11-11 18:16:48 +01002908 {(char_u *)"folds,options,cursor,curdir",
2909 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002910#else
2911 (char_u *)NULL, PV_NONE,
2912 {(char_u *)0L, (char_u *)0L}
2913#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002914 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002915 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002916#ifdef FEAT_VIMINFO
2917 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002918#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002919 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002920#else
2921# ifdef AMIGA
2922 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002923 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002924# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002925 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002926# endif
2927#endif
2928#else
2929 (char_u *)NULL, PV_NONE,
2930 {(char_u *)0L, (char_u *)0L}
2931#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002932 SCTX_INIT},
Bram Moolenaarc229e542018-07-08 21:46:56 +02002933 {"viminfofile", "vif", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP
2934 |P_SECURE|P_VI_DEF,
Bram Moolenaarc4da1132017-07-15 19:39:43 +02002935#ifdef FEAT_VIMINFO
2936 (char_u *)&p_viminfofile, PV_NONE,
2937 {(char_u *)"", (char_u *)0L}
2938#else
2939 (char_u *)NULL, PV_NONE,
2940 {(char_u *)0L, (char_u *)0L}
2941#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002942 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002943 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2944 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002945 (char_u *)&p_ve, PV_NONE,
2946 {(char_u *)"", (char_u *)""}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002947 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002948 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2949 (char_u *)&p_vb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002950 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002951 {"w300", NULL, P_NUM|P_VI_DEF,
2952 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002953 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002954 {"w1200", NULL, P_NUM|P_VI_DEF,
2955 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002956 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002957 {"w9600", NULL, P_NUM|P_VI_DEF,
2958 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002959 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002960 {"warn", NULL, P_BOOL|P_VI_DEF,
2961 (char_u *)&p_warn, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002962 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002963 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2964 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002965 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002966 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002967 (char_u *)&p_ww, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002968 {(char_u *)"", (char_u *)"b,s"} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002969 {"wildchar", "wc", P_NUM|P_VIM,
2970 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002971 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002972 SCTX_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002973 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002974 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002975 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002976 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002977#ifdef FEAT_WILDIGN
2978 (char_u *)&p_wig, PV_NONE,
2979#else
2980 (char_u *)NULL, PV_NONE,
2981#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002982 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002983 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2984 (char_u *)&p_wic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002985 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002986 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2987#ifdef FEAT_WILDMENU
2988 (char_u *)&p_wmnu, PV_NONE,
2989#else
2990 (char_u *)NULL, PV_NONE,
2991#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002992 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002993 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002994 (char_u *)&p_wim, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002995 {(char_u *)"full", (char_u *)0L} SCTX_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002996 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2997#ifdef FEAT_CMDL_COMPL
2998 (char_u *)&p_wop, PV_NONE,
2999 {(char_u *)"", (char_u *)0L}
3000#else
3001 (char_u *)NULL, PV_NONE,
3002 {(char_u *)NULL, (char_u *)0L}
3003#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003004 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003005 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3006#ifdef FEAT_WAK
3007 (char_u *)&p_wak, PV_NONE,
3008 {(char_u *)"menu", (char_u *)0L}
3009#else
3010 (char_u *)NULL, PV_NONE,
3011 {(char_u *)NULL, (char_u *)0L}
3012#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003013 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003014 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003015 (char_u *)&p_window, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003016 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003017 {"winheight", "wh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003018 (char_u *)&p_wh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003019 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003020 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003021 (char_u *)VAR_WIN, PV_WFH,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003022 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003023 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003024 (char_u *)VAR_WIN, PV_WFW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003025 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003026 {"winminheight", "wmh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003027 (char_u *)&p_wmh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003028 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003029 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003030 (char_u *)&p_wmw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003031 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003032 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar84ed4ad2017-08-17 11:33:42 +02003033#if defined(WIN3264) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003034 (char_u *)&p_winptydll, PV_NONE, {
3035# ifdef _WIN64
3036 (char_u *)"winpty64.dll",
3037# else
3038 (char_u *)"winpty32.dll",
3039# endif
3040 (char_u *)0L}
3041#else
3042 (char_u *)NULL, PV_NONE,
3043 {(char_u *)0L, (char_u *)0L}
3044#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003045 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003046 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003047 (char_u *)&p_wiw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003048 {(char_u *)20L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003049 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3050 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003051 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003052 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3053 (char_u *)&p_wm, PV_WM,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003054 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003055 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3056 (char_u *)&p_ws, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003057 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003058 {"write", NULL, P_BOOL|P_VI_DEF,
3059 (char_u *)&p_write, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003060 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003061 {"writeany", "wa", P_BOOL|P_VI_DEF,
3062 (char_u *)&p_wa, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003063 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003064 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3065 (char_u *)&p_wb, PV_NONE,
3066 {
3067#ifdef FEAT_WRITEBACKUP
3068 (char_u *)TRUE,
3069#else
3070 (char_u *)FALSE,
3071#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003072 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003073 {"writedelay", "wd", P_NUM|P_VI_DEF,
3074 (char_u *)&p_wd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003075 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003076
3077/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003078#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003079 (char_u *)&vvv, PV_NONE, \
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003080 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003081
3082 p_term("t_AB", T_CAB)
3083 p_term("t_AF", T_CAF)
3084 p_term("t_AL", T_CAL)
3085 p_term("t_al", T_AL)
3086 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003087 p_term("t_BE", T_BE)
3088 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003089 p_term("t_cd", T_CD)
3090 p_term("t_ce", T_CE)
3091 p_term("t_cl", T_CL)
3092 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003093 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003094 p_term("t_Co", T_CCO)
3095 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003096 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003097 p_term("t_cs", T_CS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003098 p_term("t_CV", T_CSV)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003099 p_term("t_da", T_DA)
3100 p_term("t_db", T_DB)
3101 p_term("t_DL", T_CDL)
3102 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003103 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003104 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003105 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003106 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003107 p_term("t_IE", T_CIE)
3108 p_term("t_IS", T_CIS)
3109 p_term("t_ke", T_KE)
3110 p_term("t_ks", T_KS)
3111 p_term("t_le", T_LE)
3112 p_term("t_mb", T_MB)
3113 p_term("t_md", T_MD)
3114 p_term("t_me", T_ME)
3115 p_term("t_mr", T_MR)
3116 p_term("t_ms", T_MS)
3117 p_term("t_nd", T_ND)
3118 p_term("t_op", T_OP)
Bram Moolenaara20f83d2017-10-15 13:35:01 +02003119 p_term("t_RF", T_RFG)
Bram Moolenaare5401222015-06-25 19:16:56 +02003120 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003121 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003122 p_term("t_RI", T_CRI)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003123 p_term("t_Ri", T_SRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003124 p_term("t_RS", T_CRS)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003125 p_term("t_RT", T_CRT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003126 p_term("t_RV", T_CRV)
3127 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003128 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003129 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003130 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003131 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003132 p_term("t_SI", T_CSI)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003133 p_term("t_Si", T_SSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003134 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003135 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003136 p_term("t_sr", T_SR)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003137 p_term("t_ST", T_CST)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003138 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003139 p_term("t_te", T_TE)
3140 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003141 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003142 p_term("t_ts", T_TS)
3143 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003144 p_term("t_ue", T_UE)
3145 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003146 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003147 p_term("t_vb", T_VB)
3148 p_term("t_ve", T_VE)
3149 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003150 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003151 p_term("t_vs", T_VS)
3152 p_term("t_WP", T_CWP)
3153 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003154 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003155 p_term("t_xs", T_XS)
3156 p_term("t_ZH", T_CZH)
3157 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003158 p_term("t_8f", T_8F)
3159 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003160
3161/* terminal key codes are not in here */
3162
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003163 /* end marker */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003164 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCTX_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003165};
3166
3167#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3168
Bram Moolenaar071d4272004-06-13 20:20:40 +00003169static char *(p_ambw_values[]) = {"single", "double", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003170static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003171static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003172static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003173#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003174static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003175#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003176#ifdef FEAT_CMDL_COMPL
3177static char *(p_wop_values[]) = {"tagfile", NULL};
3178#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003179#ifdef FEAT_WAK
3180static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3181#endif
3182static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003183static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3184static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003185static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003186#ifdef FEAT_BROWSE
3187static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3188#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003189static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
Bram Moolenaar57657d82006-04-21 22:12:41 +00003190static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003191static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
Bram Moolenaarf2732452018-06-03 14:47:35 +02003192static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", "prompt", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003193static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003194static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3195#ifdef FEAT_FOLDING
3196static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003197# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003198 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003199# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003200 NULL};
3201static char *(p_fcl_values[]) = {"all", NULL};
3202#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003203#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003204static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003205#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003206#ifdef FEAT_SIGNS
3207static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3208#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003209
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003210static void set_options_default(int opt_flags);
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003211static void set_string_default_esc(char *name, char_u *val, int escape);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003212static char_u *term_bg_default(void);
Bram Moolenaar916a8182018-11-25 02:18:29 +01003213static void did_set_option(int opt_idx, int opt_flags, int new_value, int value_checked);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003214static char_u *option_expand(int opt_idx, char_u *val);
3215static void didset_options(void);
3216static void didset_options2(void);
3217static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003218#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003219static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003220#else
3221# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3222#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003223static void set_string_option_global(int opt_idx, char_u **varp);
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003224static 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);
3225static char *set_chars_option(char_u **varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003226#ifdef FEAT_CLIPBOARD
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003227static char *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003228#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003229#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003230static char *did_set_spell_option(int is_spellfile);
3231static char *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003232#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003233#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003234static void set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003235#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003236static char *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3237static 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 +01003238static void check_redraw(long_u flags);
3239static int findoption(char_u *);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02003240static int find_key_option(char_u *arg_arg, int has_lt);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003241static void showoptions(int all, int opt_flags);
3242static int optval_default(struct vimoption *, char_u *varp);
3243static void showoneopt(struct vimoption *, int opt_flags);
Bram Moolenaared18f2c2019-01-24 20:30:52 +01003244static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, long_u flags);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003245static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3246static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3247static int istermoption(struct vimoption *);
3248static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3249static char_u *get_varp(struct vimoption *);
3250static void option_value2string(struct vimoption *, int opt_flags);
3251static void check_winopt(winopt_T *wop);
3252static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003253#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003254static void langmap_init(void);
3255static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003256#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003257static void paste_option_changed(void);
3258static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003259#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003260static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003261#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003262static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3263static int check_opt_strings(char_u *val, char **values, int);
3264static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003265#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003266static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003267#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003268
3269/*
3270 * Initialize the options, first part.
3271 *
3272 * Called only once from main(), just after creating the first buffer.
Bram Moolenaar07268702018-03-01 21:57:32 +01003273 * If "clean_arg" is TRUE Vim was started with --clean.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003274 */
3275 void
Bram Moolenaar07268702018-03-01 21:57:32 +01003276set_init_1(int clean_arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003277{
3278 char_u *p;
3279 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003280 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003281
3282#ifdef FEAT_LANGMAP
3283 langmap_init();
3284#endif
3285
3286 /* Be Vi compatible by default */
3287 p_cp = TRUE;
3288
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003289 /* Use POSIX compatibility when $VIM_POSIX is set. */
3290 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003291 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003292 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003293 set_string_default("shm", (char_u *)"A");
3294 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003295
Bram Moolenaar071d4272004-06-13 20:20:40 +00003296 /*
3297 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003298 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003299 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003300 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003301#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003302 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003303# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003304 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003305# endif
3306#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003307 )
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003308 set_string_default_esc("sh", p, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003309
3310#ifdef FEAT_WILDIGN
3311 /*
3312 * Set the default for 'backupskip' to include environment variables for
3313 * temp files.
3314 */
3315 {
3316# ifdef UNIX
3317 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3318# else
3319 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3320# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003321 int len;
3322 garray_T ga;
3323 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003324
3325 ga_init2(&ga, 1, 100);
3326 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3327 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003328 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003329# ifdef UNIX
3330 if (*names[n] == NUL)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003331# ifdef MACOS_X
3332 p = (char_u *)"/private/tmp";
3333# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003334 p = (char_u *)"/tmp";
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003335# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003336 else
3337# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003338 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003339 if (p != NULL && *p != NUL)
3340 {
3341 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003342 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003343 if (ga_grow(&ga, len) == OK)
3344 {
3345 if (ga.ga_len > 0)
3346 STRCAT(ga.ga_data, ",");
3347 STRCAT(ga.ga_data, p);
3348 add_pathsep(ga.ga_data);
3349 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003350 ga.ga_len += len;
3351 }
3352 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003353 if (mustfree)
3354 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003355 }
3356 if (ga.ga_data != NULL)
3357 {
3358 set_string_default("bsk", ga.ga_data);
3359 vim_free(ga.ga_data);
3360 }
3361 }
3362#endif
3363
3364 /*
3365 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3366 */
3367 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003368 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003369 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003370#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3371 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3372#endif
3373 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003374#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003375 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003376 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003377#else
3378# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003379 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003380 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003381# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003382 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003383# endif
3384#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003385 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003386 opt_idx = findoption((char_u *)"maxmem");
3387 if (opt_idx >= 0)
3388 {
3389#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003390 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3391 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003392#endif
3393 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3394 }
3395 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003396 }
3397
Bram Moolenaar071d4272004-06-13 20:20:40 +00003398#ifdef FEAT_SEARCHPATH
3399 {
3400 char_u *cdpath;
3401 char_u *buf;
3402 int i;
3403 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003404 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003405
3406 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003407 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003408 if (cdpath != NULL)
3409 {
3410 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3411 if (buf != NULL)
3412 {
3413 buf[0] = ','; /* start with ",", current dir first */
3414 j = 1;
3415 for (i = 0; cdpath[i] != NUL; ++i)
3416 {
3417 if (vim_ispathlistsep(cdpath[i]))
3418 buf[j++] = ',';
3419 else
3420 {
3421 if (cdpath[i] == ' ' || cdpath[i] == ',')
3422 buf[j++] = '\\';
3423 buf[j++] = cdpath[i];
3424 }
3425 }
3426 buf[j] = NUL;
3427 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003428 if (opt_idx >= 0)
3429 {
3430 options[opt_idx].def_val[VI_DEFAULT] = buf;
3431 options[opt_idx].flags |= P_DEF_ALLOCED;
3432 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003433 else
3434 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003435 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003436 if (mustfree)
3437 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003438 }
3439 }
3440#endif
3441
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003442#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003443 /* Set print encoding on platforms that don't default to latin1 */
3444 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003445# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003446 (char_u *)"cp1252"
3447# else
3448# ifdef VMS
3449 (char_u *)"dec-mcs"
3450# else
3451# ifdef EBCDIC
3452 (char_u *)"ebcdic-uk"
3453# else
3454# ifdef MAC
3455 (char_u *)"mac-roman"
3456# else /* HPUX */
3457 (char_u *)"hp-roman8"
3458# endif
3459# endif
3460# endif
3461# endif
3462 );
3463#endif
3464
3465#ifdef FEAT_POSTSCRIPT
3466 /* 'printexpr' must be allocated to be able to evaluate it. */
3467 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003468# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003469 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003470# else
3471# ifdef VMS
3472 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3473
3474# else
3475 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3476# endif
3477# endif
3478 );
3479#endif
3480
3481 /*
3482 * Set all the options (except the terminal options) to their default
3483 * value. Also set the global value for local options.
3484 */
3485 set_options_default(0);
3486
Bram Moolenaar07268702018-03-01 21:57:32 +01003487#ifdef CLEAN_RUNTIMEPATH
3488 if (clean_arg)
3489 {
3490 opt_idx = findoption((char_u *)"runtimepath");
3491 if (opt_idx >= 0)
3492 {
3493 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3494 p_rtp = (char_u *)CLEAN_RUNTIMEPATH;
3495 }
3496 opt_idx = findoption((char_u *)"packpath");
3497 if (opt_idx >= 0)
3498 {
3499 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3500 p_pp = (char_u *)CLEAN_RUNTIMEPATH;
3501 }
3502 }
3503#endif
3504
Bram Moolenaar071d4272004-06-13 20:20:40 +00003505#ifdef FEAT_GUI
3506 if (found_reverse_arg)
3507 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3508#endif
3509
3510 curbuf->b_p_initialized = TRUE;
3511 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003512 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003513 check_buf_options(curbuf);
3514 check_win_options(curwin);
3515 check_options();
3516
3517 /* Must be before option_expand(), because that one needs vim_isIDc() */
3518 didset_options();
3519
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003520#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003521 /* Use the current chartab for the generic chartab. This is not in
3522 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003523 init_spell_chartab();
3524#endif
3525
Bram Moolenaar071d4272004-06-13 20:20:40 +00003526 /*
3527 * Expand environment variables and things like "~" for the defaults.
3528 * If option_expand() returns non-NULL the variable is expanded. This can
3529 * only happen for non-indirect options.
3530 * Also set the default to the expanded value, so ":set" does not list
3531 * them.
3532 * Don't set the P_ALLOCED flag, because we don't want to free the
3533 * default.
3534 */
3535 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3536 {
3537 if ((options[opt_idx].flags & P_GETTEXT)
3538 && options[opt_idx].var != NULL)
3539 p = (char_u *)_(*(char **)options[opt_idx].var);
3540 else
3541 p = option_expand(opt_idx, NULL);
3542 if (p != NULL && (p = vim_strsave(p)) != NULL)
3543 {
3544 *(char_u **)options[opt_idx].var = p;
3545 /* VIMEXP
3546 * Defaults for all expanded options are currently the same for Vi
3547 * and Vim. When this changes, add some code here! Also need to
3548 * split P_DEF_ALLOCED in two.
3549 */
3550 if (options[opt_idx].flags & P_DEF_ALLOCED)
3551 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3552 options[opt_idx].def_val[VI_DEFAULT] = p;
3553 options[opt_idx].flags |= P_DEF_ALLOCED;
3554 }
3555 }
3556
Bram Moolenaar071d4272004-06-13 20:20:40 +00003557 save_file_ff(curbuf); /* Buffer is unchanged */
3558
Bram Moolenaar071d4272004-06-13 20:20:40 +00003559#if defined(FEAT_ARABIC)
3560 /* Detect use of mlterm.
3561 * Mlterm is a terminal emulator akin to xterm that has some special
3562 * abilities (bidi namely).
3563 * NOTE: mlterm's author is being asked to 'set' a variable
3564 * instead of an environment variable due to inheritance.
3565 */
3566 if (mch_getenv((char_u *)"MLTERM") != NULL)
3567 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3568#endif
3569
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003570 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003571
Bram Moolenaar071d4272004-06-13 20:20:40 +00003572# if defined(WIN3264) && defined(FEAT_GETTEXT)
3573 /*
3574 * If $LANG isn't set, try to get a good value for it. This makes the
3575 * right language be used automatically. Don't do this for English.
3576 */
3577 if (mch_getenv((char_u *)"LANG") == NULL)
3578 {
3579 char buf[20];
3580
3581 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3582 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3583 * only the first two. */
3584 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3585 (LPTSTR)buf, 20);
3586 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3587 {
3588 /* There are a few exceptions (probably more) */
3589 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3590 STRCPY(buf, "zh_TW");
3591 else if (STRNICMP(buf, "chs", 3) == 0
3592 || STRNICMP(buf, "zhc", 3) == 0)
3593 STRCPY(buf, "zh_CN");
3594 else if (STRNICMP(buf, "jp", 2) == 0)
3595 STRCPY(buf, "ja");
3596 else
3597 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003598 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003599 }
3600 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003601# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003602# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003603 /* Moved to os_mac_conv.c to avoid dependency problems. */
3604 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003605# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003606# endif
3607
3608 /* enc_locale() will try to find the encoding of the current locale. */
3609 p = enc_locale();
3610 if (p != NULL)
3611 {
3612 char_u *save_enc;
3613
3614 /* Try setting 'encoding' and check if the value is valid.
3615 * If not, go back to the default "latin1". */
3616 save_enc = p_enc;
3617 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003618 if (STRCMP(p_enc, "gb18030") == 0)
3619 {
3620 /* We don't support "gb18030", but "cp936" is a good substitute
3621 * for practical purposes, thus use that. It's not an alias to
3622 * still support conversion between gb18030 and utf-8. */
3623 p_enc = vim_strsave((char_u *)"cp936");
3624 vim_free(p);
3625 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003626 if (mb_init() == NULL)
3627 {
3628 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003629 if (opt_idx >= 0)
3630 {
3631 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3632 options[opt_idx].flags |= P_DEF_ALLOCED;
3633 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003634
Bram Moolenaard0573012017-10-28 21:11:06 +02003635#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003636 if (STRCMP(p_enc, "latin1") == 0 || enc_utf8)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003637 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003638 /* Adjust the default for 'isprint' and 'iskeyword' to match
3639 * latin1. Also set the defaults for when 'nocompatible' is
3640 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003641 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003642 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003643 set_string_option_direct((char_u *)"isk", -1,
3644 ISK_LATIN1, OPT_FREE, SID_NONE);
3645 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003646 if (opt_idx >= 0)
3647 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003648 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003649 if (opt_idx >= 0)
3650 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003651 (void)init_chartab();
3652 }
3653#endif
3654
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003655#if defined(WIN3264) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003656 /* Win32 console: When GetACP() returns a different value from
3657 * GetConsoleCP() set 'termencoding'. */
3658 if (GetACP() != GetConsoleCP())
3659 {
3660 char buf[50];
3661
3662 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3663 p_tenc = vim_strsave((char_u *)buf);
3664 if (p_tenc != NULL)
3665 {
3666 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003667 if (opt_idx >= 0)
3668 {
3669 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3670 options[opt_idx].flags |= P_DEF_ALLOCED;
3671 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003672 convert_setup(&input_conv, p_tenc, p_enc);
3673 convert_setup(&output_conv, p_enc, p_tenc);
3674 }
3675 else
3676 p_tenc = empty_option;
3677 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003678#endif
3679#if defined(WIN3264)
Bram Moolenaar05159a02005-02-26 23:04:13 +00003680 /* $HOME may have characters in active code page. */
3681 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003682#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003683 }
3684 else
3685 {
3686 vim_free(p_enc);
3687 p_enc = save_enc;
3688 }
3689 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003690
3691#ifdef FEAT_MULTI_LANG
3692 /* Set the default for 'helplang'. */
3693 set_helplang_default(get_mess_lang());
3694#endif
3695}
3696
3697/*
3698 * Set an option to its default value.
3699 * This does not take care of side effects!
3700 */
3701 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003702set_option_default(
3703 int opt_idx,
3704 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3705 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003706{
3707 char_u *varp; /* pointer to variable for current option */
3708 int dvi; /* index in def_val[] */
3709 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003710 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003711 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3712
3713 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3714 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003715 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003716 {
3717 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3718 if (flags & P_STRING)
3719 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003720 /* Use set_string_option_direct() for local options to handle
3721 * freeing and allocating the value. */
3722 if (options[opt_idx].indir != PV_NONE)
3723 set_string_option_direct(NULL, opt_idx,
3724 options[opt_idx].def_val[dvi], opt_flags, 0);
3725 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003726 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003727 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3728 free_string_option(*(char_u **)(varp));
3729 *(char_u **)varp = options[opt_idx].def_val[dvi];
3730 options[opt_idx].flags &= ~P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003731 }
3732 }
3733 else if (flags & P_NUM)
3734 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003735 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003736 win_comp_scroll(curwin);
3737 else
3738 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003739 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003740 /* May also set global value for local option. */
3741 if (both)
3742 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3743 *(long *)varp;
3744 }
3745 }
3746 else /* P_BOOL */
3747 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003748 /* the cast to long is required for Manx C, long_i is needed for
3749 * MSVC */
3750 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003751#ifdef UNIX
3752 /* 'modeline' defaults to off for root */
3753 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3754 *(int *)varp = FALSE;
3755#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003756 /* May also set global value for local option. */
3757 if (both)
3758 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3759 *(int *)varp;
3760 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003761
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003762 /* The default value is not insecure. */
3763 flagsp = insecure_flag(opt_idx, opt_flags);
3764 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003765 }
3766
3767#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003768 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003769#endif
3770}
3771
3772/*
3773 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003774 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003775 */
3776 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003777set_options_default(
3778 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003779{
3780 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003781 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003782 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003783
3784 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003785 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003786 && (opt_flags == 0
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003787 || (options[i].var != (char_u *)&p_enc
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003788# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003789 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003790 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003791# endif
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003792 )))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003793 set_option_default(i, opt_flags, p_cp);
3794
Bram Moolenaar071d4272004-06-13 20:20:40 +00003795 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003796 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003797 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003798#ifdef FEAT_CINDENT
3799 parse_cino(curbuf);
3800#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003801}
3802
3803/*
3804 * Set the Vi-default value of a string option.
3805 * Used for 'sh', 'backupskip' and 'term'.
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003806 * When "escape" is TRUE escape spaces with a backslash.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003807 */
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003808 static void
3809set_string_default_esc(char *name, char_u *val, int escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003810{
3811 char_u *p;
3812 int opt_idx;
3813
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003814 if (escape && vim_strchr(val, ' ') != NULL)
3815 p = vim_strsave_escaped(val, (char_u *)" ");
3816 else
3817 p = vim_strsave(val);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003818 if (p != NULL) /* we don't want a NULL */
3819 {
3820 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003821 if (opt_idx >= 0)
3822 {
3823 if (options[opt_idx].flags & P_DEF_ALLOCED)
3824 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3825 options[opt_idx].def_val[VI_DEFAULT] = p;
3826 options[opt_idx].flags |= P_DEF_ALLOCED;
3827 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003828 }
3829}
3830
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003831 void
3832set_string_default(char *name, char_u *val)
3833{
3834 set_string_default_esc(name, val, FALSE);
3835}
3836
Bram Moolenaar071d4272004-06-13 20:20:40 +00003837/*
3838 * Set the Vi-default value of a number option.
3839 * Used for 'lines' and 'columns'.
3840 */
3841 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003842set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003843{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003844 int opt_idx;
3845
3846 opt_idx = findoption((char_u *)name);
3847 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003848 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003849}
3850
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003851#if defined(EXITFREE) || defined(PROTO)
3852/*
3853 * Free all options.
3854 */
3855 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003856free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003857{
3858 int i;
3859
3860 for (i = 0; !istermoption(&options[i]); i++)
3861 {
3862 if (options[i].indir == PV_NONE)
3863 {
3864 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003865 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003866 free_string_option(*(char_u **)options[i].var);
3867 if (options[i].flags & P_DEF_ALLOCED)
3868 free_string_option(options[i].def_val[VI_DEFAULT]);
3869 }
3870 else if (options[i].var != VAR_WIN
3871 && (options[i].flags & P_STRING))
3872 /* buffer-local option: free global value */
3873 free_string_option(*(char_u **)options[i].var);
3874 }
3875}
3876#endif
3877
3878
Bram Moolenaar071d4272004-06-13 20:20:40 +00003879/*
3880 * Initialize the options, part two: After getting Rows and Columns and
3881 * setting 'term'.
3882 */
3883 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003884set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003885{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003886 int idx;
3887
Bram Moolenaar071d4272004-06-13 20:20:40 +00003888 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003889 * 'scroll' defaults to half the window height. The stored default is zero,
3890 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003891 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003892 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003893 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003894 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003895 comp_col();
3896
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003897 /*
3898 * 'window' is only for backwards compatibility with Vi.
3899 * Default is Rows - 1.
3900 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003901 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003902 p_window = Rows - 1;
3903 set_number_default("window", Rows - 1);
3904
Bram Moolenaarf740b292006-02-16 22:11:02 +00003905 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003906#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003907 /*
3908 * If 'background' wasn't set by the user, try guessing the value,
3909 * depending on the terminal name. Only need to check for terminals
3910 * with a dark background, that can handle color.
3911 */
3912 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003913 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3914 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003915 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003916 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003917 /* don't mark it as set, when starting the GUI it may be
3918 * changed again */
3919 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003920 }
3921#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003922
3923#ifdef CURSOR_SHAPE
3924 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3925#endif
3926#ifdef FEAT_MOUSESHAPE
3927 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3928#endif
3929#ifdef FEAT_PRINTER
3930 (void)parse_printoptions(); /* parse 'printoptions' default value */
3931#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003932}
3933
3934/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003935 * Return "dark" or "light" depending on the kind of terminal.
3936 * This is just guessing! Recognized are:
3937 * "linux" Linux console
3938 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003939 * "cygwin.*" Cygwin shell
3940 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00003941 * We also check the COLORFGBG environment variable, which is set by
3942 * rxvt and derivatives. This variable contains either two or three
3943 * values separated by semicolons; we want the last value in either
3944 * case. If this value is 0-6 or 8, our background is dark.
3945 */
3946 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003947term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003948{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003949#if defined(WIN3264)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003950 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003951 return (char_u *)"dark";
3952#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003953 char_u *p;
3954
Bram Moolenaarf740b292006-02-16 22:11:02 +00003955 if (STRCMP(T_NAME, "linux") == 0
3956 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003957 || STRNCMP(T_NAME, "cygwin", 6) == 0
3958 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00003959 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3960 && (p = vim_strrchr(p, ';')) != NULL
3961 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3962 && p[2] == NUL))
3963 return (char_u *)"dark";
3964 return (char_u *)"light";
3965#endif
3966}
3967
3968/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003969 * Initialize the options, part three: After reading the .vimrc
3970 */
3971 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003972set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003973{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003974#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003975/*
3976 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3977 * This is done after other initializations, where 'shell' might have been
3978 * set, but only if they have not been set before.
3979 */
3980 char_u *p;
3981 int idx_srr;
3982 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003983# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003984 int idx_sp;
3985 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003986# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003987
3988 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003989 if (idx_srr < 0)
3990 do_srr = FALSE;
3991 else
3992 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003993# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003994 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003995 if (idx_sp < 0)
3996 do_sp = FALSE;
3997 else
3998 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003999# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004000 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004001 if (p != NULL)
4002 {
4003 /*
4004 * Default for p_sp is "| tee", for p_srr is ">".
4005 * For known shells it is changed here to include stderr.
4006 */
4007 if ( fnamecmp(p, "csh") == 0
4008 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004009# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004010 || fnamecmp(p, "csh.exe") == 0
4011 || fnamecmp(p, "tcsh.exe") == 0
4012# endif
4013 )
4014 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004015# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004016 if (do_sp)
4017 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004018# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004019 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004020# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004021 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004022# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004023 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4024 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004025# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004026 if (do_srr)
4027 {
4028 p_srr = (char_u *)">&";
4029 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4030 }
4031 }
4032 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004033 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004034 if ( fnamecmp(p, "sh") == 0
4035 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004036 || fnamecmp(p, "mksh") == 0
4037 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004038 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004039 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004040 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004041 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004042# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004043 || fnamecmp(p, "cmd") == 0
4044 || fnamecmp(p, "sh.exe") == 0
4045 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004046 || fnamecmp(p, "mksh.exe") == 0
4047 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004048 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004049 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004050 || fnamecmp(p, "bash.exe") == 0
4051 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004052# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004053 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004054 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004055# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004056 if (do_sp)
4057 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004058# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004059 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004060# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004061 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004062# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004063 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4064 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004065# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004066 if (do_srr)
4067 {
4068 p_srr = (char_u *)">%s 2>&1";
4069 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4070 }
4071 }
4072 vim_free(p);
4073 }
4074#endif
4075
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004076#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004077 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004078 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4079 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004080 * This is done after other initializations, where 'shell' might have been
4081 * set, but only if they have not been set before. Default for p_shcf is
4082 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004083 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004084 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004085 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004086 {
4087 int idx3;
4088
4089 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004090 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004091 {
4092 p_shcf = (char_u *)"-c";
4093 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4094 }
4095
Bram Moolenaar071d4272004-06-13 20:20:40 +00004096 /* Somehow Win32 requires the quotes around the redirection too */
4097 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004098 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004099 {
4100 p_sxq = (char_u *)"\"";
4101 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4102 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004103 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004104 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4105 {
4106 int idx3;
4107
4108 /*
4109 * cmd.exe on Windows will strip the first and last double quote given
4110 * on the command line, e.g. most of the time things like:
4111 * cmd /c "my path/to/echo" "my args to echo"
4112 * become:
4113 * my path/to/echo" "my args to echo
4114 * when executed.
4115 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004116 * To avoid this, set shellxquote to surround the command in
4117 * parenthesis. This appears to make most commands work, without
4118 * breaking commands that worked previously, such as
4119 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004120 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004121 idx3 = findoption((char_u *)"sxq");
4122 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4123 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004124 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004125 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4126 }
4127
Bram Moolenaara64ba222012-02-12 23:23:31 +01004128 idx3 = findoption((char_u *)"shcf");
4129 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4130 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004131 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004132 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4133 }
4134 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004135#endif
4136
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004137 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004138 {
4139 int idx_ffs = findoption((char_u *)"ffs");
4140
4141 /* Apply the first entry of 'fileformats' to the initial buffer. */
4142 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4143 set_fileformat(default_fileformat(), OPT_LOCAL);
4144 }
4145
Bram Moolenaar071d4272004-06-13 20:20:40 +00004146#ifdef FEAT_TITLE
4147 set_title_defaults();
4148#endif
4149}
4150
4151#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4152/*
4153 * When 'helplang' is still at its default value, set it to "lang".
4154 * Only the first two characters of "lang" are used.
4155 */
4156 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004157set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004158{
4159 int idx;
4160
4161 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4162 return;
4163 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004164 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004165 {
4166 if (options[idx].flags & P_ALLOCED)
4167 free_string_option(p_hlg);
4168 p_hlg = vim_strsave(lang);
4169 if (p_hlg == NULL)
4170 p_hlg = empty_option;
4171 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004172 {
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004173 // zh_CN becomes "cn", zh_TW becomes "tw"
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004174 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4175 {
4176 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4177 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4178 }
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004179 // any C like setting, such as C.UTF-8, becomes "en"
4180 else if (STRLEN(p_hlg) >= 1 && *p_hlg == 'C')
4181 {
4182 p_hlg[0] = 'e';
4183 p_hlg[1] = 'n';
4184 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004185 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004186 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004187 options[idx].flags |= P_ALLOCED;
4188 }
4189}
4190#endif
4191
4192#ifdef FEAT_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00004193 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004194gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004195{
4196 if (gui_get_lightness(gui.back_pixel) < 127)
4197 return (char_u *)"dark";
4198 return (char_u *)"light";
4199}
4200
4201/*
4202 * Option initializations that can only be done after opening the GUI window.
4203 */
4204 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004205init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004206{
4207 /* Set the 'background' option according to the lightness of the
4208 * background color, unless the user has set it already. */
4209 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4210 {
4211 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4212 highlight_changed();
4213 }
4214}
4215#endif
4216
4217#ifdef FEAT_TITLE
4218/*
4219 * 'title' and 'icon' only default to true if they have not been set or reset
4220 * in .vimrc and we can read the old value.
4221 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4222 * they can be reset. This reduces startup time when using X on a remote
4223 * machine.
4224 */
4225 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004226set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004227{
4228 int idx1;
4229 long val;
4230
4231 /*
4232 * If GUI is (going to be) used, we can always set the window title and
4233 * icon name. Saves a bit of time, because the X11 display server does
4234 * not need to be contacted.
4235 */
4236 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004237 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004238 {
4239#ifdef FEAT_GUI
4240 if (gui.starting || gui.in_use)
4241 val = TRUE;
4242 else
4243#endif
4244 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004245 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004246 p_title = val;
4247 }
4248 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004249 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004250 {
4251#ifdef FEAT_GUI
4252 if (gui.starting || gui.in_use)
4253 val = TRUE;
4254 else
4255#endif
4256 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004257 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004258 p_icon = val;
4259 }
4260}
4261#endif
4262
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004263#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004264 static void
4265trigger_optionsset_string(
4266 int opt_idx,
4267 int opt_flags,
4268 char_u *oldval,
4269 char_u *newval)
4270{
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02004271 // Don't do this recursively.
4272 if (oldval != NULL && newval != NULL
4273 && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004274 {
4275 char_u buf_type[7];
4276
4277 sprintf((char *)buf_type, "%s",
4278 (opt_flags & OPT_LOCAL) ? "local" : "global");
4279 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4280 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4281 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4282 apply_autocmds(EVENT_OPTIONSET,
4283 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4284 reset_v_option_vars();
4285 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004286}
4287#endif
4288
Bram Moolenaar071d4272004-06-13 20:20:40 +00004289/*
4290 * Parse 'arg' for option settings.
4291 *
4292 * 'arg' may be IObuff, but only when no errors can be present and option
4293 * does not need to be expanded with option_expand().
4294 * "opt_flags":
4295 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004296 * OPT_GLOBAL for ":setglobal"
4297 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004298 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004299 * OPT_WINONLY to only set window-local options
4300 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004301 *
4302 * returns FAIL if an error is detected, OK otherwise
4303 */
4304 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004305do_set(
4306 char_u *arg, /* option string (may be written to!) */
4307 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004308{
4309 int opt_idx;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004310 char *errmsg;
4311 char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00004312 char_u *startarg;
4313 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4314 int nextchar; /* next non-white char after option name */
4315 int afterchar; /* character just after option name */
4316 int len;
4317 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004318 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004319 int key;
4320 long_u flags; /* flags for current option */
4321 char_u *varp = NULL; /* pointer to variable for current option */
4322 int did_show = FALSE; /* already showed one value */
4323 int adding; /* "opt+=arg" */
4324 int prepending; /* "opt^=arg" */
4325 int removing; /* "opt-=arg" */
4326 int cp_val = 0;
4327 char_u key_name[2];
4328
4329 if (*arg == NUL)
4330 {
4331 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004332 did_show = TRUE;
4333 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004334 }
4335
4336 while (*arg != NUL) /* loop to process all options */
4337 {
4338 errmsg = NULL;
4339 startarg = arg; /* remember for error message */
4340
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004341 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4342 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004343 {
4344 /*
4345 * ":set all" show all options.
4346 * ":set all&" set all options to their default value.
4347 */
4348 arg += 3;
4349 if (*arg == '&')
4350 {
4351 ++arg;
4352 /* Only for :set command set global value of local options. */
4353 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004354 didset_options();
4355 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004356 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004357 }
4358 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004359 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004360 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004361 did_show = TRUE;
4362 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004363 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004364 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004365 {
4366 showoptions(2, opt_flags);
4367 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004368 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004369 arg += 7;
4370 }
4371 else
4372 {
4373 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004374 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004375 {
4376 prefix = 0;
4377 arg += 2;
4378 }
4379 else if (STRNCMP(arg, "inv", 3) == 0)
4380 {
4381 prefix = 2;
4382 arg += 3;
4383 }
4384
4385 /* find end of name */
4386 key = 0;
4387 if (*arg == '<')
4388 {
4389 nextchar = 0;
4390 opt_idx = -1;
4391 /* look out for <t_>;> */
4392 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4393 len = 5;
4394 else
4395 {
4396 len = 1;
4397 while (arg[len] != NUL && arg[len] != '>')
4398 ++len;
4399 }
4400 if (arg[len] != '>')
4401 {
4402 errmsg = e_invarg;
4403 goto skip;
4404 }
4405 arg[len] = NUL; /* put NUL after name */
4406 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4407 opt_idx = findoption(arg + 1);
4408 arg[len++] = '>'; /* restore '>' */
4409 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004410 key = find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004411 }
4412 else
4413 {
4414 len = 0;
4415 /*
4416 * The two characters after "t_" may not be alphanumeric.
4417 */
4418 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4419 len = 4;
4420 else
4421 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4422 ++len;
4423 nextchar = arg[len];
4424 arg[len] = NUL; /* put NUL after name */
4425 opt_idx = findoption(arg);
4426 arg[len] = nextchar; /* restore nextchar */
4427 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004428 key = find_key_option(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004429 }
4430
4431 /* remember character after option name */
4432 afterchar = arg[len];
4433
4434 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004435 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004436 ++len;
4437
4438 adding = FALSE;
4439 prepending = FALSE;
4440 removing = FALSE;
4441 if (arg[len] != NUL && arg[len + 1] == '=')
4442 {
4443 if (arg[len] == '+')
4444 {
4445 adding = TRUE; /* "+=" */
4446 ++len;
4447 }
4448 else if (arg[len] == '^')
4449 {
4450 prepending = TRUE; /* "^=" */
4451 ++len;
4452 }
4453 else if (arg[len] == '-')
4454 {
4455 removing = TRUE; /* "-=" */
4456 ++len;
4457 }
4458 }
4459 nextchar = arg[len];
4460
4461 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4462 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004463 errmsg = N_("E518: Unknown option");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004464 goto skip;
4465 }
4466
4467 if (opt_idx >= 0)
4468 {
4469 if (options[opt_idx].var == NULL) /* hidden option: skip */
4470 {
4471 /* Only give an error message when requesting the value of
4472 * a hidden option, ignore setting it. */
4473 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4474 && (!(options[opt_idx].flags & P_BOOL)
4475 || nextchar == '?'))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004476 errmsg = N_("E519: Option not supported");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004477 goto skip;
4478 }
4479
4480 flags = options[opt_idx].flags;
4481 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4482 }
4483 else
4484 {
4485 flags = P_STRING;
4486 if (key < 0)
4487 {
4488 key_name[0] = KEY2TERMCAP0(key);
4489 key_name[1] = KEY2TERMCAP1(key);
4490 }
4491 else
4492 {
4493 key_name[0] = KS_KEY;
4494 key_name[1] = (key & 0xff);
4495 }
4496 }
4497
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004498 /* Skip all options that are not window-local (used when showing
4499 * an already loaded buffer in a window). */
4500 if ((opt_flags & OPT_WINONLY)
4501 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4502 goto skip;
4503
Bram Moolenaara3227e22006-03-08 21:32:40 +00004504 /* Skip all options that are window-local (used for :vimgrep). */
4505 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4506 && options[opt_idx].var == VAR_WIN)
4507 goto skip;
4508
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004509 /* Disallow changing some options from modelines. */
4510 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004511 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004512 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004513 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004514 errmsg = _("E520: Not allowed in a modeline");
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004515 goto skip;
4516 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004517#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004518 /* In diff mode some options are overruled. This avoids that
4519 * 'foldmethod' becomes "marker" instead of "diff" and that
4520 * "wrap" gets set. */
4521 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004522 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004523 && (
4524#ifdef FEAT_FOLDING
4525 options[opt_idx].indir == PV_FDM ||
4526#endif
4527 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004528 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004529#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004530 }
4531
4532#ifdef HAVE_SANDBOX
4533 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004534 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004535 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004536 errmsg = _(e_sandbox);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004537 goto skip;
4538 }
4539#endif
4540
4541 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4542 {
4543 arg += len;
4544 cp_val = p_cp;
4545 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4546 {
4547 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4548 {
4549 cp_val = FALSE;
4550 arg += 3;
4551 }
4552 else /* "opt&vi": set to Vi default */
4553 {
4554 cp_val = TRUE;
4555 arg += 2;
4556 }
4557 }
4558 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004559 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004560 {
4561 errmsg = e_trailing;
4562 goto skip;
4563 }
4564 }
4565
4566 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004567 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4568 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004569 */
4570 if (nextchar == '?'
4571 || (prefix == 1
4572 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4573 && !(flags & P_BOOL)))
4574 {
4575 /*
4576 * print value
4577 */
4578 if (did_show)
4579 msg_putchar('\n'); /* cursor below last one */
4580 else
4581 {
4582 gotocmdline(TRUE); /* cursor at status line */
4583 did_show = TRUE; /* remember that we did a line */
4584 }
4585 if (opt_idx >= 0)
4586 {
4587 showoneopt(&options[opt_idx], opt_flags);
4588#ifdef FEAT_EVAL
4589 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004590 {
4591 /* Mention where the option was last set. */
4592 if (varp == options[opt_idx].var)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004593 last_set_msg(options[opt_idx].script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004594 else if ((int)options[opt_idx].indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004595 last_set_msg(curwin->w_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004596 (int)options[opt_idx].indir & PV_MASK]);
4597 else if ((int)options[opt_idx].indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004598 last_set_msg(curbuf->b_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004599 (int)options[opt_idx].indir & PV_MASK]);
4600 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004601#endif
4602 }
4603 else
4604 {
4605 char_u *p;
4606
4607 p = find_termcode(key_name);
4608 if (p == NULL)
4609 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004610 errmsg = N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004611 goto skip;
4612 }
4613 else
4614 (void)show_one_termcode(key_name, p, TRUE);
4615 }
4616 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004617 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004618 errmsg = e_trailing;
4619 }
4620 else
4621 {
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004622 int value_is_replaced = !prepending && !adding && !removing;
Bram Moolenaar916a8182018-11-25 02:18:29 +01004623 int value_checked = FALSE;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004624
Bram Moolenaar071d4272004-06-13 20:20:40 +00004625 if (flags & P_BOOL) /* boolean */
4626 {
4627 if (nextchar == '=' || nextchar == ':')
4628 {
4629 errmsg = e_invarg;
4630 goto skip;
4631 }
4632
4633 /*
4634 * ":set opt!": invert
4635 * ":set opt&": reset to default value
4636 * ":set opt<": reset to global value
4637 */
4638 if (nextchar == '!')
4639 value = *(int *)(varp) ^ 1;
4640 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004641 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004642 ((flags & P_VI_DEF) || cp_val)
4643 ? VI_DEFAULT : VIM_DEFAULT];
4644 else if (nextchar == '<')
4645 {
4646 /* For 'autoread' -1 means to use global value. */
4647 if ((int *)varp == &curbuf->b_p_ar
4648 && opt_flags == OPT_LOCAL)
4649 value = -1;
4650 else
4651 value = *(int *)get_varp_scope(&(options[opt_idx]),
4652 OPT_GLOBAL);
4653 }
4654 else
4655 {
4656 /*
4657 * ":set invopt": invert
4658 * ":set opt" or ":set noopt": set or reset
4659 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004660 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004661 {
4662 errmsg = e_trailing;
4663 goto skip;
4664 }
4665 if (prefix == 2) /* inv */
4666 value = *(int *)(varp) ^ 1;
4667 else
4668 value = prefix;
4669 }
4670
4671 errmsg = set_bool_option(opt_idx, varp, (int)value,
4672 opt_flags);
4673 }
4674 else /* numeric or string */
4675 {
4676 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4677 || prefix != 1)
4678 {
4679 errmsg = e_invarg;
4680 goto skip;
4681 }
4682
4683 if (flags & P_NUM) /* numeric */
4684 {
4685 /*
4686 * Different ways to set a number option:
4687 * & set to default value
4688 * < set to global value
4689 * <xx> accept special key codes for 'wildchar'
4690 * c accept any non-digit for 'wildchar'
4691 * [-]0-9 set number
4692 * other error
4693 */
4694 ++arg;
4695 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004696 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004697 ((flags & P_VI_DEF) || cp_val)
4698 ? VI_DEFAULT : VIM_DEFAULT];
4699 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004700 {
4701 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4702 * use the global value. */
4703 if ((long *)varp == &curbuf->b_p_ul
4704 && opt_flags == OPT_LOCAL)
4705 value = NO_LOCAL_UNDOLEVEL;
4706 else
4707 value = *(long *)get_varp_scope(
4708 &(options[opt_idx]), OPT_GLOBAL);
4709 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004710 else if (((long *)varp == &p_wc
4711 || (long *)varp == &p_wcm)
4712 && (*arg == '<'
4713 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004714 || (*arg != NUL
4715 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004716 && !VIM_ISDIGIT(*arg))))
4717 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004718 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004719 if (value == 0 && (long *)varp != &p_wcm)
4720 {
4721 errmsg = e_invarg;
4722 goto skip;
4723 }
4724 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004725 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4726 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004727 /* Allow negative (for 'undolevels'), octal and
4728 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004729 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4730 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004731 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004732 {
4733 errmsg = e_invarg;
4734 goto skip;
4735 }
4736 }
4737 else
4738 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004739 errmsg = N_("E521: Number required after =");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004740 goto skip;
4741 }
4742
4743 if (adding)
4744 value = *(long *)varp + value;
4745 if (prepending)
4746 value = *(long *)varp * value;
4747 if (removing)
4748 value = *(long *)varp - value;
4749 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004750 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004751 }
4752 else if (opt_idx >= 0) /* string */
4753 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004754 char_u *save_arg = NULL;
4755 char_u *s = NULL;
4756 char_u *oldval = NULL; /* previous value if *varp */
4757 char_u *newval;
4758 char_u *origval = NULL;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004759#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004760 char_u *saved_origval = NULL;
4761 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004762#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004763 unsigned newlen;
4764 int comma;
4765 int bs;
4766 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004767 was allocated */
4768
4769 /* When using ":set opt=val" for a global option
4770 * with a local value the local value will be
4771 * reset, use the global value here. */
4772 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004773 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004774 varp = options[opt_idx].var;
4775
4776 /* The old value is kept until we are sure that the
4777 * new value is valid. */
4778 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004779
4780 /* When setting the local value of a global
4781 * option, the old value may be the global value. */
4782 if (((int)options[opt_idx].indir & PV_BOTH)
4783 && (opt_flags & OPT_LOCAL))
4784 origval = *(char_u **)get_varp(
4785 &options[opt_idx]);
4786 else
4787 origval = oldval;
4788
Bram Moolenaar071d4272004-06-13 20:20:40 +00004789 if (nextchar == '&') /* set to default val */
4790 {
4791 newval = options[opt_idx].def_val[
4792 ((flags & P_VI_DEF) || cp_val)
4793 ? VI_DEFAULT : VIM_DEFAULT];
4794 if ((char_u **)varp == &p_bg)
4795 {
4796 /* guess the value of 'background' */
4797#ifdef FEAT_GUI
4798 if (gui.in_use)
4799 newval = gui_bg_default();
4800 else
4801#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004802 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004803 }
4804
4805 /* expand environment variables and ~ (since the
4806 * default value was already expanded, only
4807 * required when an environment variable was set
4808 * later */
4809 if (newval == NULL)
4810 newval = empty_option;
4811 else
4812 {
4813 s = option_expand(opt_idx, newval);
4814 if (s == NULL)
4815 s = newval;
4816 newval = vim_strsave(s);
4817 }
4818 new_value_alloced = TRUE;
4819 }
4820 else if (nextchar == '<') /* set to global val */
4821 {
4822 newval = vim_strsave(*(char_u **)get_varp_scope(
4823 &(options[opt_idx]), OPT_GLOBAL));
4824 new_value_alloced = TRUE;
4825 }
4826 else
4827 {
4828 ++arg; /* jump to after the '=' or ':' */
4829
4830 /*
4831 * Set 'keywordprg' to ":help" if an empty
4832 * value was passed to :set by the user.
4833 * Misuse errbuf[] for the resulting string.
4834 */
4835 if (varp == (char_u *)&p_kp
4836 && (*arg == NUL || *arg == ' '))
4837 {
4838 STRCPY(errbuf, ":help");
4839 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004840 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004841 }
4842 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004843 * Convert 'backspace' number to string, for
4844 * adding, prepending and removing string.
4845 */
4846 else if (varp == (char_u *)&p_bs
4847 && VIM_ISDIGIT(**(char_u **)varp))
4848 {
4849 i = getdigits((char_u **)varp);
4850 switch (i)
4851 {
4852 case 0:
4853 *(char_u **)varp = empty_option;
4854 break;
4855 case 1:
4856 *(char_u **)varp = vim_strsave(
4857 (char_u *)"indent,eol");
4858 break;
4859 case 2:
4860 *(char_u **)varp = vim_strsave(
4861 (char_u *)"indent,eol,start");
4862 break;
4863 }
4864 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004865 if (origval == oldval)
4866 origval = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004867 oldval = *(char_u **)varp;
4868 }
4869 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004870 * Convert 'whichwrap' number to string, for
4871 * backwards compatibility with Vim 3.0.
4872 * Misuse errbuf[] for the resulting string.
4873 */
4874 else if (varp == (char_u *)&p_ww
4875 && VIM_ISDIGIT(*arg))
4876 {
4877 *errbuf = NUL;
4878 i = getdigits(&arg);
4879 if (i & 1)
4880 STRCAT(errbuf, "b,");
4881 if (i & 2)
4882 STRCAT(errbuf, "s,");
4883 if (i & 4)
4884 STRCAT(errbuf, "h,l,");
4885 if (i & 8)
4886 STRCAT(errbuf, "<,>,");
4887 if (i & 16)
4888 STRCAT(errbuf, "[,],");
4889 if (*errbuf != NUL) /* remove trailing , */
4890 errbuf[STRLEN(errbuf) - 1] = NUL;
4891 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004892 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004893 }
4894 /*
4895 * Remove '>' before 'dir' and 'bdir', for
4896 * backwards compatibility with version 3.0
4897 */
4898 else if ( *arg == '>'
4899 && (varp == (char_u *)&p_dir
4900 || varp == (char_u *)&p_bdir))
4901 {
4902 ++arg;
4903 }
4904
Bram Moolenaar071d4272004-06-13 20:20:40 +00004905 /*
4906 * Copy the new string into allocated memory.
4907 * Can't use set_string_option_direct(), because
4908 * we need to remove the backslashes.
4909 */
4910 /* get a bit too much */
4911 newlen = (unsigned)STRLEN(arg) + 1;
4912 if (adding || prepending || removing)
4913 newlen += (unsigned)STRLEN(origval) + 1;
4914 newval = alloc(newlen);
4915 if (newval == NULL) /* out of mem, don't change */
4916 break;
4917 s = newval;
4918
4919 /*
4920 * Copy the string, skip over escaped chars.
4921 * For MS-DOS and WIN32 backslashes before normal
4922 * file name characters are not removed, and keep
4923 * backslash at start, for "\\machine\path", but
4924 * do remove it for "\\\\machine\\path".
4925 * The reverse is found in ExpandOldSetting().
4926 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004927 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004928 {
4929 if (*arg == '\\' && arg[1] != NUL
4930#ifdef BACKSLASH_IN_FILENAME
4931 && !((flags & P_EXPAND)
4932 && vim_isfilec(arg[1])
4933 && (arg[1] != '\\'
4934 || (s == newval
4935 && arg[2] != '\\')))
4936#endif
4937 )
4938 ++arg; /* remove backslash */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004939 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004940 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004941 {
4942 /* copy multibyte char */
4943 mch_memmove(s, arg, (size_t)i);
4944 arg += i;
4945 s += i;
4946 }
4947 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004948 *s++ = *arg++;
4949 }
4950 *s = NUL;
4951
4952 /*
4953 * Expand environment variables and ~.
4954 * Don't do it when adding without inserting a
4955 * comma.
4956 */
4957 if (!(adding || prepending || removing)
4958 || (flags & P_COMMA))
4959 {
4960 s = option_expand(opt_idx, newval);
4961 if (s != NULL)
4962 {
4963 vim_free(newval);
4964 newlen = (unsigned)STRLEN(s) + 1;
4965 if (adding || prepending || removing)
4966 newlen += (unsigned)STRLEN(origval) + 1;
4967 newval = alloc(newlen);
4968 if (newval == NULL)
4969 break;
4970 STRCPY(newval, s);
4971 }
4972 }
4973
4974 /* locate newval[] in origval[] when removing it
4975 * and when adding to avoid duplicates */
4976 i = 0; /* init for GCC */
4977 if (removing || (flags & P_NODUP))
4978 {
4979 i = (int)STRLEN(newval);
4980 bs = 0;
4981 for (s = origval; *s; ++s)
4982 {
4983 if ((!(flags & P_COMMA)
4984 || s == origval
4985 || (s[-1] == ',' && !(bs & 1)))
4986 && STRNCMP(s, newval, i) == 0
4987 && (!(flags & P_COMMA)
4988 || s[i] == ','
4989 || s[i] == NUL))
4990 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004991 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01004992 * even number of backslashes or a single
4993 * backslash preceded by a comma before it
4994 * is recognized as a separator */
4995 if ((s > origval + 1
4996 && s[-1] == '\\'
4997 && s[-2] != ',')
4998 || (s == origval + 1
4999 && s[-1] == '\\'))
5000
Bram Moolenaar071d4272004-06-13 20:20:40 +00005001 ++bs;
5002 else
5003 bs = 0;
5004 }
5005
5006 /* do not add if already there */
5007 if ((adding || prepending) && *s)
5008 {
5009 prepending = FALSE;
5010 adding = FALSE;
5011 STRCPY(newval, origval);
5012 }
5013 }
5014
5015 /* concatenate the two strings; add a ',' if
5016 * needed */
5017 if (adding || prepending)
5018 {
5019 comma = ((flags & P_COMMA) && *origval != NUL
5020 && *newval != NUL);
5021 if (adding)
5022 {
5023 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005024 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005025 if (comma && i > 1
5026 && (flags & P_ONECOMMA) == P_ONECOMMA
5027 && origval[i - 1] == ','
5028 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005029 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005030 mch_memmove(newval + i + comma, newval,
5031 STRLEN(newval) + 1);
5032 mch_memmove(newval, origval, (size_t)i);
5033 }
5034 else
5035 {
5036 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005037 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005038 }
5039 if (comma)
5040 newval[i] = ',';
5041 }
5042
5043 /* Remove newval[] from origval[]. (Note: "i" has
5044 * been set above and is used here). */
5045 if (removing)
5046 {
5047 STRCPY(newval, origval);
5048 if (*s)
5049 {
5050 /* may need to remove a comma */
5051 if (flags & P_COMMA)
5052 {
5053 if (s == origval)
5054 {
5055 /* include comma after string */
5056 if (s[i] == ',')
5057 ++i;
5058 }
5059 else
5060 {
5061 /* include comma before string */
5062 --s;
5063 ++i;
5064 }
5065 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005066 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005067 }
5068 }
5069
5070 if (flags & P_FLAGLIST)
5071 {
5072 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005073 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005074 {
5075 /* if options have P_FLAGLIST and
5076 * P_ONECOMMA such as 'whichwrap' */
5077 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005078 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005079 if (*s != ',' && *(s + 1) == ','
5080 && vim_strchr(s + 2, *s) != NULL)
5081 {
5082 /* Remove the duplicated value and
5083 * the next comma. */
5084 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005085 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005086 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005087 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005088 else
5089 {
5090 if ((!(flags & P_COMMA) || *s != ',')
5091 && vim_strchr(s + 1, *s) != NULL)
5092 {
5093 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005094 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005095 }
5096 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005097 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005098 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005099 }
5100
5101 if (save_arg != NULL) /* number for 'whichwrap' */
5102 arg = save_arg;
5103 new_value_alloced = TRUE;
5104 }
5105
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005106 /*
5107 * Set the new value.
5108 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005109 *(char_u **)(varp) = newval;
5110
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005111#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005112 if (!starting
5113# ifdef FEAT_CRYPT
5114 && options[opt_idx].indir != PV_KEY
5115# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005116 && origval != NULL && newval != NULL)
5117 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005118 /* origval may be freed by
5119 * did_set_string_option(), make a copy. */
5120 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005121 /* newval (and varp) may become invalid if the
5122 * buffer is closed by autocommands. */
5123 saved_newval = vim_strsave(newval);
5124 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005125#endif
5126
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005127 {
5128 long_u *p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005129 int secure_saved = secure;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005130
5131 // When an option is set in the sandbox, from a
5132 // modeline or in secure mode, then deal with side
5133 // effects in secure mode. Also when the value was
5134 // set with the P_INSECURE flag and is not
5135 // completely replaced.
5136 if (secure
5137#ifdef HAVE_SANDBOX
5138 || sandbox != 0
5139#endif
5140 || (opt_flags & OPT_MODELINE)
5141 || (!value_is_replaced && (*p & P_INSECURE)))
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005142 ++secure;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005143
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005144 // Handle side effects, and set the global value
5145 // for ":set" on local options. Note: when setting
5146 // 'syntax' or 'filetype' autocommands may be
5147 // triggered that can cause havoc.
5148 errmsg = did_set_string_option(
5149 opt_idx, (char_u **)varp,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005150 new_value_alloced, oldval, errbuf,
5151 opt_flags, &value_checked);
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005152
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005153 secure = secure_saved;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005154 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005155
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005156#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005157 if (errmsg == NULL)
5158 trigger_optionsset_string(opt_idx, opt_flags,
5159 saved_origval, saved_newval);
5160 vim_free(saved_origval);
5161 vim_free(saved_newval);
5162#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005163 /* If error detected, print the error message. */
5164 if (errmsg != NULL)
5165 goto skip;
5166 }
5167 else /* key code option */
5168 {
5169 char_u *p;
5170
5171 if (nextchar == '&')
5172 {
5173 if (add_termcap_entry(key_name, TRUE) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005174 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005175 }
5176 else
5177 {
5178 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005179 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005180 if (*p == '\\' && p[1] != NUL)
5181 ++p;
5182 nextchar = *p;
5183 *p = NUL;
5184 add_termcode(key_name, arg, FALSE);
5185 *p = nextchar;
5186 }
5187 if (full_screen)
5188 ttest(FALSE);
5189 redraw_all_later(CLEAR);
5190 }
5191 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005192
Bram Moolenaar071d4272004-06-13 20:20:40 +00005193 if (opt_idx >= 0)
Bram Moolenaar916a8182018-11-25 02:18:29 +01005194 did_set_option(
5195 opt_idx, opt_flags, value_is_replaced, value_checked);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005196 }
5197
5198skip:
5199 /*
5200 * Advance to next argument.
5201 * - skip until a blank found, taking care of backslashes
5202 * - skip blanks
5203 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5204 */
5205 for (i = 0; i < 2 ; ++i)
5206 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005207 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005208 if (*arg++ == '\\' && *arg != NUL)
5209 ++arg;
5210 arg = skipwhite(arg);
5211 if (*arg != '=')
5212 break;
5213 }
5214 }
5215
5216 if (errmsg != NULL)
5217 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005218 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005219 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005220 if (i + (arg - startarg) < IOSIZE)
5221 {
5222 /* append the argument with the error */
5223 STRCAT(IObuff, ": ");
5224 mch_memmove(IObuff + i, startarg, (arg - startarg));
5225 IObuff[i + (arg - startarg)] = NUL;
5226 }
5227 /* make sure all characters are printable */
5228 trans_characters(IObuff, IOSIZE);
5229
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005230 ++no_wait_return; // wait_return done later
5231 emsg((char *)IObuff); // show error highlighted
Bram Moolenaar071d4272004-06-13 20:20:40 +00005232 --no_wait_return;
5233
5234 return FAIL;
5235 }
5236
5237 arg = skipwhite(arg);
5238 }
5239
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005240theend:
5241 if (silent_mode && did_show)
5242 {
5243 /* After displaying option values in silent mode. */
5244 silent_mode = FALSE;
5245 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5246 msg_putchar('\n');
5247 cursor_on(); /* msg_start() switches it off */
5248 out_flush();
5249 silent_mode = TRUE;
5250 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5251 }
5252
Bram Moolenaar071d4272004-06-13 20:20:40 +00005253 return OK;
5254}
5255
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005256/*
5257 * Call this when an option has been given a new value through a user command.
5258 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5259 */
5260 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005261did_set_option(
5262 int opt_idx,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005263 int opt_flags, // possibly with OPT_MODELINE
5264 int new_value, // value was replaced completely
5265 int value_checked) // value was checked to be safe, no need to set the
5266 // P_INSECURE flag.
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005267{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005268 long_u *p;
5269
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005270 options[opt_idx].flags |= P_WAS_SET;
5271
5272 /* When an option is set in the sandbox, from a modeline or in secure mode
5273 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005274 * flag. */
5275 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar916a8182018-11-25 02:18:29 +01005276 if (!value_checked && (secure
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005277#ifdef HAVE_SANDBOX
5278 || sandbox != 0
5279#endif
Bram Moolenaar916a8182018-11-25 02:18:29 +01005280 || (opt_flags & OPT_MODELINE)))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005281 *p = *p | P_INSECURE;
5282 else if (new_value)
5283 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005284}
5285
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005286 static char *
5287illegal_char(char *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005288{
5289 if (errbuf == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005290 return "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00005291 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005292 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005293 return errbuf;
5294}
5295
5296/*
5297 * Convert a key name or string into a key value.
5298 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005299 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005300 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005301 int
5302string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005303{
5304 if (*arg == '<')
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02005305 return find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005306 if (*arg == '^')
5307 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005308 if (multi_byte)
5309 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005310 return *arg;
5311}
5312
5313#ifdef FEAT_CMDWIN
5314/*
5315 * Check value of 'cedit' and set cedit_key.
5316 * Returns NULL if value is OK, error message otherwise.
5317 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005318 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005319check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005320{
5321 int n;
5322
5323 if (*p_cedit == NUL)
5324 cedit_key = -1;
5325 else
5326 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005327 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005328 if (vim_isprintc(n))
5329 return e_invarg;
5330 cedit_key = n;
5331 }
5332 return NULL;
5333}
5334#endif
5335
5336#ifdef FEAT_TITLE
5337/*
5338 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5339 * maketitle() to create and display it.
5340 * When switching the title or icon off, call mch_restore_title() to get
5341 * the old value back.
5342 */
5343 static void
Bram Moolenaar84a93082018-06-16 22:58:15 +02005344did_set_title(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005345{
5346 if (starting != NO_SCREEN
5347#ifdef FEAT_GUI
5348 && !gui.starting
5349#endif
5350 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00005351 maketitle();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005352}
5353#endif
5354
5355/*
5356 * set_options_bin - called when 'bin' changes value.
5357 */
5358 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005359set_options_bin(
5360 int oldval,
5361 int newval,
5362 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005363{
5364 /*
5365 * The option values that are changed when 'bin' changes are
5366 * copied when 'bin is set and restored when 'bin' is reset.
5367 */
5368 if (newval)
5369 {
5370 if (!oldval) /* switched on */
5371 {
5372 if (!(opt_flags & OPT_GLOBAL))
5373 {
5374 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5375 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5376 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5377 curbuf->b_p_et_nobin = curbuf->b_p_et;
5378 }
5379 if (!(opt_flags & OPT_LOCAL))
5380 {
5381 p_tw_nobin = p_tw;
5382 p_wm_nobin = p_wm;
5383 p_ml_nobin = p_ml;
5384 p_et_nobin = p_et;
5385 }
5386 }
5387
5388 if (!(opt_flags & OPT_GLOBAL))
5389 {
5390 curbuf->b_p_tw = 0; /* no automatic line wrap */
5391 curbuf->b_p_wm = 0; /* no automatic line wrap */
5392 curbuf->b_p_ml = 0; /* no modelines */
5393 curbuf->b_p_et = 0; /* no expandtab */
5394 }
5395 if (!(opt_flags & OPT_LOCAL))
5396 {
5397 p_tw = 0;
5398 p_wm = 0;
5399 p_ml = FALSE;
5400 p_et = FALSE;
5401 p_bin = TRUE; /* needed when called for the "-b" argument */
5402 }
5403 }
5404 else if (oldval) /* switched off */
5405 {
5406 if (!(opt_flags & OPT_GLOBAL))
5407 {
5408 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5409 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5410 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5411 curbuf->b_p_et = curbuf->b_p_et_nobin;
5412 }
5413 if (!(opt_flags & OPT_LOCAL))
5414 {
5415 p_tw = p_tw_nobin;
5416 p_wm = p_wm_nobin;
5417 p_ml = p_ml_nobin;
5418 p_et = p_et_nobin;
5419 }
5420 }
5421}
5422
5423#ifdef FEAT_VIMINFO
5424/*
5425 * Find the parameter represented by the given character (eg ', :, ", or /),
5426 * and return its associated value in the 'viminfo' string.
5427 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005428 * If the parameter is not specified in the string or there is no following
5429 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005430 */
5431 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005432get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005433{
5434 char_u *p;
5435
5436 p = find_viminfo_parameter(type);
5437 if (p != NULL && VIM_ISDIGIT(*p))
5438 return atoi((char *)p);
5439 return -1;
5440}
5441
5442/*
5443 * Find the parameter represented by the given character (eg ''', ':', '"', or
5444 * '/') in the 'viminfo' option and return a pointer to the string after it.
5445 * Return NULL if the parameter is not specified in the string.
5446 */
5447 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005448find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005449{
5450 char_u *p;
5451
5452 for (p = p_viminfo; *p; ++p)
5453 {
5454 if (*p == type)
5455 return p + 1;
5456 if (*p == 'n') /* 'n' is always the last one */
5457 break;
5458 p = vim_strchr(p, ','); /* skip until next ',' */
5459 if (p == NULL) /* hit the end without finding parameter */
5460 break;
5461 }
5462 return NULL;
5463}
5464#endif
5465
5466/*
5467 * Expand environment variables for some string options.
5468 * These string options cannot be indirect!
5469 * If "val" is NULL expand the current value of the option.
5470 * Return pointer to NameBuff, or NULL when not expanded.
5471 */
5472 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005473option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005474{
5475 /* if option doesn't need expansion nothing to do */
5476 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5477 return NULL;
5478
5479 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5480 * expand_env() would truncate the string. */
5481 if (val != NULL && STRLEN(val) > MAXPATHL)
5482 return NULL;
5483
5484 if (val == NULL)
5485 val = *(char_u **)options[opt_idx].var;
5486
5487 /*
5488 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5489 * Escape spaces when expanding 'tags', they are used to separate file
5490 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005491 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005492 */
5493 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005494 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005495#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005496 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5497#endif
5498 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005499 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5500 return NULL;
5501
5502 return NameBuff;
5503}
5504
5505/*
5506 * After setting various option values: recompute variables that depend on
5507 * option values.
5508 */
5509 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005510didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005511{
5512 /* initialize the table for 'iskeyword' et.al. */
5513 (void)init_chartab();
5514
5515 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
5516 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005517 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005518#ifdef FEAT_SESSION
5519 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5520 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5521#endif
5522#ifdef FEAT_FOLDING
5523 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5524#endif
5525 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005526 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005527 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005528#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5529 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5530#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005531#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005532 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005533 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005534 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005535 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005536#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005537#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5538 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5539#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005540#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005541 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5542#endif
5543#ifdef FEAT_CMDWIN
5544 /* set cedit_key */
5545 (void)check_cedit();
5546#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005547#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005548 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005549#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005550#ifdef FEAT_LINEBREAK
5551 /* initialize the table for 'breakat'. */
5552 fill_breakat_flags();
5553#endif
5554
5555}
5556
5557/*
5558 * More side effects of setting options.
5559 */
5560 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005561didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005562{
5563 /* Initialize the highlight_attr[] table. */
5564 (void)highlight_changed();
5565
5566 /* Parse default for 'wildmode' */
5567 check_opt_wim();
5568
5569 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005570 /* Parse default for 'fillchars'. */
5571 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005572
5573#ifdef FEAT_CLIPBOARD
5574 /* Parse default for 'clipboard' */
5575 (void)check_clipboard_option();
5576#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005577#ifdef FEAT_VARTABS
5578 tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_array);
5579 tabstop_set(curbuf->b_p_vts, &curbuf->b_p_vts_array);
5580#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005581}
5582
5583/*
5584 * Check for string options that are NULL (normally only termcap options).
5585 */
5586 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005587check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005588{
5589 int opt_idx;
5590
5591 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5592 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5593 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5594}
5595
5596/*
5597 * Check string options in a buffer for NULL value.
5598 */
5599 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005600check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005601{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005602 check_string_option(&buf->b_p_bh);
5603 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005604 check_string_option(&buf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005605 check_string_option(&buf->b_p_ff);
5606#ifdef FEAT_FIND_ID
5607 check_string_option(&buf->b_p_def);
5608 check_string_option(&buf->b_p_inc);
5609# ifdef FEAT_EVAL
5610 check_string_option(&buf->b_p_inex);
5611# endif
5612#endif
5613#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5614 check_string_option(&buf->b_p_inde);
5615 check_string_option(&buf->b_p_indk);
5616#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005617#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5618 check_string_option(&buf->b_p_bexpr);
5619#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005620#if defined(FEAT_CRYPT)
5621 check_string_option(&buf->b_p_cm);
5622#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005623 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005624#if defined(FEAT_EVAL)
5625 check_string_option(&buf->b_p_fex);
5626#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005627#ifdef FEAT_CRYPT
5628 check_string_option(&buf->b_p_key);
5629#endif
5630 check_string_option(&buf->b_p_kp);
5631 check_string_option(&buf->b_p_mps);
5632 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005633 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005634 check_string_option(&buf->b_p_isk);
5635#ifdef FEAT_COMMENTS
5636 check_string_option(&buf->b_p_com);
5637#endif
5638#ifdef FEAT_FOLDING
5639 check_string_option(&buf->b_p_cms);
5640#endif
5641 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005642#ifdef FEAT_TEXTOBJ
5643 check_string_option(&buf->b_p_qe);
5644#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005645#ifdef FEAT_SYN_HL
5646 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005647 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005648#endif
5649#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005650 check_string_option(&buf->b_s.b_p_spc);
5651 check_string_option(&buf->b_s.b_p_spf);
5652 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005653#endif
5654#ifdef FEAT_SEARCHPATH
5655 check_string_option(&buf->b_p_sua);
5656#endif
5657#ifdef FEAT_CINDENT
5658 check_string_option(&buf->b_p_cink);
5659 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005660 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005661#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005662 check_string_option(&buf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005663#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5664 check_string_option(&buf->b_p_cinw);
5665#endif
5666#ifdef FEAT_INS_EXPAND
5667 check_string_option(&buf->b_p_cpt);
5668#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005669#ifdef FEAT_COMPL_FUNC
5670 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005671 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005672#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005673#ifdef FEAT_KEYMAP
5674 check_string_option(&buf->b_p_keymap);
5675#endif
5676#ifdef FEAT_QUICKFIX
5677 check_string_option(&buf->b_p_gp);
5678 check_string_option(&buf->b_p_mp);
5679 check_string_option(&buf->b_p_efm);
5680#endif
5681 check_string_option(&buf->b_p_ep);
5682 check_string_option(&buf->b_p_path);
5683 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005684 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005685#ifdef FEAT_INS_EXPAND
5686 check_string_option(&buf->b_p_dict);
5687 check_string_option(&buf->b_p_tsr);
5688#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005689#ifdef FEAT_LISP
5690 check_string_option(&buf->b_p_lw);
5691#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005692 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005693 check_string_option(&buf->b_p_menc);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005694#ifdef FEAT_VARTABS
5695 check_string_option(&buf->b_p_vsts);
5696 check_string_option(&buf->b_p_vts);
5697#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005698}
5699
5700/*
5701 * Free the string allocated for an option.
5702 * Checks for the string being empty_option. This may happen if we're out of
5703 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5704 * check_options().
5705 * Does NOT check for P_ALLOCED flag!
5706 */
5707 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005708free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005709{
5710 if (p != empty_option)
5711 vim_free(p);
5712}
5713
5714 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005715clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005716{
5717 if (*pp != empty_option)
5718 vim_free(*pp);
5719 *pp = empty_option;
5720}
5721
5722 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005723check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005724{
5725 if (*pp == NULL)
5726 *pp = empty_option;
5727}
5728
5729/*
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005730 * Return the option index found by a pointer into term_strings[].
5731 * Return -1 if not found.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005732 */
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005733 int
5734get_term_opt_idx(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005735{
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005736 int opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005737
5738 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5739 if (options[opt_idx].var == (char_u *)p)
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005740 return opt_idx;
5741 return -1; // cannot happen: didn't find it!
5742}
5743
5744/*
5745 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5746 * Return the option index or -1 if not found.
5747 */
5748 int
5749set_term_option_alloced(char_u **p)
5750{
5751 int opt_idx = get_term_opt_idx(p);
5752
5753 if (opt_idx >= 0)
5754 options[opt_idx].flags |= P_ALLOCED;
5755 return opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005756}
5757
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005758#if defined(FEAT_EVAL) || defined(PROTO)
5759/*
5760 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5761 * Return FALSE when it wasn't.
5762 * Return -1 for an unknown option.
5763 */
5764 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005765was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005766{
5767 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005768 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005769
5770 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005771 {
5772 flagp = insecure_flag(idx, opt_flags);
5773 return (*flagp & P_INSECURE) != 0;
5774 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005775 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005776 return -1;
5777}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005778
5779/*
5780 * Get a pointer to the flags used for the P_INSECURE flag of option
5781 * "opt_idx". For some local options a local flags field is used.
5782 */
5783 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005784insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005785{
5786 if (opt_flags & OPT_LOCAL)
5787 switch ((int)options[opt_idx].indir)
5788 {
5789#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005790 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005791#endif
5792#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005793# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005794 case PV_FDE: return &curwin->w_p_fde_flags;
5795 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005796# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005797# ifdef FEAT_BEVAL
5798 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5799# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005800# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005801 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005802# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005803 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005804# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005805 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005806# endif
5807#endif
5808 }
5809
5810 /* Nothing special, return global flags field. */
5811 return &options[opt_idx].flags;
5812}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005813#endif
5814
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005815#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005816/*
5817 * Redraw the window title and/or tab page text later.
5818 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005819static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005820{
5821 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005822 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005823}
5824#endif
5825
Bram Moolenaar071d4272004-06-13 20:20:40 +00005826/*
5827 * Set a string option to a new value (without checking the effect).
5828 * The string is copied into allocated memory.
5829 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005830 * When "set_sid" is zero set the scriptID to current_sctx.sc_sid. When
5831 * "set_sid" is SID_NONE don't set the scriptID. Otherwise set the scriptID to
5832 * "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005833 */
5834 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005835set_string_option_direct(
5836 char_u *name,
5837 int opt_idx,
5838 char_u *val,
5839 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5840 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005841{
5842 char_u *s;
5843 char_u **varp;
5844 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005845 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005846
Bram Moolenaar89d40322006-08-29 15:30:07 +00005847 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005848 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005849 idx = findoption(name);
5850 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005851 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005852 semsg(_(e_intern2), "set_string_option_direct()");
5853 siemsg(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005854 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005855 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005856 }
5857
Bram Moolenaar89d40322006-08-29 15:30:07 +00005858 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005859 return;
5860
5861 s = vim_strsave(val);
5862 if (s != NULL)
5863 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005864 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005865 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005866 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005867 free_string_option(*varp);
5868 *varp = s;
5869
5870 /* For buffer/window local option may also set the global value. */
5871 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005872 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005873
Bram Moolenaar89d40322006-08-29 15:30:07 +00005874 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005875
5876 /* When setting both values of a global option with a local value,
5877 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005878 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005879 {
5880 free_string_option(*varp);
5881 *varp = empty_option;
5882 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005883# ifdef FEAT_EVAL
5884 if (set_sid != SID_NONE)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005885 {
5886 sctx_T script_ctx;
5887
5888 if (set_sid == 0)
5889 script_ctx = current_sctx;
5890 else
5891 {
5892 script_ctx.sc_sid = set_sid;
Bram Moolenaarded5f1b2018-11-10 17:33:29 +01005893 script_ctx.sc_seq = 0;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005894 script_ctx.sc_lnum = 0;
5895 }
5896 set_option_sctx_idx(idx, opt_flags, script_ctx);
5897 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005898# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005899 }
5900}
5901
5902/*
5903 * Set global value for string option when it's a local option.
5904 */
5905 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005906set_string_option_global(
5907 int opt_idx, /* option index */
5908 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005909{
5910 char_u **p, *s;
5911
5912 /* the global value is always allocated */
5913 if (options[opt_idx].var == VAR_WIN)
5914 p = (char_u **)GLOBAL_WO(varp);
5915 else
5916 p = (char_u **)options[opt_idx].var;
5917 if (options[opt_idx].indir != PV_NONE
5918 && p != varp
5919 && (s = vim_strsave(*varp)) != NULL)
5920 {
5921 free_string_option(*p);
5922 *p = s;
5923 }
5924}
5925
5926/*
5927 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005928 *
5929 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005930 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005931 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005932set_string_option(
5933 int opt_idx,
5934 char_u *value,
5935 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005936{
5937 char_u *s;
5938 char_u **varp;
5939 char_u *oldval;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005940#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02005941 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005942 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02005943#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005944 char *r = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01005945 int value_checked = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005946
5947 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005948 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005949
5950 s = vim_strsave(value);
5951 if (s != NULL)
5952 {
5953 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5954 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005955 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005956 ? OPT_GLOBAL : OPT_LOCAL)
5957 : opt_flags);
5958 oldval = *varp;
5959 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005960
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005961#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005962 if (!starting
5963# ifdef FEAT_CRYPT
5964 && options[opt_idx].indir != PV_KEY
5965# endif
5966 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005967 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005968 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005969 saved_newval = vim_strsave(s);
5970 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005971#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005972 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005973 opt_flags, &value_checked)) == NULL)
5974 did_set_option(opt_idx, opt_flags, TRUE, value_checked);
Bram Moolenaar53744302015-07-17 17:38:22 +02005975
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005976#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005977 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005978 if (r == NULL)
5979 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005980 saved_oldval, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005981 vim_free(saved_oldval);
5982 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02005983#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005984 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005985 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005986}
5987
5988/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01005989 * Return TRUE if "val" is a valid 'filetype' name.
5990 * Also used for 'syntax' and 'keymap'.
5991 */
5992 static int
5993valid_filetype(char_u *val)
5994{
5995 char_u *s;
5996
5997 for (s = val; *s != NUL; ++s)
5998 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
5999 return FALSE;
6000 return TRUE;
6001}
6002
6003/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006004 * Handle string options that need some action to perform when changed.
6005 * Returns NULL for success, or an error message for an error.
6006 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006007 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006008did_set_string_option(
Bram Moolenaar916a8182018-11-25 02:18:29 +01006009 int opt_idx, // index in options[] table
6010 char_u **varp, // pointer to the option variable
6011 int new_value_alloced, // new value was allocated
6012 char_u *oldval, // previous value of the option
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006013 char *errbuf, // buffer for errors, or NULL
Bram Moolenaar916a8182018-11-25 02:18:29 +01006014 int opt_flags, // OPT_LOCAL and/or OPT_GLOBAL
6015 int *value_checked) // value was checked to be save, no
6016 // need to set P_INSECURE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006017{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006018 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006019 char_u *s, *p;
6020 int did_chartab = FALSE;
6021 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006022 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006023#ifdef FEAT_GUI
6024 /* set when changing an option that only requires a redraw in the GUI */
6025 int redraw_gui_only = FALSE;
6026#endif
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02006027 int value_changed = FALSE;
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006028#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6029 int did_swaptcap = FALSE;
6030#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006031
6032 /* Get the global option to compare with, otherwise we would have to check
6033 * two values for all local options. */
6034 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6035
6036 /* Disallow changing some options from secure mode */
6037 if ((secure
6038#ifdef HAVE_SANDBOX
6039 || sandbox != 0
6040#endif
6041 ) && (options[opt_idx].flags & P_SECURE))
6042 {
6043 errmsg = e_secure;
6044 }
6045
Bram Moolenaar916a8182018-11-25 02:18:29 +01006046 // Check for a "normal" directory or file name in some options. Disallow a
6047 // path separator (slash and/or backslash), wildcards and characters that
6048 // are often illegal in a file name. Be more permissive if "secure" is off.
Bram Moolenaar7554da42016-11-25 22:04:13 +01006049 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006050 && vim_strpbrk(*varp, (char_u *)(secure
6051 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006052 || ((options[opt_idx].flags & P_NDNAME)
6053 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006054 {
6055 errmsg = e_invarg;
6056 }
6057
Bram Moolenaar071d4272004-06-13 20:20:40 +00006058 /* 'term' */
6059 else if (varp == &T_NAME)
6060 {
6061 if (T_NAME[0] == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006062 errmsg = N_("E529: Cannot set 'term' to empty string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006063#ifdef FEAT_GUI
6064 if (gui.in_use)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006065 errmsg = N_("E530: Cannot change term in GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006066 else if (term_is_gui(T_NAME))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006067 errmsg = N_("E531: Use \":gui\" to start the GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006068#endif
6069 else if (set_termname(T_NAME) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006070 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006071 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006072 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006073 /* Screen colors may have changed. */
6074 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006075
6076 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6077 * P_ALLOCED flag on 'term'. */
6078 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006079 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006080 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006081 }
6082
6083 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006084 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006085 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006086 char_u *bkc = p_bkc;
6087 unsigned int *flags = &bkc_flags;
6088
6089 if (opt_flags & OPT_LOCAL)
6090 {
6091 bkc = curbuf->b_p_bkc;
6092 flags = &curbuf->b_bkc_flags;
6093 }
6094
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006095 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6096 /* make the local value empty: use the global value */
6097 *flags = 0;
6098 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006099 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006100 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6101 errmsg = e_invarg;
6102 if ((((int)*flags & BKC_AUTO) != 0)
6103 + (((int)*flags & BKC_YES) != 0)
6104 + (((int)*flags & BKC_NO) != 0) != 1)
6105 {
6106 /* Must have exactly one of "auto", "yes" and "no". */
6107 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6108 errmsg = e_invarg;
6109 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006110 }
6111 }
6112
6113 /* 'backupext' and 'patchmode' */
6114 else if (varp == &p_bex || varp == &p_pm)
6115 {
6116 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6117 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006118 errmsg = N_("E589: 'backupext' and 'patchmode' are equal");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006119 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006120#ifdef FEAT_LINEBREAK
6121 /* 'breakindentopt' */
6122 else if (varp == &curwin->w_p_briopt)
6123 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006124 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006125 errmsg = e_invarg;
6126 }
6127#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006128
6129 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006130 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006131 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006132 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006133 */
6134 else if ( varp == &p_isi
6135 || varp == &(curbuf->b_p_isk)
6136 || varp == &p_isp
6137 || varp == &p_isf)
6138 {
6139 if (init_chartab() == FAIL)
6140 {
6141 did_chartab = TRUE; /* need to restore it below */
6142 errmsg = e_invarg; /* error in value */
6143 }
6144 }
6145
6146 /* 'helpfile' */
6147 else if (varp == &p_hf)
6148 {
6149 /* May compute new values for $VIM and $VIMRUNTIME */
6150 if (didset_vim)
6151 {
6152 vim_setenv((char_u *)"VIM", (char_u *)"");
6153 didset_vim = FALSE;
6154 }
6155 if (didset_vimruntime)
6156 {
6157 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6158 didset_vimruntime = FALSE;
6159 }
6160 }
6161
Bram Moolenaar1a384422010-07-14 19:53:30 +02006162#ifdef FEAT_SYN_HL
6163 /* 'colorcolumn' */
6164 else if (varp == &curwin->w_p_cc)
6165 errmsg = check_colorcolumn(curwin);
6166#endif
6167
Bram Moolenaar071d4272004-06-13 20:20:40 +00006168#ifdef FEAT_MULTI_LANG
6169 /* 'helplang' */
6170 else if (varp == &p_hlg)
6171 {
6172 /* Check for "", "ab", "ab,cd", etc. */
6173 for (s = p_hlg; *s != NUL; s += 3)
6174 {
6175 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6176 {
6177 errmsg = e_invarg;
6178 break;
6179 }
6180 if (s[2] == NUL)
6181 break;
6182 }
6183 }
6184#endif
6185
6186 /* 'highlight' */
6187 else if (varp == &p_hl)
6188 {
6189 if (highlight_changed() == FAIL)
6190 errmsg = e_invarg; /* invalid flags */
6191 }
6192
6193 /* 'nrformats' */
6194 else if (gvarp == &p_nf)
6195 {
6196 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6197 errmsg = e_invarg;
6198 }
6199
6200#ifdef FEAT_SESSION
6201 /* 'sessionoptions' */
6202 else if (varp == &p_ssop)
6203 {
6204 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6205 errmsg = e_invarg;
6206 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6207 {
6208 /* Don't allow both "sesdir" and "curdir". */
6209 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6210 errmsg = e_invarg;
6211 }
6212 }
6213 /* 'viewoptions' */
6214 else if (varp == &p_vop)
6215 {
6216 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6217 errmsg = e_invarg;
6218 }
6219#endif
6220
6221 /* 'scrollopt' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006222 else if (varp == &p_sbo)
6223 {
6224 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6225 errmsg = e_invarg;
6226 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006227
6228 /* 'ambiwidth' */
Bram Moolenaar3848e002016-03-19 18:42:29 +01006229 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006230 {
6231 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6232 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006233 else if (set_chars_option(&p_lcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006234 errmsg = _("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006235 else if (set_chars_option(&p_fcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006236 errmsg = _("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006237 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006238
6239 /* 'background' */
6240 else if (varp == &p_bg)
6241 {
6242 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6243 {
6244#ifdef FEAT_EVAL
6245 int dark = (*p_bg == 'd');
6246#endif
6247
6248 init_highlight(FALSE, FALSE);
6249
6250#ifdef FEAT_EVAL
6251 if (dark != (*p_bg == 'd')
6252 && get_var_value((char_u *)"g:colors_name") != NULL)
6253 {
6254 /* The color scheme must have set 'background' back to another
6255 * value, that's not what we want here. Disable the color
6256 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006257 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006258 free_string_option(p_bg);
6259 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6260 check_string_option(&p_bg);
6261 init_highlight(FALSE, FALSE);
6262 }
6263#endif
6264 }
6265 else
6266 errmsg = e_invarg;
6267 }
6268
6269 /* 'wildmode' */
6270 else if (varp == &p_wim)
6271 {
6272 if (check_opt_wim() == FAIL)
6273 errmsg = e_invarg;
6274 }
6275
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006276#ifdef FEAT_CMDL_COMPL
6277 /* 'wildoptions' */
6278 else if (varp == &p_wop)
6279 {
6280 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6281 errmsg = e_invarg;
6282 }
6283#endif
6284
Bram Moolenaar071d4272004-06-13 20:20:40 +00006285#ifdef FEAT_WAK
6286 /* 'winaltkeys' */
6287 else if (varp == &p_wak)
6288 {
6289 if (*p_wak == NUL
6290 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6291 errmsg = e_invarg;
6292# ifdef FEAT_MENU
6293# ifdef FEAT_GUI_MOTIF
6294 else if (gui.in_use)
6295 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6296# else
6297# ifdef FEAT_GUI_GTK
6298 else if (gui.in_use)
6299 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6300# endif
6301# endif
6302# endif
6303 }
6304#endif
6305
Bram Moolenaar071d4272004-06-13 20:20:40 +00006306 /* 'eventignore' */
6307 else if (varp == &p_ei)
6308 {
6309 if (check_ei() == FAIL)
6310 errmsg = e_invarg;
6311 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006312
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006313 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6314 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6315 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006316 {
6317 if (gvarp == &p_fenc)
6318 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006319 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006320 errmsg = e_modifiable;
6321 else if (vim_strchr(*varp, ',') != NULL)
6322 /* No comma allowed in 'fileencoding'; catches confusing it
6323 * with 'fileencodings'. */
6324 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006325 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006326 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006327#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006328 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006329 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006330#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006331 /* Add 'fileencoding' to the swap file. */
6332 ml_setflags(curbuf);
6333 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006334 }
6335 if (errmsg == NULL)
6336 {
6337 /* canonize the value, so that STRCMP() can be used on it */
6338 p = enc_canonize(*varp);
6339 if (p != NULL)
6340 {
6341 vim_free(*varp);
6342 *varp = p;
6343 }
6344 if (varp == &p_enc)
6345 {
6346 errmsg = mb_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006347#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006348 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006349#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006350 }
6351 }
6352
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006353#if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006354 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6355 {
6356 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6357 if (STRCMP(p_tenc, "utf-8") != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006358 errmsg = N_("E617: Cannot be changed in the GTK+ 2 GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006359 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006360#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006361
6362 if (errmsg == NULL)
6363 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006364#ifdef FEAT_KEYMAP
Bram Moolenaar071d4272004-06-13 20:20:40 +00006365 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6366 * (with another encoding). */
6367 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6368 (void)keymap_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006369#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006370
6371 /* When 'termencoding' is not empty and 'encoding' changes or when
6372 * 'termencoding' changes, need to setup for keyboard input and
6373 * display output conversion. */
6374 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6375 {
Bram Moolenaar17471e82017-11-26 23:47:18 +01006376 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6377 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6378 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006379 semsg(_("E950: Cannot convert between %s and %s"),
Bram Moolenaar17471e82017-11-26 23:47:18 +01006380 p_tenc, p_enc);
6381 errmsg = e_invarg;
6382 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006383 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006384
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006385#if defined(WIN3264)
Bram Moolenaar05159a02005-02-26 23:04:13 +00006386 /* $HOME may have characters in active code page. */
6387 if (varp == &p_enc)
6388 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006389#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006390 }
6391 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006392
6393#if defined(FEAT_POSTSCRIPT)
6394 else if (varp == &p_penc)
6395 {
6396 /* Canonize printencoding if VIM standard one */
6397 p = enc_canonize(p_penc);
6398 if (p != NULL)
6399 {
6400 vim_free(p_penc);
6401 p_penc = p;
6402 }
6403 else
6404 {
6405 /* Ensure lower case and '-' for '_' */
6406 for (s = p_penc; *s != NUL; s++)
6407 {
6408 if (*s == '_')
6409 *s = '-';
6410 else
6411 *s = TOLOWER_ASC(*s);
6412 }
6413 }
6414 }
6415#endif
6416
Bram Moolenaar9372a112005-12-06 19:59:18 +00006417#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006418 else if (varp == &p_imak)
6419 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006420 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006421 errmsg = e_invarg;
6422 }
6423#endif
6424
6425#ifdef FEAT_KEYMAP
6426 else if (varp == &curbuf->b_p_keymap)
6427 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006428 if (!valid_filetype(*varp))
6429 errmsg = e_invarg;
6430 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01006431 {
6432 int secure_save = secure;
6433
6434 // Reset the secure flag, since the value of 'keymap' has
6435 // been checked to be safe.
6436 secure = 0;
6437
6438 // load or unload key mapping tables
Bram Moolenaard0b51382016-11-04 15:23:45 +01006439 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006440
Bram Moolenaar916a8182018-11-25 02:18:29 +01006441 secure = secure_save;
6442
6443 // Since we check the value, there is no need to set P_INSECURE,
6444 // even when the value comes from a modeline.
6445 *value_checked = TRUE;
6446 }
6447
Bram Moolenaarfab06232009-03-04 03:13:35 +00006448 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006449 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006450 if (*curbuf->b_p_keymap != NUL)
6451 {
6452 /* Installed a new keymap, switch on using it. */
6453 curbuf->b_p_iminsert = B_IMODE_LMAP;
6454 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6455 curbuf->b_p_imsearch = B_IMODE_LMAP;
6456 }
6457 else
6458 {
6459 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6460 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6461 curbuf->b_p_iminsert = B_IMODE_NONE;
6462 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6463 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6464 }
6465 if ((opt_flags & OPT_LOCAL) == 0)
6466 {
6467 set_iminsert_global();
6468 set_imsearch_global();
6469 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006470 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006471 }
6472 }
6473#endif
6474
6475 /* 'fileformat' */
6476 else if (gvarp == &p_ff)
6477 {
6478 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6479 errmsg = e_modifiable;
6480 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6481 errmsg = e_invarg;
6482 else
6483 {
6484 /* may also change 'textmode' */
6485 if (get_fileformat(curbuf) == EOL_DOS)
6486 curbuf->b_p_tx = TRUE;
6487 else
6488 curbuf->b_p_tx = FALSE;
6489#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006490 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006491#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006492 /* update flag in swap file */
6493 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006494 /* Redraw needed when switching to/from "mac": a CR in the text
6495 * will be displayed differently. */
6496 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6497 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006498 }
6499 }
6500
6501 /* 'fileformats' */
6502 else if (varp == &p_ffs)
6503 {
6504 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6505 errmsg = e_invarg;
6506 else
6507 {
6508 /* also change 'textauto' */
6509 if (*p_ffs == NUL)
6510 p_ta = FALSE;
6511 else
6512 p_ta = TRUE;
6513 }
6514 }
6515
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006516#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006517 /* 'cryptkey' */
6518 else if (gvarp == &p_key)
6519 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006520# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006521 /* Make sure the ":set" command doesn't show the new value in the
6522 * history. */
6523 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006524# endif
6525 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6526 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006527 ml_set_crypt_key(curbuf, oldval,
6528 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006529 }
6530
6531 else if (gvarp == &p_cm)
6532 {
6533 if (opt_flags & OPT_LOCAL)
6534 p = curbuf->b_p_cm;
6535 else
6536 p = p_cm;
6537 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6538 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006539 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006540 errmsg = e_invarg;
6541 else
6542 {
6543 /* When setting the global value to empty, make it "zip". */
6544 if (*p_cm == NUL)
6545 {
6546 if (new_value_alloced)
6547 free_string_option(p_cm);
6548 p_cm = vim_strsave((char_u *)"zip");
6549 new_value_alloced = TRUE;
6550 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006551 /* When using ":set cm=name" the local value is going to be empty.
6552 * Do that here, otherwise the crypt functions will still use the
6553 * local value. */
6554 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6555 {
6556 free_string_option(curbuf->b_p_cm);
6557 curbuf->b_p_cm = empty_option;
6558 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006559
6560 /* Need to update the swapfile when the effective method changed.
6561 * Set "s" to the effective old value, "p" to the effective new
6562 * method and compare. */
6563 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6564 s = p_cm; /* was previously using the global value */
6565 else
6566 s = oldval;
6567 if (*curbuf->b_p_cm == NUL)
6568 p = p_cm; /* is now using the global value */
6569 else
6570 p = curbuf->b_p_cm;
6571 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006572 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006573
6574 /* If the global value changes need to update the swapfile for all
6575 * buffers using that value. */
6576 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6577 {
6578 buf_T *buf;
6579
Bram Moolenaar29323592016-07-24 22:04:11 +02006580 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006581 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006582 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006583 }
6584 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006585 }
6586#endif
6587
6588 /* 'matchpairs' */
6589 else if (gvarp == &p_mps)
6590 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006591 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006592 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006593 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006594 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006595 int x2 = -1;
6596 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006597
6598 if (*p != NUL)
6599 p += mb_ptr2len(p);
6600 if (*p != NUL)
6601 x2 = *p++;
6602 if (*p != NUL)
6603 {
6604 x3 = mb_ptr2char(p);
6605 p += mb_ptr2len(p);
6606 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006607 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006608 {
6609 errmsg = e_invarg;
6610 break;
6611 }
6612 if (*p == NUL)
6613 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006614 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006615 }
6616 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006617 {
6618 /* Check for "x:y,x:y" */
6619 for (p = *varp; *p != NUL; p += 4)
6620 {
6621 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6622 {
6623 errmsg = e_invarg;
6624 break;
6625 }
6626 if (p[3] == NUL)
6627 break;
6628 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006629 }
6630 }
6631
6632#ifdef FEAT_COMMENTS
6633 /* 'comments' */
6634 else if (gvarp == &p_com)
6635 {
6636 for (s = *varp; *s; )
6637 {
6638 while (*s && *s != ':')
6639 {
6640 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6641 && !VIM_ISDIGIT(*s) && *s != '-')
6642 {
6643 errmsg = illegal_char(errbuf, *s);
6644 break;
6645 }
6646 ++s;
6647 }
6648 if (*s++ == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006649 errmsg = N_("E524: Missing colon");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006650 else if (*s == ',' || *s == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006651 errmsg = N_("E525: Zero length string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006652 if (errmsg != NULL)
6653 break;
6654 while (*s && *s != ',')
6655 {
6656 if (*s == '\\' && s[1] != NUL)
6657 ++s;
6658 ++s;
6659 }
6660 s = skip_to_option_part(s);
6661 }
6662 }
6663#endif
6664
6665 /* 'listchars' */
6666 else if (varp == &p_lcs)
6667 {
6668 errmsg = set_chars_option(varp);
6669 }
6670
Bram Moolenaar071d4272004-06-13 20:20:40 +00006671 /* 'fillchars' */
6672 else if (varp == &p_fcs)
6673 {
6674 errmsg = set_chars_option(varp);
6675 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006676
6677#ifdef FEAT_CMDWIN
6678 /* 'cedit' */
6679 else if (varp == &p_cedit)
6680 {
6681 errmsg = check_cedit();
6682 }
6683#endif
6684
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006685 /* 'verbosefile' */
6686 else if (varp == &p_vfile)
6687 {
6688 verbose_stop();
6689 if (*p_vfile != NUL && verbose_open() == FAIL)
6690 errmsg = e_invarg;
6691 }
6692
Bram Moolenaar071d4272004-06-13 20:20:40 +00006693#ifdef FEAT_VIMINFO
6694 /* 'viminfo' */
6695 else if (varp == &p_viminfo)
6696 {
6697 for (s = p_viminfo; *s;)
6698 {
6699 /* Check it's a valid character */
6700 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6701 {
6702 errmsg = illegal_char(errbuf, *s);
6703 break;
6704 }
6705 if (*s == 'n') /* name is always last one */
6706 {
6707 break;
6708 }
6709 else if (*s == 'r') /* skip until next ',' */
6710 {
6711 while (*++s && *s != ',')
6712 ;
6713 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006714 else if (*s == '%')
6715 {
6716 /* optional number */
6717 while (vim_isdigit(*++s))
6718 ;
6719 }
6720 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006721 ++s; /* no extra chars */
6722 else /* must have a number */
6723 {
6724 while (vim_isdigit(*++s))
6725 ;
6726
6727 if (!VIM_ISDIGIT(*(s - 1)))
6728 {
6729 if (errbuf != NULL)
6730 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006731 sprintf(errbuf, _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006732 transchar_byte(*(s - 1)));
6733 errmsg = errbuf;
6734 }
6735 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006736 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006737 break;
6738 }
6739 }
6740 if (*s == ',')
6741 ++s;
6742 else if (*s)
6743 {
6744 if (errbuf != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006745 errmsg = N_("E527: Missing comma");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006746 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006747 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006748 break;
6749 }
6750 }
6751 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006752 errmsg = N_("E528: Must specify a ' value");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006753 }
6754#endif /* FEAT_VIMINFO */
6755
6756 /* terminal options */
6757 else if (istermoption(&options[opt_idx]) && full_screen)
6758 {
6759 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6760 if (varp == &T_CCO)
6761 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006762 int colors = atoi((char *)T_CCO);
6763
6764 /* Only reinitialize colors if t_Co value has really changed to
6765 * avoid expensive reload of colorscheme if t_Co is set to the
6766 * same value multiple times. */
6767 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006768 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006769 t_colors = colors;
6770 if (t_colors <= 1)
6771 {
6772 if (new_value_alloced)
6773 vim_free(T_CCO);
6774 T_CCO = empty_option;
6775 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006776#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6777 if (is_term_win32())
6778 {
6779 swap_tcap();
6780 did_swaptcap = TRUE;
6781 }
6782#endif
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006783 /* We now have a different color setup, initialize it again. */
6784 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006785 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006786 }
6787 ttest(FALSE);
6788 if (varp == &T_ME)
6789 {
6790 out_str(T_ME);
6791 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006792#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006793 /* Since t_me has been set, this probably means that the user
6794 * wants to use this as default colors. Need to reset default
6795 * background/foreground colors. */
6796 mch_set_normal_colors();
6797#endif
6798 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006799 if (varp == &T_BE && termcap_active)
6800 {
6801 if (*T_BE == NUL)
6802 /* When clearing t_BE we assume the user no longer wants
6803 * bracketed paste, thus disable it by writing t_BD. */
6804 out_str(T_BD);
6805 else
6806 out_str(T_BE);
6807 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006808 }
6809
6810#ifdef FEAT_LINEBREAK
6811 /* 'showbreak' */
6812 else if (varp == &p_sbr)
6813 {
6814 for (s = p_sbr; *s; )
6815 {
6816 if (ptr2cells(s) != 1)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006817 errmsg = N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006818 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006819 }
6820 }
6821#endif
6822
6823#ifdef FEAT_GUI
6824 /* 'guifont' */
6825 else if (varp == &p_guifont)
6826 {
6827 if (gui.in_use)
6828 {
6829 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006830# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006831 /*
6832 * Put up a font dialog and let the user select a new value.
6833 * If this is cancelled go back to the old value but don't
6834 * give an error message.
6835 */
6836 if (STRCMP(p, "*") == 0)
6837 {
6838 p = gui_mch_font_dialog(oldval);
6839
6840 if (new_value_alloced)
6841 free_string_option(p_guifont);
6842
6843 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6844 new_value_alloced = TRUE;
6845 }
6846# endif
6847 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6848 {
6849# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6850 if (STRCMP(p_guifont, "*") == 0)
6851 {
6852 /* Dialog was cancelled: Keep the old value without giving
6853 * an error message. */
6854 if (new_value_alloced)
6855 free_string_option(p_guifont);
6856 p_guifont = vim_strsave(oldval);
6857 new_value_alloced = TRUE;
6858 }
6859 else
6860# endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006861 errmsg = N_("E596: Invalid font(s)");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006862 }
6863 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006864 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006865 }
6866# ifdef FEAT_XFONTSET
6867 else if (varp == &p_guifontset)
6868 {
6869 if (STRCMP(p_guifontset, "*") == 0)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01006870 errmsg = N_("E597: can't select fontset");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006871 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01006872 errmsg = N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006873 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006874 }
6875# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006876 else if (varp == &p_guifontwide)
6877 {
6878 if (STRCMP(p_guifontwide, "*") == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006879 errmsg = N_("E533: can't select wide font");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006880 else if (gui_get_wide_font() == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006881 errmsg = N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006882 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006883 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006884#endif
6885
6886#ifdef CURSOR_SHAPE
6887 /* 'guicursor' */
6888 else if (varp == &p_guicursor)
6889 errmsg = parse_shape_opt(SHAPE_CURSOR);
6890#endif
6891
6892#ifdef FEAT_MOUSESHAPE
6893 /* 'mouseshape' */
6894 else if (varp == &p_mouseshape)
6895 {
6896 errmsg = parse_shape_opt(SHAPE_MOUSE);
6897 update_mouseshape(-1);
6898 }
6899#endif
6900
6901#ifdef FEAT_PRINTER
6902 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006903 errmsg = parse_printoptions();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006904# if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006905 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006906 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006907# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006908#endif
6909
6910#ifdef FEAT_LANGMAP
6911 /* 'langmap' */
6912 else if (varp == &p_langmap)
6913 langmap_set();
6914#endif
6915
6916#ifdef FEAT_LINEBREAK
6917 /* 'breakat' */
6918 else if (varp == &p_breakat)
6919 fill_breakat_flags();
6920#endif
6921
6922#ifdef FEAT_TITLE
6923 /* 'titlestring' and 'iconstring' */
6924 else if (varp == &p_titlestring || varp == &p_iconstring)
6925 {
6926# ifdef FEAT_STL_OPT
6927 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6928
6929 /* NULL => statusline syntax */
6930 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6931 stl_syntax |= flagval;
6932 else
6933 stl_syntax &= ~flagval;
6934# endif
Bram Moolenaar84a93082018-06-16 22:58:15 +02006935 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006936 }
6937#endif
6938
6939#ifdef FEAT_GUI
6940 /* 'guioptions' */
6941 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006942 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006943 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006944 redraw_gui_only = TRUE;
6945 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006946#endif
6947
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006948#if defined(FEAT_GUI_TABLINE)
6949 /* 'guitablabel' */
6950 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006951 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006952 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006953 redraw_gui_only = TRUE;
6954 }
6955 /* 'guitabtooltip' */
6956 else if (varp == &p_gtt)
6957 {
6958 redraw_gui_only = TRUE;
6959 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006960#endif
6961
Bram Moolenaar071d4272004-06-13 20:20:40 +00006962#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6963 /* 'ttymouse' */
6964 else if (varp == &p_ttym)
6965 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006966 /* Switch the mouse off before changing the escape sequences used for
6967 * that. */
6968 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006969 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6970 errmsg = e_invarg;
6971 else
6972 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006973 if (termcap_active)
6974 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006975 }
6976#endif
6977
Bram Moolenaar071d4272004-06-13 20:20:40 +00006978 /* 'selection' */
6979 else if (varp == &p_sel)
6980 {
6981 if (*p_sel == NUL
6982 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6983 errmsg = e_invarg;
6984 }
6985
6986 /* 'selectmode' */
6987 else if (varp == &p_slm)
6988 {
6989 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6990 errmsg = e_invarg;
6991 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006992
6993#ifdef FEAT_BROWSE
6994 /* 'browsedir' */
6995 else if (varp == &p_bsdir)
6996 {
6997 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6998 && !mch_isdir(p_bsdir))
6999 errmsg = e_invarg;
7000 }
7001#endif
7002
Bram Moolenaar071d4272004-06-13 20:20:40 +00007003 /* 'keymodel' */
7004 else if (varp == &p_km)
7005 {
7006 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7007 errmsg = e_invarg;
7008 else
7009 {
7010 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7011 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7012 }
7013 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007014
7015 /* 'mousemodel' */
7016 else if (varp == &p_mousem)
7017 {
7018 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7019 errmsg = e_invarg;
7020#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7021 else if (*p_mousem != *oldval)
7022 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7023 * to create or delete the popup menus. */
7024 gui_motif_update_mousemodel(root_menu);
7025#endif
7026 }
7027
7028 /* 'switchbuf' */
7029 else if (varp == &p_swb)
7030 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007031 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007032 errmsg = e_invarg;
7033 }
7034
7035 /* 'debug' */
7036 else if (varp == &p_debug)
7037 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007038 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007039 errmsg = e_invarg;
7040 }
7041
7042 /* 'display' */
7043 else if (varp == &p_dy)
7044 {
7045 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7046 errmsg = e_invarg;
7047 else
7048 (void)init_chartab();
7049
7050 }
7051
Bram Moolenaar071d4272004-06-13 20:20:40 +00007052 /* 'eadirection' */
7053 else if (varp == &p_ead)
7054 {
7055 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7056 errmsg = e_invarg;
7057 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007058
7059#ifdef FEAT_CLIPBOARD
7060 /* 'clipboard' */
7061 else if (varp == &p_cb)
7062 errmsg = check_clipboard_option();
7063#endif
7064
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007065#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007066 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7067 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007068 else if (varp == &(curwin->w_s->b_p_spl)
7069 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007070 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007071 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007072 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007073 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007074 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007075 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007076 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007077 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007078 /* 'spellsuggest' */
7079 else if (varp == &p_sps)
7080 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007081 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007082 errmsg = e_invarg;
7083 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007084 /* 'mkspellmem' */
7085 else if (varp == &p_msm)
7086 {
7087 if (spell_check_msm() != OK)
7088 errmsg = e_invarg;
7089 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007090#endif
7091
Bram Moolenaar071d4272004-06-13 20:20:40 +00007092 /* When 'bufhidden' is set, check for valid value. */
7093 else if (gvarp == &p_bh)
7094 {
7095 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7096 errmsg = e_invarg;
7097 }
7098
7099 /* When 'buftype' is set, check for valid value. */
7100 else if (gvarp == &p_bt)
7101 {
7102 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7103 errmsg = e_invarg;
7104 else
7105 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007106 if (curwin->w_status_height)
7107 {
7108 curwin->w_redr_status = TRUE;
7109 redraw_later(VALID);
7110 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007111 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007112#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007113 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007114#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007115 }
7116 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007117
7118#ifdef FEAT_STL_OPT
7119 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007120 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007121 {
7122 int wid;
7123
7124 if (varp == &p_ruf) /* reset ru_wid first */
7125 ru_wid = 0;
7126 s = *varp;
7127 if (varp == &p_ruf && *s == '%')
7128 {
7129 /* set ru_wid if 'ruf' starts with "%99(" */
7130 if (*++s == '-') /* ignore a '-' */
7131 s++;
7132 wid = getdigits(&s);
7133 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7134 ru_wid = wid;
7135 else
7136 errmsg = check_stl_option(p_ruf);
7137 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007138 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007139 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007140 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007141 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007142 comp_col();
7143 }
7144#endif
7145
7146#ifdef FEAT_INS_EXPAND
7147 /* check if it is a valid value for 'complete' -- Acevedo */
7148 else if (gvarp == &p_cpt)
7149 {
7150 for (s = *varp; *s;)
7151 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007152 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007153 s++;
7154 if (!*s)
7155 break;
7156 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7157 {
7158 errmsg = illegal_char(errbuf, *s);
7159 break;
7160 }
7161 if (*++s != NUL && *s != ',' && *s != ' ')
7162 {
7163 if (s[-1] == 'k' || s[-1] == 's')
7164 {
7165 /* skip optional filename after 'k' and 's' */
7166 while (*s && *s != ',' && *s != ' ')
7167 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007168 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007169 ++s;
7170 ++s;
7171 }
7172 }
7173 else
7174 {
7175 if (errbuf != NULL)
7176 {
7177 sprintf((char *)errbuf,
7178 _("E535: Illegal character after <%c>"),
7179 *--s);
7180 errmsg = errbuf;
7181 }
7182 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007183 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00007184 break;
7185 }
7186 }
7187 }
7188 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007189
7190 /* 'completeopt' */
7191 else if (varp == &p_cot)
7192 {
7193 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7194 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007195 else
7196 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007197 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007198#endif /* FEAT_INS_EXPAND */
7199
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007200#ifdef FEAT_SIGNS
7201 /* 'signcolumn' */
7202 else if (varp == &curwin->w_p_scl)
7203 {
7204 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7205 errmsg = e_invarg;
7206 }
7207#endif
7208
Bram Moolenaar071d4272004-06-13 20:20:40 +00007209
7210#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007211 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007212 else if (varp == &p_toolbar)
7213 {
7214 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7215 &toolbar_flags, TRUE) != OK)
7216 errmsg = e_invarg;
7217 else
7218 {
7219 out_flush();
7220 gui_mch_show_toolbar((toolbar_flags &
7221 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7222 }
7223 }
7224#endif
7225
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007226#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007227 /* 'toolbariconsize': GTK+ 2 only */
7228 else if (varp == &p_tbis)
7229 {
7230 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7231 errmsg = e_invarg;
7232 else
7233 {
7234 out_flush();
7235 gui_mch_show_toolbar((toolbar_flags &
7236 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7237 }
7238 }
7239#endif
7240
7241 /* 'pastetoggle': translate key codes like in a mapping */
7242 else if (varp == &p_pt)
7243 {
7244 if (*p_pt)
7245 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007246 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007247 if (p != NULL)
7248 {
7249 if (new_value_alloced)
7250 free_string_option(p_pt);
7251 p_pt = p;
7252 new_value_alloced = TRUE;
7253 }
7254 }
7255 }
7256
7257 /* 'backspace' */
7258 else if (varp == &p_bs)
7259 {
7260 if (VIM_ISDIGIT(*p_bs))
7261 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007262 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007263 errmsg = e_invarg;
7264 }
7265 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7266 errmsg = e_invarg;
7267 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007268 else if (varp == &p_bo)
7269 {
7270 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7271 errmsg = e_invarg;
7272 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007273
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007274 /* 'tagcase' */
7275 else if (gvarp == &p_tc)
7276 {
7277 unsigned int *flags;
7278
7279 if (opt_flags & OPT_LOCAL)
7280 {
7281 p = curbuf->b_p_tc;
7282 flags = &curbuf->b_tc_flags;
7283 }
7284 else
7285 {
7286 p = p_tc;
7287 flags = &tc_flags;
7288 }
7289
7290 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7291 /* make the local value empty: use the global value */
7292 *flags = 0;
7293 else if (*p == NUL
7294 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7295 errmsg = e_invarg;
7296 }
7297
Bram Moolenaar071d4272004-06-13 20:20:40 +00007298 /* 'casemap' */
7299 else if (varp == &p_cmp)
7300 {
7301 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7302 errmsg = e_invarg;
7303 }
7304
7305#ifdef FEAT_DIFF
7306 /* 'diffopt' */
7307 else if (varp == &p_dip)
7308 {
7309 if (diffopt_changed() == FAIL)
7310 errmsg = e_invarg;
7311 }
7312#endif
7313
7314#ifdef FEAT_FOLDING
7315 /* 'foldmethod' */
7316 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7317 {
7318 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7319 || *curwin->w_p_fdm == NUL)
7320 errmsg = e_invarg;
7321 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007322 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007323 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007324 if (foldmethodIsDiff(curwin))
7325 newFoldLevel();
7326 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007327 }
7328# ifdef FEAT_EVAL
7329 /* 'foldexpr' */
7330 else if (varp == &curwin->w_p_fde)
7331 {
7332 if (foldmethodIsExpr(curwin))
7333 foldUpdateAll(curwin);
7334 }
7335# endif
7336 /* 'foldmarker' */
7337 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7338 {
7339 p = vim_strchr(*varp, ',');
7340 if (p == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007341 errmsg = N_("E536: comma required");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007342 else if (p == *varp || p[1] == NUL)
7343 errmsg = e_invarg;
7344 else if (foldmethodIsMarker(curwin))
7345 foldUpdateAll(curwin);
7346 }
7347 /* 'commentstring' */
7348 else if (gvarp == &p_cms)
7349 {
7350 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007351 errmsg = N_("E537: 'commentstring' must be empty or contain %s");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007352 }
7353 /* 'foldopen' */
7354 else if (varp == &p_fdo)
7355 {
7356 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7357 errmsg = e_invarg;
7358 }
7359 /* 'foldclose' */
7360 else if (varp == &p_fcl)
7361 {
7362 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7363 errmsg = e_invarg;
7364 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007365 /* 'foldignore' */
7366 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7367 {
7368 if (foldmethodIsIndent(curwin))
7369 foldUpdateAll(curwin);
7370 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007371#endif
7372
Bram Moolenaar071d4272004-06-13 20:20:40 +00007373 /* 'virtualedit' */
7374 else if (varp == &p_ve)
7375 {
7376 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7377 errmsg = e_invarg;
7378 else if (STRCMP(p_ve, oldval) != 0)
7379 {
7380 /* Recompute cursor position in case the new 've' setting
7381 * changes something. */
7382 validate_virtcol();
7383 coladvance(curwin->w_virtcol);
7384 }
7385 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007386
7387#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7388 else if (varp == &p_csqf)
7389 {
7390 if (p_csqf != NULL)
7391 {
7392 p = p_csqf;
7393 while (*p != NUL)
7394 {
7395 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7396 || p[1] == NUL
7397 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7398 || (p[2] != NUL && p[2] != ','))
7399 {
7400 errmsg = e_invarg;
7401 break;
7402 }
7403 else if (p[2] == NUL)
7404 break;
7405 else
7406 p += 3;
7407 }
7408 }
7409 }
7410#endif
7411
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007412#ifdef FEAT_CINDENT
7413 /* 'cinoptions' */
7414 else if (gvarp == &p_cino)
7415 {
7416 /* TODO: recognize errors */
7417 parse_cino(curbuf);
7418 }
7419#endif
7420
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007421#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007422 /* 'renderoptions' */
Bram Moolenaar3767c6e2017-12-05 16:57:56 +01007423 else if (varp == &p_rop)
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007424 {
7425 if (!gui_mch_set_rendering_options(p_rop))
7426 errmsg = e_invarg;
7427 }
7428#endif
7429
Bram Moolenaard0b51382016-11-04 15:23:45 +01007430 else if (gvarp == &p_ft)
7431 {
7432 if (!valid_filetype(*varp))
7433 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007434 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007435 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007436 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007437
7438 // Since we check the value, there is no need to set P_INSECURE,
7439 // even when the value comes from a modeline.
7440 *value_checked = TRUE;
7441 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007442 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007443
7444#ifdef FEAT_SYN_HL
7445 else if (gvarp == &p_syn)
7446 {
7447 if (!valid_filetype(*varp))
7448 errmsg = e_invarg;
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007449 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007450 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007451 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007452
7453 // Since we check the value, there is no need to set P_INSECURE,
7454 // even when the value comes from a modeline.
7455 *value_checked = TRUE;
7456 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007457 }
7458#endif
7459
Bram Moolenaar825680f2017-07-22 17:04:02 +02007460#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007461 /* 'termwinkey' */
7462 else if (varp == &curwin->w_p_twk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007463 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007464 if (*curwin->w_p_twk != NUL
7465 && string_to_key(curwin->w_p_twk, TRUE) == 0)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007466 errmsg = e_invarg;
7467 }
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007468 /* 'termwinsize' */
7469 else if (varp == &curwin->w_p_tws)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007470 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007471 if (*curwin->w_p_tws != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007472 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007473 p = skipdigits(curwin->w_p_tws);
7474 if (p == curwin->w_p_tws
Bram Moolenaar498c2562018-04-15 23:45:15 +02007475 || (*p != 'x' && *p != '*')
7476 || *skipdigits(p + 1) != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007477 errmsg = e_invarg;
7478 }
7479 }
7480#endif
7481
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007482#ifdef FEAT_VARTABS
7483 /* 'varsofttabstop' */
7484 else if (varp == &(curbuf->b_p_vsts))
7485 {
7486 char_u *cp;
7487
7488 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7489 {
7490 if (curbuf->b_p_vsts_array)
7491 {
7492 vim_free(curbuf->b_p_vsts_array);
7493 curbuf->b_p_vsts_array = 0;
7494 }
7495 }
7496 else
7497 {
7498 for (cp = *varp; *cp; ++cp)
7499 {
7500 if (vim_isdigit(*cp))
7501 continue;
7502 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7503 continue;
7504 errmsg = e_invarg;
7505 break;
7506 }
7507 if (errmsg == NULL)
7508 {
7509 int *oldarray = curbuf->b_p_vsts_array;
7510 if (tabstop_set(*varp, &(curbuf->b_p_vsts_array)))
7511 {
7512 if (oldarray)
7513 vim_free(oldarray);
7514 }
7515 else
7516 errmsg = e_invarg;
7517 }
7518 }
7519 }
7520
7521 /* 'vartabstop' */
7522 else if (varp == &(curbuf->b_p_vts))
7523 {
7524 char_u *cp;
7525
7526 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7527 {
7528 if (curbuf->b_p_vts_array)
7529 {
7530 vim_free(curbuf->b_p_vts_array);
7531 curbuf->b_p_vts_array = NULL;
7532 }
7533 }
7534 else
7535 {
7536 for (cp = *varp; *cp; ++cp)
7537 {
7538 if (vim_isdigit(*cp))
7539 continue;
7540 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7541 continue;
7542 errmsg = e_invarg;
7543 break;
7544 }
7545 if (errmsg == NULL)
7546 {
7547 int *oldarray = curbuf->b_p_vts_array;
7548 if (tabstop_set(*varp, &(curbuf->b_p_vts_array)))
7549 {
7550 if (oldarray)
7551 vim_free(oldarray);
7552#ifdef FEAT_FOLDING
7553 if (foldmethodIsIndent(curwin))
7554 foldUpdateAll(curwin);
7555#endif /* FEAT_FOLDING */
7556 }
7557 else
7558 errmsg = e_invarg;
7559 }
7560 }
7561 }
7562#endif
7563
Bram Moolenaar071d4272004-06-13 20:20:40 +00007564 /* Options that are a list of flags. */
7565 else
7566 {
7567 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007568 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007569 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007570 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007571 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007572 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007573 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007574 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007575 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007576#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007577 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007578 p = (char_u *)COCU_ALL;
7579#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007580 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007581 {
7582#ifdef FEAT_MOUSE
7583 p = (char_u *)MOUSE_ALL;
7584#else
7585 if (*p_mouse != NUL)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007586 errmsg = N_("E538: No mouse support");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007587#endif
7588 }
7589#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007590 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007591 p = (char_u *)GO_ALL;
7592#endif
7593 if (p != NULL)
7594 {
7595 for (s = *varp; *s; ++s)
7596 if (vim_strchr(p, *s) == NULL)
7597 {
7598 errmsg = illegal_char(errbuf, *s);
7599 break;
7600 }
7601 }
7602 }
7603
7604 /*
7605 * If error detected, restore the previous value.
7606 */
7607 if (errmsg != NULL)
7608 {
7609 if (new_value_alloced)
7610 free_string_option(*varp);
7611 *varp = oldval;
7612 /*
7613 * When resetting some values, need to act on it.
7614 */
7615 if (did_chartab)
7616 (void)init_chartab();
7617 if (varp == &p_hl)
7618 (void)highlight_changed();
7619 }
7620 else
7621 {
7622#ifdef FEAT_EVAL
7623 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02007624 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007625#endif
7626 /*
7627 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007628 * Use "free_oldval", because recursiveness may change the flags under
7629 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007630 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007631 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007632 free_string_option(oldval);
7633 if (new_value_alloced)
7634 options[opt_idx].flags |= P_ALLOCED;
7635 else
7636 options[opt_idx].flags &= ~P_ALLOCED;
7637
7638 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007639 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007640 {
7641 /* global option with local value set to use global value; free
7642 * the local value and make it empty */
7643 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7644 free_string_option(*(char_u **)p);
7645 *(char_u **)p = empty_option;
7646 }
7647
7648 /* May set global value for local option. */
7649 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7650 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007651
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007652 /*
7653 * Trigger the autocommand only after setting the flags.
7654 */
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007655#ifdef FEAT_SYN_HL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007656 /* When 'syntax' is set, load the syntax of that name */
7657 if (varp == &(curbuf->b_p_syn))
7658 {
Bram Moolenaara5616b02018-06-17 19:08:30 +02007659 static int syn_recursive = 0;
7660
7661 ++syn_recursive;
7662 // Only pass TRUE for "force" when the value changed or not used
7663 // recursively, to avoid endless recurrence.
7664 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname,
7665 value_changed || syn_recursive == 1, curbuf);
7666 --syn_recursive;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007667 }
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007668#endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007669 else if (varp == &(curbuf->b_p_ft))
7670 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007671 /* 'filetype' is set, trigger the FileType autocommand.
7672 * Skip this when called from a modeline and the filetype was
Bram Moolenaara5616b02018-06-17 19:08:30 +02007673 * already set to this value. */
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007674 if (!(opt_flags & OPT_MODELINE) || value_changed)
Bram Moolenaar90492982017-06-22 14:16:31 +02007675 {
Bram Moolenaar916a8182018-11-25 02:18:29 +01007676 static int ft_recursive = 0;
7677 int secure_save = secure;
7678
7679 // Reset the secure flag, since the value of 'filetype' has
7680 // been checked to be safe.
7681 secure = 0;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007682
7683 ++ft_recursive;
Bram Moolenaar90492982017-06-22 14:16:31 +02007684 did_filetype = TRUE;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007685 // Only pass TRUE for "force" when the value changed or not
7686 // used recursively, to avoid endless recurrence.
7687 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname,
7688 value_changed || ft_recursive == 1, curbuf);
7689 --ft_recursive;
Bram Moolenaar163095f2017-07-09 15:41:53 +02007690 /* Just in case the old "curbuf" is now invalid. */
7691 if (varp != &(curbuf->b_p_ft))
7692 varp = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007693
7694 secure = secure_save;
Bram Moolenaar90492982017-06-22 14:16:31 +02007695 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007696 }
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007697#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007698 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007699 {
7700 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007701 char_u *q = curwin->w_s->b_p_spl;
7702
7703 /* Skip the first name if it is "cjk". */
7704 if (STRNCMP(q, "cjk,", 4) == 0)
7705 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007706
7707 /*
7708 * Source the spell/LANG.vim in 'runtimepath'.
7709 * They could set 'spellcapcheck' depending on the language.
7710 * Use the first name in 'spelllang' up to '_region' or
7711 * '.encoding'.
7712 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007713 for (p = q; *p != NUL; ++p)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01007714 if (!ASCII_ISALNUM(*p) && *p != '-')
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007715 break;
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007716 if (p > q)
7717 {
7718 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
7719 source_runtime(fname, DIP_ALL);
7720 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007721 }
7722#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007723 }
7724
7725#ifdef FEAT_MOUSE
7726 if (varp == &p_mouse)
7727 {
7728# ifdef FEAT_MOUSE_TTY
7729 if (*p_mouse == NUL)
7730 mch_setmouse(FALSE); /* switch mouse off */
7731 else
7732# endif
7733 setmouse(); /* in case 'mouse' changed */
7734 }
7735#endif
7736
Bram Moolenaar913077c2012-03-28 19:59:04 +02007737 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007738 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007739 curwin->w_set_curswant = TRUE;
7740
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007741#ifdef FEAT_GUI
7742 /* check redraw when it's not a GUI option or the GUI is active. */
7743 if (!redraw_gui_only || gui.in_use)
7744#endif
7745 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007746
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007747#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
7748 if (did_swaptcap)
7749 {
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007750 set_termname((char_u *)"win32");
7751 init_highlight(TRUE, FALSE);
7752 }
7753#endif
7754
Bram Moolenaar071d4272004-06-13 20:20:40 +00007755 return errmsg;
7756}
7757
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007758#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007759/*
7760 * Simple int comparison function for use with qsort()
7761 */
7762 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007763int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007764{
7765 return *(const int *)a - *(const int *)b;
7766}
7767
7768/*
7769 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7770 * Returns error message, NULL if it's OK.
7771 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007772 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007773check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007774{
7775 char_u *s;
7776 int col;
7777 int count = 0;
7778 int color_cols[256];
7779 int i;
7780 int j = 0;
7781
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007782 if (wp->w_buffer == NULL)
7783 return NULL; /* buffer was closed */
7784
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007785 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007786 {
7787 if (*s == '-' || *s == '+')
7788 {
7789 /* -N and +N: add to 'textwidth' */
7790 col = (*s == '-') ? -1 : 1;
7791 ++s;
7792 if (!VIM_ISDIGIT(*s))
7793 return e_invarg;
7794 col = col * getdigits(&s);
7795 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007796 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007797 col += wp->w_buffer->b_p_tw;
7798 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007799 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007800 }
7801 else if (VIM_ISDIGIT(*s))
7802 col = getdigits(&s);
7803 else
7804 return e_invarg;
7805 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007806skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007807 if (*s == NUL)
7808 break;
7809 if (*s != ',')
7810 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007811 if (*++s == NUL)
7812 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007813 }
7814
7815 vim_free(wp->w_p_cc_cols);
7816 if (count == 0)
7817 wp->w_p_cc_cols = NULL;
7818 else
7819 {
7820 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7821 if (wp->w_p_cc_cols != NULL)
7822 {
7823 /* sort the columns for faster usage on screen redraw inside
7824 * win_line() */
7825 qsort(color_cols, count, sizeof(int), int_cmp);
7826
7827 for (i = 0; i < count; ++i)
7828 /* skip duplicates */
7829 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7830 wp->w_p_cc_cols[j++] = color_cols[i];
7831 wp->w_p_cc_cols[j] = -1; /* end marker */
7832 }
7833 }
7834
7835 return NULL; /* no error */
7836}
7837#endif
7838
Bram Moolenaar071d4272004-06-13 20:20:40 +00007839/*
7840 * Handle setting 'listchars' or 'fillchars'.
7841 * Returns error message, NULL if it's OK.
7842 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007843 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007844set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007845{
7846 int round, i, len, entries;
7847 char_u *p, *s;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007848 int c1 = 0, c2 = 0, c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007849 struct charstab
7850 {
7851 int *cp;
7852 char *name;
7853 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007854 static struct charstab filltab[] =
7855 {
7856 {&fill_stl, "stl"},
7857 {&fill_stlnc, "stlnc"},
7858 {&fill_vert, "vert"},
7859 {&fill_fold, "fold"},
7860 {&fill_diff, "diff"},
7861 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007862 static struct charstab lcstab[] =
7863 {
7864 {&lcs_eol, "eol"},
7865 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007866 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007867 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007868 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007869 {&lcs_tab2, "tab"},
7870 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007871#ifdef FEAT_CONCEAL
7872 {&lcs_conceal, "conceal"},
7873#else
7874 {NULL, "conceal"},
7875#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007876 };
7877 struct charstab *tab;
7878
Bram Moolenaar071d4272004-06-13 20:20:40 +00007879 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007880 {
7881 tab = lcstab;
7882 entries = sizeof(lcstab) / sizeof(struct charstab);
7883 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007884 else
7885 {
7886 tab = filltab;
7887 entries = sizeof(filltab) / sizeof(struct charstab);
7888 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007889
7890 /* first round: check for valid value, second round: assign values */
7891 for (round = 0; round <= 1; ++round)
7892 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007893 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007894 {
7895 /* After checking that the value is valid: set defaults: space for
7896 * 'fillchars', NUL for 'listchars' */
7897 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007898 if (tab[i].cp != NULL)
7899 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar83a52172019-01-16 22:41:54 +01007900
Bram Moolenaar071d4272004-06-13 20:20:40 +00007901 if (varp == &p_lcs)
Bram Moolenaar83a52172019-01-16 22:41:54 +01007902 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007903 lcs_tab1 = NUL;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007904 lcs_tab3 = NUL;
7905 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007906 else
7907 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007908 }
7909 p = *varp;
7910 while (*p)
7911 {
7912 for (i = 0; i < entries; ++i)
7913 {
7914 len = (int)STRLEN(tab[i].name);
7915 if (STRNCMP(p, tab[i].name, len) == 0
7916 && p[len] == ':'
7917 && p[len + 1] != NUL)
7918 {
Bram Moolenaar83a52172019-01-16 22:41:54 +01007919 c1 = c2 = c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007920 s = p + len + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007921 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007922 if (mb_char2cells(c1) > 1)
7923 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007924 if (tab[i].cp == &lcs_tab2)
7925 {
7926 if (*s == NUL)
7927 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007928 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007929 if (mb_char2cells(c2) > 1)
7930 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007931 if (!(*s == ',' || *s == NUL))
7932 {
Bram Moolenaar83a52172019-01-16 22:41:54 +01007933 c3 = mb_ptr2char_adv(&s);
7934 if (mb_char2cells(c3) > 1)
7935 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007936 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007937 }
Bram Moolenaar83a52172019-01-16 22:41:54 +01007938
Bram Moolenaar071d4272004-06-13 20:20:40 +00007939 if (*s == ',' || *s == NUL)
7940 {
7941 if (round)
7942 {
7943 if (tab[i].cp == &lcs_tab2)
7944 {
7945 lcs_tab1 = c1;
7946 lcs_tab2 = c2;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007947 lcs_tab3 = c3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007948 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007949 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007950 *(tab[i].cp) = c1;
7951
7952 }
7953 p = s;
7954 break;
7955 }
7956 }
7957 }
7958
7959 if (i == entries)
7960 return e_invarg;
7961 if (*p == ',')
7962 ++p;
7963 }
7964 }
7965
7966 return NULL; /* no error */
7967}
7968
7969#ifdef FEAT_STL_OPT
7970/*
7971 * Check validity of options with the 'statusline' format.
7972 * Return error message or NULL.
7973 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007974 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007975check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007976{
7977 int itemcnt = 0;
7978 int groupdepth = 0;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007979 static char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00007980
7981 while (*s && itemcnt < STL_MAX_ITEM)
7982 {
7983 /* Check for valid keys after % sequences */
7984 while (*s && *s != '%')
7985 s++;
7986 if (!*s)
7987 break;
7988 s++;
7989 if (*s != '%' && *s != ')')
7990 ++itemcnt;
7991 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7992 {
7993 s++;
7994 continue;
7995 }
7996 if (*s == ')')
7997 {
7998 s++;
7999 if (--groupdepth < 0)
8000 break;
8001 continue;
8002 }
8003 if (*s == '-')
8004 s++;
8005 while (VIM_ISDIGIT(*s))
8006 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00008007 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008008 continue;
8009 if (*s == '.')
8010 {
8011 s++;
8012 while (*s && VIM_ISDIGIT(*s))
8013 s++;
8014 }
8015 if (*s == '(')
8016 {
8017 groupdepth++;
8018 continue;
8019 }
8020 if (vim_strchr(STL_ALL, *s) == NULL)
8021 {
8022 return illegal_char(errbuf, *s);
8023 }
8024 if (*s == '{')
8025 {
8026 s++;
8027 while (*s != '}' && *s)
8028 s++;
8029 if (*s != '}')
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008030 return N_("E540: Unclosed expression sequence");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008031 }
8032 }
8033 if (itemcnt >= STL_MAX_ITEM)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008034 return N_("E541: too many items");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008035 if (groupdepth != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008036 return N_("E542: unbalanced groups");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008037 return NULL;
8038}
8039#endif
8040
8041#ifdef FEAT_CLIPBOARD
8042/*
8043 * Extract the items in the 'clipboard' option and set global values.
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008044 * Return an error message or NULL for success.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008045 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008046 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008047check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008048{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008049 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008050 int new_autoselect_star = FALSE;
8051 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008052 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008053 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008054 regprog_T *new_exclude_prog = NULL;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008055 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008056 char_u *p;
8057
8058 for (p = p_cb; *p != NUL; )
8059 {
8060 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
8061 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008062 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008063 p += 7;
8064 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02008065 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008066 && (p[11] == ',' || p[11] == NUL))
8067 {
8068 new_unnamed |= CLIP_UNNAMED_PLUS;
8069 p += 11;
8070 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008071 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008072 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008073 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02008074 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008075 p += 10;
8076 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02008077 else if (STRNCMP(p, "autoselectplus", 14) == 0
8078 && (p[14] == ',' || p[14] == NUL))
8079 {
8080 new_autoselect_plus = TRUE;
8081 p += 14;
8082 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008083 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008084 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008085 {
8086 new_autoselectml = TRUE;
8087 p += 12;
8088 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008089 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
8090 {
8091 new_html = TRUE;
8092 p += 4;
8093 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008094 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
8095 {
8096 p += 8;
8097 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
8098 if (new_exclude_prog == NULL)
8099 errmsg = e_invarg;
8100 break;
8101 }
8102 else
8103 {
8104 errmsg = e_invarg;
8105 break;
8106 }
8107 if (*p == ',')
8108 ++p;
8109 }
8110 if (errmsg == NULL)
8111 {
8112 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008113 clip_autoselect_star = new_autoselect_star;
8114 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008115 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008116 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008117 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008118 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008119#ifdef FEAT_GUI_GTK
8120 if (gui.in_use)
8121 {
8122 gui_gtk_set_selection_targets();
8123 gui_gtk_set_dnd_targets();
8124 }
8125#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008126 }
8127 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008128 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008129
8130 return errmsg;
8131}
8132#endif
8133
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008134#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008135/*
8136 * Handle side effects of setting 'spell'.
8137 * Return an error message or NULL for success.
8138 */
8139 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008140did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008141{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008142 char *errmsg = NULL;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008143 win_T *wp;
8144 int l;
8145
8146 if (is_spellfile)
8147 {
8148 l = (int)STRLEN(curwin->w_s->b_p_spf);
8149 if (l > 0 && (l < 4
8150 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8151 errmsg = e_invarg;
8152 }
8153
8154 if (errmsg == NULL)
8155 {
8156 FOR_ALL_WINDOWS(wp)
8157 if (wp->w_buffer == curbuf && wp->w_p_spell)
8158 {
8159 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008160 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008161 }
8162 }
8163 return errmsg;
8164}
8165
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008166/*
8167 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8168 * Return error message when failed, NULL when OK.
8169 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008170 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008171compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008172{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008173 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008174 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008175
Bram Moolenaar860cae12010-06-05 23:22:07 +02008176 if (*synblock->b_p_spc == NUL)
8177 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008178 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008179 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008180 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008181 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008182 if (re != NULL)
8183 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008184 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008185 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008186 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008187 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008188 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008189 return e_invarg;
8190 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008191 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008192 }
8193
Bram Moolenaar473de612013-06-08 18:19:48 +02008194 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008195 return NULL;
8196}
8197#endif
8198
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008199#if defined(FEAT_EVAL) || defined(PROTO)
8200/*
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008201 * Set the script_ctx for an option, taking care of setting the buffer- or
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008202 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008203 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008204 static void
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008205set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008206{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008207 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8208 int indir = (int)options[opt_idx].indir;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008209 sctx_T new_script_ctx = script_ctx;
8210
8211 new_script_ctx.sc_lnum += sourcing_lnum;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008212
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008213 /* Remember where the option was set. For local options need to do that
8214 * in the buffer or window structure. */
8215 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008216 options[opt_idx].script_ctx = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008217 if (both || (opt_flags & OPT_LOCAL))
8218 {
8219 if (indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008220 curbuf->b_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008221 else if (indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008222 curwin->w_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008223 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008224}
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02008225
8226/*
8227 * Set the script_ctx for a termcap option.
8228 * "name" must be the two character code, e.g. "RV".
8229 * When "name" is NULL use "opt_idx".
8230 */
8231 void
8232set_term_option_sctx_idx(char *name, int opt_idx)
8233{
8234 char_u buf[5];
8235 int idx;
8236
8237 if (name == NULL)
8238 idx = opt_idx;
8239 else
8240 {
8241 buf[0] = 't';
8242 buf[1] = '_';
8243 buf[2] = name[0];
8244 buf[3] = name[1];
8245 buf[4] = 0;
8246 idx = findoption(buf);
8247 }
8248 if (idx >= 0)
8249 set_option_sctx_idx(idx, OPT_GLOBAL, current_sctx);
8250}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008251#endif
8252
Bram Moolenaar071d4272004-06-13 20:20:40 +00008253/*
8254 * Set the value of a boolean option, and take care of side effects.
8255 * Returns NULL for success, or an error message for an error.
8256 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008257 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008258set_bool_option(
8259 int opt_idx, /* index in options[] table */
8260 char_u *varp, /* pointer to the option variable */
8261 int value, /* new value */
8262 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008263{
8264 int old_value = *(int *)varp;
8265
Bram Moolenaar071d4272004-06-13 20:20:40 +00008266 /* Disallow changing some options from secure mode */
8267 if ((secure
8268#ifdef HAVE_SANDBOX
8269 || sandbox != 0
8270#endif
8271 ) && (options[opt_idx].flags & P_SECURE))
8272 return e_secure;
8273
8274 *(int *)varp = value; /* set the new value */
8275#ifdef FEAT_EVAL
8276 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008277 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008278#endif
8279
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008280#ifdef FEAT_GUI
8281 need_mouse_correct = TRUE;
8282#endif
8283
Bram Moolenaar071d4272004-06-13 20:20:40 +00008284 /* May set global value for local option. */
8285 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8286 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8287
8288 /*
8289 * Handle side effects of changing a bool option.
8290 */
8291
8292 /* 'compatible' */
8293 if ((int *)varp == &p_cp)
8294 {
8295 compatible_set();
8296 }
8297
Bram Moolenaar920694c2016-08-21 17:45:02 +02008298#ifdef FEAT_LANGMAP
8299 if ((int *)varp == &p_lrm)
8300 /* 'langremap' -> !'langnoremap' */
8301 p_lnr = !p_lrm;
8302 else if ((int *)varp == &p_lnr)
8303 /* 'langnoremap' -> !'langremap' */
8304 p_lrm = !p_lnr;
8305#endif
8306
Bram Moolenaar8c63e0e2018-09-25 22:17:54 +02008307#ifdef FEAT_SYN_HL
8308 else if ((int *)varp == &curwin->w_p_cul && !value && old_value)
8309 reset_cursorline();
8310#endif
8311
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008312#ifdef FEAT_PERSISTENT_UNDO
8313 /* 'undofile' */
8314 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8315 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008316 /* Only take action when the option was set. When reset we do not
8317 * delete the undo file, the option may be set again without making
8318 * any changes in between. */
8319 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008320 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008321 char_u hash[UNDO_HASH_SIZE];
8322 buf_T *save_curbuf = curbuf;
8323
Bram Moolenaar29323592016-07-24 22:04:11 +02008324 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008325 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008326 /* When 'undofile' is set globally: for every buffer, otherwise
8327 * only for the current buffer: Try to read in the undofile,
8328 * if one exists, the buffer wasn't changed and the buffer was
8329 * loaded */
8330 if ((curbuf == save_curbuf
8331 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8332 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8333 {
8334 u_compute_hash(hash);
8335 u_read_undo(NULL, hash, curbuf->b_fname);
8336 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008337 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008338 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008339 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008340 }
8341#endif
8342
Bram Moolenaar071d4272004-06-13 20:20:40 +00008343 else if ((int *)varp == &curbuf->b_p_ro)
8344 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008345 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008346 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8347 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008348
8349 /* when 'readonly' is set may give W10 again */
8350 if (curbuf->b_p_ro)
8351 curbuf->b_did_warn = FALSE;
8352
Bram Moolenaar071d4272004-06-13 20:20:40 +00008353#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008354 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008355#endif
8356 }
8357
Bram Moolenaar9c449722010-07-20 18:44:27 +02008358#ifdef FEAT_GUI
8359 else if ((int *)varp == &p_mh)
8360 {
8361 if (!p_mh)
8362 gui_mch_mousehide(FALSE);
8363 }
8364#endif
8365
Bram Moolenaara539df02010-08-01 14:35:05 +02008366 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008367 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008368 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008369# ifdef FEAT_TERMINAL
8370 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaard7db27b2018-03-07 23:02:33 +01008371 if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf)
8372 && curbuf->b_term != NULL && !term_is_finished(curbuf))))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008373 {
8374 curbuf->b_p_ma = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008375 return N_("E946: Cannot make a terminal with running job modifiable");
Bram Moolenaar423802d2017-07-30 16:52:24 +02008376 }
8377# endif
8378# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008379 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008380# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008381 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008382#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008383 /* when 'endofline' is changed, redraw the window title */
8384 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008385 {
8386 redraw_titles();
8387 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008388 /* when 'fixeol' is changed, redraw the window title */
8389 else if ((int *)varp == &curbuf->b_p_fixeol)
8390 {
8391 redraw_titles();
8392 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008393 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008394 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008395 {
8396 redraw_titles();
8397 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008398#endif
8399
8400 /* when 'bin' is set also set some other options */
8401 else if ((int *)varp == &curbuf->b_p_bin)
8402 {
8403 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8404#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008405 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008406#endif
8407 }
8408
Bram Moolenaar071d4272004-06-13 20:20:40 +00008409 /* when 'buflisted' changes, trigger autocommands */
8410 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8411 {
8412 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8413 NULL, NULL, TRUE, curbuf);
8414 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008415
8416 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8417 else if ((int *)varp == &curbuf->b_p_swf)
8418 {
8419 if (curbuf->b_p_swf && p_uc)
8420 ml_open_file(curbuf); /* create the swap file */
8421 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008422 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8423 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008424 mf_close_file(curbuf, TRUE); /* remove the swap file */
8425 }
8426
8427 /* when 'terse' is set change 'shortmess' */
8428 else if ((int *)varp == &p_terse)
8429 {
8430 char_u *p;
8431
8432 p = vim_strchr(p_shm, SHM_SEARCH);
8433
8434 /* insert 's' in p_shm */
8435 if (p_terse && p == NULL)
8436 {
8437 STRCPY(IObuff, p_shm);
8438 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008439 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008440 }
8441 /* remove 's' from p_shm */
8442 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008443 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008444 }
8445
8446 /* when 'paste' is set or reset also change other options */
8447 else if ((int *)varp == &p_paste)
8448 {
8449 paste_option_changed();
8450 }
8451
8452 /* when 'insertmode' is set from an autocommand need to do work here */
8453 else if ((int *)varp == &p_im)
8454 {
8455 if (p_im)
8456 {
8457 if ((State & INSERT) == 0)
8458 need_start_insertmode = TRUE;
8459 stop_insert_mode = FALSE;
8460 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008461 /* only reset if it was set previously */
8462 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008463 {
8464 need_start_insertmode = FALSE;
8465 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008466 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008467 clear_cmdline = TRUE; /* remove "(insert)" */
8468 restart_edit = 0;
8469 }
8470 }
8471
8472 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8473 else if ((int *)varp == &p_ic && p_hls)
8474 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008475 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008476 }
8477
8478#ifdef FEAT_SEARCH_EXTRA
8479 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8480 else if ((int *)varp == &p_hls)
8481 {
Bram Moolenaar451fc7b2018-04-27 22:53:07 +02008482 set_no_hlsearch(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008483 }
8484#endif
8485
Bram Moolenaar071d4272004-06-13 20:20:40 +00008486 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8487 * at the end of normal_cmd() */
8488 else if ((int *)varp == &curwin->w_p_scb)
8489 {
8490 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008491 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008492 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008493 curwin->w_scbind_pos = curwin->w_topline;
8494 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008495 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008496
Bram Moolenaar4033c552017-09-16 20:54:51 +02008497#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008498 /* There can be only one window with 'previewwindow' set. */
8499 else if ((int *)varp == &curwin->w_p_pvw)
8500 {
8501 if (curwin->w_p_pvw)
8502 {
8503 win_T *win;
8504
Bram Moolenaar29323592016-07-24 22:04:11 +02008505 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008506 if (win->w_p_pvw && win != curwin)
8507 {
8508 curwin->w_p_pvw = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008509 return N_("E590: A preview window already exists");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008510 }
8511 }
8512 }
8513#endif
8514
8515 /* when 'textmode' is set or reset also change 'fileformat' */
8516 else if ((int *)varp == &curbuf->b_p_tx)
8517 {
8518 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8519 }
8520
8521 /* when 'textauto' is set or reset also change 'fileformats' */
8522 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008523 set_string_option_direct((char_u *)"ffs", -1,
8524 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008525 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008526
8527 /*
8528 * When 'lisp' option changes include/exclude '-' in
8529 * keyword characters.
8530 */
8531#ifdef FEAT_LISP
8532 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8533 {
8534 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8535 }
8536#endif
8537
8538#ifdef FEAT_TITLE
8539 /* when 'title' changed, may need to change the title; same for 'icon' */
Bram Moolenaar84a93082018-06-16 22:58:15 +02008540 else if ((int *)varp == &p_title || (int *)varp == &p_icon)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008541 {
Bram Moolenaar84a93082018-06-16 22:58:15 +02008542 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008543 }
8544#endif
8545
8546 else if ((int *)varp == &curbuf->b_changed)
8547 {
8548 if (!value)
8549 save_file_ff(curbuf); /* Buffer is unchanged */
8550#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008551 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008552#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008553 modified_was_set = value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008554 }
8555
8556#ifdef BACKSLASH_IN_FILENAME
8557 else if ((int *)varp == &p_ssl)
8558 {
8559 if (p_ssl)
8560 {
8561 psepc = '/';
8562 psepcN = '\\';
8563 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008564 }
8565 else
8566 {
8567 psepc = '\\';
8568 psepcN = '/';
8569 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008570 }
8571
8572 /* need to adjust the file name arguments and buffer names. */
8573 buflist_slash_adjust();
8574 alist_slash_adjust();
8575# ifdef FEAT_EVAL
8576 scriptnames_slash_adjust();
8577# endif
8578 }
8579#endif
8580
8581 /* If 'wrap' is set, set w_leftcol to zero. */
8582 else if ((int *)varp == &curwin->w_p_wrap)
8583 {
8584 if (curwin->w_p_wrap)
8585 curwin->w_leftcol = 0;
8586 }
8587
Bram Moolenaar071d4272004-06-13 20:20:40 +00008588 else if ((int *)varp == &p_ea)
8589 {
8590 if (p_ea && !old_value)
8591 win_equal(curwin, FALSE, 0);
8592 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008593
8594 else if ((int *)varp == &p_wiv)
8595 {
8596 /*
8597 * When 'weirdinvert' changed, set/reset 't_xs'.
8598 * Then set 'weirdinvert' according to value of 't_xs'.
8599 */
8600 if (p_wiv && !old_value)
8601 T_XS = (char_u *)"y";
8602 else if (!p_wiv && old_value)
8603 T_XS = empty_option;
8604 p_wiv = (*T_XS != NUL);
8605 }
8606
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008607#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008608 else if ((int *)varp == &p_beval)
8609 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008610 if (!balloonEvalForTerm)
8611 {
8612 if (p_beval && !old_value)
8613 gui_mch_enable_beval_area(balloonEval);
8614 else if (!p_beval && old_value)
8615 gui_mch_disable_beval_area(balloonEval);
8616 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008617 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008618#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008619#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008620 else if ((int *)varp == &p_bevalterm)
8621 {
8622 mch_bevalterm_changed();
8623 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008624#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008625
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008626#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008627 else if ((int *)varp == &p_acd)
8628 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008629 /* Change directories when the 'acd' option is set now. */
Bram Moolenaar6f470022018-04-10 18:47:20 +02008630 DO_AUTOCHDIR;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008631 }
8632#endif
8633
8634#ifdef FEAT_DIFF
8635 /* 'diff' */
8636 else if ((int *)varp == &curwin->w_p_diff)
8637 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008638 /* May add or remove the buffer from the list of diff buffers. */
8639 diff_buf_adjust(curwin);
8640# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008641 if (foldmethodIsDiff(curwin))
8642 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008643# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008644 }
8645#endif
8646
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008647#ifdef HAVE_INPUT_METHOD
Bram Moolenaar071d4272004-06-13 20:20:40 +00008648 /* 'imdisable' */
8649 else if ((int *)varp == &p_imdisable)
8650 {
8651 /* Only de-activate it here, it will be enabled when changing mode. */
8652 if (p_imdisable)
8653 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008654 else if (State & INSERT)
8655 /* When the option is set from an autocommand, it may need to take
8656 * effect right away. */
8657 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008658 }
8659#endif
8660
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008661#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008662 /* 'spell' */
8663 else if ((int *)varp == &curwin->w_p_spell)
8664 {
8665 if (curwin->w_p_spell)
8666 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008667 char *errmsg = did_set_spelllang(curwin);
8668
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008669 if (errmsg != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008670 emsg(_(errmsg));
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008671 }
8672 }
8673#endif
8674
Bram Moolenaar071d4272004-06-13 20:20:40 +00008675#ifdef FEAT_FKMAP
8676 else if ((int *)varp == &p_altkeymap)
8677 {
8678 if (old_value != p_altkeymap)
8679 {
8680 if (!p_altkeymap)
8681 {
8682 p_hkmap = p_fkmap;
8683 p_fkmap = 0;
8684 }
8685 else
8686 {
8687 p_fkmap = p_hkmap;
8688 p_hkmap = 0;
8689 }
8690 (void)init_chartab();
8691 }
8692 }
8693
8694 /*
8695 * In case some second language keymapping options have changed, check
8696 * and correct the setting in a consistent way.
8697 */
8698
8699 /*
8700 * If hkmap or fkmap are set, reset Arabic keymapping.
8701 */
8702 if ((p_hkmap || p_fkmap) && p_altkeymap)
8703 {
8704 p_altkeymap = p_fkmap;
8705# ifdef FEAT_ARABIC
8706 curwin->w_p_arab = FALSE;
8707# endif
8708 (void)init_chartab();
8709 }
8710
8711 /*
8712 * If hkmap set, reset Farsi keymapping.
8713 */
8714 if (p_hkmap && p_altkeymap)
8715 {
8716 p_altkeymap = 0;
8717 p_fkmap = 0;
8718# ifdef FEAT_ARABIC
8719 curwin->w_p_arab = FALSE;
8720# endif
8721 (void)init_chartab();
8722 }
8723
8724 /*
8725 * If fkmap set, reset Hebrew keymapping.
8726 */
8727 if (p_fkmap && !p_altkeymap)
8728 {
8729 p_altkeymap = 1;
8730 p_hkmap = 0;
8731# ifdef FEAT_ARABIC
8732 curwin->w_p_arab = FALSE;
8733# endif
8734 (void)init_chartab();
8735 }
8736#endif
8737
8738#ifdef FEAT_ARABIC
8739 if ((int *)varp == &curwin->w_p_arab)
8740 {
8741 if (curwin->w_p_arab)
8742 {
8743 /*
8744 * 'arabic' is set, handle various sub-settings.
8745 */
8746 if (!p_tbidi)
8747 {
8748 /* set rightleft mode */
8749 if (!curwin->w_p_rl)
8750 {
8751 curwin->w_p_rl = TRUE;
8752 changed_window_setting();
8753 }
8754
8755 /* Enable Arabic shaping (major part of what Arabic requires) */
8756 if (!p_arshape)
8757 {
8758 p_arshape = TRUE;
8759 redraw_later_clear();
8760 }
8761 }
8762
8763 /* Arabic requires a utf-8 encoding, inform the user if its not
8764 * set. */
8765 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008766 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008767 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8768
Bram Moolenaar8820b482017-03-16 17:23:31 +01008769 msg_source(HL_ATTR(HLF_W));
Bram Moolenaar32526b32019-01-19 17:43:09 +01008770 msg_attr(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008771#ifdef FEAT_EVAL
8772 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8773#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008774 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008775
Bram Moolenaar071d4272004-06-13 20:20:40 +00008776 /* set 'delcombine' */
8777 p_deco = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008778
8779# ifdef FEAT_KEYMAP
8780 /* Force-set the necessary keymap for arabic */
8781 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8782 OPT_LOCAL);
8783# endif
8784# ifdef FEAT_FKMAP
8785 p_altkeymap = 0;
8786 p_hkmap = 0;
8787 p_fkmap = 0;
8788 (void)init_chartab();
8789# endif
8790 }
8791 else
8792 {
8793 /*
8794 * 'arabic' is reset, handle various sub-settings.
8795 */
8796 if (!p_tbidi)
8797 {
8798 /* reset rightleft mode */
8799 if (curwin->w_p_rl)
8800 {
8801 curwin->w_p_rl = FALSE;
8802 changed_window_setting();
8803 }
8804
8805 /* 'arabicshape' isn't reset, it is a global option and
8806 * another window may still need it "on". */
8807 }
8808
8809 /* 'delcombine' isn't reset, it is a global option and another
8810 * window may still want it "on". */
8811
8812# ifdef FEAT_KEYMAP
8813 /* Revert to the default keymap */
8814 curbuf->b_p_iminsert = B_IMODE_NONE;
8815 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8816# endif
8817 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008818 }
8819
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008820#endif
8821
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008822#ifdef FEAT_TERMGUICOLORS
8823 /* 'termguicolors' */
8824 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008825 {
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008826# ifdef FEAT_VTP
8827 /* Do not turn on 'tgc' when 24-bit colors are not supported. */
8828 if (!has_vtp_working())
8829 {
8830 p_tgc = 0;
8831 return (char_u*)N_("E954: 24-bit colors are not supported on this environment");
8832 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008833 if (is_term_win32())
8834 swap_tcap();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008835# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008836# ifdef FEAT_GUI
8837 if (!gui.in_use && !gui.starting)
8838# endif
8839 highlight_gui_started();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008840# ifdef FEAT_VTP
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008841 /* reset t_Co */
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008842 if (is_term_win32())
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02008843 {
8844 control_console_color_rgb();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008845 set_termname(T_NAME);
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02008846 init_highlight(TRUE, FALSE);
8847 }
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008848# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008849 }
8850#endif
8851
Bram Moolenaar071d4272004-06-13 20:20:40 +00008852 /*
8853 * End of handling side effects for bool options.
8854 */
8855
Bram Moolenaar53744302015-07-17 17:38:22 +02008856 /* after handling side effects, call autocommand */
8857
Bram Moolenaar071d4272004-06-13 20:20:40 +00008858 options[opt_idx].flags |= P_WAS_SET;
8859
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008860#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02008861 // Don't do this while starting up or recursively.
8862 if (!starting && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02008863 {
8864 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02008865
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008866 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8867 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8868 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008869 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8870 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8871 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8872 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8873 reset_v_option_vars();
8874 }
8875#endif
8876
Bram Moolenaar071d4272004-06-13 20:20:40 +00008877 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008878 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008879 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008880 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008881 check_redraw(options[opt_idx].flags);
8882
8883 return NULL;
8884}
8885
8886/*
8887 * Set the value of a number option, and take care of side effects.
8888 * Returns NULL for success, or an error message for an error.
8889 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008890 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008891set_num_option(
8892 int opt_idx, /* index in options[] table */
8893 char_u *varp, /* pointer to the option variable */
8894 long value, /* new value */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008895 char *errbuf, /* buffer for error messages */
Bram Moolenaar9b578142016-01-30 19:39:49 +01008896 size_t errbuflen, /* length of "errbuf" */
8897 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008898 OPT_MODELINE */
8899{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008900 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008901 long old_value = *(long *)varp;
8902 long old_Rows = Rows; /* remember old Rows */
8903 long old_Columns = Columns; /* remember old Columns */
8904 long *pp = (long *)varp;
8905
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008906 /* Disallow changing some options from secure mode. */
8907 if ((secure
8908#ifdef HAVE_SANDBOX
8909 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008910#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008911 ) && (options[opt_idx].flags & P_SECURE))
8912 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008913
8914 *pp = value;
8915#ifdef FEAT_EVAL
8916 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008917 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008918#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008919#ifdef FEAT_GUI
8920 need_mouse_correct = TRUE;
8921#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008922
Bram Moolenaar14f24742012-08-08 18:01:05 +02008923 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008924 {
8925 errmsg = e_positive;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02008926#ifdef FEAT_VARTABS
8927 // Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use.
8928 curbuf->b_p_sw = tabstop_count(curbuf->b_p_vts_array) > 0
8929 ? tabstop_first(curbuf->b_p_vts_array)
8930 : curbuf->b_p_ts;
8931#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00008932 curbuf->b_p_sw = curbuf->b_p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02008933#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008934 }
8935
8936 /*
8937 * Number options that need some action when changed
8938 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008939 if (pp == &p_wh || pp == &p_hh)
8940 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008941 // 'winheight' and 'helpheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008942 if (p_wh < 1)
8943 {
8944 errmsg = e_positive;
8945 p_wh = 1;
8946 }
8947 if (p_wmh > p_wh)
8948 {
8949 errmsg = e_winheight;
8950 p_wh = p_wmh;
8951 }
8952 if (p_hh < 0)
8953 {
8954 errmsg = e_positive;
8955 p_hh = 0;
8956 }
8957
8958 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008959 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008960 {
8961 if (pp == &p_wh && curwin->w_height < p_wh)
8962 win_setheight((int)p_wh);
8963 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8964 win_setheight((int)p_hh);
8965 }
8966 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008967 else if (pp == &p_wmh)
8968 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008969 // 'winminheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008970 if (p_wmh < 0)
8971 {
8972 errmsg = e_positive;
8973 p_wmh = 0;
8974 }
8975 if (p_wmh > p_wh)
8976 {
8977 errmsg = e_winheight;
8978 p_wmh = p_wh;
8979 }
8980 win_setminheight();
8981 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008982 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008983 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008984 // 'winwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008985 if (p_wiw < 1)
8986 {
8987 errmsg = e_positive;
8988 p_wiw = 1;
8989 }
8990 if (p_wmw > p_wiw)
8991 {
8992 errmsg = e_winwidth;
8993 p_wiw = p_wmw;
8994 }
8995
8996 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008997 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008998 win_setwidth((int)p_wiw);
8999 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009000 else if (pp == &p_wmw)
9001 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009002 // 'winminwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009003 if (p_wmw < 0)
9004 {
9005 errmsg = e_positive;
9006 p_wmw = 0;
9007 }
9008 if (p_wmw > p_wiw)
9009 {
9010 errmsg = e_winwidth;
9011 p_wmw = p_wiw;
9012 }
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009013 win_setminwidth();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009014 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009015
Bram Moolenaar071d4272004-06-13 20:20:40 +00009016 /* (re)set last window status line */
9017 else if (pp == &p_ls)
9018 {
9019 last_status(FALSE);
9020 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009021
9022 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00009023 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009024 {
9025 shell_new_rows(); /* recompute window positions and heights */
9026 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009027
9028#ifdef FEAT_GUI
9029 else if (pp == &p_linespace)
9030 {
Bram Moolenaar02743632005-07-25 20:42:36 +00009031 /* Recompute gui.char_height and resize the Vim window to keep the
9032 * same number of lines. */
9033 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00009034 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009035 }
9036#endif
9037
9038#ifdef FEAT_FOLDING
9039 /* 'foldlevel' */
9040 else if (pp == &curwin->w_p_fdl)
9041 {
9042 if (curwin->w_p_fdl < 0)
9043 curwin->w_p_fdl = 0;
9044 newFoldLevel();
9045 }
9046
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00009047 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009048 else if (pp == &curwin->w_p_fml)
9049 {
9050 foldUpdateAll(curwin);
9051 }
9052
9053 /* 'foldnestmax' */
9054 else if (pp == &curwin->w_p_fdn)
9055 {
9056 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
9057 foldUpdateAll(curwin);
9058 }
9059
9060 /* 'foldcolumn' */
9061 else if (pp == &curwin->w_p_fdc)
9062 {
9063 if (curwin->w_p_fdc < 0)
9064 {
9065 errmsg = e_positive;
9066 curwin->w_p_fdc = 0;
9067 }
9068 else if (curwin->w_p_fdc > 12)
9069 {
9070 errmsg = e_invarg;
9071 curwin->w_p_fdc = 12;
9072 }
9073 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009074#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009075
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009076#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009077 /* 'shiftwidth' or 'tabstop' */
9078 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
9079 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009080# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00009081 if (foldmethodIsIndent(curwin))
9082 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009083# endif
9084# ifdef FEAT_CINDENT
9085 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
9086 * parse 'cinoptions'. */
9087 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
9088 parse_cino(curbuf);
9089# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009090 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009091#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009092
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009093 /* 'maxcombine' */
9094 else if (pp == &p_mco)
9095 {
9096 if (p_mco > MAX_MCO)
9097 p_mco = MAX_MCO;
9098 else if (p_mco < 0)
9099 p_mco = 0;
9100 screenclear(); /* will re-allocate the screen */
9101 }
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009102
Bram Moolenaar071d4272004-06-13 20:20:40 +00009103 else if (pp == &curbuf->b_p_iminsert)
9104 {
9105 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
9106 {
9107 errmsg = e_invarg;
9108 curbuf->b_p_iminsert = B_IMODE_NONE;
9109 }
9110 p_iminsert = curbuf->b_p_iminsert;
9111 if (termcap_active) /* don't do this in the alternate screen */
9112 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02009113#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009114 /* Show/unshow value of 'keymap' in status lines. */
9115 status_redraw_curbuf();
9116#endif
9117 }
9118
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02009119#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
9120 /* 'imstyle' */
9121 else if (pp == &p_imst)
9122 {
9123 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
9124 errmsg = e_invarg;
9125 }
9126#endif
9127
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009128 else if (pp == &p_window)
9129 {
9130 if (p_window < 1)
9131 p_window = 1;
9132 else if (p_window >= Rows)
9133 p_window = Rows - 1;
9134 }
9135
Bram Moolenaar071d4272004-06-13 20:20:40 +00009136 else if (pp == &curbuf->b_p_imsearch)
9137 {
9138 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
9139 {
9140 errmsg = e_invarg;
9141 curbuf->b_p_imsearch = B_IMODE_NONE;
9142 }
9143 p_imsearch = curbuf->b_p_imsearch;
9144 }
9145
9146#ifdef FEAT_TITLE
9147 /* if 'titlelen' has changed, redraw the title */
9148 else if (pp == &p_titlelen)
9149 {
9150 if (p_titlelen < 0)
9151 {
9152 errmsg = e_positive;
9153 p_titlelen = 85;
9154 }
9155 if (starting != NO_SCREEN && old_value != p_titlelen)
9156 need_maketitle = TRUE;
9157 }
9158#endif
9159
9160 /* if p_ch changed value, change the command line height */
9161 else if (pp == &p_ch)
9162 {
9163 if (p_ch < 1)
9164 {
9165 errmsg = e_positive;
9166 p_ch = 1;
9167 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009168 if (p_ch > Rows - min_rows() + 1)
9169 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009170
9171 /* Only compute the new window layout when startup has been
9172 * completed. Otherwise the frame sizes may be wrong. */
9173 if (p_ch != old_value && full_screen
9174#ifdef FEAT_GUI
9175 && !gui.starting
9176#endif
9177 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009178 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009179 }
9180
9181 /* when 'updatecount' changes from zero to non-zero, open swap files */
9182 else if (pp == &p_uc)
9183 {
9184 if (p_uc < 0)
9185 {
9186 errmsg = e_positive;
9187 p_uc = 100;
9188 }
9189 if (p_uc && !old_value)
9190 ml_open_files();
9191 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009192#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009193 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009194 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009195 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009196 {
9197 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009198 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009199 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009200 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009201 {
9202 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009203 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009204 }
9205 }
9206#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009207#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009208 else if (pp == &p_mzq)
9209 mzvim_reset_timer();
9210#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009211
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009212#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9213 /* 'pyxversion' */
9214 else if (pp == &p_pyx)
9215 {
9216 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9217 errmsg = e_invarg;
9218 }
9219#endif
9220
Bram Moolenaar071d4272004-06-13 20:20:40 +00009221 /* sync undo before 'undolevels' changes */
9222 else if (pp == &p_ul)
9223 {
9224 /* use the old value, otherwise u_sync() may not work properly */
9225 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009226 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009227 p_ul = value;
9228 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009229 else if (pp == &curbuf->b_p_ul)
9230 {
9231 /* use the old value, otherwise u_sync() may not work properly */
9232 curbuf->b_p_ul = old_value;
9233 u_sync(TRUE);
9234 curbuf->b_p_ul = value;
9235 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009236
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009237#ifdef FEAT_LINEBREAK
9238 /* 'numberwidth' must be positive */
9239 else if (pp == &curwin->w_p_nuw)
9240 {
9241 if (curwin->w_p_nuw < 1)
9242 {
9243 errmsg = e_positive;
9244 curwin->w_p_nuw = 1;
9245 }
9246 if (curwin->w_p_nuw > 10)
9247 {
9248 errmsg = e_invarg;
9249 curwin->w_p_nuw = 10;
9250 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009251 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009252 }
9253#endif
9254
Bram Moolenaar1a384422010-07-14 19:53:30 +02009255 else if (pp == &curbuf->b_p_tw)
9256 {
9257 if (curbuf->b_p_tw < 0)
9258 {
9259 errmsg = e_positive;
9260 curbuf->b_p_tw = 0;
9261 }
9262#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009263 {
9264 win_T *wp;
9265 tabpage_T *tp;
9266
9267 FOR_ALL_TAB_WINDOWS(tp, wp)
9268 check_colorcolumn(wp);
9269 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009270#endif
9271 }
9272
Bram Moolenaar071d4272004-06-13 20:20:40 +00009273 /*
9274 * Check the bounds for numeric options here
9275 */
9276 if (Rows < min_rows() && full_screen)
9277 {
9278 if (errbuf != NULL)
9279 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009280 vim_snprintf((char *)errbuf, errbuflen,
9281 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009282 errmsg = errbuf;
9283 }
9284 Rows = min_rows();
9285 }
9286 if (Columns < MIN_COLUMNS && full_screen)
9287 {
9288 if (errbuf != NULL)
9289 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009290 vim_snprintf((char *)errbuf, errbuflen,
9291 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009292 errmsg = errbuf;
9293 }
9294 Columns = MIN_COLUMNS;
9295 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009296 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009297
Bram Moolenaar071d4272004-06-13 20:20:40 +00009298 /*
9299 * If the screen (shell) height has been changed, assume it is the
9300 * physical screenheight.
9301 */
9302 if (old_Rows != Rows || old_Columns != Columns)
9303 {
9304 /* Changing the screen size is not allowed while updating the screen. */
9305 if (updating_screen)
9306 *pp = old_value;
9307 else if (full_screen
9308#ifdef FEAT_GUI
9309 && !gui.starting
9310#endif
9311 )
9312 set_shellsize((int)Columns, (int)Rows, TRUE);
9313 else
9314 {
9315 /* Postpone the resizing; check the size and cmdline position for
9316 * messages. */
9317 check_shellsize();
9318 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9319 cmdline_row = Rows - p_ch;
9320 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009321 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009322 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009323 }
9324
Bram Moolenaar071d4272004-06-13 20:20:40 +00009325 if (curbuf->b_p_ts <= 0)
9326 {
9327 errmsg = e_positive;
9328 curbuf->b_p_ts = 8;
9329 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009330 if (p_tm < 0)
9331 {
9332 errmsg = e_positive;
9333 p_tm = 0;
9334 }
9335 if ((curwin->w_p_scr <= 0
9336 || (curwin->w_p_scr > curwin->w_height
9337 && curwin->w_height > 0))
9338 && full_screen)
9339 {
9340 if (pp == &(curwin->w_p_scr))
9341 {
9342 if (curwin->w_p_scr != 0)
9343 errmsg = e_scroll;
9344 win_comp_scroll(curwin);
9345 }
9346 /* If 'scroll' became invalid because of a side effect silently adjust
9347 * it. */
9348 else if (curwin->w_p_scr <= 0)
9349 curwin->w_p_scr = 1;
9350 else /* curwin->w_p_scr > curwin->w_height */
9351 curwin->w_p_scr = curwin->w_height;
9352 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009353 if (p_hi < 0)
9354 {
9355 errmsg = e_positive;
9356 p_hi = 0;
9357 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009358 else if (p_hi > 10000)
9359 {
9360 errmsg = e_invarg;
9361 p_hi = 10000;
9362 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009363 if (p_re < 0 || p_re > 2)
9364 {
9365 errmsg = e_invarg;
9366 p_re = 0;
9367 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009368 if (p_report < 0)
9369 {
9370 errmsg = e_positive;
9371 p_report = 1;
9372 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009373 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009374 {
9375 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9376 p_sj = Rows / 2;
9377 else
9378 {
9379 errmsg = e_scroll;
9380 p_sj = 1;
9381 }
9382 }
9383 if (p_so < 0 && full_screen)
9384 {
9385 errmsg = e_scroll;
9386 p_so = 0;
9387 }
9388 if (p_siso < 0 && full_screen)
9389 {
9390 errmsg = e_positive;
9391 p_siso = 0;
9392 }
9393#ifdef FEAT_CMDWIN
9394 if (p_cwh < 1)
9395 {
9396 errmsg = e_positive;
9397 p_cwh = 1;
9398 }
9399#endif
9400 if (p_ut < 0)
9401 {
9402 errmsg = e_positive;
9403 p_ut = 2000;
9404 }
9405 if (p_ss < 0)
9406 {
9407 errmsg = e_positive;
9408 p_ss = 0;
9409 }
9410
9411 /* May set global value for local option. */
9412 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9413 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9414
9415 options[opt_idx].flags |= P_WAS_SET;
9416
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009417#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009418 // Don't do this while starting up, failure or recursively.
9419 if (!starting && errmsg == NULL && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009420 {
9421 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009422 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9423 vim_snprintf((char *)buf_new, 10, "%ld", value);
9424 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009425 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9426 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9427 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9428 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9429 reset_v_option_vars();
9430 }
9431#endif
9432
Bram Moolenaar071d4272004-06-13 20:20:40 +00009433 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009434 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009435 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009436 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009437 check_redraw(options[opt_idx].flags);
9438
9439 return errmsg;
9440}
9441
9442/*
9443 * Called after an option changed: check if something needs to be redrawn.
9444 */
9445 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009446check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009447{
9448 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009449 int doclear = (flags & P_RCLR) == P_RCLR;
9450 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009451
Bram Moolenaar071d4272004-06-13 20:20:40 +00009452 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9453 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009454
9455 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9456 changed_window_setting();
9457 if (flags & P_RBUF)
9458 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009459 if (flags & P_RWINONLY)
9460 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009461 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009462 redraw_all_later(CLEAR);
9463 else if (all)
9464 redraw_all_later(NOT_VALID);
9465}
9466
9467/*
9468 * Find index for option 'arg'.
9469 * Return -1 if not found.
9470 */
9471 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009472findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009473{
9474 int opt_idx;
9475 char *s, *p;
9476 static short quick_tab[27] = {0, 0}; /* quick access table */
9477 int is_term_opt;
9478
9479 /*
9480 * For first call: Initialize the quick-access table.
9481 * It contains the index for the first option that starts with a certain
9482 * letter. There are 26 letters, plus the first "t_" option.
9483 */
9484 if (quick_tab[1] == 0)
9485 {
9486 p = options[0].fullname;
9487 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9488 {
9489 if (s[0] != p[0])
9490 {
9491 if (s[0] == 't' && s[1] == '_')
9492 quick_tab[26] = opt_idx;
9493 else
9494 quick_tab[CharOrdLow(s[0])] = opt_idx;
9495 }
9496 p = s;
9497 }
9498 }
9499
9500 /*
9501 * Check for name starting with an illegal character.
9502 */
9503#ifdef EBCDIC
9504 if (!islower(arg[0]))
9505#else
9506 if (arg[0] < 'a' || arg[0] > 'z')
9507#endif
9508 return -1;
9509
9510 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9511 if (is_term_opt)
9512 opt_idx = quick_tab[26];
9513 else
9514 opt_idx = quick_tab[CharOrdLow(arg[0])];
9515 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9516 {
9517 if (STRCMP(arg, s) == 0) /* match full name */
9518 break;
9519 }
9520 if (s == NULL && !is_term_opt)
9521 {
9522 opt_idx = quick_tab[CharOrdLow(arg[0])];
9523 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9524 {
9525 s = options[opt_idx].shortname;
9526 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9527 break;
9528 s = NULL;
9529 }
9530 }
9531 if (s == NULL)
9532 opt_idx = -1;
9533 return opt_idx;
9534}
9535
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009536#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009537/*
9538 * Get the value for an option.
9539 *
9540 * Returns:
9541 * Number or Toggle option: 1, *numval gets value.
9542 * String option: 0, *stringval gets allocated string.
9543 * Hidden Number or Toggle option: -1.
9544 * hidden String option: -2.
9545 * unknown option: -3.
9546 */
9547 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009548get_option_value(
9549 char_u *name,
9550 long *numval,
9551 char_u **stringval, /* NULL when only checking existence */
9552 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009553{
9554 int opt_idx;
9555 char_u *varp;
9556
9557 opt_idx = findoption(name);
9558 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009559 {
9560 int key;
9561
9562 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009563 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009564 {
9565 char_u key_name[2];
9566 char_u *p;
9567
9568 if (key < 0)
9569 {
9570 key_name[0] = KEY2TERMCAP0(key);
9571 key_name[1] = KEY2TERMCAP1(key);
9572 }
9573 else
9574 {
9575 key_name[0] = KS_KEY;
9576 key_name[1] = (key & 0xff);
9577 }
9578 p = find_termcode(key_name);
9579 if (p != NULL)
9580 {
9581 if (stringval != NULL)
9582 *stringval = vim_strsave(p);
9583 return 0;
9584 }
9585 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009586 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009587 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009588
9589 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9590
9591 if (options[opt_idx].flags & P_STRING)
9592 {
9593 if (varp == NULL) /* hidden option */
9594 return -2;
9595 if (stringval != NULL)
9596 {
9597#ifdef FEAT_CRYPT
9598 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009599 if ((char_u **)varp == &curbuf->b_p_key
9600 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009601 *stringval = vim_strsave((char_u *)"*****");
9602 else
9603#endif
9604 *stringval = vim_strsave(*(char_u **)(varp));
9605 }
9606 return 0;
9607 }
9608
9609 if (varp == NULL) /* hidden option */
9610 return -1;
9611 if (options[opt_idx].flags & P_NUM)
9612 *numval = *(long *)varp;
9613 else
9614 {
9615 /* Special case: 'modified' is b_changed, but we also want to consider
9616 * it set when 'ff' or 'fenc' changed. */
9617 if ((int *)varp == &curbuf->b_changed)
9618 *numval = curbufIsChanged();
9619 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009620 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009621 }
9622 return 1;
9623}
9624#endif
9625
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009626#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009627/*
9628 * Returns the option attributes and its value. Unlike the above function it
9629 * will return either global value or local value of the option depending on
9630 * what was requested, but it will never return global value if it was
9631 * requested to return local one and vice versa. Neither it will return
9632 * buffer-local value if it was requested to return window-local one.
9633 *
9634 * Pretends that option is absent if it is not present in the requested scope
9635 * (i.e. has no global, window-local or buffer-local value depending on
9636 * opt_type). Uses
9637 *
9638 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009639 * 0 hidden or unknown option, also option that does not have requested
9640 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009641 * see SOPT_* in vim.h for other flags
9642 *
9643 * Possible opt_type values: see SREQ_* in vim.h
9644 */
9645 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009646get_option_value_strict(
9647 char_u *name,
9648 long *numval,
9649 char_u **stringval, /* NULL when only obtaining attributes */
9650 int opt_type,
9651 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009652{
9653 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009654 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009655 struct vimoption *p;
9656 int r = 0;
9657
9658 opt_idx = findoption(name);
9659 if (opt_idx < 0)
9660 return 0;
9661
9662 p = &(options[opt_idx]);
9663
9664 /* Hidden option */
9665 if (p->var == NULL)
9666 return 0;
9667
9668 if (p->flags & P_BOOL)
9669 r |= SOPT_BOOL;
9670 else if (p->flags & P_NUM)
9671 r |= SOPT_NUM;
9672 else if (p->flags & P_STRING)
9673 r |= SOPT_STRING;
9674
9675 if (p->indir == PV_NONE)
9676 {
9677 if (opt_type == SREQ_GLOBAL)
9678 r |= SOPT_GLOBAL;
9679 else
9680 return 0; /* Did not request global-only option */
9681 }
9682 else
9683 {
9684 if (p->indir & PV_BOTH)
9685 r |= SOPT_GLOBAL;
9686 else if (opt_type == SREQ_GLOBAL)
9687 return 0; /* Requested global option */
9688
9689 if (p->indir & PV_WIN)
9690 {
9691 if (opt_type == SREQ_BUF)
9692 return 0; /* Did not request window-local option */
9693 else
9694 r |= SOPT_WIN;
9695 }
9696 else if (p->indir & PV_BUF)
9697 {
9698 if (opt_type == SREQ_WIN)
9699 return 0; /* Did not request buffer-local option */
9700 else
9701 r |= SOPT_BUF;
9702 }
9703 }
9704
9705 if (stringval == NULL)
9706 return r;
9707
9708 if (opt_type == SREQ_GLOBAL)
9709 varp = p->var;
9710 else
9711 {
9712 if (opt_type == SREQ_BUF)
9713 {
9714 /* Special case: 'modified' is b_changed, but we also want to
9715 * consider it set when 'ff' or 'fenc' changed. */
9716 if (p->indir == PV_MOD)
9717 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009718 *numval = bufIsChanged((buf_T *)from);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009719 varp = NULL;
9720 }
9721#ifdef FEAT_CRYPT
9722 else if (p->indir == PV_KEY)
9723 {
9724 /* never return the value of the crypt key */
9725 *stringval = NULL;
9726 varp = NULL;
9727 }
9728#endif
9729 else
9730 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009731 buf_T *save_curbuf = curbuf;
9732
9733 // only getting a pointer, no need to use aucmd_prepbuf()
9734 curbuf = (buf_T *)from;
9735 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009736 varp = get_varp(p);
Bram Moolenaardefe6422018-06-24 15:14:07 +02009737 curbuf = save_curbuf;
9738 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009739 }
9740 }
9741 else if (opt_type == SREQ_WIN)
9742 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009743 win_T *save_curwin = curwin;
9744
9745 curwin = (win_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009746 curbuf = curwin->w_buffer;
9747 varp = get_varp(p);
9748 curwin = save_curwin;
9749 curbuf = curwin->w_buffer;
9750 }
9751 if (varp == p->var)
9752 return (r | SOPT_UNSET);
9753 }
9754
9755 if (varp != NULL)
9756 {
9757 if (p->flags & P_STRING)
9758 *stringval = vim_strsave(*(char_u **)(varp));
9759 else if (p->flags & P_NUM)
9760 *numval = *(long *) varp;
9761 else
9762 *numval = *(int *)varp;
9763 }
9764
9765 return r;
9766}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009767
9768/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009769 * Iterate over options. First argument is a pointer to a pointer to a
9770 * structure inside options[] array, second is option type like in the above
9771 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009772 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009773 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009774 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009775 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009776 * first argument to NULL.
9777 *
9778 * Returns full option name for current option on each call.
9779 */
9780 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009781option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009782{
9783 struct vimoption *ret = NULL;
9784 do
9785 {
9786 if (*option == NULL)
9787 *option = (void *) options;
9788 else if (((struct vimoption *) (*option))->fullname == NULL)
9789 {
9790 *option = NULL;
9791 return NULL;
9792 }
9793 else
9794 *option = (void *) (((struct vimoption *) (*option)) + 1);
9795
9796 ret = ((struct vimoption *) (*option));
9797
9798 /* Hidden option */
9799 if (ret->var == NULL)
9800 {
9801 ret = NULL;
9802 continue;
9803 }
9804
9805 switch (opt_type)
9806 {
9807 case SREQ_GLOBAL:
9808 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9809 ret = NULL;
9810 break;
9811 case SREQ_BUF:
9812 if (!(ret->indir & PV_BUF))
9813 ret = NULL;
9814 break;
9815 case SREQ_WIN:
9816 if (!(ret->indir & PV_WIN))
9817 ret = NULL;
9818 break;
9819 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009820 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009821 return NULL;
9822 }
9823 }
9824 while (ret == NULL);
9825
9826 return (char_u *)ret->fullname;
9827}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009828#endif
9829
Bram Moolenaar071d4272004-06-13 20:20:40 +00009830/*
9831 * Set the value of option "name".
9832 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009833 *
9834 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009835 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009836 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009837set_option_value(
9838 char_u *name,
9839 long number,
9840 char_u *string,
9841 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009842{
9843 int opt_idx;
9844 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009845 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009846
9847 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009848 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009849 {
9850 int key;
9851
9852 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009853 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009854 {
9855 char_u key_name[2];
9856
9857 if (key < 0)
9858 {
9859 key_name[0] = KEY2TERMCAP0(key);
9860 key_name[1] = KEY2TERMCAP1(key);
9861 }
9862 else
9863 {
9864 key_name[0] = KS_KEY;
9865 key_name[1] = (key & 0xff);
9866 }
9867 add_termcode(key_name, string, FALSE);
9868 if (full_screen)
9869 ttest(FALSE);
9870 redraw_all_later(CLEAR);
9871 return NULL;
9872 }
9873
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009874 semsg(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009875 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009876 else
9877 {
9878 flags = options[opt_idx].flags;
9879#ifdef HAVE_SANDBOX
9880 /* Disallow changing some options in the sandbox */
9881 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009882 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009883 emsg(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009884 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009885 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009886#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009887 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009888 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009889 else
9890 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009891 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009892 if (varp != NULL) /* hidden option is not changed */
9893 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009894 if (number == 0 && string != NULL)
9895 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009896 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009897
9898 /* Either we are given a string or we are setting option
9899 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009900 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009901 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009902 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009903 {
9904 /* There's another character after zeros or the string
9905 * is empty. In both cases, we are trying to set a
9906 * num option using a string. */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009907 semsg(_("E521: Number required: &%s = '%s'"),
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009908 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009909 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009910
9911 }
9912 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009913 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009914 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009915 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009916 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009917 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009918 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009919 }
9920 }
9921 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009922 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009923}
9924
9925/*
9926 * Get the terminal code for a terminal option.
9927 * Returns NULL when not found.
9928 */
9929 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009930get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009931{
9932 int opt_idx;
9933 char_u *varp;
9934
9935 if (tname[0] != 't' || tname[1] != '_' ||
9936 tname[2] == NUL || tname[3] == NUL)
9937 return NULL;
9938 if ((opt_idx = findoption(tname)) >= 0)
9939 {
9940 varp = get_varp(&(options[opt_idx]));
9941 if (varp != NULL)
9942 varp = *(char_u **)(varp);
9943 return varp;
9944 }
9945 return find_termcode(tname + 2);
9946}
9947
9948 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009949get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009950{
9951 int i;
9952
9953 i = findoption((char_u *)"hl");
9954 if (i >= 0)
9955 return options[i].def_val[VI_DEFAULT];
9956 return (char_u *)NULL;
9957}
9958
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009959 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009960get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009961{
9962 int i;
9963
9964 i = findoption((char_u *)"enc");
9965 if (i >= 0)
9966 return options[i].def_val[VI_DEFAULT];
9967 return (char_u *)NULL;
9968}
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009969
Bram Moolenaar071d4272004-06-13 20:20:40 +00009970/*
9971 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009972 * When "has_lt" is true there is a '<' before "*arg_arg".
9973 * Returns 0 when the key is not recognized.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009974 */
9975 static int
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009976find_key_option(char_u *arg_arg, int has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009977{
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009978 int key = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009979 int modifiers;
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009980 char_u *arg = arg_arg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009981
9982 /*
9983 * Don't use get_special_key_code() for t_xx, we don't want it to call
9984 * add_termcap_entry().
9985 */
9986 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9987 key = TERMCAP2KEY(arg[2], arg[3]);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009988 else if (has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009989 {
9990 --arg; /* put arg at the '<' */
9991 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009992 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009993 if (modifiers) /* can't handle modifiers here */
9994 key = 0;
9995 }
9996 return key;
9997}
9998
9999/*
10000 * if 'all' == 0: show changed options
10001 * if 'all' == 1: show all normal options
10002 * if 'all' == 2: show all terminal options
10003 */
10004 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010005showoptions(
10006 int all,
10007 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010008{
10009 struct vimoption *p;
10010 int col;
10011 int isterm;
10012 char_u *varp;
10013 struct vimoption **items;
10014 int item_count;
10015 int run;
10016 int row, rows;
10017 int cols;
10018 int i;
10019 int len;
10020
10021#define INC 20
10022#define GAP 3
10023
10024 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
10025 PARAM_COUNT));
10026 if (items == NULL)
10027 return;
10028
10029 /* Highlight title */
10030 if (all == 2)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010031 msg_puts_title(_("\n--- Terminal codes ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010032 else if (opt_flags & OPT_GLOBAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010033 msg_puts_title(_("\n--- Global option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010034 else if (opt_flags & OPT_LOCAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010035 msg_puts_title(_("\n--- Local option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010036 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010037 msg_puts_title(_("\n--- Options ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010038
10039 /*
10040 * do the loop two times:
10041 * 1. display the short items
10042 * 2. display the long items (only strings and numbers)
10043 */
10044 for (run = 1; run <= 2 && !got_int; ++run)
10045 {
10046 /*
10047 * collect the items in items[]
10048 */
10049 item_count = 0;
10050 for (p = &options[0]; p->fullname != NULL; p++)
10051 {
Bram Moolenaarf86db782018-10-25 13:31:37 +020010052 // apply :filter /pat/
10053 if (message_filtered((char_u *) p->fullname))
10054 continue;
10055
Bram Moolenaar071d4272004-06-13 20:20:40 +000010056 varp = NULL;
10057 isterm = istermoption(p);
10058 if (opt_flags != 0)
10059 {
10060 if (p->indir != PV_NONE && !isterm)
10061 varp = get_varp_scope(p, opt_flags);
10062 }
10063 else
10064 varp = get_varp(p);
10065 if (varp != NULL
10066 && ((all == 2 && isterm)
10067 || (all == 1 && !isterm)
10068 || (all == 0 && !optval_default(p, varp))))
10069 {
10070 if (p->flags & P_BOOL)
10071 len = 1; /* a toggle option fits always */
10072 else
10073 {
10074 option_value2string(p, opt_flags);
10075 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
10076 }
10077 if ((len <= INC - GAP && run == 1) ||
10078 (len > INC - GAP && run == 2))
10079 items[item_count++] = p;
10080 }
10081 }
10082
10083 /*
10084 * display the items
10085 */
10086 if (run == 1)
10087 {
10088 cols = (Columns + GAP - 3) / INC;
10089 if (cols == 0)
10090 cols = 1;
10091 rows = (item_count + cols - 1) / cols;
10092 }
10093 else /* run == 2 */
10094 rows = item_count;
10095 for (row = 0; row < rows && !got_int; ++row)
10096 {
10097 msg_putchar('\n'); /* go to next line */
10098 if (got_int) /* 'q' typed in more */
10099 break;
10100 col = 0;
10101 for (i = row; i < item_count; i += rows)
10102 {
10103 msg_col = col; /* make columns */
10104 showoneopt(items[i], opt_flags);
10105 col += INC;
10106 }
10107 out_flush();
10108 ui_breakcheck();
10109 }
10110 }
10111 vim_free(items);
10112}
10113
10114/*
10115 * Return TRUE if option "p" has its default value.
10116 */
10117 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010118optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010119{
10120 int dvi;
10121
10122 if (varp == NULL)
10123 return TRUE; /* hidden option is always at default */
10124 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
10125 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010126 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010127 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010128 /* the cast to long is required for Manx C, long_i is
10129 * needed for MSVC */
10130 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010131 /* P_STRING */
10132 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
10133}
10134
10135/*
10136 * showoneopt: show the value of one option
10137 * must not be called with a hidden option!
10138 */
10139 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010140showoneopt(
10141 struct vimoption *p,
10142 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010143{
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010144 char_u *varp;
10145 int save_silent = silent_mode;
10146
10147 silent_mode = FALSE;
10148 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010149
10150 varp = get_varp_scope(p, opt_flags);
10151
10152 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
10153 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
10154 ? !curbufIsChanged() : !*(int *)varp))
Bram Moolenaar32526b32019-01-19 17:43:09 +010010155 msg_puts("no");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010156 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010157 msg_puts("--");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010158 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010159 msg_puts(" ");
10160 msg_puts(p->fullname);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010161 if (!(p->flags & P_BOOL))
10162 {
10163 msg_putchar('=');
10164 /* put value string in NameBuff */
10165 option_value2string(p, opt_flags);
10166 msg_outtrans(NameBuff);
10167 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010168
10169 silent_mode = save_silent;
10170 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010171}
10172
10173/*
10174 * Write modified options as ":set" commands to a file.
10175 *
10176 * There are three values for "opt_flags":
10177 * OPT_GLOBAL: Write global option values and fresh values of
10178 * buffer-local options (used for start of a session
10179 * file).
10180 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10181 * curwin (used for a vimrc file).
10182 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10183 * and local values for window-local options of
10184 * curwin. Local values are also written when at the
10185 * default value, because a modeline or autocommand
10186 * may have set them when doing ":edit file" and the
10187 * user has set them back at the default or fresh
10188 * value.
10189 * When "local_only" is TRUE, don't write fresh
10190 * values, only local values (for ":mkview").
10191 * (fresh value = value used for a new buffer or window for a local option).
10192 *
10193 * Return FAIL on error, OK otherwise.
10194 */
10195 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010196makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010197{
10198 struct vimoption *p;
10199 char_u *varp; /* currently used value */
10200 char_u *varp_fresh; /* local value */
10201 char_u *varp_local = NULL; /* fresh value */
10202 char *cmd;
10203 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010204 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010205
10206 /*
10207 * The options that don't have a default (terminal name, columns, lines)
10208 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010209 * Do the loop over "options[]" twice: once for options with the
10210 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010211 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010212 for (pri = 1; pri >= 0; --pri)
10213 {
10214 for (p = &options[0]; !istermoption(p); p++)
10215 if (!(p->flags & P_NO_MKRC)
10216 && !istermoption(p)
10217 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010218 {
10219 /* skip global option when only doing locals */
10220 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10221 continue;
10222
10223 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10224 * file, they are always buffer-specific. */
10225 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10226 continue;
10227
10228 /* Global values are only written when not at the default value. */
10229 varp = get_varp_scope(p, opt_flags);
10230 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10231 continue;
10232
10233 round = 2;
10234 if (p->indir != PV_NONE)
10235 {
10236 if (p->var == VAR_WIN)
10237 {
10238 /* skip window-local option when only doing globals */
10239 if (!(opt_flags & OPT_LOCAL))
10240 continue;
10241 /* When fresh value of window-local option is not at the
10242 * default, need to write it too. */
10243 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10244 {
10245 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10246 if (!optval_default(p, varp_fresh))
10247 {
10248 round = 1;
10249 varp_local = varp;
10250 varp = varp_fresh;
10251 }
10252 }
10253 }
10254 }
10255
10256 /* Round 1: fresh value for window-local options.
10257 * Round 2: other values */
10258 for ( ; round <= 2; varp = varp_local, ++round)
10259 {
10260 if (round == 1 || (opt_flags & OPT_GLOBAL))
10261 cmd = "set";
10262 else
10263 cmd = "setlocal";
10264
10265 if (p->flags & P_BOOL)
10266 {
10267 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10268 return FAIL;
10269 }
10270 else if (p->flags & P_NUM)
10271 {
10272 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10273 return FAIL;
10274 }
10275 else /* P_STRING */
10276 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010277 int do_endif = FALSE;
10278
Bram Moolenaar071d4272004-06-13 20:20:40 +000010279 /* Don't set 'syntax' and 'filetype' again if the value is
10280 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010281 if (
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +010010282#if defined(FEAT_SYN_HL)
10283 p->indir == PV_SYN ||
10284#endif
10285 p->indir == PV_FT)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010286 {
10287 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10288 *(char_u **)(varp)) < 0
10289 || put_eol(fd) < 0)
10290 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010291 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010292 }
10293 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010294 p->flags) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010295 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010296 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010297 {
10298 if (put_line(fd, "endif") == FAIL)
10299 return FAIL;
10300 }
10301 }
10302 }
10303 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010304 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010305 return OK;
10306}
10307
10308#if defined(FEAT_FOLDING) || defined(PROTO)
10309/*
10310 * Generate set commands for the local fold options only. Used when
10311 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10312 */
10313 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010314makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010315{
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010316 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, 0) == FAIL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010317# ifdef FEAT_EVAL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010318 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010319 == FAIL
10320# endif
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010321 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010322 == FAIL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010323 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010324 == FAIL
10325 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10326 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10327 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10328 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10329 )
10330 return FAIL;
10331
10332 return OK;
10333}
10334#endif
10335
10336 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010337put_setstring(
10338 FILE *fd,
10339 char *cmd,
10340 char *name,
10341 char_u **valuep,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010342 long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010343{
10344 char_u *s;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010345 char_u *buf = NULL;
10346 char_u *part = NULL;
10347 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010348
10349 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10350 return FAIL;
10351 if (*valuep != NULL)
10352 {
10353 /* Output 'pastetoggle' as key names. For other
10354 * options some characters have to be escaped with
10355 * CTRL-V or backslash */
10356 if (valuep == &p_pt)
10357 {
10358 s = *valuep;
10359 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010360 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010361 return FAIL;
10362 }
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010363 // expand the option value, replace $HOME by ~
10364 else if ((flags & P_EXPAND) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010365 {
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010366 int size = (int)STRLEN(*valuep) + 1;
10367
10368 // replace home directory in the whole option value into "buf"
10369 buf = alloc(size);
Bram Moolenaarf8441472011-04-28 17:24:58 +020010370 if (buf == NULL)
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010371 goto fail;
10372 home_replace(NULL, *valuep, buf, size, FALSE);
10373
10374 // If the option value is longer than MAXPATHL, we need to append
10375 // earch comma separated part of the option separately, so that it
10376 // can be expanded when read back.
10377 if (size >= MAXPATHL && (flags & P_COMMA) != 0
10378 && vim_strchr(*valuep, ',') != NULL)
10379 {
10380 part = alloc(size);
10381 if (part == NULL)
10382 goto fail;
10383
10384 // write line break to clear the option, e.g. ':set rtp='
10385 if (put_eol(fd) == FAIL)
10386 goto fail;
10387
10388 p = buf;
10389 while (*p != NUL)
10390 {
10391 // for each comma separated option part, append value to
10392 // the option, :set rtp+=value
10393 if (fprintf(fd, "%s %s+=", cmd, name) < 0)
10394 goto fail;
10395 (void)copy_option_part(&p, part, size, ",");
10396 if (put_escstr(fd, part, 2) == FAIL || put_eol(fd) == FAIL)
10397 goto fail;
10398 }
10399 vim_free(buf);
10400 vim_free(part);
10401 return OK;
10402 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010403 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010404 {
10405 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010406 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010407 }
10408 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010409 }
10410 else if (put_escstr(fd, *valuep, 2) == FAIL)
10411 return FAIL;
10412 }
10413 if (put_eol(fd) < 0)
10414 return FAIL;
10415 return OK;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010416fail:
10417 vim_free(buf);
10418 vim_free(part);
10419 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010420}
10421
10422 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010423put_setnum(
10424 FILE *fd,
10425 char *cmd,
10426 char *name,
10427 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010428{
10429 long wc;
10430
10431 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10432 return FAIL;
10433 if (wc_use_keyname((char_u *)valuep, &wc))
10434 {
10435 /* print 'wildchar' and 'wildcharm' as a key name */
10436 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10437 return FAIL;
10438 }
10439 else if (fprintf(fd, "%ld", *valuep) < 0)
10440 return FAIL;
10441 if (put_eol(fd) < 0)
10442 return FAIL;
10443 return OK;
10444}
10445
10446 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010447put_setbool(
10448 FILE *fd,
10449 char *cmd,
10450 char *name,
10451 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010452{
Bram Moolenaar893de922007-10-02 18:40:57 +000010453 if (value < 0) /* global/local option using global value */
10454 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010455 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10456 || put_eol(fd) < 0)
10457 return FAIL;
10458 return OK;
10459}
10460
10461/*
10462 * Clear all the terminal options.
10463 * If the option has been allocated, free the memory.
10464 * Terminal options are never hidden or indirect.
10465 */
10466 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010467clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010468{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010469 /*
10470 * Reset a few things before clearing the old options. This may cause
10471 * outputting a few things that the terminal doesn't understand, but the
10472 * screen will be cleared later, so this is OK.
10473 */
10474#ifdef FEAT_MOUSE_TTY
10475 mch_setmouse(FALSE); /* switch mouse off */
10476#endif
10477#ifdef FEAT_TITLE
Bram Moolenaar40385db2018-08-07 22:31:44 +020010478 mch_restore_title(SAVE_RESTORE_BOTH); /* restore window titles */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010479#endif
10480#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10481 /* When starting the GUI close the display opened for the clipboard.
10482 * After restoring the title, because that will need the display. */
10483 if (gui.starting)
10484 clear_xterm_clip();
10485#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010486 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010487
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010488 free_termoptions();
10489}
10490
10491 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010492free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010493{
10494 struct vimoption *p;
10495
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010496 for (p = options; p->fullname != NULL; p++)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010497 if (istermoption(p))
10498 {
10499 if (p->flags & P_ALLOCED)
10500 free_string_option(*(char_u **)(p->var));
10501 if (p->flags & P_DEF_ALLOCED)
10502 free_string_option(p->def_val[VI_DEFAULT]);
10503 *(char_u **)(p->var) = empty_option;
10504 p->def_val[VI_DEFAULT] = empty_option;
10505 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010506#ifdef FEAT_EVAL
10507 // remember where the option was cleared
10508 set_option_sctx_idx((int)(p - options), OPT_GLOBAL, current_sctx);
10509#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010510 }
10511 clear_termcodes();
10512}
10513
10514/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010515 * Free the string for one term option, if it was allocated.
10516 * Set the string to empty_option and clear allocated flag.
10517 * "var" points to the option value.
10518 */
10519 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010520free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010521{
10522 struct vimoption *p;
10523
10524 for (p = &options[0]; p->fullname != NULL; p++)
10525 if (p->var == var)
10526 {
10527 if (p->flags & P_ALLOCED)
10528 free_string_option(*(char_u **)(p->var));
10529 *(char_u **)(p->var) = empty_option;
10530 p->flags &= ~P_ALLOCED;
10531 break;
10532 }
10533}
10534
10535/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010536 * Set the terminal option defaults to the current value.
10537 * Used after setting the terminal name.
10538 */
10539 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010540set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010541{
10542 struct vimoption *p;
10543
10544 for (p = &options[0]; p->fullname != NULL; p++)
10545 {
10546 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10547 {
10548 if (p->flags & P_DEF_ALLOCED)
10549 {
10550 free_string_option(p->def_val[VI_DEFAULT]);
10551 p->flags &= ~P_DEF_ALLOCED;
10552 }
10553 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10554 if (p->flags & P_ALLOCED)
10555 {
10556 p->flags |= P_DEF_ALLOCED;
10557 p->flags &= ~P_ALLOCED; /* don't free the value now */
10558 }
10559 }
10560 }
10561}
10562
10563/*
10564 * return TRUE if 'p' starts with 't_'
10565 */
10566 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010567istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010568{
10569 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10570}
10571
10572/*
10573 * Compute columns for ruler and shown command. 'sc_col' is also used to
10574 * decide what the maximum length of a message on the status line can be.
10575 * If there is a status line for the last window, 'sc_col' is independent
10576 * of 'ru_col'.
10577 */
10578
10579#define COL_RULER 17 /* columns needed by standard ruler */
10580
10581 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010582comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010583{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010584#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010585 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010586
10587 sc_col = 0;
10588 ru_col = 0;
10589 if (p_ru)
10590 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010591# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010592 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010593# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010594 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010595# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010596 /* no last status line, adjust sc_col */
10597 if (!last_has_status)
10598 sc_col = ru_col;
10599 }
10600 if (p_sc)
10601 {
10602 sc_col += SHOWCMD_COLS;
10603 if (!p_ru || last_has_status) /* no need for separating space */
10604 ++sc_col;
10605 }
10606 sc_col = Columns - sc_col;
10607 ru_col = Columns - ru_col;
10608 if (sc_col <= 0) /* screen too narrow, will become a mess */
10609 sc_col = 1;
10610 if (ru_col <= 0)
10611 ru_col = 1;
10612#else
10613 sc_col = Columns;
10614 ru_col = Columns;
10615#endif
10616}
10617
Bram Moolenaar113e1072019-01-20 15:30:40 +010010618#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010619/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010620 * Unset local option value, similar to ":set opt<".
10621 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010622 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010623unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010624{
10625 struct vimoption *p;
10626 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010627 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010628
10629 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010630 if (opt_idx < 0)
10631 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010632 p = &(options[opt_idx]);
10633
10634 switch ((int)p->indir)
10635 {
10636 /* global option with local value: use local value if it's been set */
10637 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010638 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010639 break;
10640 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010641 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010642 break;
10643 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010644 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010645 break;
10646 case PV_AR:
10647 buf->b_p_ar = -1;
10648 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010649 case PV_BKC:
10650 clear_string_option(&buf->b_p_bkc);
10651 buf->b_bkc_flags = 0;
10652 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010653 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010654 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010655 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010656 case PV_TC:
10657 clear_string_option(&buf->b_p_tc);
10658 buf->b_tc_flags = 0;
10659 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010660#ifdef FEAT_FIND_ID
10661 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010662 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010663 break;
10664 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010665 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010666 break;
10667#endif
10668#ifdef FEAT_INS_EXPAND
10669 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010670 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010671 break;
10672 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010673 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010674 break;
10675#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010676 case PV_FP:
10677 clear_string_option(&buf->b_p_fp);
10678 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010679#ifdef FEAT_QUICKFIX
10680 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010681 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010682 break;
10683 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010684 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010685 break;
10686 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010687 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010688 break;
10689#endif
10690#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10691 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010692 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010693 break;
10694#endif
10695#if defined(FEAT_CRYPT)
10696 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010697 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010698 break;
10699#endif
10700#ifdef FEAT_STL_OPT
10701 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010702 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010703 break;
10704#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010705 case PV_UL:
10706 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10707 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010708#ifdef FEAT_LISP
10709 case PV_LW:
10710 clear_string_option(&buf->b_p_lw);
10711 break;
10712#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010713 case PV_MENC:
10714 clear_string_option(&buf->b_p_menc);
10715 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010716 }
10717}
Bram Moolenaar113e1072019-01-20 15:30:40 +010010718#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010719
10720/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010721 * Get pointer to option variable, depending on local or global scope.
10722 */
10723 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010724get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010725{
10726 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10727 {
10728 if (p->var == VAR_WIN)
10729 return (char_u *)GLOBAL_WO(get_varp(p));
10730 return p->var;
10731 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010732 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010733 {
10734 switch ((int)p->indir)
10735 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010736 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010737#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010738 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10739 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10740 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010741#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010742 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10743 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10744 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010745 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010746 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010747 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010748#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010749 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10750 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010751#endif
10752#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010753 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10754 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010755#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010756#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10757 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10758#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010759#if defined(FEAT_CRYPT)
10760 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10761#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010762#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010763 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010764#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010765 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010766#ifdef FEAT_LISP
10767 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10768#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010769 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010770 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010771 }
10772 return NULL; /* "cannot happen" */
10773 }
10774 return get_varp(p);
10775}
10776
10777/*
10778 * Get pointer to option variable.
10779 */
10780 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010781get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010782{
10783 /* hidden option, always return NULL */
10784 if (p->var == NULL)
10785 return NULL;
10786
10787 switch ((int)p->indir)
10788 {
10789 case PV_NONE: return p->var;
10790
10791 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010792 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010793 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010794 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010795 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010796 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010797 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010798 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010799 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010800 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010801 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010802 case PV_TC: return *curbuf->b_p_tc != NUL
10803 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010804 case PV_BKC: return *curbuf->b_p_bkc != NUL
10805 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010806#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010807 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010808 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010809 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010810 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10811#endif
10812#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010813 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010814 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010815 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010816 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10817#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010818 case PV_FP: return *curbuf->b_p_fp != NUL
10819 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010820#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010821 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010822 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010823 case PV_GP: return *curbuf->b_p_gp != NUL
10824 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10825 case PV_MP: return *curbuf->b_p_mp != NUL
10826 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010827#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010828#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10829 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10830 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10831#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010832#if defined(FEAT_CRYPT)
10833 case PV_CM: return *curbuf->b_p_cm != NUL
10834 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10835#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010836#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010837 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010838 ? (char_u *)&(curwin->w_p_stl) : p->var;
10839#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010840 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10841 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010842#ifdef FEAT_LISP
10843 case PV_LW: return *curbuf->b_p_lw != NUL
10844 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10845#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010846 case PV_MENC: return *curbuf->b_p_menc != NUL
10847 ? (char_u *)&(curbuf->b_p_menc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010848
10849#ifdef FEAT_ARABIC
10850 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10851#endif
10852 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010853#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010854 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10855#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010856#ifdef FEAT_SYN_HL
10857 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10858 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010859 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010860#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010861#ifdef FEAT_DIFF
10862 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10863#endif
10864#ifdef FEAT_FOLDING
10865 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10866 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10867 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10868 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10869 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10870 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10871 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10872# ifdef FEAT_EVAL
10873 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10874 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10875# endif
10876 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10877#endif
10878 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010879 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010880#ifdef FEAT_LINEBREAK
10881 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10882#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010883 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010884 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020010885#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010886 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10887#endif
10888#ifdef FEAT_RIGHTLEFT
10889 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10890 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10891#endif
10892 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10893 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10894#ifdef FEAT_LINEBREAK
10895 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010896 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10897 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010898#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010899 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010900 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010901#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010902 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10903 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10904#endif
10905#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020010906 case PV_TWK: return (char_u *)&(curwin->w_p_twk);
10907 case PV_TWS: return (char_u *)&(curwin->w_p_tws);
10908 case PV_TWSL: return (char_u *)&(curbuf->b_p_twsl);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010909#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010910
10911 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10912 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010913 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010914 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10915 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010916 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10917 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10918#ifdef FEAT_CINDENT
10919 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10920 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10921 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10922#endif
10923#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10924 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10925#endif
10926#ifdef FEAT_COMMENTS
10927 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10928#endif
10929#ifdef FEAT_FOLDING
10930 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10931#endif
10932#ifdef FEAT_INS_EXPAND
10933 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10934#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010935#ifdef FEAT_COMPL_FUNC
10936 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010937 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010938#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010939 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010940 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010941 case PV_ET: return (char_u *)&(curbuf->b_p_et);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010942 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010943 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010944 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010945 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010946 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010947 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10948 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10949 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10950 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10951#ifdef FEAT_FIND_ID
10952# ifdef FEAT_EVAL
10953 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10954# endif
10955#endif
10956#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10957 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10958 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10959#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010960#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010961 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10962#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010963#ifdef FEAT_CRYPT
10964 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10965#endif
10966#ifdef FEAT_LISP
10967 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10968#endif
10969 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10970 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10971 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10972 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10973 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010974 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010975#ifdef FEAT_TEXTOBJ
10976 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10977#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010978 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10979#ifdef FEAT_SMARTINDENT
10980 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10981#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010982 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010983 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10984#ifdef FEAT_SEARCHPATH
10985 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10986#endif
10987 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10988#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010989 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010990 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10991#endif
10992#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010993 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10994 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10995 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010996#endif
10997 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10998 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10999 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
11000 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011001#ifdef FEAT_PERSISTENT_UNDO
11002 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
11003#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011004 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
11005#ifdef FEAT_KEYMAP
11006 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
11007#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011008#ifdef FEAT_SIGNS
11009 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
11010#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011011#ifdef FEAT_VARTABS
11012 case PV_VSTS: return (char_u *)&(curbuf->b_p_vsts);
11013 case PV_VTS: return (char_u *)&(curbuf->b_p_vts);
11014#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010011015 default: iemsg(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011016 }
11017 /* always return a valid pointer to avoid a crash! */
11018 return (char_u *)&(curbuf->b_p_wm);
11019}
11020
11021/*
11022 * Get the value of 'equalprg', either the buffer-local one or the global one.
11023 */
11024 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011025get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011026{
11027 if (*curbuf->b_p_ep == NUL)
11028 return p_ep;
11029 return curbuf->b_p_ep;
11030}
11031
Bram Moolenaar071d4272004-06-13 20:20:40 +000011032/*
11033 * Copy options from one window to another.
11034 * Used when splitting a window.
11035 */
11036 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011037win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011038{
11039 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
11040 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
11041# ifdef FEAT_RIGHTLEFT
11042# ifdef FEAT_FKMAP
11043 /* Is this right? */
11044 wp_to->w_farsi = wp_from->w_farsi;
11045# endif
11046# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020011047#if defined(FEAT_LINEBREAK)
11048 briopt_check(wp_to);
11049#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011050}
Bram Moolenaar071d4272004-06-13 20:20:40 +000011051
11052/*
11053 * Copy the options from one winopt_T to another.
11054 * Doesn't free the old option values in "to", use clear_winopt() for that.
11055 * The 'scroll' option is not copied, because it depends on the window height.
11056 * The 'previewwindow' option is reset, there can be only one preview window.
11057 */
11058 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011059copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011060{
11061#ifdef FEAT_ARABIC
11062 to->wo_arab = from->wo_arab;
11063#endif
11064 to->wo_list = from->wo_list;
11065 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020011066 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011067#ifdef FEAT_LINEBREAK
11068 to->wo_nuw = from->wo_nuw;
11069#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011070#ifdef FEAT_RIGHTLEFT
11071 to->wo_rl = from->wo_rl;
11072 to->wo_rlc = vim_strsave(from->wo_rlc);
11073#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011074#ifdef FEAT_STL_OPT
11075 to->wo_stl = vim_strsave(from->wo_stl);
11076#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011077 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011078#ifdef FEAT_DIFF
11079 to->wo_wrap_save = from->wo_wrap_save;
11080#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011081#ifdef FEAT_LINEBREAK
11082 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020011083 to->wo_bri = from->wo_bri;
11084 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011085#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011086 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011087 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010011088 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011089 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011090#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000011091 to->wo_spell = from->wo_spell;
11092#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011093#ifdef FEAT_SYN_HL
11094 to->wo_cuc = from->wo_cuc;
11095 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020011096 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011097#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011098#ifdef FEAT_DIFF
11099 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011100 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011101#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011102#ifdef FEAT_CONCEAL
11103 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020011104 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011105#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011106#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011107 to->wo_twk = vim_strsave(from->wo_twk);
11108 to->wo_tws = vim_strsave(from->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011109#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011110#ifdef FEAT_FOLDING
11111 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011112 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011113 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011114 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011115 to->wo_fdi = vim_strsave(from->wo_fdi);
11116 to->wo_fml = from->wo_fml;
11117 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011118 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011119 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011120 to->wo_fdm_save = from->wo_diff_saved
11121 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011122 to->wo_fdn = from->wo_fdn;
11123# ifdef FEAT_EVAL
11124 to->wo_fde = vim_strsave(from->wo_fde);
11125 to->wo_fdt = vim_strsave(from->wo_fdt);
11126# endif
11127 to->wo_fmr = vim_strsave(from->wo_fmr);
11128#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011129#ifdef FEAT_SIGNS
11130 to->wo_scl = vim_strsave(from->wo_scl);
11131#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011132 check_winopt(to); /* don't want NULL pointers */
11133}
11134
11135/*
11136 * Check string options in a window for a NULL value.
11137 */
11138 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011139check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011140{
11141 check_winopt(&win->w_onebuf_opt);
11142 check_winopt(&win->w_allbuf_opt);
11143}
11144
11145/*
11146 * Check for NULL pointers in a winopt_T and replace them with empty_option.
11147 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020011148 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011149check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011150{
11151#ifdef FEAT_FOLDING
11152 check_string_option(&wop->wo_fdi);
11153 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011154 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011155# ifdef FEAT_EVAL
11156 check_string_option(&wop->wo_fde);
11157 check_string_option(&wop->wo_fdt);
11158# endif
11159 check_string_option(&wop->wo_fmr);
11160#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011161#ifdef FEAT_SIGNS
11162 check_string_option(&wop->wo_scl);
11163#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011164#ifdef FEAT_RIGHTLEFT
11165 check_string_option(&wop->wo_rlc);
11166#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011167#ifdef FEAT_STL_OPT
11168 check_string_option(&wop->wo_stl);
11169#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011170#ifdef FEAT_SYN_HL
11171 check_string_option(&wop->wo_cc);
11172#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011173#ifdef FEAT_CONCEAL
11174 check_string_option(&wop->wo_cocu);
11175#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011176#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011177 check_string_option(&wop->wo_twk);
11178 check_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011179#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011180#ifdef FEAT_LINEBREAK
11181 check_string_option(&wop->wo_briopt);
11182#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011183}
11184
11185/*
11186 * Free the allocated memory inside a winopt_T.
11187 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011188 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011189clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011190{
11191#ifdef FEAT_FOLDING
11192 clear_string_option(&wop->wo_fdi);
11193 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011194 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011195# ifdef FEAT_EVAL
11196 clear_string_option(&wop->wo_fde);
11197 clear_string_option(&wop->wo_fdt);
11198# endif
11199 clear_string_option(&wop->wo_fmr);
11200#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011201#ifdef FEAT_SIGNS
11202 clear_string_option(&wop->wo_scl);
11203#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011204#ifdef FEAT_LINEBREAK
11205 clear_string_option(&wop->wo_briopt);
11206#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011207#ifdef FEAT_RIGHTLEFT
11208 clear_string_option(&wop->wo_rlc);
11209#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011210#ifdef FEAT_STL_OPT
11211 clear_string_option(&wop->wo_stl);
11212#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011213#ifdef FEAT_SYN_HL
11214 clear_string_option(&wop->wo_cc);
11215#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011216#ifdef FEAT_CONCEAL
11217 clear_string_option(&wop->wo_cocu);
11218#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011219#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011220 clear_string_option(&wop->wo_twk);
11221 clear_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011222#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011223}
11224
11225/*
11226 * Copy global option values to local options for one buffer.
11227 * Used when creating a new buffer and sometimes when entering a buffer.
11228 * flags:
11229 * BCO_ENTER We will enter the buf buffer.
11230 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11231 * appropriate.
11232 * BCO_NOHELP Don't copy the values to a help buffer.
11233 */
11234 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011235buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011236{
11237 int should_copy = TRUE;
11238 char_u *save_p_isk = NULL; /* init for GCC */
11239 int dont_do_help;
11240 int did_isk = FALSE;
11241
11242 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011243 * Skip this when the option defaults have not been set yet. Happens when
11244 * main() allocates the first buffer.
11245 */
11246 if (p_cpo != NULL)
11247 {
11248 /*
11249 * Always copy when entering and 'cpo' contains 'S'.
11250 * Don't copy when already initialized.
11251 * Don't copy when 'cpo' contains 's' and not entering.
11252 * 'S' BCO_ENTER initialized 's' should_copy
11253 * yes yes X X TRUE
11254 * yes no yes X FALSE
11255 * no X yes X FALSE
11256 * X no no yes FALSE
11257 * X no no no TRUE
11258 * no yes no X TRUE
11259 */
11260 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11261 && (buf->b_p_initialized
11262 || (!(flags & BCO_ENTER)
11263 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11264 should_copy = FALSE;
11265
11266 if (should_copy || (flags & BCO_ALWAYS))
11267 {
11268 /* Don't copy the options specific to a help buffer when
11269 * BCO_NOHELP is given or the options were initialized already
11270 * (jumping back to a help file with CTRL-T or CTRL-O) */
11271 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11272 || buf->b_p_initialized;
11273 if (dont_do_help) /* don't free b_p_isk */
11274 {
11275 save_p_isk = buf->b_p_isk;
11276 buf->b_p_isk = NULL;
11277 }
11278 /*
Bram Moolenaar40385db2018-08-07 22:31:44 +020011279 * Always free the allocated strings. If not already initialized,
11280 * reset 'readonly' and copy 'fileformat'.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011281 */
11282 if (!buf->b_p_initialized)
11283 {
11284 free_buf_options(buf, TRUE);
11285 buf->b_p_ro = FALSE; /* don't copy readonly */
11286 buf->b_p_tx = p_tx;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011287 buf->b_p_fenc = vim_strsave(p_fenc);
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011288 switch (*p_ffs)
11289 {
11290 case 'm':
11291 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11292 case 'd':
11293 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11294 case 'u':
11295 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11296 default:
11297 buf->b_p_ff = vim_strsave(p_ff);
11298 }
11299 if (buf->b_p_ff != NULL)
11300 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011301 buf->b_p_bh = empty_option;
11302 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011303 }
11304 else
11305 free_buf_options(buf, FALSE);
11306
11307 buf->b_p_ai = p_ai;
11308 buf->b_p_ai_nopaste = p_ai_nopaste;
11309 buf->b_p_sw = p_sw;
11310 buf->b_p_tw = p_tw;
11311 buf->b_p_tw_nopaste = p_tw_nopaste;
11312 buf->b_p_tw_nobin = p_tw_nobin;
11313 buf->b_p_wm = p_wm;
11314 buf->b_p_wm_nopaste = p_wm_nopaste;
11315 buf->b_p_wm_nobin = p_wm_nobin;
11316 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011317 buf->b_p_bomb = p_bomb;
Bram Moolenaarb388be02015-07-22 22:19:38 +020011318 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011319 buf->b_p_et = p_et;
11320 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011321 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011322 buf->b_p_ml = p_ml;
11323 buf->b_p_ml_nobin = p_ml_nobin;
11324 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011325 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011326#ifdef FEAT_INS_EXPAND
11327 buf->b_p_cpt = vim_strsave(p_cpt);
11328#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011329#ifdef FEAT_COMPL_FUNC
11330 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011331 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011332#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011333 buf->b_p_sts = p_sts;
11334 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011335#ifdef FEAT_VARTABS
11336 buf->b_p_vsts = vim_strsave(p_vsts);
11337 if (p_vsts && p_vsts != empty_option)
11338 tabstop_set(p_vsts, &buf->b_p_vsts_array);
11339 else
11340 buf->b_p_vsts_array = 0;
11341 buf->b_p_vsts_nopaste = p_vsts_nopaste
11342 ? vim_strsave(p_vsts_nopaste) : NULL;
11343#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011344 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011345#ifdef FEAT_COMMENTS
11346 buf->b_p_com = vim_strsave(p_com);
11347#endif
11348#ifdef FEAT_FOLDING
11349 buf->b_p_cms = vim_strsave(p_cms);
11350#endif
11351 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011352 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011353 buf->b_p_nf = vim_strsave(p_nf);
11354 buf->b_p_mps = vim_strsave(p_mps);
11355#ifdef FEAT_SMARTINDENT
11356 buf->b_p_si = p_si;
11357#endif
11358 buf->b_p_ci = p_ci;
11359#ifdef FEAT_CINDENT
11360 buf->b_p_cin = p_cin;
11361 buf->b_p_cink = vim_strsave(p_cink);
11362 buf->b_p_cino = vim_strsave(p_cino);
11363#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011364 /* Don't copy 'filetype', it must be detected */
11365 buf->b_p_ft = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011366 buf->b_p_pi = p_pi;
11367#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11368 buf->b_p_cinw = vim_strsave(p_cinw);
11369#endif
11370#ifdef FEAT_LISP
11371 buf->b_p_lisp = p_lisp;
11372#endif
11373#ifdef FEAT_SYN_HL
11374 /* Don't copy 'syntax', it must be set */
11375 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011376 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011377 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011378#endif
11379#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011380 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011381 (void)compile_cap_prog(&buf->b_s);
11382 buf->b_s.b_p_spf = vim_strsave(p_spf);
11383 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011384#endif
11385#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11386 buf->b_p_inde = vim_strsave(p_inde);
11387 buf->b_p_indk = vim_strsave(p_indk);
11388#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011389 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011390#if defined(FEAT_EVAL)
11391 buf->b_p_fex = vim_strsave(p_fex);
11392#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011393#ifdef FEAT_CRYPT
11394 buf->b_p_key = vim_strsave(p_key);
11395#endif
11396#ifdef FEAT_SEARCHPATH
11397 buf->b_p_sua = vim_strsave(p_sua);
11398#endif
11399#ifdef FEAT_KEYMAP
11400 buf->b_p_keymap = vim_strsave(p_keymap);
11401 buf->b_kmap_state |= KEYMAP_INIT;
11402#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011403#ifdef FEAT_TERMINAL
11404 buf->b_p_twsl = p_twsl;
11405#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011406 /* This isn't really an option, but copying the langmap and IME
11407 * state from the current buffer is better than resetting it. */
11408 buf->b_p_iminsert = p_iminsert;
11409 buf->b_p_imsearch = p_imsearch;
11410
11411 /* options that are normally global but also have a local value
11412 * are not copied, start using the global value */
11413 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011414 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011415 buf->b_p_bkc = empty_option;
11416 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011417#ifdef FEAT_QUICKFIX
11418 buf->b_p_gp = empty_option;
11419 buf->b_p_mp = empty_option;
11420 buf->b_p_efm = empty_option;
11421#endif
11422 buf->b_p_ep = empty_option;
11423 buf->b_p_kp = empty_option;
11424 buf->b_p_path = empty_option;
11425 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011426 buf->b_p_tc = empty_option;
11427 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011428#ifdef FEAT_FIND_ID
11429 buf->b_p_def = empty_option;
11430 buf->b_p_inc = empty_option;
11431# ifdef FEAT_EVAL
11432 buf->b_p_inex = vim_strsave(p_inex);
11433# endif
11434#endif
11435#ifdef FEAT_INS_EXPAND
11436 buf->b_p_dict = empty_option;
11437 buf->b_p_tsr = empty_option;
11438#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011439#ifdef FEAT_TEXTOBJ
11440 buf->b_p_qe = vim_strsave(p_qe);
11441#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011442#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11443 buf->b_p_bexpr = empty_option;
11444#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011445#if defined(FEAT_CRYPT)
11446 buf->b_p_cm = empty_option;
11447#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011448#ifdef FEAT_PERSISTENT_UNDO
11449 buf->b_p_udf = p_udf;
11450#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011451#ifdef FEAT_LISP
11452 buf->b_p_lw = empty_option;
11453#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011454 buf->b_p_menc = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011455
11456 /*
11457 * Don't copy the options set by ex_help(), use the saved values,
11458 * when going from a help buffer to a non-help buffer.
11459 * Don't touch these at all when BCO_NOHELP is used and going from
11460 * or to a help buffer.
11461 */
11462 if (dont_do_help)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011463 {
Bram Moolenaar071d4272004-06-13 20:20:40 +000011464 buf->b_p_isk = save_p_isk;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011465#ifdef FEAT_VARTABS
11466 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11467 tabstop_set(p_vts, &buf->b_p_vts_array);
11468 else
11469 buf->b_p_vts_array = NULL;
11470#endif
11471 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011472 else
11473 {
11474 buf->b_p_isk = vim_strsave(p_isk);
11475 did_isk = TRUE;
11476 buf->b_p_ts = p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011477#ifdef FEAT_VARTABS
11478 buf->b_p_vts = vim_strsave(p_vts);
11479 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11480 tabstop_set(p_vts, &buf->b_p_vts_array);
11481 else
11482 buf->b_p_vts_array = NULL;
11483#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011484 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011485 if (buf->b_p_bt[0] == 'h')
11486 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011487 buf->b_p_ma = p_ma;
11488 }
11489 }
11490
11491 /*
11492 * When the options should be copied (ignoring BCO_ALWAYS), set the
11493 * flag that indicates that the options have been initialized.
11494 */
11495 if (should_copy)
11496 buf->b_p_initialized = TRUE;
11497 }
11498
11499 check_buf_options(buf); /* make sure we don't have NULLs */
11500 if (did_isk)
11501 (void)buf_init_chartab(buf, FALSE);
11502}
11503
11504/*
11505 * Reset the 'modifiable' option and its default value.
11506 */
11507 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011508reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011509{
11510 int opt_idx;
11511
11512 curbuf->b_p_ma = FALSE;
11513 p_ma = FALSE;
11514 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011515 if (opt_idx >= 0)
11516 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011517}
11518
11519/*
11520 * Set the global value for 'iminsert' to the local value.
11521 */
11522 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011523set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011524{
11525 p_iminsert = curbuf->b_p_iminsert;
11526}
11527
11528/*
11529 * Set the global value for 'imsearch' to the local value.
11530 */
11531 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011532set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011533{
11534 p_imsearch = curbuf->b_p_imsearch;
11535}
11536
11537#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11538static int expand_option_idx = -1;
11539static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11540static int expand_option_flags = 0;
11541
11542 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011543set_context_in_set_cmd(
11544 expand_T *xp,
11545 char_u *arg,
11546 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011547{
11548 int nextchar;
11549 long_u flags = 0; /* init for GCC */
11550 int opt_idx = 0; /* init for GCC */
11551 char_u *p;
11552 char_u *s;
11553 int is_term_option = FALSE;
11554 int key;
11555
11556 expand_option_flags = opt_flags;
11557
11558 xp->xp_context = EXPAND_SETTINGS;
11559 if (*arg == NUL)
11560 {
11561 xp->xp_pattern = arg;
11562 return;
11563 }
11564 p = arg + STRLEN(arg) - 1;
11565 if (*p == ' ' && *(p - 1) != '\\')
11566 {
11567 xp->xp_pattern = p + 1;
11568 return;
11569 }
11570 while (p > arg)
11571 {
11572 s = p;
11573 /* count number of backslashes before ' ' or ',' */
11574 if (*p == ' ' || *p == ',')
11575 {
11576 while (s > arg && *(s - 1) == '\\')
11577 --s;
11578 }
11579 /* break at a space with an even number of backslashes */
11580 if (*p == ' ' && ((p - s) & 1) == 0)
11581 {
11582 ++p;
11583 break;
11584 }
11585 --p;
11586 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011587 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011588 {
11589 xp->xp_context = EXPAND_BOOL_SETTINGS;
11590 p += 2;
11591 }
11592 if (STRNCMP(p, "inv", 3) == 0)
11593 {
11594 xp->xp_context = EXPAND_BOOL_SETTINGS;
11595 p += 3;
11596 }
11597 xp->xp_pattern = arg = p;
11598 if (*arg == '<')
11599 {
11600 while (*p != '>')
11601 if (*p++ == NUL) /* expand terminal option name */
11602 return;
11603 key = get_special_key_code(arg + 1);
11604 if (key == 0) /* unknown name */
11605 {
11606 xp->xp_context = EXPAND_NOTHING;
11607 return;
11608 }
11609 nextchar = *++p;
11610 is_term_option = TRUE;
11611 expand_option_name[2] = KEY2TERMCAP0(key);
11612 expand_option_name[3] = KEY2TERMCAP1(key);
11613 }
11614 else
11615 {
11616 if (p[0] == 't' && p[1] == '_')
11617 {
11618 p += 2;
11619 if (*p != NUL)
11620 ++p;
11621 if (*p == NUL)
11622 return; /* expand option name */
11623 nextchar = *++p;
11624 is_term_option = TRUE;
11625 expand_option_name[2] = p[-2];
11626 expand_option_name[3] = p[-1];
11627 }
11628 else
11629 {
11630 /* Allow * wildcard */
11631 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11632 p++;
11633 if (*p == NUL)
11634 return;
11635 nextchar = *p;
11636 *p = NUL;
11637 opt_idx = findoption(arg);
11638 *p = nextchar;
11639 if (opt_idx == -1 || options[opt_idx].var == NULL)
11640 {
11641 xp->xp_context = EXPAND_NOTHING;
11642 return;
11643 }
11644 flags = options[opt_idx].flags;
11645 if (flags & P_BOOL)
11646 {
11647 xp->xp_context = EXPAND_NOTHING;
11648 return;
11649 }
11650 }
11651 }
11652 /* handle "-=" and "+=" */
11653 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11654 {
11655 ++p;
11656 nextchar = '=';
11657 }
11658 if ((nextchar != '=' && nextchar != ':')
11659 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11660 {
11661 xp->xp_context = EXPAND_UNSUCCESSFUL;
11662 return;
11663 }
11664 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11665 {
11666 xp->xp_context = EXPAND_OLD_SETTING;
11667 if (is_term_option)
11668 expand_option_idx = -1;
11669 else
11670 expand_option_idx = opt_idx;
11671 xp->xp_pattern = p + 1;
11672 return;
11673 }
11674 xp->xp_context = EXPAND_NOTHING;
11675 if (is_term_option || (flags & P_NUM))
11676 return;
11677
11678 xp->xp_pattern = p + 1;
11679
11680 if (flags & P_EXPAND)
11681 {
11682 p = options[opt_idx].var;
11683 if (p == (char_u *)&p_bdir
11684 || p == (char_u *)&p_dir
11685 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011686 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011687 || p == (char_u *)&p_rtp
11688#ifdef FEAT_SEARCHPATH
11689 || p == (char_u *)&p_cdpath
11690#endif
11691#ifdef FEAT_SESSION
11692 || p == (char_u *)&p_vdir
11693#endif
11694 )
11695 {
11696 xp->xp_context = EXPAND_DIRECTORIES;
11697 if (p == (char_u *)&p_path
11698#ifdef FEAT_SEARCHPATH
11699 || p == (char_u *)&p_cdpath
11700#endif
11701 )
11702 xp->xp_backslash = XP_BS_THREE;
11703 else
11704 xp->xp_backslash = XP_BS_ONE;
11705 }
11706 else
11707 {
11708 xp->xp_context = EXPAND_FILES;
11709 /* for 'tags' need three backslashes for a space */
11710 if (p == (char_u *)&p_tags)
11711 xp->xp_backslash = XP_BS_THREE;
11712 else
11713 xp->xp_backslash = XP_BS_ONE;
11714 }
11715 }
11716
11717 /* For an option that is a list of file names, find the start of the
11718 * last file name. */
11719 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11720 {
11721 /* count number of backslashes before ' ' or ',' */
11722 if (*p == ' ' || *p == ',')
11723 {
11724 s = p;
11725 while (s > xp->xp_pattern && *(s - 1) == '\\')
11726 --s;
11727 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11728 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11729 {
11730 xp->xp_pattern = p + 1;
11731 break;
11732 }
11733 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011734
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011735#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011736 /* for 'spellsuggest' start at "file:" */
11737 if (options[opt_idx].var == (char_u *)&p_sps
11738 && STRNCMP(p, "file:", 5) == 0)
11739 {
11740 xp->xp_pattern = p + 5;
11741 break;
11742 }
11743#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011744 }
11745
11746 return;
11747}
11748
11749 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011750ExpandSettings(
11751 expand_T *xp,
11752 regmatch_T *regmatch,
11753 int *num_file,
11754 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011755{
11756 int num_normal = 0; /* Nr of matching non-term-code settings */
11757 int num_term = 0; /* Nr of matching terminal code settings */
11758 int opt_idx;
11759 int match;
11760 int count = 0;
11761 char_u *str;
11762 int loop;
11763 int is_term_opt;
11764 char_u name_buf[MAX_KEY_NAME_LEN];
11765 static char *(names[]) = {"all", "termcap"};
11766 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11767
11768 /* do this loop twice:
11769 * loop == 0: count the number of matching options
11770 * loop == 1: copy the matching options into allocated memory
11771 */
11772 for (loop = 0; loop <= 1; ++loop)
11773 {
11774 regmatch->rm_ic = ic;
11775 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11776 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011777 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11778 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011779 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11780 {
11781 if (loop == 0)
11782 num_normal++;
11783 else
11784 (*file)[count++] = vim_strsave((char_u *)names[match]);
11785 }
11786 }
11787 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11788 opt_idx++)
11789 {
11790 if (options[opt_idx].var == NULL)
11791 continue;
11792 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11793 && !(options[opt_idx].flags & P_BOOL))
11794 continue;
11795 is_term_opt = istermoption(&options[opt_idx]);
11796 if (is_term_opt && num_normal > 0)
11797 continue;
11798 match = FALSE;
11799 if (vim_regexec(regmatch, str, (colnr_T)0)
11800 || (options[opt_idx].shortname != NULL
11801 && vim_regexec(regmatch,
11802 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11803 match = TRUE;
11804 else if (is_term_opt)
11805 {
11806 name_buf[0] = '<';
11807 name_buf[1] = 't';
11808 name_buf[2] = '_';
11809 name_buf[3] = str[2];
11810 name_buf[4] = str[3];
11811 name_buf[5] = '>';
11812 name_buf[6] = NUL;
11813 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11814 {
11815 match = TRUE;
11816 str = name_buf;
11817 }
11818 }
11819 if (match)
11820 {
11821 if (loop == 0)
11822 {
11823 if (is_term_opt)
11824 num_term++;
11825 else
11826 num_normal++;
11827 }
11828 else
11829 (*file)[count++] = vim_strsave(str);
11830 }
11831 }
11832 /*
11833 * Check terminal key codes, these are not in the option table
11834 */
11835 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11836 {
11837 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11838 {
11839 if (!isprint(str[0]) || !isprint(str[1]))
11840 continue;
11841
11842 name_buf[0] = 't';
11843 name_buf[1] = '_';
11844 name_buf[2] = str[0];
11845 name_buf[3] = str[1];
11846 name_buf[4] = NUL;
11847
11848 match = FALSE;
11849 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11850 match = TRUE;
11851 else
11852 {
11853 name_buf[0] = '<';
11854 name_buf[1] = 't';
11855 name_buf[2] = '_';
11856 name_buf[3] = str[0];
11857 name_buf[4] = str[1];
11858 name_buf[5] = '>';
11859 name_buf[6] = NUL;
11860
11861 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11862 match = TRUE;
11863 }
11864 if (match)
11865 {
11866 if (loop == 0)
11867 num_term++;
11868 else
11869 (*file)[count++] = vim_strsave(name_buf);
11870 }
11871 }
11872
11873 /*
11874 * Check special key names.
11875 */
11876 regmatch->rm_ic = TRUE; /* ignore case here */
11877 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11878 {
11879 name_buf[0] = '<';
11880 STRCPY(name_buf + 1, str);
11881 STRCAT(name_buf, ">");
11882
11883 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11884 {
11885 if (loop == 0)
11886 num_term++;
11887 else
11888 (*file)[count++] = vim_strsave(name_buf);
11889 }
11890 }
11891 }
11892 if (loop == 0)
11893 {
11894 if (num_normal > 0)
11895 *num_file = num_normal;
11896 else if (num_term > 0)
11897 *num_file = num_term;
11898 else
11899 return OK;
11900 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11901 if (*file == NULL)
11902 {
11903 *file = (char_u **)"";
11904 return FAIL;
11905 }
11906 }
11907 }
11908 return OK;
11909}
11910
11911 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011912ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011913{
11914 char_u *var = NULL; /* init for GCC */
11915 char_u *buf;
11916
11917 *num_file = 0;
11918 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11919 if (*file == NULL)
11920 return FAIL;
11921
11922 /*
11923 * For a terminal key code expand_option_idx is < 0.
11924 */
11925 if (expand_option_idx < 0)
11926 {
11927 var = find_termcode(expand_option_name + 2);
11928 if (var == NULL)
11929 expand_option_idx = findoption(expand_option_name);
11930 }
11931
11932 if (expand_option_idx >= 0)
11933 {
11934 /* put string of option value in NameBuff */
11935 option_value2string(&options[expand_option_idx], expand_option_flags);
11936 var = NameBuff;
11937 }
11938 else if (var == NULL)
11939 var = (char_u *)"";
11940
11941 /* A backslash is required before some characters. This is the reverse of
11942 * what happens in do_set(). */
11943 buf = vim_strsave_escaped(var, escape_chars);
11944
11945 if (buf == NULL)
11946 {
Bram Moolenaard23a8232018-02-10 18:45:26 +010011947 VIM_CLEAR(*file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011948 return FAIL;
11949 }
11950
11951#ifdef BACKSLASH_IN_FILENAME
11952 /* For MS-Windows et al. we don't double backslashes at the start and
11953 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011954 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011955 if (var[0] == '\\' && var[1] == '\\'
11956 && expand_option_idx >= 0
11957 && (options[expand_option_idx].flags & P_EXPAND)
11958 && vim_isfilec(var[2])
11959 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011960 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011961#endif
11962
11963 *file[0] = buf;
11964 *num_file = 1;
11965 return OK;
11966}
11967#endif
11968
11969/*
11970 * Get the value for the numeric or string option *opp in a nice format into
11971 * NameBuff[]. Must not be called with a hidden option!
11972 */
11973 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011974option_value2string(
11975 struct vimoption *opp,
11976 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011977{
11978 char_u *varp;
11979
11980 varp = get_varp_scope(opp, opt_flags);
11981
11982 if (opp->flags & P_NUM)
11983 {
11984 long wc = 0;
11985
11986 if (wc_use_keyname(varp, &wc))
11987 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11988 else if (wc != 0)
11989 STRCPY(NameBuff, transchar((int)wc));
11990 else
11991 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11992 }
11993 else /* P_STRING */
11994 {
11995 varp = *(char_u **)(varp);
11996 if (varp == NULL) /* just in case */
11997 NameBuff[0] = NUL;
11998#ifdef FEAT_CRYPT
11999 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000012000 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012001 STRCPY(NameBuff, "*****");
12002#endif
12003 else if (opp->flags & P_EXPAND)
12004 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
12005 /* Translate 'pastetoggle' into special key names */
12006 else if ((char_u **)opp->var == &p_pt)
12007 str2specialbuf(p_pt, NameBuff, MAXPATHL);
12008 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000012009 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012010 }
12011}
12012
12013/*
12014 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
12015 * printed as a keyname.
12016 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
12017 */
12018 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012019wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012020{
12021 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
12022 {
12023 *wcp = *(long *)varp;
12024 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
12025 return TRUE;
12026 }
12027 return FALSE;
12028}
12029
Bram Moolenaar01615492015-02-03 13:00:38 +010012030#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012031/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012032 * Any character has an equivalent 'langmap' character. This is used for
12033 * keyboards that have a special language mode that sends characters above
12034 * 128 (although other characters can be translated too). The "to" field is a
12035 * Vim command character. This avoids having to switch the keyboard back to
12036 * ASCII mode when leaving Insert mode.
12037 *
12038 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
12039 * commands.
Bram Moolenaarfc3abf42019-01-24 15:54:21 +010012040 * langmap_mapga.ga_data is a sorted table of langmap_entry_T. This does the
12041 * same as langmap_mapchar[] for characters >= 256.
12042 *
12043 * Use growarray for 'langmap' chars >= 256
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012044 */
12045typedef struct
12046{
12047 int from;
12048 int to;
12049} langmap_entry_T;
12050
12051static garray_T langmap_mapga;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012052
12053/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012054 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
12055 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012056 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012057 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012058langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012059{
12060 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020012061 int a = 0;
12062 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012063
12064 /* Do a binary search for an existing entry. */
12065 while (a != b)
12066 {
12067 int i = (a + b) / 2;
12068 int d = entries[i].from - from;
12069
12070 if (d == 0)
12071 {
12072 entries[i].to = to;
12073 return;
12074 }
12075 if (d < 0)
12076 a = i + 1;
12077 else
12078 b = i;
12079 }
12080
12081 if (ga_grow(&langmap_mapga, 1) != OK)
12082 return; /* out of memory */
12083
12084 /* insert new entry at position "a" */
12085 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
12086 mch_memmove(entries + 1, entries,
12087 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
12088 ++langmap_mapga.ga_len;
12089 entries[0].from = from;
12090 entries[0].to = to;
12091}
12092
12093/*
12094 * Apply 'langmap' to multi-byte character "c" and return the result.
12095 */
12096 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012097langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012098{
12099 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
12100 int a = 0;
12101 int b = langmap_mapga.ga_len;
12102
12103 while (a != b)
12104 {
12105 int i = (a + b) / 2;
12106 int d = entries[i].from - c;
12107
12108 if (d == 0)
12109 return entries[i].to; /* found matching entry */
12110 if (d < 0)
12111 a = i + 1;
12112 else
12113 b = i;
12114 }
12115 return c; /* no entry found, return "c" unmodified */
12116}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012117
12118 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012119langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012120{
12121 int i;
12122
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012123 for (i = 0; i < 256; i++)
12124 langmap_mapchar[i] = i; /* we init with a one-to-one map */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012125 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012126}
12127
12128/*
12129 * Called when langmap option is set; the language map can be
12130 * changed at any time!
12131 */
12132 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012133langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012134{
12135 char_u *p;
12136 char_u *p2;
12137 int from, to;
12138
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012139 ga_clear(&langmap_mapga); /* clear the previous map first */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012140 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012141
12142 for (p = p_langmap; p[0] != NUL; )
12143 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000012144 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012145 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012146 {
12147 if (p2[0] == '\\' && p2[1] != NUL)
12148 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012149 }
12150 if (p2[0] == ';')
12151 ++p2; /* abcd;ABCD form, p2 points to A */
12152 else
12153 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
12154 while (p[0])
12155 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012156 if (p[0] == ',')
12157 {
12158 ++p;
12159 break;
12160 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012161 if (p[0] == '\\' && p[1] != NUL)
12162 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012163 from = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012164 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012165 if (p2 == NULL)
12166 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012167 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012168 if (p[0] != ',')
12169 {
12170 if (p[0] == '\\')
12171 ++p;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012172 to = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012173 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012174 }
12175 else
12176 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012177 if (p2[0] != ',')
12178 {
12179 if (p2[0] == '\\')
12180 ++p2;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012181 to = (*mb_ptr2char)(p2);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012182 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012183 }
12184 if (to == NUL)
12185 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012186 semsg(_("E357: 'langmap': Matching character missing for %s"),
Bram Moolenaar071d4272004-06-13 20:20:40 +000012187 transchar(from));
12188 return;
12189 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012190
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012191 if (from >= 256)
12192 langmap_set_entry(from, to);
12193 else
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012194 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012195
12196 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012197 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012198 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012199 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012200 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012201 if (*p == ';')
12202 {
12203 p = p2;
12204 if (p[0] != NUL)
12205 {
12206 if (p[0] != ',')
12207 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012208 semsg(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012209 return;
12210 }
12211 ++p;
12212 }
12213 break;
12214 }
12215 }
12216 }
12217 }
12218}
12219#endif
12220
12221/*
12222 * Return TRUE if format option 'x' is in effect.
12223 * Take care of no formatting when 'paste' is set.
12224 */
12225 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012226has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012227{
12228 if (p_paste)
12229 return FALSE;
12230 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12231}
12232
12233/*
12234 * Return TRUE if "x" is present in 'shortmess' option, or
12235 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12236 */
12237 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012238shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012239{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012240 return p_shm != NULL &&
12241 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012242 || (vim_strchr(p_shm, 'a') != NULL
12243 && vim_strchr((char_u *)SHM_A, x) != NULL));
12244}
12245
12246/*
12247 * paste_option_changed() - Called after p_paste was set or reset.
12248 */
12249 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012250paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012251{
12252 static int old_p_paste = FALSE;
12253 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012254 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012255#ifdef FEAT_CMDL_INFO
12256 static int save_ru = 0;
12257#endif
12258#ifdef FEAT_RIGHTLEFT
12259 static int save_ri = 0;
12260 static int save_hkmap = 0;
12261#endif
12262 buf_T *buf;
12263
12264 if (p_paste)
12265 {
12266 /*
12267 * Paste switched from off to on.
12268 * Save the current values, so they can be restored later.
12269 */
12270 if (!old_p_paste)
12271 {
12272 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012273 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012274 {
12275 buf->b_p_tw_nopaste = buf->b_p_tw;
12276 buf->b_p_wm_nopaste = buf->b_p_wm;
12277 buf->b_p_sts_nopaste = buf->b_p_sts;
12278 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012279 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012280#ifdef FEAT_VARTABS
12281 if (buf->b_p_vsts_nopaste)
12282 vim_free(buf->b_p_vsts_nopaste);
12283 buf->b_p_vsts_nopaste = buf->b_p_vsts && buf->b_p_vsts != empty_option
12284 ? vim_strsave(buf->b_p_vsts) : NULL;
12285#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012286 }
12287
12288 /* save global options */
12289 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012290 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012291#ifdef FEAT_CMDL_INFO
12292 save_ru = p_ru;
12293#endif
12294#ifdef FEAT_RIGHTLEFT
12295 save_ri = p_ri;
12296 save_hkmap = p_hkmap;
12297#endif
12298 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012299 p_ai_nopaste = p_ai;
12300 p_et_nopaste = p_et;
12301 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012302 p_tw_nopaste = p_tw;
12303 p_wm_nopaste = p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012304#ifdef FEAT_VARTABS
12305 if (p_vsts_nopaste)
12306 vim_free(p_vsts_nopaste);
12307 p_vsts_nopaste = p_vsts && p_vsts != empty_option ? vim_strsave(p_vsts) : NULL;
12308#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012309 }
12310
12311 /*
12312 * Always set the option values, also when 'paste' is set when it is
12313 * already on.
12314 */
12315 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012316 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012317 {
12318 buf->b_p_tw = 0; /* textwidth is 0 */
12319 buf->b_p_wm = 0; /* wrapmargin is 0 */
12320 buf->b_p_sts = 0; /* softtabstop is 0 */
12321 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012322 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012323#ifdef FEAT_VARTABS
12324 if (buf->b_p_vsts)
12325 free_string_option(buf->b_p_vsts);
12326 buf->b_p_vsts = empty_option;
12327 if (buf->b_p_vsts_array)
12328 vim_free(buf->b_p_vsts_array);
12329 buf->b_p_vsts_array = 0;
12330#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012331 }
12332
12333 /* set global options */
12334 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012335 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012336#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012337 if (p_ru)
12338 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012339 p_ru = 0; /* no ruler */
12340#endif
12341#ifdef FEAT_RIGHTLEFT
12342 p_ri = 0; /* no reverse insert */
12343 p_hkmap = 0; /* no Hebrew keyboard */
12344#endif
12345 /* set global values for local buffer options */
12346 p_tw = 0;
12347 p_wm = 0;
12348 p_sts = 0;
12349 p_ai = 0;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012350#ifdef FEAT_VARTABS
12351 if (p_vsts)
12352 free_string_option(p_vsts);
12353 p_vsts = empty_option;
12354#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012355 }
12356
12357 /*
12358 * Paste switched from on to off: Restore saved values.
12359 */
12360 else if (old_p_paste)
12361 {
12362 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012363 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012364 {
12365 buf->b_p_tw = buf->b_p_tw_nopaste;
12366 buf->b_p_wm = buf->b_p_wm_nopaste;
12367 buf->b_p_sts = buf->b_p_sts_nopaste;
12368 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012369 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012370#ifdef FEAT_VARTABS
12371 if (buf->b_p_vsts)
12372 free_string_option(buf->b_p_vsts);
12373 buf->b_p_vsts = buf->b_p_vsts_nopaste
12374 ? vim_strsave(buf->b_p_vsts_nopaste) : empty_option;
12375 if (buf->b_p_vsts_array)
12376 vim_free(buf->b_p_vsts_array);
12377 if (buf->b_p_vsts && buf->b_p_vsts != empty_option)
12378 tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array);
12379 else
12380 buf->b_p_vsts_array = 0;
12381#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012382 }
12383
12384 /* restore global options */
12385 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012386 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012387#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012388 if (p_ru != save_ru)
12389 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012390 p_ru = save_ru;
12391#endif
12392#ifdef FEAT_RIGHTLEFT
12393 p_ri = save_ri;
12394 p_hkmap = save_hkmap;
12395#endif
12396 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012397 p_ai = p_ai_nopaste;
12398 p_et = p_et_nopaste;
12399 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012400 p_tw = p_tw_nopaste;
12401 p_wm = p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012402#ifdef FEAT_VARTABS
12403 if (p_vsts)
12404 free_string_option(p_vsts);
12405 p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option;
12406#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012407 }
12408
12409 old_p_paste = p_paste;
12410}
12411
12412/*
12413 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12414 *
12415 * Reset 'compatible' and set the values for options that didn't get set yet
12416 * to the Vim defaults.
12417 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012418 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012419 */
12420 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012421vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012422{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012423 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012424 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012425 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012426
12427 if (!option_was_set((char_u *)"cp"))
12428 {
12429 p_cp = FALSE;
12430 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12431 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12432 set_option_default(opt_idx, OPT_FREE, FALSE);
12433 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012434 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012435 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012436
12437 if (fname != NULL)
12438 {
12439 p = vim_getenv(envname, &dofree);
12440 if (p == NULL)
12441 {
12442 /* Set $MYVIMRC to the first vimrc file found. */
12443 p = FullName_save(fname, FALSE);
12444 if (p != NULL)
12445 {
12446 vim_setenv(envname, p);
12447 vim_free(p);
12448 }
12449 }
12450 else if (dofree)
12451 vim_free(p);
12452 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012453}
12454
12455/*
12456 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12457 */
12458 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012459change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012460{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012461 int opt_idx;
12462
Bram Moolenaar071d4272004-06-13 20:20:40 +000012463 if (p_cp != on)
12464 {
12465 p_cp = on;
12466 compatible_set();
12467 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012468 opt_idx = findoption((char_u *)"cp");
12469 if (opt_idx >= 0)
12470 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012471}
12472
12473/*
12474 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012475 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012476 */
12477 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012478option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012479{
12480 int idx;
12481
12482 idx = findoption(name);
12483 if (idx < 0) /* unknown option */
12484 return FALSE;
12485 if (options[idx].flags & P_WAS_SET)
12486 return TRUE;
12487 return FALSE;
12488}
12489
12490/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012491 * Reset the flag indicating option "name" was set.
12492 */
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012493 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012494reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012495{
12496 int idx = findoption(name);
12497
12498 if (idx >= 0)
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012499 {
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012500 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012501 return OK;
12502 }
12503 return FAIL;
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012504}
12505
12506/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012507 * compatible_set() - Called when 'compatible' has been set or unset.
12508 *
12509 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12510 * flag) to a Vi compatible value.
12511 * When 'compatible' is unset: Set all options that have a different default
12512 * for Vim (without the P_VI_DEF flag) to that default.
12513 */
12514 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012515compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012516{
12517 int opt_idx;
12518
12519 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12520 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12521 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12522 set_option_default(opt_idx, OPT_FREE, p_cp);
12523 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012524 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012525}
12526
12527#ifdef FEAT_LINEBREAK
12528
12529# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12530 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012531 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012532# endif
12533
12534/*
12535 * fill_breakat_flags() -- called when 'breakat' changes value.
12536 */
12537 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012538fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012539{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012540 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012541 int i;
12542
12543 for (i = 0; i < 256; i++)
12544 breakat_flags[i] = FALSE;
12545
12546 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012547 for (p = p_breakat; *p; p++)
12548 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012549}
12550
12551# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012552 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012553# endif
12554
12555#endif
12556
12557/*
12558 * Check an option that can be a range of string values.
12559 *
12560 * Return OK for correct value, FAIL otherwise.
12561 * Empty is always OK.
12562 */
12563 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012564check_opt_strings(
12565 char_u *val,
12566 char **values,
12567 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012568{
12569 return opt_strings_flags(val, values, NULL, list);
12570}
12571
12572/*
12573 * Handle an option that can be a range of string values.
12574 * Set a flag in "*flagp" for each string present.
12575 *
12576 * Return OK for correct value, FAIL otherwise.
12577 * Empty is always OK.
12578 */
12579 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012580opt_strings_flags(
12581 char_u *val, /* new value */
12582 char **values, /* array of valid string values */
12583 unsigned *flagp,
12584 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012585{
12586 int i;
12587 int len;
12588 unsigned new_flags = 0;
12589
12590 while (*val)
12591 {
12592 for (i = 0; ; ++i)
12593 {
12594 if (values[i] == NULL) /* val not found in values[] */
12595 return FAIL;
12596
12597 len = (int)STRLEN(values[i]);
12598 if (STRNCMP(values[i], val, len) == 0
12599 && ((list && val[len] == ',') || val[len] == NUL))
12600 {
12601 val += len + (val[len] == ',');
12602 new_flags |= (1 << i);
12603 break; /* check next item in val list */
12604 }
12605 }
12606 }
12607 if (flagp != NULL)
12608 *flagp = new_flags;
12609
12610 return OK;
12611}
12612
12613/*
12614 * Read the 'wildmode' option, fill wim_flags[].
12615 */
12616 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012617check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012618{
12619 char_u new_wim_flags[4];
12620 char_u *p;
12621 int i;
12622 int idx = 0;
12623
12624 for (i = 0; i < 4; ++i)
12625 new_wim_flags[i] = 0;
12626
12627 for (p = p_wim; *p; ++p)
12628 {
12629 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12630 ;
12631 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12632 return FAIL;
12633 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12634 new_wim_flags[idx] |= WIM_LONGEST;
12635 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12636 new_wim_flags[idx] |= WIM_FULL;
12637 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12638 new_wim_flags[idx] |= WIM_LIST;
12639 else
12640 return FAIL;
12641 p += i;
12642 if (*p == NUL)
12643 break;
12644 if (*p == ',')
12645 {
12646 if (idx == 3)
12647 return FAIL;
12648 ++idx;
12649 }
12650 }
12651
12652 /* fill remaining entries with last flag */
12653 while (idx < 3)
12654 {
12655 new_wim_flags[idx + 1] = new_wim_flags[idx];
12656 ++idx;
12657 }
12658
12659 /* only when there are no errors, wim_flags[] is changed */
12660 for (i = 0; i < 4; ++i)
12661 wim_flags[i] = new_wim_flags[i];
12662 return OK;
12663}
12664
12665/*
12666 * Check if backspacing over something is allowed.
12667 */
12668 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012669can_bs(
12670 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012671{
Bram Moolenaar6b810d92018-06-04 17:28:44 +020012672#ifdef FEAT_JOB_CHANNEL
12673 if (what == BS_START && bt_prompt(curbuf))
12674 return FALSE;
12675#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012676 switch (*p_bs)
12677 {
12678 case '2': return TRUE;
12679 case '1': return (what != BS_START);
12680 case '0': return FALSE;
12681 }
12682 return vim_strchr(p_bs, what) != NULL;
12683}
12684
12685/*
12686 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12687 * the file must be considered changed when the value is different.
12688 */
12689 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012690save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012691{
12692 buf->b_start_ffc = *buf->b_p_ff;
12693 buf->b_start_eol = buf->b_p_eol;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012694 buf->b_start_bomb = buf->b_p_bomb;
12695
Bram Moolenaar071d4272004-06-13 20:20:40 +000012696 /* Only use free/alloc when necessary, they take time. */
12697 if (buf->b_start_fenc == NULL
12698 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12699 {
12700 vim_free(buf->b_start_fenc);
12701 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12702 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012703}
12704
12705/*
12706 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12707 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012708 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12709 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012710 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012711 * When "ignore_empty" is true don't consider a new, empty buffer to be
12712 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012713 */
12714 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012715file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012716{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012717 /* In a buffer that was never loaded the options are not valid. */
12718 if (buf->b_flags & BF_NEVERLOADED)
12719 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012720 if (ignore_empty
12721 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012722 && buf->b_ml.ml_line_count == 1
12723 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12724 return FALSE;
12725 if (buf->b_start_ffc != *buf->b_p_ff)
12726 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012727 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012728 return TRUE;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012729 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12730 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012731 if (buf->b_start_fenc == NULL)
12732 return (*buf->b_p_fenc != NUL);
12733 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012734}
12735
12736/*
12737 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12738 */
12739 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012740check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012741{
12742 return check_opt_strings(p, p_ff_values, FALSE);
12743}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012744
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012745#ifdef FEAT_VARTABS
12746
12747/*
12748 * Set the integer values corresponding to the string setting of 'vartabstop'.
12749 */
12750 int
12751tabstop_set(char_u *var, int **array)
12752{
12753 int valcount = 1;
12754 int t;
12755 char_u *cp;
12756
Bram Moolenaar64f41072018-10-15 22:51:50 +020012757 if (var[0] == NUL || (var[0] == '0' && var[1] == NUL))
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012758 {
12759 *array = NULL;
12760 return TRUE;
12761 }
12762
Bram Moolenaar64f41072018-10-15 22:51:50 +020012763 for (cp = var; *cp != NUL; ++cp)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012764 {
Bram Moolenaar64f41072018-10-15 22:51:50 +020012765 if (cp == var || cp[-1] == ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012766 {
12767 char_u *end;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012768
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012769 if (strtol((char *)cp, (char **)&end, 10) <= 0)
12770 {
12771 if (cp != end)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012772 emsg(_(e_positive));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012773 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012774 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012775 return FALSE;
12776 }
12777 }
12778
12779 if (VIM_ISDIGIT(*cp))
12780 continue;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012781 if (cp[0] == ',' && cp > var && cp[-1] != ',' && cp[1] != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012782 {
12783 ++valcount;
12784 continue;
12785 }
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012786 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012787 return FALSE;
12788 }
12789
Bram Moolenaar64f41072018-10-15 22:51:50 +020012790 *array = (int *)alloc((unsigned) ((valcount + 1) * sizeof(int)));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012791 (*array)[0] = valcount;
12792
12793 t = 1;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012794 for (cp = var; *cp != NUL;)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012795 {
12796 (*array)[t++] = atoi((char *)cp);
Bram Moolenaar64f41072018-10-15 22:51:50 +020012797 while (*cp != NUL && *cp != ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012798 ++cp;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012799 if (*cp != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012800 ++cp;
12801 }
12802
12803 return TRUE;
12804}
12805
12806/*
12807 * Calculate the number of screen spaces a tab will occupy.
12808 * If "vts" is set then the tab widths are taken from that array,
12809 * otherwise the value of ts is used.
12810 */
12811 int
12812tabstop_padding(colnr_T col, int ts_arg, int *vts)
12813{
12814 int ts = ts_arg == 0 ? 8 : ts_arg;
12815 int tabcount;
12816 colnr_T tabcol = 0;
12817 int t;
12818 int padding = 0;
12819
12820 if (vts == NULL || vts[0] == 0)
12821 return ts - (col % ts);
12822
12823 tabcount = vts[0];
12824
12825 for (t = 1; t <= tabcount; ++t)
12826 {
12827 tabcol += vts[t];
12828 if (tabcol > col)
12829 {
12830 padding = (int)(tabcol - col);
12831 break;
12832 }
12833 }
12834 if (t > tabcount)
12835 padding = vts[tabcount] - (int)((col - tabcol) % vts[tabcount]);
12836
12837 return padding;
12838}
12839
12840/*
12841 * Find the size of the tab that covers a particular column.
12842 */
12843 int
12844tabstop_at(colnr_T col, int ts, int *vts)
12845{
12846 int tabcount;
12847 colnr_T tabcol = 0;
12848 int t;
12849 int tab_size = 0;
12850
12851 if (vts == 0 || vts[0] == 0)
12852 return ts;
12853
12854 tabcount = vts[0];
12855 for (t = 1; t <= tabcount; ++t)
12856 {
12857 tabcol += vts[t];
12858 if (tabcol > col)
12859 {
12860 tab_size = vts[t];
12861 break;
12862 }
12863 }
12864 if (t > tabcount)
12865 tab_size = vts[tabcount];
12866
12867 return tab_size;
12868}
12869
12870/*
12871 * Find the column on which a tab starts.
12872 */
12873 colnr_T
12874tabstop_start(colnr_T col, int ts, int *vts)
12875{
12876 int tabcount;
12877 colnr_T tabcol = 0;
12878 int t;
12879 int excess;
12880
Bram Moolenaar0119a592018-06-24 23:53:28 +020012881 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012882 return (col / ts) * ts;
12883
12884 tabcount = vts[0];
12885 for (t = 1; t <= tabcount; ++t)
12886 {
12887 tabcol += vts[t];
12888 if (tabcol > col)
12889 return tabcol - vts[t];
12890 }
12891
12892 excess = tabcol % vts[tabcount];
12893 return excess + ((col - excess) / vts[tabcount]) * vts[tabcount];
12894}
12895
12896/*
12897 * Find the number of tabs and spaces necessary to get from one column
12898 * to another.
12899 */
12900 void
12901tabstop_fromto(
12902 colnr_T start_col,
12903 colnr_T end_col,
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012904 int ts_arg,
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012905 int *vts,
12906 int *ntabs,
12907 int *nspcs)
12908{
12909 int spaces = end_col - start_col;
12910 colnr_T tabcol = 0;
12911 int padding = 0;
12912 int tabcount;
12913 int t;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012914 int ts = ts_arg == 0 ? curbuf->b_p_ts : ts_arg;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012915
Bram Moolenaar0119a592018-06-24 23:53:28 +020012916 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012917 {
12918 int tabs = 0;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012919 int initspc = 0;
Bram Moolenaar0119a592018-06-24 23:53:28 +020012920
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012921 initspc = ts - (start_col % ts);
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012922 if (spaces >= initspc)
12923 {
12924 spaces -= initspc;
12925 tabs++;
12926 }
12927 tabs += spaces / ts;
12928 spaces -= (spaces / ts) * ts;
12929
12930 *ntabs = tabs;
12931 *nspcs = spaces;
12932 return;
12933 }
12934
12935 /* Find the padding needed to reach the next tabstop. */
12936 tabcount = vts[0];
12937 for (t = 1; t <= tabcount; ++t)
12938 {
12939 tabcol += vts[t];
12940 if (tabcol > start_col)
12941 {
12942 padding = (int)(tabcol - start_col);
12943 break;
12944 }
12945 }
12946 if (t > tabcount)
12947 padding = vts[tabcount] - (int)((start_col - tabcol) % vts[tabcount]);
12948
12949 /* If the space needed is less than the padding no tabs can be used. */
12950 if (spaces < padding)
12951 {
12952 *ntabs = 0;
12953 *nspcs = spaces;
12954 return;
12955 }
12956
12957 *ntabs = 1;
12958 spaces -= padding;
12959
12960 /* At least one tab has been used. See if any more will fit. */
12961 while (spaces != 0 && ++t <= tabcount)
12962 {
12963 padding = vts[t];
12964 if (spaces < padding)
12965 {
12966 *nspcs = spaces;
12967 return;
12968 }
12969 ++*ntabs;
12970 spaces -= padding;
12971 }
12972
12973 *ntabs += spaces / vts[tabcount];
12974 *nspcs = spaces % vts[tabcount];
12975}
12976
12977/*
12978 * See if two tabstop arrays contain the same values.
12979 */
12980 int
12981tabstop_eq(int *ts1, int *ts2)
12982{
12983 int t;
12984
12985 if ((ts1 == 0 && ts2) || (ts1 && ts2 == 0))
12986 return FALSE;
12987 if (ts1 == ts2)
12988 return TRUE;
12989 if (ts1[0] != ts2[0])
12990 return FALSE;
12991
12992 for (t = 1; t <= ts1[0]; ++t)
12993 if (ts1[t] != ts2[t])
12994 return FALSE;
12995
12996 return TRUE;
12997}
12998
Bram Moolenaar113e1072019-01-20 15:30:40 +010012999#if defined(FEAT_BEVAL) || defined(PROTO)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013000/*
13001 * Copy a tabstop array, allocating space for the new array.
13002 */
13003 int *
13004tabstop_copy(int *oldts)
13005{
13006 int *newts;
13007 int t;
13008
13009 if (oldts == 0)
13010 return 0;
13011
13012 newts = (int *) alloc((unsigned) ((oldts[0] + 1) * sizeof(int)));
13013 for (t = 0; t <= oldts[0]; ++t)
13014 newts[t] = oldts[t];
13015
13016 return newts;
13017}
Bram Moolenaar113e1072019-01-20 15:30:40 +010013018#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013019
13020/*
13021 * Return a count of the number of tabstops.
13022 */
13023 int
13024tabstop_count(int *ts)
13025{
13026 return ts != NULL ? ts[0] : 0;
13027}
13028
13029/*
13030 * Return the first tabstop, or 8 if there are no tabstops defined.
13031 */
13032 int
13033tabstop_first(int *ts)
13034{
13035 return ts != NULL ? ts[1] : 8;
13036}
13037
13038#endif
13039
Bram Moolenaar14f24742012-08-08 18:01:05 +020013040/*
13041 * Return the effective shiftwidth value for current buffer, using the
13042 * 'tabstop' value when 'shiftwidth' is zero.
13043 */
13044 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013045get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020013046{
Bram Moolenaarf9514162018-11-22 03:08:29 +010013047 return get_sw_value_col(buf, 0);
13048}
13049
13050/*
13051 * Idem, using the first non-black in the current line.
13052 */
13053 long
13054get_sw_value_indent(buf_T *buf)
13055{
13056 pos_T pos = curwin->w_cursor;
13057
13058 pos.col = getwhitecols_curline();
13059 return get_sw_value_pos(buf, &pos);
13060}
13061
13062/*
13063 * Idem, using "pos".
13064 */
13065 long
13066get_sw_value_pos(buf_T *buf, pos_T *pos)
13067{
13068 pos_T save_cursor = curwin->w_cursor;
13069 long sw_value;
13070
13071 curwin->w_cursor = *pos;
13072 sw_value = get_sw_value_col(buf, get_nolist_virtcol());
13073 curwin->w_cursor = save_cursor;
13074 return sw_value;
13075}
13076
13077/*
13078 * Idem, using virtual column "col".
13079 */
13080 long
13081get_sw_value_col(buf_T *buf, colnr_T col UNUSED)
13082{
13083 return buf->b_p_sw ? buf->b_p_sw :
13084 #ifdef FEAT_VARTABS
13085 tabstop_at(col, buf->b_p_ts, buf->b_p_vts_array);
13086 #else
13087 buf->b_p_ts;
13088 #endif
Bram Moolenaar14f24742012-08-08 18:01:05 +020013089}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013090
13091/*
13092 * Return the effective softtabstop value for the current buffer, using the
Bram Moolenaar33d5ab32018-07-02 20:51:24 +020013093 * 'shiftwidth' value when 'softtabstop' is negative.
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013094 */
13095 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013096get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013097{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010013098 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013099}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013100
13101/*
13102 * Check matchpairs option for "*initc".
13103 * If there is a match set "*initc" to the matching character and "*findc" to
13104 * the opposite character. Set "*backwards" to the direction.
13105 * When "switchit" is TRUE swap the direction.
13106 */
13107 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010013108find_mps_values(
13109 int *initc,
13110 int *findc,
13111 int *backwards,
13112 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013113{
13114 char_u *ptr;
13115
13116 ptr = curbuf->b_p_mps;
13117 while (*ptr != NUL)
13118 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013119 if (has_mbyte)
13120 {
13121 char_u *prev;
13122
13123 if (mb_ptr2char(ptr) == *initc)
13124 {
13125 if (switchit)
13126 {
13127 *findc = *initc;
13128 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13129 *backwards = TRUE;
13130 }
13131 else
13132 {
13133 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13134 *backwards = FALSE;
13135 }
13136 return;
13137 }
13138 prev = ptr;
13139 ptr += mb_ptr2len(ptr) + 1;
13140 if (mb_ptr2char(ptr) == *initc)
13141 {
13142 if (switchit)
13143 {
13144 *findc = *initc;
13145 *initc = mb_ptr2char(prev);
13146 *backwards = FALSE;
13147 }
13148 else
13149 {
13150 *findc = mb_ptr2char(prev);
13151 *backwards = TRUE;
13152 }
13153 return;
13154 }
13155 ptr += mb_ptr2len(ptr);
13156 }
13157 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013158 {
13159 if (*ptr == *initc)
13160 {
13161 if (switchit)
13162 {
13163 *backwards = TRUE;
13164 *findc = *initc;
13165 *initc = ptr[2];
13166 }
13167 else
13168 {
13169 *backwards = FALSE;
13170 *findc = ptr[2];
13171 }
13172 return;
13173 }
13174 ptr += 2;
13175 if (*ptr == *initc)
13176 {
13177 if (switchit)
13178 {
13179 *backwards = FALSE;
13180 *findc = *initc;
13181 *initc = ptr[-2];
13182 }
13183 else
13184 {
13185 *backwards = TRUE;
13186 *findc = ptr[-2];
13187 }
13188 return;
13189 }
13190 ++ptr;
13191 }
13192 if (*ptr == ',')
13193 ++ptr;
13194 }
13195}
Bram Moolenaar597a4222014-06-25 14:39:50 +020013196
13197#if defined(FEAT_LINEBREAK) || defined(PROTO)
13198/*
13199 * This is called when 'breakindentopt' is changed and when a window is
13200 * initialized.
13201 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013202 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013203briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020013204{
13205 char_u *p;
13206 int bri_shift = 0;
13207 long bri_min = 20;
13208 int bri_sbr = FALSE;
13209
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013210 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013211 while (*p != NUL)
13212 {
13213 if (STRNCMP(p, "shift:", 6) == 0
13214 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
13215 {
13216 p += 6;
13217 bri_shift = getdigits(&p);
13218 }
13219 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
13220 {
13221 p += 4;
13222 bri_min = getdigits(&p);
13223 }
13224 else if (STRNCMP(p, "sbr", 3) == 0)
13225 {
13226 p += 3;
13227 bri_sbr = TRUE;
13228 }
13229 if (*p != ',' && *p != NUL)
13230 return FAIL;
13231 if (*p == ',')
13232 ++p;
13233 }
13234
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013235 wp->w_p_brishift = bri_shift;
13236 wp->w_p_brimin = bri_min;
13237 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013238
13239 return OK;
13240}
13241#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013242
13243/*
13244 * Get the local or global value of 'backupcopy'.
13245 */
13246 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013247get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013248{
13249 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
13250}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020013251
13252#if defined(FEAT_SIGNS) || defined(PROTO)
13253/*
13254 * Return TRUE when window "wp" has a column to draw signs in.
13255 */
13256 int
13257signcolumn_on(win_T *wp)
13258{
13259 if (*wp->w_p_scl == 'n')
13260 return FALSE;
13261 if (*wp->w_p_scl == 'y')
13262 return TRUE;
13263 return (wp->w_buffer->b_signlist != NULL
13264# ifdef FEAT_NETBEANS_INTG
13265 || wp->w_buffer->b_has_sign_column
13266# endif
13267 );
13268}
13269#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013270
13271#if defined(FEAT_EVAL) || defined(PROTO)
13272/*
13273 * Get window or buffer local options.
13274 */
13275 dict_T *
13276get_winbuf_options(int bufopt)
13277{
13278 dict_T *d;
13279 int opt_idx;
13280
13281 d = dict_alloc();
13282 if (d == NULL)
13283 return NULL;
13284
13285 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
13286 {
13287 struct vimoption *opt = &options[opt_idx];
13288
13289 if ((bufopt && (opt->indir & PV_BUF))
13290 || (!bufopt && (opt->indir & PV_WIN)))
13291 {
13292 char_u *varp = get_varp(opt);
13293
13294 if (varp != NULL)
13295 {
13296 if (opt->flags & P_STRING)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013297 dict_add_string(d, opt->fullname, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020013298 else if (opt->flags & P_NUM)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013299 dict_add_number(d, opt->fullname, *(long *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013300 else
Bram Moolenaare0be1672018-07-08 16:50:37 +020013301 dict_add_number(d, opt->fullname, *(int *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013302 }
13303 }
13304 }
13305
13306 return d;
13307}
13308#endif