blob: c8808be041e97e79fa933e6a50c0be7dad0740f7 [file] [log] [blame]
Bram Moolenaaredf3f972016-08-29 22:49:24 +02001/* vi:set ts=8 sts=4 sw=4 noet:
Bram Moolenaar071d4272004-06-13 20:20:40 +00002 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * Code to handle user-settable options. This is all pretty much table-
12 * driven. Checklist for adding a new option:
13 * - Put it in the options array below (copy an existing entry).
14 * - For a global option: Add a variable for it in option.h.
15 * - For a buffer or window local option:
16 * - Add a PV_XX entry to the enum below.
17 * - Add a variable to the window or buffer struct in structs.h.
18 * - For a window option, add some code to copy_winopt().
19 * - For a buffer option, add some code to buf_copy_options().
20 * - For a buffer string option, add code to check_buf_options().
21 * - If it's a numeric option, add any necessary bounds checks to do_set().
22 * - If it's a list of flags, add some code in do_set(), search for WW_ALL.
23 * - When adding an option with expansion (P_EXPAND), but with a different
24 * default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP.
Bram Moolenaarcea912a2016-10-12 14:20:24 +020025 * - Add documentation! One line in doc/quickref.txt, full description in
Bram Moolenaar071d4272004-06-13 20:20:40 +000026 * options.txt, and any other related places.
27 * - Add an entry in runtime/optwin.vim.
28 * When making changes:
29 * - Adjust the help for the option in doc/option.txt.
30 * - When an entry has the P_VIM flag, or is lacking the P_VI_DEF flag, add a
31 * comment at the help for the 'compatible' option.
32 */
33
34#define IN_OPTION_C
35#include "vim.h"
36
37/*
38 * The options that are local to a window or buffer have "indir" set to one of
39 * these values. Special values:
40 * PV_NONE: global option.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000041 * PV_WIN is added: window-local option
42 * PV_BUF is added: buffer-local option
Bram Moolenaar071d4272004-06-13 20:20:40 +000043 * PV_BOTH is added: global option which also has a local value.
44 */
45#define PV_BOTH 0x1000
Bram Moolenaara23ccb82006-02-27 00:08:02 +000046#define PV_WIN 0x2000
47#define PV_BUF 0x4000
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000048#define PV_MASK 0x0fff
Bram Moolenaara23ccb82006-02-27 00:08:02 +000049#define OPT_WIN(x) (idopt_T)(PV_WIN + (int)(x))
50#define OPT_BUF(x) (idopt_T)(PV_BUF + (int)(x))
Bram Moolenaar071d4272004-06-13 20:20:40 +000051#define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
52
Bram Moolenaara23ccb82006-02-27 00:08:02 +000053/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000054 * Definition of the PV_ values for buffer-local options.
55 * The BV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000056 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +000057#define PV_AI OPT_BUF(BV_AI)
58#define PV_AR OPT_BOTH(OPT_BUF(BV_AR))
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020059#define PV_BKC OPT_BOTH(OPT_BUF(BV_BKC))
Bram Moolenaar81bdd6a2017-07-23 22:57:00 +020060#define PV_BH OPT_BUF(BV_BH)
61#define PV_BT OPT_BUF(BV_BT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000062#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000063# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
64# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
65# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000066#endif
67#define PV_BIN OPT_BUF(BV_BIN)
68#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaarfc3abf42019-01-24 15:54:21 +010069#define PV_BOMB OPT_BUF(BV_BOMB)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000070#define PV_CI OPT_BUF(BV_CI)
71#ifdef FEAT_CINDENT
72# define PV_CIN OPT_BUF(BV_CIN)
73# define PV_CINK OPT_BUF(BV_CINK)
74# define PV_CINO OPT_BUF(BV_CINO)
75#endif
76#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
77# define PV_CINW OPT_BUF(BV_CINW)
78#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020079#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000080#ifdef FEAT_FOLDING
81# define PV_CMS OPT_BUF(BV_CMS)
82#endif
83#ifdef FEAT_COMMENTS
84# define PV_COM OPT_BUF(BV_COM)
85#endif
86#ifdef FEAT_INS_EXPAND
87# define PV_CPT OPT_BUF(BV_CPT)
88# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
89# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
90#endif
91#ifdef FEAT_COMPL_FUNC
92# define PV_CFU OPT_BUF(BV_CFU)
93#endif
94#ifdef FEAT_FIND_ID
95# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
96# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
97#endif
98#define PV_EOL OPT_BUF(BV_EOL)
Bram Moolenaar34d72d42015-07-17 14:18:08 +020099#define PV_FIXEOL OPT_BUF(BV_FIXEOL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000100#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
101#define PV_ET OPT_BUF(BV_ET)
Bram Moolenaarfc3abf42019-01-24 15:54:21 +0100102#define PV_FENC OPT_BUF(BV_FENC)
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000103#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
104# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
105#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100106#define PV_FP OPT_BOTH(OPT_BUF(BV_FP))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000107#ifdef FEAT_EVAL
108# define PV_FEX OPT_BUF(BV_FEX)
109#endif
110#define PV_FF OPT_BUF(BV_FF)
111#define PV_FLP OPT_BUF(BV_FLP)
112#define PV_FO OPT_BUF(BV_FO)
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +0100113#define PV_FT OPT_BUF(BV_FT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000114#define PV_IMI OPT_BUF(BV_IMI)
115#define PV_IMS OPT_BUF(BV_IMS)
116#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
117# define PV_INDE OPT_BUF(BV_INDE)
118# define PV_INDK OPT_BUF(BV_INDK)
119#endif
120#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
121# define PV_INEX OPT_BUF(BV_INEX)
122#endif
123#define PV_INF OPT_BUF(BV_INF)
124#define PV_ISK OPT_BUF(BV_ISK)
125#ifdef FEAT_CRYPT
126# define PV_KEY OPT_BUF(BV_KEY)
127#endif
128#ifdef FEAT_KEYMAP
129# define PV_KMAP OPT_BUF(BV_KMAP)
130#endif
131#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
132#ifdef FEAT_LISP
133# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100134# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000135#endif
Bram Moolenaarfc3abf42019-01-24 15:54:21 +0100136#define PV_MENC OPT_BOTH(OPT_BUF(BV_MENC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000137#define PV_MA OPT_BUF(BV_MA)
138#define PV_ML OPT_BUF(BV_ML)
139#define PV_MOD OPT_BUF(BV_MOD)
140#define PV_MPS OPT_BUF(BV_MPS)
141#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000142#ifdef FEAT_COMPL_FUNC
143# define PV_OFU OPT_BUF(BV_OFU)
144#endif
145#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
146#define PV_PI OPT_BUF(BV_PI)
147#ifdef FEAT_TEXTOBJ
148# define PV_QE OPT_BUF(BV_QE)
149#endif
150#define PV_RO OPT_BUF(BV_RO)
151#ifdef FEAT_SMARTINDENT
152# define PV_SI OPT_BUF(BV_SI)
153#endif
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100154#define PV_SN OPT_BUF(BV_SN)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000155#ifdef FEAT_SYN_HL
156# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000157# define PV_SYN OPT_BUF(BV_SYN)
158#endif
159#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000160# define PV_SPC OPT_BUF(BV_SPC)
161# define PV_SPF OPT_BUF(BV_SPF)
162# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000163#endif
164#define PV_STS OPT_BUF(BV_STS)
165#ifdef FEAT_SEARCHPATH
166# define PV_SUA OPT_BUF(BV_SUA)
167#endif
168#define PV_SW OPT_BUF(BV_SW)
169#define PV_SWF OPT_BUF(BV_SWF)
170#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
Bram Moolenaar0f6562e2015-11-24 18:48:14 +0100171#define PV_TC OPT_BOTH(OPT_BUF(BV_TC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000172#define PV_TS OPT_BUF(BV_TS)
173#define PV_TW OPT_BUF(BV_TW)
174#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200175#ifdef FEAT_PERSISTENT_UNDO
176# define PV_UDF OPT_BUF(BV_UDF)
177#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000178#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200179#ifdef FEAT_VARTABS
180# define PV_VSTS OPT_BUF(BV_VSTS)
181# define PV_VTS OPT_BUF(BV_VTS)
182#endif
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000183
184/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000185 * Definition of the PV_ values for window-local options.
186 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000187 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000188#define PV_LIST OPT_WIN(WV_LIST)
189#ifdef FEAT_ARABIC
190# define PV_ARAB OPT_WIN(WV_ARAB)
191#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200192#ifdef FEAT_LINEBREAK
193# define PV_BRI OPT_WIN(WV_BRI)
194# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
195#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000196#ifdef FEAT_DIFF
197# define PV_DIFF OPT_WIN(WV_DIFF)
198#endif
199#ifdef FEAT_FOLDING
200# define PV_FDC OPT_WIN(WV_FDC)
201# define PV_FEN OPT_WIN(WV_FEN)
202# define PV_FDI OPT_WIN(WV_FDI)
203# define PV_FDL OPT_WIN(WV_FDL)
204# define PV_FDM OPT_WIN(WV_FDM)
205# define PV_FML OPT_WIN(WV_FML)
206# define PV_FDN OPT_WIN(WV_FDN)
207# ifdef FEAT_EVAL
208# define PV_FDE OPT_WIN(WV_FDE)
209# define PV_FDT OPT_WIN(WV_FDT)
210# endif
211# define PV_FMR OPT_WIN(WV_FMR)
212#endif
213#ifdef FEAT_LINEBREAK
214# define PV_LBR OPT_WIN(WV_LBR)
215#endif
216#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200217#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000218#ifdef FEAT_LINEBREAK
219# define PV_NUW OPT_WIN(WV_NUW)
220#endif
Bram Moolenaar4033c552017-09-16 20:54:51 +0200221#if defined(FEAT_QUICKFIX)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000222# define PV_PVW OPT_WIN(WV_PVW)
223#endif
224#ifdef FEAT_RIGHTLEFT
225# define PV_RL OPT_WIN(WV_RL)
226# define PV_RLC OPT_WIN(WV_RLC)
227#endif
Bram Moolenaar8a3bb562018-03-04 20:14:14 +0100228#define PV_SCBIND OPT_WIN(WV_SCBIND)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000229#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaar375e3392019-01-31 18:26:10 +0100230#define PV_SISO OPT_BOTH(OPT_WIN(WV_SISO))
231#define PV_SO OPT_BOTH(OPT_WIN(WV_SO))
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000232#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000233# define PV_SPELL OPT_WIN(WV_SPELL)
234#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000235#ifdef FEAT_SYN_HL
236# define PV_CUC OPT_WIN(WV_CUC)
237# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200238# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000239#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000240#ifdef FEAT_STL_OPT
241# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
242#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100243#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000244# define PV_WFH OPT_WIN(WV_WFH)
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000245# define PV_WFW OPT_WIN(WV_WFW)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000246#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar8a3bb562018-03-04 20:14:14 +0100247#define PV_CRBIND OPT_WIN(WV_CRBIND)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200248#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200249# define PV_COCU OPT_WIN(WV_COCU)
250# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200251#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200252#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200253# define PV_TWK OPT_WIN(WV_TWK)
254# define PV_TWS OPT_WIN(WV_TWS)
255# define PV_TWSL OPT_BUF(BV_TWSL)
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200256#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200257#ifdef FEAT_SIGNS
258# define PV_SCL OPT_WIN(WV_SCL)
259#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000260
261/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000262typedef enum
263{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000264 PV_NONE = 0,
265 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000266} idopt_T;
267
268/*
269 * Options local to a window have a value local to a buffer and global to all
270 * buffers. Indicate this by setting "var" to VAR_WIN.
271 */
272#define VAR_WIN ((char_u *)-1)
273
274/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000275 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000276 * Only to be used in option.c!
277 */
278static int p_ai;
279static int p_bin;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000280static int p_bomb;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000281static char_u *p_bh;
282static char_u *p_bt;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000283static int p_bl;
284static int p_ci;
285#ifdef FEAT_CINDENT
286static int p_cin;
287static char_u *p_cink;
288static char_u *p_cino;
289#endif
290#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
291static char_u *p_cinw;
292#endif
293#ifdef FEAT_COMMENTS
294static char_u *p_com;
295#endif
296#ifdef FEAT_FOLDING
297static char_u *p_cms;
298#endif
299#ifdef FEAT_INS_EXPAND
300static char_u *p_cpt;
301#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000302#ifdef FEAT_COMPL_FUNC
303static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000304static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000305#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000306static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200307static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000308static int p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000309static char_u *p_fenc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000310static char_u *p_ff;
311static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000312static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000313static char_u *p_ft;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000314static long p_iminsert;
315static long p_imsearch;
316#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
317static char_u *p_inex;
318#endif
319#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
320static char_u *p_inde;
321static char_u *p_indk;
322#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000323#if defined(FEAT_EVAL)
324static char_u *p_fex;
325#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000326static int p_inf;
327static char_u *p_isk;
328#ifdef FEAT_CRYPT
329static char_u *p_key;
330#endif
331#ifdef FEAT_LISP
332static int p_lisp;
333#endif
334static int p_ml;
335static int p_ma;
336static int p_mod;
337static char_u *p_mps;
338static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000339static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000340#ifdef FEAT_TEXTOBJ
341static char_u *p_qe;
342#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000343static int p_ro;
344#ifdef FEAT_SMARTINDENT
345static int p_si;
346#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000347static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000348static long p_sts;
349#if defined(FEAT_SEARCHPATH)
350static char_u *p_sua;
351#endif
352static long p_sw;
353static int p_swf;
354#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000355static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000356static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000357#endif
358#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000359static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000360static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000361static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000362#endif
363static long p_ts;
364static long p_tw;
365static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200366#ifdef FEAT_PERSISTENT_UNDO
367static int p_udf;
368#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000369static long p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200370#ifdef FEAT_VARTABS
371static char_u *p_vsts;
372static char_u *p_vts;
373#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000374#ifdef FEAT_KEYMAP
375static char_u *p_keymap;
376#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200377#ifdef FEAT_TERMINAL
Bram Moolenaarb833c1e2018-05-05 16:36:06 +0200378static long p_twsl; /* 'termwinscroll' */
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200379#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000380
381/* Saved values for when 'bin' is set. */
382static int p_et_nobin;
383static int p_ml_nobin;
384static long p_tw_nobin;
385static long p_wm_nobin;
386
387/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200388static int p_ai_nopaste;
389static int p_et_nopaste;
390static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000391static long p_tw_nopaste;
392static long p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200393#ifdef FEAT_VARTABS
394static char_u *p_vsts_nopaste;
395#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000396
397struct vimoption
398{
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200399 char *fullname; // full option name
400 char *shortname; // permissible abbreviation
401 long_u flags; // see below
402 char_u *var; // global option: pointer to variable;
403 // window-local option: VAR_WIN;
404 // buffer-local option: global value
405 idopt_T indir; // global option: PV_NONE;
406 // local option: indirect option index
407 char_u *def_val[2]; // default values for variable (vi and vim)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000408#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200409 sctx_T script_ctx; // script context where the option was last set
Bram Moolenaarded5f1b2018-11-10 17:33:29 +0100410# define SCTX_INIT , {0, 0, 0}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000411#else
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200412# define SCTX_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000413#endif
414};
415
416#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
417#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
418
419/*
420 * Flags
421 */
422#define P_BOOL 0x01 /* the option is boolean */
423#define P_NUM 0x02 /* the option is numeric */
424#define P_STRING 0x04 /* the option is a string */
425#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000426 must use free_string_option() when
427 assigning new value. Not set if default is
428 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000429#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
430 never be used for local or hidden options! */
431#define P_NODEFAULT 0x40 /* don't set to default value */
432#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
433 use vim_free() when assigning new value */
434#define P_WAS_SET 0x100 /* option has been set/reset */
435#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
436#define P_VI_DEF 0x400 /* Use Vi default for Vim */
437#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
438
439 /* when option changed, what to display: */
440#define P_RSTAT 0x1000 /* redraw status lines */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100441#define P_RWIN 0x2000 /* redraw current window and recompute text */
442#define P_RBUF 0x4000 /* redraw current buffer and recompute text */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000443#define P_RALL 0x6000 /* redraw all windows */
444#define P_RCLR 0x7000 /* clear and redraw all */
445
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200446#define P_COMMA 0x8000 /* comma separated list */
447#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
448 * commas */
449#define P_NODUP 0x20000L /* don't allow duplicate strings */
450#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000451
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200452#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
453#define P_GETTEXT 0x100000L /* expand default value with _() */
454#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
455#define P_NFNAME 0x400000L /* only normal file name chars allowed */
456#define P_INSECURE 0x800000L /* option was set from a modeline */
457#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7554da42016-11-25 22:04:13 +0100458 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200459#define P_NO_ML 0x2000000L /* not allowed in modeline */
460#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200461 * there is a redraw flag */
Bram Moolenaar7554da42016-11-25 22:04:13 +0100462#define P_NDNAME 0x8000000L /* only normal dir name chars allowed */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100463#define P_RWINONLY 0x10000000L /* only redraw current window */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000464
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000465#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
466
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000467/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
468 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100469#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000470# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000471#else
472# define ISP_LATIN1 (char_u *)"@,161-255"
473#endif
474
Bram Moolenaar05fbfdc2017-08-14 22:35:08 +0200475# define HIGHLIGHT_INIT "8:SpecialKey,~:EndOfBuffer,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn,q:QuickFixLine,z:StatusLineTerm,Z:StatusLineTermNC"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000476
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +0100477/* Default python version for pyx* commands */
478#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
479# define DEFAULT_PYTHON_VER 0
480#elif defined(FEAT_PYTHON3)
481# define DEFAULT_PYTHON_VER 3
482#elif defined(FEAT_PYTHON)
483# define DEFAULT_PYTHON_VER 2
484#else
485# define DEFAULT_PYTHON_VER 0
486#endif
487
Bram Moolenaarce655742019-01-31 14:12:57 +0100488// used for 'cinkeys' and 'indentkeys'
489#define INDENTKEYS_DEFAULT (char_u *)"0{,0},0),0],:,0#,!^F,o,O,e"
490
Bram Moolenaar071d4272004-06-13 20:20:40 +0000491/*
492 * options[] is initialized here.
493 * The order of the options MUST be alphabetic for ":set all" and findoption().
494 * All option names MUST start with a lowercase letter (for findoption()).
495 * Exception: "t_" options are at the end.
496 * The options with a NULL variable are 'hidden': a set command for them is
497 * ignored and they are not printed.
498 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100499static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000500{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200501 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000502#ifdef FEAT_RIGHTLEFT
503 (char_u *)&p_aleph, PV_NONE,
504#else
505 (char_u *)NULL, PV_NONE,
506#endif
507 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100508#if (defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000509 (char_u *)128L,
510#else
511 (char_u *)224L,
512#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200513 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000514 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
Bram Moolenaard0573012017-10-28 21:11:06 +0200515#if defined(FEAT_GUI_MAC)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000516 (char_u *)&p_antialias, PV_NONE,
517 {(char_u *)FALSE, (char_u *)FALSE}
518#else
519 (char_u *)NULL, PV_NONE,
520 {(char_u *)FALSE, (char_u *)FALSE}
521#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200522 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200523 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000524#ifdef FEAT_ARABIC
525 (char_u *)VAR_WIN, PV_ARAB,
526#else
527 (char_u *)NULL, PV_NONE,
528#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200529 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000530 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
531#ifdef FEAT_ARABIC
532 (char_u *)&p_arshape, PV_NONE,
533#else
534 (char_u *)NULL, PV_NONE,
535#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200536 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000537 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
538#ifdef FEAT_RIGHTLEFT
539 (char_u *)&p_ari, PV_NONE,
540#else
541 (char_u *)NULL, PV_NONE,
542#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200543 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000544 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
545#ifdef FEAT_FKMAP
546 (char_u *)&p_altkeymap, PV_NONE,
547#else
548 (char_u *)NULL, PV_NONE,
549#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200550 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000551 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000552 (char_u *)&p_ambw, PV_NONE,
553 {(char_u *)"single", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200554 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000555 {"autochdir", "acd", P_BOOL|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100556#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000557 (char_u *)&p_acd, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100558 {(char_u *)FALSE, (char_u *)0L}
559#else
560 (char_u *)NULL, PV_NONE,
561 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000562#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200563 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000564 {"autoindent", "ai", P_BOOL|P_VI_DEF,
565 (char_u *)&p_ai, PV_AI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200566 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000567 {"autoprint", "ap", P_BOOL|P_VI_DEF,
568 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200569 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000570 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000571 (char_u *)&p_ar, PV_AR,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200572 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000573 {"autowrite", "aw", P_BOOL|P_VI_DEF,
574 (char_u *)&p_aw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200575 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000576 {"autowriteall","awa", P_BOOL|P_VI_DEF,
577 (char_u *)&p_awa, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200578 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000579 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
580 (char_u *)&p_bg, PV_NONE,
581 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100582#if (defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000583 (char_u *)"dark",
584#else
585 (char_u *)"light",
586#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200587 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200588 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000589 (char_u *)&p_bs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200590 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000591 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
592 (char_u *)&p_bk, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200593 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200594 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200595 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000596#ifdef UNIX
597 {(char_u *)"yes", (char_u *)"auto"}
598#else
599 {(char_u *)"auto", (char_u *)"auto"}
600#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200601 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200602 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
603 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000604 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200605 {(char_u *)DFLT_BDIR, (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000606 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000607 (char_u *)&p_bex, PV_NONE,
608 {
609#ifdef VMS
610 (char_u *)"_",
611#else
612 (char_u *)"~",
613#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200614 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200615 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000616#ifdef FEAT_WILDIGN
617 (char_u *)&p_bsk, PV_NONE,
618 {(char_u *)"", (char_u *)0L}
619#else
620 (char_u *)NULL, PV_NONE,
621 {(char_u *)0L, (char_u *)0L}
622#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200623 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000624 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100625#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000626 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100627 {(char_u *)600L, (char_u *)0L}
628#else
629 (char_u *)NULL, PV_NONE,
630 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000631#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200632 SCTX_INIT},
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100633 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100634#ifdef FEAT_BEVAL_GUI
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100635 (char_u *)&p_beval, PV_NONE,
636 {(char_u *)FALSE, (char_u *)0L}
637#else
638 (char_u *)NULL, PV_NONE,
639 {(char_u *)0L, (char_u *)0L}
640#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200641 SCTX_INIT},
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100642 {"balloonevalterm", "bevalterm",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100643#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100644 (char_u *)&p_bevalterm, PV_NONE,
645 {(char_u *)FALSE, (char_u *)0L}
646#else
647 (char_u *)NULL, PV_NONE,
648 {(char_u *)0L, (char_u *)0L}
649#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200650 SCTX_INIT},
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100651 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
652#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
653 (char_u *)&p_bexpr, PV_BEXPR,
654 {(char_u *)"", (char_u *)0L}
655#else
656 (char_u *)NULL, PV_NONE,
657 {(char_u *)0L, (char_u *)0L}
658#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200659 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000660 {"beautify", "bf", P_BOOL|P_VI_DEF,
661 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200662 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200663 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
664 (char_u *)&p_bo, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200665 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000666 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
667 (char_u *)&p_bin, PV_BIN,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200668 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000669 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000670 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200671 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000672 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000673 (char_u *)&p_bomb, PV_BOMB,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200674 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000675 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
676#ifdef FEAT_LINEBREAK
677 (char_u *)&p_breakat, PV_NONE,
678 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
679#else
680 (char_u *)NULL, PV_NONE,
681 {(char_u *)0L, (char_u *)0L}
682#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200683 SCTX_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200684 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
685#ifdef FEAT_LINEBREAK
686 (char_u *)VAR_WIN, PV_BRI,
687 {(char_u *)FALSE, (char_u *)0L}
688#else
689 (char_u *)NULL, PV_NONE,
690 {(char_u *)0L, (char_u *)0L}
691#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200692 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200693 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
694 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200695#ifdef FEAT_LINEBREAK
696 (char_u *)VAR_WIN, PV_BRIOPT,
697 {(char_u *)"", (char_u *)NULL}
698#else
699 (char_u *)NULL, PV_NONE,
700 {(char_u *)"", (char_u *)NULL}
701#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200702 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000703 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
704#ifdef FEAT_BROWSE
705 (char_u *)&p_bsdir, PV_NONE,
706 {(char_u *)"last", (char_u *)0L}
707#else
708 (char_u *)NULL, PV_NONE,
709 {(char_u *)0L, (char_u *)0L}
710#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200711 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000712 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000713 (char_u *)&p_bh, PV_BH,
714 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200715 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000716 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
717 (char_u *)&p_bl, PV_BL,
718 {(char_u *)1L, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200719 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000720 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000721 (char_u *)&p_bt, PV_BT,
722 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200723 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200724 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000725 (char_u *)&p_cmp, PV_NONE,
726 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200727 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000728 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
729#ifdef FEAT_SEARCHPATH
730 (char_u *)&p_cdpath, PV_NONE,
731 {(char_u *)",,", (char_u *)0L}
732#else
733 (char_u *)NULL, PV_NONE,
734 {(char_u *)0L, (char_u *)0L}
735#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200736 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000737 {"cedit", NULL, P_STRING,
738#ifdef FEAT_CMDWIN
739 (char_u *)&p_cedit, PV_NONE,
740 {(char_u *)"", (char_u *)CTRL_F_STR}
741#else
742 (char_u *)NULL, PV_NONE,
743 {(char_u *)0L, (char_u *)0L}
744#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200745 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000746 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +0100747#if defined(FEAT_EVAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000748 (char_u *)&p_ccv, PV_NONE,
749 {(char_u *)"", (char_u *)0L}
750#else
751 (char_u *)NULL, PV_NONE,
752 {(char_u *)0L, (char_u *)0L}
753#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200754 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000755 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
756#ifdef FEAT_CINDENT
757 (char_u *)&p_cin, PV_CIN,
758#else
759 (char_u *)NULL, PV_NONE,
760#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200761 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200762 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000763#ifdef FEAT_CINDENT
764 (char_u *)&p_cink, PV_CINK,
Bram Moolenaarce655742019-01-31 14:12:57 +0100765 {INDENTKEYS_DEFAULT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000766#else
767 (char_u *)NULL, PV_NONE,
768 {(char_u *)0L, (char_u *)0L}
769#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200770 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200771 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000772#ifdef FEAT_CINDENT
773 (char_u *)&p_cino, PV_CINO,
774#else
775 (char_u *)NULL, PV_NONE,
776#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200777 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200778 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000779#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
780 (char_u *)&p_cinw, PV_CINW,
781 {(char_u *)"if,else,while,do,for,switch",
782 (char_u *)0L}
783#else
784 (char_u *)NULL, PV_NONE,
785 {(char_u *)0L, (char_u *)0L}
786#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200787 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200788 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000789#ifdef FEAT_CLIPBOARD
790 (char_u *)&p_cb, PV_NONE,
791# ifdef FEAT_XCLIPBOARD
792 {(char_u *)"autoselect,exclude:cons\\|linux",
793 (char_u *)0L}
794# else
795 {(char_u *)"", (char_u *)0L}
796# endif
797#else
798 (char_u *)NULL, PV_NONE,
799 {(char_u *)"", (char_u *)0L}
800#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200801 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000802 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
803 (char_u *)&p_ch, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200804 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000805 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
806#ifdef FEAT_CMDWIN
807 (char_u *)&p_cwh, PV_NONE,
808#else
809 (char_u *)NULL, PV_NONE,
810#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200811 {(char_u *)7L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200812 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200813#ifdef FEAT_SYN_HL
814 (char_u *)VAR_WIN, PV_CC,
815#else
816 (char_u *)NULL, PV_NONE,
817#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200818 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000819 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
820 (char_u *)&Columns, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200821 {(char_u *)80L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200822 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
823 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000824#ifdef FEAT_COMMENTS
825 (char_u *)&p_com, PV_COM,
826 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
827 (char_u *)0L}
828#else
829 (char_u *)NULL, PV_NONE,
830 {(char_u *)0L, (char_u *)0L}
831#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200832 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200833 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000834#ifdef FEAT_FOLDING
835 (char_u *)&p_cms, PV_CMS,
836 {(char_u *)"/*%s*/", (char_u *)0L}
837#else
838 (char_u *)NULL, PV_NONE,
839 {(char_u *)0L, (char_u *)0L}
840#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200841 SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000842 /* P_PRI_MKRC isn't needed here, optval_default()
843 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000844 {"compatible", "cp", P_BOOL|P_RALL,
845 (char_u *)&p_cp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200846 {(char_u *)TRUE, (char_u *)FALSE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200847 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000848#ifdef FEAT_INS_EXPAND
849 (char_u *)&p_cpt, PV_CPT,
850 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
851#else
852 (char_u *)NULL, PV_NONE,
853 {(char_u *)0L, (char_u *)0L}
854#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200855 SCTX_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200856 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200857#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200858 (char_u *)VAR_WIN, PV_COCU,
859 {(char_u *)"", (char_u *)NULL}
860#else
861 (char_u *)NULL, PV_NONE,
862 {(char_u *)NULL, (char_u *)0L}
863#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200864 SCTX_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200865 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
866#ifdef FEAT_CONCEAL
867 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200868#else
869 (char_u *)NULL, PV_NONE,
870#endif
871 {(char_u *)0L, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200872 SCTX_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000873 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
874#ifdef FEAT_COMPL_FUNC
875 (char_u *)&p_cfu, PV_CFU,
876 {(char_u *)"", (char_u *)0L}
877#else
878 (char_u *)NULL, PV_NONE,
879 {(char_u *)0L, (char_u *)0L}
880#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200881 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200882 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000883#ifdef FEAT_INS_EXPAND
884 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000885 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000886#else
887 (char_u *)NULL, PV_NONE,
888 {(char_u *)0L, (char_u *)0L}
889#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200890 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000891 {"confirm", "cf", P_BOOL|P_VI_DEF,
892#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
893 (char_u *)&p_confirm, PV_NONE,
894#else
895 (char_u *)NULL, PV_NONE,
896#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200897 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000898 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000899 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200900 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000901 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
902 (char_u *)&p_ci, PV_CI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200903 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000904 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
905 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000906 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200907 SCTX_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200908 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200909#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200910 (char_u *)&p_cm, PV_CM,
Bram Moolenaara86187b2018-12-16 18:20:00 +0100911 {(char_u *)"blowfish2", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200912#else
913 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200914 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200915#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200916 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000917 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
918#ifdef FEAT_CSCOPE
919 (char_u *)&p_cspc, PV_NONE,
920#else
921 (char_u *)NULL, PV_NONE,
922#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200923 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000924 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
925#ifdef FEAT_CSCOPE
926 (char_u *)&p_csprg, PV_NONE,
927 {(char_u *)"cscope", (char_u *)0L}
928#else
929 (char_u *)NULL, PV_NONE,
930 {(char_u *)0L, (char_u *)0L}
931#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200932 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200933 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000934#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
935 (char_u *)&p_csqf, PV_NONE,
936 {(char_u *)"", (char_u *)0L}
937#else
938 (char_u *)NULL, PV_NONE,
939 {(char_u *)0L, (char_u *)0L}
940#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200941 SCTX_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200942 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
943#ifdef FEAT_CSCOPE
944 (char_u *)&p_csre, PV_NONE,
945#else
946 (char_u *)NULL, PV_NONE,
947#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200948 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000949 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
950#ifdef FEAT_CSCOPE
951 (char_u *)&p_cst, PV_NONE,
952#else
953 (char_u *)NULL, PV_NONE,
954#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200955 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000956 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
957#ifdef FEAT_CSCOPE
958 (char_u *)&p_csto, PV_NONE,
959#else
960 (char_u *)NULL, PV_NONE,
961#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200962 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000963 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
964#ifdef FEAT_CSCOPE
965 (char_u *)&p_csverbose, PV_NONE,
966#else
967 (char_u *)NULL, PV_NONE,
968#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200969 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200970 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200971 (char_u *)VAR_WIN, PV_CRBIND,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200972 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar177ab9e2019-01-15 21:12:57 +0100973 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000974#ifdef FEAT_SYN_HL
975 (char_u *)VAR_WIN, PV_CUC,
976#else
977 (char_u *)NULL, PV_NONE,
978#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200979 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100980 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000981#ifdef FEAT_SYN_HL
982 (char_u *)VAR_WIN, PV_CUL,
983#else
984 (char_u *)NULL, PV_NONE,
985#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200986 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000987 {"debug", NULL, P_STRING|P_VI_DEF,
988 (char_u *)&p_debug, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200989 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200990 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000991#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000992 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000993 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000994#else
995 (char_u *)NULL, PV_NONE,
996 {(char_u *)NULL, (char_u *)0L}
997#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200998 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000999 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001000 (char_u *)&p_deco, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001001 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001002 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001003#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001004 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001005#else
1006 (char_u *)NULL, PV_NONE,
1007#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001008 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001009 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1010#ifdef FEAT_DIFF
1011 (char_u *)VAR_WIN, PV_DIFF,
1012#else
1013 (char_u *)NULL, PV_NONE,
1014#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001015 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001016 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001017#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1018 (char_u *)&p_dex, PV_NONE,
1019 {(char_u *)"", (char_u *)0L}
1020#else
1021 (char_u *)NULL, PV_NONE,
1022 {(char_u *)0L, (char_u *)0L}
1023#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001024 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001025 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1026 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001027#ifdef FEAT_DIFF
1028 (char_u *)&p_dip, PV_NONE,
Bram Moolenaarc93262b2018-09-10 21:15:40 +02001029 {(char_u *)"internal,filler", (char_u *)NULL}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001030#else
1031 (char_u *)NULL, PV_NONE,
1032 {(char_u *)"", (char_u *)NULL}
1033#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001034 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001035 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1036#ifdef FEAT_DIGRAPHS
1037 (char_u *)&p_dg, PV_NONE,
1038#else
1039 (char_u *)NULL, PV_NONE,
1040#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001041 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001042 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1043 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001044 (char_u *)&p_dir, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001045 {(char_u *)DFLT_DIR, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001046 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001047 (char_u *)&p_dy, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001048 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001049 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001050 (char_u *)&p_ead, PV_NONE,
1051 {(char_u *)"both", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001052 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001053 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1054 (char_u *)&p_ed, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001055 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001056 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaar3848e002016-03-19 18:42:29 +01001057 (char_u *)&p_emoji, PV_NONE,
1058 {(char_u *)TRUE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001059 SCTX_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001060 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001061 (char_u *)&p_enc, PV_NONE,
1062 {(char_u *)ENC_DFLT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001063 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001064 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1065 (char_u *)&p_eol, PV_EOL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001066 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001067 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1068 (char_u *)&p_ea, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001069 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001070 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001071 (char_u *)&p_ep, PV_EP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001072 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001073 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1074 (char_u *)&p_eb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001075 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001076 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1077#ifdef FEAT_QUICKFIX
1078 (char_u *)&p_ef, PV_NONE,
1079 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1080#else
1081 (char_u *)NULL, PV_NONE,
1082 {(char_u *)NULL, (char_u *)0L}
1083#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001084 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001085 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001086#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001087 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001088 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001089#else
1090 (char_u *)NULL, PV_NONE,
1091 {(char_u *)NULL, (char_u *)0L}
1092#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001093 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001094 {"esckeys", "ek", P_BOOL|P_VIM,
1095 (char_u *)&p_ek, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001096 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001097 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001098 (char_u *)&p_ei, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001099 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001100 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1101 (char_u *)&p_et, PV_ET,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001102 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001103 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1104 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001105 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001106 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1107 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001108 (char_u *)&p_fenc, PV_FENC,
1109 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001110 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001111 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001112 (char_u *)&p_fencs, PV_NONE,
1113 {(char_u *)"ucs-bom", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001114 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001115 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1116 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001117 (char_u *)&p_ff, PV_FF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001118 {(char_u *)DFLT_FF, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001119 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001120 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001121 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001122 SCTX_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001123 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1124 (char_u *)&p_fic, PV_NONE,
1125 {
1126#ifdef CASE_INSENSITIVE_FILENAME
1127 (char_u *)TRUE,
1128#else
1129 (char_u *)FALSE,
1130#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001131 (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001132 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001133 (char_u *)&p_ft, PV_FT,
1134 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001135 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001136 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001137 (char_u *)&p_fcs, PV_NONE,
1138 {(char_u *)"vert:|,fold:-", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001139 SCTX_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001140 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1141 (char_u *)&p_fixeol, PV_FIXEOL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001142 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001143 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1144#ifdef FEAT_FKMAP
1145 (char_u *)&p_fkmap, PV_NONE,
1146#else
1147 (char_u *)NULL, PV_NONE,
1148#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001149 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001150 {"flash", "fl", P_BOOL|P_VI_DEF,
1151 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001152 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001153 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001154#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001155 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001156 {(char_u *)"", (char_u *)0L}
1157#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001158 (char_u *)NULL, PV_NONE,
1159 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001160#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001161 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001162 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1163#ifdef FEAT_FOLDING
1164 (char_u *)VAR_WIN, PV_FDC,
1165 {(char_u *)FALSE, (char_u *)0L}
1166#else
1167 (char_u *)NULL, PV_NONE,
1168 {(char_u *)NULL, (char_u *)0L}
1169#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001170 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001171 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1172#ifdef FEAT_FOLDING
1173 (char_u *)VAR_WIN, PV_FEN,
1174 {(char_u *)TRUE, (char_u *)0L}
1175#else
1176 (char_u *)NULL, PV_NONE,
1177 {(char_u *)NULL, (char_u *)0L}
1178#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001179 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001180 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1181#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1182 (char_u *)VAR_WIN, PV_FDE,
1183 {(char_u *)"0", (char_u *)NULL}
1184#else
1185 (char_u *)NULL, PV_NONE,
1186 {(char_u *)NULL, (char_u *)0L}
1187#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001188 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001189 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001190#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001191 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001192 {(char_u *)"#", (char_u *)NULL}
1193#else
1194 (char_u *)NULL, PV_NONE,
1195 {(char_u *)NULL, (char_u *)0L}
1196#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001197 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001198 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001199#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001200 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001201 {(char_u *)0L, (char_u *)0L}
1202#else
1203 (char_u *)NULL, PV_NONE,
1204 {(char_u *)NULL, (char_u *)0L}
1205#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001206 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001207 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001208#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001209 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001210 {(char_u *)-1L, (char_u *)0L}
1211#else
1212 (char_u *)NULL, PV_NONE,
1213 {(char_u *)NULL, (char_u *)0L}
1214#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001215 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001216 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001217 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001218#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001219 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001220 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001221#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001222 (char_u *)NULL, PV_NONE,
1223 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001224#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001225 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001226 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1227#ifdef FEAT_FOLDING
1228 (char_u *)VAR_WIN, PV_FDM,
1229 {(char_u *)"manual", (char_u *)NULL}
1230#else
1231 (char_u *)NULL, PV_NONE,
1232 {(char_u *)NULL, (char_u *)0L}
1233#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001234 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001235 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1236#ifdef FEAT_FOLDING
1237 (char_u *)VAR_WIN, PV_FML,
1238 {(char_u *)1L, (char_u *)0L}
1239#else
1240 (char_u *)NULL, PV_NONE,
1241 {(char_u *)NULL, (char_u *)0L}
1242#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001243 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001244 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1245#ifdef FEAT_FOLDING
1246 (char_u *)VAR_WIN, PV_FDN,
1247 {(char_u *)20L, (char_u *)0L}
1248#else
1249 (char_u *)NULL, PV_NONE,
1250 {(char_u *)NULL, (char_u *)0L}
1251#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001252 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001253 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1254#ifdef FEAT_FOLDING
1255 (char_u *)&p_fdo, PV_NONE,
1256 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1257 (char_u *)0L}
1258#else
1259 (char_u *)NULL, PV_NONE,
1260 {(char_u *)NULL, (char_u *)0L}
1261#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001262 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001263 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1264#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1265 (char_u *)VAR_WIN, PV_FDT,
1266 {(char_u *)"foldtext()", (char_u *)NULL}
1267#else
1268 (char_u *)NULL, PV_NONE,
1269 {(char_u *)NULL, (char_u *)0L}
1270#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001271 SCTX_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001272 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001273#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001274 (char_u *)&p_fex, PV_FEX,
1275 {(char_u *)"", (char_u *)0L}
1276#else
1277 (char_u *)NULL, PV_NONE,
1278 {(char_u *)0L, (char_u *)0L}
1279#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001280 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001281 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1282 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001283 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001284 SCTX_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001285 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1286 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001287 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001288 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001289 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001290 (char_u *)&p_fp, PV_FP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001291 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001292 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1293#ifdef HAVE_FSYNC
1294 (char_u *)&p_fs, PV_NONE,
1295 {(char_u *)TRUE, (char_u *)0L}
1296#else
1297 (char_u *)NULL, PV_NONE,
1298 {(char_u *)FALSE, (char_u *)0L}
1299#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001300 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001301 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1302 (char_u *)&p_gd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001303 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001304 {"graphic", "gr", P_BOOL|P_VI_DEF,
1305 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001306 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001307 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001308#ifdef FEAT_QUICKFIX
1309 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001310 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001311#else
1312 (char_u *)NULL, PV_NONE,
1313 {(char_u *)NULL, (char_u *)0L}
1314#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001315 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001316 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1317#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001318 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001319 {
1320# ifdef WIN3264
1321 /* may be changed to "grep -n" in os_win32.c */
1322 (char_u *)"findstr /n",
1323# else
1324# ifdef UNIX
1325 /* Add an extra file name so that grep will always
1326 * insert a file name in the match line. */
1327 (char_u *)"grep -n $* /dev/null",
1328# else
1329# ifdef VMS
1330 (char_u *)"SEARCH/NUMBERS ",
1331# else
1332 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001333# endif
1334# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001335# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001336 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001337#else
1338 (char_u *)NULL, PV_NONE,
1339 {(char_u *)NULL, (char_u *)0L}
1340#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001341 SCTX_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001342 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001343#ifdef CURSOR_SHAPE
1344 (char_u *)&p_guicursor, PV_NONE,
1345 {
1346# ifdef FEAT_GUI
1347 (char_u *)"n-v-c:block-Cursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001348# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001349 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1350# endif
1351 (char_u *)0L}
1352#else
1353 (char_u *)NULL, PV_NONE,
1354 {(char_u *)NULL, (char_u *)0L}
1355#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001356 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001357 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001358#ifdef FEAT_GUI
1359 (char_u *)&p_guifont, PV_NONE,
1360 {(char_u *)"", (char_u *)0L}
1361#else
1362 (char_u *)NULL, PV_NONE,
1363 {(char_u *)NULL, (char_u *)0L}
1364#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001365 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001366 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001367#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1368 (char_u *)&p_guifontset, PV_NONE,
1369 {(char_u *)"", (char_u *)0L}
1370#else
1371 (char_u *)NULL, PV_NONE,
1372 {(char_u *)NULL, (char_u *)0L}
1373#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001374 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001375 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001376#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001377 (char_u *)&p_guifontwide, PV_NONE,
1378 {(char_u *)"", (char_u *)0L}
1379#else
1380 (char_u *)NULL, PV_NONE,
1381 {(char_u *)NULL, (char_u *)0L}
1382#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001383 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001384 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001385#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001386 (char_u *)&p_ghr, PV_NONE,
1387#else
1388 (char_u *)NULL, PV_NONE,
1389#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001390 {(char_u *)50L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001391 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001392#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001393 (char_u *)&p_go, PV_NONE,
Bram Moolenaard0573012017-10-28 21:11:06 +02001394# if defined(UNIX) && !defined(FEAT_GUI_MAC)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001395 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001396# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001397 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001398# endif
1399#else
1400 (char_u *)NULL, PV_NONE,
1401 {(char_u *)NULL, (char_u *)0L}
1402#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001403 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001404 {"guipty", NULL, P_BOOL|P_VI_DEF,
1405#if defined(FEAT_GUI)
1406 (char_u *)&p_guipty, PV_NONE,
1407#else
1408 (char_u *)NULL, PV_NONE,
1409#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001410 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001411 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001412#if defined(FEAT_GUI_TABLINE)
1413 (char_u *)&p_gtl, PV_NONE,
1414 {(char_u *)"", (char_u *)0L}
1415#else
1416 (char_u *)NULL, PV_NONE,
1417 {(char_u *)NULL, (char_u *)0L}
1418#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001419 SCTX_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001420 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001421#if defined(FEAT_GUI_TABLINE)
1422 (char_u *)&p_gtt, PV_NONE,
1423 {(char_u *)"", (char_u *)0L}
1424#else
1425 (char_u *)NULL, PV_NONE,
1426 {(char_u *)NULL, (char_u *)0L}
1427#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001428 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001429 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1430 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001431 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001432 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1433 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001434 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001435 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001436 {"helpheight", "hh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001437 (char_u *)&p_hh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001438 {(char_u *)20L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001439 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001440#ifdef FEAT_MULTI_LANG
1441 (char_u *)&p_hlg, PV_NONE,
1442 {(char_u *)"", (char_u *)0L}
1443#else
1444 (char_u *)NULL, PV_NONE,
1445 {(char_u *)0L, (char_u *)0L}
1446#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001447 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001448 {"hidden", "hid", P_BOOL|P_VI_DEF,
1449 (char_u *)&p_hid, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001450 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001451 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001452 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001453 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001454 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001455 {"history", "hi", P_NUM|P_VIM,
1456 (char_u *)&p_hi, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001457 {(char_u *)0L, (char_u *)50L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001458 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1459#ifdef FEAT_RIGHTLEFT
1460 (char_u *)&p_hkmap, PV_NONE,
1461#else
1462 (char_u *)NULL, PV_NONE,
1463#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001464 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001465 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1466#ifdef FEAT_RIGHTLEFT
1467 (char_u *)&p_hkmapp, PV_NONE,
1468#else
1469 (char_u *)NULL, PV_NONE,
1470#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001471 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001472 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1473 (char_u *)&p_hls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001474 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001475 {"icon", NULL, P_BOOL|P_VI_DEF,
1476#ifdef FEAT_TITLE
1477 (char_u *)&p_icon, PV_NONE,
1478#else
1479 (char_u *)NULL, PV_NONE,
1480#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001481 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001482 {"iconstring", NULL, P_STRING|P_VI_DEF,
1483#ifdef FEAT_TITLE
1484 (char_u *)&p_iconstring, PV_NONE,
1485#else
1486 (char_u *)NULL, PV_NONE,
1487#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001488 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001489 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1490 (char_u *)&p_ic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001491 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001492 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001493#if defined(FEAT_EVAL)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001494 (char_u *)&p_imaf, PV_NONE,
1495 {(char_u *)"", (char_u *)NULL}
1496# else
1497 (char_u *)NULL, PV_NONE,
1498 {(char_u *)NULL, (char_u *)0L}
1499# endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001500 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001501 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001502#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001503 (char_u *)&p_imak, PV_NONE,
1504#else
1505 (char_u *)NULL, PV_NONE,
1506#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001507 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001508 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001509 (char_u *)&p_imcmdline, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001510 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001511 {"imdisable", "imd", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001512 (char_u *)&p_imdisable, PV_NONE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001513#ifdef __sgi
1514 {(char_u *)TRUE, (char_u *)0L}
1515#else
1516 {(char_u *)FALSE, (char_u *)0L}
1517#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001518 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001519 {"iminsert", "imi", P_NUM|P_VI_DEF,
1520 (char_u *)&p_iminsert, PV_IMI,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001521 {(char_u *)B_IMODE_NONE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001522 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001523 {"imsearch", "ims", P_NUM|P_VI_DEF,
1524 (char_u *)&p_imsearch, PV_IMS,
Bram Moolenaar4cf56bb2017-09-16 15:50:32 +02001525 {(char_u *)B_IMODE_USE_INSERT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001526 SCTX_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001527 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001528#if defined(FEAT_EVAL)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001529 (char_u *)&p_imsf, PV_NONE,
1530 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001531#else
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001532 (char_u *)NULL, PV_NONE,
1533 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001534#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001535 SCTX_INIT},
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001536 {"imstyle", "imst", P_NUM|P_VI_DEF|P_SECURE,
1537#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1538 (char_u *)&p_imst, PV_NONE,
1539 {(char_u *)IM_OVER_THE_SPOT, (char_u *)0L}
1540#else
1541 (char_u *)NULL, PV_NONE,
1542 {(char_u *)0L, (char_u *)0L}
1543#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001544 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001545 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1546#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001547 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001548 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1549#else
1550 (char_u *)NULL, PV_NONE,
1551 {(char_u *)0L, (char_u *)0L}
1552#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001553 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001554 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1555#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1556 (char_u *)&p_inex, PV_INEX,
1557 {(char_u *)"", (char_u *)0L}
1558#else
1559 (char_u *)NULL, PV_NONE,
1560 {(char_u *)0L, (char_u *)0L}
1561#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001562 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001563 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1564 (char_u *)&p_is, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001565 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001566 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1567#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1568 (char_u *)&p_inde, PV_INDE,
1569 {(char_u *)"", (char_u *)0L}
1570#else
1571 (char_u *)NULL, PV_NONE,
1572 {(char_u *)0L, (char_u *)0L}
1573#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001574 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001575 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001576#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1577 (char_u *)&p_indk, PV_INDK,
Bram Moolenaarce655742019-01-31 14:12:57 +01001578 {INDENTKEYS_DEFAULT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001579#else
1580 (char_u *)NULL, PV_NONE,
1581 {(char_u *)0L, (char_u *)0L}
1582#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001583 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001584 {"infercase", "inf", P_BOOL|P_VI_DEF,
1585 (char_u *)&p_inf, PV_INF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001586 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001587 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1588 (char_u *)&p_im, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001589 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001590 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1591 (char_u *)&p_isf, PV_NONE,
1592 {
1593#ifdef BACKSLASH_IN_FILENAME
1594 /* Excluded are: & and ^ are special in cmd.exe
1595 * ( and ) are used in text separating fnames */
1596 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1597#else
1598# ifdef AMIGA
1599 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1600# else
1601# ifdef VMS
1602 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1603# else /* UNIX et al. */
1604# ifdef EBCDIC
1605 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1606# else
1607 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1608# endif
1609# endif
1610# endif
1611#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001612 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001613 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1614 (char_u *)&p_isi, PV_NONE,
1615 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001616#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001617 (char_u *)"@,48-57,_,128-167,224-235",
1618#else
1619# ifdef EBCDIC
1620 /* TODO: EBCDIC Check this! @ == isalpha()*/
1621 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1622 "112-120,128,140-142,156,158,172,"
1623 "174,186,191,203-207,219-225,235-239,"
1624 "251-254",
1625# else
1626 (char_u *)"@,48-57,_,192-255",
1627# endif
1628#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001629 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001630 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1631 (char_u *)&p_isk, PV_ISK,
1632 {
1633#ifdef EBCDIC
1634 (char_u *)"@,240-249,_",
1635 /* TODO: EBCDIC Check this! @ == isalpha()*/
1636 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1637 "112-120,128,140-142,156,158,172,"
1638 "174,186,191,203-207,219-225,235-239,"
1639 "251-254",
1640#else
1641 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001642# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001643 (char_u *)"@,48-57,_,128-167,224-235"
1644# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001645 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001646# endif
1647#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001648 } SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001649 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1650 (char_u *)&p_isp, PV_NONE,
1651 {
Bram Moolenaard0573012017-10-28 21:11:06 +02001652#if defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001653 (char_u *)"@,~-255",
1654#else
1655# ifdef EBCDIC
1656 /* all chars above 63 are printable */
1657 (char_u *)"63-255",
1658# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001659 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001660# endif
1661#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001662 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001663 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1664 (char_u *)&p_js, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001665 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001666 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1667#ifdef FEAT_CRYPT
1668 (char_u *)&p_key, PV_KEY,
1669 {(char_u *)"", (char_u *)0L}
1670#else
1671 (char_u *)NULL, PV_NONE,
1672 {(char_u *)0L, (char_u *)0L}
1673#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001674 SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001675 {"keymap", "kmp", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_RSTAT|P_NFNAME|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001676#ifdef FEAT_KEYMAP
1677 (char_u *)&p_keymap, PV_KMAP,
1678 {(char_u *)"", (char_u *)0L}
1679#else
1680 (char_u *)NULL, PV_NONE,
1681 {(char_u *)"", (char_u *)0L}
1682#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001683 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001684 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001685 (char_u *)&p_km, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001686 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001687 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001688 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001689 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001690#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001691 (char_u *)":help",
1692#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001693# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001694 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001695# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001696# ifdef USEMAN_S
1697 (char_u *)"man -s",
1698# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001699 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001700# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001701# endif
1702#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001703 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001704 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001705#ifdef FEAT_LANGMAP
1706 (char_u *)&p_langmap, PV_NONE,
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001707 {(char_u *)"", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001708#else
1709 (char_u *)NULL, PV_NONE,
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001710 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001711#endif
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001712 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001713 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001714#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1715 (char_u *)&p_lm, PV_NONE,
1716#else
1717 (char_u *)NULL, PV_NONE,
1718#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001719 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001720 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1721#ifdef FEAT_LANGMAP
1722 (char_u *)&p_lnr, PV_NONE,
1723#else
1724 (char_u *)NULL, PV_NONE,
1725#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001726 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001727 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1728#ifdef FEAT_LANGMAP
1729 (char_u *)&p_lrm, PV_NONE,
1730#else
1731 (char_u *)NULL, PV_NONE,
1732#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001733 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001734 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001735 (char_u *)&p_ls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001736 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001737 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1738 (char_u *)&p_lz, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001739 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001740 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1741#ifdef FEAT_LINEBREAK
1742 (char_u *)VAR_WIN, PV_LBR,
1743#else
1744 (char_u *)NULL, PV_NONE,
1745#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001746 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001747 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1748 (char_u *)&Rows, PV_NONE,
1749 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001750#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001751 (char_u *)25L,
1752#else
1753 (char_u *)24L,
1754#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001755 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001756 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1757#ifdef FEAT_GUI
1758 (char_u *)&p_linespace, PV_NONE,
1759#else
1760 (char_u *)NULL, PV_NONE,
1761#endif
1762#ifdef FEAT_GUI_W32
1763 {(char_u *)1L, (char_u *)0L}
1764#else
1765 {(char_u *)0L, (char_u *)0L}
1766#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001767 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001768 {"lisp", NULL, P_BOOL|P_VI_DEF,
1769#ifdef FEAT_LISP
1770 (char_u *)&p_lisp, PV_LISP,
1771#else
1772 (char_u *)NULL, PV_NONE,
1773#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001774 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001775 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001776#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001777 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001778 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1779#else
1780 (char_u *)NULL, PV_NONE,
1781 {(char_u *)"", (char_u *)0L}
1782#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001783 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001784 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1785 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001786 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001787 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001788 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001789 {(char_u *)"eol:$", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001790 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1791 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001792 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001793 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001794#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001795 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001796 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001797#else
1798 (char_u *)NULL, PV_NONE,
1799 {(char_u *)"", (char_u *)0L}
1800#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001801 SCTX_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001802 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001803#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001804 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001805 {(char_u *)TRUE, (char_u *)0L}
1806#else
1807 (char_u *)NULL, PV_NONE,
1808 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001809#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001810 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001811 {"magic", NULL, P_BOOL|P_VI_DEF,
1812 (char_u *)&p_magic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001813 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001814 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001815#ifdef FEAT_QUICKFIX
1816 (char_u *)&p_mef, PV_NONE,
1817 {(char_u *)"", (char_u *)0L}
1818#else
1819 (char_u *)NULL, PV_NONE,
1820 {(char_u *)NULL, (char_u *)0L}
1821#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001822 SCTX_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001823 {"makeencoding","menc", P_STRING|P_VI_DEF,
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001824 (char_u *)&p_menc, PV_MENC,
1825 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001826 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001827 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1828#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001829 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001830# ifdef VMS
1831 {(char_u *)"MMS", (char_u *)0L}
1832# else
1833 {(char_u *)"make", (char_u *)0L}
1834# endif
1835#else
1836 (char_u *)NULL, PV_NONE,
1837 {(char_u *)NULL, (char_u *)0L}
1838#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001839 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001840 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001841 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001842 {(char_u *)"(:),{:},[:]", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001843 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001844 {"matchtime", "mat", P_NUM|P_VI_DEF,
1845 (char_u *)&p_mat, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001846 {(char_u *)5L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001847 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001848 (char_u *)&p_mco, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001849 {(char_u *)2, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001850 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1851#ifdef FEAT_EVAL
1852 (char_u *)&p_mfd, PV_NONE,
1853#else
1854 (char_u *)NULL, PV_NONE,
1855#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001856 {(char_u *)100L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001857 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1858 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001859 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001860 {"maxmem", "mm", P_NUM|P_VI_DEF,
1861 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001862 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001863 SCTX_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001864 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1865 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001866 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001867 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1868 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001869 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001870 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001871 {"menuitems", "mis", P_NUM|P_VI_DEF,
1872#ifdef FEAT_MENU
1873 (char_u *)&p_mis, PV_NONE,
1874#else
1875 (char_u *)NULL, PV_NONE,
1876#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001877 {(char_u *)25L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001878 {"mesg", NULL, P_BOOL|P_VI_DEF,
1879 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001880 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001881 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001882#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001883 (char_u *)&p_msm, PV_NONE,
1884 {(char_u *)"460000,2000,500", (char_u *)0L}
1885#else
1886 (char_u *)NULL, PV_NONE,
1887 {(char_u *)0L, (char_u *)0L}
1888#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001889 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001890 {"modeline", "ml", P_BOOL|P_VIM,
1891 (char_u *)&p_ml, PV_ML,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001892 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001893 {"modelines", "mls", P_NUM|P_VI_DEF,
1894 (char_u *)&p_mls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001895 {(char_u *)5L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001896 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1897 (char_u *)&p_ma, PV_MA,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001898 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001899 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1900 (char_u *)&p_mod, PV_MOD,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001901 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001902 {"more", NULL, P_BOOL|P_VIM,
1903 (char_u *)&p_more, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001904 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001905 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1906 (char_u *)&p_mouse, PV_NONE,
1907 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001908#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001909 (char_u *)"a",
1910#else
1911 (char_u *)"",
1912#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001913 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001914 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1915#ifdef FEAT_GUI
1916 (char_u *)&p_mousef, PV_NONE,
1917#else
1918 (char_u *)NULL, PV_NONE,
1919#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001920 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001921 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1922#ifdef FEAT_GUI
1923 (char_u *)&p_mh, PV_NONE,
1924#else
1925 (char_u *)NULL, PV_NONE,
1926#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001927 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001928 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1929 (char_u *)&p_mousem, PV_NONE,
1930 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001931#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001932 (char_u *)"popup",
1933#else
Bram Moolenaard0573012017-10-28 21:11:06 +02001934# if defined(MACOS_X)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001935 (char_u *)"popup_setpos",
1936# else
1937 (char_u *)"extend",
1938# endif
1939#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001940 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001941 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001942#ifdef FEAT_MOUSESHAPE
1943 (char_u *)&p_mouseshape, PV_NONE,
1944 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1945#else
1946 (char_u *)NULL, PV_NONE,
1947 {(char_u *)NULL, (char_u *)0L}
1948#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001949 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001950 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1951 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001952 {(char_u *)500L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02001953 {"mzschemedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1954#if defined(DYNAMIC_MZSCHEME)
1955 (char_u *)&p_mzschemedll, PV_NONE,
1956 {(char_u *)DYNAMIC_MZSCH_DLL, (char_u *)0L}
1957#else
1958 (char_u *)NULL, PV_NONE,
1959 {(char_u *)"", (char_u *)0L}
1960#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001961 SCTX_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02001962 {"mzschemegcdll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1963#if defined(DYNAMIC_MZSCHEME)
1964 (char_u *)&p_mzschemegcdll, PV_NONE,
1965 {(char_u *)DYNAMIC_MZGC_DLL, (char_u *)0L}
1966#else
1967 (char_u *)NULL, PV_NONE,
1968 {(char_u *)"", (char_u *)0L}
1969#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001970 SCTX_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001971 {"mzquantum", "mzq", P_NUM,
1972#ifdef FEAT_MZSCHEME
1973 (char_u *)&p_mzq, PV_NONE,
1974#else
1975 (char_u *)NULL, PV_NONE,
1976#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001977 {(char_u *)100L, (char_u *)100L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001978 {"novice", NULL, P_BOOL|P_VI_DEF,
1979 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001980 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001981 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001982 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01001983 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001984 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001985 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1986 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001987 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001988 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1989#ifdef FEAT_LINEBREAK
1990 (char_u *)VAR_WIN, PV_NUW,
1991#else
1992 (char_u *)NULL, PV_NONE,
1993#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001994 {(char_u *)8L, (char_u *)4L} SCTX_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001995 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001996#ifdef FEAT_COMPL_FUNC
1997 (char_u *)&p_ofu, PV_OFU,
1998 {(char_u *)"", (char_u *)0L}
1999#else
2000 (char_u *)NULL, PV_NONE,
2001 {(char_u *)0L, (char_u *)0L}
2002#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002003 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002004 {"open", NULL, P_BOOL|P_VI_DEF,
2005 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002006 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002007 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002008#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002009 (char_u *)&p_odev, PV_NONE,
2010#else
2011 (char_u *)NULL, PV_NONE,
2012#endif
2013 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002014 SCTX_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002015 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2016 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002017 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002018 {"optimize", "opt", P_BOOL|P_VI_DEF,
2019 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002020 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002021 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002022 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002023 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002024 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2025 |P_SECURE,
2026 (char_u *)&p_pp, PV_NONE,
2027 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002028 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002029 {"paragraphs", "para", P_STRING|P_VI_DEF,
2030 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002031 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002032 (char_u *)0L} SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002033 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002034 (char_u *)&p_paste, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002035 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002036 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2037 (char_u *)&p_pt, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002038 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002039 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2040#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2041 (char_u *)&p_pex, PV_NONE,
2042 {(char_u *)"", (char_u *)0L}
2043#else
2044 (char_u *)NULL, PV_NONE,
2045 {(char_u *)0L, (char_u *)0L}
2046#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002047 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002048 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002049 (char_u *)&p_pm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002050 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002051 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002052 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002053 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002054#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002055 (char_u *)".,,",
2056#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002057 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002058#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002059 (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002060 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002061#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002062 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002063 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002064#else
2065 (char_u *)NULL, PV_NONE,
2066 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002067#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002068 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002069 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2070 (char_u *)&p_pi, PV_PI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002071 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002072 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002073#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002074 (char_u *)&p_pvh, PV_NONE,
2075#else
2076 (char_u *)NULL, PV_NONE,
2077#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002078 {(char_u *)12L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002079 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002080#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002081 (char_u *)VAR_WIN, PV_PVW,
2082#else
2083 (char_u *)NULL, PV_NONE,
2084#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002085 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002086 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002087#ifdef FEAT_PRINTER
2088 (char_u *)&p_pdev, PV_NONE,
2089 {(char_u *)"", (char_u *)0L}
2090#else
2091 (char_u *)NULL, PV_NONE,
2092 {(char_u *)NULL, (char_u *)0L}
2093#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002094 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002095 {"printencoding", "penc", P_STRING|P_VI_DEF,
2096#ifdef FEAT_POSTSCRIPT
2097 (char_u *)&p_penc, PV_NONE,
2098 {(char_u *)"", (char_u *)0L}
2099#else
2100 (char_u *)NULL, PV_NONE,
2101 {(char_u *)NULL, (char_u *)0L}
2102#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002103 SCTX_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002104 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002105#ifdef FEAT_POSTSCRIPT
2106 (char_u *)&p_pexpr, PV_NONE,
2107 {(char_u *)"", (char_u *)0L}
2108#else
2109 (char_u *)NULL, PV_NONE,
2110 {(char_u *)NULL, (char_u *)0L}
2111#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002112 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002113 {"printfont", "pfn", P_STRING|P_VI_DEF,
2114#ifdef FEAT_PRINTER
2115 (char_u *)&p_pfn, PV_NONE,
2116 {
2117# ifdef MSWIN
2118 (char_u *)"Courier_New:h10",
2119# else
2120 (char_u *)"courier",
2121# endif
2122 (char_u *)0L}
2123#else
2124 (char_u *)NULL, PV_NONE,
2125 {(char_u *)NULL, (char_u *)0L}
2126#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002127 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002128 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2129#ifdef FEAT_PRINTER
2130 (char_u *)&p_header, PV_NONE,
Bram Moolenaar0903d562017-08-26 22:30:15 +02002131 /* untranslated to avoid problems when 'encoding'
2132 * is changed */
2133 {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002134#else
2135 (char_u *)NULL, PV_NONE,
2136 {(char_u *)NULL, (char_u *)0L}
2137#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002138 SCTX_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002139 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01002140#if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002141 (char_u *)&p_pmcs, PV_NONE,
2142 {(char_u *)"", (char_u *)0L}
2143#else
2144 (char_u *)NULL, PV_NONE,
2145 {(char_u *)NULL, (char_u *)0L}
2146#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002147 SCTX_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002148 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01002149#if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002150 (char_u *)&p_pmfn, PV_NONE,
2151 {(char_u *)"", (char_u *)0L}
2152#else
2153 (char_u *)NULL, PV_NONE,
2154 {(char_u *)NULL, (char_u *)0L}
2155#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002156 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002157 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002158#ifdef FEAT_PRINTER
2159 (char_u *)&p_popt, PV_NONE,
2160 {(char_u *)"", (char_u *)0L}
2161#else
2162 (char_u *)NULL, PV_NONE,
2163 {(char_u *)NULL, (char_u *)0L}
2164#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002165 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002166 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002167 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002168 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002169 {"pumheight", "ph", P_NUM|P_VI_DEF,
2170#ifdef FEAT_INS_EXPAND
2171 (char_u *)&p_ph, PV_NONE,
2172#else
2173 (char_u *)NULL, PV_NONE,
2174#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002175 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaara8f04aa2018-02-10 15:36:55 +01002176 {"pumwidth", "pw", P_NUM|P_VI_DEF,
2177#ifdef FEAT_INS_EXPAND
2178 (char_u *)&p_pw, PV_NONE,
2179#else
2180 (char_u *)NULL, PV_NONE,
2181#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002182 {(char_u *)15L, (char_u *)15L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002183 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002184#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002185 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002186 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002187#else
2188 (char_u *)NULL, PV_NONE,
2189 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002190#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002191 SCTX_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002192 {"pythonthreehome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2193#if defined(FEAT_PYTHON3)
2194 (char_u *)&p_py3home, PV_NONE,
2195 {(char_u *)"", (char_u *)0L}
2196#else
2197 (char_u *)NULL, PV_NONE,
2198 {(char_u *)NULL, (char_u *)0L}
2199#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002200 SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002201 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002202#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002203 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002204 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002205#else
2206 (char_u *)NULL, PV_NONE,
2207 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002208#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002209 SCTX_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002210 {"pythonhome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2211#if defined(FEAT_PYTHON)
2212 (char_u *)&p_pyhome, PV_NONE,
2213 {(char_u *)"", (char_u *)0L}
2214#else
2215 (char_u *)NULL, PV_NONE,
2216 {(char_u *)NULL, (char_u *)0L}
2217#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002218 SCTX_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002219 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2220#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2221 (char_u *)&p_pyx, PV_NONE,
2222#else
2223 (char_u *)NULL, PV_NONE,
2224#endif
2225 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002226 SCTX_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002227 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2228#ifdef FEAT_TEXTOBJ
2229 (char_u *)&p_qe, PV_QE,
2230 {(char_u *)"\\", (char_u *)0L}
2231#else
2232 (char_u *)NULL, PV_NONE,
2233 {(char_u *)NULL, (char_u *)0L}
2234#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002235 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002236 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2237 (char_u *)&p_ro, PV_RO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002238 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002239 {"redraw", NULL, P_BOOL|P_VI_DEF,
2240 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002241 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002242 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2243#ifdef FEAT_RELTIME
2244 (char_u *)&p_rdt, PV_NONE,
2245#else
2246 (char_u *)NULL, PV_NONE,
2247#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002248 {(char_u *)2000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002249 {"regexpengine", "re", P_NUM|P_VI_DEF,
2250 (char_u *)&p_re, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002251 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002252 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2253 (char_u *)VAR_WIN, PV_RNU,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002254 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002255 {"remap", NULL, P_BOOL|P_VI_DEF,
2256 (char_u *)&p_remap, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002257 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002258 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002259#ifdef FEAT_RENDER_OPTIONS
2260 (char_u *)&p_rop, PV_NONE,
2261 {(char_u *)"", (char_u *)0L}
2262#else
2263 (char_u *)NULL, PV_NONE,
2264 {(char_u *)NULL, (char_u *)0L}
2265#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002266 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002267 {"report", NULL, P_NUM|P_VI_DEF,
2268 (char_u *)&p_report, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002269 {(char_u *)2L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002270 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2271#ifdef WIN3264
2272 (char_u *)&p_rs, PV_NONE,
2273#else
2274 (char_u *)NULL, PV_NONE,
2275#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002276 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002277 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2278#ifdef FEAT_RIGHTLEFT
2279 (char_u *)&p_ri, PV_NONE,
2280#else
2281 (char_u *)NULL, PV_NONE,
2282#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002283 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002284 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2285#ifdef FEAT_RIGHTLEFT
2286 (char_u *)VAR_WIN, PV_RL,
2287#else
2288 (char_u *)NULL, PV_NONE,
2289#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002290 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002291 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2292#ifdef FEAT_RIGHTLEFT
2293 (char_u *)VAR_WIN, PV_RLC,
2294 {(char_u *)"search", (char_u *)NULL}
2295#else
2296 (char_u *)NULL, PV_NONE,
2297 {(char_u *)NULL, (char_u *)0L}
2298#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002299 SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002300 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002301#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002302 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002303 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002304#else
2305 (char_u *)NULL, PV_NONE,
2306 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002307#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002308 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002309 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2310#ifdef FEAT_CMDL_INFO
2311 (char_u *)&p_ru, PV_NONE,
2312#else
2313 (char_u *)NULL, PV_NONE,
2314#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002315 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002316 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2317#ifdef FEAT_STL_OPT
2318 (char_u *)&p_ruf, PV_NONE,
2319#else
2320 (char_u *)NULL, PV_NONE,
2321#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002322 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002323 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2324 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002325 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002326 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002327 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002328 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2329 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002330 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002331 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002332 (char_u *)VAR_WIN, PV_SCBIND,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002333 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002334 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2335 (char_u *)&p_sj, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002336 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002337 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
Bram Moolenaar375e3392019-01-31 18:26:10 +01002338 (char_u *)&p_so, PV_SO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002339 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002340 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002341 (char_u *)&p_sbo, PV_NONE,
2342 {(char_u *)"ver,jump", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002343 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002344 {"sections", "sect", P_STRING|P_VI_DEF,
2345 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002346 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002347 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002348 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2349 (char_u *)&p_secure, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002350 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002351 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002352 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002353 {(char_u *)"inclusive", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002354 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002355 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002356 (char_u *)&p_slm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002357 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002358 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002359#ifdef FEAT_SESSION
2360 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar4d8bac82018-03-09 21:33:34 +01002361 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize,terminal",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002362 (char_u *)0L}
2363#else
2364 (char_u *)NULL, PV_NONE,
2365 {(char_u *)0L, (char_u *)0L}
2366#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002367 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002368 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2369 (char_u *)&p_sh, PV_NONE,
2370 {
2371#ifdef VMS
2372 (char_u *)"-",
2373#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002374# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002375 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002376# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002377 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002378# endif
2379#endif /* VMS */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002380 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002381 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2382 (char_u *)&p_shcf, PV_NONE,
2383 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002384#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002385 (char_u *)"/c",
2386#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002387 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002388#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002389 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002390 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2391#ifdef FEAT_QUICKFIX
2392 (char_u *)&p_sp, PV_NONE,
2393 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002394#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002395 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002396#else
2397 (char_u *)">",
2398#endif
2399 (char_u *)0L}
2400#else
2401 (char_u *)NULL, PV_NONE,
2402 {(char_u *)0L, (char_u *)0L}
2403#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002404 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002405 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2406 (char_u *)&p_shq, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002407 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002408 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2409 (char_u *)&p_srr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002410 {(char_u *)">", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002411 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2412#ifdef BACKSLASH_IN_FILENAME
2413 (char_u *)&p_ssl, PV_NONE,
2414#else
2415 (char_u *)NULL, PV_NONE,
2416#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002417 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002418 {"shelltemp", "stmp", P_BOOL,
2419 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002420 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002421 {"shelltype", "st", P_NUM|P_VI_DEF,
2422#ifdef AMIGA
2423 (char_u *)&p_st, PV_NONE,
2424#else
2425 (char_u *)NULL, PV_NONE,
2426#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002427 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002428 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2429 (char_u *)&p_sxq, PV_NONE,
2430 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002431#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002432 (char_u *)"\"",
2433#else
2434 (char_u *)"",
2435#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002436 (char_u *)0L} SCTX_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002437 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2438 (char_u *)&p_sxe, PV_NONE,
2439 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002440#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002441 (char_u *)"\"&|<>()@^",
2442#else
2443 (char_u *)"",
2444#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002445 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002446 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2447 (char_u *)&p_sr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002448 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002449 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2450 (char_u *)&p_sw, PV_SW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002451 {(char_u *)8L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002452 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2453 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002454 {(char_u *)"", (char_u *)"filnxtToO"}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002455 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002456 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002457 (char_u *)&p_sn, PV_SN,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002458 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002459 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2460#ifdef FEAT_LINEBREAK
2461 (char_u *)&p_sbr, PV_NONE,
2462#else
2463 (char_u *)NULL, PV_NONE,
2464#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002465 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002466 {"showcmd", "sc", P_BOOL|P_VIM,
2467#ifdef FEAT_CMDL_INFO
2468 (char_u *)&p_sc, PV_NONE,
2469#else
2470 (char_u *)NULL, PV_NONE,
2471#endif
2472 {(char_u *)FALSE,
2473#ifdef UNIX
2474 (char_u *)FALSE
2475#else
2476 (char_u *)TRUE
2477#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002478 } SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002479 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2480 (char_u *)&p_sft, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002481 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002482 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2483 (char_u *)&p_sm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002484 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002485 {"showmode", "smd", P_BOOL|P_VIM,
2486 (char_u *)&p_smd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002487 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002488 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002489 (char_u *)&p_stal, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002490 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002491 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2492 (char_u *)&p_ss, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002493 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002494 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar375e3392019-01-31 18:26:10 +01002495 (char_u *)&p_siso, PV_SISO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002496 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002497 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2498#ifdef FEAT_SIGNS
2499 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002500 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002501#else
2502 (char_u *)NULL, PV_NONE,
2503 {(char_u *)NULL, (char_u *)0L}
2504#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002505 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002506 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2507 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002508 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002509 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2510 (char_u *)&p_scs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002511 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002512 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2513#ifdef FEAT_SMARTINDENT
2514 (char_u *)&p_si, PV_SI,
2515#else
2516 (char_u *)NULL, PV_NONE,
2517#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002518 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002519 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2520 (char_u *)&p_sta, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002521 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002522 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2523 (char_u *)&p_sts, PV_STS,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002524 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002525 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2526 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002527 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002528 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002529#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002530 (char_u *)VAR_WIN, PV_SPELL,
2531#else
2532 (char_u *)NULL, PV_NONE,
2533#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002534 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002535 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002536#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002537 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002538 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002539#else
2540 (char_u *)NULL, PV_NONE,
2541 {(char_u *)0L, (char_u *)0L}
2542#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002543 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002544 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2545 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002546#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002547 (char_u *)&p_spf, PV_SPF,
2548 {(char_u *)"", (char_u *)0L}
2549#else
2550 (char_u *)NULL, PV_NONE,
2551 {(char_u *)0L, (char_u *)0L}
2552#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002553 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002554 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2555 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002556#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002557 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002558 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002559#else
2560 (char_u *)NULL, PV_NONE,
2561 {(char_u *)0L, (char_u *)0L}
2562#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002563 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002564 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002565#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002566 (char_u *)&p_sps, PV_NONE,
2567 {(char_u *)"best", (char_u *)0L}
2568#else
2569 (char_u *)NULL, PV_NONE,
2570 {(char_u *)0L, (char_u *)0L}
2571#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002572 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002573 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002574 (char_u *)&p_sb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002575 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002576 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002577 (char_u *)&p_spr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002578 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002579 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2580 (char_u *)&p_sol, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002581 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002582 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2583#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002584 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002585#else
2586 (char_u *)NULL, PV_NONE,
2587#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002588 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002589 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002590 (char_u *)&p_su, PV_NONE,
2591 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002592 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002593 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002594#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002595 (char_u *)&p_sua, PV_SUA,
2596 {(char_u *)"", (char_u *)0L}
2597#else
2598 (char_u *)NULL, PV_NONE,
2599 {(char_u *)0L, (char_u *)0L}
2600#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002601 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002602 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2603 (char_u *)&p_swf, PV_SWF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002604 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002605 {"swapsync", "sws", P_STRING|P_VI_DEF,
2606 (char_u *)&p_sws, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002607 {(char_u *)"fsync", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002608 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002609 (char_u *)&p_swb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002610 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002611 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2612#ifdef FEAT_SYN_HL
2613 (char_u *)&p_smc, PV_SMC,
2614 {(char_u *)3000L, (char_u *)0L}
2615#else
2616 (char_u *)NULL, PV_NONE,
2617 {(char_u *)0L, (char_u *)0L}
2618#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002619 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002620 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002621#ifdef FEAT_SYN_HL
2622 (char_u *)&p_syn, PV_SYN,
2623 {(char_u *)"", (char_u *)0L}
2624#else
2625 (char_u *)NULL, PV_NONE,
2626 {(char_u *)0L, (char_u *)0L}
2627#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002628 SCTX_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002629 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2630#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002631 (char_u *)&p_tal, PV_NONE,
2632#else
2633 (char_u *)NULL, PV_NONE,
2634#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002635 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002636 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002637 (char_u *)&p_tpm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002638 {(char_u *)10L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002639 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2640 (char_u *)&p_ts, PV_TS,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002641 {(char_u *)8L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002642 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2643 (char_u *)&p_tbs, PV_NONE,
2644#ifdef VMS /* binary searching doesn't appear to work on VMS */
2645 {(char_u *)0L, (char_u *)0L}
2646#else
2647 {(char_u *)TRUE, (char_u *)0L}
2648#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002649 SCTX_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002650 {"tagcase", "tc", P_STRING|P_VIM,
2651 (char_u *)&p_tc, PV_TC,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002652 {(char_u *)"followic", (char_u *)"followic"} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002653 {"taglength", "tl", P_NUM|P_VI_DEF,
2654 (char_u *)&p_tl, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002655 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002656 {"tagrelative", "tr", P_BOOL|P_VIM,
2657 (char_u *)&p_tr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002658 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002659 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002660 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002661 {
2662#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2663 (char_u *)"./tags,./TAGS,tags,TAGS",
2664#else
2665 (char_u *)"./tags,tags",
2666#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002667 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002668 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2669 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002670 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002671 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002672#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002673 (char_u *)&p_tcldll, PV_NONE,
2674 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002675#else
2676 (char_u *)NULL, PV_NONE,
2677 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002678#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002679 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002680 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2681 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002682 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002683 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2684#ifdef FEAT_ARABIC
2685 (char_u *)&p_tbidi, PV_NONE,
2686#else
2687 (char_u *)NULL, PV_NONE,
2688#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002689 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002690 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002691 (char_u *)&p_tenc, PV_NONE,
2692 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002693 SCTX_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002694 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2695#ifdef FEAT_TERMGUICOLORS
2696 (char_u *)&p_tgc, PV_NONE,
2697 {(char_u *)FALSE, (char_u *)FALSE}
2698#else
2699 (char_u*)NULL, PV_NONE,
2700 {(char_u *)FALSE, (char_u *)FALSE}
2701#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002702 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002703 {"termwinkey", "twk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2704#ifdef FEAT_TERMINAL
2705 (char_u *)VAR_WIN, PV_TWK,
2706 {(char_u *)"", (char_u *)NULL}
2707#else
2708 (char_u *)NULL, PV_NONE,
2709 {(char_u *)NULL, (char_u *)0L}
2710#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002711 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002712 {"termwinscroll", "twsl", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2713#ifdef FEAT_TERMINAL
2714 (char_u *)&p_twsl, PV_TWSL,
2715 {(char_u *)10000L, (char_u *)10000L}
2716#else
2717 (char_u *)NULL, PV_NONE,
2718 {(char_u *)NULL, (char_u *)0L}
2719#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002720 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002721 {"termwinsize", "tws", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2722#ifdef FEAT_TERMINAL
2723 (char_u *)VAR_WIN, PV_TWS,
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002724 {(char_u *)"", (char_u *)NULL}
2725#else
2726 (char_u *)NULL, PV_NONE,
2727 {(char_u *)NULL, (char_u *)0L}
2728#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002729 SCTX_INIT},
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01002730 {"termwintype", "twt", P_STRING|P_ALLOCED|P_VI_DEF,
2731#if defined(WIN3264) && defined(FEAT_TERMINAL)
2732 (char_u *)&p_twt, PV_NONE,
2733 {(char_u *)"", (char_u *)NULL}
2734#else
2735 (char_u *)NULL, PV_NONE,
2736 {(char_u *)NULL, (char_u *)0L}
2737#endif
2738 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002739 {"terse", NULL, P_BOOL|P_VI_DEF,
2740 (char_u *)&p_terse, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002741 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002742 {"textauto", "ta", P_BOOL|P_VIM,
2743 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002744 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002745 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002746 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2747 (char_u *)&p_tx, PV_TX,
2748 {
2749#ifdef USE_CRNL
2750 (char_u *)TRUE,
2751#else
2752 (char_u *)FALSE,
2753#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002754 (char_u *)0L} SCTX_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002755 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002756 (char_u *)&p_tw, PV_TW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002757 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002758 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002759#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002760 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002761#else
2762 (char_u *)NULL, PV_NONE,
2763#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002764 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002765 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2766 (char_u *)&p_to, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002767 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002768 {"timeout", "to", P_BOOL|P_VI_DEF,
2769 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002770 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002771 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2772 (char_u *)&p_tm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002773 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002774 {"title", NULL, P_BOOL|P_VI_DEF,
2775#ifdef FEAT_TITLE
2776 (char_u *)&p_title, PV_NONE,
2777#else
2778 (char_u *)NULL, PV_NONE,
2779#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002780 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002781 {"titlelen", NULL, P_NUM|P_VI_DEF,
2782#ifdef FEAT_TITLE
2783 (char_u *)&p_titlelen, PV_NONE,
2784#else
2785 (char_u *)NULL, PV_NONE,
2786#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002787 {(char_u *)85L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002788 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002789#ifdef FEAT_TITLE
2790 (char_u *)&p_titleold, PV_NONE,
2791 {(char_u *)N_("Thanks for flying Vim"),
2792 (char_u *)0L}
2793#else
2794 (char_u *)NULL, PV_NONE,
2795 {(char_u *)0L, (char_u *)0L}
2796#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002797 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002798 {"titlestring", NULL, P_STRING|P_VI_DEF,
2799#ifdef FEAT_TITLE
2800 (char_u *)&p_titlestring, PV_NONE,
2801#else
2802 (char_u *)NULL, PV_NONE,
2803#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002804 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002805 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002806#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002807 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002808 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002809#else
2810 (char_u *)NULL, PV_NONE,
2811 {(char_u *)0L, (char_u *)0L}
2812#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002813 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002814 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002815#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002816 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002817 {(char_u *)"small", (char_u *)0L}
2818#else
2819 (char_u *)NULL, PV_NONE,
2820 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002821#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002822 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002823 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2824 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002825 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002826 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2827 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002828 {(char_u *)-1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002829 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2830 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002831 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002832 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2833 (char_u *)&p_tf, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002834 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002835 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2836#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2837 (char_u *)&p_ttym, PV_NONE,
2838#else
2839 (char_u *)NULL, PV_NONE,
2840#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002841 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002842 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2843 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002844 {(char_u *)999L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002845 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2846 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002847 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002848 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2849 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002850#ifdef FEAT_PERSISTENT_UNDO
2851 (char_u *)&p_udir, PV_NONE,
2852 {(char_u *)".", (char_u *)0L}
2853#else
2854 (char_u *)NULL, PV_NONE,
2855 {(char_u *)0L, (char_u *)0L}
2856#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002857 SCTX_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002858 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2859#ifdef FEAT_PERSISTENT_UNDO
2860 (char_u *)&p_udf, PV_UDF,
2861#else
2862 (char_u *)NULL, PV_NONE,
2863#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002864 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002865 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002866 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002867 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002868#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002869 (char_u *)1000L,
2870#else
2871 (char_u *)100L,
2872#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002873 (char_u *)0L} SCTX_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002874 {"undoreload", "ur", P_NUM|P_VI_DEF,
2875 (char_u *)&p_ur, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002876 { (char_u *)10000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002877 {"updatecount", "uc", P_NUM|P_VI_DEF,
2878 (char_u *)&p_uc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002879 {(char_u *)200L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002880 {"updatetime", "ut", P_NUM|P_VI_DEF,
2881 (char_u *)&p_ut, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002882 {(char_u *)4000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar04958cb2018-06-23 19:23:02 +02002883 {"varsofttabstop", "vsts", P_STRING|P_VI_DEF|P_VIM|P_COMMA,
2884#ifdef FEAT_VARTABS
2885 (char_u *)&p_vsts, PV_VSTS,
2886 {(char_u *)"", (char_u *)0L}
2887#else
2888 (char_u *)NULL, PV_NONE,
2889 {(char_u *)"", (char_u *)NULL}
2890#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002891 SCTX_INIT},
Bram Moolenaar04958cb2018-06-23 19:23:02 +02002892 {"vartabstop", "vts", P_STRING|P_VI_DEF|P_VIM|P_RBUF|P_COMMA,
2893#ifdef FEAT_VARTABS
2894 (char_u *)&p_vts, PV_VTS,
2895 {(char_u *)"", (char_u *)0L}
2896#else
2897 (char_u *)NULL, PV_NONE,
2898 {(char_u *)"", (char_u *)NULL}
2899#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002900 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002901 {"verbose", "vbs", P_NUM|P_VI_DEF,
2902 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002903 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002904 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2905 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002906 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002907 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2908#ifdef FEAT_SESSION
2909 (char_u *)&p_vdir, PV_NONE,
2910 {(char_u *)DFLT_VDIR, (char_u *)0L}
2911#else
2912 (char_u *)NULL, PV_NONE,
2913 {(char_u *)0L, (char_u *)0L}
2914#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002915 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002916 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002917#ifdef FEAT_SESSION
2918 (char_u *)&p_vop, PV_NONE,
Bram Moolenaar13e90412017-11-11 18:16:48 +01002919 {(char_u *)"folds,options,cursor,curdir",
2920 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002921#else
2922 (char_u *)NULL, PV_NONE,
2923 {(char_u *)0L, (char_u *)0L}
2924#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002925 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002926 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002927#ifdef FEAT_VIMINFO
2928 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002929#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002930 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002931#else
2932# ifdef AMIGA
2933 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002934 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002935# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002936 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002937# endif
2938#endif
2939#else
2940 (char_u *)NULL, PV_NONE,
2941 {(char_u *)0L, (char_u *)0L}
2942#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002943 SCTX_INIT},
Bram Moolenaarc229e542018-07-08 21:46:56 +02002944 {"viminfofile", "vif", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP
2945 |P_SECURE|P_VI_DEF,
Bram Moolenaarc4da1132017-07-15 19:39:43 +02002946#ifdef FEAT_VIMINFO
2947 (char_u *)&p_viminfofile, PV_NONE,
2948 {(char_u *)"", (char_u *)0L}
2949#else
2950 (char_u *)NULL, PV_NONE,
2951 {(char_u *)0L, (char_u *)0L}
2952#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002953 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002954 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2955 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002956 (char_u *)&p_ve, PV_NONE,
2957 {(char_u *)"", (char_u *)""}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002958 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002959 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2960 (char_u *)&p_vb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002961 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002962 {"w300", NULL, P_NUM|P_VI_DEF,
2963 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002964 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002965 {"w1200", NULL, P_NUM|P_VI_DEF,
2966 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002967 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002968 {"w9600", NULL, P_NUM|P_VI_DEF,
2969 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002970 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002971 {"warn", NULL, P_BOOL|P_VI_DEF,
2972 (char_u *)&p_warn, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002973 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002974 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2975 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002976 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002977 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002978 (char_u *)&p_ww, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002979 {(char_u *)"", (char_u *)"b,s"} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002980 {"wildchar", "wc", P_NUM|P_VIM,
2981 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002982 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002983 SCTX_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002984 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002985 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002986 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002987 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002988#ifdef FEAT_WILDIGN
2989 (char_u *)&p_wig, PV_NONE,
2990#else
2991 (char_u *)NULL, PV_NONE,
2992#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002993 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002994 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2995 (char_u *)&p_wic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002996 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002997 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2998#ifdef FEAT_WILDMENU
2999 (char_u *)&p_wmnu, PV_NONE,
3000#else
3001 (char_u *)NULL, PV_NONE,
3002#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003003 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003004 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003005 (char_u *)&p_wim, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003006 {(char_u *)"full", (char_u *)0L} SCTX_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003007 {"wildoptions", "wop", P_STRING|P_VI_DEF,
3008#ifdef FEAT_CMDL_COMPL
3009 (char_u *)&p_wop, PV_NONE,
3010 {(char_u *)"", (char_u *)0L}
3011#else
3012 (char_u *)NULL, PV_NONE,
3013 {(char_u *)NULL, (char_u *)0L}
3014#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003015 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003016 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3017#ifdef FEAT_WAK
3018 (char_u *)&p_wak, PV_NONE,
3019 {(char_u *)"menu", (char_u *)0L}
3020#else
3021 (char_u *)NULL, PV_NONE,
3022 {(char_u *)NULL, (char_u *)0L}
3023#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003024 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003025 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003026 (char_u *)&p_window, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003027 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003028 {"winheight", "wh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003029 (char_u *)&p_wh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003030 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003031 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003032 (char_u *)VAR_WIN, PV_WFH,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003033 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003034 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003035 (char_u *)VAR_WIN, PV_WFW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003036 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003037 {"winminheight", "wmh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003038 (char_u *)&p_wmh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003039 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003040 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003041 (char_u *)&p_wmw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003042 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003043 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar84ed4ad2017-08-17 11:33:42 +02003044#if defined(WIN3264) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003045 (char_u *)&p_winptydll, PV_NONE, {
3046# ifdef _WIN64
3047 (char_u *)"winpty64.dll",
3048# else
3049 (char_u *)"winpty32.dll",
3050# endif
3051 (char_u *)0L}
3052#else
3053 (char_u *)NULL, PV_NONE,
3054 {(char_u *)0L, (char_u *)0L}
3055#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003056 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003057 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003058 (char_u *)&p_wiw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003059 {(char_u *)20L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003060 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3061 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003062 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003063 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3064 (char_u *)&p_wm, PV_WM,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003065 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003066 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3067 (char_u *)&p_ws, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003068 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003069 {"write", NULL, P_BOOL|P_VI_DEF,
3070 (char_u *)&p_write, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003071 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003072 {"writeany", "wa", P_BOOL|P_VI_DEF,
3073 (char_u *)&p_wa, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003074 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003075 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3076 (char_u *)&p_wb, PV_NONE,
3077 {
3078#ifdef FEAT_WRITEBACKUP
3079 (char_u *)TRUE,
3080#else
3081 (char_u *)FALSE,
3082#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003083 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003084 {"writedelay", "wd", P_NUM|P_VI_DEF,
3085 (char_u *)&p_wd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003086 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003087
3088/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003089#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003090 (char_u *)&vvv, PV_NONE, \
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003091 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003092
3093 p_term("t_AB", T_CAB)
3094 p_term("t_AF", T_CAF)
3095 p_term("t_AL", T_CAL)
3096 p_term("t_al", T_AL)
3097 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003098 p_term("t_BE", T_BE)
3099 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003100 p_term("t_cd", T_CD)
3101 p_term("t_ce", T_CE)
3102 p_term("t_cl", T_CL)
3103 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003104 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003105 p_term("t_Co", T_CCO)
3106 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003107 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003108 p_term("t_cs", T_CS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003109 p_term("t_CV", T_CSV)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003110 p_term("t_da", T_DA)
3111 p_term("t_db", T_DB)
3112 p_term("t_DL", T_CDL)
3113 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003114 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003115 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003116 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003117 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003118 p_term("t_IE", T_CIE)
3119 p_term("t_IS", T_CIS)
3120 p_term("t_ke", T_KE)
3121 p_term("t_ks", T_KS)
3122 p_term("t_le", T_LE)
3123 p_term("t_mb", T_MB)
3124 p_term("t_md", T_MD)
3125 p_term("t_me", T_ME)
3126 p_term("t_mr", T_MR)
3127 p_term("t_ms", T_MS)
3128 p_term("t_nd", T_ND)
3129 p_term("t_op", T_OP)
Bram Moolenaara20f83d2017-10-15 13:35:01 +02003130 p_term("t_RF", T_RFG)
Bram Moolenaare5401222015-06-25 19:16:56 +02003131 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003132 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003133 p_term("t_RI", T_CRI)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003134 p_term("t_Ri", T_SRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003135 p_term("t_RS", T_CRS)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003136 p_term("t_RT", T_CRT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003137 p_term("t_RV", T_CRV)
3138 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003139 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003140 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003141 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003142 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003143 p_term("t_SI", T_CSI)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003144 p_term("t_Si", T_SSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003145 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003146 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003147 p_term("t_sr", T_SR)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003148 p_term("t_ST", T_CST)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003149 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003150 p_term("t_te", T_TE)
3151 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003152 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003153 p_term("t_ts", T_TS)
3154 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003155 p_term("t_ue", T_UE)
3156 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003157 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003158 p_term("t_vb", T_VB)
3159 p_term("t_ve", T_VE)
3160 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003161 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003162 p_term("t_vs", T_VS)
3163 p_term("t_WP", T_CWP)
3164 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003165 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003166 p_term("t_xs", T_XS)
3167 p_term("t_ZH", T_CZH)
3168 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003169 p_term("t_8f", T_8F)
3170 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003171
3172/* terminal key codes are not in here */
3173
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003174 /* end marker */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003175 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCTX_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003176};
3177
3178#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3179
Bram Moolenaar071d4272004-06-13 20:20:40 +00003180static char *(p_ambw_values[]) = {"single", "double", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003181static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003182static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003183static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003184#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003185static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003186#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003187#ifdef FEAT_CMDL_COMPL
3188static char *(p_wop_values[]) = {"tagfile", NULL};
3189#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003190#ifdef FEAT_WAK
3191static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3192#endif
3193static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003194static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3195static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003196static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003197#ifdef FEAT_BROWSE
3198static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3199#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003200static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
Bram Moolenaar57657d82006-04-21 22:12:41 +00003201static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003202static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
Bram Moolenaarf2732452018-06-03 14:47:35 +02003203static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", "prompt", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003204static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003205static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3206#ifdef FEAT_FOLDING
3207static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003208# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003209 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003210# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003211 NULL};
3212static char *(p_fcl_values[]) = {"all", NULL};
3213#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003214#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003215static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003216#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003217#ifdef FEAT_SIGNS
3218static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3219#endif
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01003220#if defined(WIN3264) && defined(FEAT_TERMINAL)
3221static char *(p_twt_values[]) = {"winpty", "conpty", "", NULL};
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01003222#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003223
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003224static void set_options_default(int opt_flags);
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003225static void set_string_default_esc(char *name, char_u *val, int escape);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003226static char_u *term_bg_default(void);
Bram Moolenaar916a8182018-11-25 02:18:29 +01003227static void did_set_option(int opt_idx, int opt_flags, int new_value, int value_checked);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003228static char_u *option_expand(int opt_idx, char_u *val);
3229static void didset_options(void);
3230static void didset_options2(void);
3231static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003232#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003233static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003234#else
3235# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3236#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003237static void set_string_option_global(int opt_idx, char_u **varp);
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003238static 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);
3239static char *set_chars_option(char_u **varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003240#ifdef FEAT_CLIPBOARD
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003241static char *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003242#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003243#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003244static char *did_set_spell_option(int is_spellfile);
3245static char *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003246#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003247#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003248static void set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003249#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003250static char *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3251static 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 +01003252static void check_redraw(long_u flags);
3253static int findoption(char_u *);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02003254static int find_key_option(char_u *arg_arg, int has_lt);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003255static void showoptions(int all, int opt_flags);
3256static int optval_default(struct vimoption *, char_u *varp);
3257static void showoneopt(struct vimoption *, int opt_flags);
Bram Moolenaared18f2c2019-01-24 20:30:52 +01003258static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, long_u flags);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003259static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3260static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3261static int istermoption(struct vimoption *);
3262static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3263static char_u *get_varp(struct vimoption *);
3264static void option_value2string(struct vimoption *, int opt_flags);
3265static void check_winopt(winopt_T *wop);
3266static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003267#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003268static void langmap_init(void);
3269static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003270#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003271static void paste_option_changed(void);
3272static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003273#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003274static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003275#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003276static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3277static int check_opt_strings(char_u *val, char **values, int);
3278static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003279#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003280static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003281#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003282
3283/*
3284 * Initialize the options, first part.
3285 *
3286 * Called only once from main(), just after creating the first buffer.
Bram Moolenaar07268702018-03-01 21:57:32 +01003287 * If "clean_arg" is TRUE Vim was started with --clean.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003288 */
3289 void
Bram Moolenaar07268702018-03-01 21:57:32 +01003290set_init_1(int clean_arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003291{
3292 char_u *p;
3293 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003294 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003295
3296#ifdef FEAT_LANGMAP
3297 langmap_init();
3298#endif
3299
3300 /* Be Vi compatible by default */
3301 p_cp = TRUE;
3302
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003303 /* Use POSIX compatibility when $VIM_POSIX is set. */
3304 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003305 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003306 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003307 set_string_default("shm", (char_u *)"A");
3308 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003309
Bram Moolenaar071d4272004-06-13 20:20:40 +00003310 /*
3311 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003312 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003313 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003314 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003315#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003316 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003317# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003318 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003319# endif
3320#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003321 )
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003322 set_string_default_esc("sh", p, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003323
3324#ifdef FEAT_WILDIGN
3325 /*
3326 * Set the default for 'backupskip' to include environment variables for
3327 * temp files.
3328 */
3329 {
3330# ifdef UNIX
3331 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3332# else
3333 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3334# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003335 int len;
3336 garray_T ga;
3337 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003338
3339 ga_init2(&ga, 1, 100);
3340 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3341 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003342 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003343# ifdef UNIX
3344 if (*names[n] == NUL)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003345# ifdef MACOS_X
3346 p = (char_u *)"/private/tmp";
3347# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003348 p = (char_u *)"/tmp";
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003349# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003350 else
3351# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003352 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003353 if (p != NULL && *p != NUL)
3354 {
3355 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003356 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003357 if (ga_grow(&ga, len) == OK)
3358 {
3359 if (ga.ga_len > 0)
3360 STRCAT(ga.ga_data, ",");
3361 STRCAT(ga.ga_data, p);
3362 add_pathsep(ga.ga_data);
3363 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003364 ga.ga_len += len;
3365 }
3366 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003367 if (mustfree)
3368 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003369 }
3370 if (ga.ga_data != NULL)
3371 {
3372 set_string_default("bsk", ga.ga_data);
3373 vim_free(ga.ga_data);
3374 }
3375 }
3376#endif
3377
3378 /*
3379 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3380 */
3381 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003382 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003383 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003384#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3385 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3386#endif
3387 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003388#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003389 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003390 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003391#else
3392# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003393 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003394 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003395# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003396 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003397# endif
3398#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003399 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003400 opt_idx = findoption((char_u *)"maxmem");
3401 if (opt_idx >= 0)
3402 {
3403#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003404 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3405 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003406#endif
3407 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3408 }
3409 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003410 }
3411
Bram Moolenaar071d4272004-06-13 20:20:40 +00003412#ifdef FEAT_SEARCHPATH
3413 {
3414 char_u *cdpath;
3415 char_u *buf;
3416 int i;
3417 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003418 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003419
3420 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003421 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003422 if (cdpath != NULL)
3423 {
3424 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3425 if (buf != NULL)
3426 {
3427 buf[0] = ','; /* start with ",", current dir first */
3428 j = 1;
3429 for (i = 0; cdpath[i] != NUL; ++i)
3430 {
3431 if (vim_ispathlistsep(cdpath[i]))
3432 buf[j++] = ',';
3433 else
3434 {
3435 if (cdpath[i] == ' ' || cdpath[i] == ',')
3436 buf[j++] = '\\';
3437 buf[j++] = cdpath[i];
3438 }
3439 }
3440 buf[j] = NUL;
3441 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003442 if (opt_idx >= 0)
3443 {
3444 options[opt_idx].def_val[VI_DEFAULT] = buf;
3445 options[opt_idx].flags |= P_DEF_ALLOCED;
3446 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003447 else
3448 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003449 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003450 if (mustfree)
3451 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003452 }
3453 }
3454#endif
3455
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003456#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003457 /* Set print encoding on platforms that don't default to latin1 */
3458 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003459# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003460 (char_u *)"cp1252"
3461# else
3462# ifdef VMS
3463 (char_u *)"dec-mcs"
3464# else
3465# ifdef EBCDIC
3466 (char_u *)"ebcdic-uk"
3467# else
3468# ifdef MAC
3469 (char_u *)"mac-roman"
3470# else /* HPUX */
3471 (char_u *)"hp-roman8"
3472# endif
3473# endif
3474# endif
3475# endif
3476 );
3477#endif
3478
3479#ifdef FEAT_POSTSCRIPT
3480 /* 'printexpr' must be allocated to be able to evaluate it. */
3481 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003482# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003483 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003484# else
3485# ifdef VMS
3486 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3487
3488# else
3489 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3490# endif
3491# endif
3492 );
3493#endif
3494
3495 /*
3496 * Set all the options (except the terminal options) to their default
3497 * value. Also set the global value for local options.
3498 */
3499 set_options_default(0);
3500
Bram Moolenaar07268702018-03-01 21:57:32 +01003501#ifdef CLEAN_RUNTIMEPATH
3502 if (clean_arg)
3503 {
3504 opt_idx = findoption((char_u *)"runtimepath");
3505 if (opt_idx >= 0)
3506 {
3507 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3508 p_rtp = (char_u *)CLEAN_RUNTIMEPATH;
3509 }
3510 opt_idx = findoption((char_u *)"packpath");
3511 if (opt_idx >= 0)
3512 {
3513 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3514 p_pp = (char_u *)CLEAN_RUNTIMEPATH;
3515 }
3516 }
3517#endif
3518
Bram Moolenaar071d4272004-06-13 20:20:40 +00003519#ifdef FEAT_GUI
3520 if (found_reverse_arg)
3521 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3522#endif
3523
3524 curbuf->b_p_initialized = TRUE;
3525 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003526 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003527 check_buf_options(curbuf);
3528 check_win_options(curwin);
3529 check_options();
3530
3531 /* Must be before option_expand(), because that one needs vim_isIDc() */
3532 didset_options();
3533
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003534#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003535 /* Use the current chartab for the generic chartab. This is not in
3536 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003537 init_spell_chartab();
3538#endif
3539
Bram Moolenaar071d4272004-06-13 20:20:40 +00003540 /*
3541 * Expand environment variables and things like "~" for the defaults.
3542 * If option_expand() returns non-NULL the variable is expanded. This can
3543 * only happen for non-indirect options.
3544 * Also set the default to the expanded value, so ":set" does not list
3545 * them.
3546 * Don't set the P_ALLOCED flag, because we don't want to free the
3547 * default.
3548 */
3549 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3550 {
3551 if ((options[opt_idx].flags & P_GETTEXT)
3552 && options[opt_idx].var != NULL)
3553 p = (char_u *)_(*(char **)options[opt_idx].var);
3554 else
3555 p = option_expand(opt_idx, NULL);
3556 if (p != NULL && (p = vim_strsave(p)) != NULL)
3557 {
3558 *(char_u **)options[opt_idx].var = p;
3559 /* VIMEXP
3560 * Defaults for all expanded options are currently the same for Vi
3561 * and Vim. When this changes, add some code here! Also need to
3562 * split P_DEF_ALLOCED in two.
3563 */
3564 if (options[opt_idx].flags & P_DEF_ALLOCED)
3565 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3566 options[opt_idx].def_val[VI_DEFAULT] = p;
3567 options[opt_idx].flags |= P_DEF_ALLOCED;
3568 }
3569 }
3570
Bram Moolenaar071d4272004-06-13 20:20:40 +00003571 save_file_ff(curbuf); /* Buffer is unchanged */
3572
Bram Moolenaar071d4272004-06-13 20:20:40 +00003573#if defined(FEAT_ARABIC)
3574 /* Detect use of mlterm.
3575 * Mlterm is a terminal emulator akin to xterm that has some special
3576 * abilities (bidi namely).
3577 * NOTE: mlterm's author is being asked to 'set' a variable
3578 * instead of an environment variable due to inheritance.
3579 */
3580 if (mch_getenv((char_u *)"MLTERM") != NULL)
3581 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3582#endif
3583
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003584 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003585
Bram Moolenaar071d4272004-06-13 20:20:40 +00003586# if defined(WIN3264) && defined(FEAT_GETTEXT)
3587 /*
3588 * If $LANG isn't set, try to get a good value for it. This makes the
3589 * right language be used automatically. Don't do this for English.
3590 */
3591 if (mch_getenv((char_u *)"LANG") == NULL)
3592 {
3593 char buf[20];
3594
3595 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3596 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3597 * only the first two. */
3598 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3599 (LPTSTR)buf, 20);
3600 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3601 {
3602 /* There are a few exceptions (probably more) */
3603 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3604 STRCPY(buf, "zh_TW");
3605 else if (STRNICMP(buf, "chs", 3) == 0
3606 || STRNICMP(buf, "zhc", 3) == 0)
3607 STRCPY(buf, "zh_CN");
3608 else if (STRNICMP(buf, "jp", 2) == 0)
3609 STRCPY(buf, "ja");
3610 else
3611 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003612 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003613 }
3614 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003615# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003616# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003617 /* Moved to os_mac_conv.c to avoid dependency problems. */
3618 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003619# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003620# endif
3621
3622 /* enc_locale() will try to find the encoding of the current locale. */
3623 p = enc_locale();
3624 if (p != NULL)
3625 {
3626 char_u *save_enc;
3627
3628 /* Try setting 'encoding' and check if the value is valid.
3629 * If not, go back to the default "latin1". */
3630 save_enc = p_enc;
3631 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003632 if (STRCMP(p_enc, "gb18030") == 0)
3633 {
3634 /* We don't support "gb18030", but "cp936" is a good substitute
3635 * for practical purposes, thus use that. It's not an alias to
3636 * still support conversion between gb18030 and utf-8. */
3637 p_enc = vim_strsave((char_u *)"cp936");
3638 vim_free(p);
3639 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003640 if (mb_init() == NULL)
3641 {
3642 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003643 if (opt_idx >= 0)
3644 {
3645 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3646 options[opt_idx].flags |= P_DEF_ALLOCED;
3647 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003648
Bram Moolenaard0573012017-10-28 21:11:06 +02003649#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003650 if (STRCMP(p_enc, "latin1") == 0 || enc_utf8)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003651 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003652 /* Adjust the default for 'isprint' and 'iskeyword' to match
3653 * latin1. Also set the defaults for when 'nocompatible' is
3654 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003655 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003656 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003657 set_string_option_direct((char_u *)"isk", -1,
3658 ISK_LATIN1, OPT_FREE, SID_NONE);
3659 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003660 if (opt_idx >= 0)
3661 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003662 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003663 if (opt_idx >= 0)
3664 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003665 (void)init_chartab();
3666 }
3667#endif
3668
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003669#if defined(WIN3264) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003670 /* Win32 console: When GetACP() returns a different value from
3671 * GetConsoleCP() set 'termencoding'. */
3672 if (GetACP() != GetConsoleCP())
3673 {
3674 char buf[50];
3675
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01003676 /* Win32 console: In ConPTY, GetConsoleCP() returns zero.
3677 * Use an alternative value. */
3678 if (GetConsoleCP() == 0)
3679 sprintf(buf, "cp%ld", (long)GetACP());
3680 else
3681 sprintf(buf, "cp%ld", (long)GetConsoleCP());
Bram Moolenaar071d4272004-06-13 20:20:40 +00003682 p_tenc = vim_strsave((char_u *)buf);
3683 if (p_tenc != NULL)
3684 {
3685 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003686 if (opt_idx >= 0)
3687 {
3688 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3689 options[opt_idx].flags |= P_DEF_ALLOCED;
3690 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003691 convert_setup(&input_conv, p_tenc, p_enc);
3692 convert_setup(&output_conv, p_enc, p_tenc);
3693 }
3694 else
3695 p_tenc = empty_option;
3696 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003697#endif
3698#if defined(WIN3264)
Bram Moolenaar05159a02005-02-26 23:04:13 +00003699 /* $HOME may have characters in active code page. */
3700 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003701#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003702 }
3703 else
3704 {
3705 vim_free(p_enc);
3706 p_enc = save_enc;
3707 }
3708 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003709
3710#ifdef FEAT_MULTI_LANG
3711 /* Set the default for 'helplang'. */
3712 set_helplang_default(get_mess_lang());
3713#endif
3714}
3715
3716/*
3717 * Set an option to its default value.
3718 * This does not take care of side effects!
3719 */
3720 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003721set_option_default(
3722 int opt_idx,
3723 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3724 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003725{
3726 char_u *varp; /* pointer to variable for current option */
3727 int dvi; /* index in def_val[] */
3728 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003729 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003730 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3731
3732 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3733 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003734 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003735 {
3736 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3737 if (flags & P_STRING)
3738 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003739 /* Use set_string_option_direct() for local options to handle
3740 * freeing and allocating the value. */
3741 if (options[opt_idx].indir != PV_NONE)
3742 set_string_option_direct(NULL, opt_idx,
3743 options[opt_idx].def_val[dvi], opt_flags, 0);
3744 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003745 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003746 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3747 free_string_option(*(char_u **)(varp));
3748 *(char_u **)varp = options[opt_idx].def_val[dvi];
3749 options[opt_idx].flags &= ~P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003750 }
3751 }
3752 else if (flags & P_NUM)
3753 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003754 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003755 win_comp_scroll(curwin);
3756 else
3757 {
Bram Moolenaar375e3392019-01-31 18:26:10 +01003758 long def_val = (long)(long_i)options[opt_idx].def_val[dvi];
3759
3760 if ((long *)varp == &curwin->w_p_so
3761 || (long *)varp == &curwin->w_p_siso)
3762 // 'scrolloff' and 'sidescrolloff' local values have a
3763 // different default value than the global default.
3764 *(long *)varp = -1;
3765 else
3766 *(long *)varp = def_val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003767 /* May also set global value for local option. */
3768 if (both)
3769 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
Bram Moolenaar375e3392019-01-31 18:26:10 +01003770 def_val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003771 }
3772 }
3773 else /* P_BOOL */
3774 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003775 /* the cast to long is required for Manx C, long_i is needed for
3776 * MSVC */
3777 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003778#ifdef UNIX
3779 /* 'modeline' defaults to off for root */
3780 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3781 *(int *)varp = FALSE;
3782#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003783 /* May also set global value for local option. */
3784 if (both)
3785 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3786 *(int *)varp;
3787 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003788
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003789 /* The default value is not insecure. */
3790 flagsp = insecure_flag(opt_idx, opt_flags);
3791 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003792 }
3793
3794#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003795 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003796#endif
3797}
3798
3799/*
3800 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003801 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003802 */
3803 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003804set_options_default(
3805 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003806{
3807 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003808 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003809 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003810
3811 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003812 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003813 && (opt_flags == 0
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003814 || (options[i].var != (char_u *)&p_enc
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003815# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003816 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003817 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003818# endif
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003819 )))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003820 set_option_default(i, opt_flags, p_cp);
3821
Bram Moolenaar071d4272004-06-13 20:20:40 +00003822 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003823 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003824 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003825#ifdef FEAT_CINDENT
3826 parse_cino(curbuf);
3827#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003828}
3829
3830/*
3831 * Set the Vi-default value of a string option.
3832 * Used for 'sh', 'backupskip' and 'term'.
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003833 * When "escape" is TRUE escape spaces with a backslash.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003834 */
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003835 static void
3836set_string_default_esc(char *name, char_u *val, int escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003837{
3838 char_u *p;
3839 int opt_idx;
3840
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003841 if (escape && vim_strchr(val, ' ') != NULL)
3842 p = vim_strsave_escaped(val, (char_u *)" ");
3843 else
3844 p = vim_strsave(val);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003845 if (p != NULL) /* we don't want a NULL */
3846 {
3847 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003848 if (opt_idx >= 0)
3849 {
3850 if (options[opt_idx].flags & P_DEF_ALLOCED)
3851 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3852 options[opt_idx].def_val[VI_DEFAULT] = p;
3853 options[opt_idx].flags |= P_DEF_ALLOCED;
3854 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003855 }
3856}
3857
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003858 void
3859set_string_default(char *name, char_u *val)
3860{
3861 set_string_default_esc(name, val, FALSE);
3862}
3863
Bram Moolenaar071d4272004-06-13 20:20:40 +00003864/*
3865 * Set the Vi-default value of a number option.
3866 * Used for 'lines' and 'columns'.
3867 */
3868 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003869set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003870{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003871 int opt_idx;
3872
3873 opt_idx = findoption((char_u *)name);
3874 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003875 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003876}
3877
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003878#if defined(EXITFREE) || defined(PROTO)
3879/*
3880 * Free all options.
3881 */
3882 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003883free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003884{
3885 int i;
3886
3887 for (i = 0; !istermoption(&options[i]); i++)
3888 {
3889 if (options[i].indir == PV_NONE)
3890 {
3891 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003892 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003893 free_string_option(*(char_u **)options[i].var);
3894 if (options[i].flags & P_DEF_ALLOCED)
3895 free_string_option(options[i].def_val[VI_DEFAULT]);
3896 }
3897 else if (options[i].var != VAR_WIN
3898 && (options[i].flags & P_STRING))
3899 /* buffer-local option: free global value */
3900 free_string_option(*(char_u **)options[i].var);
3901 }
3902}
3903#endif
3904
3905
Bram Moolenaar071d4272004-06-13 20:20:40 +00003906/*
3907 * Initialize the options, part two: After getting Rows and Columns and
3908 * setting 'term'.
3909 */
3910 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003911set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003912{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003913 int idx;
3914
Bram Moolenaar071d4272004-06-13 20:20:40 +00003915 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003916 * 'scroll' defaults to half the window height. The stored default is zero,
3917 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003918 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003919 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003920 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003921 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003922 comp_col();
3923
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003924 /*
3925 * 'window' is only for backwards compatibility with Vi.
3926 * Default is Rows - 1.
3927 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003928 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003929 p_window = Rows - 1;
3930 set_number_default("window", Rows - 1);
3931
Bram Moolenaarf740b292006-02-16 22:11:02 +00003932 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003933#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003934 /*
3935 * If 'background' wasn't set by the user, try guessing the value,
3936 * depending on the terminal name. Only need to check for terminals
3937 * with a dark background, that can handle color.
3938 */
3939 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003940 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3941 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003942 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003943 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003944 /* don't mark it as set, when starting the GUI it may be
3945 * changed again */
3946 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003947 }
3948#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003949
3950#ifdef CURSOR_SHAPE
3951 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3952#endif
3953#ifdef FEAT_MOUSESHAPE
3954 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3955#endif
3956#ifdef FEAT_PRINTER
3957 (void)parse_printoptions(); /* parse 'printoptions' default value */
3958#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003959}
3960
3961/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003962 * Return "dark" or "light" depending on the kind of terminal.
3963 * This is just guessing! Recognized are:
3964 * "linux" Linux console
3965 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003966 * "cygwin.*" Cygwin shell
3967 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00003968 * We also check the COLORFGBG environment variable, which is set by
3969 * rxvt and derivatives. This variable contains either two or three
3970 * values separated by semicolons; we want the last value in either
3971 * case. If this value is 0-6 or 8, our background is dark.
3972 */
3973 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003974term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003975{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003976#if defined(WIN3264)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003977 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003978 return (char_u *)"dark";
3979#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003980 char_u *p;
3981
Bram Moolenaarf740b292006-02-16 22:11:02 +00003982 if (STRCMP(T_NAME, "linux") == 0
3983 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003984 || STRNCMP(T_NAME, "cygwin", 6) == 0
3985 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00003986 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3987 && (p = vim_strrchr(p, ';')) != NULL
3988 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3989 && p[2] == NUL))
3990 return (char_u *)"dark";
3991 return (char_u *)"light";
3992#endif
3993}
3994
3995/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003996 * Initialize the options, part three: After reading the .vimrc
3997 */
3998 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003999set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004000{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004001#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004002/*
4003 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4004 * This is done after other initializations, where 'shell' might have been
4005 * set, but only if they have not been set before.
4006 */
4007 char_u *p;
4008 int idx_srr;
4009 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004010# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004011 int idx_sp;
4012 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004013# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004014
4015 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004016 if (idx_srr < 0)
4017 do_srr = FALSE;
4018 else
4019 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004020# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004021 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004022 if (idx_sp < 0)
4023 do_sp = FALSE;
4024 else
4025 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004026# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004027 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004028 if (p != NULL)
4029 {
4030 /*
4031 * Default for p_sp is "| tee", for p_srr is ">".
4032 * For known shells it is changed here to include stderr.
4033 */
4034 if ( fnamecmp(p, "csh") == 0
4035 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004036# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004037 || fnamecmp(p, "csh.exe") == 0
4038 || fnamecmp(p, "tcsh.exe") == 0
4039# endif
4040 )
4041 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004042# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004043 if (do_sp)
4044 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004045# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004046 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004047# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004048 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004049# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004050 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4051 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004052# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004053 if (do_srr)
4054 {
4055 p_srr = (char_u *)">&";
4056 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4057 }
4058 }
4059 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004060 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004061 if ( fnamecmp(p, "sh") == 0
4062 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004063 || fnamecmp(p, "mksh") == 0
4064 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004065 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004066 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004067 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004068 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004069# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004070 || fnamecmp(p, "cmd") == 0
4071 || fnamecmp(p, "sh.exe") == 0
4072 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004073 || fnamecmp(p, "mksh.exe") == 0
4074 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004075 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004076 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004077 || fnamecmp(p, "bash.exe") == 0
4078 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004079# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004080 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004081 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004082# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004083 if (do_sp)
4084 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004085# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004086 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004087# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004088 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004089# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004090 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4091 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004092# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004093 if (do_srr)
4094 {
4095 p_srr = (char_u *)">%s 2>&1";
4096 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4097 }
4098 }
4099 vim_free(p);
4100 }
4101#endif
4102
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004103#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004104 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004105 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4106 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004107 * This is done after other initializations, where 'shell' might have been
4108 * set, but only if they have not been set before. Default for p_shcf is
4109 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004110 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004111 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004112 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004113 {
4114 int idx3;
4115
4116 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004117 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004118 {
4119 p_shcf = (char_u *)"-c";
4120 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4121 }
4122
Bram Moolenaar071d4272004-06-13 20:20:40 +00004123 /* Somehow Win32 requires the quotes around the redirection too */
4124 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004125 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004126 {
4127 p_sxq = (char_u *)"\"";
4128 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4129 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004130 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004131 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4132 {
4133 int idx3;
4134
4135 /*
4136 * cmd.exe on Windows will strip the first and last double quote given
4137 * on the command line, e.g. most of the time things like:
4138 * cmd /c "my path/to/echo" "my args to echo"
4139 * become:
4140 * my path/to/echo" "my args to echo
4141 * when executed.
4142 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004143 * To avoid this, set shellxquote to surround the command in
4144 * parenthesis. This appears to make most commands work, without
4145 * breaking commands that worked previously, such as
4146 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004147 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004148 idx3 = findoption((char_u *)"sxq");
4149 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4150 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004151 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004152 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4153 }
4154
Bram Moolenaara64ba222012-02-12 23:23:31 +01004155 idx3 = findoption((char_u *)"shcf");
4156 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4157 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004158 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004159 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4160 }
4161 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004162#endif
4163
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004164 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004165 {
4166 int idx_ffs = findoption((char_u *)"ffs");
4167
4168 /* Apply the first entry of 'fileformats' to the initial buffer. */
4169 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4170 set_fileformat(default_fileformat(), OPT_LOCAL);
4171 }
4172
Bram Moolenaar071d4272004-06-13 20:20:40 +00004173#ifdef FEAT_TITLE
4174 set_title_defaults();
4175#endif
4176}
4177
4178#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4179/*
4180 * When 'helplang' is still at its default value, set it to "lang".
4181 * Only the first two characters of "lang" are used.
4182 */
4183 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004184set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004185{
4186 int idx;
4187
4188 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4189 return;
4190 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004191 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004192 {
4193 if (options[idx].flags & P_ALLOCED)
4194 free_string_option(p_hlg);
4195 p_hlg = vim_strsave(lang);
4196 if (p_hlg == NULL)
4197 p_hlg = empty_option;
4198 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004199 {
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004200 // zh_CN becomes "cn", zh_TW becomes "tw"
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004201 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4202 {
4203 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4204 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4205 }
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004206 // any C like setting, such as C.UTF-8, becomes "en"
4207 else if (STRLEN(p_hlg) >= 1 && *p_hlg == 'C')
4208 {
4209 p_hlg[0] = 'e';
4210 p_hlg[1] = 'n';
4211 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004212 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004213 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004214 options[idx].flags |= P_ALLOCED;
4215 }
4216}
4217#endif
4218
4219#ifdef FEAT_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00004220 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004221gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004222{
4223 if (gui_get_lightness(gui.back_pixel) < 127)
4224 return (char_u *)"dark";
4225 return (char_u *)"light";
4226}
4227
4228/*
4229 * Option initializations that can only be done after opening the GUI window.
4230 */
4231 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004232init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004233{
4234 /* Set the 'background' option according to the lightness of the
4235 * background color, unless the user has set it already. */
4236 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4237 {
4238 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4239 highlight_changed();
4240 }
4241}
4242#endif
4243
4244#ifdef FEAT_TITLE
4245/*
4246 * 'title' and 'icon' only default to true if they have not been set or reset
4247 * in .vimrc and we can read the old value.
4248 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4249 * they can be reset. This reduces startup time when using X on a remote
4250 * machine.
4251 */
4252 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004253set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004254{
4255 int idx1;
4256 long val;
4257
4258 /*
4259 * If GUI is (going to be) used, we can always set the window title and
4260 * icon name. Saves a bit of time, because the X11 display server does
4261 * not need to be contacted.
4262 */
4263 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004264 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004265 {
4266#ifdef FEAT_GUI
4267 if (gui.starting || gui.in_use)
4268 val = TRUE;
4269 else
4270#endif
4271 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004272 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004273 p_title = val;
4274 }
4275 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004276 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004277 {
4278#ifdef FEAT_GUI
4279 if (gui.starting || gui.in_use)
4280 val = TRUE;
4281 else
4282#endif
4283 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004284 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004285 p_icon = val;
4286 }
4287}
4288#endif
4289
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004290#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004291 static void
4292trigger_optionsset_string(
4293 int opt_idx,
4294 int opt_flags,
4295 char_u *oldval,
4296 char_u *newval)
4297{
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02004298 // Don't do this recursively.
4299 if (oldval != NULL && newval != NULL
4300 && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004301 {
4302 char_u buf_type[7];
4303
4304 sprintf((char *)buf_type, "%s",
4305 (opt_flags & OPT_LOCAL) ? "local" : "global");
4306 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4307 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4308 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4309 apply_autocmds(EVENT_OPTIONSET,
4310 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4311 reset_v_option_vars();
4312 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004313}
4314#endif
4315
Bram Moolenaar071d4272004-06-13 20:20:40 +00004316/*
4317 * Parse 'arg' for option settings.
4318 *
4319 * 'arg' may be IObuff, but only when no errors can be present and option
4320 * does not need to be expanded with option_expand().
4321 * "opt_flags":
4322 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004323 * OPT_GLOBAL for ":setglobal"
4324 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004325 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004326 * OPT_WINONLY to only set window-local options
4327 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004328 *
4329 * returns FAIL if an error is detected, OK otherwise
4330 */
4331 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004332do_set(
4333 char_u *arg, /* option string (may be written to!) */
4334 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004335{
4336 int opt_idx;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004337 char *errmsg;
4338 char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00004339 char_u *startarg;
4340 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4341 int nextchar; /* next non-white char after option name */
4342 int afterchar; /* character just after option name */
4343 int len;
4344 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004345 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004346 int key;
4347 long_u flags; /* flags for current option */
4348 char_u *varp = NULL; /* pointer to variable for current option */
4349 int did_show = FALSE; /* already showed one value */
4350 int adding; /* "opt+=arg" */
4351 int prepending; /* "opt^=arg" */
4352 int removing; /* "opt-=arg" */
4353 int cp_val = 0;
4354 char_u key_name[2];
4355
4356 if (*arg == NUL)
4357 {
4358 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004359 did_show = TRUE;
4360 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004361 }
4362
4363 while (*arg != NUL) /* loop to process all options */
4364 {
4365 errmsg = NULL;
4366 startarg = arg; /* remember for error message */
4367
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004368 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4369 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004370 {
4371 /*
4372 * ":set all" show all options.
4373 * ":set all&" set all options to their default value.
4374 */
4375 arg += 3;
4376 if (*arg == '&')
4377 {
4378 ++arg;
4379 /* Only for :set command set global value of local options. */
4380 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004381 didset_options();
4382 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004383 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004384 }
4385 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004386 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004387 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004388 did_show = TRUE;
4389 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004390 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004391 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004392 {
4393 showoptions(2, opt_flags);
4394 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004395 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004396 arg += 7;
4397 }
4398 else
4399 {
4400 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004401 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004402 {
4403 prefix = 0;
4404 arg += 2;
4405 }
4406 else if (STRNCMP(arg, "inv", 3) == 0)
4407 {
4408 prefix = 2;
4409 arg += 3;
4410 }
4411
4412 /* find end of name */
4413 key = 0;
4414 if (*arg == '<')
4415 {
4416 nextchar = 0;
4417 opt_idx = -1;
4418 /* look out for <t_>;> */
4419 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4420 len = 5;
4421 else
4422 {
4423 len = 1;
4424 while (arg[len] != NUL && arg[len] != '>')
4425 ++len;
4426 }
4427 if (arg[len] != '>')
4428 {
4429 errmsg = e_invarg;
4430 goto skip;
4431 }
4432 arg[len] = NUL; /* put NUL after name */
4433 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4434 opt_idx = findoption(arg + 1);
4435 arg[len++] = '>'; /* restore '>' */
4436 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004437 key = find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004438 }
4439 else
4440 {
4441 len = 0;
4442 /*
4443 * The two characters after "t_" may not be alphanumeric.
4444 */
4445 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4446 len = 4;
4447 else
4448 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4449 ++len;
4450 nextchar = arg[len];
4451 arg[len] = NUL; /* put NUL after name */
4452 opt_idx = findoption(arg);
4453 arg[len] = nextchar; /* restore nextchar */
4454 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004455 key = find_key_option(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004456 }
4457
4458 /* remember character after option name */
4459 afterchar = arg[len];
4460
4461 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004462 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004463 ++len;
4464
4465 adding = FALSE;
4466 prepending = FALSE;
4467 removing = FALSE;
4468 if (arg[len] != NUL && arg[len + 1] == '=')
4469 {
4470 if (arg[len] == '+')
4471 {
4472 adding = TRUE; /* "+=" */
4473 ++len;
4474 }
4475 else if (arg[len] == '^')
4476 {
4477 prepending = TRUE; /* "^=" */
4478 ++len;
4479 }
4480 else if (arg[len] == '-')
4481 {
4482 removing = TRUE; /* "-=" */
4483 ++len;
4484 }
4485 }
4486 nextchar = arg[len];
4487
4488 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4489 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004490 errmsg = N_("E518: Unknown option");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004491 goto skip;
4492 }
4493
4494 if (opt_idx >= 0)
4495 {
4496 if (options[opt_idx].var == NULL) /* hidden option: skip */
4497 {
4498 /* Only give an error message when requesting the value of
4499 * a hidden option, ignore setting it. */
4500 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4501 && (!(options[opt_idx].flags & P_BOOL)
4502 || nextchar == '?'))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004503 errmsg = N_("E519: Option not supported");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004504 goto skip;
4505 }
4506
4507 flags = options[opt_idx].flags;
4508 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4509 }
4510 else
4511 {
4512 flags = P_STRING;
4513 if (key < 0)
4514 {
4515 key_name[0] = KEY2TERMCAP0(key);
4516 key_name[1] = KEY2TERMCAP1(key);
4517 }
4518 else
4519 {
4520 key_name[0] = KS_KEY;
4521 key_name[1] = (key & 0xff);
4522 }
4523 }
4524
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004525 /* Skip all options that are not window-local (used when showing
4526 * an already loaded buffer in a window). */
4527 if ((opt_flags & OPT_WINONLY)
4528 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4529 goto skip;
4530
Bram Moolenaara3227e22006-03-08 21:32:40 +00004531 /* Skip all options that are window-local (used for :vimgrep). */
4532 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4533 && options[opt_idx].var == VAR_WIN)
4534 goto skip;
4535
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004536 /* Disallow changing some options from modelines. */
4537 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004538 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004539 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004540 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004541 errmsg = _("E520: Not allowed in a modeline");
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004542 goto skip;
4543 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004544#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004545 /* In diff mode some options are overruled. This avoids that
4546 * 'foldmethod' becomes "marker" instead of "diff" and that
4547 * "wrap" gets set. */
4548 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004549 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004550 && (
4551#ifdef FEAT_FOLDING
4552 options[opt_idx].indir == PV_FDM ||
4553#endif
4554 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004555 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004556#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004557 }
4558
4559#ifdef HAVE_SANDBOX
4560 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004561 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004562 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004563 errmsg = _(e_sandbox);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004564 goto skip;
4565 }
4566#endif
4567
4568 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4569 {
4570 arg += len;
4571 cp_val = p_cp;
4572 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4573 {
4574 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4575 {
4576 cp_val = FALSE;
4577 arg += 3;
4578 }
4579 else /* "opt&vi": set to Vi default */
4580 {
4581 cp_val = TRUE;
4582 arg += 2;
4583 }
4584 }
4585 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004586 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004587 {
4588 errmsg = e_trailing;
4589 goto skip;
4590 }
4591 }
4592
4593 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004594 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4595 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004596 */
4597 if (nextchar == '?'
4598 || (prefix == 1
4599 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4600 && !(flags & P_BOOL)))
4601 {
4602 /*
4603 * print value
4604 */
4605 if (did_show)
4606 msg_putchar('\n'); /* cursor below last one */
4607 else
4608 {
4609 gotocmdline(TRUE); /* cursor at status line */
4610 did_show = TRUE; /* remember that we did a line */
4611 }
4612 if (opt_idx >= 0)
4613 {
4614 showoneopt(&options[opt_idx], opt_flags);
4615#ifdef FEAT_EVAL
4616 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004617 {
4618 /* Mention where the option was last set. */
4619 if (varp == options[opt_idx].var)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004620 last_set_msg(options[opt_idx].script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004621 else if ((int)options[opt_idx].indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004622 last_set_msg(curwin->w_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004623 (int)options[opt_idx].indir & PV_MASK]);
4624 else if ((int)options[opt_idx].indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004625 last_set_msg(curbuf->b_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004626 (int)options[opt_idx].indir & PV_MASK]);
4627 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004628#endif
4629 }
4630 else
4631 {
4632 char_u *p;
4633
4634 p = find_termcode(key_name);
4635 if (p == NULL)
4636 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004637 errmsg = N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004638 goto skip;
4639 }
4640 else
4641 (void)show_one_termcode(key_name, p, TRUE);
4642 }
4643 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004644 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004645 errmsg = e_trailing;
4646 }
4647 else
4648 {
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004649 int value_is_replaced = !prepending && !adding && !removing;
Bram Moolenaar916a8182018-11-25 02:18:29 +01004650 int value_checked = FALSE;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004651
Bram Moolenaar071d4272004-06-13 20:20:40 +00004652 if (flags & P_BOOL) /* boolean */
4653 {
4654 if (nextchar == '=' || nextchar == ':')
4655 {
4656 errmsg = e_invarg;
4657 goto skip;
4658 }
4659
4660 /*
4661 * ":set opt!": invert
4662 * ":set opt&": reset to default value
4663 * ":set opt<": reset to global value
4664 */
4665 if (nextchar == '!')
4666 value = *(int *)(varp) ^ 1;
4667 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004668 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004669 ((flags & P_VI_DEF) || cp_val)
4670 ? VI_DEFAULT : VIM_DEFAULT];
4671 else if (nextchar == '<')
4672 {
4673 /* For 'autoread' -1 means to use global value. */
4674 if ((int *)varp == &curbuf->b_p_ar
4675 && opt_flags == OPT_LOCAL)
4676 value = -1;
4677 else
4678 value = *(int *)get_varp_scope(&(options[opt_idx]),
4679 OPT_GLOBAL);
4680 }
4681 else
4682 {
4683 /*
4684 * ":set invopt": invert
4685 * ":set opt" or ":set noopt": set or reset
4686 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004687 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004688 {
4689 errmsg = e_trailing;
4690 goto skip;
4691 }
4692 if (prefix == 2) /* inv */
4693 value = *(int *)(varp) ^ 1;
4694 else
4695 value = prefix;
4696 }
4697
4698 errmsg = set_bool_option(opt_idx, varp, (int)value,
4699 opt_flags);
4700 }
4701 else /* numeric or string */
4702 {
4703 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4704 || prefix != 1)
4705 {
4706 errmsg = e_invarg;
4707 goto skip;
4708 }
4709
4710 if (flags & P_NUM) /* numeric */
4711 {
4712 /*
4713 * Different ways to set a number option:
4714 * & set to default value
4715 * < set to global value
4716 * <xx> accept special key codes for 'wildchar'
4717 * c accept any non-digit for 'wildchar'
4718 * [-]0-9 set number
4719 * other error
4720 */
4721 ++arg;
4722 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004723 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004724 ((flags & P_VI_DEF) || cp_val)
4725 ? VI_DEFAULT : VIM_DEFAULT];
4726 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004727 {
4728 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4729 * use the global value. */
4730 if ((long *)varp == &curbuf->b_p_ul
4731 && opt_flags == OPT_LOCAL)
4732 value = NO_LOCAL_UNDOLEVEL;
4733 else
4734 value = *(long *)get_varp_scope(
4735 &(options[opt_idx]), OPT_GLOBAL);
4736 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004737 else if (((long *)varp == &p_wc
4738 || (long *)varp == &p_wcm)
4739 && (*arg == '<'
4740 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004741 || (*arg != NUL
4742 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004743 && !VIM_ISDIGIT(*arg))))
4744 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004745 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004746 if (value == 0 && (long *)varp != &p_wcm)
4747 {
4748 errmsg = e_invarg;
4749 goto skip;
4750 }
4751 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004752 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4753 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004754 /* Allow negative (for 'undolevels'), octal and
4755 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004756 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4757 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004758 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004759 {
4760 errmsg = e_invarg;
4761 goto skip;
4762 }
4763 }
4764 else
4765 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004766 errmsg = N_("E521: Number required after =");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004767 goto skip;
4768 }
4769
4770 if (adding)
4771 value = *(long *)varp + value;
4772 if (prepending)
4773 value = *(long *)varp * value;
4774 if (removing)
4775 value = *(long *)varp - value;
4776 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004777 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004778 }
4779 else if (opt_idx >= 0) /* string */
4780 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004781 char_u *save_arg = NULL;
4782 char_u *s = NULL;
4783 char_u *oldval = NULL; /* previous value if *varp */
4784 char_u *newval;
4785 char_u *origval = NULL;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004786#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004787 char_u *saved_origval = NULL;
4788 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004789#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004790 unsigned newlen;
4791 int comma;
4792 int bs;
4793 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004794 was allocated */
4795
4796 /* When using ":set opt=val" for a global option
4797 * with a local value the local value will be
4798 * reset, use the global value here. */
4799 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004800 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004801 varp = options[opt_idx].var;
4802
4803 /* The old value is kept until we are sure that the
4804 * new value is valid. */
4805 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004806
4807 /* When setting the local value of a global
4808 * option, the old value may be the global value. */
4809 if (((int)options[opt_idx].indir & PV_BOTH)
4810 && (opt_flags & OPT_LOCAL))
4811 origval = *(char_u **)get_varp(
4812 &options[opt_idx]);
4813 else
4814 origval = oldval;
4815
Bram Moolenaar071d4272004-06-13 20:20:40 +00004816 if (nextchar == '&') /* set to default val */
4817 {
4818 newval = options[opt_idx].def_val[
4819 ((flags & P_VI_DEF) || cp_val)
4820 ? VI_DEFAULT : VIM_DEFAULT];
4821 if ((char_u **)varp == &p_bg)
4822 {
4823 /* guess the value of 'background' */
4824#ifdef FEAT_GUI
4825 if (gui.in_use)
4826 newval = gui_bg_default();
4827 else
4828#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004829 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004830 }
4831
4832 /* expand environment variables and ~ (since the
4833 * default value was already expanded, only
4834 * required when an environment variable was set
4835 * later */
4836 if (newval == NULL)
4837 newval = empty_option;
4838 else
4839 {
4840 s = option_expand(opt_idx, newval);
4841 if (s == NULL)
4842 s = newval;
4843 newval = vim_strsave(s);
4844 }
4845 new_value_alloced = TRUE;
4846 }
4847 else if (nextchar == '<') /* set to global val */
4848 {
4849 newval = vim_strsave(*(char_u **)get_varp_scope(
4850 &(options[opt_idx]), OPT_GLOBAL));
4851 new_value_alloced = TRUE;
4852 }
4853 else
4854 {
4855 ++arg; /* jump to after the '=' or ':' */
4856
4857 /*
4858 * Set 'keywordprg' to ":help" if an empty
4859 * value was passed to :set by the user.
4860 * Misuse errbuf[] for the resulting string.
4861 */
4862 if (varp == (char_u *)&p_kp
4863 && (*arg == NUL || *arg == ' '))
4864 {
4865 STRCPY(errbuf, ":help");
4866 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004867 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004868 }
4869 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004870 * Convert 'backspace' number to string, for
4871 * adding, prepending and removing string.
4872 */
4873 else if (varp == (char_u *)&p_bs
4874 && VIM_ISDIGIT(**(char_u **)varp))
4875 {
4876 i = getdigits((char_u **)varp);
4877 switch (i)
4878 {
4879 case 0:
4880 *(char_u **)varp = empty_option;
4881 break;
4882 case 1:
4883 *(char_u **)varp = vim_strsave(
4884 (char_u *)"indent,eol");
4885 break;
4886 case 2:
4887 *(char_u **)varp = vim_strsave(
4888 (char_u *)"indent,eol,start");
4889 break;
4890 }
4891 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004892 if (origval == oldval)
4893 origval = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004894 oldval = *(char_u **)varp;
4895 }
4896 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004897 * Convert 'whichwrap' number to string, for
4898 * backwards compatibility with Vim 3.0.
4899 * Misuse errbuf[] for the resulting string.
4900 */
4901 else if (varp == (char_u *)&p_ww
4902 && VIM_ISDIGIT(*arg))
4903 {
4904 *errbuf = NUL;
4905 i = getdigits(&arg);
4906 if (i & 1)
4907 STRCAT(errbuf, "b,");
4908 if (i & 2)
4909 STRCAT(errbuf, "s,");
4910 if (i & 4)
4911 STRCAT(errbuf, "h,l,");
4912 if (i & 8)
4913 STRCAT(errbuf, "<,>,");
4914 if (i & 16)
4915 STRCAT(errbuf, "[,],");
4916 if (*errbuf != NUL) /* remove trailing , */
4917 errbuf[STRLEN(errbuf) - 1] = NUL;
4918 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004919 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004920 }
4921 /*
4922 * Remove '>' before 'dir' and 'bdir', for
4923 * backwards compatibility with version 3.0
4924 */
4925 else if ( *arg == '>'
4926 && (varp == (char_u *)&p_dir
4927 || varp == (char_u *)&p_bdir))
4928 {
4929 ++arg;
4930 }
4931
Bram Moolenaar071d4272004-06-13 20:20:40 +00004932 /*
4933 * Copy the new string into allocated memory.
4934 * Can't use set_string_option_direct(), because
4935 * we need to remove the backslashes.
4936 */
4937 /* get a bit too much */
4938 newlen = (unsigned)STRLEN(arg) + 1;
4939 if (adding || prepending || removing)
4940 newlen += (unsigned)STRLEN(origval) + 1;
4941 newval = alloc(newlen);
4942 if (newval == NULL) /* out of mem, don't change */
4943 break;
4944 s = newval;
4945
4946 /*
4947 * Copy the string, skip over escaped chars.
4948 * For MS-DOS and WIN32 backslashes before normal
4949 * file name characters are not removed, and keep
4950 * backslash at start, for "\\machine\path", but
4951 * do remove it for "\\\\machine\\path".
4952 * The reverse is found in ExpandOldSetting().
4953 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004954 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004955 {
4956 if (*arg == '\\' && arg[1] != NUL
4957#ifdef BACKSLASH_IN_FILENAME
4958 && !((flags & P_EXPAND)
4959 && vim_isfilec(arg[1])
4960 && (arg[1] != '\\'
4961 || (s == newval
4962 && arg[2] != '\\')))
4963#endif
4964 )
4965 ++arg; /* remove backslash */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004966 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004967 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004968 {
4969 /* copy multibyte char */
4970 mch_memmove(s, arg, (size_t)i);
4971 arg += i;
4972 s += i;
4973 }
4974 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004975 *s++ = *arg++;
4976 }
4977 *s = NUL;
4978
4979 /*
4980 * Expand environment variables and ~.
4981 * Don't do it when adding without inserting a
4982 * comma.
4983 */
4984 if (!(adding || prepending || removing)
4985 || (flags & P_COMMA))
4986 {
4987 s = option_expand(opt_idx, newval);
4988 if (s != NULL)
4989 {
4990 vim_free(newval);
4991 newlen = (unsigned)STRLEN(s) + 1;
4992 if (adding || prepending || removing)
4993 newlen += (unsigned)STRLEN(origval) + 1;
4994 newval = alloc(newlen);
4995 if (newval == NULL)
4996 break;
4997 STRCPY(newval, s);
4998 }
4999 }
5000
5001 /* locate newval[] in origval[] when removing it
5002 * and when adding to avoid duplicates */
5003 i = 0; /* init for GCC */
5004 if (removing || (flags & P_NODUP))
5005 {
5006 i = (int)STRLEN(newval);
5007 bs = 0;
5008 for (s = origval; *s; ++s)
5009 {
5010 if ((!(flags & P_COMMA)
5011 || s == origval
5012 || (s[-1] == ',' && !(bs & 1)))
5013 && STRNCMP(s, newval, i) == 0
5014 && (!(flags & P_COMMA)
5015 || s[i] == ','
5016 || s[i] == NUL))
5017 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005018 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005019 * even number of backslashes or a single
5020 * backslash preceded by a comma before it
5021 * is recognized as a separator */
5022 if ((s > origval + 1
5023 && s[-1] == '\\'
5024 && s[-2] != ',')
5025 || (s == origval + 1
5026 && s[-1] == '\\'))
5027
Bram Moolenaar071d4272004-06-13 20:20:40 +00005028 ++bs;
5029 else
5030 bs = 0;
5031 }
5032
5033 /* do not add if already there */
5034 if ((adding || prepending) && *s)
5035 {
5036 prepending = FALSE;
5037 adding = FALSE;
5038 STRCPY(newval, origval);
5039 }
5040 }
5041
5042 /* concatenate the two strings; add a ',' if
5043 * needed */
5044 if (adding || prepending)
5045 {
5046 comma = ((flags & P_COMMA) && *origval != NUL
5047 && *newval != NUL);
5048 if (adding)
5049 {
5050 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005051 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005052 if (comma && i > 1
5053 && (flags & P_ONECOMMA) == P_ONECOMMA
5054 && origval[i - 1] == ','
5055 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005056 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005057 mch_memmove(newval + i + comma, newval,
5058 STRLEN(newval) + 1);
5059 mch_memmove(newval, origval, (size_t)i);
5060 }
5061 else
5062 {
5063 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005064 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005065 }
5066 if (comma)
5067 newval[i] = ',';
5068 }
5069
5070 /* Remove newval[] from origval[]. (Note: "i" has
5071 * been set above and is used here). */
5072 if (removing)
5073 {
5074 STRCPY(newval, origval);
5075 if (*s)
5076 {
5077 /* may need to remove a comma */
5078 if (flags & P_COMMA)
5079 {
5080 if (s == origval)
5081 {
5082 /* include comma after string */
5083 if (s[i] == ',')
5084 ++i;
5085 }
5086 else
5087 {
5088 /* include comma before string */
5089 --s;
5090 ++i;
5091 }
5092 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005093 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005094 }
5095 }
5096
5097 if (flags & P_FLAGLIST)
5098 {
5099 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005100 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005101 {
5102 /* if options have P_FLAGLIST and
5103 * P_ONECOMMA such as 'whichwrap' */
5104 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005105 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005106 if (*s != ',' && *(s + 1) == ','
5107 && vim_strchr(s + 2, *s) != NULL)
5108 {
5109 /* Remove the duplicated value and
5110 * the next comma. */
5111 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005112 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005113 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005114 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005115 else
5116 {
5117 if ((!(flags & P_COMMA) || *s != ',')
5118 && vim_strchr(s + 1, *s) != NULL)
5119 {
5120 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005121 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005122 }
5123 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005124 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005125 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005126 }
5127
5128 if (save_arg != NULL) /* number for 'whichwrap' */
5129 arg = save_arg;
5130 new_value_alloced = TRUE;
5131 }
5132
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005133 /*
5134 * Set the new value.
5135 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005136 *(char_u **)(varp) = newval;
5137
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005138#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005139 if (!starting
5140# ifdef FEAT_CRYPT
5141 && options[opt_idx].indir != PV_KEY
5142# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005143 && origval != NULL && newval != NULL)
5144 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005145 /* origval may be freed by
5146 * did_set_string_option(), make a copy. */
5147 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005148 /* newval (and varp) may become invalid if the
5149 * buffer is closed by autocommands. */
5150 saved_newval = vim_strsave(newval);
5151 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005152#endif
5153
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005154 {
5155 long_u *p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005156 int secure_saved = secure;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005157
5158 // When an option is set in the sandbox, from a
5159 // modeline or in secure mode, then deal with side
5160 // effects in secure mode. Also when the value was
5161 // set with the P_INSECURE flag and is not
5162 // completely replaced.
5163 if (secure
5164#ifdef HAVE_SANDBOX
5165 || sandbox != 0
5166#endif
5167 || (opt_flags & OPT_MODELINE)
5168 || (!value_is_replaced && (*p & P_INSECURE)))
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005169 ++secure;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005170
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005171 // Handle side effects, and set the global value
5172 // for ":set" on local options. Note: when setting
5173 // 'syntax' or 'filetype' autocommands may be
5174 // triggered that can cause havoc.
5175 errmsg = did_set_string_option(
5176 opt_idx, (char_u **)varp,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005177 new_value_alloced, oldval, errbuf,
5178 opt_flags, &value_checked);
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005179
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005180 secure = secure_saved;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005181 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005182
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005183#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005184 if (errmsg == NULL)
5185 trigger_optionsset_string(opt_idx, opt_flags,
5186 saved_origval, saved_newval);
5187 vim_free(saved_origval);
5188 vim_free(saved_newval);
5189#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005190 /* If error detected, print the error message. */
5191 if (errmsg != NULL)
5192 goto skip;
5193 }
5194 else /* key code option */
5195 {
5196 char_u *p;
5197
5198 if (nextchar == '&')
5199 {
5200 if (add_termcap_entry(key_name, TRUE) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005201 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005202 }
5203 else
5204 {
5205 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005206 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005207 if (*p == '\\' && p[1] != NUL)
5208 ++p;
5209 nextchar = *p;
5210 *p = NUL;
5211 add_termcode(key_name, arg, FALSE);
5212 *p = nextchar;
5213 }
5214 if (full_screen)
5215 ttest(FALSE);
5216 redraw_all_later(CLEAR);
5217 }
5218 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005219
Bram Moolenaar071d4272004-06-13 20:20:40 +00005220 if (opt_idx >= 0)
Bram Moolenaar916a8182018-11-25 02:18:29 +01005221 did_set_option(
5222 opt_idx, opt_flags, value_is_replaced, value_checked);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005223 }
5224
5225skip:
5226 /*
5227 * Advance to next argument.
5228 * - skip until a blank found, taking care of backslashes
5229 * - skip blanks
5230 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5231 */
5232 for (i = 0; i < 2 ; ++i)
5233 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005234 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005235 if (*arg++ == '\\' && *arg != NUL)
5236 ++arg;
5237 arg = skipwhite(arg);
5238 if (*arg != '=')
5239 break;
5240 }
5241 }
5242
5243 if (errmsg != NULL)
5244 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005245 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005246 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005247 if (i + (arg - startarg) < IOSIZE)
5248 {
5249 /* append the argument with the error */
5250 STRCAT(IObuff, ": ");
5251 mch_memmove(IObuff + i, startarg, (arg - startarg));
5252 IObuff[i + (arg - startarg)] = NUL;
5253 }
5254 /* make sure all characters are printable */
5255 trans_characters(IObuff, IOSIZE);
5256
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005257 ++no_wait_return; // wait_return done later
5258 emsg((char *)IObuff); // show error highlighted
Bram Moolenaar071d4272004-06-13 20:20:40 +00005259 --no_wait_return;
5260
5261 return FAIL;
5262 }
5263
5264 arg = skipwhite(arg);
5265 }
5266
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005267theend:
5268 if (silent_mode && did_show)
5269 {
5270 /* After displaying option values in silent mode. */
5271 silent_mode = FALSE;
5272 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5273 msg_putchar('\n');
5274 cursor_on(); /* msg_start() switches it off */
5275 out_flush();
5276 silent_mode = TRUE;
5277 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5278 }
5279
Bram Moolenaar071d4272004-06-13 20:20:40 +00005280 return OK;
5281}
5282
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005283/*
5284 * Call this when an option has been given a new value through a user command.
5285 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5286 */
5287 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005288did_set_option(
5289 int opt_idx,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005290 int opt_flags, // possibly with OPT_MODELINE
5291 int new_value, // value was replaced completely
5292 int value_checked) // value was checked to be safe, no need to set the
5293 // P_INSECURE flag.
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005294{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005295 long_u *p;
5296
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005297 options[opt_idx].flags |= P_WAS_SET;
5298
5299 /* When an option is set in the sandbox, from a modeline or in secure mode
5300 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005301 * flag. */
5302 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar916a8182018-11-25 02:18:29 +01005303 if (!value_checked && (secure
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005304#ifdef HAVE_SANDBOX
5305 || sandbox != 0
5306#endif
Bram Moolenaar916a8182018-11-25 02:18:29 +01005307 || (opt_flags & OPT_MODELINE)))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005308 *p = *p | P_INSECURE;
5309 else if (new_value)
5310 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005311}
5312
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005313 static char *
5314illegal_char(char *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005315{
5316 if (errbuf == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005317 return "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00005318 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005319 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005320 return errbuf;
5321}
5322
5323/*
5324 * Convert a key name or string into a key value.
5325 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005326 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005327 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005328 int
5329string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005330{
5331 if (*arg == '<')
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02005332 return find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005333 if (*arg == '^')
5334 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005335 if (multi_byte)
5336 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005337 return *arg;
5338}
5339
5340#ifdef FEAT_CMDWIN
5341/*
5342 * Check value of 'cedit' and set cedit_key.
5343 * Returns NULL if value is OK, error message otherwise.
5344 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005345 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005346check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005347{
5348 int n;
5349
5350 if (*p_cedit == NUL)
5351 cedit_key = -1;
5352 else
5353 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005354 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005355 if (vim_isprintc(n))
5356 return e_invarg;
5357 cedit_key = n;
5358 }
5359 return NULL;
5360}
5361#endif
5362
5363#ifdef FEAT_TITLE
5364/*
5365 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5366 * maketitle() to create and display it.
5367 * When switching the title or icon off, call mch_restore_title() to get
5368 * the old value back.
5369 */
5370 static void
Bram Moolenaar84a93082018-06-16 22:58:15 +02005371did_set_title(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005372{
5373 if (starting != NO_SCREEN
5374#ifdef FEAT_GUI
5375 && !gui.starting
5376#endif
5377 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00005378 maketitle();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005379}
5380#endif
5381
5382/*
5383 * set_options_bin - called when 'bin' changes value.
5384 */
5385 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005386set_options_bin(
5387 int oldval,
5388 int newval,
5389 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005390{
5391 /*
5392 * The option values that are changed when 'bin' changes are
5393 * copied when 'bin is set and restored when 'bin' is reset.
5394 */
5395 if (newval)
5396 {
5397 if (!oldval) /* switched on */
5398 {
5399 if (!(opt_flags & OPT_GLOBAL))
5400 {
5401 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5402 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5403 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5404 curbuf->b_p_et_nobin = curbuf->b_p_et;
5405 }
5406 if (!(opt_flags & OPT_LOCAL))
5407 {
5408 p_tw_nobin = p_tw;
5409 p_wm_nobin = p_wm;
5410 p_ml_nobin = p_ml;
5411 p_et_nobin = p_et;
5412 }
5413 }
5414
5415 if (!(opt_flags & OPT_GLOBAL))
5416 {
5417 curbuf->b_p_tw = 0; /* no automatic line wrap */
5418 curbuf->b_p_wm = 0; /* no automatic line wrap */
5419 curbuf->b_p_ml = 0; /* no modelines */
5420 curbuf->b_p_et = 0; /* no expandtab */
5421 }
5422 if (!(opt_flags & OPT_LOCAL))
5423 {
5424 p_tw = 0;
5425 p_wm = 0;
5426 p_ml = FALSE;
5427 p_et = FALSE;
5428 p_bin = TRUE; /* needed when called for the "-b" argument */
5429 }
5430 }
5431 else if (oldval) /* switched off */
5432 {
5433 if (!(opt_flags & OPT_GLOBAL))
5434 {
5435 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5436 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5437 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5438 curbuf->b_p_et = curbuf->b_p_et_nobin;
5439 }
5440 if (!(opt_flags & OPT_LOCAL))
5441 {
5442 p_tw = p_tw_nobin;
5443 p_wm = p_wm_nobin;
5444 p_ml = p_ml_nobin;
5445 p_et = p_et_nobin;
5446 }
5447 }
5448}
5449
5450#ifdef FEAT_VIMINFO
5451/*
5452 * Find the parameter represented by the given character (eg ', :, ", or /),
5453 * and return its associated value in the 'viminfo' string.
5454 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005455 * If the parameter is not specified in the string or there is no following
5456 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005457 */
5458 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005459get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005460{
5461 char_u *p;
5462
5463 p = find_viminfo_parameter(type);
5464 if (p != NULL && VIM_ISDIGIT(*p))
5465 return atoi((char *)p);
5466 return -1;
5467}
5468
5469/*
5470 * Find the parameter represented by the given character (eg ''', ':', '"', or
5471 * '/') in the 'viminfo' option and return a pointer to the string after it.
5472 * Return NULL if the parameter is not specified in the string.
5473 */
5474 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005475find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005476{
5477 char_u *p;
5478
5479 for (p = p_viminfo; *p; ++p)
5480 {
5481 if (*p == type)
5482 return p + 1;
5483 if (*p == 'n') /* 'n' is always the last one */
5484 break;
5485 p = vim_strchr(p, ','); /* skip until next ',' */
5486 if (p == NULL) /* hit the end without finding parameter */
5487 break;
5488 }
5489 return NULL;
5490}
5491#endif
5492
5493/*
5494 * Expand environment variables for some string options.
5495 * These string options cannot be indirect!
5496 * If "val" is NULL expand the current value of the option.
5497 * Return pointer to NameBuff, or NULL when not expanded.
5498 */
5499 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005500option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005501{
5502 /* if option doesn't need expansion nothing to do */
5503 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5504 return NULL;
5505
5506 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5507 * expand_env() would truncate the string. */
5508 if (val != NULL && STRLEN(val) > MAXPATHL)
5509 return NULL;
5510
5511 if (val == NULL)
5512 val = *(char_u **)options[opt_idx].var;
5513
5514 /*
5515 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5516 * Escape spaces when expanding 'tags', they are used to separate file
5517 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005518 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005519 */
5520 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005521 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005522#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005523 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5524#endif
5525 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005526 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5527 return NULL;
5528
5529 return NameBuff;
5530}
5531
5532/*
5533 * After setting various option values: recompute variables that depend on
5534 * option values.
5535 */
5536 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005537didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005538{
5539 /* initialize the table for 'iskeyword' et.al. */
5540 (void)init_chartab();
5541
5542 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
5543 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005544 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005545#ifdef FEAT_SESSION
5546 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5547 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5548#endif
5549#ifdef FEAT_FOLDING
5550 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5551#endif
5552 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005553 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005554 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005555#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5556 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5557#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005558#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005559 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005560 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005561 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005562 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005563#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005564#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5565 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5566#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005567#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005568 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5569#endif
5570#ifdef FEAT_CMDWIN
5571 /* set cedit_key */
5572 (void)check_cedit();
5573#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005574#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005575 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005576#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005577#ifdef FEAT_LINEBREAK
5578 /* initialize the table for 'breakat'. */
5579 fill_breakat_flags();
5580#endif
5581
5582}
5583
5584/*
5585 * More side effects of setting options.
5586 */
5587 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005588didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005589{
5590 /* Initialize the highlight_attr[] table. */
5591 (void)highlight_changed();
5592
5593 /* Parse default for 'wildmode' */
5594 check_opt_wim();
5595
5596 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005597 /* Parse default for 'fillchars'. */
5598 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005599
5600#ifdef FEAT_CLIPBOARD
5601 /* Parse default for 'clipboard' */
5602 (void)check_clipboard_option();
5603#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005604#ifdef FEAT_VARTABS
5605 tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_array);
5606 tabstop_set(curbuf->b_p_vts, &curbuf->b_p_vts_array);
5607#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005608}
5609
5610/*
5611 * Check for string options that are NULL (normally only termcap options).
5612 */
5613 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005614check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005615{
5616 int opt_idx;
5617
5618 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5619 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5620 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5621}
5622
5623/*
5624 * Check string options in a buffer for NULL value.
5625 */
5626 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005627check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005628{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005629 check_string_option(&buf->b_p_bh);
5630 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005631 check_string_option(&buf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005632 check_string_option(&buf->b_p_ff);
5633#ifdef FEAT_FIND_ID
5634 check_string_option(&buf->b_p_def);
5635 check_string_option(&buf->b_p_inc);
5636# ifdef FEAT_EVAL
5637 check_string_option(&buf->b_p_inex);
5638# endif
5639#endif
5640#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5641 check_string_option(&buf->b_p_inde);
5642 check_string_option(&buf->b_p_indk);
5643#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005644#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5645 check_string_option(&buf->b_p_bexpr);
5646#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005647#if defined(FEAT_CRYPT)
5648 check_string_option(&buf->b_p_cm);
5649#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005650 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005651#if defined(FEAT_EVAL)
5652 check_string_option(&buf->b_p_fex);
5653#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005654#ifdef FEAT_CRYPT
5655 check_string_option(&buf->b_p_key);
5656#endif
5657 check_string_option(&buf->b_p_kp);
5658 check_string_option(&buf->b_p_mps);
5659 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005660 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005661 check_string_option(&buf->b_p_isk);
5662#ifdef FEAT_COMMENTS
5663 check_string_option(&buf->b_p_com);
5664#endif
5665#ifdef FEAT_FOLDING
5666 check_string_option(&buf->b_p_cms);
5667#endif
5668 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005669#ifdef FEAT_TEXTOBJ
5670 check_string_option(&buf->b_p_qe);
5671#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005672#ifdef FEAT_SYN_HL
5673 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005674 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005675#endif
5676#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005677 check_string_option(&buf->b_s.b_p_spc);
5678 check_string_option(&buf->b_s.b_p_spf);
5679 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005680#endif
5681#ifdef FEAT_SEARCHPATH
5682 check_string_option(&buf->b_p_sua);
5683#endif
5684#ifdef FEAT_CINDENT
5685 check_string_option(&buf->b_p_cink);
5686 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005687 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005688#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005689 check_string_option(&buf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005690#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5691 check_string_option(&buf->b_p_cinw);
5692#endif
5693#ifdef FEAT_INS_EXPAND
5694 check_string_option(&buf->b_p_cpt);
5695#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005696#ifdef FEAT_COMPL_FUNC
5697 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005698 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005699#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005700#ifdef FEAT_KEYMAP
5701 check_string_option(&buf->b_p_keymap);
5702#endif
5703#ifdef FEAT_QUICKFIX
5704 check_string_option(&buf->b_p_gp);
5705 check_string_option(&buf->b_p_mp);
5706 check_string_option(&buf->b_p_efm);
5707#endif
5708 check_string_option(&buf->b_p_ep);
5709 check_string_option(&buf->b_p_path);
5710 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005711 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005712#ifdef FEAT_INS_EXPAND
5713 check_string_option(&buf->b_p_dict);
5714 check_string_option(&buf->b_p_tsr);
5715#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005716#ifdef FEAT_LISP
5717 check_string_option(&buf->b_p_lw);
5718#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005719 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005720 check_string_option(&buf->b_p_menc);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005721#ifdef FEAT_VARTABS
5722 check_string_option(&buf->b_p_vsts);
5723 check_string_option(&buf->b_p_vts);
5724#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005725}
5726
5727/*
5728 * Free the string allocated for an option.
5729 * Checks for the string being empty_option. This may happen if we're out of
5730 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5731 * check_options().
5732 * Does NOT check for P_ALLOCED flag!
5733 */
5734 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005735free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005736{
5737 if (p != empty_option)
5738 vim_free(p);
5739}
5740
5741 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005742clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005743{
5744 if (*pp != empty_option)
5745 vim_free(*pp);
5746 *pp = empty_option;
5747}
5748
5749 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005750check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005751{
5752 if (*pp == NULL)
5753 *pp = empty_option;
5754}
5755
5756/*
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005757 * Return the option index found by a pointer into term_strings[].
5758 * Return -1 if not found.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005759 */
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005760 int
5761get_term_opt_idx(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005762{
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005763 int opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005764
5765 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5766 if (options[opt_idx].var == (char_u *)p)
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005767 return opt_idx;
5768 return -1; // cannot happen: didn't find it!
5769}
5770
5771/*
5772 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5773 * Return the option index or -1 if not found.
5774 */
5775 int
5776set_term_option_alloced(char_u **p)
5777{
5778 int opt_idx = get_term_opt_idx(p);
5779
5780 if (opt_idx >= 0)
5781 options[opt_idx].flags |= P_ALLOCED;
5782 return opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005783}
5784
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005785#if defined(FEAT_EVAL) || defined(PROTO)
5786/*
5787 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5788 * Return FALSE when it wasn't.
5789 * Return -1 for an unknown option.
5790 */
5791 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005792was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005793{
5794 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005795 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005796
5797 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005798 {
5799 flagp = insecure_flag(idx, opt_flags);
5800 return (*flagp & P_INSECURE) != 0;
5801 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005802 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005803 return -1;
5804}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005805
5806/*
5807 * Get a pointer to the flags used for the P_INSECURE flag of option
5808 * "opt_idx". For some local options a local flags field is used.
5809 */
5810 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005811insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005812{
5813 if (opt_flags & OPT_LOCAL)
5814 switch ((int)options[opt_idx].indir)
5815 {
5816#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005817 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005818#endif
5819#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005820# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005821 case PV_FDE: return &curwin->w_p_fde_flags;
5822 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005823# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005824# ifdef FEAT_BEVAL
5825 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5826# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005827# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005828 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005829# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005830 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005831# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005832 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005833# endif
5834#endif
5835 }
5836
5837 /* Nothing special, return global flags field. */
5838 return &options[opt_idx].flags;
5839}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005840#endif
5841
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005842#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005843/*
5844 * Redraw the window title and/or tab page text later.
5845 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005846static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005847{
5848 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005849 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005850}
5851#endif
5852
Bram Moolenaar071d4272004-06-13 20:20:40 +00005853/*
5854 * Set a string option to a new value (without checking the effect).
5855 * The string is copied into allocated memory.
5856 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005857 * When "set_sid" is zero set the scriptID to current_sctx.sc_sid. When
5858 * "set_sid" is SID_NONE don't set the scriptID. Otherwise set the scriptID to
5859 * "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005860 */
5861 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005862set_string_option_direct(
5863 char_u *name,
5864 int opt_idx,
5865 char_u *val,
5866 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5867 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005868{
5869 char_u *s;
5870 char_u **varp;
5871 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005872 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005873
Bram Moolenaar89d40322006-08-29 15:30:07 +00005874 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005875 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005876 idx = findoption(name);
5877 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005878 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005879 semsg(_(e_intern2), "set_string_option_direct()");
5880 siemsg(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005881 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005882 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005883 }
5884
Bram Moolenaar89d40322006-08-29 15:30:07 +00005885 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005886 return;
5887
5888 s = vim_strsave(val);
5889 if (s != NULL)
5890 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005891 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005892 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005893 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005894 free_string_option(*varp);
5895 *varp = s;
5896
5897 /* For buffer/window local option may also set the global value. */
5898 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005899 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005900
Bram Moolenaar89d40322006-08-29 15:30:07 +00005901 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005902
5903 /* When setting both values of a global option with a local value,
5904 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005905 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005906 {
5907 free_string_option(*varp);
5908 *varp = empty_option;
5909 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005910# ifdef FEAT_EVAL
5911 if (set_sid != SID_NONE)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005912 {
5913 sctx_T script_ctx;
5914
5915 if (set_sid == 0)
5916 script_ctx = current_sctx;
5917 else
5918 {
5919 script_ctx.sc_sid = set_sid;
Bram Moolenaarded5f1b2018-11-10 17:33:29 +01005920 script_ctx.sc_seq = 0;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005921 script_ctx.sc_lnum = 0;
5922 }
5923 set_option_sctx_idx(idx, opt_flags, script_ctx);
5924 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005925# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005926 }
5927}
5928
5929/*
5930 * Set global value for string option when it's a local option.
5931 */
5932 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005933set_string_option_global(
5934 int opt_idx, /* option index */
5935 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005936{
5937 char_u **p, *s;
5938
5939 /* the global value is always allocated */
5940 if (options[opt_idx].var == VAR_WIN)
5941 p = (char_u **)GLOBAL_WO(varp);
5942 else
5943 p = (char_u **)options[opt_idx].var;
5944 if (options[opt_idx].indir != PV_NONE
5945 && p != varp
5946 && (s = vim_strsave(*varp)) != NULL)
5947 {
5948 free_string_option(*p);
5949 *p = s;
5950 }
5951}
5952
5953/*
5954 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005955 *
5956 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005957 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005958 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005959set_string_option(
5960 int opt_idx,
5961 char_u *value,
5962 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005963{
5964 char_u *s;
5965 char_u **varp;
5966 char_u *oldval;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005967#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02005968 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005969 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02005970#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005971 char *r = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01005972 int value_checked = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005973
5974 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005975 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005976
5977 s = vim_strsave(value);
5978 if (s != NULL)
5979 {
5980 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5981 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005982 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005983 ? OPT_GLOBAL : OPT_LOCAL)
5984 : opt_flags);
5985 oldval = *varp;
5986 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005987
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005988#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005989 if (!starting
5990# ifdef FEAT_CRYPT
5991 && options[opt_idx].indir != PV_KEY
5992# endif
5993 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005994 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005995 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005996 saved_newval = vim_strsave(s);
5997 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005998#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005999 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
Bram Moolenaar916a8182018-11-25 02:18:29 +01006000 opt_flags, &value_checked)) == NULL)
6001 did_set_option(opt_idx, opt_flags, TRUE, value_checked);
Bram Moolenaar53744302015-07-17 17:38:22 +02006002
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006003#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006004 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006005 if (r == NULL)
6006 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006007 saved_oldval, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006008 vim_free(saved_oldval);
6009 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02006010#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006011 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006012 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006013}
6014
6015/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01006016 * Return TRUE if "val" is a valid 'filetype' name.
6017 * Also used for 'syntax' and 'keymap'.
6018 */
6019 static int
6020valid_filetype(char_u *val)
6021{
6022 char_u *s;
6023
6024 for (s = val; *s != NUL; ++s)
6025 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
6026 return FALSE;
6027 return TRUE;
6028}
6029
6030/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006031 * Handle string options that need some action to perform when changed.
6032 * Returns NULL for success, or an error message for an error.
6033 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006034 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006035did_set_string_option(
Bram Moolenaar916a8182018-11-25 02:18:29 +01006036 int opt_idx, // index in options[] table
6037 char_u **varp, // pointer to the option variable
6038 int new_value_alloced, // new value was allocated
6039 char_u *oldval, // previous value of the option
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006040 char *errbuf, // buffer for errors, or NULL
Bram Moolenaar916a8182018-11-25 02:18:29 +01006041 int opt_flags, // OPT_LOCAL and/or OPT_GLOBAL
6042 int *value_checked) // value was checked to be save, no
6043 // need to set P_INSECURE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006044{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006045 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006046 char_u *s, *p;
6047 int did_chartab = FALSE;
6048 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006049 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006050#ifdef FEAT_GUI
6051 /* set when changing an option that only requires a redraw in the GUI */
6052 int redraw_gui_only = FALSE;
6053#endif
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02006054 int value_changed = FALSE;
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006055#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6056 int did_swaptcap = FALSE;
6057#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006058
6059 /* Get the global option to compare with, otherwise we would have to check
6060 * two values for all local options. */
6061 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6062
6063 /* Disallow changing some options from secure mode */
6064 if ((secure
6065#ifdef HAVE_SANDBOX
6066 || sandbox != 0
6067#endif
6068 ) && (options[opt_idx].flags & P_SECURE))
6069 {
6070 errmsg = e_secure;
6071 }
6072
Bram Moolenaar916a8182018-11-25 02:18:29 +01006073 // Check for a "normal" directory or file name in some options. Disallow a
6074 // path separator (slash and/or backslash), wildcards and characters that
6075 // are often illegal in a file name. Be more permissive if "secure" is off.
Bram Moolenaar7554da42016-11-25 22:04:13 +01006076 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006077 && vim_strpbrk(*varp, (char_u *)(secure
6078 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006079 || ((options[opt_idx].flags & P_NDNAME)
6080 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006081 {
6082 errmsg = e_invarg;
6083 }
6084
Bram Moolenaar071d4272004-06-13 20:20:40 +00006085 /* 'term' */
6086 else if (varp == &T_NAME)
6087 {
6088 if (T_NAME[0] == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006089 errmsg = N_("E529: Cannot set 'term' to empty string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006090#ifdef FEAT_GUI
6091 if (gui.in_use)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006092 errmsg = N_("E530: Cannot change term in GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006093 else if (term_is_gui(T_NAME))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006094 errmsg = N_("E531: Use \":gui\" to start the GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006095#endif
6096 else if (set_termname(T_NAME) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006097 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006098 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006099 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006100 /* Screen colors may have changed. */
6101 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006102
6103 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6104 * P_ALLOCED flag on 'term'. */
6105 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006106 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006107 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006108 }
6109
6110 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006111 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006112 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006113 char_u *bkc = p_bkc;
6114 unsigned int *flags = &bkc_flags;
6115
6116 if (opt_flags & OPT_LOCAL)
6117 {
6118 bkc = curbuf->b_p_bkc;
6119 flags = &curbuf->b_bkc_flags;
6120 }
6121
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006122 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6123 /* make the local value empty: use the global value */
6124 *flags = 0;
6125 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006126 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006127 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6128 errmsg = e_invarg;
6129 if ((((int)*flags & BKC_AUTO) != 0)
6130 + (((int)*flags & BKC_YES) != 0)
6131 + (((int)*flags & BKC_NO) != 0) != 1)
6132 {
6133 /* Must have exactly one of "auto", "yes" and "no". */
6134 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6135 errmsg = e_invarg;
6136 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006137 }
6138 }
6139
6140 /* 'backupext' and 'patchmode' */
6141 else if (varp == &p_bex || varp == &p_pm)
6142 {
6143 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6144 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006145 errmsg = N_("E589: 'backupext' and 'patchmode' are equal");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006146 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006147#ifdef FEAT_LINEBREAK
6148 /* 'breakindentopt' */
6149 else if (varp == &curwin->w_p_briopt)
6150 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006151 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006152 errmsg = e_invarg;
6153 }
6154#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006155
6156 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006157 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006158 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006159 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006160 */
6161 else if ( varp == &p_isi
6162 || varp == &(curbuf->b_p_isk)
6163 || varp == &p_isp
6164 || varp == &p_isf)
6165 {
6166 if (init_chartab() == FAIL)
6167 {
6168 did_chartab = TRUE; /* need to restore it below */
6169 errmsg = e_invarg; /* error in value */
6170 }
6171 }
6172
6173 /* 'helpfile' */
6174 else if (varp == &p_hf)
6175 {
6176 /* May compute new values for $VIM and $VIMRUNTIME */
6177 if (didset_vim)
6178 {
6179 vim_setenv((char_u *)"VIM", (char_u *)"");
6180 didset_vim = FALSE;
6181 }
6182 if (didset_vimruntime)
6183 {
6184 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6185 didset_vimruntime = FALSE;
6186 }
6187 }
6188
Bram Moolenaar1a384422010-07-14 19:53:30 +02006189#ifdef FEAT_SYN_HL
6190 /* 'colorcolumn' */
6191 else if (varp == &curwin->w_p_cc)
6192 errmsg = check_colorcolumn(curwin);
6193#endif
6194
Bram Moolenaar071d4272004-06-13 20:20:40 +00006195#ifdef FEAT_MULTI_LANG
6196 /* 'helplang' */
6197 else if (varp == &p_hlg)
6198 {
6199 /* Check for "", "ab", "ab,cd", etc. */
6200 for (s = p_hlg; *s != NUL; s += 3)
6201 {
6202 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6203 {
6204 errmsg = e_invarg;
6205 break;
6206 }
6207 if (s[2] == NUL)
6208 break;
6209 }
6210 }
6211#endif
6212
6213 /* 'highlight' */
6214 else if (varp == &p_hl)
6215 {
6216 if (highlight_changed() == FAIL)
6217 errmsg = e_invarg; /* invalid flags */
6218 }
6219
6220 /* 'nrformats' */
6221 else if (gvarp == &p_nf)
6222 {
6223 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6224 errmsg = e_invarg;
6225 }
6226
6227#ifdef FEAT_SESSION
6228 /* 'sessionoptions' */
6229 else if (varp == &p_ssop)
6230 {
6231 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6232 errmsg = e_invarg;
6233 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6234 {
6235 /* Don't allow both "sesdir" and "curdir". */
6236 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6237 errmsg = e_invarg;
6238 }
6239 }
6240 /* 'viewoptions' */
6241 else if (varp == &p_vop)
6242 {
6243 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6244 errmsg = e_invarg;
6245 }
6246#endif
6247
6248 /* 'scrollopt' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006249 else if (varp == &p_sbo)
6250 {
6251 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6252 errmsg = e_invarg;
6253 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006254
6255 /* 'ambiwidth' */
Bram Moolenaar3848e002016-03-19 18:42:29 +01006256 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006257 {
6258 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6259 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006260 else if (set_chars_option(&p_lcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006261 errmsg = _("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006262 else if (set_chars_option(&p_fcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006263 errmsg = _("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006264 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006265
6266 /* 'background' */
6267 else if (varp == &p_bg)
6268 {
6269 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6270 {
6271#ifdef FEAT_EVAL
6272 int dark = (*p_bg == 'd');
6273#endif
6274
6275 init_highlight(FALSE, FALSE);
6276
6277#ifdef FEAT_EVAL
6278 if (dark != (*p_bg == 'd')
6279 && get_var_value((char_u *)"g:colors_name") != NULL)
6280 {
6281 /* The color scheme must have set 'background' back to another
6282 * value, that's not what we want here. Disable the color
6283 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006284 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006285 free_string_option(p_bg);
6286 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6287 check_string_option(&p_bg);
6288 init_highlight(FALSE, FALSE);
6289 }
6290#endif
6291 }
6292 else
6293 errmsg = e_invarg;
6294 }
6295
6296 /* 'wildmode' */
6297 else if (varp == &p_wim)
6298 {
6299 if (check_opt_wim() == FAIL)
6300 errmsg = e_invarg;
6301 }
6302
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006303#ifdef FEAT_CMDL_COMPL
6304 /* 'wildoptions' */
6305 else if (varp == &p_wop)
6306 {
6307 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6308 errmsg = e_invarg;
6309 }
6310#endif
6311
Bram Moolenaar071d4272004-06-13 20:20:40 +00006312#ifdef FEAT_WAK
6313 /* 'winaltkeys' */
6314 else if (varp == &p_wak)
6315 {
6316 if (*p_wak == NUL
6317 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6318 errmsg = e_invarg;
6319# ifdef FEAT_MENU
6320# ifdef FEAT_GUI_MOTIF
6321 else if (gui.in_use)
6322 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6323# else
6324# ifdef FEAT_GUI_GTK
6325 else if (gui.in_use)
6326 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6327# endif
6328# endif
6329# endif
6330 }
6331#endif
6332
Bram Moolenaar071d4272004-06-13 20:20:40 +00006333 /* 'eventignore' */
6334 else if (varp == &p_ei)
6335 {
6336 if (check_ei() == FAIL)
6337 errmsg = e_invarg;
6338 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006339
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006340 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6341 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6342 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006343 {
6344 if (gvarp == &p_fenc)
6345 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006346 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006347 errmsg = e_modifiable;
6348 else if (vim_strchr(*varp, ',') != NULL)
6349 /* No comma allowed in 'fileencoding'; catches confusing it
6350 * with 'fileencodings'. */
6351 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006352 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006353 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006354#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006355 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006356 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006357#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006358 /* Add 'fileencoding' to the swap file. */
6359 ml_setflags(curbuf);
6360 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006361 }
6362 if (errmsg == NULL)
6363 {
6364 /* canonize the value, so that STRCMP() can be used on it */
6365 p = enc_canonize(*varp);
6366 if (p != NULL)
6367 {
6368 vim_free(*varp);
6369 *varp = p;
6370 }
6371 if (varp == &p_enc)
6372 {
6373 errmsg = mb_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006374#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006375 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006376#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006377 }
6378 }
6379
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006380#if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006381 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6382 {
6383 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6384 if (STRCMP(p_tenc, "utf-8") != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006385 errmsg = N_("E617: Cannot be changed in the GTK+ 2 GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006386 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006387#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006388
6389 if (errmsg == NULL)
6390 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006391#ifdef FEAT_KEYMAP
Bram Moolenaar071d4272004-06-13 20:20:40 +00006392 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6393 * (with another encoding). */
6394 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6395 (void)keymap_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006396#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006397
6398 /* When 'termencoding' is not empty and 'encoding' changes or when
6399 * 'termencoding' changes, need to setup for keyboard input and
6400 * display output conversion. */
6401 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6402 {
Bram Moolenaar17471e82017-11-26 23:47:18 +01006403 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6404 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6405 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006406 semsg(_("E950: Cannot convert between %s and %s"),
Bram Moolenaar17471e82017-11-26 23:47:18 +01006407 p_tenc, p_enc);
6408 errmsg = e_invarg;
6409 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006410 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006411
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006412#if defined(WIN3264)
Bram Moolenaar05159a02005-02-26 23:04:13 +00006413 /* $HOME may have characters in active code page. */
6414 if (varp == &p_enc)
6415 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006416#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006417 }
6418 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006419
6420#if defined(FEAT_POSTSCRIPT)
6421 else if (varp == &p_penc)
6422 {
6423 /* Canonize printencoding if VIM standard one */
6424 p = enc_canonize(p_penc);
6425 if (p != NULL)
6426 {
6427 vim_free(p_penc);
6428 p_penc = p;
6429 }
6430 else
6431 {
6432 /* Ensure lower case and '-' for '_' */
6433 for (s = p_penc; *s != NUL; s++)
6434 {
6435 if (*s == '_')
6436 *s = '-';
6437 else
6438 *s = TOLOWER_ASC(*s);
6439 }
6440 }
6441 }
6442#endif
6443
Bram Moolenaar9372a112005-12-06 19:59:18 +00006444#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006445 else if (varp == &p_imak)
6446 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006447 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006448 errmsg = e_invarg;
6449 }
6450#endif
6451
6452#ifdef FEAT_KEYMAP
6453 else if (varp == &curbuf->b_p_keymap)
6454 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006455 if (!valid_filetype(*varp))
6456 errmsg = e_invarg;
6457 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01006458 {
6459 int secure_save = secure;
6460
6461 // Reset the secure flag, since the value of 'keymap' has
6462 // been checked to be safe.
6463 secure = 0;
6464
6465 // load or unload key mapping tables
Bram Moolenaard0b51382016-11-04 15:23:45 +01006466 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006467
Bram Moolenaar916a8182018-11-25 02:18:29 +01006468 secure = secure_save;
6469
6470 // Since we check the value, there is no need to set P_INSECURE,
6471 // even when the value comes from a modeline.
6472 *value_checked = TRUE;
6473 }
6474
Bram Moolenaarfab06232009-03-04 03:13:35 +00006475 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006476 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006477 if (*curbuf->b_p_keymap != NUL)
6478 {
6479 /* Installed a new keymap, switch on using it. */
6480 curbuf->b_p_iminsert = B_IMODE_LMAP;
6481 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6482 curbuf->b_p_imsearch = B_IMODE_LMAP;
6483 }
6484 else
6485 {
6486 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6487 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6488 curbuf->b_p_iminsert = B_IMODE_NONE;
6489 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6490 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6491 }
6492 if ((opt_flags & OPT_LOCAL) == 0)
6493 {
6494 set_iminsert_global();
6495 set_imsearch_global();
6496 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006497 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006498 }
6499 }
6500#endif
6501
6502 /* 'fileformat' */
6503 else if (gvarp == &p_ff)
6504 {
6505 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6506 errmsg = e_modifiable;
6507 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6508 errmsg = e_invarg;
6509 else
6510 {
6511 /* may also change 'textmode' */
6512 if (get_fileformat(curbuf) == EOL_DOS)
6513 curbuf->b_p_tx = TRUE;
6514 else
6515 curbuf->b_p_tx = FALSE;
6516#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006517 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006518#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006519 /* update flag in swap file */
6520 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006521 /* Redraw needed when switching to/from "mac": a CR in the text
6522 * will be displayed differently. */
6523 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6524 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006525 }
6526 }
6527
6528 /* 'fileformats' */
6529 else if (varp == &p_ffs)
6530 {
6531 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6532 errmsg = e_invarg;
6533 else
6534 {
6535 /* also change 'textauto' */
6536 if (*p_ffs == NUL)
6537 p_ta = FALSE;
6538 else
6539 p_ta = TRUE;
6540 }
6541 }
6542
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006543#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006544 /* 'cryptkey' */
6545 else if (gvarp == &p_key)
6546 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006547# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006548 /* Make sure the ":set" command doesn't show the new value in the
6549 * history. */
6550 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006551# endif
6552 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6553 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006554 ml_set_crypt_key(curbuf, oldval,
6555 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006556 }
6557
6558 else if (gvarp == &p_cm)
6559 {
6560 if (opt_flags & OPT_LOCAL)
6561 p = curbuf->b_p_cm;
6562 else
6563 p = p_cm;
6564 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6565 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006566 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006567 errmsg = e_invarg;
6568 else
6569 {
6570 /* When setting the global value to empty, make it "zip". */
6571 if (*p_cm == NUL)
6572 {
6573 if (new_value_alloced)
6574 free_string_option(p_cm);
6575 p_cm = vim_strsave((char_u *)"zip");
6576 new_value_alloced = TRUE;
6577 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006578 /* When using ":set cm=name" the local value is going to be empty.
6579 * Do that here, otherwise the crypt functions will still use the
6580 * local value. */
6581 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6582 {
6583 free_string_option(curbuf->b_p_cm);
6584 curbuf->b_p_cm = empty_option;
6585 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006586
6587 /* Need to update the swapfile when the effective method changed.
6588 * Set "s" to the effective old value, "p" to the effective new
6589 * method and compare. */
6590 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6591 s = p_cm; /* was previously using the global value */
6592 else
6593 s = oldval;
6594 if (*curbuf->b_p_cm == NUL)
6595 p = p_cm; /* is now using the global value */
6596 else
6597 p = curbuf->b_p_cm;
6598 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006599 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006600
6601 /* If the global value changes need to update the swapfile for all
6602 * buffers using that value. */
6603 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6604 {
6605 buf_T *buf;
6606
Bram Moolenaar29323592016-07-24 22:04:11 +02006607 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006608 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006609 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006610 }
6611 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006612 }
6613#endif
6614
6615 /* 'matchpairs' */
6616 else if (gvarp == &p_mps)
6617 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006618 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006619 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006620 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006621 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006622 int x2 = -1;
6623 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006624
6625 if (*p != NUL)
6626 p += mb_ptr2len(p);
6627 if (*p != NUL)
6628 x2 = *p++;
6629 if (*p != NUL)
6630 {
6631 x3 = mb_ptr2char(p);
6632 p += mb_ptr2len(p);
6633 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006634 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006635 {
6636 errmsg = e_invarg;
6637 break;
6638 }
6639 if (*p == NUL)
6640 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006641 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006642 }
6643 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006644 {
6645 /* Check for "x:y,x:y" */
6646 for (p = *varp; *p != NUL; p += 4)
6647 {
6648 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6649 {
6650 errmsg = e_invarg;
6651 break;
6652 }
6653 if (p[3] == NUL)
6654 break;
6655 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006656 }
6657 }
6658
6659#ifdef FEAT_COMMENTS
6660 /* 'comments' */
6661 else if (gvarp == &p_com)
6662 {
6663 for (s = *varp; *s; )
6664 {
6665 while (*s && *s != ':')
6666 {
6667 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6668 && !VIM_ISDIGIT(*s) && *s != '-')
6669 {
6670 errmsg = illegal_char(errbuf, *s);
6671 break;
6672 }
6673 ++s;
6674 }
6675 if (*s++ == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006676 errmsg = N_("E524: Missing colon");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006677 else if (*s == ',' || *s == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006678 errmsg = N_("E525: Zero length string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006679 if (errmsg != NULL)
6680 break;
6681 while (*s && *s != ',')
6682 {
6683 if (*s == '\\' && s[1] != NUL)
6684 ++s;
6685 ++s;
6686 }
6687 s = skip_to_option_part(s);
6688 }
6689 }
6690#endif
6691
6692 /* 'listchars' */
6693 else if (varp == &p_lcs)
6694 {
6695 errmsg = set_chars_option(varp);
6696 }
6697
Bram Moolenaar071d4272004-06-13 20:20:40 +00006698 /* 'fillchars' */
6699 else if (varp == &p_fcs)
6700 {
6701 errmsg = set_chars_option(varp);
6702 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006703
6704#ifdef FEAT_CMDWIN
6705 /* 'cedit' */
6706 else if (varp == &p_cedit)
6707 {
6708 errmsg = check_cedit();
6709 }
6710#endif
6711
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006712 /* 'verbosefile' */
6713 else if (varp == &p_vfile)
6714 {
6715 verbose_stop();
6716 if (*p_vfile != NUL && verbose_open() == FAIL)
6717 errmsg = e_invarg;
6718 }
6719
Bram Moolenaar071d4272004-06-13 20:20:40 +00006720#ifdef FEAT_VIMINFO
6721 /* 'viminfo' */
6722 else if (varp == &p_viminfo)
6723 {
6724 for (s = p_viminfo; *s;)
6725 {
6726 /* Check it's a valid character */
6727 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6728 {
6729 errmsg = illegal_char(errbuf, *s);
6730 break;
6731 }
6732 if (*s == 'n') /* name is always last one */
6733 {
6734 break;
6735 }
6736 else if (*s == 'r') /* skip until next ',' */
6737 {
6738 while (*++s && *s != ',')
6739 ;
6740 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006741 else if (*s == '%')
6742 {
6743 /* optional number */
6744 while (vim_isdigit(*++s))
6745 ;
6746 }
6747 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006748 ++s; /* no extra chars */
6749 else /* must have a number */
6750 {
6751 while (vim_isdigit(*++s))
6752 ;
6753
6754 if (!VIM_ISDIGIT(*(s - 1)))
6755 {
6756 if (errbuf != NULL)
6757 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006758 sprintf(errbuf, _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006759 transchar_byte(*(s - 1)));
6760 errmsg = errbuf;
6761 }
6762 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006763 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006764 break;
6765 }
6766 }
6767 if (*s == ',')
6768 ++s;
6769 else if (*s)
6770 {
6771 if (errbuf != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006772 errmsg = N_("E527: Missing comma");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006773 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006774 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006775 break;
6776 }
6777 }
6778 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006779 errmsg = N_("E528: Must specify a ' value");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006780 }
6781#endif /* FEAT_VIMINFO */
6782
6783 /* terminal options */
6784 else if (istermoption(&options[opt_idx]) && full_screen)
6785 {
6786 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6787 if (varp == &T_CCO)
6788 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006789 int colors = atoi((char *)T_CCO);
6790
6791 /* Only reinitialize colors if t_Co value has really changed to
6792 * avoid expensive reload of colorscheme if t_Co is set to the
6793 * same value multiple times. */
6794 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006795 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006796 t_colors = colors;
6797 if (t_colors <= 1)
6798 {
6799 if (new_value_alloced)
6800 vim_free(T_CCO);
6801 T_CCO = empty_option;
6802 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006803#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6804 if (is_term_win32())
6805 {
6806 swap_tcap();
6807 did_swaptcap = TRUE;
6808 }
6809#endif
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006810 /* We now have a different color setup, initialize it again. */
6811 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006812 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006813 }
6814 ttest(FALSE);
6815 if (varp == &T_ME)
6816 {
6817 out_str(T_ME);
6818 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006819#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006820 /* Since t_me has been set, this probably means that the user
6821 * wants to use this as default colors. Need to reset default
6822 * background/foreground colors. */
6823 mch_set_normal_colors();
6824#endif
6825 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006826 if (varp == &T_BE && termcap_active)
6827 {
6828 if (*T_BE == NUL)
6829 /* When clearing t_BE we assume the user no longer wants
6830 * bracketed paste, thus disable it by writing t_BD. */
6831 out_str(T_BD);
6832 else
6833 out_str(T_BE);
6834 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006835 }
6836
6837#ifdef FEAT_LINEBREAK
6838 /* 'showbreak' */
6839 else if (varp == &p_sbr)
6840 {
6841 for (s = p_sbr; *s; )
6842 {
6843 if (ptr2cells(s) != 1)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006844 errmsg = N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006845 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006846 }
6847 }
6848#endif
6849
6850#ifdef FEAT_GUI
6851 /* 'guifont' */
6852 else if (varp == &p_guifont)
6853 {
6854 if (gui.in_use)
6855 {
6856 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006857# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006858 /*
6859 * Put up a font dialog and let the user select a new value.
6860 * If this is cancelled go back to the old value but don't
6861 * give an error message.
6862 */
6863 if (STRCMP(p, "*") == 0)
6864 {
6865 p = gui_mch_font_dialog(oldval);
6866
6867 if (new_value_alloced)
6868 free_string_option(p_guifont);
6869
6870 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6871 new_value_alloced = TRUE;
6872 }
6873# endif
6874 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6875 {
6876# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6877 if (STRCMP(p_guifont, "*") == 0)
6878 {
6879 /* Dialog was cancelled: Keep the old value without giving
6880 * an error message. */
6881 if (new_value_alloced)
6882 free_string_option(p_guifont);
6883 p_guifont = vim_strsave(oldval);
6884 new_value_alloced = TRUE;
6885 }
6886 else
6887# endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006888 errmsg = N_("E596: Invalid font(s)");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006889 }
6890 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006891 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006892 }
6893# ifdef FEAT_XFONTSET
6894 else if (varp == &p_guifontset)
6895 {
6896 if (STRCMP(p_guifontset, "*") == 0)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01006897 errmsg = N_("E597: can't select fontset");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006898 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01006899 errmsg = N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006900 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006901 }
6902# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006903 else if (varp == &p_guifontwide)
6904 {
6905 if (STRCMP(p_guifontwide, "*") == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006906 errmsg = N_("E533: can't select wide font");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006907 else if (gui_get_wide_font() == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006908 errmsg = N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006909 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006910 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006911#endif
6912
6913#ifdef CURSOR_SHAPE
6914 /* 'guicursor' */
6915 else if (varp == &p_guicursor)
6916 errmsg = parse_shape_opt(SHAPE_CURSOR);
6917#endif
6918
6919#ifdef FEAT_MOUSESHAPE
6920 /* 'mouseshape' */
6921 else if (varp == &p_mouseshape)
6922 {
6923 errmsg = parse_shape_opt(SHAPE_MOUSE);
6924 update_mouseshape(-1);
6925 }
6926#endif
6927
6928#ifdef FEAT_PRINTER
6929 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006930 errmsg = parse_printoptions();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006931# if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006932 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006933 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006934# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006935#endif
6936
6937#ifdef FEAT_LANGMAP
6938 /* 'langmap' */
6939 else if (varp == &p_langmap)
6940 langmap_set();
6941#endif
6942
6943#ifdef FEAT_LINEBREAK
6944 /* 'breakat' */
6945 else if (varp == &p_breakat)
6946 fill_breakat_flags();
6947#endif
6948
6949#ifdef FEAT_TITLE
6950 /* 'titlestring' and 'iconstring' */
6951 else if (varp == &p_titlestring || varp == &p_iconstring)
6952 {
6953# ifdef FEAT_STL_OPT
6954 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6955
6956 /* NULL => statusline syntax */
6957 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6958 stl_syntax |= flagval;
6959 else
6960 stl_syntax &= ~flagval;
6961# endif
Bram Moolenaar84a93082018-06-16 22:58:15 +02006962 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006963 }
6964#endif
6965
6966#ifdef FEAT_GUI
6967 /* 'guioptions' */
6968 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006969 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006970 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006971 redraw_gui_only = TRUE;
6972 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006973#endif
6974
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006975#if defined(FEAT_GUI_TABLINE)
6976 /* 'guitablabel' */
6977 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006978 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006979 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006980 redraw_gui_only = TRUE;
6981 }
6982 /* 'guitabtooltip' */
6983 else if (varp == &p_gtt)
6984 {
6985 redraw_gui_only = TRUE;
6986 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006987#endif
6988
Bram Moolenaar071d4272004-06-13 20:20:40 +00006989#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6990 /* 'ttymouse' */
6991 else if (varp == &p_ttym)
6992 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006993 /* Switch the mouse off before changing the escape sequences used for
6994 * that. */
6995 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006996 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6997 errmsg = e_invarg;
6998 else
6999 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00007000 if (termcap_active)
7001 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007002 }
7003#endif
7004
Bram Moolenaar071d4272004-06-13 20:20:40 +00007005 /* 'selection' */
7006 else if (varp == &p_sel)
7007 {
7008 if (*p_sel == NUL
7009 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
7010 errmsg = e_invarg;
7011 }
7012
7013 /* 'selectmode' */
7014 else if (varp == &p_slm)
7015 {
7016 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
7017 errmsg = e_invarg;
7018 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007019
7020#ifdef FEAT_BROWSE
7021 /* 'browsedir' */
7022 else if (varp == &p_bsdir)
7023 {
7024 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7025 && !mch_isdir(p_bsdir))
7026 errmsg = e_invarg;
7027 }
7028#endif
7029
Bram Moolenaar071d4272004-06-13 20:20:40 +00007030 /* 'keymodel' */
7031 else if (varp == &p_km)
7032 {
7033 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7034 errmsg = e_invarg;
7035 else
7036 {
7037 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7038 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7039 }
7040 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007041
7042 /* 'mousemodel' */
7043 else if (varp == &p_mousem)
7044 {
7045 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7046 errmsg = e_invarg;
7047#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7048 else if (*p_mousem != *oldval)
7049 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7050 * to create or delete the popup menus. */
7051 gui_motif_update_mousemodel(root_menu);
7052#endif
7053 }
7054
7055 /* 'switchbuf' */
7056 else if (varp == &p_swb)
7057 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007058 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007059 errmsg = e_invarg;
7060 }
7061
7062 /* 'debug' */
7063 else if (varp == &p_debug)
7064 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007065 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007066 errmsg = e_invarg;
7067 }
7068
7069 /* 'display' */
7070 else if (varp == &p_dy)
7071 {
7072 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7073 errmsg = e_invarg;
7074 else
7075 (void)init_chartab();
7076
7077 }
7078
Bram Moolenaar071d4272004-06-13 20:20:40 +00007079 /* 'eadirection' */
7080 else if (varp == &p_ead)
7081 {
7082 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7083 errmsg = e_invarg;
7084 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007085
7086#ifdef FEAT_CLIPBOARD
7087 /* 'clipboard' */
7088 else if (varp == &p_cb)
7089 errmsg = check_clipboard_option();
7090#endif
7091
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007092#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007093 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7094 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007095 else if (varp == &(curwin->w_s->b_p_spl)
7096 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007097 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007098 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007099 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007100 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007101 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007102 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007103 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007104 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007105 /* 'spellsuggest' */
7106 else if (varp == &p_sps)
7107 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007108 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007109 errmsg = e_invarg;
7110 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007111 /* 'mkspellmem' */
7112 else if (varp == &p_msm)
7113 {
7114 if (spell_check_msm() != OK)
7115 errmsg = e_invarg;
7116 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007117#endif
7118
Bram Moolenaar071d4272004-06-13 20:20:40 +00007119 /* When 'bufhidden' is set, check for valid value. */
7120 else if (gvarp == &p_bh)
7121 {
7122 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7123 errmsg = e_invarg;
7124 }
7125
7126 /* When 'buftype' is set, check for valid value. */
7127 else if (gvarp == &p_bt)
7128 {
7129 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7130 errmsg = e_invarg;
7131 else
7132 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007133 if (curwin->w_status_height)
7134 {
7135 curwin->w_redr_status = TRUE;
7136 redraw_later(VALID);
7137 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007138 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007139#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007140 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007141#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007142 }
7143 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007144
7145#ifdef FEAT_STL_OPT
7146 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007147 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007148 {
7149 int wid;
7150
7151 if (varp == &p_ruf) /* reset ru_wid first */
7152 ru_wid = 0;
7153 s = *varp;
7154 if (varp == &p_ruf && *s == '%')
7155 {
7156 /* set ru_wid if 'ruf' starts with "%99(" */
7157 if (*++s == '-') /* ignore a '-' */
7158 s++;
7159 wid = getdigits(&s);
7160 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7161 ru_wid = wid;
7162 else
7163 errmsg = check_stl_option(p_ruf);
7164 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007165 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007166 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007167 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007168 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007169 comp_col();
7170 }
7171#endif
7172
7173#ifdef FEAT_INS_EXPAND
7174 /* check if it is a valid value for 'complete' -- Acevedo */
7175 else if (gvarp == &p_cpt)
7176 {
7177 for (s = *varp; *s;)
7178 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007179 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007180 s++;
7181 if (!*s)
7182 break;
7183 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7184 {
7185 errmsg = illegal_char(errbuf, *s);
7186 break;
7187 }
7188 if (*++s != NUL && *s != ',' && *s != ' ')
7189 {
7190 if (s[-1] == 'k' || s[-1] == 's')
7191 {
7192 /* skip optional filename after 'k' and 's' */
7193 while (*s && *s != ',' && *s != ' ')
7194 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007195 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007196 ++s;
7197 ++s;
7198 }
7199 }
7200 else
7201 {
7202 if (errbuf != NULL)
7203 {
7204 sprintf((char *)errbuf,
7205 _("E535: Illegal character after <%c>"),
7206 *--s);
7207 errmsg = errbuf;
7208 }
7209 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007210 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00007211 break;
7212 }
7213 }
7214 }
7215 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007216
7217 /* 'completeopt' */
7218 else if (varp == &p_cot)
7219 {
7220 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7221 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007222 else
7223 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007224 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007225#endif /* FEAT_INS_EXPAND */
7226
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007227#ifdef FEAT_SIGNS
7228 /* 'signcolumn' */
7229 else if (varp == &curwin->w_p_scl)
7230 {
7231 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7232 errmsg = e_invarg;
7233 }
7234#endif
7235
Bram Moolenaar071d4272004-06-13 20:20:40 +00007236
7237#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007238 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007239 else if (varp == &p_toolbar)
7240 {
7241 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7242 &toolbar_flags, TRUE) != OK)
7243 errmsg = e_invarg;
7244 else
7245 {
7246 out_flush();
7247 gui_mch_show_toolbar((toolbar_flags &
7248 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7249 }
7250 }
7251#endif
7252
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007253#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007254 /* 'toolbariconsize': GTK+ 2 only */
7255 else if (varp == &p_tbis)
7256 {
7257 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7258 errmsg = e_invarg;
7259 else
7260 {
7261 out_flush();
7262 gui_mch_show_toolbar((toolbar_flags &
7263 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7264 }
7265 }
7266#endif
7267
7268 /* 'pastetoggle': translate key codes like in a mapping */
7269 else if (varp == &p_pt)
7270 {
7271 if (*p_pt)
7272 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007273 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007274 if (p != NULL)
7275 {
7276 if (new_value_alloced)
7277 free_string_option(p_pt);
7278 p_pt = p;
7279 new_value_alloced = TRUE;
7280 }
7281 }
7282 }
7283
7284 /* 'backspace' */
7285 else if (varp == &p_bs)
7286 {
7287 if (VIM_ISDIGIT(*p_bs))
7288 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007289 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007290 errmsg = e_invarg;
7291 }
7292 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7293 errmsg = e_invarg;
7294 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007295 else if (varp == &p_bo)
7296 {
7297 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7298 errmsg = e_invarg;
7299 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007300
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007301 /* 'tagcase' */
7302 else if (gvarp == &p_tc)
7303 {
7304 unsigned int *flags;
7305
7306 if (opt_flags & OPT_LOCAL)
7307 {
7308 p = curbuf->b_p_tc;
7309 flags = &curbuf->b_tc_flags;
7310 }
7311 else
7312 {
7313 p = p_tc;
7314 flags = &tc_flags;
7315 }
7316
7317 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7318 /* make the local value empty: use the global value */
7319 *flags = 0;
7320 else if (*p == NUL
7321 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7322 errmsg = e_invarg;
7323 }
7324
Bram Moolenaar071d4272004-06-13 20:20:40 +00007325 /* 'casemap' */
7326 else if (varp == &p_cmp)
7327 {
7328 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7329 errmsg = e_invarg;
7330 }
7331
7332#ifdef FEAT_DIFF
7333 /* 'diffopt' */
7334 else if (varp == &p_dip)
7335 {
7336 if (diffopt_changed() == FAIL)
7337 errmsg = e_invarg;
7338 }
7339#endif
7340
7341#ifdef FEAT_FOLDING
7342 /* 'foldmethod' */
7343 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7344 {
7345 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7346 || *curwin->w_p_fdm == NUL)
7347 errmsg = e_invarg;
7348 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007349 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007350 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007351 if (foldmethodIsDiff(curwin))
7352 newFoldLevel();
7353 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007354 }
7355# ifdef FEAT_EVAL
7356 /* 'foldexpr' */
7357 else if (varp == &curwin->w_p_fde)
7358 {
7359 if (foldmethodIsExpr(curwin))
7360 foldUpdateAll(curwin);
7361 }
7362# endif
7363 /* 'foldmarker' */
7364 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7365 {
7366 p = vim_strchr(*varp, ',');
7367 if (p == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007368 errmsg = N_("E536: comma required");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007369 else if (p == *varp || p[1] == NUL)
7370 errmsg = e_invarg;
7371 else if (foldmethodIsMarker(curwin))
7372 foldUpdateAll(curwin);
7373 }
7374 /* 'commentstring' */
7375 else if (gvarp == &p_cms)
7376 {
7377 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007378 errmsg = N_("E537: 'commentstring' must be empty or contain %s");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007379 }
7380 /* 'foldopen' */
7381 else if (varp == &p_fdo)
7382 {
7383 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7384 errmsg = e_invarg;
7385 }
7386 /* 'foldclose' */
7387 else if (varp == &p_fcl)
7388 {
7389 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7390 errmsg = e_invarg;
7391 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007392 /* 'foldignore' */
7393 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7394 {
7395 if (foldmethodIsIndent(curwin))
7396 foldUpdateAll(curwin);
7397 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007398#endif
7399
Bram Moolenaar071d4272004-06-13 20:20:40 +00007400 /* 'virtualedit' */
7401 else if (varp == &p_ve)
7402 {
7403 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7404 errmsg = e_invarg;
7405 else if (STRCMP(p_ve, oldval) != 0)
7406 {
7407 /* Recompute cursor position in case the new 've' setting
7408 * changes something. */
7409 validate_virtcol();
7410 coladvance(curwin->w_virtcol);
7411 }
7412 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007413
7414#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7415 else if (varp == &p_csqf)
7416 {
7417 if (p_csqf != NULL)
7418 {
7419 p = p_csqf;
7420 while (*p != NUL)
7421 {
7422 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7423 || p[1] == NUL
7424 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7425 || (p[2] != NUL && p[2] != ','))
7426 {
7427 errmsg = e_invarg;
7428 break;
7429 }
7430 else if (p[2] == NUL)
7431 break;
7432 else
7433 p += 3;
7434 }
7435 }
7436 }
7437#endif
7438
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007439#ifdef FEAT_CINDENT
7440 /* 'cinoptions' */
7441 else if (gvarp == &p_cino)
7442 {
7443 /* TODO: recognize errors */
7444 parse_cino(curbuf);
7445 }
7446#endif
7447
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007448#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007449 /* 'renderoptions' */
Bram Moolenaar3767c6e2017-12-05 16:57:56 +01007450 else if (varp == &p_rop)
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007451 {
7452 if (!gui_mch_set_rendering_options(p_rop))
7453 errmsg = e_invarg;
7454 }
7455#endif
7456
Bram Moolenaard0b51382016-11-04 15:23:45 +01007457 else if (gvarp == &p_ft)
7458 {
7459 if (!valid_filetype(*varp))
7460 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007461 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007462 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007463 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007464
7465 // Since we check the value, there is no need to set P_INSECURE,
7466 // even when the value comes from a modeline.
7467 *value_checked = TRUE;
7468 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007469 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007470
7471#ifdef FEAT_SYN_HL
7472 else if (gvarp == &p_syn)
7473 {
7474 if (!valid_filetype(*varp))
7475 errmsg = e_invarg;
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007476 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007477 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007478 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007479
7480 // Since we check the value, there is no need to set P_INSECURE,
7481 // even when the value comes from a modeline.
7482 *value_checked = TRUE;
7483 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007484 }
7485#endif
7486
Bram Moolenaar825680f2017-07-22 17:04:02 +02007487#ifdef FEAT_TERMINAL
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007488 // 'termwinkey'
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007489 else if (varp == &curwin->w_p_twk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007490 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007491 if (*curwin->w_p_twk != NUL
7492 && string_to_key(curwin->w_p_twk, TRUE) == 0)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007493 errmsg = e_invarg;
7494 }
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007495 // 'termwinsize'
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007496 else if (varp == &curwin->w_p_tws)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007497 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007498 if (*curwin->w_p_tws != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007499 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007500 p = skipdigits(curwin->w_p_tws);
7501 if (p == curwin->w_p_tws
Bram Moolenaar498c2562018-04-15 23:45:15 +02007502 || (*p != 'x' && *p != '*')
7503 || *skipdigits(p + 1) != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007504 errmsg = e_invarg;
7505 }
7506 }
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007507# if defined(WIN3264)
7508 // 'termwintype'
7509 else if (varp == &p_twt)
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007510 {
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007511 if (check_opt_strings(*varp, p_twt_values, FALSE) != OK)
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007512 errmsg = e_invarg;
7513 }
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007514# endif
Bram Moolenaar825680f2017-07-22 17:04:02 +02007515#endif
7516
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007517#ifdef FEAT_VARTABS
7518 /* 'varsofttabstop' */
7519 else if (varp == &(curbuf->b_p_vsts))
7520 {
7521 char_u *cp;
7522
7523 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7524 {
7525 if (curbuf->b_p_vsts_array)
7526 {
7527 vim_free(curbuf->b_p_vsts_array);
7528 curbuf->b_p_vsts_array = 0;
7529 }
7530 }
7531 else
7532 {
7533 for (cp = *varp; *cp; ++cp)
7534 {
7535 if (vim_isdigit(*cp))
7536 continue;
7537 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7538 continue;
7539 errmsg = e_invarg;
7540 break;
7541 }
7542 if (errmsg == NULL)
7543 {
7544 int *oldarray = curbuf->b_p_vsts_array;
7545 if (tabstop_set(*varp, &(curbuf->b_p_vsts_array)))
7546 {
7547 if (oldarray)
7548 vim_free(oldarray);
7549 }
7550 else
7551 errmsg = e_invarg;
7552 }
7553 }
7554 }
7555
7556 /* 'vartabstop' */
7557 else if (varp == &(curbuf->b_p_vts))
7558 {
7559 char_u *cp;
7560
7561 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7562 {
7563 if (curbuf->b_p_vts_array)
7564 {
7565 vim_free(curbuf->b_p_vts_array);
7566 curbuf->b_p_vts_array = NULL;
7567 }
7568 }
7569 else
7570 {
7571 for (cp = *varp; *cp; ++cp)
7572 {
7573 if (vim_isdigit(*cp))
7574 continue;
7575 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7576 continue;
7577 errmsg = e_invarg;
7578 break;
7579 }
7580 if (errmsg == NULL)
7581 {
7582 int *oldarray = curbuf->b_p_vts_array;
7583 if (tabstop_set(*varp, &(curbuf->b_p_vts_array)))
7584 {
7585 if (oldarray)
7586 vim_free(oldarray);
7587#ifdef FEAT_FOLDING
7588 if (foldmethodIsIndent(curwin))
7589 foldUpdateAll(curwin);
7590#endif /* FEAT_FOLDING */
7591 }
7592 else
7593 errmsg = e_invarg;
7594 }
7595 }
7596 }
7597#endif
7598
Bram Moolenaar071d4272004-06-13 20:20:40 +00007599 /* Options that are a list of flags. */
7600 else
7601 {
7602 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007603 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007604 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007605 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007606 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007607 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007608 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007609 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007610 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007611#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007612 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007613 p = (char_u *)COCU_ALL;
7614#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007615 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007616 {
7617#ifdef FEAT_MOUSE
7618 p = (char_u *)MOUSE_ALL;
7619#else
7620 if (*p_mouse != NUL)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007621 errmsg = N_("E538: No mouse support");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007622#endif
7623 }
7624#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007625 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007626 p = (char_u *)GO_ALL;
7627#endif
7628 if (p != NULL)
7629 {
7630 for (s = *varp; *s; ++s)
7631 if (vim_strchr(p, *s) == NULL)
7632 {
7633 errmsg = illegal_char(errbuf, *s);
7634 break;
7635 }
7636 }
7637 }
7638
7639 /*
7640 * If error detected, restore the previous value.
7641 */
7642 if (errmsg != NULL)
7643 {
7644 if (new_value_alloced)
7645 free_string_option(*varp);
7646 *varp = oldval;
7647 /*
7648 * When resetting some values, need to act on it.
7649 */
7650 if (did_chartab)
7651 (void)init_chartab();
7652 if (varp == &p_hl)
7653 (void)highlight_changed();
7654 }
7655 else
7656 {
7657#ifdef FEAT_EVAL
7658 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02007659 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007660#endif
7661 /*
7662 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007663 * Use "free_oldval", because recursiveness may change the flags under
7664 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007665 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007666 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007667 free_string_option(oldval);
7668 if (new_value_alloced)
7669 options[opt_idx].flags |= P_ALLOCED;
7670 else
7671 options[opt_idx].flags &= ~P_ALLOCED;
7672
7673 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007674 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007675 {
7676 /* global option with local value set to use global value; free
7677 * the local value and make it empty */
7678 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7679 free_string_option(*(char_u **)p);
7680 *(char_u **)p = empty_option;
7681 }
7682
7683 /* May set global value for local option. */
7684 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7685 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007686
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007687 /*
7688 * Trigger the autocommand only after setting the flags.
7689 */
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007690#ifdef FEAT_SYN_HL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007691 /* When 'syntax' is set, load the syntax of that name */
7692 if (varp == &(curbuf->b_p_syn))
7693 {
Bram Moolenaara5616b02018-06-17 19:08:30 +02007694 static int syn_recursive = 0;
7695
7696 ++syn_recursive;
7697 // Only pass TRUE for "force" when the value changed or not used
7698 // recursively, to avoid endless recurrence.
7699 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname,
7700 value_changed || syn_recursive == 1, curbuf);
7701 --syn_recursive;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007702 }
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007703#endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007704 else if (varp == &(curbuf->b_p_ft))
7705 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007706 /* 'filetype' is set, trigger the FileType autocommand.
7707 * Skip this when called from a modeline and the filetype was
Bram Moolenaara5616b02018-06-17 19:08:30 +02007708 * already set to this value. */
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007709 if (!(opt_flags & OPT_MODELINE) || value_changed)
Bram Moolenaar90492982017-06-22 14:16:31 +02007710 {
Bram Moolenaar916a8182018-11-25 02:18:29 +01007711 static int ft_recursive = 0;
7712 int secure_save = secure;
7713
7714 // Reset the secure flag, since the value of 'filetype' has
7715 // been checked to be safe.
7716 secure = 0;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007717
7718 ++ft_recursive;
Bram Moolenaar90492982017-06-22 14:16:31 +02007719 did_filetype = TRUE;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007720 // Only pass TRUE for "force" when the value changed or not
7721 // used recursively, to avoid endless recurrence.
7722 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname,
7723 value_changed || ft_recursive == 1, curbuf);
7724 --ft_recursive;
Bram Moolenaar163095f2017-07-09 15:41:53 +02007725 /* Just in case the old "curbuf" is now invalid. */
7726 if (varp != &(curbuf->b_p_ft))
7727 varp = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007728
7729 secure = secure_save;
Bram Moolenaar90492982017-06-22 14:16:31 +02007730 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007731 }
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007732#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007733 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007734 {
7735 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007736 char_u *q = curwin->w_s->b_p_spl;
7737
7738 /* Skip the first name if it is "cjk". */
7739 if (STRNCMP(q, "cjk,", 4) == 0)
7740 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007741
7742 /*
7743 * Source the spell/LANG.vim in 'runtimepath'.
7744 * They could set 'spellcapcheck' depending on the language.
7745 * Use the first name in 'spelllang' up to '_region' or
7746 * '.encoding'.
7747 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007748 for (p = q; *p != NUL; ++p)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01007749 if (!ASCII_ISALNUM(*p) && *p != '-')
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007750 break;
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007751 if (p > q)
7752 {
7753 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
7754 source_runtime(fname, DIP_ALL);
7755 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007756 }
7757#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007758 }
7759
7760#ifdef FEAT_MOUSE
7761 if (varp == &p_mouse)
7762 {
7763# ifdef FEAT_MOUSE_TTY
7764 if (*p_mouse == NUL)
7765 mch_setmouse(FALSE); /* switch mouse off */
7766 else
7767# endif
7768 setmouse(); /* in case 'mouse' changed */
7769 }
7770#endif
7771
Bram Moolenaar913077c2012-03-28 19:59:04 +02007772 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007773 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007774 curwin->w_set_curswant = TRUE;
7775
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007776#ifdef FEAT_GUI
7777 /* check redraw when it's not a GUI option or the GUI is active. */
7778 if (!redraw_gui_only || gui.in_use)
7779#endif
7780 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007781
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007782#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
7783 if (did_swaptcap)
7784 {
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007785 set_termname((char_u *)"win32");
7786 init_highlight(TRUE, FALSE);
7787 }
7788#endif
7789
Bram Moolenaar071d4272004-06-13 20:20:40 +00007790 return errmsg;
7791}
7792
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007793#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007794/*
7795 * Simple int comparison function for use with qsort()
7796 */
7797 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007798int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007799{
7800 return *(const int *)a - *(const int *)b;
7801}
7802
7803/*
7804 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7805 * Returns error message, NULL if it's OK.
7806 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007807 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007808check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007809{
7810 char_u *s;
7811 int col;
7812 int count = 0;
7813 int color_cols[256];
7814 int i;
7815 int j = 0;
7816
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007817 if (wp->w_buffer == NULL)
7818 return NULL; /* buffer was closed */
7819
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007820 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007821 {
7822 if (*s == '-' || *s == '+')
7823 {
7824 /* -N and +N: add to 'textwidth' */
7825 col = (*s == '-') ? -1 : 1;
7826 ++s;
7827 if (!VIM_ISDIGIT(*s))
7828 return e_invarg;
7829 col = col * getdigits(&s);
7830 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007831 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007832 col += wp->w_buffer->b_p_tw;
7833 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007834 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007835 }
7836 else if (VIM_ISDIGIT(*s))
7837 col = getdigits(&s);
7838 else
7839 return e_invarg;
7840 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007841skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007842 if (*s == NUL)
7843 break;
7844 if (*s != ',')
7845 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007846 if (*++s == NUL)
7847 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007848 }
7849
7850 vim_free(wp->w_p_cc_cols);
7851 if (count == 0)
7852 wp->w_p_cc_cols = NULL;
7853 else
7854 {
7855 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7856 if (wp->w_p_cc_cols != NULL)
7857 {
7858 /* sort the columns for faster usage on screen redraw inside
7859 * win_line() */
7860 qsort(color_cols, count, sizeof(int), int_cmp);
7861
7862 for (i = 0; i < count; ++i)
7863 /* skip duplicates */
7864 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7865 wp->w_p_cc_cols[j++] = color_cols[i];
7866 wp->w_p_cc_cols[j] = -1; /* end marker */
7867 }
7868 }
7869
7870 return NULL; /* no error */
7871}
7872#endif
7873
Bram Moolenaar071d4272004-06-13 20:20:40 +00007874/*
7875 * Handle setting 'listchars' or 'fillchars'.
7876 * Returns error message, NULL if it's OK.
7877 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007878 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007879set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007880{
7881 int round, i, len, entries;
7882 char_u *p, *s;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007883 int c1 = 0, c2 = 0, c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007884 struct charstab
7885 {
7886 int *cp;
7887 char *name;
7888 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007889 static struct charstab filltab[] =
7890 {
7891 {&fill_stl, "stl"},
7892 {&fill_stlnc, "stlnc"},
7893 {&fill_vert, "vert"},
7894 {&fill_fold, "fold"},
7895 {&fill_diff, "diff"},
7896 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007897 static struct charstab lcstab[] =
7898 {
7899 {&lcs_eol, "eol"},
7900 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007901 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007902 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007903 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007904 {&lcs_tab2, "tab"},
7905 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007906#ifdef FEAT_CONCEAL
7907 {&lcs_conceal, "conceal"},
7908#else
7909 {NULL, "conceal"},
7910#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007911 };
7912 struct charstab *tab;
7913
Bram Moolenaar071d4272004-06-13 20:20:40 +00007914 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007915 {
7916 tab = lcstab;
7917 entries = sizeof(lcstab) / sizeof(struct charstab);
7918 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007919 else
7920 {
7921 tab = filltab;
7922 entries = sizeof(filltab) / sizeof(struct charstab);
7923 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007924
7925 /* first round: check for valid value, second round: assign values */
7926 for (round = 0; round <= 1; ++round)
7927 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007928 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007929 {
7930 /* After checking that the value is valid: set defaults: space for
7931 * 'fillchars', NUL for 'listchars' */
7932 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007933 if (tab[i].cp != NULL)
7934 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar83a52172019-01-16 22:41:54 +01007935
Bram Moolenaar071d4272004-06-13 20:20:40 +00007936 if (varp == &p_lcs)
Bram Moolenaar83a52172019-01-16 22:41:54 +01007937 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007938 lcs_tab1 = NUL;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007939 lcs_tab3 = NUL;
7940 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007941 else
7942 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007943 }
7944 p = *varp;
7945 while (*p)
7946 {
7947 for (i = 0; i < entries; ++i)
7948 {
7949 len = (int)STRLEN(tab[i].name);
7950 if (STRNCMP(p, tab[i].name, len) == 0
7951 && p[len] == ':'
7952 && p[len + 1] != NUL)
7953 {
Bram Moolenaar83a52172019-01-16 22:41:54 +01007954 c1 = c2 = c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007955 s = p + len + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007956 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007957 if (mb_char2cells(c1) > 1)
7958 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007959 if (tab[i].cp == &lcs_tab2)
7960 {
7961 if (*s == NUL)
7962 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007963 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007964 if (mb_char2cells(c2) > 1)
7965 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007966 if (!(*s == ',' || *s == NUL))
7967 {
Bram Moolenaar83a52172019-01-16 22:41:54 +01007968 c3 = mb_ptr2char_adv(&s);
7969 if (mb_char2cells(c3) > 1)
7970 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007971 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007972 }
Bram Moolenaar83a52172019-01-16 22:41:54 +01007973
Bram Moolenaar071d4272004-06-13 20:20:40 +00007974 if (*s == ',' || *s == NUL)
7975 {
7976 if (round)
7977 {
7978 if (tab[i].cp == &lcs_tab2)
7979 {
7980 lcs_tab1 = c1;
7981 lcs_tab2 = c2;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007982 lcs_tab3 = c3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007983 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007984 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007985 *(tab[i].cp) = c1;
7986
7987 }
7988 p = s;
7989 break;
7990 }
7991 }
7992 }
7993
7994 if (i == entries)
7995 return e_invarg;
7996 if (*p == ',')
7997 ++p;
7998 }
7999 }
8000
8001 return NULL; /* no error */
8002}
8003
8004#ifdef FEAT_STL_OPT
8005/*
8006 * Check validity of options with the 'statusline' format.
8007 * Return error message or NULL.
8008 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008009 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008010check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008011{
8012 int itemcnt = 0;
8013 int groupdepth = 0;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008014 static char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00008015
8016 while (*s && itemcnt < STL_MAX_ITEM)
8017 {
8018 /* Check for valid keys after % sequences */
8019 while (*s && *s != '%')
8020 s++;
8021 if (!*s)
8022 break;
8023 s++;
8024 if (*s != '%' && *s != ')')
8025 ++itemcnt;
8026 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
8027 {
8028 s++;
8029 continue;
8030 }
8031 if (*s == ')')
8032 {
8033 s++;
8034 if (--groupdepth < 0)
8035 break;
8036 continue;
8037 }
8038 if (*s == '-')
8039 s++;
8040 while (VIM_ISDIGIT(*s))
8041 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00008042 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008043 continue;
8044 if (*s == '.')
8045 {
8046 s++;
8047 while (*s && VIM_ISDIGIT(*s))
8048 s++;
8049 }
8050 if (*s == '(')
8051 {
8052 groupdepth++;
8053 continue;
8054 }
8055 if (vim_strchr(STL_ALL, *s) == NULL)
8056 {
8057 return illegal_char(errbuf, *s);
8058 }
8059 if (*s == '{')
8060 {
8061 s++;
8062 while (*s != '}' && *s)
8063 s++;
8064 if (*s != '}')
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008065 return N_("E540: Unclosed expression sequence");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008066 }
8067 }
8068 if (itemcnt >= STL_MAX_ITEM)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008069 return N_("E541: too many items");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008070 if (groupdepth != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008071 return N_("E542: unbalanced groups");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008072 return NULL;
8073}
8074#endif
8075
8076#ifdef FEAT_CLIPBOARD
8077/*
8078 * Extract the items in the 'clipboard' option and set global values.
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008079 * Return an error message or NULL for success.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008080 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008081 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008082check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008083{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008084 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008085 int new_autoselect_star = FALSE;
8086 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008087 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008088 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008089 regprog_T *new_exclude_prog = NULL;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008090 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008091 char_u *p;
8092
8093 for (p = p_cb; *p != NUL; )
8094 {
8095 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
8096 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008097 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008098 p += 7;
8099 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02008100 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008101 && (p[11] == ',' || p[11] == NUL))
8102 {
8103 new_unnamed |= CLIP_UNNAMED_PLUS;
8104 p += 11;
8105 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008106 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008107 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008108 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02008109 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008110 p += 10;
8111 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02008112 else if (STRNCMP(p, "autoselectplus", 14) == 0
8113 && (p[14] == ',' || p[14] == NUL))
8114 {
8115 new_autoselect_plus = TRUE;
8116 p += 14;
8117 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008118 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008119 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008120 {
8121 new_autoselectml = TRUE;
8122 p += 12;
8123 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008124 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
8125 {
8126 new_html = TRUE;
8127 p += 4;
8128 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008129 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
8130 {
8131 p += 8;
8132 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
8133 if (new_exclude_prog == NULL)
8134 errmsg = e_invarg;
8135 break;
8136 }
8137 else
8138 {
8139 errmsg = e_invarg;
8140 break;
8141 }
8142 if (*p == ',')
8143 ++p;
8144 }
8145 if (errmsg == NULL)
8146 {
8147 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008148 clip_autoselect_star = new_autoselect_star;
8149 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008150 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008151 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008152 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008153 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008154#ifdef FEAT_GUI_GTK
8155 if (gui.in_use)
8156 {
8157 gui_gtk_set_selection_targets();
8158 gui_gtk_set_dnd_targets();
8159 }
8160#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008161 }
8162 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008163 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008164
8165 return errmsg;
8166}
8167#endif
8168
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008169#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008170/*
8171 * Handle side effects of setting 'spell'.
8172 * Return an error message or NULL for success.
8173 */
8174 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008175did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008176{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008177 char *errmsg = NULL;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008178 win_T *wp;
8179 int l;
8180
8181 if (is_spellfile)
8182 {
8183 l = (int)STRLEN(curwin->w_s->b_p_spf);
8184 if (l > 0 && (l < 4
8185 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8186 errmsg = e_invarg;
8187 }
8188
8189 if (errmsg == NULL)
8190 {
8191 FOR_ALL_WINDOWS(wp)
8192 if (wp->w_buffer == curbuf && wp->w_p_spell)
8193 {
8194 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008195 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008196 }
8197 }
8198 return errmsg;
8199}
8200
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008201/*
8202 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8203 * Return error message when failed, NULL when OK.
8204 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008205 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008206compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008207{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008208 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008209 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008210
Bram Moolenaar860cae12010-06-05 23:22:07 +02008211 if (*synblock->b_p_spc == NUL)
8212 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008213 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008214 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008215 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008216 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008217 if (re != NULL)
8218 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008219 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008220 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008221 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008222 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008223 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008224 return e_invarg;
8225 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008226 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008227 }
8228
Bram Moolenaar473de612013-06-08 18:19:48 +02008229 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008230 return NULL;
8231}
8232#endif
8233
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008234#if defined(FEAT_EVAL) || defined(PROTO)
8235/*
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008236 * Set the script_ctx for an option, taking care of setting the buffer- or
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008237 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008238 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008239 static void
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008240set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008241{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008242 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8243 int indir = (int)options[opt_idx].indir;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008244 sctx_T new_script_ctx = script_ctx;
8245
8246 new_script_ctx.sc_lnum += sourcing_lnum;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008247
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008248 /* Remember where the option was set. For local options need to do that
8249 * in the buffer or window structure. */
8250 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008251 options[opt_idx].script_ctx = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008252 if (both || (opt_flags & OPT_LOCAL))
8253 {
8254 if (indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008255 curbuf->b_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008256 else if (indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008257 curwin->w_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008258 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008259}
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02008260
8261/*
8262 * Set the script_ctx for a termcap option.
8263 * "name" must be the two character code, e.g. "RV".
8264 * When "name" is NULL use "opt_idx".
8265 */
8266 void
8267set_term_option_sctx_idx(char *name, int opt_idx)
8268{
8269 char_u buf[5];
8270 int idx;
8271
8272 if (name == NULL)
8273 idx = opt_idx;
8274 else
8275 {
8276 buf[0] = 't';
8277 buf[1] = '_';
8278 buf[2] = name[0];
8279 buf[3] = name[1];
8280 buf[4] = 0;
8281 idx = findoption(buf);
8282 }
8283 if (idx >= 0)
8284 set_option_sctx_idx(idx, OPT_GLOBAL, current_sctx);
8285}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008286#endif
8287
Bram Moolenaar071d4272004-06-13 20:20:40 +00008288/*
8289 * Set the value of a boolean option, and take care of side effects.
8290 * Returns NULL for success, or an error message for an error.
8291 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008292 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008293set_bool_option(
8294 int opt_idx, /* index in options[] table */
8295 char_u *varp, /* pointer to the option variable */
8296 int value, /* new value */
8297 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008298{
8299 int old_value = *(int *)varp;
8300
Bram Moolenaar071d4272004-06-13 20:20:40 +00008301 /* Disallow changing some options from secure mode */
8302 if ((secure
8303#ifdef HAVE_SANDBOX
8304 || sandbox != 0
8305#endif
8306 ) && (options[opt_idx].flags & P_SECURE))
8307 return e_secure;
8308
8309 *(int *)varp = value; /* set the new value */
8310#ifdef FEAT_EVAL
8311 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008312 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008313#endif
8314
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008315#ifdef FEAT_GUI
8316 need_mouse_correct = TRUE;
8317#endif
8318
Bram Moolenaar071d4272004-06-13 20:20:40 +00008319 /* May set global value for local option. */
8320 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8321 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8322
8323 /*
8324 * Handle side effects of changing a bool option.
8325 */
8326
8327 /* 'compatible' */
8328 if ((int *)varp == &p_cp)
8329 {
8330 compatible_set();
8331 }
8332
Bram Moolenaar920694c2016-08-21 17:45:02 +02008333#ifdef FEAT_LANGMAP
8334 if ((int *)varp == &p_lrm)
8335 /* 'langremap' -> !'langnoremap' */
8336 p_lnr = !p_lrm;
8337 else if ((int *)varp == &p_lnr)
8338 /* 'langnoremap' -> !'langremap' */
8339 p_lrm = !p_lnr;
8340#endif
8341
Bram Moolenaar8c63e0e2018-09-25 22:17:54 +02008342#ifdef FEAT_SYN_HL
8343 else if ((int *)varp == &curwin->w_p_cul && !value && old_value)
8344 reset_cursorline();
8345#endif
8346
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008347#ifdef FEAT_PERSISTENT_UNDO
8348 /* 'undofile' */
8349 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8350 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008351 /* Only take action when the option was set. When reset we do not
8352 * delete the undo file, the option may be set again without making
8353 * any changes in between. */
8354 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008355 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008356 char_u hash[UNDO_HASH_SIZE];
8357 buf_T *save_curbuf = curbuf;
8358
Bram Moolenaar29323592016-07-24 22:04:11 +02008359 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008360 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008361 /* When 'undofile' is set globally: for every buffer, otherwise
8362 * only for the current buffer: Try to read in the undofile,
8363 * if one exists, the buffer wasn't changed and the buffer was
8364 * loaded */
8365 if ((curbuf == save_curbuf
8366 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8367 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8368 {
8369 u_compute_hash(hash);
8370 u_read_undo(NULL, hash, curbuf->b_fname);
8371 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008372 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008373 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008374 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008375 }
8376#endif
8377
Bram Moolenaar071d4272004-06-13 20:20:40 +00008378 else if ((int *)varp == &curbuf->b_p_ro)
8379 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008380 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008381 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8382 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008383
8384 /* when 'readonly' is set may give W10 again */
8385 if (curbuf->b_p_ro)
8386 curbuf->b_did_warn = FALSE;
8387
Bram Moolenaar071d4272004-06-13 20:20:40 +00008388#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008389 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008390#endif
8391 }
8392
Bram Moolenaar9c449722010-07-20 18:44:27 +02008393#ifdef FEAT_GUI
8394 else if ((int *)varp == &p_mh)
8395 {
8396 if (!p_mh)
8397 gui_mch_mousehide(FALSE);
8398 }
8399#endif
8400
Bram Moolenaara539df02010-08-01 14:35:05 +02008401 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008402 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008403 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008404# ifdef FEAT_TERMINAL
8405 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaard7db27b2018-03-07 23:02:33 +01008406 if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf)
8407 && curbuf->b_term != NULL && !term_is_finished(curbuf))))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008408 {
8409 curbuf->b_p_ma = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008410 return N_("E946: Cannot make a terminal with running job modifiable");
Bram Moolenaar423802d2017-07-30 16:52:24 +02008411 }
8412# endif
8413# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008414 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008415# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008416 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008417#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008418 /* when 'endofline' is changed, redraw the window title */
8419 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008420 {
8421 redraw_titles();
8422 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008423 /* when 'fixeol' is changed, redraw the window title */
8424 else if ((int *)varp == &curbuf->b_p_fixeol)
8425 {
8426 redraw_titles();
8427 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008428 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008429 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008430 {
8431 redraw_titles();
8432 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008433#endif
8434
8435 /* when 'bin' is set also set some other options */
8436 else if ((int *)varp == &curbuf->b_p_bin)
8437 {
8438 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8439#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008440 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008441#endif
8442 }
8443
Bram Moolenaar071d4272004-06-13 20:20:40 +00008444 /* when 'buflisted' changes, trigger autocommands */
8445 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8446 {
8447 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8448 NULL, NULL, TRUE, curbuf);
8449 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008450
8451 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8452 else if ((int *)varp == &curbuf->b_p_swf)
8453 {
8454 if (curbuf->b_p_swf && p_uc)
8455 ml_open_file(curbuf); /* create the swap file */
8456 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008457 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8458 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008459 mf_close_file(curbuf, TRUE); /* remove the swap file */
8460 }
8461
8462 /* when 'terse' is set change 'shortmess' */
8463 else if ((int *)varp == &p_terse)
8464 {
8465 char_u *p;
8466
8467 p = vim_strchr(p_shm, SHM_SEARCH);
8468
8469 /* insert 's' in p_shm */
8470 if (p_terse && p == NULL)
8471 {
8472 STRCPY(IObuff, p_shm);
8473 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008474 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008475 }
8476 /* remove 's' from p_shm */
8477 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008478 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008479 }
8480
8481 /* when 'paste' is set or reset also change other options */
8482 else if ((int *)varp == &p_paste)
8483 {
8484 paste_option_changed();
8485 }
8486
8487 /* when 'insertmode' is set from an autocommand need to do work here */
8488 else if ((int *)varp == &p_im)
8489 {
8490 if (p_im)
8491 {
8492 if ((State & INSERT) == 0)
8493 need_start_insertmode = TRUE;
8494 stop_insert_mode = FALSE;
8495 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008496 /* only reset if it was set previously */
8497 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008498 {
8499 need_start_insertmode = FALSE;
8500 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008501 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008502 clear_cmdline = TRUE; /* remove "(insert)" */
8503 restart_edit = 0;
8504 }
8505 }
8506
8507 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8508 else if ((int *)varp == &p_ic && p_hls)
8509 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008510 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008511 }
8512
8513#ifdef FEAT_SEARCH_EXTRA
8514 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8515 else if ((int *)varp == &p_hls)
8516 {
Bram Moolenaar451fc7b2018-04-27 22:53:07 +02008517 set_no_hlsearch(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008518 }
8519#endif
8520
Bram Moolenaar071d4272004-06-13 20:20:40 +00008521 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8522 * at the end of normal_cmd() */
8523 else if ((int *)varp == &curwin->w_p_scb)
8524 {
8525 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008526 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008527 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008528 curwin->w_scbind_pos = curwin->w_topline;
8529 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008530 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008531
Bram Moolenaar4033c552017-09-16 20:54:51 +02008532#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008533 /* There can be only one window with 'previewwindow' set. */
8534 else if ((int *)varp == &curwin->w_p_pvw)
8535 {
8536 if (curwin->w_p_pvw)
8537 {
8538 win_T *win;
8539
Bram Moolenaar29323592016-07-24 22:04:11 +02008540 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008541 if (win->w_p_pvw && win != curwin)
8542 {
8543 curwin->w_p_pvw = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008544 return N_("E590: A preview window already exists");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008545 }
8546 }
8547 }
8548#endif
8549
8550 /* when 'textmode' is set or reset also change 'fileformat' */
8551 else if ((int *)varp == &curbuf->b_p_tx)
8552 {
8553 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8554 }
8555
8556 /* when 'textauto' is set or reset also change 'fileformats' */
8557 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008558 set_string_option_direct((char_u *)"ffs", -1,
8559 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008560 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008561
8562 /*
8563 * When 'lisp' option changes include/exclude '-' in
8564 * keyword characters.
8565 */
8566#ifdef FEAT_LISP
8567 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8568 {
8569 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8570 }
8571#endif
8572
8573#ifdef FEAT_TITLE
8574 /* when 'title' changed, may need to change the title; same for 'icon' */
Bram Moolenaar84a93082018-06-16 22:58:15 +02008575 else if ((int *)varp == &p_title || (int *)varp == &p_icon)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008576 {
Bram Moolenaar84a93082018-06-16 22:58:15 +02008577 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008578 }
8579#endif
8580
8581 else if ((int *)varp == &curbuf->b_changed)
8582 {
8583 if (!value)
8584 save_file_ff(curbuf); /* Buffer is unchanged */
8585#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008586 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008587#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008588 modified_was_set = value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008589 }
8590
8591#ifdef BACKSLASH_IN_FILENAME
8592 else if ((int *)varp == &p_ssl)
8593 {
8594 if (p_ssl)
8595 {
8596 psepc = '/';
8597 psepcN = '\\';
8598 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008599 }
8600 else
8601 {
8602 psepc = '\\';
8603 psepcN = '/';
8604 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008605 }
8606
8607 /* need to adjust the file name arguments and buffer names. */
8608 buflist_slash_adjust();
8609 alist_slash_adjust();
8610# ifdef FEAT_EVAL
8611 scriptnames_slash_adjust();
8612# endif
8613 }
8614#endif
8615
8616 /* If 'wrap' is set, set w_leftcol to zero. */
8617 else if ((int *)varp == &curwin->w_p_wrap)
8618 {
8619 if (curwin->w_p_wrap)
8620 curwin->w_leftcol = 0;
8621 }
8622
Bram Moolenaar071d4272004-06-13 20:20:40 +00008623 else if ((int *)varp == &p_ea)
8624 {
8625 if (p_ea && !old_value)
8626 win_equal(curwin, FALSE, 0);
8627 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008628
8629 else if ((int *)varp == &p_wiv)
8630 {
8631 /*
8632 * When 'weirdinvert' changed, set/reset 't_xs'.
8633 * Then set 'weirdinvert' according to value of 't_xs'.
8634 */
8635 if (p_wiv && !old_value)
8636 T_XS = (char_u *)"y";
8637 else if (!p_wiv && old_value)
8638 T_XS = empty_option;
8639 p_wiv = (*T_XS != NUL);
8640 }
8641
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008642#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008643 else if ((int *)varp == &p_beval)
8644 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008645 if (!balloonEvalForTerm)
8646 {
8647 if (p_beval && !old_value)
8648 gui_mch_enable_beval_area(balloonEval);
8649 else if (!p_beval && old_value)
8650 gui_mch_disable_beval_area(balloonEval);
8651 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008652 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008653#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008654#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008655 else if ((int *)varp == &p_bevalterm)
8656 {
8657 mch_bevalterm_changed();
8658 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008659#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008660
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008661#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008662 else if ((int *)varp == &p_acd)
8663 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008664 /* Change directories when the 'acd' option is set now. */
Bram Moolenaar6f470022018-04-10 18:47:20 +02008665 DO_AUTOCHDIR;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008666 }
8667#endif
8668
8669#ifdef FEAT_DIFF
8670 /* 'diff' */
8671 else if ((int *)varp == &curwin->w_p_diff)
8672 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008673 /* May add or remove the buffer from the list of diff buffers. */
8674 diff_buf_adjust(curwin);
8675# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008676 if (foldmethodIsDiff(curwin))
8677 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008678# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008679 }
8680#endif
8681
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008682#ifdef HAVE_INPUT_METHOD
Bram Moolenaar071d4272004-06-13 20:20:40 +00008683 /* 'imdisable' */
8684 else if ((int *)varp == &p_imdisable)
8685 {
8686 /* Only de-activate it here, it will be enabled when changing mode. */
8687 if (p_imdisable)
8688 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008689 else if (State & INSERT)
8690 /* When the option is set from an autocommand, it may need to take
8691 * effect right away. */
8692 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008693 }
8694#endif
8695
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008696#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008697 /* 'spell' */
8698 else if ((int *)varp == &curwin->w_p_spell)
8699 {
8700 if (curwin->w_p_spell)
8701 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008702 char *errmsg = did_set_spelllang(curwin);
8703
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008704 if (errmsg != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008705 emsg(_(errmsg));
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008706 }
8707 }
8708#endif
8709
Bram Moolenaar071d4272004-06-13 20:20:40 +00008710#ifdef FEAT_FKMAP
8711 else if ((int *)varp == &p_altkeymap)
8712 {
8713 if (old_value != p_altkeymap)
8714 {
8715 if (!p_altkeymap)
8716 {
8717 p_hkmap = p_fkmap;
8718 p_fkmap = 0;
8719 }
8720 else
8721 {
8722 p_fkmap = p_hkmap;
8723 p_hkmap = 0;
8724 }
8725 (void)init_chartab();
8726 }
8727 }
8728
8729 /*
8730 * In case some second language keymapping options have changed, check
8731 * and correct the setting in a consistent way.
8732 */
8733
8734 /*
8735 * If hkmap or fkmap are set, reset Arabic keymapping.
8736 */
8737 if ((p_hkmap || p_fkmap) && p_altkeymap)
8738 {
8739 p_altkeymap = p_fkmap;
8740# ifdef FEAT_ARABIC
8741 curwin->w_p_arab = FALSE;
8742# endif
8743 (void)init_chartab();
8744 }
8745
8746 /*
8747 * If hkmap set, reset Farsi keymapping.
8748 */
8749 if (p_hkmap && p_altkeymap)
8750 {
8751 p_altkeymap = 0;
8752 p_fkmap = 0;
8753# ifdef FEAT_ARABIC
8754 curwin->w_p_arab = FALSE;
8755# endif
8756 (void)init_chartab();
8757 }
8758
8759 /*
8760 * If fkmap set, reset Hebrew keymapping.
8761 */
8762 if (p_fkmap && !p_altkeymap)
8763 {
8764 p_altkeymap = 1;
8765 p_hkmap = 0;
8766# ifdef FEAT_ARABIC
8767 curwin->w_p_arab = FALSE;
8768# endif
8769 (void)init_chartab();
8770 }
8771#endif
8772
8773#ifdef FEAT_ARABIC
8774 if ((int *)varp == &curwin->w_p_arab)
8775 {
8776 if (curwin->w_p_arab)
8777 {
8778 /*
8779 * 'arabic' is set, handle various sub-settings.
8780 */
8781 if (!p_tbidi)
8782 {
8783 /* set rightleft mode */
8784 if (!curwin->w_p_rl)
8785 {
8786 curwin->w_p_rl = TRUE;
8787 changed_window_setting();
8788 }
8789
8790 /* Enable Arabic shaping (major part of what Arabic requires) */
8791 if (!p_arshape)
8792 {
8793 p_arshape = TRUE;
8794 redraw_later_clear();
8795 }
8796 }
8797
8798 /* Arabic requires a utf-8 encoding, inform the user if its not
8799 * set. */
8800 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008801 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008802 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8803
Bram Moolenaar8820b482017-03-16 17:23:31 +01008804 msg_source(HL_ATTR(HLF_W));
Bram Moolenaar32526b32019-01-19 17:43:09 +01008805 msg_attr(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008806#ifdef FEAT_EVAL
8807 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8808#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008809 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008810
Bram Moolenaar071d4272004-06-13 20:20:40 +00008811 /* set 'delcombine' */
8812 p_deco = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008813
8814# ifdef FEAT_KEYMAP
8815 /* Force-set the necessary keymap for arabic */
8816 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8817 OPT_LOCAL);
8818# endif
8819# ifdef FEAT_FKMAP
8820 p_altkeymap = 0;
8821 p_hkmap = 0;
8822 p_fkmap = 0;
8823 (void)init_chartab();
8824# endif
8825 }
8826 else
8827 {
8828 /*
8829 * 'arabic' is reset, handle various sub-settings.
8830 */
8831 if (!p_tbidi)
8832 {
8833 /* reset rightleft mode */
8834 if (curwin->w_p_rl)
8835 {
8836 curwin->w_p_rl = FALSE;
8837 changed_window_setting();
8838 }
8839
8840 /* 'arabicshape' isn't reset, it is a global option and
8841 * another window may still need it "on". */
8842 }
8843
8844 /* 'delcombine' isn't reset, it is a global option and another
8845 * window may still want it "on". */
8846
8847# ifdef FEAT_KEYMAP
8848 /* Revert to the default keymap */
8849 curbuf->b_p_iminsert = B_IMODE_NONE;
8850 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8851# endif
8852 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008853 }
8854
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008855#endif
8856
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008857#ifdef FEAT_TERMGUICOLORS
8858 /* 'termguicolors' */
8859 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008860 {
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008861# ifdef FEAT_VTP
8862 /* Do not turn on 'tgc' when 24-bit colors are not supported. */
8863 if (!has_vtp_working())
8864 {
8865 p_tgc = 0;
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01008866 return N_("E954: 24-bit colors are not supported on this environment");
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008867 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008868 if (is_term_win32())
8869 swap_tcap();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008870# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008871# ifdef FEAT_GUI
8872 if (!gui.in_use && !gui.starting)
8873# endif
8874 highlight_gui_started();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008875# ifdef FEAT_VTP
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008876 /* reset t_Co */
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008877 if (is_term_win32())
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02008878 {
8879 control_console_color_rgb();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008880 set_termname(T_NAME);
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02008881 init_highlight(TRUE, FALSE);
8882 }
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008883# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008884 }
8885#endif
8886
Bram Moolenaar071d4272004-06-13 20:20:40 +00008887 /*
8888 * End of handling side effects for bool options.
8889 */
8890
Bram Moolenaar53744302015-07-17 17:38:22 +02008891 /* after handling side effects, call autocommand */
8892
Bram Moolenaar071d4272004-06-13 20:20:40 +00008893 options[opt_idx].flags |= P_WAS_SET;
8894
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008895#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02008896 // Don't do this while starting up or recursively.
8897 if (!starting && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02008898 {
8899 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02008900
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008901 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8902 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8903 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008904 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8905 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8906 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8907 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8908 reset_v_option_vars();
8909 }
8910#endif
8911
Bram Moolenaar071d4272004-06-13 20:20:40 +00008912 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008913 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008914 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008915 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008916 check_redraw(options[opt_idx].flags);
8917
8918 return NULL;
8919}
8920
8921/*
8922 * Set the value of a number option, and take care of side effects.
8923 * Returns NULL for success, or an error message for an error.
8924 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008925 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008926set_num_option(
8927 int opt_idx, /* index in options[] table */
8928 char_u *varp, /* pointer to the option variable */
8929 long value, /* new value */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008930 char *errbuf, /* buffer for error messages */
Bram Moolenaar9b578142016-01-30 19:39:49 +01008931 size_t errbuflen, /* length of "errbuf" */
8932 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008933 OPT_MODELINE */
8934{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008935 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008936 long old_value = *(long *)varp;
8937 long old_Rows = Rows; /* remember old Rows */
8938 long old_Columns = Columns; /* remember old Columns */
8939 long *pp = (long *)varp;
8940
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008941 /* Disallow changing some options from secure mode. */
8942 if ((secure
8943#ifdef HAVE_SANDBOX
8944 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008945#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008946 ) && (options[opt_idx].flags & P_SECURE))
8947 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008948
8949 *pp = value;
8950#ifdef FEAT_EVAL
8951 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008952 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008953#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008954#ifdef FEAT_GUI
8955 need_mouse_correct = TRUE;
8956#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008957
Bram Moolenaar14f24742012-08-08 18:01:05 +02008958 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008959 {
8960 errmsg = e_positive;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02008961#ifdef FEAT_VARTABS
8962 // Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use.
8963 curbuf->b_p_sw = tabstop_count(curbuf->b_p_vts_array) > 0
8964 ? tabstop_first(curbuf->b_p_vts_array)
8965 : curbuf->b_p_ts;
8966#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00008967 curbuf->b_p_sw = curbuf->b_p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02008968#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008969 }
8970
8971 /*
8972 * Number options that need some action when changed
8973 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008974 if (pp == &p_wh || pp == &p_hh)
8975 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008976 // 'winheight' and 'helpheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008977 if (p_wh < 1)
8978 {
8979 errmsg = e_positive;
8980 p_wh = 1;
8981 }
8982 if (p_wmh > p_wh)
8983 {
8984 errmsg = e_winheight;
8985 p_wh = p_wmh;
8986 }
8987 if (p_hh < 0)
8988 {
8989 errmsg = e_positive;
8990 p_hh = 0;
8991 }
8992
8993 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008994 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008995 {
8996 if (pp == &p_wh && curwin->w_height < p_wh)
8997 win_setheight((int)p_wh);
8998 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8999 win_setheight((int)p_hh);
9000 }
9001 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009002 else if (pp == &p_wmh)
9003 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009004 // 'winminheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009005 if (p_wmh < 0)
9006 {
9007 errmsg = e_positive;
9008 p_wmh = 0;
9009 }
9010 if (p_wmh > p_wh)
9011 {
9012 errmsg = e_winheight;
9013 p_wmh = p_wh;
9014 }
9015 win_setminheight();
9016 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009017 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009018 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009019 // 'winwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009020 if (p_wiw < 1)
9021 {
9022 errmsg = e_positive;
9023 p_wiw = 1;
9024 }
9025 if (p_wmw > p_wiw)
9026 {
9027 errmsg = e_winwidth;
9028 p_wiw = p_wmw;
9029 }
9030
9031 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01009032 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009033 win_setwidth((int)p_wiw);
9034 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009035 else if (pp == &p_wmw)
9036 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009037 // 'winminwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009038 if (p_wmw < 0)
9039 {
9040 errmsg = e_positive;
9041 p_wmw = 0;
9042 }
9043 if (p_wmw > p_wiw)
9044 {
9045 errmsg = e_winwidth;
9046 p_wmw = p_wiw;
9047 }
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009048 win_setminwidth();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009049 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009050
Bram Moolenaar071d4272004-06-13 20:20:40 +00009051 /* (re)set last window status line */
9052 else if (pp == &p_ls)
9053 {
9054 last_status(FALSE);
9055 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009056
9057 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00009058 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009059 {
9060 shell_new_rows(); /* recompute window positions and heights */
9061 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009062
9063#ifdef FEAT_GUI
9064 else if (pp == &p_linespace)
9065 {
Bram Moolenaar02743632005-07-25 20:42:36 +00009066 /* Recompute gui.char_height and resize the Vim window to keep the
9067 * same number of lines. */
9068 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00009069 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009070 }
9071#endif
9072
9073#ifdef FEAT_FOLDING
9074 /* 'foldlevel' */
9075 else if (pp == &curwin->w_p_fdl)
9076 {
9077 if (curwin->w_p_fdl < 0)
9078 curwin->w_p_fdl = 0;
9079 newFoldLevel();
9080 }
9081
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00009082 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009083 else if (pp == &curwin->w_p_fml)
9084 {
9085 foldUpdateAll(curwin);
9086 }
9087
9088 /* 'foldnestmax' */
9089 else if (pp == &curwin->w_p_fdn)
9090 {
9091 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
9092 foldUpdateAll(curwin);
9093 }
9094
9095 /* 'foldcolumn' */
9096 else if (pp == &curwin->w_p_fdc)
9097 {
9098 if (curwin->w_p_fdc < 0)
9099 {
9100 errmsg = e_positive;
9101 curwin->w_p_fdc = 0;
9102 }
9103 else if (curwin->w_p_fdc > 12)
9104 {
9105 errmsg = e_invarg;
9106 curwin->w_p_fdc = 12;
9107 }
9108 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009109#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009110
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009111#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009112 /* 'shiftwidth' or 'tabstop' */
9113 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
9114 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009115# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00009116 if (foldmethodIsIndent(curwin))
9117 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009118# endif
9119# ifdef FEAT_CINDENT
9120 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
9121 * parse 'cinoptions'. */
9122 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
9123 parse_cino(curbuf);
9124# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009125 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009126#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009127
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009128 /* 'maxcombine' */
9129 else if (pp == &p_mco)
9130 {
9131 if (p_mco > MAX_MCO)
9132 p_mco = MAX_MCO;
9133 else if (p_mco < 0)
9134 p_mco = 0;
9135 screenclear(); /* will re-allocate the screen */
9136 }
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009137
Bram Moolenaar071d4272004-06-13 20:20:40 +00009138 else if (pp == &curbuf->b_p_iminsert)
9139 {
9140 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
9141 {
9142 errmsg = e_invarg;
9143 curbuf->b_p_iminsert = B_IMODE_NONE;
9144 }
9145 p_iminsert = curbuf->b_p_iminsert;
9146 if (termcap_active) /* don't do this in the alternate screen */
9147 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02009148#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009149 /* Show/unshow value of 'keymap' in status lines. */
9150 status_redraw_curbuf();
9151#endif
9152 }
9153
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02009154#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
9155 /* 'imstyle' */
9156 else if (pp == &p_imst)
9157 {
9158 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
9159 errmsg = e_invarg;
9160 }
9161#endif
9162
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009163 else if (pp == &p_window)
9164 {
9165 if (p_window < 1)
9166 p_window = 1;
9167 else if (p_window >= Rows)
9168 p_window = Rows - 1;
9169 }
9170
Bram Moolenaar071d4272004-06-13 20:20:40 +00009171 else if (pp == &curbuf->b_p_imsearch)
9172 {
9173 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
9174 {
9175 errmsg = e_invarg;
9176 curbuf->b_p_imsearch = B_IMODE_NONE;
9177 }
9178 p_imsearch = curbuf->b_p_imsearch;
9179 }
9180
9181#ifdef FEAT_TITLE
9182 /* if 'titlelen' has changed, redraw the title */
9183 else if (pp == &p_titlelen)
9184 {
9185 if (p_titlelen < 0)
9186 {
9187 errmsg = e_positive;
9188 p_titlelen = 85;
9189 }
9190 if (starting != NO_SCREEN && old_value != p_titlelen)
9191 need_maketitle = TRUE;
9192 }
9193#endif
9194
9195 /* if p_ch changed value, change the command line height */
9196 else if (pp == &p_ch)
9197 {
9198 if (p_ch < 1)
9199 {
9200 errmsg = e_positive;
9201 p_ch = 1;
9202 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009203 if (p_ch > Rows - min_rows() + 1)
9204 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009205
9206 /* Only compute the new window layout when startup has been
9207 * completed. Otherwise the frame sizes may be wrong. */
9208 if (p_ch != old_value && full_screen
9209#ifdef FEAT_GUI
9210 && !gui.starting
9211#endif
9212 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009213 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009214 }
9215
9216 /* when 'updatecount' changes from zero to non-zero, open swap files */
9217 else if (pp == &p_uc)
9218 {
9219 if (p_uc < 0)
9220 {
9221 errmsg = e_positive;
9222 p_uc = 100;
9223 }
9224 if (p_uc && !old_value)
9225 ml_open_files();
9226 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009227#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009228 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009229 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009230 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009231 {
9232 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009233 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009234 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009235 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009236 {
9237 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009238 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009239 }
9240 }
9241#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009242#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009243 else if (pp == &p_mzq)
9244 mzvim_reset_timer();
9245#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009246
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009247#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9248 /* 'pyxversion' */
9249 else if (pp == &p_pyx)
9250 {
9251 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9252 errmsg = e_invarg;
9253 }
9254#endif
9255
Bram Moolenaar071d4272004-06-13 20:20:40 +00009256 /* sync undo before 'undolevels' changes */
9257 else if (pp == &p_ul)
9258 {
9259 /* use the old value, otherwise u_sync() may not work properly */
9260 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009261 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009262 p_ul = value;
9263 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009264 else if (pp == &curbuf->b_p_ul)
9265 {
9266 /* use the old value, otherwise u_sync() may not work properly */
9267 curbuf->b_p_ul = old_value;
9268 u_sync(TRUE);
9269 curbuf->b_p_ul = value;
9270 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009271
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009272#ifdef FEAT_LINEBREAK
9273 /* 'numberwidth' must be positive */
9274 else if (pp == &curwin->w_p_nuw)
9275 {
9276 if (curwin->w_p_nuw < 1)
9277 {
9278 errmsg = e_positive;
9279 curwin->w_p_nuw = 1;
9280 }
9281 if (curwin->w_p_nuw > 10)
9282 {
9283 errmsg = e_invarg;
9284 curwin->w_p_nuw = 10;
9285 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009286 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009287 }
9288#endif
9289
Bram Moolenaar1a384422010-07-14 19:53:30 +02009290 else if (pp == &curbuf->b_p_tw)
9291 {
9292 if (curbuf->b_p_tw < 0)
9293 {
9294 errmsg = e_positive;
9295 curbuf->b_p_tw = 0;
9296 }
9297#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009298 {
9299 win_T *wp;
9300 tabpage_T *tp;
9301
9302 FOR_ALL_TAB_WINDOWS(tp, wp)
9303 check_colorcolumn(wp);
9304 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009305#endif
9306 }
9307
Bram Moolenaar071d4272004-06-13 20:20:40 +00009308 /*
9309 * Check the bounds for numeric options here
9310 */
9311 if (Rows < min_rows() && full_screen)
9312 {
9313 if (errbuf != NULL)
9314 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009315 vim_snprintf((char *)errbuf, errbuflen,
9316 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009317 errmsg = errbuf;
9318 }
9319 Rows = min_rows();
9320 }
9321 if (Columns < MIN_COLUMNS && full_screen)
9322 {
9323 if (errbuf != NULL)
9324 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009325 vim_snprintf((char *)errbuf, errbuflen,
9326 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009327 errmsg = errbuf;
9328 }
9329 Columns = MIN_COLUMNS;
9330 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009331 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009332
Bram Moolenaar071d4272004-06-13 20:20:40 +00009333 /*
9334 * If the screen (shell) height has been changed, assume it is the
9335 * physical screenheight.
9336 */
9337 if (old_Rows != Rows || old_Columns != Columns)
9338 {
9339 /* Changing the screen size is not allowed while updating the screen. */
9340 if (updating_screen)
9341 *pp = old_value;
9342 else if (full_screen
9343#ifdef FEAT_GUI
9344 && !gui.starting
9345#endif
9346 )
9347 set_shellsize((int)Columns, (int)Rows, TRUE);
9348 else
9349 {
9350 /* Postpone the resizing; check the size and cmdline position for
9351 * messages. */
9352 check_shellsize();
9353 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9354 cmdline_row = Rows - p_ch;
9355 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009356 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009357 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009358 }
9359
Bram Moolenaar071d4272004-06-13 20:20:40 +00009360 if (curbuf->b_p_ts <= 0)
9361 {
9362 errmsg = e_positive;
9363 curbuf->b_p_ts = 8;
9364 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009365 if (p_tm < 0)
9366 {
9367 errmsg = e_positive;
9368 p_tm = 0;
9369 }
9370 if ((curwin->w_p_scr <= 0
9371 || (curwin->w_p_scr > curwin->w_height
9372 && curwin->w_height > 0))
9373 && full_screen)
9374 {
9375 if (pp == &(curwin->w_p_scr))
9376 {
9377 if (curwin->w_p_scr != 0)
9378 errmsg = e_scroll;
9379 win_comp_scroll(curwin);
9380 }
9381 /* If 'scroll' became invalid because of a side effect silently adjust
9382 * it. */
9383 else if (curwin->w_p_scr <= 0)
9384 curwin->w_p_scr = 1;
9385 else /* curwin->w_p_scr > curwin->w_height */
9386 curwin->w_p_scr = curwin->w_height;
9387 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009388 if (p_hi < 0)
9389 {
9390 errmsg = e_positive;
9391 p_hi = 0;
9392 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009393 else if (p_hi > 10000)
9394 {
9395 errmsg = e_invarg;
9396 p_hi = 10000;
9397 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009398 if (p_re < 0 || p_re > 2)
9399 {
9400 errmsg = e_invarg;
9401 p_re = 0;
9402 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009403 if (p_report < 0)
9404 {
9405 errmsg = e_positive;
9406 p_report = 1;
9407 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009408 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009409 {
9410 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9411 p_sj = Rows / 2;
9412 else
9413 {
9414 errmsg = e_scroll;
9415 p_sj = 1;
9416 }
9417 }
9418 if (p_so < 0 && full_screen)
9419 {
Bram Moolenaar375e3392019-01-31 18:26:10 +01009420 errmsg = e_positive;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009421 p_so = 0;
9422 }
9423 if (p_siso < 0 && full_screen)
9424 {
9425 errmsg = e_positive;
9426 p_siso = 0;
9427 }
9428#ifdef FEAT_CMDWIN
9429 if (p_cwh < 1)
9430 {
9431 errmsg = e_positive;
9432 p_cwh = 1;
9433 }
9434#endif
9435 if (p_ut < 0)
9436 {
9437 errmsg = e_positive;
9438 p_ut = 2000;
9439 }
9440 if (p_ss < 0)
9441 {
9442 errmsg = e_positive;
9443 p_ss = 0;
9444 }
9445
9446 /* May set global value for local option. */
9447 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9448 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9449
9450 options[opt_idx].flags |= P_WAS_SET;
9451
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009452#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009453 // Don't do this while starting up, failure or recursively.
9454 if (!starting && errmsg == NULL && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009455 {
9456 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009457 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9458 vim_snprintf((char *)buf_new, 10, "%ld", value);
9459 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009460 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9461 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9462 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9463 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9464 reset_v_option_vars();
9465 }
9466#endif
9467
Bram Moolenaar071d4272004-06-13 20:20:40 +00009468 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009469 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009470 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009471 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009472 check_redraw(options[opt_idx].flags);
9473
9474 return errmsg;
9475}
9476
9477/*
9478 * Called after an option changed: check if something needs to be redrawn.
9479 */
9480 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009481check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009482{
9483 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009484 int doclear = (flags & P_RCLR) == P_RCLR;
9485 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009486
Bram Moolenaar071d4272004-06-13 20:20:40 +00009487 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9488 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009489
9490 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9491 changed_window_setting();
9492 if (flags & P_RBUF)
9493 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009494 if (flags & P_RWINONLY)
9495 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009496 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009497 redraw_all_later(CLEAR);
9498 else if (all)
9499 redraw_all_later(NOT_VALID);
9500}
9501
9502/*
9503 * Find index for option 'arg'.
9504 * Return -1 if not found.
9505 */
9506 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009507findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009508{
9509 int opt_idx;
9510 char *s, *p;
9511 static short quick_tab[27] = {0, 0}; /* quick access table */
9512 int is_term_opt;
9513
9514 /*
9515 * For first call: Initialize the quick-access table.
9516 * It contains the index for the first option that starts with a certain
9517 * letter. There are 26 letters, plus the first "t_" option.
9518 */
9519 if (quick_tab[1] == 0)
9520 {
9521 p = options[0].fullname;
9522 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9523 {
9524 if (s[0] != p[0])
9525 {
9526 if (s[0] == 't' && s[1] == '_')
9527 quick_tab[26] = opt_idx;
9528 else
9529 quick_tab[CharOrdLow(s[0])] = opt_idx;
9530 }
9531 p = s;
9532 }
9533 }
9534
9535 /*
9536 * Check for name starting with an illegal character.
9537 */
9538#ifdef EBCDIC
9539 if (!islower(arg[0]))
9540#else
9541 if (arg[0] < 'a' || arg[0] > 'z')
9542#endif
9543 return -1;
9544
9545 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9546 if (is_term_opt)
9547 opt_idx = quick_tab[26];
9548 else
9549 opt_idx = quick_tab[CharOrdLow(arg[0])];
9550 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9551 {
9552 if (STRCMP(arg, s) == 0) /* match full name */
9553 break;
9554 }
9555 if (s == NULL && !is_term_opt)
9556 {
9557 opt_idx = quick_tab[CharOrdLow(arg[0])];
9558 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9559 {
9560 s = options[opt_idx].shortname;
9561 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9562 break;
9563 s = NULL;
9564 }
9565 }
9566 if (s == NULL)
9567 opt_idx = -1;
9568 return opt_idx;
9569}
9570
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009571#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009572/*
9573 * Get the value for an option.
9574 *
9575 * Returns:
9576 * Number or Toggle option: 1, *numval gets value.
9577 * String option: 0, *stringval gets allocated string.
9578 * Hidden Number or Toggle option: -1.
9579 * hidden String option: -2.
9580 * unknown option: -3.
9581 */
9582 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009583get_option_value(
9584 char_u *name,
9585 long *numval,
9586 char_u **stringval, /* NULL when only checking existence */
9587 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009588{
9589 int opt_idx;
9590 char_u *varp;
9591
9592 opt_idx = findoption(name);
9593 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009594 {
9595 int key;
9596
9597 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009598 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009599 {
9600 char_u key_name[2];
9601 char_u *p;
9602
9603 if (key < 0)
9604 {
9605 key_name[0] = KEY2TERMCAP0(key);
9606 key_name[1] = KEY2TERMCAP1(key);
9607 }
9608 else
9609 {
9610 key_name[0] = KS_KEY;
9611 key_name[1] = (key & 0xff);
9612 }
9613 p = find_termcode(key_name);
9614 if (p != NULL)
9615 {
9616 if (stringval != NULL)
9617 *stringval = vim_strsave(p);
9618 return 0;
9619 }
9620 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009621 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009622 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009623
9624 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9625
9626 if (options[opt_idx].flags & P_STRING)
9627 {
9628 if (varp == NULL) /* hidden option */
9629 return -2;
9630 if (stringval != NULL)
9631 {
9632#ifdef FEAT_CRYPT
9633 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009634 if ((char_u **)varp == &curbuf->b_p_key
9635 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009636 *stringval = vim_strsave((char_u *)"*****");
9637 else
9638#endif
9639 *stringval = vim_strsave(*(char_u **)(varp));
9640 }
9641 return 0;
9642 }
9643
9644 if (varp == NULL) /* hidden option */
9645 return -1;
9646 if (options[opt_idx].flags & P_NUM)
9647 *numval = *(long *)varp;
9648 else
9649 {
9650 /* Special case: 'modified' is b_changed, but we also want to consider
9651 * it set when 'ff' or 'fenc' changed. */
9652 if ((int *)varp == &curbuf->b_changed)
9653 *numval = curbufIsChanged();
9654 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009655 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009656 }
9657 return 1;
9658}
9659#endif
9660
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009661#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009662/*
9663 * Returns the option attributes and its value. Unlike the above function it
9664 * will return either global value or local value of the option depending on
9665 * what was requested, but it will never return global value if it was
9666 * requested to return local one and vice versa. Neither it will return
9667 * buffer-local value if it was requested to return window-local one.
9668 *
9669 * Pretends that option is absent if it is not present in the requested scope
9670 * (i.e. has no global, window-local or buffer-local value depending on
9671 * opt_type). Uses
9672 *
9673 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009674 * 0 hidden or unknown option, also option that does not have requested
9675 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009676 * see SOPT_* in vim.h for other flags
9677 *
9678 * Possible opt_type values: see SREQ_* in vim.h
9679 */
9680 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009681get_option_value_strict(
9682 char_u *name,
9683 long *numval,
9684 char_u **stringval, /* NULL when only obtaining attributes */
9685 int opt_type,
9686 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009687{
9688 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009689 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009690 struct vimoption *p;
9691 int r = 0;
9692
9693 opt_idx = findoption(name);
9694 if (opt_idx < 0)
9695 return 0;
9696
9697 p = &(options[opt_idx]);
9698
9699 /* Hidden option */
9700 if (p->var == NULL)
9701 return 0;
9702
9703 if (p->flags & P_BOOL)
9704 r |= SOPT_BOOL;
9705 else if (p->flags & P_NUM)
9706 r |= SOPT_NUM;
9707 else if (p->flags & P_STRING)
9708 r |= SOPT_STRING;
9709
9710 if (p->indir == PV_NONE)
9711 {
9712 if (opt_type == SREQ_GLOBAL)
9713 r |= SOPT_GLOBAL;
9714 else
9715 return 0; /* Did not request global-only option */
9716 }
9717 else
9718 {
9719 if (p->indir & PV_BOTH)
9720 r |= SOPT_GLOBAL;
9721 else if (opt_type == SREQ_GLOBAL)
9722 return 0; /* Requested global option */
9723
9724 if (p->indir & PV_WIN)
9725 {
9726 if (opt_type == SREQ_BUF)
9727 return 0; /* Did not request window-local option */
9728 else
9729 r |= SOPT_WIN;
9730 }
9731 else if (p->indir & PV_BUF)
9732 {
9733 if (opt_type == SREQ_WIN)
9734 return 0; /* Did not request buffer-local option */
9735 else
9736 r |= SOPT_BUF;
9737 }
9738 }
9739
9740 if (stringval == NULL)
9741 return r;
9742
9743 if (opt_type == SREQ_GLOBAL)
9744 varp = p->var;
9745 else
9746 {
9747 if (opt_type == SREQ_BUF)
9748 {
9749 /* Special case: 'modified' is b_changed, but we also want to
9750 * consider it set when 'ff' or 'fenc' changed. */
9751 if (p->indir == PV_MOD)
9752 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009753 *numval = bufIsChanged((buf_T *)from);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009754 varp = NULL;
9755 }
9756#ifdef FEAT_CRYPT
9757 else if (p->indir == PV_KEY)
9758 {
9759 /* never return the value of the crypt key */
9760 *stringval = NULL;
9761 varp = NULL;
9762 }
9763#endif
9764 else
9765 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009766 buf_T *save_curbuf = curbuf;
9767
9768 // only getting a pointer, no need to use aucmd_prepbuf()
9769 curbuf = (buf_T *)from;
9770 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009771 varp = get_varp(p);
Bram Moolenaardefe6422018-06-24 15:14:07 +02009772 curbuf = save_curbuf;
9773 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009774 }
9775 }
9776 else if (opt_type == SREQ_WIN)
9777 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009778 win_T *save_curwin = curwin;
9779
9780 curwin = (win_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009781 curbuf = curwin->w_buffer;
9782 varp = get_varp(p);
9783 curwin = save_curwin;
9784 curbuf = curwin->w_buffer;
9785 }
9786 if (varp == p->var)
9787 return (r | SOPT_UNSET);
9788 }
9789
9790 if (varp != NULL)
9791 {
9792 if (p->flags & P_STRING)
9793 *stringval = vim_strsave(*(char_u **)(varp));
9794 else if (p->flags & P_NUM)
9795 *numval = *(long *) varp;
9796 else
9797 *numval = *(int *)varp;
9798 }
9799
9800 return r;
9801}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009802
9803/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009804 * Iterate over options. First argument is a pointer to a pointer to a
9805 * structure inside options[] array, second is option type like in the above
9806 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009807 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009808 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009809 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009810 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009811 * first argument to NULL.
9812 *
9813 * Returns full option name for current option on each call.
9814 */
9815 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009816option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009817{
9818 struct vimoption *ret = NULL;
9819 do
9820 {
9821 if (*option == NULL)
9822 *option = (void *) options;
9823 else if (((struct vimoption *) (*option))->fullname == NULL)
9824 {
9825 *option = NULL;
9826 return NULL;
9827 }
9828 else
9829 *option = (void *) (((struct vimoption *) (*option)) + 1);
9830
9831 ret = ((struct vimoption *) (*option));
9832
9833 /* Hidden option */
9834 if (ret->var == NULL)
9835 {
9836 ret = NULL;
9837 continue;
9838 }
9839
9840 switch (opt_type)
9841 {
9842 case SREQ_GLOBAL:
9843 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9844 ret = NULL;
9845 break;
9846 case SREQ_BUF:
9847 if (!(ret->indir & PV_BUF))
9848 ret = NULL;
9849 break;
9850 case SREQ_WIN:
9851 if (!(ret->indir & PV_WIN))
9852 ret = NULL;
9853 break;
9854 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009855 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009856 return NULL;
9857 }
9858 }
9859 while (ret == NULL);
9860
9861 return (char_u *)ret->fullname;
9862}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009863#endif
9864
Bram Moolenaar071d4272004-06-13 20:20:40 +00009865/*
9866 * Set the value of option "name".
9867 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009868 *
9869 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009870 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009871 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009872set_option_value(
9873 char_u *name,
9874 long number,
9875 char_u *string,
9876 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009877{
9878 int opt_idx;
9879 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009880 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009881
9882 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009883 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009884 {
9885 int key;
9886
9887 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009888 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009889 {
9890 char_u key_name[2];
9891
9892 if (key < 0)
9893 {
9894 key_name[0] = KEY2TERMCAP0(key);
9895 key_name[1] = KEY2TERMCAP1(key);
9896 }
9897 else
9898 {
9899 key_name[0] = KS_KEY;
9900 key_name[1] = (key & 0xff);
9901 }
9902 add_termcode(key_name, string, FALSE);
9903 if (full_screen)
9904 ttest(FALSE);
9905 redraw_all_later(CLEAR);
9906 return NULL;
9907 }
9908
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009909 semsg(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009910 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009911 else
9912 {
9913 flags = options[opt_idx].flags;
9914#ifdef HAVE_SANDBOX
9915 /* Disallow changing some options in the sandbox */
9916 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009917 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009918 emsg(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009919 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009920 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009921#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009922 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009923 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009924 else
9925 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009926 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009927 if (varp != NULL) /* hidden option is not changed */
9928 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009929 if (number == 0 && string != NULL)
9930 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009931 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009932
9933 /* Either we are given a string or we are setting option
9934 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009935 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009936 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009937 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009938 {
9939 /* There's another character after zeros or the string
9940 * is empty. In both cases, we are trying to set a
9941 * num option using a string. */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009942 semsg(_("E521: Number required: &%s = '%s'"),
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009943 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009944 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009945
9946 }
9947 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009948 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009949 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009950 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009951 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009952 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009953 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009954 }
9955 }
9956 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009957 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009958}
9959
9960/*
9961 * Get the terminal code for a terminal option.
9962 * Returns NULL when not found.
9963 */
9964 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009965get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009966{
9967 int opt_idx;
9968 char_u *varp;
9969
9970 if (tname[0] != 't' || tname[1] != '_' ||
9971 tname[2] == NUL || tname[3] == NUL)
9972 return NULL;
9973 if ((opt_idx = findoption(tname)) >= 0)
9974 {
9975 varp = get_varp(&(options[opt_idx]));
9976 if (varp != NULL)
9977 varp = *(char_u **)(varp);
9978 return varp;
9979 }
9980 return find_termcode(tname + 2);
9981}
9982
9983 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009984get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009985{
9986 int i;
9987
9988 i = findoption((char_u *)"hl");
9989 if (i >= 0)
9990 return options[i].def_val[VI_DEFAULT];
9991 return (char_u *)NULL;
9992}
9993
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009994 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009995get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009996{
9997 int i;
9998
9999 i = findoption((char_u *)"enc");
10000 if (i >= 0)
10001 return options[i].def_val[VI_DEFAULT];
10002 return (char_u *)NULL;
10003}
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010004
Bram Moolenaar071d4272004-06-13 20:20:40 +000010005/*
10006 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010007 * When "has_lt" is true there is a '<' before "*arg_arg".
10008 * Returns 0 when the key is not recognized.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010009 */
10010 static int
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010011find_key_option(char_u *arg_arg, int has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010012{
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010013 int key = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010014 int modifiers;
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010015 char_u *arg = arg_arg;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010016
10017 /*
10018 * Don't use get_special_key_code() for t_xx, we don't want it to call
10019 * add_termcap_entry().
10020 */
10021 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
10022 key = TERMCAP2KEY(arg[2], arg[3]);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010023 else if (has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010024 {
10025 --arg; /* put arg at the '<' */
10026 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +020010027 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010028 if (modifiers) /* can't handle modifiers here */
10029 key = 0;
10030 }
10031 return key;
10032}
10033
10034/*
10035 * if 'all' == 0: show changed options
10036 * if 'all' == 1: show all normal options
10037 * if 'all' == 2: show all terminal options
10038 */
10039 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010040showoptions(
10041 int all,
10042 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010043{
10044 struct vimoption *p;
10045 int col;
10046 int isterm;
10047 char_u *varp;
10048 struct vimoption **items;
10049 int item_count;
10050 int run;
10051 int row, rows;
10052 int cols;
10053 int i;
10054 int len;
10055
10056#define INC 20
10057#define GAP 3
10058
10059 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
10060 PARAM_COUNT));
10061 if (items == NULL)
10062 return;
10063
10064 /* Highlight title */
10065 if (all == 2)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010066 msg_puts_title(_("\n--- Terminal codes ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010067 else if (opt_flags & OPT_GLOBAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010068 msg_puts_title(_("\n--- Global option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010069 else if (opt_flags & OPT_LOCAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010070 msg_puts_title(_("\n--- Local option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010071 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010072 msg_puts_title(_("\n--- Options ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010073
10074 /*
10075 * do the loop two times:
10076 * 1. display the short items
10077 * 2. display the long items (only strings and numbers)
10078 */
10079 for (run = 1; run <= 2 && !got_int; ++run)
10080 {
10081 /*
10082 * collect the items in items[]
10083 */
10084 item_count = 0;
10085 for (p = &options[0]; p->fullname != NULL; p++)
10086 {
Bram Moolenaarf86db782018-10-25 13:31:37 +020010087 // apply :filter /pat/
10088 if (message_filtered((char_u *) p->fullname))
10089 continue;
10090
Bram Moolenaar071d4272004-06-13 20:20:40 +000010091 varp = NULL;
10092 isterm = istermoption(p);
10093 if (opt_flags != 0)
10094 {
10095 if (p->indir != PV_NONE && !isterm)
10096 varp = get_varp_scope(p, opt_flags);
10097 }
10098 else
10099 varp = get_varp(p);
10100 if (varp != NULL
10101 && ((all == 2 && isterm)
10102 || (all == 1 && !isterm)
10103 || (all == 0 && !optval_default(p, varp))))
10104 {
10105 if (p->flags & P_BOOL)
10106 len = 1; /* a toggle option fits always */
10107 else
10108 {
10109 option_value2string(p, opt_flags);
10110 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
10111 }
10112 if ((len <= INC - GAP && run == 1) ||
10113 (len > INC - GAP && run == 2))
10114 items[item_count++] = p;
10115 }
10116 }
10117
10118 /*
10119 * display the items
10120 */
10121 if (run == 1)
10122 {
10123 cols = (Columns + GAP - 3) / INC;
10124 if (cols == 0)
10125 cols = 1;
10126 rows = (item_count + cols - 1) / cols;
10127 }
10128 else /* run == 2 */
10129 rows = item_count;
10130 for (row = 0; row < rows && !got_int; ++row)
10131 {
10132 msg_putchar('\n'); /* go to next line */
10133 if (got_int) /* 'q' typed in more */
10134 break;
10135 col = 0;
10136 for (i = row; i < item_count; i += rows)
10137 {
10138 msg_col = col; /* make columns */
10139 showoneopt(items[i], opt_flags);
10140 col += INC;
10141 }
10142 out_flush();
10143 ui_breakcheck();
10144 }
10145 }
10146 vim_free(items);
10147}
10148
10149/*
10150 * Return TRUE if option "p" has its default value.
10151 */
10152 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010153optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010154{
10155 int dvi;
10156
10157 if (varp == NULL)
10158 return TRUE; /* hidden option is always at default */
10159 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
10160 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010161 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010162 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010163 /* the cast to long is required for Manx C, long_i is
10164 * needed for MSVC */
10165 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010166 /* P_STRING */
10167 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
10168}
10169
10170/*
10171 * showoneopt: show the value of one option
10172 * must not be called with a hidden option!
10173 */
10174 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010175showoneopt(
10176 struct vimoption *p,
10177 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010178{
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010179 char_u *varp;
10180 int save_silent = silent_mode;
10181
10182 silent_mode = FALSE;
10183 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010184
10185 varp = get_varp_scope(p, opt_flags);
10186
10187 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
10188 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
10189 ? !curbufIsChanged() : !*(int *)varp))
Bram Moolenaar32526b32019-01-19 17:43:09 +010010190 msg_puts("no");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010191 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010192 msg_puts("--");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010193 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010194 msg_puts(" ");
10195 msg_puts(p->fullname);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010196 if (!(p->flags & P_BOOL))
10197 {
10198 msg_putchar('=');
10199 /* put value string in NameBuff */
10200 option_value2string(p, opt_flags);
10201 msg_outtrans(NameBuff);
10202 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010203
10204 silent_mode = save_silent;
10205 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010206}
10207
10208/*
10209 * Write modified options as ":set" commands to a file.
10210 *
10211 * There are three values for "opt_flags":
10212 * OPT_GLOBAL: Write global option values and fresh values of
10213 * buffer-local options (used for start of a session
10214 * file).
10215 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10216 * curwin (used for a vimrc file).
10217 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10218 * and local values for window-local options of
10219 * curwin. Local values are also written when at the
10220 * default value, because a modeline or autocommand
10221 * may have set them when doing ":edit file" and the
10222 * user has set them back at the default or fresh
10223 * value.
10224 * When "local_only" is TRUE, don't write fresh
10225 * values, only local values (for ":mkview").
10226 * (fresh value = value used for a new buffer or window for a local option).
10227 *
10228 * Return FAIL on error, OK otherwise.
10229 */
10230 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010231makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010232{
10233 struct vimoption *p;
10234 char_u *varp; /* currently used value */
10235 char_u *varp_fresh; /* local value */
10236 char_u *varp_local = NULL; /* fresh value */
10237 char *cmd;
10238 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010239 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010240
10241 /*
10242 * The options that don't have a default (terminal name, columns, lines)
10243 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010244 * Do the loop over "options[]" twice: once for options with the
10245 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010246 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010247 for (pri = 1; pri >= 0; --pri)
10248 {
10249 for (p = &options[0]; !istermoption(p); p++)
10250 if (!(p->flags & P_NO_MKRC)
10251 && !istermoption(p)
10252 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010253 {
10254 /* skip global option when only doing locals */
10255 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10256 continue;
10257
10258 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10259 * file, they are always buffer-specific. */
10260 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10261 continue;
10262
10263 /* Global values are only written when not at the default value. */
10264 varp = get_varp_scope(p, opt_flags);
10265 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10266 continue;
10267
10268 round = 2;
10269 if (p->indir != PV_NONE)
10270 {
10271 if (p->var == VAR_WIN)
10272 {
10273 /* skip window-local option when only doing globals */
10274 if (!(opt_flags & OPT_LOCAL))
10275 continue;
10276 /* When fresh value of window-local option is not at the
10277 * default, need to write it too. */
10278 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10279 {
10280 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10281 if (!optval_default(p, varp_fresh))
10282 {
10283 round = 1;
10284 varp_local = varp;
10285 varp = varp_fresh;
10286 }
10287 }
10288 }
10289 }
10290
10291 /* Round 1: fresh value for window-local options.
10292 * Round 2: other values */
10293 for ( ; round <= 2; varp = varp_local, ++round)
10294 {
10295 if (round == 1 || (opt_flags & OPT_GLOBAL))
10296 cmd = "set";
10297 else
10298 cmd = "setlocal";
10299
10300 if (p->flags & P_BOOL)
10301 {
10302 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10303 return FAIL;
10304 }
10305 else if (p->flags & P_NUM)
10306 {
10307 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10308 return FAIL;
10309 }
10310 else /* P_STRING */
10311 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010312 int do_endif = FALSE;
10313
Bram Moolenaar071d4272004-06-13 20:20:40 +000010314 /* Don't set 'syntax' and 'filetype' again if the value is
10315 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010316 if (
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +010010317#if defined(FEAT_SYN_HL)
10318 p->indir == PV_SYN ||
10319#endif
10320 p->indir == PV_FT)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010321 {
10322 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10323 *(char_u **)(varp)) < 0
10324 || put_eol(fd) < 0)
10325 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010326 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010327 }
10328 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010329 p->flags) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010330 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010331 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010332 {
10333 if (put_line(fd, "endif") == FAIL)
10334 return FAIL;
10335 }
10336 }
10337 }
10338 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010339 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010340 return OK;
10341}
10342
10343#if defined(FEAT_FOLDING) || defined(PROTO)
10344/*
10345 * Generate set commands for the local fold options only. Used when
10346 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10347 */
10348 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010349makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010350{
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010351 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, 0) == FAIL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010352# ifdef FEAT_EVAL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010353 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010354 == FAIL
10355# endif
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010356 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010357 == FAIL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010358 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010359 == FAIL
10360 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10361 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10362 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10363 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10364 )
10365 return FAIL;
10366
10367 return OK;
10368}
10369#endif
10370
10371 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010372put_setstring(
10373 FILE *fd,
10374 char *cmd,
10375 char *name,
10376 char_u **valuep,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010377 long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010378{
10379 char_u *s;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010380 char_u *buf = NULL;
10381 char_u *part = NULL;
10382 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010383
10384 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10385 return FAIL;
10386 if (*valuep != NULL)
10387 {
10388 /* Output 'pastetoggle' as key names. For other
10389 * options some characters have to be escaped with
10390 * CTRL-V or backslash */
10391 if (valuep == &p_pt)
10392 {
10393 s = *valuep;
10394 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010395 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010396 return FAIL;
10397 }
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010398 // expand the option value, replace $HOME by ~
10399 else if ((flags & P_EXPAND) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010400 {
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010401 int size = (int)STRLEN(*valuep) + 1;
10402
10403 // replace home directory in the whole option value into "buf"
10404 buf = alloc(size);
Bram Moolenaarf8441472011-04-28 17:24:58 +020010405 if (buf == NULL)
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010406 goto fail;
10407 home_replace(NULL, *valuep, buf, size, FALSE);
10408
10409 // If the option value is longer than MAXPATHL, we need to append
10410 // earch comma separated part of the option separately, so that it
10411 // can be expanded when read back.
10412 if (size >= MAXPATHL && (flags & P_COMMA) != 0
10413 && vim_strchr(*valuep, ',') != NULL)
10414 {
10415 part = alloc(size);
10416 if (part == NULL)
10417 goto fail;
10418
10419 // write line break to clear the option, e.g. ':set rtp='
10420 if (put_eol(fd) == FAIL)
10421 goto fail;
10422
10423 p = buf;
10424 while (*p != NUL)
10425 {
10426 // for each comma separated option part, append value to
10427 // the option, :set rtp+=value
10428 if (fprintf(fd, "%s %s+=", cmd, name) < 0)
10429 goto fail;
10430 (void)copy_option_part(&p, part, size, ",");
10431 if (put_escstr(fd, part, 2) == FAIL || put_eol(fd) == FAIL)
10432 goto fail;
10433 }
10434 vim_free(buf);
10435 vim_free(part);
10436 return OK;
10437 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010438 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010439 {
10440 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010441 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010442 }
10443 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010444 }
10445 else if (put_escstr(fd, *valuep, 2) == FAIL)
10446 return FAIL;
10447 }
10448 if (put_eol(fd) < 0)
10449 return FAIL;
10450 return OK;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010451fail:
10452 vim_free(buf);
10453 vim_free(part);
10454 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010455}
10456
10457 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010458put_setnum(
10459 FILE *fd,
10460 char *cmd,
10461 char *name,
10462 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010463{
10464 long wc;
10465
10466 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10467 return FAIL;
10468 if (wc_use_keyname((char_u *)valuep, &wc))
10469 {
10470 /* print 'wildchar' and 'wildcharm' as a key name */
10471 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10472 return FAIL;
10473 }
10474 else if (fprintf(fd, "%ld", *valuep) < 0)
10475 return FAIL;
10476 if (put_eol(fd) < 0)
10477 return FAIL;
10478 return OK;
10479}
10480
10481 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010482put_setbool(
10483 FILE *fd,
10484 char *cmd,
10485 char *name,
10486 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010487{
Bram Moolenaar893de922007-10-02 18:40:57 +000010488 if (value < 0) /* global/local option using global value */
10489 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010490 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10491 || put_eol(fd) < 0)
10492 return FAIL;
10493 return OK;
10494}
10495
10496/*
10497 * Clear all the terminal options.
10498 * If the option has been allocated, free the memory.
10499 * Terminal options are never hidden or indirect.
10500 */
10501 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010502clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010503{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010504 /*
10505 * Reset a few things before clearing the old options. This may cause
10506 * outputting a few things that the terminal doesn't understand, but the
10507 * screen will be cleared later, so this is OK.
10508 */
10509#ifdef FEAT_MOUSE_TTY
10510 mch_setmouse(FALSE); /* switch mouse off */
10511#endif
10512#ifdef FEAT_TITLE
Bram Moolenaar40385db2018-08-07 22:31:44 +020010513 mch_restore_title(SAVE_RESTORE_BOTH); /* restore window titles */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010514#endif
10515#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10516 /* When starting the GUI close the display opened for the clipboard.
10517 * After restoring the title, because that will need the display. */
10518 if (gui.starting)
10519 clear_xterm_clip();
10520#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010521 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010522
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010523 free_termoptions();
10524}
10525
10526 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010527free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010528{
10529 struct vimoption *p;
10530
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010531 for (p = options; p->fullname != NULL; p++)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010532 if (istermoption(p))
10533 {
10534 if (p->flags & P_ALLOCED)
10535 free_string_option(*(char_u **)(p->var));
10536 if (p->flags & P_DEF_ALLOCED)
10537 free_string_option(p->def_val[VI_DEFAULT]);
10538 *(char_u **)(p->var) = empty_option;
10539 p->def_val[VI_DEFAULT] = empty_option;
10540 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010541#ifdef FEAT_EVAL
10542 // remember where the option was cleared
10543 set_option_sctx_idx((int)(p - options), OPT_GLOBAL, current_sctx);
10544#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010545 }
10546 clear_termcodes();
10547}
10548
10549/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010550 * Free the string for one term option, if it was allocated.
10551 * Set the string to empty_option and clear allocated flag.
10552 * "var" points to the option value.
10553 */
10554 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010555free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010556{
10557 struct vimoption *p;
10558
10559 for (p = &options[0]; p->fullname != NULL; p++)
10560 if (p->var == var)
10561 {
10562 if (p->flags & P_ALLOCED)
10563 free_string_option(*(char_u **)(p->var));
10564 *(char_u **)(p->var) = empty_option;
10565 p->flags &= ~P_ALLOCED;
10566 break;
10567 }
10568}
10569
10570/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010571 * Set the terminal option defaults to the current value.
10572 * Used after setting the terminal name.
10573 */
10574 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010575set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010576{
10577 struct vimoption *p;
10578
10579 for (p = &options[0]; p->fullname != NULL; p++)
10580 {
10581 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10582 {
10583 if (p->flags & P_DEF_ALLOCED)
10584 {
10585 free_string_option(p->def_val[VI_DEFAULT]);
10586 p->flags &= ~P_DEF_ALLOCED;
10587 }
10588 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10589 if (p->flags & P_ALLOCED)
10590 {
10591 p->flags |= P_DEF_ALLOCED;
10592 p->flags &= ~P_ALLOCED; /* don't free the value now */
10593 }
10594 }
10595 }
10596}
10597
10598/*
10599 * return TRUE if 'p' starts with 't_'
10600 */
10601 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010602istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010603{
10604 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10605}
10606
10607/*
10608 * Compute columns for ruler and shown command. 'sc_col' is also used to
10609 * decide what the maximum length of a message on the status line can be.
10610 * If there is a status line for the last window, 'sc_col' is independent
10611 * of 'ru_col'.
10612 */
10613
10614#define COL_RULER 17 /* columns needed by standard ruler */
10615
10616 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010617comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010618{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010619#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010620 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010621
10622 sc_col = 0;
10623 ru_col = 0;
10624 if (p_ru)
10625 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010626# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010627 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010628# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010629 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010630# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010631 /* no last status line, adjust sc_col */
10632 if (!last_has_status)
10633 sc_col = ru_col;
10634 }
10635 if (p_sc)
10636 {
10637 sc_col += SHOWCMD_COLS;
10638 if (!p_ru || last_has_status) /* no need for separating space */
10639 ++sc_col;
10640 }
10641 sc_col = Columns - sc_col;
10642 ru_col = Columns - ru_col;
10643 if (sc_col <= 0) /* screen too narrow, will become a mess */
10644 sc_col = 1;
10645 if (ru_col <= 0)
10646 ru_col = 1;
10647#else
10648 sc_col = Columns;
10649 ru_col = Columns;
10650#endif
10651}
10652
Bram Moolenaar113e1072019-01-20 15:30:40 +010010653#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010654/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010655 * Unset local option value, similar to ":set opt<".
10656 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010657 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010658unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010659{
10660 struct vimoption *p;
10661 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010662 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010663
10664 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010665 if (opt_idx < 0)
10666 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010667 p = &(options[opt_idx]);
10668
10669 switch ((int)p->indir)
10670 {
10671 /* global option with local value: use local value if it's been set */
10672 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010673 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010674 break;
10675 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010676 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010677 break;
10678 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010679 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010680 break;
10681 case PV_AR:
10682 buf->b_p_ar = -1;
10683 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010684 case PV_BKC:
10685 clear_string_option(&buf->b_p_bkc);
10686 buf->b_bkc_flags = 0;
10687 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010688 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010689 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010690 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010691 case PV_TC:
10692 clear_string_option(&buf->b_p_tc);
10693 buf->b_tc_flags = 0;
10694 break;
Bram Moolenaar375e3392019-01-31 18:26:10 +010010695 case PV_SISO:
10696 curwin->w_p_siso = -1;
10697 break;
10698 case PV_SO:
10699 curwin->w_p_so = -1;
10700 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010701#ifdef FEAT_FIND_ID
10702 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010703 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010704 break;
10705 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010706 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010707 break;
10708#endif
10709#ifdef FEAT_INS_EXPAND
10710 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010711 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010712 break;
10713 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010714 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010715 break;
10716#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010717 case PV_FP:
10718 clear_string_option(&buf->b_p_fp);
10719 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010720#ifdef FEAT_QUICKFIX
10721 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010722 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010723 break;
10724 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010725 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010726 break;
10727 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010728 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010729 break;
10730#endif
10731#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10732 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010733 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010734 break;
10735#endif
10736#if defined(FEAT_CRYPT)
10737 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010738 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010739 break;
10740#endif
10741#ifdef FEAT_STL_OPT
10742 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010743 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010744 break;
10745#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010746 case PV_UL:
10747 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10748 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010749#ifdef FEAT_LISP
10750 case PV_LW:
10751 clear_string_option(&buf->b_p_lw);
10752 break;
10753#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010754 case PV_MENC:
10755 clear_string_option(&buf->b_p_menc);
10756 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010757 }
10758}
Bram Moolenaar113e1072019-01-20 15:30:40 +010010759#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010760
10761/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010762 * Get pointer to option variable, depending on local or global scope.
10763 */
10764 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010765get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010766{
10767 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10768 {
10769 if (p->var == VAR_WIN)
10770 return (char_u *)GLOBAL_WO(get_varp(p));
10771 return p->var;
10772 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010773 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010774 {
10775 switch ((int)p->indir)
10776 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010777 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010778#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010779 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10780 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10781 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010782#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010783 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10784 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10785 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010786 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010787 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010788 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar375e3392019-01-31 18:26:10 +010010789 case PV_SISO: return (char_u *)&(curwin->w_p_siso);
10790 case PV_SO: return (char_u *)&(curwin->w_p_so);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010791#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010792 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10793 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010794#endif
10795#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010796 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10797 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010798#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010799#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10800 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10801#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010802#if defined(FEAT_CRYPT)
10803 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10804#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010805#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010806 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010807#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010808 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010809#ifdef FEAT_LISP
10810 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10811#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010812 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010813 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010814 }
10815 return NULL; /* "cannot happen" */
10816 }
10817 return get_varp(p);
10818}
10819
10820/*
10821 * Get pointer to option variable.
10822 */
10823 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010824get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010825{
10826 /* hidden option, always return NULL */
10827 if (p->var == NULL)
10828 return NULL;
10829
10830 switch ((int)p->indir)
10831 {
10832 case PV_NONE: return p->var;
10833
10834 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010835 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010836 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010837 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010838 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010839 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010840 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010841 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010842 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010843 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010844 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010845 case PV_TC: return *curbuf->b_p_tc != NUL
10846 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010847 case PV_BKC: return *curbuf->b_p_bkc != NUL
10848 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar375e3392019-01-31 18:26:10 +010010849 case PV_SISO: return curwin->w_p_siso >= 0
10850 ? (char_u *)&(curwin->w_p_siso) : p->var;
10851 case PV_SO: return curwin->w_p_so >= 0
10852 ? (char_u *)&(curwin->w_p_so) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010853#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010854 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010855 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010856 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010857 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10858#endif
10859#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010860 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010861 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010862 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010863 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10864#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010865 case PV_FP: return *curbuf->b_p_fp != NUL
10866 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010867#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010868 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010869 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010870 case PV_GP: return *curbuf->b_p_gp != NUL
10871 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10872 case PV_MP: return *curbuf->b_p_mp != NUL
10873 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010874#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010875#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10876 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10877 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10878#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010879#if defined(FEAT_CRYPT)
10880 case PV_CM: return *curbuf->b_p_cm != NUL
10881 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10882#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010883#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010884 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010885 ? (char_u *)&(curwin->w_p_stl) : p->var;
10886#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010887 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10888 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010889#ifdef FEAT_LISP
10890 case PV_LW: return *curbuf->b_p_lw != NUL
10891 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10892#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010893 case PV_MENC: return *curbuf->b_p_menc != NUL
10894 ? (char_u *)&(curbuf->b_p_menc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010895
10896#ifdef FEAT_ARABIC
10897 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10898#endif
10899 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010900#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010901 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10902#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010903#ifdef FEAT_SYN_HL
10904 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10905 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010906 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010907#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010908#ifdef FEAT_DIFF
10909 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10910#endif
10911#ifdef FEAT_FOLDING
10912 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10913 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10914 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10915 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10916 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10917 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10918 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10919# ifdef FEAT_EVAL
10920 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10921 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10922# endif
10923 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10924#endif
10925 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010926 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010927#ifdef FEAT_LINEBREAK
10928 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10929#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010930 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010931 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020010932#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010933 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10934#endif
10935#ifdef FEAT_RIGHTLEFT
10936 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10937 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10938#endif
10939 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10940 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10941#ifdef FEAT_LINEBREAK
10942 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010943 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10944 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010945#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010946 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010947 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010948#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010949 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10950 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10951#endif
10952#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020010953 case PV_TWK: return (char_u *)&(curwin->w_p_twk);
10954 case PV_TWS: return (char_u *)&(curwin->w_p_tws);
10955 case PV_TWSL: return (char_u *)&(curbuf->b_p_twsl);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010956#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010957
10958 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10959 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010960 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010961 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10962 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010963 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10964 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10965#ifdef FEAT_CINDENT
10966 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10967 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10968 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10969#endif
10970#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10971 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10972#endif
10973#ifdef FEAT_COMMENTS
10974 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10975#endif
10976#ifdef FEAT_FOLDING
10977 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10978#endif
10979#ifdef FEAT_INS_EXPAND
10980 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10981#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010982#ifdef FEAT_COMPL_FUNC
10983 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010984 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010985#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010986 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010987 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010988 case PV_ET: return (char_u *)&(curbuf->b_p_et);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010989 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010990 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010991 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010992 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010993 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010994 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10995 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10996 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10997 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10998#ifdef FEAT_FIND_ID
10999# ifdef FEAT_EVAL
11000 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
11001# endif
11002#endif
11003#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11004 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
11005 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
11006#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011007#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011008 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
11009#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011010#ifdef FEAT_CRYPT
11011 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
11012#endif
11013#ifdef FEAT_LISP
11014 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
11015#endif
11016 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
11017 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
11018 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
11019 case PV_MOD: return (char_u *)&(curbuf->b_changed);
11020 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011021 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011022#ifdef FEAT_TEXTOBJ
11023 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
11024#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011025 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
11026#ifdef FEAT_SMARTINDENT
11027 case PV_SI: return (char_u *)&(curbuf->b_p_si);
11028#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011029 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011030 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
11031#ifdef FEAT_SEARCHPATH
11032 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
11033#endif
11034 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
11035#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011036 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011037 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
11038#endif
11039#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020011040 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
11041 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
11042 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011043#endif
11044 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
11045 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
11046 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
11047 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011048#ifdef FEAT_PERSISTENT_UNDO
11049 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
11050#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011051 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
11052#ifdef FEAT_KEYMAP
11053 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
11054#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011055#ifdef FEAT_SIGNS
11056 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
11057#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011058#ifdef FEAT_VARTABS
11059 case PV_VSTS: return (char_u *)&(curbuf->b_p_vsts);
11060 case PV_VTS: return (char_u *)&(curbuf->b_p_vts);
11061#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010011062 default: iemsg(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011063 }
11064 /* always return a valid pointer to avoid a crash! */
11065 return (char_u *)&(curbuf->b_p_wm);
11066}
11067
11068/*
11069 * Get the value of 'equalprg', either the buffer-local one or the global one.
11070 */
11071 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011072get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011073{
11074 if (*curbuf->b_p_ep == NUL)
11075 return p_ep;
11076 return curbuf->b_p_ep;
11077}
11078
Bram Moolenaar071d4272004-06-13 20:20:40 +000011079/*
11080 * Copy options from one window to another.
11081 * Used when splitting a window.
11082 */
11083 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011084win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011085{
11086 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
11087 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
11088# ifdef FEAT_RIGHTLEFT
11089# ifdef FEAT_FKMAP
11090 /* Is this right? */
11091 wp_to->w_farsi = wp_from->w_farsi;
11092# endif
11093# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020011094#if defined(FEAT_LINEBREAK)
11095 briopt_check(wp_to);
11096#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011097}
Bram Moolenaar071d4272004-06-13 20:20:40 +000011098
11099/*
11100 * Copy the options from one winopt_T to another.
11101 * Doesn't free the old option values in "to", use clear_winopt() for that.
11102 * The 'scroll' option is not copied, because it depends on the window height.
11103 * The 'previewwindow' option is reset, there can be only one preview window.
11104 */
11105 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011106copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011107{
11108#ifdef FEAT_ARABIC
11109 to->wo_arab = from->wo_arab;
11110#endif
11111 to->wo_list = from->wo_list;
11112 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020011113 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011114#ifdef FEAT_LINEBREAK
11115 to->wo_nuw = from->wo_nuw;
11116#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011117#ifdef FEAT_RIGHTLEFT
11118 to->wo_rl = from->wo_rl;
11119 to->wo_rlc = vim_strsave(from->wo_rlc);
11120#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011121#ifdef FEAT_STL_OPT
11122 to->wo_stl = vim_strsave(from->wo_stl);
11123#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011124 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011125#ifdef FEAT_DIFF
11126 to->wo_wrap_save = from->wo_wrap_save;
11127#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011128#ifdef FEAT_LINEBREAK
11129 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020011130 to->wo_bri = from->wo_bri;
11131 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011132#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011133 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011134 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010011135 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011136 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011137#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000011138 to->wo_spell = from->wo_spell;
11139#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011140#ifdef FEAT_SYN_HL
11141 to->wo_cuc = from->wo_cuc;
11142 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020011143 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011144#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011145#ifdef FEAT_DIFF
11146 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011147 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011148#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011149#ifdef FEAT_CONCEAL
11150 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020011151 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011152#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011153#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011154 to->wo_twk = vim_strsave(from->wo_twk);
11155 to->wo_tws = vim_strsave(from->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011156#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011157#ifdef FEAT_FOLDING
11158 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011159 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011160 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011161 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011162 to->wo_fdi = vim_strsave(from->wo_fdi);
11163 to->wo_fml = from->wo_fml;
11164 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011165 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011166 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011167 to->wo_fdm_save = from->wo_diff_saved
11168 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011169 to->wo_fdn = from->wo_fdn;
11170# ifdef FEAT_EVAL
11171 to->wo_fde = vim_strsave(from->wo_fde);
11172 to->wo_fdt = vim_strsave(from->wo_fdt);
11173# endif
11174 to->wo_fmr = vim_strsave(from->wo_fmr);
11175#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011176#ifdef FEAT_SIGNS
11177 to->wo_scl = vim_strsave(from->wo_scl);
11178#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011179 check_winopt(to); /* don't want NULL pointers */
11180}
11181
11182/*
11183 * Check string options in a window for a NULL value.
11184 */
11185 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011186check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011187{
11188 check_winopt(&win->w_onebuf_opt);
11189 check_winopt(&win->w_allbuf_opt);
11190}
11191
11192/*
11193 * Check for NULL pointers in a winopt_T and replace them with empty_option.
11194 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020011195 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011196check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011197{
11198#ifdef FEAT_FOLDING
11199 check_string_option(&wop->wo_fdi);
11200 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011201 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011202# ifdef FEAT_EVAL
11203 check_string_option(&wop->wo_fde);
11204 check_string_option(&wop->wo_fdt);
11205# endif
11206 check_string_option(&wop->wo_fmr);
11207#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011208#ifdef FEAT_SIGNS
11209 check_string_option(&wop->wo_scl);
11210#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011211#ifdef FEAT_RIGHTLEFT
11212 check_string_option(&wop->wo_rlc);
11213#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011214#ifdef FEAT_STL_OPT
11215 check_string_option(&wop->wo_stl);
11216#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011217#ifdef FEAT_SYN_HL
11218 check_string_option(&wop->wo_cc);
11219#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011220#ifdef FEAT_CONCEAL
11221 check_string_option(&wop->wo_cocu);
11222#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011223#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011224 check_string_option(&wop->wo_twk);
11225 check_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011226#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011227#ifdef FEAT_LINEBREAK
11228 check_string_option(&wop->wo_briopt);
11229#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011230}
11231
11232/*
11233 * Free the allocated memory inside a winopt_T.
11234 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011235 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011236clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011237{
11238#ifdef FEAT_FOLDING
11239 clear_string_option(&wop->wo_fdi);
11240 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011241 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011242# ifdef FEAT_EVAL
11243 clear_string_option(&wop->wo_fde);
11244 clear_string_option(&wop->wo_fdt);
11245# endif
11246 clear_string_option(&wop->wo_fmr);
11247#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011248#ifdef FEAT_SIGNS
11249 clear_string_option(&wop->wo_scl);
11250#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011251#ifdef FEAT_LINEBREAK
11252 clear_string_option(&wop->wo_briopt);
11253#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011254#ifdef FEAT_RIGHTLEFT
11255 clear_string_option(&wop->wo_rlc);
11256#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011257#ifdef FEAT_STL_OPT
11258 clear_string_option(&wop->wo_stl);
11259#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011260#ifdef FEAT_SYN_HL
11261 clear_string_option(&wop->wo_cc);
11262#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011263#ifdef FEAT_CONCEAL
11264 clear_string_option(&wop->wo_cocu);
11265#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011266#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011267 clear_string_option(&wop->wo_twk);
11268 clear_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011269#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011270}
11271
11272/*
11273 * Copy global option values to local options for one buffer.
11274 * Used when creating a new buffer and sometimes when entering a buffer.
11275 * flags:
11276 * BCO_ENTER We will enter the buf buffer.
11277 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11278 * appropriate.
11279 * BCO_NOHELP Don't copy the values to a help buffer.
11280 */
11281 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011282buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011283{
11284 int should_copy = TRUE;
11285 char_u *save_p_isk = NULL; /* init for GCC */
11286 int dont_do_help;
11287 int did_isk = FALSE;
11288
11289 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011290 * Skip this when the option defaults have not been set yet. Happens when
11291 * main() allocates the first buffer.
11292 */
11293 if (p_cpo != NULL)
11294 {
11295 /*
11296 * Always copy when entering and 'cpo' contains 'S'.
11297 * Don't copy when already initialized.
11298 * Don't copy when 'cpo' contains 's' and not entering.
11299 * 'S' BCO_ENTER initialized 's' should_copy
11300 * yes yes X X TRUE
11301 * yes no yes X FALSE
11302 * no X yes X FALSE
11303 * X no no yes FALSE
11304 * X no no no TRUE
11305 * no yes no X TRUE
11306 */
11307 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11308 && (buf->b_p_initialized
11309 || (!(flags & BCO_ENTER)
11310 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11311 should_copy = FALSE;
11312
11313 if (should_copy || (flags & BCO_ALWAYS))
11314 {
11315 /* Don't copy the options specific to a help buffer when
11316 * BCO_NOHELP is given or the options were initialized already
11317 * (jumping back to a help file with CTRL-T or CTRL-O) */
11318 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11319 || buf->b_p_initialized;
11320 if (dont_do_help) /* don't free b_p_isk */
11321 {
11322 save_p_isk = buf->b_p_isk;
11323 buf->b_p_isk = NULL;
11324 }
11325 /*
Bram Moolenaar40385db2018-08-07 22:31:44 +020011326 * Always free the allocated strings. If not already initialized,
11327 * reset 'readonly' and copy 'fileformat'.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011328 */
11329 if (!buf->b_p_initialized)
11330 {
11331 free_buf_options(buf, TRUE);
11332 buf->b_p_ro = FALSE; /* don't copy readonly */
11333 buf->b_p_tx = p_tx;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011334 buf->b_p_fenc = vim_strsave(p_fenc);
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011335 switch (*p_ffs)
11336 {
11337 case 'm':
11338 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11339 case 'd':
11340 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11341 case 'u':
11342 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11343 default:
11344 buf->b_p_ff = vim_strsave(p_ff);
11345 }
11346 if (buf->b_p_ff != NULL)
11347 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011348 buf->b_p_bh = empty_option;
11349 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011350 }
11351 else
11352 free_buf_options(buf, FALSE);
11353
11354 buf->b_p_ai = p_ai;
11355 buf->b_p_ai_nopaste = p_ai_nopaste;
11356 buf->b_p_sw = p_sw;
11357 buf->b_p_tw = p_tw;
11358 buf->b_p_tw_nopaste = p_tw_nopaste;
11359 buf->b_p_tw_nobin = p_tw_nobin;
11360 buf->b_p_wm = p_wm;
11361 buf->b_p_wm_nopaste = p_wm_nopaste;
11362 buf->b_p_wm_nobin = p_wm_nobin;
11363 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011364 buf->b_p_bomb = p_bomb;
Bram Moolenaarb388be02015-07-22 22:19:38 +020011365 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011366 buf->b_p_et = p_et;
11367 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011368 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011369 buf->b_p_ml = p_ml;
11370 buf->b_p_ml_nobin = p_ml_nobin;
11371 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011372 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011373#ifdef FEAT_INS_EXPAND
11374 buf->b_p_cpt = vim_strsave(p_cpt);
11375#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011376#ifdef FEAT_COMPL_FUNC
11377 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011378 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011379#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011380 buf->b_p_sts = p_sts;
11381 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011382#ifdef FEAT_VARTABS
11383 buf->b_p_vsts = vim_strsave(p_vsts);
11384 if (p_vsts && p_vsts != empty_option)
11385 tabstop_set(p_vsts, &buf->b_p_vsts_array);
11386 else
11387 buf->b_p_vsts_array = 0;
11388 buf->b_p_vsts_nopaste = p_vsts_nopaste
11389 ? vim_strsave(p_vsts_nopaste) : NULL;
11390#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011391 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011392#ifdef FEAT_COMMENTS
11393 buf->b_p_com = vim_strsave(p_com);
11394#endif
11395#ifdef FEAT_FOLDING
11396 buf->b_p_cms = vim_strsave(p_cms);
11397#endif
11398 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011399 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011400 buf->b_p_nf = vim_strsave(p_nf);
11401 buf->b_p_mps = vim_strsave(p_mps);
11402#ifdef FEAT_SMARTINDENT
11403 buf->b_p_si = p_si;
11404#endif
11405 buf->b_p_ci = p_ci;
11406#ifdef FEAT_CINDENT
11407 buf->b_p_cin = p_cin;
11408 buf->b_p_cink = vim_strsave(p_cink);
11409 buf->b_p_cino = vim_strsave(p_cino);
11410#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011411 /* Don't copy 'filetype', it must be detected */
11412 buf->b_p_ft = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011413 buf->b_p_pi = p_pi;
11414#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11415 buf->b_p_cinw = vim_strsave(p_cinw);
11416#endif
11417#ifdef FEAT_LISP
11418 buf->b_p_lisp = p_lisp;
11419#endif
11420#ifdef FEAT_SYN_HL
11421 /* Don't copy 'syntax', it must be set */
11422 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011423 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011424 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011425#endif
11426#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011427 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011428 (void)compile_cap_prog(&buf->b_s);
11429 buf->b_s.b_p_spf = vim_strsave(p_spf);
11430 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011431#endif
11432#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11433 buf->b_p_inde = vim_strsave(p_inde);
11434 buf->b_p_indk = vim_strsave(p_indk);
11435#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011436 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011437#if defined(FEAT_EVAL)
11438 buf->b_p_fex = vim_strsave(p_fex);
11439#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011440#ifdef FEAT_CRYPT
11441 buf->b_p_key = vim_strsave(p_key);
11442#endif
11443#ifdef FEAT_SEARCHPATH
11444 buf->b_p_sua = vim_strsave(p_sua);
11445#endif
11446#ifdef FEAT_KEYMAP
11447 buf->b_p_keymap = vim_strsave(p_keymap);
11448 buf->b_kmap_state |= KEYMAP_INIT;
11449#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011450#ifdef FEAT_TERMINAL
11451 buf->b_p_twsl = p_twsl;
11452#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011453 /* This isn't really an option, but copying the langmap and IME
11454 * state from the current buffer is better than resetting it. */
11455 buf->b_p_iminsert = p_iminsert;
11456 buf->b_p_imsearch = p_imsearch;
11457
11458 /* options that are normally global but also have a local value
11459 * are not copied, start using the global value */
11460 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011461 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011462 buf->b_p_bkc = empty_option;
11463 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011464#ifdef FEAT_QUICKFIX
11465 buf->b_p_gp = empty_option;
11466 buf->b_p_mp = empty_option;
11467 buf->b_p_efm = empty_option;
11468#endif
11469 buf->b_p_ep = empty_option;
11470 buf->b_p_kp = empty_option;
11471 buf->b_p_path = empty_option;
11472 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011473 buf->b_p_tc = empty_option;
11474 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011475#ifdef FEAT_FIND_ID
11476 buf->b_p_def = empty_option;
11477 buf->b_p_inc = empty_option;
11478# ifdef FEAT_EVAL
11479 buf->b_p_inex = vim_strsave(p_inex);
11480# endif
11481#endif
11482#ifdef FEAT_INS_EXPAND
11483 buf->b_p_dict = empty_option;
11484 buf->b_p_tsr = empty_option;
11485#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011486#ifdef FEAT_TEXTOBJ
11487 buf->b_p_qe = vim_strsave(p_qe);
11488#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011489#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11490 buf->b_p_bexpr = empty_option;
11491#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011492#if defined(FEAT_CRYPT)
11493 buf->b_p_cm = empty_option;
11494#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011495#ifdef FEAT_PERSISTENT_UNDO
11496 buf->b_p_udf = p_udf;
11497#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011498#ifdef FEAT_LISP
11499 buf->b_p_lw = empty_option;
11500#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011501 buf->b_p_menc = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011502
11503 /*
11504 * Don't copy the options set by ex_help(), use the saved values,
11505 * when going from a help buffer to a non-help buffer.
11506 * Don't touch these at all when BCO_NOHELP is used and going from
11507 * or to a help buffer.
11508 */
11509 if (dont_do_help)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011510 {
Bram Moolenaar071d4272004-06-13 20:20:40 +000011511 buf->b_p_isk = save_p_isk;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011512#ifdef FEAT_VARTABS
11513 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11514 tabstop_set(p_vts, &buf->b_p_vts_array);
11515 else
11516 buf->b_p_vts_array = NULL;
11517#endif
11518 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011519 else
11520 {
11521 buf->b_p_isk = vim_strsave(p_isk);
11522 did_isk = TRUE;
11523 buf->b_p_ts = p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011524#ifdef FEAT_VARTABS
11525 buf->b_p_vts = vim_strsave(p_vts);
11526 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11527 tabstop_set(p_vts, &buf->b_p_vts_array);
11528 else
11529 buf->b_p_vts_array = NULL;
11530#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011531 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011532 if (buf->b_p_bt[0] == 'h')
11533 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011534 buf->b_p_ma = p_ma;
11535 }
11536 }
11537
11538 /*
11539 * When the options should be copied (ignoring BCO_ALWAYS), set the
11540 * flag that indicates that the options have been initialized.
11541 */
11542 if (should_copy)
11543 buf->b_p_initialized = TRUE;
11544 }
11545
11546 check_buf_options(buf); /* make sure we don't have NULLs */
11547 if (did_isk)
11548 (void)buf_init_chartab(buf, FALSE);
11549}
11550
11551/*
11552 * Reset the 'modifiable' option and its default value.
11553 */
11554 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011555reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011556{
11557 int opt_idx;
11558
11559 curbuf->b_p_ma = FALSE;
11560 p_ma = FALSE;
11561 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011562 if (opt_idx >= 0)
11563 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011564}
11565
11566/*
11567 * Set the global value for 'iminsert' to the local value.
11568 */
11569 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011570set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011571{
11572 p_iminsert = curbuf->b_p_iminsert;
11573}
11574
11575/*
11576 * Set the global value for 'imsearch' to the local value.
11577 */
11578 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011579set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011580{
11581 p_imsearch = curbuf->b_p_imsearch;
11582}
11583
11584#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11585static int expand_option_idx = -1;
11586static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11587static int expand_option_flags = 0;
11588
11589 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011590set_context_in_set_cmd(
11591 expand_T *xp,
11592 char_u *arg,
11593 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011594{
11595 int nextchar;
11596 long_u flags = 0; /* init for GCC */
11597 int opt_idx = 0; /* init for GCC */
11598 char_u *p;
11599 char_u *s;
11600 int is_term_option = FALSE;
11601 int key;
11602
11603 expand_option_flags = opt_flags;
11604
11605 xp->xp_context = EXPAND_SETTINGS;
11606 if (*arg == NUL)
11607 {
11608 xp->xp_pattern = arg;
11609 return;
11610 }
11611 p = arg + STRLEN(arg) - 1;
11612 if (*p == ' ' && *(p - 1) != '\\')
11613 {
11614 xp->xp_pattern = p + 1;
11615 return;
11616 }
11617 while (p > arg)
11618 {
11619 s = p;
11620 /* count number of backslashes before ' ' or ',' */
11621 if (*p == ' ' || *p == ',')
11622 {
11623 while (s > arg && *(s - 1) == '\\')
11624 --s;
11625 }
11626 /* break at a space with an even number of backslashes */
11627 if (*p == ' ' && ((p - s) & 1) == 0)
11628 {
11629 ++p;
11630 break;
11631 }
11632 --p;
11633 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011634 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011635 {
11636 xp->xp_context = EXPAND_BOOL_SETTINGS;
11637 p += 2;
11638 }
11639 if (STRNCMP(p, "inv", 3) == 0)
11640 {
11641 xp->xp_context = EXPAND_BOOL_SETTINGS;
11642 p += 3;
11643 }
11644 xp->xp_pattern = arg = p;
11645 if (*arg == '<')
11646 {
11647 while (*p != '>')
11648 if (*p++ == NUL) /* expand terminal option name */
11649 return;
11650 key = get_special_key_code(arg + 1);
11651 if (key == 0) /* unknown name */
11652 {
11653 xp->xp_context = EXPAND_NOTHING;
11654 return;
11655 }
11656 nextchar = *++p;
11657 is_term_option = TRUE;
11658 expand_option_name[2] = KEY2TERMCAP0(key);
11659 expand_option_name[3] = KEY2TERMCAP1(key);
11660 }
11661 else
11662 {
11663 if (p[0] == 't' && p[1] == '_')
11664 {
11665 p += 2;
11666 if (*p != NUL)
11667 ++p;
11668 if (*p == NUL)
11669 return; /* expand option name */
11670 nextchar = *++p;
11671 is_term_option = TRUE;
11672 expand_option_name[2] = p[-2];
11673 expand_option_name[3] = p[-1];
11674 }
11675 else
11676 {
11677 /* Allow * wildcard */
11678 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11679 p++;
11680 if (*p == NUL)
11681 return;
11682 nextchar = *p;
11683 *p = NUL;
11684 opt_idx = findoption(arg);
11685 *p = nextchar;
11686 if (opt_idx == -1 || options[opt_idx].var == NULL)
11687 {
11688 xp->xp_context = EXPAND_NOTHING;
11689 return;
11690 }
11691 flags = options[opt_idx].flags;
11692 if (flags & P_BOOL)
11693 {
11694 xp->xp_context = EXPAND_NOTHING;
11695 return;
11696 }
11697 }
11698 }
11699 /* handle "-=" and "+=" */
11700 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11701 {
11702 ++p;
11703 nextchar = '=';
11704 }
11705 if ((nextchar != '=' && nextchar != ':')
11706 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11707 {
11708 xp->xp_context = EXPAND_UNSUCCESSFUL;
11709 return;
11710 }
11711 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11712 {
11713 xp->xp_context = EXPAND_OLD_SETTING;
11714 if (is_term_option)
11715 expand_option_idx = -1;
11716 else
11717 expand_option_idx = opt_idx;
11718 xp->xp_pattern = p + 1;
11719 return;
11720 }
11721 xp->xp_context = EXPAND_NOTHING;
11722 if (is_term_option || (flags & P_NUM))
11723 return;
11724
11725 xp->xp_pattern = p + 1;
11726
11727 if (flags & P_EXPAND)
11728 {
11729 p = options[opt_idx].var;
11730 if (p == (char_u *)&p_bdir
11731 || p == (char_u *)&p_dir
11732 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011733 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011734 || p == (char_u *)&p_rtp
11735#ifdef FEAT_SEARCHPATH
11736 || p == (char_u *)&p_cdpath
11737#endif
11738#ifdef FEAT_SESSION
11739 || p == (char_u *)&p_vdir
11740#endif
11741 )
11742 {
11743 xp->xp_context = EXPAND_DIRECTORIES;
11744 if (p == (char_u *)&p_path
11745#ifdef FEAT_SEARCHPATH
11746 || p == (char_u *)&p_cdpath
11747#endif
11748 )
11749 xp->xp_backslash = XP_BS_THREE;
11750 else
11751 xp->xp_backslash = XP_BS_ONE;
11752 }
11753 else
11754 {
11755 xp->xp_context = EXPAND_FILES;
11756 /* for 'tags' need three backslashes for a space */
11757 if (p == (char_u *)&p_tags)
11758 xp->xp_backslash = XP_BS_THREE;
11759 else
11760 xp->xp_backslash = XP_BS_ONE;
11761 }
11762 }
11763
11764 /* For an option that is a list of file names, find the start of the
11765 * last file name. */
11766 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11767 {
11768 /* count number of backslashes before ' ' or ',' */
11769 if (*p == ' ' || *p == ',')
11770 {
11771 s = p;
11772 while (s > xp->xp_pattern && *(s - 1) == '\\')
11773 --s;
11774 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11775 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11776 {
11777 xp->xp_pattern = p + 1;
11778 break;
11779 }
11780 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011781
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011782#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011783 /* for 'spellsuggest' start at "file:" */
11784 if (options[opt_idx].var == (char_u *)&p_sps
11785 && STRNCMP(p, "file:", 5) == 0)
11786 {
11787 xp->xp_pattern = p + 5;
11788 break;
11789 }
11790#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011791 }
11792
11793 return;
11794}
11795
11796 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011797ExpandSettings(
11798 expand_T *xp,
11799 regmatch_T *regmatch,
11800 int *num_file,
11801 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011802{
11803 int num_normal = 0; /* Nr of matching non-term-code settings */
11804 int num_term = 0; /* Nr of matching terminal code settings */
11805 int opt_idx;
11806 int match;
11807 int count = 0;
11808 char_u *str;
11809 int loop;
11810 int is_term_opt;
11811 char_u name_buf[MAX_KEY_NAME_LEN];
11812 static char *(names[]) = {"all", "termcap"};
11813 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11814
11815 /* do this loop twice:
11816 * loop == 0: count the number of matching options
11817 * loop == 1: copy the matching options into allocated memory
11818 */
11819 for (loop = 0; loop <= 1; ++loop)
11820 {
11821 regmatch->rm_ic = ic;
11822 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11823 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011824 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11825 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011826 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11827 {
11828 if (loop == 0)
11829 num_normal++;
11830 else
11831 (*file)[count++] = vim_strsave((char_u *)names[match]);
11832 }
11833 }
11834 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11835 opt_idx++)
11836 {
11837 if (options[opt_idx].var == NULL)
11838 continue;
11839 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11840 && !(options[opt_idx].flags & P_BOOL))
11841 continue;
11842 is_term_opt = istermoption(&options[opt_idx]);
11843 if (is_term_opt && num_normal > 0)
11844 continue;
11845 match = FALSE;
11846 if (vim_regexec(regmatch, str, (colnr_T)0)
11847 || (options[opt_idx].shortname != NULL
11848 && vim_regexec(regmatch,
11849 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11850 match = TRUE;
11851 else if (is_term_opt)
11852 {
11853 name_buf[0] = '<';
11854 name_buf[1] = 't';
11855 name_buf[2] = '_';
11856 name_buf[3] = str[2];
11857 name_buf[4] = str[3];
11858 name_buf[5] = '>';
11859 name_buf[6] = NUL;
11860 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11861 {
11862 match = TRUE;
11863 str = name_buf;
11864 }
11865 }
11866 if (match)
11867 {
11868 if (loop == 0)
11869 {
11870 if (is_term_opt)
11871 num_term++;
11872 else
11873 num_normal++;
11874 }
11875 else
11876 (*file)[count++] = vim_strsave(str);
11877 }
11878 }
11879 /*
11880 * Check terminal key codes, these are not in the option table
11881 */
11882 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11883 {
11884 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11885 {
11886 if (!isprint(str[0]) || !isprint(str[1]))
11887 continue;
11888
11889 name_buf[0] = 't';
11890 name_buf[1] = '_';
11891 name_buf[2] = str[0];
11892 name_buf[3] = str[1];
11893 name_buf[4] = NUL;
11894
11895 match = FALSE;
11896 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11897 match = TRUE;
11898 else
11899 {
11900 name_buf[0] = '<';
11901 name_buf[1] = 't';
11902 name_buf[2] = '_';
11903 name_buf[3] = str[0];
11904 name_buf[4] = str[1];
11905 name_buf[5] = '>';
11906 name_buf[6] = NUL;
11907
11908 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11909 match = TRUE;
11910 }
11911 if (match)
11912 {
11913 if (loop == 0)
11914 num_term++;
11915 else
11916 (*file)[count++] = vim_strsave(name_buf);
11917 }
11918 }
11919
11920 /*
11921 * Check special key names.
11922 */
11923 regmatch->rm_ic = TRUE; /* ignore case here */
11924 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11925 {
11926 name_buf[0] = '<';
11927 STRCPY(name_buf + 1, str);
11928 STRCAT(name_buf, ">");
11929
11930 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11931 {
11932 if (loop == 0)
11933 num_term++;
11934 else
11935 (*file)[count++] = vim_strsave(name_buf);
11936 }
11937 }
11938 }
11939 if (loop == 0)
11940 {
11941 if (num_normal > 0)
11942 *num_file = num_normal;
11943 else if (num_term > 0)
11944 *num_file = num_term;
11945 else
11946 return OK;
11947 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11948 if (*file == NULL)
11949 {
11950 *file = (char_u **)"";
11951 return FAIL;
11952 }
11953 }
11954 }
11955 return OK;
11956}
11957
11958 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011959ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011960{
11961 char_u *var = NULL; /* init for GCC */
11962 char_u *buf;
11963
11964 *num_file = 0;
11965 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11966 if (*file == NULL)
11967 return FAIL;
11968
11969 /*
11970 * For a terminal key code expand_option_idx is < 0.
11971 */
11972 if (expand_option_idx < 0)
11973 {
11974 var = find_termcode(expand_option_name + 2);
11975 if (var == NULL)
11976 expand_option_idx = findoption(expand_option_name);
11977 }
11978
11979 if (expand_option_idx >= 0)
11980 {
11981 /* put string of option value in NameBuff */
11982 option_value2string(&options[expand_option_idx], expand_option_flags);
11983 var = NameBuff;
11984 }
11985 else if (var == NULL)
11986 var = (char_u *)"";
11987
11988 /* A backslash is required before some characters. This is the reverse of
11989 * what happens in do_set(). */
11990 buf = vim_strsave_escaped(var, escape_chars);
11991
11992 if (buf == NULL)
11993 {
Bram Moolenaard23a8232018-02-10 18:45:26 +010011994 VIM_CLEAR(*file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011995 return FAIL;
11996 }
11997
11998#ifdef BACKSLASH_IN_FILENAME
11999 /* For MS-Windows et al. we don't double backslashes at the start and
12000 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012001 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012002 if (var[0] == '\\' && var[1] == '\\'
12003 && expand_option_idx >= 0
12004 && (options[expand_option_idx].flags & P_EXPAND)
12005 && vim_isfilec(var[2])
12006 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000012007 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012008#endif
12009
12010 *file[0] = buf;
12011 *num_file = 1;
12012 return OK;
12013}
12014#endif
12015
12016/*
12017 * Get the value for the numeric or string option *opp in a nice format into
12018 * NameBuff[]. Must not be called with a hidden option!
12019 */
12020 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012021option_value2string(
12022 struct vimoption *opp,
12023 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012024{
12025 char_u *varp;
12026
12027 varp = get_varp_scope(opp, opt_flags);
12028
12029 if (opp->flags & P_NUM)
12030 {
12031 long wc = 0;
12032
12033 if (wc_use_keyname(varp, &wc))
12034 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
12035 else if (wc != 0)
12036 STRCPY(NameBuff, transchar((int)wc));
12037 else
12038 sprintf((char *)NameBuff, "%ld", *(long *)varp);
12039 }
12040 else /* P_STRING */
12041 {
12042 varp = *(char_u **)(varp);
12043 if (varp == NULL) /* just in case */
12044 NameBuff[0] = NUL;
12045#ifdef FEAT_CRYPT
12046 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000012047 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012048 STRCPY(NameBuff, "*****");
12049#endif
12050 else if (opp->flags & P_EXPAND)
12051 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
12052 /* Translate 'pastetoggle' into special key names */
12053 else if ((char_u **)opp->var == &p_pt)
12054 str2specialbuf(p_pt, NameBuff, MAXPATHL);
12055 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000012056 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012057 }
12058}
12059
12060/*
12061 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
12062 * printed as a keyname.
12063 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
12064 */
12065 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012066wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012067{
12068 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
12069 {
12070 *wcp = *(long *)varp;
12071 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
12072 return TRUE;
12073 }
12074 return FALSE;
12075}
12076
Bram Moolenaar01615492015-02-03 13:00:38 +010012077#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012078/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012079 * Any character has an equivalent 'langmap' character. This is used for
12080 * keyboards that have a special language mode that sends characters above
12081 * 128 (although other characters can be translated too). The "to" field is a
12082 * Vim command character. This avoids having to switch the keyboard back to
12083 * ASCII mode when leaving Insert mode.
12084 *
12085 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
12086 * commands.
Bram Moolenaarfc3abf42019-01-24 15:54:21 +010012087 * langmap_mapga.ga_data is a sorted table of langmap_entry_T. This does the
12088 * same as langmap_mapchar[] for characters >= 256.
12089 *
12090 * Use growarray for 'langmap' chars >= 256
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012091 */
12092typedef struct
12093{
12094 int from;
12095 int to;
12096} langmap_entry_T;
12097
12098static garray_T langmap_mapga;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012099
12100/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012101 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
12102 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012103 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012104 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012105langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012106{
12107 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020012108 int a = 0;
12109 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012110
12111 /* Do a binary search for an existing entry. */
12112 while (a != b)
12113 {
12114 int i = (a + b) / 2;
12115 int d = entries[i].from - from;
12116
12117 if (d == 0)
12118 {
12119 entries[i].to = to;
12120 return;
12121 }
12122 if (d < 0)
12123 a = i + 1;
12124 else
12125 b = i;
12126 }
12127
12128 if (ga_grow(&langmap_mapga, 1) != OK)
12129 return; /* out of memory */
12130
12131 /* insert new entry at position "a" */
12132 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
12133 mch_memmove(entries + 1, entries,
12134 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
12135 ++langmap_mapga.ga_len;
12136 entries[0].from = from;
12137 entries[0].to = to;
12138}
12139
12140/*
12141 * Apply 'langmap' to multi-byte character "c" and return the result.
12142 */
12143 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012144langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012145{
12146 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
12147 int a = 0;
12148 int b = langmap_mapga.ga_len;
12149
12150 while (a != b)
12151 {
12152 int i = (a + b) / 2;
12153 int d = entries[i].from - c;
12154
12155 if (d == 0)
12156 return entries[i].to; /* found matching entry */
12157 if (d < 0)
12158 a = i + 1;
12159 else
12160 b = i;
12161 }
12162 return c; /* no entry found, return "c" unmodified */
12163}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012164
12165 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012166langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012167{
12168 int i;
12169
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012170 for (i = 0; i < 256; i++)
12171 langmap_mapchar[i] = i; /* we init with a one-to-one map */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012172 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012173}
12174
12175/*
12176 * Called when langmap option is set; the language map can be
12177 * changed at any time!
12178 */
12179 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012180langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012181{
12182 char_u *p;
12183 char_u *p2;
12184 int from, to;
12185
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012186 ga_clear(&langmap_mapga); /* clear the previous map first */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012187 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012188
12189 for (p = p_langmap; p[0] != NUL; )
12190 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000012191 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012192 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012193 {
12194 if (p2[0] == '\\' && p2[1] != NUL)
12195 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012196 }
12197 if (p2[0] == ';')
12198 ++p2; /* abcd;ABCD form, p2 points to A */
12199 else
12200 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
12201 while (p[0])
12202 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012203 if (p[0] == ',')
12204 {
12205 ++p;
12206 break;
12207 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012208 if (p[0] == '\\' && p[1] != NUL)
12209 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012210 from = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012211 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012212 if (p2 == NULL)
12213 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012214 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012215 if (p[0] != ',')
12216 {
12217 if (p[0] == '\\')
12218 ++p;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012219 to = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012220 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012221 }
12222 else
12223 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012224 if (p2[0] != ',')
12225 {
12226 if (p2[0] == '\\')
12227 ++p2;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012228 to = (*mb_ptr2char)(p2);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012229 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012230 }
12231 if (to == NUL)
12232 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012233 semsg(_("E357: 'langmap': Matching character missing for %s"),
Bram Moolenaar071d4272004-06-13 20:20:40 +000012234 transchar(from));
12235 return;
12236 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012237
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012238 if (from >= 256)
12239 langmap_set_entry(from, to);
12240 else
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012241 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012242
12243 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012244 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012245 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012246 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012247 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012248 if (*p == ';')
12249 {
12250 p = p2;
12251 if (p[0] != NUL)
12252 {
12253 if (p[0] != ',')
12254 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012255 semsg(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012256 return;
12257 }
12258 ++p;
12259 }
12260 break;
12261 }
12262 }
12263 }
12264 }
12265}
12266#endif
12267
12268/*
12269 * Return TRUE if format option 'x' is in effect.
12270 * Take care of no formatting when 'paste' is set.
12271 */
12272 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012273has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012274{
12275 if (p_paste)
12276 return FALSE;
12277 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12278}
12279
12280/*
12281 * Return TRUE if "x" is present in 'shortmess' option, or
12282 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12283 */
12284 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012285shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012286{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012287 return p_shm != NULL &&
12288 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012289 || (vim_strchr(p_shm, 'a') != NULL
12290 && vim_strchr((char_u *)SHM_A, x) != NULL));
12291}
12292
12293/*
12294 * paste_option_changed() - Called after p_paste was set or reset.
12295 */
12296 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012297paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012298{
12299 static int old_p_paste = FALSE;
12300 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012301 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012302#ifdef FEAT_CMDL_INFO
12303 static int save_ru = 0;
12304#endif
12305#ifdef FEAT_RIGHTLEFT
12306 static int save_ri = 0;
12307 static int save_hkmap = 0;
12308#endif
12309 buf_T *buf;
12310
12311 if (p_paste)
12312 {
12313 /*
12314 * Paste switched from off to on.
12315 * Save the current values, so they can be restored later.
12316 */
12317 if (!old_p_paste)
12318 {
12319 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012320 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012321 {
12322 buf->b_p_tw_nopaste = buf->b_p_tw;
12323 buf->b_p_wm_nopaste = buf->b_p_wm;
12324 buf->b_p_sts_nopaste = buf->b_p_sts;
12325 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012326 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012327#ifdef FEAT_VARTABS
12328 if (buf->b_p_vsts_nopaste)
12329 vim_free(buf->b_p_vsts_nopaste);
12330 buf->b_p_vsts_nopaste = buf->b_p_vsts && buf->b_p_vsts != empty_option
12331 ? vim_strsave(buf->b_p_vsts) : NULL;
12332#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012333 }
12334
12335 /* save global options */
12336 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012337 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012338#ifdef FEAT_CMDL_INFO
12339 save_ru = p_ru;
12340#endif
12341#ifdef FEAT_RIGHTLEFT
12342 save_ri = p_ri;
12343 save_hkmap = p_hkmap;
12344#endif
12345 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012346 p_ai_nopaste = p_ai;
12347 p_et_nopaste = p_et;
12348 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012349 p_tw_nopaste = p_tw;
12350 p_wm_nopaste = p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012351#ifdef FEAT_VARTABS
12352 if (p_vsts_nopaste)
12353 vim_free(p_vsts_nopaste);
12354 p_vsts_nopaste = p_vsts && p_vsts != empty_option ? vim_strsave(p_vsts) : NULL;
12355#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012356 }
12357
12358 /*
12359 * Always set the option values, also when 'paste' is set when it is
12360 * already on.
12361 */
12362 /* set 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 = 0; /* textwidth is 0 */
12366 buf->b_p_wm = 0; /* wrapmargin is 0 */
12367 buf->b_p_sts = 0; /* softtabstop is 0 */
12368 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012369 buf->b_p_et = 0; /* no expandtab */
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 = empty_option;
12374 if (buf->b_p_vsts_array)
12375 vim_free(buf->b_p_vsts_array);
12376 buf->b_p_vsts_array = 0;
12377#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012378 }
12379
12380 /* set global options */
12381 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012382 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012383#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012384 if (p_ru)
12385 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012386 p_ru = 0; /* no ruler */
12387#endif
12388#ifdef FEAT_RIGHTLEFT
12389 p_ri = 0; /* no reverse insert */
12390 p_hkmap = 0; /* no Hebrew keyboard */
12391#endif
12392 /* set global values for local buffer options */
12393 p_tw = 0;
12394 p_wm = 0;
12395 p_sts = 0;
12396 p_ai = 0;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012397#ifdef FEAT_VARTABS
12398 if (p_vsts)
12399 free_string_option(p_vsts);
12400 p_vsts = empty_option;
12401#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012402 }
12403
12404 /*
12405 * Paste switched from on to off: Restore saved values.
12406 */
12407 else if (old_p_paste)
12408 {
12409 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012410 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012411 {
12412 buf->b_p_tw = buf->b_p_tw_nopaste;
12413 buf->b_p_wm = buf->b_p_wm_nopaste;
12414 buf->b_p_sts = buf->b_p_sts_nopaste;
12415 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012416 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012417#ifdef FEAT_VARTABS
12418 if (buf->b_p_vsts)
12419 free_string_option(buf->b_p_vsts);
12420 buf->b_p_vsts = buf->b_p_vsts_nopaste
12421 ? vim_strsave(buf->b_p_vsts_nopaste) : empty_option;
12422 if (buf->b_p_vsts_array)
12423 vim_free(buf->b_p_vsts_array);
12424 if (buf->b_p_vsts && buf->b_p_vsts != empty_option)
12425 tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array);
12426 else
12427 buf->b_p_vsts_array = 0;
12428#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012429 }
12430
12431 /* restore global options */
12432 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012433 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012434#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012435 if (p_ru != save_ru)
12436 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012437 p_ru = save_ru;
12438#endif
12439#ifdef FEAT_RIGHTLEFT
12440 p_ri = save_ri;
12441 p_hkmap = save_hkmap;
12442#endif
12443 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012444 p_ai = p_ai_nopaste;
12445 p_et = p_et_nopaste;
12446 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012447 p_tw = p_tw_nopaste;
12448 p_wm = p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012449#ifdef FEAT_VARTABS
12450 if (p_vsts)
12451 free_string_option(p_vsts);
12452 p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option;
12453#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012454 }
12455
12456 old_p_paste = p_paste;
12457}
12458
12459/*
12460 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12461 *
12462 * Reset 'compatible' and set the values for options that didn't get set yet
12463 * to the Vim defaults.
12464 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012465 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012466 */
12467 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012468vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012469{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012470 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012471 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012472 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012473
12474 if (!option_was_set((char_u *)"cp"))
12475 {
12476 p_cp = FALSE;
12477 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12478 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12479 set_option_default(opt_idx, OPT_FREE, FALSE);
12480 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012481 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012482 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012483
12484 if (fname != NULL)
12485 {
12486 p = vim_getenv(envname, &dofree);
12487 if (p == NULL)
12488 {
12489 /* Set $MYVIMRC to the first vimrc file found. */
12490 p = FullName_save(fname, FALSE);
12491 if (p != NULL)
12492 {
12493 vim_setenv(envname, p);
12494 vim_free(p);
12495 }
12496 }
12497 else if (dofree)
12498 vim_free(p);
12499 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012500}
12501
12502/*
12503 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12504 */
12505 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012506change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012507{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012508 int opt_idx;
12509
Bram Moolenaar071d4272004-06-13 20:20:40 +000012510 if (p_cp != on)
12511 {
12512 p_cp = on;
12513 compatible_set();
12514 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012515 opt_idx = findoption((char_u *)"cp");
12516 if (opt_idx >= 0)
12517 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012518}
12519
12520/*
12521 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012522 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012523 */
12524 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012525option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012526{
12527 int idx;
12528
12529 idx = findoption(name);
12530 if (idx < 0) /* unknown option */
12531 return FALSE;
12532 if (options[idx].flags & P_WAS_SET)
12533 return TRUE;
12534 return FALSE;
12535}
12536
12537/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012538 * Reset the flag indicating option "name" was set.
12539 */
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012540 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012541reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012542{
12543 int idx = findoption(name);
12544
12545 if (idx >= 0)
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012546 {
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012547 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012548 return OK;
12549 }
12550 return FAIL;
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012551}
12552
12553/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012554 * compatible_set() - Called when 'compatible' has been set or unset.
12555 *
12556 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12557 * flag) to a Vi compatible value.
12558 * When 'compatible' is unset: Set all options that have a different default
12559 * for Vim (without the P_VI_DEF flag) to that default.
12560 */
12561 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012562compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012563{
12564 int opt_idx;
12565
12566 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12567 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12568 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12569 set_option_default(opt_idx, OPT_FREE, p_cp);
12570 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012571 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012572}
12573
12574#ifdef FEAT_LINEBREAK
12575
12576# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12577 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012578 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012579# endif
12580
12581/*
12582 * fill_breakat_flags() -- called when 'breakat' changes value.
12583 */
12584 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012585fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012586{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012587 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012588 int i;
12589
12590 for (i = 0; i < 256; i++)
12591 breakat_flags[i] = FALSE;
12592
12593 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012594 for (p = p_breakat; *p; p++)
12595 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012596}
12597
12598# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012599 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012600# endif
12601
12602#endif
12603
12604/*
12605 * Check an option that can be a range of string values.
12606 *
12607 * Return OK for correct value, FAIL otherwise.
12608 * Empty is always OK.
12609 */
12610 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012611check_opt_strings(
12612 char_u *val,
12613 char **values,
12614 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012615{
12616 return opt_strings_flags(val, values, NULL, list);
12617}
12618
12619/*
12620 * Handle an option that can be a range of string values.
12621 * Set a flag in "*flagp" for each string present.
12622 *
12623 * Return OK for correct value, FAIL otherwise.
12624 * Empty is always OK.
12625 */
12626 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012627opt_strings_flags(
12628 char_u *val, /* new value */
12629 char **values, /* array of valid string values */
12630 unsigned *flagp,
12631 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012632{
12633 int i;
12634 int len;
12635 unsigned new_flags = 0;
12636
12637 while (*val)
12638 {
12639 for (i = 0; ; ++i)
12640 {
12641 if (values[i] == NULL) /* val not found in values[] */
12642 return FAIL;
12643
12644 len = (int)STRLEN(values[i]);
12645 if (STRNCMP(values[i], val, len) == 0
12646 && ((list && val[len] == ',') || val[len] == NUL))
12647 {
12648 val += len + (val[len] == ',');
12649 new_flags |= (1 << i);
12650 break; /* check next item in val list */
12651 }
12652 }
12653 }
12654 if (flagp != NULL)
12655 *flagp = new_flags;
12656
12657 return OK;
12658}
12659
12660/*
12661 * Read the 'wildmode' option, fill wim_flags[].
12662 */
12663 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012664check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012665{
12666 char_u new_wim_flags[4];
12667 char_u *p;
12668 int i;
12669 int idx = 0;
12670
12671 for (i = 0; i < 4; ++i)
12672 new_wim_flags[i] = 0;
12673
12674 for (p = p_wim; *p; ++p)
12675 {
12676 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12677 ;
12678 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12679 return FAIL;
12680 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12681 new_wim_flags[idx] |= WIM_LONGEST;
12682 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12683 new_wim_flags[idx] |= WIM_FULL;
12684 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12685 new_wim_flags[idx] |= WIM_LIST;
12686 else
12687 return FAIL;
12688 p += i;
12689 if (*p == NUL)
12690 break;
12691 if (*p == ',')
12692 {
12693 if (idx == 3)
12694 return FAIL;
12695 ++idx;
12696 }
12697 }
12698
12699 /* fill remaining entries with last flag */
12700 while (idx < 3)
12701 {
12702 new_wim_flags[idx + 1] = new_wim_flags[idx];
12703 ++idx;
12704 }
12705
12706 /* only when there are no errors, wim_flags[] is changed */
12707 for (i = 0; i < 4; ++i)
12708 wim_flags[i] = new_wim_flags[i];
12709 return OK;
12710}
12711
12712/*
12713 * Check if backspacing over something is allowed.
12714 */
12715 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012716can_bs(
12717 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012718{
Bram Moolenaar6b810d92018-06-04 17:28:44 +020012719#ifdef FEAT_JOB_CHANNEL
12720 if (what == BS_START && bt_prompt(curbuf))
12721 return FALSE;
12722#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012723 switch (*p_bs)
12724 {
12725 case '2': return TRUE;
12726 case '1': return (what != BS_START);
12727 case '0': return FALSE;
12728 }
12729 return vim_strchr(p_bs, what) != NULL;
12730}
12731
12732/*
12733 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12734 * the file must be considered changed when the value is different.
12735 */
12736 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012737save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012738{
12739 buf->b_start_ffc = *buf->b_p_ff;
12740 buf->b_start_eol = buf->b_p_eol;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012741 buf->b_start_bomb = buf->b_p_bomb;
12742
Bram Moolenaar071d4272004-06-13 20:20:40 +000012743 /* Only use free/alloc when necessary, they take time. */
12744 if (buf->b_start_fenc == NULL
12745 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12746 {
12747 vim_free(buf->b_start_fenc);
12748 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12749 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012750}
12751
12752/*
12753 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12754 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012755 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12756 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012757 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012758 * When "ignore_empty" is true don't consider a new, empty buffer to be
12759 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012760 */
12761 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012762file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012763{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012764 /* In a buffer that was never loaded the options are not valid. */
12765 if (buf->b_flags & BF_NEVERLOADED)
12766 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012767 if (ignore_empty
12768 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012769 && buf->b_ml.ml_line_count == 1
12770 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12771 return FALSE;
12772 if (buf->b_start_ffc != *buf->b_p_ff)
12773 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012774 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012775 return TRUE;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012776 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12777 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012778 if (buf->b_start_fenc == NULL)
12779 return (*buf->b_p_fenc != NUL);
12780 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012781}
12782
12783/*
12784 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12785 */
12786 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012787check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012788{
12789 return check_opt_strings(p, p_ff_values, FALSE);
12790}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012791
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012792#ifdef FEAT_VARTABS
12793
12794/*
12795 * Set the integer values corresponding to the string setting of 'vartabstop'.
12796 */
12797 int
12798tabstop_set(char_u *var, int **array)
12799{
12800 int valcount = 1;
12801 int t;
12802 char_u *cp;
12803
Bram Moolenaar64f41072018-10-15 22:51:50 +020012804 if (var[0] == NUL || (var[0] == '0' && var[1] == NUL))
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012805 {
12806 *array = NULL;
12807 return TRUE;
12808 }
12809
Bram Moolenaar64f41072018-10-15 22:51:50 +020012810 for (cp = var; *cp != NUL; ++cp)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012811 {
Bram Moolenaar64f41072018-10-15 22:51:50 +020012812 if (cp == var || cp[-1] == ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012813 {
12814 char_u *end;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012815
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012816 if (strtol((char *)cp, (char **)&end, 10) <= 0)
12817 {
12818 if (cp != end)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012819 emsg(_(e_positive));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012820 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012821 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012822 return FALSE;
12823 }
12824 }
12825
12826 if (VIM_ISDIGIT(*cp))
12827 continue;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012828 if (cp[0] == ',' && cp > var && cp[-1] != ',' && cp[1] != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012829 {
12830 ++valcount;
12831 continue;
12832 }
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012833 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012834 return FALSE;
12835 }
12836
Bram Moolenaar64f41072018-10-15 22:51:50 +020012837 *array = (int *)alloc((unsigned) ((valcount + 1) * sizeof(int)));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012838 (*array)[0] = valcount;
12839
12840 t = 1;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012841 for (cp = var; *cp != NUL;)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012842 {
12843 (*array)[t++] = atoi((char *)cp);
Bram Moolenaar64f41072018-10-15 22:51:50 +020012844 while (*cp != NUL && *cp != ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012845 ++cp;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012846 if (*cp != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012847 ++cp;
12848 }
12849
12850 return TRUE;
12851}
12852
12853/*
12854 * Calculate the number of screen spaces a tab will occupy.
12855 * If "vts" is set then the tab widths are taken from that array,
12856 * otherwise the value of ts is used.
12857 */
12858 int
12859tabstop_padding(colnr_T col, int ts_arg, int *vts)
12860{
12861 int ts = ts_arg == 0 ? 8 : ts_arg;
12862 int tabcount;
12863 colnr_T tabcol = 0;
12864 int t;
12865 int padding = 0;
12866
12867 if (vts == NULL || vts[0] == 0)
12868 return ts - (col % ts);
12869
12870 tabcount = vts[0];
12871
12872 for (t = 1; t <= tabcount; ++t)
12873 {
12874 tabcol += vts[t];
12875 if (tabcol > col)
12876 {
12877 padding = (int)(tabcol - col);
12878 break;
12879 }
12880 }
12881 if (t > tabcount)
12882 padding = vts[tabcount] - (int)((col - tabcol) % vts[tabcount]);
12883
12884 return padding;
12885}
12886
12887/*
12888 * Find the size of the tab that covers a particular column.
12889 */
12890 int
12891tabstop_at(colnr_T col, int ts, int *vts)
12892{
12893 int tabcount;
12894 colnr_T tabcol = 0;
12895 int t;
12896 int tab_size = 0;
12897
12898 if (vts == 0 || vts[0] == 0)
12899 return ts;
12900
12901 tabcount = vts[0];
12902 for (t = 1; t <= tabcount; ++t)
12903 {
12904 tabcol += vts[t];
12905 if (tabcol > col)
12906 {
12907 tab_size = vts[t];
12908 break;
12909 }
12910 }
12911 if (t > tabcount)
12912 tab_size = vts[tabcount];
12913
12914 return tab_size;
12915}
12916
12917/*
12918 * Find the column on which a tab starts.
12919 */
12920 colnr_T
12921tabstop_start(colnr_T col, int ts, int *vts)
12922{
12923 int tabcount;
12924 colnr_T tabcol = 0;
12925 int t;
12926 int excess;
12927
Bram Moolenaar0119a592018-06-24 23:53:28 +020012928 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012929 return (col / ts) * ts;
12930
12931 tabcount = vts[0];
12932 for (t = 1; t <= tabcount; ++t)
12933 {
12934 tabcol += vts[t];
12935 if (tabcol > col)
12936 return tabcol - vts[t];
12937 }
12938
12939 excess = tabcol % vts[tabcount];
12940 return excess + ((col - excess) / vts[tabcount]) * vts[tabcount];
12941}
12942
12943/*
12944 * Find the number of tabs and spaces necessary to get from one column
12945 * to another.
12946 */
12947 void
12948tabstop_fromto(
12949 colnr_T start_col,
12950 colnr_T end_col,
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012951 int ts_arg,
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012952 int *vts,
12953 int *ntabs,
12954 int *nspcs)
12955{
12956 int spaces = end_col - start_col;
12957 colnr_T tabcol = 0;
12958 int padding = 0;
12959 int tabcount;
12960 int t;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012961 int ts = ts_arg == 0 ? curbuf->b_p_ts : ts_arg;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012962
Bram Moolenaar0119a592018-06-24 23:53:28 +020012963 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012964 {
12965 int tabs = 0;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012966 int initspc = 0;
Bram Moolenaar0119a592018-06-24 23:53:28 +020012967
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012968 initspc = ts - (start_col % ts);
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012969 if (spaces >= initspc)
12970 {
12971 spaces -= initspc;
12972 tabs++;
12973 }
12974 tabs += spaces / ts;
12975 spaces -= (spaces / ts) * ts;
12976
12977 *ntabs = tabs;
12978 *nspcs = spaces;
12979 return;
12980 }
12981
12982 /* Find the padding needed to reach the next tabstop. */
12983 tabcount = vts[0];
12984 for (t = 1; t <= tabcount; ++t)
12985 {
12986 tabcol += vts[t];
12987 if (tabcol > start_col)
12988 {
12989 padding = (int)(tabcol - start_col);
12990 break;
12991 }
12992 }
12993 if (t > tabcount)
12994 padding = vts[tabcount] - (int)((start_col - tabcol) % vts[tabcount]);
12995
12996 /* If the space needed is less than the padding no tabs can be used. */
12997 if (spaces < padding)
12998 {
12999 *ntabs = 0;
13000 *nspcs = spaces;
13001 return;
13002 }
13003
13004 *ntabs = 1;
13005 spaces -= padding;
13006
13007 /* At least one tab has been used. See if any more will fit. */
13008 while (spaces != 0 && ++t <= tabcount)
13009 {
13010 padding = vts[t];
13011 if (spaces < padding)
13012 {
13013 *nspcs = spaces;
13014 return;
13015 }
13016 ++*ntabs;
13017 spaces -= padding;
13018 }
13019
13020 *ntabs += spaces / vts[tabcount];
13021 *nspcs = spaces % vts[tabcount];
13022}
13023
13024/*
13025 * See if two tabstop arrays contain the same values.
13026 */
13027 int
13028tabstop_eq(int *ts1, int *ts2)
13029{
13030 int t;
13031
13032 if ((ts1 == 0 && ts2) || (ts1 && ts2 == 0))
13033 return FALSE;
13034 if (ts1 == ts2)
13035 return TRUE;
13036 if (ts1[0] != ts2[0])
13037 return FALSE;
13038
13039 for (t = 1; t <= ts1[0]; ++t)
13040 if (ts1[t] != ts2[t])
13041 return FALSE;
13042
13043 return TRUE;
13044}
13045
Bram Moolenaar113e1072019-01-20 15:30:40 +010013046#if defined(FEAT_BEVAL) || defined(PROTO)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013047/*
13048 * Copy a tabstop array, allocating space for the new array.
13049 */
13050 int *
13051tabstop_copy(int *oldts)
13052{
13053 int *newts;
13054 int t;
13055
13056 if (oldts == 0)
13057 return 0;
13058
13059 newts = (int *) alloc((unsigned) ((oldts[0] + 1) * sizeof(int)));
13060 for (t = 0; t <= oldts[0]; ++t)
13061 newts[t] = oldts[t];
13062
13063 return newts;
13064}
Bram Moolenaar113e1072019-01-20 15:30:40 +010013065#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013066
13067/*
13068 * Return a count of the number of tabstops.
13069 */
13070 int
13071tabstop_count(int *ts)
13072{
13073 return ts != NULL ? ts[0] : 0;
13074}
13075
13076/*
13077 * Return the first tabstop, or 8 if there are no tabstops defined.
13078 */
13079 int
13080tabstop_first(int *ts)
13081{
13082 return ts != NULL ? ts[1] : 8;
13083}
13084
13085#endif
13086
Bram Moolenaar14f24742012-08-08 18:01:05 +020013087/*
13088 * Return the effective shiftwidth value for current buffer, using the
13089 * 'tabstop' value when 'shiftwidth' is zero.
13090 */
13091 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013092get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020013093{
Bram Moolenaarf9514162018-11-22 03:08:29 +010013094 return get_sw_value_col(buf, 0);
13095}
13096
13097/*
13098 * Idem, using the first non-black in the current line.
13099 */
13100 long
13101get_sw_value_indent(buf_T *buf)
13102{
13103 pos_T pos = curwin->w_cursor;
13104
13105 pos.col = getwhitecols_curline();
13106 return get_sw_value_pos(buf, &pos);
13107}
13108
13109/*
13110 * Idem, using "pos".
13111 */
13112 long
13113get_sw_value_pos(buf_T *buf, pos_T *pos)
13114{
13115 pos_T save_cursor = curwin->w_cursor;
13116 long sw_value;
13117
13118 curwin->w_cursor = *pos;
13119 sw_value = get_sw_value_col(buf, get_nolist_virtcol());
13120 curwin->w_cursor = save_cursor;
13121 return sw_value;
13122}
13123
13124/*
13125 * Idem, using virtual column "col".
13126 */
13127 long
13128get_sw_value_col(buf_T *buf, colnr_T col UNUSED)
13129{
13130 return buf->b_p_sw ? buf->b_p_sw :
13131 #ifdef FEAT_VARTABS
13132 tabstop_at(col, buf->b_p_ts, buf->b_p_vts_array);
13133 #else
13134 buf->b_p_ts;
13135 #endif
Bram Moolenaar14f24742012-08-08 18:01:05 +020013136}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013137
13138/*
13139 * Return the effective softtabstop value for the current buffer, using the
Bram Moolenaar33d5ab32018-07-02 20:51:24 +020013140 * 'shiftwidth' value when 'softtabstop' is negative.
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013141 */
13142 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013143get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013144{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010013145 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013146}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013147
13148/*
Bram Moolenaar375e3392019-01-31 18:26:10 +010013149 * Return the effective 'scrolloff' value for the current window, using the
13150 * global value when appropriate.
13151 */
13152 long
13153get_scrolloff_value(void)
13154{
13155 return curwin->w_p_so < 0 ? p_so : curwin->w_p_so;
13156}
13157
13158/*
13159 * Return the effective 'sidescrolloff' value for the current window, using the
13160 * global value when appropriate.
13161 */
13162 long
13163get_sidescrolloff_value(void)
13164{
13165 return curwin->w_p_siso < 0 ? p_siso : curwin->w_p_siso;
13166}
13167
13168/*
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013169 * Check matchpairs option for "*initc".
13170 * If there is a match set "*initc" to the matching character and "*findc" to
13171 * the opposite character. Set "*backwards" to the direction.
13172 * When "switchit" is TRUE swap the direction.
13173 */
13174 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010013175find_mps_values(
13176 int *initc,
13177 int *findc,
13178 int *backwards,
13179 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013180{
13181 char_u *ptr;
13182
13183 ptr = curbuf->b_p_mps;
13184 while (*ptr != NUL)
13185 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013186 if (has_mbyte)
13187 {
13188 char_u *prev;
13189
13190 if (mb_ptr2char(ptr) == *initc)
13191 {
13192 if (switchit)
13193 {
13194 *findc = *initc;
13195 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13196 *backwards = TRUE;
13197 }
13198 else
13199 {
13200 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13201 *backwards = FALSE;
13202 }
13203 return;
13204 }
13205 prev = ptr;
13206 ptr += mb_ptr2len(ptr) + 1;
13207 if (mb_ptr2char(ptr) == *initc)
13208 {
13209 if (switchit)
13210 {
13211 *findc = *initc;
13212 *initc = mb_ptr2char(prev);
13213 *backwards = FALSE;
13214 }
13215 else
13216 {
13217 *findc = mb_ptr2char(prev);
13218 *backwards = TRUE;
13219 }
13220 return;
13221 }
13222 ptr += mb_ptr2len(ptr);
13223 }
13224 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013225 {
13226 if (*ptr == *initc)
13227 {
13228 if (switchit)
13229 {
13230 *backwards = TRUE;
13231 *findc = *initc;
13232 *initc = ptr[2];
13233 }
13234 else
13235 {
13236 *backwards = FALSE;
13237 *findc = ptr[2];
13238 }
13239 return;
13240 }
13241 ptr += 2;
13242 if (*ptr == *initc)
13243 {
13244 if (switchit)
13245 {
13246 *backwards = FALSE;
13247 *findc = *initc;
13248 *initc = ptr[-2];
13249 }
13250 else
13251 {
13252 *backwards = TRUE;
13253 *findc = ptr[-2];
13254 }
13255 return;
13256 }
13257 ++ptr;
13258 }
13259 if (*ptr == ',')
13260 ++ptr;
13261 }
13262}
Bram Moolenaar597a4222014-06-25 14:39:50 +020013263
13264#if defined(FEAT_LINEBREAK) || defined(PROTO)
13265/*
13266 * This is called when 'breakindentopt' is changed and when a window is
13267 * initialized.
13268 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013269 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013270briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020013271{
13272 char_u *p;
13273 int bri_shift = 0;
13274 long bri_min = 20;
13275 int bri_sbr = FALSE;
13276
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013277 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013278 while (*p != NUL)
13279 {
13280 if (STRNCMP(p, "shift:", 6) == 0
13281 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
13282 {
13283 p += 6;
13284 bri_shift = getdigits(&p);
13285 }
13286 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
13287 {
13288 p += 4;
13289 bri_min = getdigits(&p);
13290 }
13291 else if (STRNCMP(p, "sbr", 3) == 0)
13292 {
13293 p += 3;
13294 bri_sbr = TRUE;
13295 }
13296 if (*p != ',' && *p != NUL)
13297 return FAIL;
13298 if (*p == ',')
13299 ++p;
13300 }
13301
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013302 wp->w_p_brishift = bri_shift;
13303 wp->w_p_brimin = bri_min;
13304 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013305
13306 return OK;
13307}
13308#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013309
13310/*
13311 * Get the local or global value of 'backupcopy'.
13312 */
13313 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013314get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013315{
13316 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
13317}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020013318
13319#if defined(FEAT_SIGNS) || defined(PROTO)
13320/*
13321 * Return TRUE when window "wp" has a column to draw signs in.
13322 */
13323 int
13324signcolumn_on(win_T *wp)
13325{
13326 if (*wp->w_p_scl == 'n')
13327 return FALSE;
13328 if (*wp->w_p_scl == 'y')
13329 return TRUE;
13330 return (wp->w_buffer->b_signlist != NULL
13331# ifdef FEAT_NETBEANS_INTG
13332 || wp->w_buffer->b_has_sign_column
13333# endif
13334 );
13335}
13336#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013337
13338#if defined(FEAT_EVAL) || defined(PROTO)
13339/*
13340 * Get window or buffer local options.
13341 */
13342 dict_T *
13343get_winbuf_options(int bufopt)
13344{
13345 dict_T *d;
13346 int opt_idx;
13347
13348 d = dict_alloc();
13349 if (d == NULL)
13350 return NULL;
13351
13352 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
13353 {
13354 struct vimoption *opt = &options[opt_idx];
13355
13356 if ((bufopt && (opt->indir & PV_BUF))
13357 || (!bufopt && (opt->indir & PV_WIN)))
13358 {
13359 char_u *varp = get_varp(opt);
13360
13361 if (varp != NULL)
13362 {
13363 if (opt->flags & P_STRING)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013364 dict_add_string(d, opt->fullname, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020013365 else if (opt->flags & P_NUM)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013366 dict_add_number(d, opt->fullname, *(long *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013367 else
Bram Moolenaare0be1672018-07-08 16:50:37 +020013368 dict_add_number(d, opt->fullname, *(int *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013369 }
13370 }
13371 }
13372
13373 return d;
13374}
13375#endif