blob: 6d2bab1e02dec7b03cc8a84db5b5267c981e3046 [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 Moolenaar071d4272004-06-13 20:20:40 +00002730 {"terse", NULL, P_BOOL|P_VI_DEF,
2731 (char_u *)&p_terse, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002732 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002733 {"textauto", "ta", P_BOOL|P_VIM,
2734 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002735 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002736 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002737 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2738 (char_u *)&p_tx, PV_TX,
2739 {
2740#ifdef USE_CRNL
2741 (char_u *)TRUE,
2742#else
2743 (char_u *)FALSE,
2744#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002745 (char_u *)0L} SCTX_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002746 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002747 (char_u *)&p_tw, PV_TW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002748 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002749 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002750#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002751 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002752#else
2753 (char_u *)NULL, PV_NONE,
2754#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002755 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002756 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2757 (char_u *)&p_to, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002758 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002759 {"timeout", "to", P_BOOL|P_VI_DEF,
2760 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002761 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002762 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2763 (char_u *)&p_tm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002764 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002765 {"title", NULL, P_BOOL|P_VI_DEF,
2766#ifdef FEAT_TITLE
2767 (char_u *)&p_title, PV_NONE,
2768#else
2769 (char_u *)NULL, PV_NONE,
2770#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002771 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002772 {"titlelen", NULL, P_NUM|P_VI_DEF,
2773#ifdef FEAT_TITLE
2774 (char_u *)&p_titlelen, PV_NONE,
2775#else
2776 (char_u *)NULL, PV_NONE,
2777#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002778 {(char_u *)85L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002779 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002780#ifdef FEAT_TITLE
2781 (char_u *)&p_titleold, PV_NONE,
2782 {(char_u *)N_("Thanks for flying Vim"),
2783 (char_u *)0L}
2784#else
2785 (char_u *)NULL, PV_NONE,
2786 {(char_u *)0L, (char_u *)0L}
2787#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002788 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002789 {"titlestring", NULL, P_STRING|P_VI_DEF,
2790#ifdef FEAT_TITLE
2791 (char_u *)&p_titlestring, PV_NONE,
2792#else
2793 (char_u *)NULL, PV_NONE,
2794#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002795 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002796 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002797#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002798 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002799 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002800#else
2801 (char_u *)NULL, PV_NONE,
2802 {(char_u *)0L, (char_u *)0L}
2803#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002804 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002805 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002806#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002807 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002808 {(char_u *)"small", (char_u *)0L}
2809#else
2810 (char_u *)NULL, PV_NONE,
2811 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002812#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002813 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002814 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2815 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002816 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002817 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2818 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002819 {(char_u *)-1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002820 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2821 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002822 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002823 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2824 (char_u *)&p_tf, 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 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2827#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2828 (char_u *)&p_ttym, PV_NONE,
2829#else
2830 (char_u *)NULL, PV_NONE,
2831#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002832 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002833 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2834 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002835 {(char_u *)999L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002836 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2837 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002838 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002839 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2840 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002841#ifdef FEAT_PERSISTENT_UNDO
2842 (char_u *)&p_udir, PV_NONE,
2843 {(char_u *)".", (char_u *)0L}
2844#else
2845 (char_u *)NULL, PV_NONE,
2846 {(char_u *)0L, (char_u *)0L}
2847#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002848 SCTX_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002849 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2850#ifdef FEAT_PERSISTENT_UNDO
2851 (char_u *)&p_udf, PV_UDF,
2852#else
2853 (char_u *)NULL, PV_NONE,
2854#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002855 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002856 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002857 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002858 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002859#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002860 (char_u *)1000L,
2861#else
2862 (char_u *)100L,
2863#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002864 (char_u *)0L} SCTX_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002865 {"undoreload", "ur", P_NUM|P_VI_DEF,
2866 (char_u *)&p_ur, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002867 { (char_u *)10000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002868 {"updatecount", "uc", P_NUM|P_VI_DEF,
2869 (char_u *)&p_uc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002870 {(char_u *)200L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002871 {"updatetime", "ut", P_NUM|P_VI_DEF,
2872 (char_u *)&p_ut, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002873 {(char_u *)4000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar04958cb2018-06-23 19:23:02 +02002874 {"varsofttabstop", "vsts", P_STRING|P_VI_DEF|P_VIM|P_COMMA,
2875#ifdef FEAT_VARTABS
2876 (char_u *)&p_vsts, PV_VSTS,
2877 {(char_u *)"", (char_u *)0L}
2878#else
2879 (char_u *)NULL, PV_NONE,
2880 {(char_u *)"", (char_u *)NULL}
2881#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002882 SCTX_INIT},
Bram Moolenaar04958cb2018-06-23 19:23:02 +02002883 {"vartabstop", "vts", P_STRING|P_VI_DEF|P_VIM|P_RBUF|P_COMMA,
2884#ifdef FEAT_VARTABS
2885 (char_u *)&p_vts, PV_VTS,
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 Moolenaar071d4272004-06-13 20:20:40 +00002892 {"verbose", "vbs", P_NUM|P_VI_DEF,
2893 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002894 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002895 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2896 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002897 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002898 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2899#ifdef FEAT_SESSION
2900 (char_u *)&p_vdir, PV_NONE,
2901 {(char_u *)DFLT_VDIR, (char_u *)0L}
2902#else
2903 (char_u *)NULL, PV_NONE,
2904 {(char_u *)0L, (char_u *)0L}
2905#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002906 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002907 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002908#ifdef FEAT_SESSION
2909 (char_u *)&p_vop, PV_NONE,
Bram Moolenaar13e90412017-11-11 18:16:48 +01002910 {(char_u *)"folds,options,cursor,curdir",
2911 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002912#else
2913 (char_u *)NULL, PV_NONE,
2914 {(char_u *)0L, (char_u *)0L}
2915#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002916 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002917 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002918#ifdef FEAT_VIMINFO
2919 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002920#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002921 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002922#else
2923# ifdef AMIGA
2924 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002925 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002926# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002927 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002928# endif
2929#endif
2930#else
2931 (char_u *)NULL, PV_NONE,
2932 {(char_u *)0L, (char_u *)0L}
2933#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002934 SCTX_INIT},
Bram Moolenaarc229e542018-07-08 21:46:56 +02002935 {"viminfofile", "vif", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP
2936 |P_SECURE|P_VI_DEF,
Bram Moolenaarc4da1132017-07-15 19:39:43 +02002937#ifdef FEAT_VIMINFO
2938 (char_u *)&p_viminfofile, PV_NONE,
2939 {(char_u *)"", (char_u *)0L}
2940#else
2941 (char_u *)NULL, PV_NONE,
2942 {(char_u *)0L, (char_u *)0L}
2943#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002944 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002945 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2946 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002947 (char_u *)&p_ve, PV_NONE,
2948 {(char_u *)"", (char_u *)""}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002949 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002950 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2951 (char_u *)&p_vb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002952 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002953 {"w300", NULL, P_NUM|P_VI_DEF,
2954 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002955 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002956 {"w1200", NULL, P_NUM|P_VI_DEF,
2957 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002958 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002959 {"w9600", NULL, P_NUM|P_VI_DEF,
2960 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002961 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002962 {"warn", NULL, P_BOOL|P_VI_DEF,
2963 (char_u *)&p_warn, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002964 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002965 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2966 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002967 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002968 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002969 (char_u *)&p_ww, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002970 {(char_u *)"", (char_u *)"b,s"} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002971 {"wildchar", "wc", P_NUM|P_VIM,
2972 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002973 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002974 SCTX_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002975 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002976 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002977 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002978 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002979#ifdef FEAT_WILDIGN
2980 (char_u *)&p_wig, PV_NONE,
2981#else
2982 (char_u *)NULL, PV_NONE,
2983#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002984 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002985 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2986 (char_u *)&p_wic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002987 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002988 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2989#ifdef FEAT_WILDMENU
2990 (char_u *)&p_wmnu, PV_NONE,
2991#else
2992 (char_u *)NULL, PV_NONE,
2993#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002994 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002995 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002996 (char_u *)&p_wim, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002997 {(char_u *)"full", (char_u *)0L} SCTX_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002998 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2999#ifdef FEAT_CMDL_COMPL
3000 (char_u *)&p_wop, PV_NONE,
3001 {(char_u *)"", (char_u *)0L}
3002#else
3003 (char_u *)NULL, PV_NONE,
3004 {(char_u *)NULL, (char_u *)0L}
3005#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003006 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003007 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3008#ifdef FEAT_WAK
3009 (char_u *)&p_wak, PV_NONE,
3010 {(char_u *)"menu", (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 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003017 (char_u *)&p_window, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003018 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003019 {"winheight", "wh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003020 (char_u *)&p_wh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003021 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003022 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003023 (char_u *)VAR_WIN, PV_WFH,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003024 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003025 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003026 (char_u *)VAR_WIN, PV_WFW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003027 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003028 {"winminheight", "wmh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003029 (char_u *)&p_wmh, 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 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003032 (char_u *)&p_wmw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003033 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003034 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar84ed4ad2017-08-17 11:33:42 +02003035#if defined(WIN3264) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003036 (char_u *)&p_winptydll, PV_NONE, {
3037# ifdef _WIN64
3038 (char_u *)"winpty64.dll",
3039# else
3040 (char_u *)"winpty32.dll",
3041# endif
3042 (char_u *)0L}
3043#else
3044 (char_u *)NULL, PV_NONE,
3045 {(char_u *)0L, (char_u *)0L}
3046#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003047 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003048 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003049 (char_u *)&p_wiw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003050 {(char_u *)20L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003051 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3052 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003053 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003054 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3055 (char_u *)&p_wm, PV_WM,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003056 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003057 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3058 (char_u *)&p_ws, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003059 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003060 {"write", NULL, P_BOOL|P_VI_DEF,
3061 (char_u *)&p_write, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003062 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003063 {"writeany", "wa", P_BOOL|P_VI_DEF,
3064 (char_u *)&p_wa, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003065 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003066 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3067 (char_u *)&p_wb, PV_NONE,
3068 {
3069#ifdef FEAT_WRITEBACKUP
3070 (char_u *)TRUE,
3071#else
3072 (char_u *)FALSE,
3073#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003074 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003075 {"writedelay", "wd", P_NUM|P_VI_DEF,
3076 (char_u *)&p_wd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003077 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003078
3079/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003080#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003081 (char_u *)&vvv, PV_NONE, \
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003082 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003083
3084 p_term("t_AB", T_CAB)
3085 p_term("t_AF", T_CAF)
3086 p_term("t_AL", T_CAL)
3087 p_term("t_al", T_AL)
3088 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003089 p_term("t_BE", T_BE)
3090 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003091 p_term("t_cd", T_CD)
3092 p_term("t_ce", T_CE)
3093 p_term("t_cl", T_CL)
3094 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003095 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003096 p_term("t_Co", T_CCO)
3097 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003098 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003099 p_term("t_cs", T_CS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003100 p_term("t_CV", T_CSV)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003101 p_term("t_da", T_DA)
3102 p_term("t_db", T_DB)
3103 p_term("t_DL", T_CDL)
3104 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003105 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003106 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003107 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003108 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003109 p_term("t_IE", T_CIE)
3110 p_term("t_IS", T_CIS)
3111 p_term("t_ke", T_KE)
3112 p_term("t_ks", T_KS)
3113 p_term("t_le", T_LE)
3114 p_term("t_mb", T_MB)
3115 p_term("t_md", T_MD)
3116 p_term("t_me", T_ME)
3117 p_term("t_mr", T_MR)
3118 p_term("t_ms", T_MS)
3119 p_term("t_nd", T_ND)
3120 p_term("t_op", T_OP)
Bram Moolenaara20f83d2017-10-15 13:35:01 +02003121 p_term("t_RF", T_RFG)
Bram Moolenaare5401222015-06-25 19:16:56 +02003122 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003123 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003124 p_term("t_RI", T_CRI)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003125 p_term("t_Ri", T_SRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003126 p_term("t_RS", T_CRS)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003127 p_term("t_RT", T_CRT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003128 p_term("t_RV", T_CRV)
3129 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003130 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003131 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003132 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003133 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003134 p_term("t_SI", T_CSI)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003135 p_term("t_Si", T_SSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003136 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003137 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003138 p_term("t_sr", T_SR)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003139 p_term("t_ST", T_CST)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003140 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003141 p_term("t_te", T_TE)
3142 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003143 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003144 p_term("t_ts", T_TS)
3145 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003146 p_term("t_ue", T_UE)
3147 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003148 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003149 p_term("t_vb", T_VB)
3150 p_term("t_ve", T_VE)
3151 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003152 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003153 p_term("t_vs", T_VS)
3154 p_term("t_WP", T_CWP)
3155 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003156 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003157 p_term("t_xs", T_XS)
3158 p_term("t_ZH", T_CZH)
3159 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003160 p_term("t_8f", T_8F)
3161 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003162
3163/* terminal key codes are not in here */
3164
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003165 /* end marker */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003166 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCTX_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003167};
3168
3169#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3170
Bram Moolenaar071d4272004-06-13 20:20:40 +00003171static char *(p_ambw_values[]) = {"single", "double", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003172static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003173static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003174static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003175#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003176static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003177#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003178#ifdef FEAT_CMDL_COMPL
3179static char *(p_wop_values[]) = {"tagfile", NULL};
3180#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003181#ifdef FEAT_WAK
3182static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3183#endif
3184static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003185static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3186static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003187static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003188#ifdef FEAT_BROWSE
3189static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3190#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003191static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
Bram Moolenaar57657d82006-04-21 22:12:41 +00003192static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003193static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
Bram Moolenaarf2732452018-06-03 14:47:35 +02003194static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", "prompt", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003195static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003196static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3197#ifdef FEAT_FOLDING
3198static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003199# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003200 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003201# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003202 NULL};
3203static char *(p_fcl_values[]) = {"all", NULL};
3204#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003205#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003206static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003207#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003208#ifdef FEAT_SIGNS
3209static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3210#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003211
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003212static void set_options_default(int opt_flags);
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003213static void set_string_default_esc(char *name, char_u *val, int escape);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003214static char_u *term_bg_default(void);
Bram Moolenaar916a8182018-11-25 02:18:29 +01003215static void did_set_option(int opt_idx, int opt_flags, int new_value, int value_checked);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003216static char_u *option_expand(int opt_idx, char_u *val);
3217static void didset_options(void);
3218static void didset_options2(void);
3219static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003220#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003221static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003222#else
3223# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3224#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003225static void set_string_option_global(int opt_idx, char_u **varp);
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003226static 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);
3227static char *set_chars_option(char_u **varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003228#ifdef FEAT_CLIPBOARD
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003229static char *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003230#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003231#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003232static char *did_set_spell_option(int is_spellfile);
3233static char *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003234#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003235#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003236static void set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003237#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003238static char *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3239static 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 +01003240static void check_redraw(long_u flags);
3241static int findoption(char_u *);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02003242static int find_key_option(char_u *arg_arg, int has_lt);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003243static void showoptions(int all, int opt_flags);
3244static int optval_default(struct vimoption *, char_u *varp);
3245static void showoneopt(struct vimoption *, int opt_flags);
Bram Moolenaared18f2c2019-01-24 20:30:52 +01003246static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, long_u flags);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003247static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3248static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3249static int istermoption(struct vimoption *);
3250static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3251static char_u *get_varp(struct vimoption *);
3252static void option_value2string(struct vimoption *, int opt_flags);
3253static void check_winopt(winopt_T *wop);
3254static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003255#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003256static void langmap_init(void);
3257static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003258#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003259static void paste_option_changed(void);
3260static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003261#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003262static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003263#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003264static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3265static int check_opt_strings(char_u *val, char **values, int);
3266static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003267#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003268static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003269#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003270
3271/*
3272 * Initialize the options, first part.
3273 *
3274 * Called only once from main(), just after creating the first buffer.
Bram Moolenaar07268702018-03-01 21:57:32 +01003275 * If "clean_arg" is TRUE Vim was started with --clean.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003276 */
3277 void
Bram Moolenaar07268702018-03-01 21:57:32 +01003278set_init_1(int clean_arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003279{
3280 char_u *p;
3281 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003282 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003283
3284#ifdef FEAT_LANGMAP
3285 langmap_init();
3286#endif
3287
3288 /* Be Vi compatible by default */
3289 p_cp = TRUE;
3290
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003291 /* Use POSIX compatibility when $VIM_POSIX is set. */
3292 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003293 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003294 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003295 set_string_default("shm", (char_u *)"A");
3296 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003297
Bram Moolenaar071d4272004-06-13 20:20:40 +00003298 /*
3299 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003300 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003301 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003302 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003303#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003304 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003305# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003306 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003307# endif
3308#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003309 )
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003310 set_string_default_esc("sh", p, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003311
3312#ifdef FEAT_WILDIGN
3313 /*
3314 * Set the default for 'backupskip' to include environment variables for
3315 * temp files.
3316 */
3317 {
3318# ifdef UNIX
3319 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3320# else
3321 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3322# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003323 int len;
3324 garray_T ga;
3325 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003326
3327 ga_init2(&ga, 1, 100);
3328 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3329 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003330 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003331# ifdef UNIX
3332 if (*names[n] == NUL)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003333# ifdef MACOS_X
3334 p = (char_u *)"/private/tmp";
3335# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003336 p = (char_u *)"/tmp";
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003337# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003338 else
3339# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003340 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003341 if (p != NULL && *p != NUL)
3342 {
3343 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003344 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003345 if (ga_grow(&ga, len) == OK)
3346 {
3347 if (ga.ga_len > 0)
3348 STRCAT(ga.ga_data, ",");
3349 STRCAT(ga.ga_data, p);
3350 add_pathsep(ga.ga_data);
3351 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003352 ga.ga_len += len;
3353 }
3354 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003355 if (mustfree)
3356 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003357 }
3358 if (ga.ga_data != NULL)
3359 {
3360 set_string_default("bsk", ga.ga_data);
3361 vim_free(ga.ga_data);
3362 }
3363 }
3364#endif
3365
3366 /*
3367 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3368 */
3369 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003370 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003371 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003372#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3373 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3374#endif
3375 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003376#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003377 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003378 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003379#else
3380# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003381 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003382 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003383# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003384 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003385# endif
3386#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003387 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003388 opt_idx = findoption((char_u *)"maxmem");
3389 if (opt_idx >= 0)
3390 {
3391#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003392 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3393 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003394#endif
3395 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3396 }
3397 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003398 }
3399
Bram Moolenaar071d4272004-06-13 20:20:40 +00003400#ifdef FEAT_SEARCHPATH
3401 {
3402 char_u *cdpath;
3403 char_u *buf;
3404 int i;
3405 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003406 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003407
3408 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003409 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003410 if (cdpath != NULL)
3411 {
3412 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3413 if (buf != NULL)
3414 {
3415 buf[0] = ','; /* start with ",", current dir first */
3416 j = 1;
3417 for (i = 0; cdpath[i] != NUL; ++i)
3418 {
3419 if (vim_ispathlistsep(cdpath[i]))
3420 buf[j++] = ',';
3421 else
3422 {
3423 if (cdpath[i] == ' ' || cdpath[i] == ',')
3424 buf[j++] = '\\';
3425 buf[j++] = cdpath[i];
3426 }
3427 }
3428 buf[j] = NUL;
3429 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003430 if (opt_idx >= 0)
3431 {
3432 options[opt_idx].def_val[VI_DEFAULT] = buf;
3433 options[opt_idx].flags |= P_DEF_ALLOCED;
3434 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003435 else
3436 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003437 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003438 if (mustfree)
3439 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003440 }
3441 }
3442#endif
3443
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003444#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003445 /* Set print encoding on platforms that don't default to latin1 */
3446 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003447# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003448 (char_u *)"cp1252"
3449# else
3450# ifdef VMS
3451 (char_u *)"dec-mcs"
3452# else
3453# ifdef EBCDIC
3454 (char_u *)"ebcdic-uk"
3455# else
3456# ifdef MAC
3457 (char_u *)"mac-roman"
3458# else /* HPUX */
3459 (char_u *)"hp-roman8"
3460# endif
3461# endif
3462# endif
3463# endif
3464 );
3465#endif
3466
3467#ifdef FEAT_POSTSCRIPT
3468 /* 'printexpr' must be allocated to be able to evaluate it. */
3469 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003470# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003471 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003472# else
3473# ifdef VMS
3474 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3475
3476# else
3477 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3478# endif
3479# endif
3480 );
3481#endif
3482
3483 /*
3484 * Set all the options (except the terminal options) to their default
3485 * value. Also set the global value for local options.
3486 */
3487 set_options_default(0);
3488
Bram Moolenaar07268702018-03-01 21:57:32 +01003489#ifdef CLEAN_RUNTIMEPATH
3490 if (clean_arg)
3491 {
3492 opt_idx = findoption((char_u *)"runtimepath");
3493 if (opt_idx >= 0)
3494 {
3495 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3496 p_rtp = (char_u *)CLEAN_RUNTIMEPATH;
3497 }
3498 opt_idx = findoption((char_u *)"packpath");
3499 if (opt_idx >= 0)
3500 {
3501 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3502 p_pp = (char_u *)CLEAN_RUNTIMEPATH;
3503 }
3504 }
3505#endif
3506
Bram Moolenaar071d4272004-06-13 20:20:40 +00003507#ifdef FEAT_GUI
3508 if (found_reverse_arg)
3509 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3510#endif
3511
3512 curbuf->b_p_initialized = TRUE;
3513 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003514 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003515 check_buf_options(curbuf);
3516 check_win_options(curwin);
3517 check_options();
3518
3519 /* Must be before option_expand(), because that one needs vim_isIDc() */
3520 didset_options();
3521
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003522#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003523 /* Use the current chartab for the generic chartab. This is not in
3524 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003525 init_spell_chartab();
3526#endif
3527
Bram Moolenaar071d4272004-06-13 20:20:40 +00003528 /*
3529 * Expand environment variables and things like "~" for the defaults.
3530 * If option_expand() returns non-NULL the variable is expanded. This can
3531 * only happen for non-indirect options.
3532 * Also set the default to the expanded value, so ":set" does not list
3533 * them.
3534 * Don't set the P_ALLOCED flag, because we don't want to free the
3535 * default.
3536 */
3537 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3538 {
3539 if ((options[opt_idx].flags & P_GETTEXT)
3540 && options[opt_idx].var != NULL)
3541 p = (char_u *)_(*(char **)options[opt_idx].var);
3542 else
3543 p = option_expand(opt_idx, NULL);
3544 if (p != NULL && (p = vim_strsave(p)) != NULL)
3545 {
3546 *(char_u **)options[opt_idx].var = p;
3547 /* VIMEXP
3548 * Defaults for all expanded options are currently the same for Vi
3549 * and Vim. When this changes, add some code here! Also need to
3550 * split P_DEF_ALLOCED in two.
3551 */
3552 if (options[opt_idx].flags & P_DEF_ALLOCED)
3553 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3554 options[opt_idx].def_val[VI_DEFAULT] = p;
3555 options[opt_idx].flags |= P_DEF_ALLOCED;
3556 }
3557 }
3558
Bram Moolenaar071d4272004-06-13 20:20:40 +00003559 save_file_ff(curbuf); /* Buffer is unchanged */
3560
Bram Moolenaar071d4272004-06-13 20:20:40 +00003561#if defined(FEAT_ARABIC)
3562 /* Detect use of mlterm.
3563 * Mlterm is a terminal emulator akin to xterm that has some special
3564 * abilities (bidi namely).
3565 * NOTE: mlterm's author is being asked to 'set' a variable
3566 * instead of an environment variable due to inheritance.
3567 */
3568 if (mch_getenv((char_u *)"MLTERM") != NULL)
3569 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3570#endif
3571
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003572 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003573
Bram Moolenaar071d4272004-06-13 20:20:40 +00003574# if defined(WIN3264) && defined(FEAT_GETTEXT)
3575 /*
3576 * If $LANG isn't set, try to get a good value for it. This makes the
3577 * right language be used automatically. Don't do this for English.
3578 */
3579 if (mch_getenv((char_u *)"LANG") == NULL)
3580 {
3581 char buf[20];
3582
3583 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3584 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3585 * only the first two. */
3586 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3587 (LPTSTR)buf, 20);
3588 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3589 {
3590 /* There are a few exceptions (probably more) */
3591 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3592 STRCPY(buf, "zh_TW");
3593 else if (STRNICMP(buf, "chs", 3) == 0
3594 || STRNICMP(buf, "zhc", 3) == 0)
3595 STRCPY(buf, "zh_CN");
3596 else if (STRNICMP(buf, "jp", 2) == 0)
3597 STRCPY(buf, "ja");
3598 else
3599 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003600 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003601 }
3602 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003603# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003604# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003605 /* Moved to os_mac_conv.c to avoid dependency problems. */
3606 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003607# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003608# endif
3609
3610 /* enc_locale() will try to find the encoding of the current locale. */
3611 p = enc_locale();
3612 if (p != NULL)
3613 {
3614 char_u *save_enc;
3615
3616 /* Try setting 'encoding' and check if the value is valid.
3617 * If not, go back to the default "latin1". */
3618 save_enc = p_enc;
3619 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003620 if (STRCMP(p_enc, "gb18030") == 0)
3621 {
3622 /* We don't support "gb18030", but "cp936" is a good substitute
3623 * for practical purposes, thus use that. It's not an alias to
3624 * still support conversion between gb18030 and utf-8. */
3625 p_enc = vim_strsave((char_u *)"cp936");
3626 vim_free(p);
3627 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003628 if (mb_init() == NULL)
3629 {
3630 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003631 if (opt_idx >= 0)
3632 {
3633 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3634 options[opt_idx].flags |= P_DEF_ALLOCED;
3635 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003636
Bram Moolenaard0573012017-10-28 21:11:06 +02003637#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003638 if (STRCMP(p_enc, "latin1") == 0 || enc_utf8)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003639 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003640 /* Adjust the default for 'isprint' and 'iskeyword' to match
3641 * latin1. Also set the defaults for when 'nocompatible' is
3642 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003643 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003644 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003645 set_string_option_direct((char_u *)"isk", -1,
3646 ISK_LATIN1, OPT_FREE, SID_NONE);
3647 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003648 if (opt_idx >= 0)
3649 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003650 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003651 if (opt_idx >= 0)
3652 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003653 (void)init_chartab();
3654 }
3655#endif
3656
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003657#if defined(WIN3264) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003658 /* Win32 console: When GetACP() returns a different value from
3659 * GetConsoleCP() set 'termencoding'. */
3660 if (GetACP() != GetConsoleCP())
3661 {
3662 char buf[50];
3663
3664 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3665 p_tenc = vim_strsave((char_u *)buf);
3666 if (p_tenc != NULL)
3667 {
3668 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003669 if (opt_idx >= 0)
3670 {
3671 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3672 options[opt_idx].flags |= P_DEF_ALLOCED;
3673 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003674 convert_setup(&input_conv, p_tenc, p_enc);
3675 convert_setup(&output_conv, p_enc, p_tenc);
3676 }
3677 else
3678 p_tenc = empty_option;
3679 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003680#endif
3681#if defined(WIN3264)
Bram Moolenaar05159a02005-02-26 23:04:13 +00003682 /* $HOME may have characters in active code page. */
3683 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003684#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003685 }
3686 else
3687 {
3688 vim_free(p_enc);
3689 p_enc = save_enc;
3690 }
3691 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003692
3693#ifdef FEAT_MULTI_LANG
3694 /* Set the default for 'helplang'. */
3695 set_helplang_default(get_mess_lang());
3696#endif
3697}
3698
3699/*
3700 * Set an option to its default value.
3701 * This does not take care of side effects!
3702 */
3703 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003704set_option_default(
3705 int opt_idx,
3706 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3707 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003708{
3709 char_u *varp; /* pointer to variable for current option */
3710 int dvi; /* index in def_val[] */
3711 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003712 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003713 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3714
3715 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3716 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003717 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003718 {
3719 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3720 if (flags & P_STRING)
3721 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003722 /* Use set_string_option_direct() for local options to handle
3723 * freeing and allocating the value. */
3724 if (options[opt_idx].indir != PV_NONE)
3725 set_string_option_direct(NULL, opt_idx,
3726 options[opt_idx].def_val[dvi], opt_flags, 0);
3727 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003728 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003729 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3730 free_string_option(*(char_u **)(varp));
3731 *(char_u **)varp = options[opt_idx].def_val[dvi];
3732 options[opt_idx].flags &= ~P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003733 }
3734 }
3735 else if (flags & P_NUM)
3736 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003737 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003738 win_comp_scroll(curwin);
3739 else
3740 {
Bram Moolenaar375e3392019-01-31 18:26:10 +01003741 long def_val = (long)(long_i)options[opt_idx].def_val[dvi];
3742
3743 if ((long *)varp == &curwin->w_p_so
3744 || (long *)varp == &curwin->w_p_siso)
3745 // 'scrolloff' and 'sidescrolloff' local values have a
3746 // different default value than the global default.
3747 *(long *)varp = -1;
3748 else
3749 *(long *)varp = def_val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003750 /* May also set global value for local option. */
3751 if (both)
3752 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
Bram Moolenaar375e3392019-01-31 18:26:10 +01003753 def_val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003754 }
3755 }
3756 else /* P_BOOL */
3757 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003758 /* the cast to long is required for Manx C, long_i is needed for
3759 * MSVC */
3760 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003761#ifdef UNIX
3762 /* 'modeline' defaults to off for root */
3763 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3764 *(int *)varp = FALSE;
3765#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003766 /* May also set global value for local option. */
3767 if (both)
3768 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3769 *(int *)varp;
3770 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003771
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003772 /* The default value is not insecure. */
3773 flagsp = insecure_flag(opt_idx, opt_flags);
3774 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003775 }
3776
3777#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003778 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003779#endif
3780}
3781
3782/*
3783 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003784 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003785 */
3786 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003787set_options_default(
3788 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003789{
3790 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003791 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003792 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003793
3794 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003795 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003796 && (opt_flags == 0
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003797 || (options[i].var != (char_u *)&p_enc
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003798# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003799 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003800 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003801# endif
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003802 )))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003803 set_option_default(i, opt_flags, p_cp);
3804
Bram Moolenaar071d4272004-06-13 20:20:40 +00003805 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003806 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003807 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003808#ifdef FEAT_CINDENT
3809 parse_cino(curbuf);
3810#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003811}
3812
3813/*
3814 * Set the Vi-default value of a string option.
3815 * Used for 'sh', 'backupskip' and 'term'.
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003816 * When "escape" is TRUE escape spaces with a backslash.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003817 */
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003818 static void
3819set_string_default_esc(char *name, char_u *val, int escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003820{
3821 char_u *p;
3822 int opt_idx;
3823
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003824 if (escape && vim_strchr(val, ' ') != NULL)
3825 p = vim_strsave_escaped(val, (char_u *)" ");
3826 else
3827 p = vim_strsave(val);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003828 if (p != NULL) /* we don't want a NULL */
3829 {
3830 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003831 if (opt_idx >= 0)
3832 {
3833 if (options[opt_idx].flags & P_DEF_ALLOCED)
3834 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3835 options[opt_idx].def_val[VI_DEFAULT] = p;
3836 options[opt_idx].flags |= P_DEF_ALLOCED;
3837 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003838 }
3839}
3840
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003841 void
3842set_string_default(char *name, char_u *val)
3843{
3844 set_string_default_esc(name, val, FALSE);
3845}
3846
Bram Moolenaar071d4272004-06-13 20:20:40 +00003847/*
3848 * Set the Vi-default value of a number option.
3849 * Used for 'lines' and 'columns'.
3850 */
3851 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003852set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003853{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003854 int opt_idx;
3855
3856 opt_idx = findoption((char_u *)name);
3857 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003858 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003859}
3860
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003861#if defined(EXITFREE) || defined(PROTO)
3862/*
3863 * Free all options.
3864 */
3865 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003866free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003867{
3868 int i;
3869
3870 for (i = 0; !istermoption(&options[i]); i++)
3871 {
3872 if (options[i].indir == PV_NONE)
3873 {
3874 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003875 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003876 free_string_option(*(char_u **)options[i].var);
3877 if (options[i].flags & P_DEF_ALLOCED)
3878 free_string_option(options[i].def_val[VI_DEFAULT]);
3879 }
3880 else if (options[i].var != VAR_WIN
3881 && (options[i].flags & P_STRING))
3882 /* buffer-local option: free global value */
3883 free_string_option(*(char_u **)options[i].var);
3884 }
3885}
3886#endif
3887
3888
Bram Moolenaar071d4272004-06-13 20:20:40 +00003889/*
3890 * Initialize the options, part two: After getting Rows and Columns and
3891 * setting 'term'.
3892 */
3893 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003894set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003895{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003896 int idx;
3897
Bram Moolenaar071d4272004-06-13 20:20:40 +00003898 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003899 * 'scroll' defaults to half the window height. The stored default is zero,
3900 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003901 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003902 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003903 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003904 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003905 comp_col();
3906
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003907 /*
3908 * 'window' is only for backwards compatibility with Vi.
3909 * Default is Rows - 1.
3910 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003911 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003912 p_window = Rows - 1;
3913 set_number_default("window", Rows - 1);
3914
Bram Moolenaarf740b292006-02-16 22:11:02 +00003915 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003916#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003917 /*
3918 * If 'background' wasn't set by the user, try guessing the value,
3919 * depending on the terminal name. Only need to check for terminals
3920 * with a dark background, that can handle color.
3921 */
3922 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003923 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3924 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003925 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003926 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003927 /* don't mark it as set, when starting the GUI it may be
3928 * changed again */
3929 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003930 }
3931#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003932
3933#ifdef CURSOR_SHAPE
3934 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3935#endif
3936#ifdef FEAT_MOUSESHAPE
3937 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3938#endif
3939#ifdef FEAT_PRINTER
3940 (void)parse_printoptions(); /* parse 'printoptions' default value */
3941#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003942}
3943
3944/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003945 * Return "dark" or "light" depending on the kind of terminal.
3946 * This is just guessing! Recognized are:
3947 * "linux" Linux console
3948 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003949 * "cygwin.*" Cygwin shell
3950 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00003951 * We also check the COLORFGBG environment variable, which is set by
3952 * rxvt and derivatives. This variable contains either two or three
3953 * values separated by semicolons; we want the last value in either
3954 * case. If this value is 0-6 or 8, our background is dark.
3955 */
3956 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003957term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003958{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003959#if defined(WIN3264)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003960 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003961 return (char_u *)"dark";
3962#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003963 char_u *p;
3964
Bram Moolenaarf740b292006-02-16 22:11:02 +00003965 if (STRCMP(T_NAME, "linux") == 0
3966 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003967 || STRNCMP(T_NAME, "cygwin", 6) == 0
3968 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00003969 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3970 && (p = vim_strrchr(p, ';')) != NULL
3971 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3972 && p[2] == NUL))
3973 return (char_u *)"dark";
3974 return (char_u *)"light";
3975#endif
3976}
3977
3978/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003979 * Initialize the options, part three: After reading the .vimrc
3980 */
3981 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003982set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003983{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003984#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003985/*
3986 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3987 * This is done after other initializations, where 'shell' might have been
3988 * set, but only if they have not been set before.
3989 */
3990 char_u *p;
3991 int idx_srr;
3992 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003993# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003994 int idx_sp;
3995 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003996# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003997
3998 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003999 if (idx_srr < 0)
4000 do_srr = FALSE;
4001 else
4002 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004003# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004004 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004005 if (idx_sp < 0)
4006 do_sp = FALSE;
4007 else
4008 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004009# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004010 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004011 if (p != NULL)
4012 {
4013 /*
4014 * Default for p_sp is "| tee", for p_srr is ">".
4015 * For known shells it is changed here to include stderr.
4016 */
4017 if ( fnamecmp(p, "csh") == 0
4018 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004019# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004020 || fnamecmp(p, "csh.exe") == 0
4021 || fnamecmp(p, "tcsh.exe") == 0
4022# endif
4023 )
4024 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004025# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004026 if (do_sp)
4027 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004028# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004029 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004030# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004031 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004032# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004033 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4034 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004035# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004036 if (do_srr)
4037 {
4038 p_srr = (char_u *)">&";
4039 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4040 }
4041 }
4042 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004043 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004044 if ( fnamecmp(p, "sh") == 0
4045 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004046 || fnamecmp(p, "mksh") == 0
4047 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004048 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004049 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004050 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004051 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004052# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004053 || fnamecmp(p, "cmd") == 0
4054 || fnamecmp(p, "sh.exe") == 0
4055 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004056 || fnamecmp(p, "mksh.exe") == 0
4057 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004058 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004059 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004060 || fnamecmp(p, "bash.exe") == 0
4061 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004062# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004063 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004064 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004065# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004066 if (do_sp)
4067 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004068# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004069 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004070# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004071 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004072# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004073 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4074 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004075# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004076 if (do_srr)
4077 {
4078 p_srr = (char_u *)">%s 2>&1";
4079 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4080 }
4081 }
4082 vim_free(p);
4083 }
4084#endif
4085
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004086#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004087 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004088 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4089 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004090 * This is done after other initializations, where 'shell' might have been
4091 * set, but only if they have not been set before. Default for p_shcf is
4092 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004093 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004094 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004095 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004096 {
4097 int idx3;
4098
4099 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004100 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004101 {
4102 p_shcf = (char_u *)"-c";
4103 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4104 }
4105
Bram Moolenaar071d4272004-06-13 20:20:40 +00004106 /* Somehow Win32 requires the quotes around the redirection too */
4107 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004108 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004109 {
4110 p_sxq = (char_u *)"\"";
4111 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4112 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004113 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004114 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4115 {
4116 int idx3;
4117
4118 /*
4119 * cmd.exe on Windows will strip the first and last double quote given
4120 * on the command line, e.g. most of the time things like:
4121 * cmd /c "my path/to/echo" "my args to echo"
4122 * become:
4123 * my path/to/echo" "my args to echo
4124 * when executed.
4125 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004126 * To avoid this, set shellxquote to surround the command in
4127 * parenthesis. This appears to make most commands work, without
4128 * breaking commands that worked previously, such as
4129 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004130 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004131 idx3 = findoption((char_u *)"sxq");
4132 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4133 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004134 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004135 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4136 }
4137
Bram Moolenaara64ba222012-02-12 23:23:31 +01004138 idx3 = findoption((char_u *)"shcf");
4139 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4140 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004141 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004142 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4143 }
4144 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004145#endif
4146
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004147 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004148 {
4149 int idx_ffs = findoption((char_u *)"ffs");
4150
4151 /* Apply the first entry of 'fileformats' to the initial buffer. */
4152 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4153 set_fileformat(default_fileformat(), OPT_LOCAL);
4154 }
4155
Bram Moolenaar071d4272004-06-13 20:20:40 +00004156#ifdef FEAT_TITLE
4157 set_title_defaults();
4158#endif
4159}
4160
4161#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4162/*
4163 * When 'helplang' is still at its default value, set it to "lang".
4164 * Only the first two characters of "lang" are used.
4165 */
4166 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004167set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004168{
4169 int idx;
4170
4171 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4172 return;
4173 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004174 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004175 {
4176 if (options[idx].flags & P_ALLOCED)
4177 free_string_option(p_hlg);
4178 p_hlg = vim_strsave(lang);
4179 if (p_hlg == NULL)
4180 p_hlg = empty_option;
4181 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004182 {
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004183 // zh_CN becomes "cn", zh_TW becomes "tw"
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004184 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4185 {
4186 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4187 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4188 }
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004189 // any C like setting, such as C.UTF-8, becomes "en"
4190 else if (STRLEN(p_hlg) >= 1 && *p_hlg == 'C')
4191 {
4192 p_hlg[0] = 'e';
4193 p_hlg[1] = 'n';
4194 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004195 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004196 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004197 options[idx].flags |= P_ALLOCED;
4198 }
4199}
4200#endif
4201
4202#ifdef FEAT_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00004203 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004204gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004205{
4206 if (gui_get_lightness(gui.back_pixel) < 127)
4207 return (char_u *)"dark";
4208 return (char_u *)"light";
4209}
4210
4211/*
4212 * Option initializations that can only be done after opening the GUI window.
4213 */
4214 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004215init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004216{
4217 /* Set the 'background' option according to the lightness of the
4218 * background color, unless the user has set it already. */
4219 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4220 {
4221 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4222 highlight_changed();
4223 }
4224}
4225#endif
4226
4227#ifdef FEAT_TITLE
4228/*
4229 * 'title' and 'icon' only default to true if they have not been set or reset
4230 * in .vimrc and we can read the old value.
4231 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4232 * they can be reset. This reduces startup time when using X on a remote
4233 * machine.
4234 */
4235 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004236set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004237{
4238 int idx1;
4239 long val;
4240
4241 /*
4242 * If GUI is (going to be) used, we can always set the window title and
4243 * icon name. Saves a bit of time, because the X11 display server does
4244 * not need to be contacted.
4245 */
4246 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004247 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004248 {
4249#ifdef FEAT_GUI
4250 if (gui.starting || gui.in_use)
4251 val = TRUE;
4252 else
4253#endif
4254 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004255 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004256 p_title = val;
4257 }
4258 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004259 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004260 {
4261#ifdef FEAT_GUI
4262 if (gui.starting || gui.in_use)
4263 val = TRUE;
4264 else
4265#endif
4266 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004267 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004268 p_icon = val;
4269 }
4270}
4271#endif
4272
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004273#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004274 static void
4275trigger_optionsset_string(
4276 int opt_idx,
4277 int opt_flags,
4278 char_u *oldval,
4279 char_u *newval)
4280{
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02004281 // Don't do this recursively.
4282 if (oldval != NULL && newval != NULL
4283 && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004284 {
4285 char_u buf_type[7];
4286
4287 sprintf((char *)buf_type, "%s",
4288 (opt_flags & OPT_LOCAL) ? "local" : "global");
4289 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4290 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4291 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4292 apply_autocmds(EVENT_OPTIONSET,
4293 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4294 reset_v_option_vars();
4295 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004296}
4297#endif
4298
Bram Moolenaar071d4272004-06-13 20:20:40 +00004299/*
4300 * Parse 'arg' for option settings.
4301 *
4302 * 'arg' may be IObuff, but only when no errors can be present and option
4303 * does not need to be expanded with option_expand().
4304 * "opt_flags":
4305 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004306 * OPT_GLOBAL for ":setglobal"
4307 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004308 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004309 * OPT_WINONLY to only set window-local options
4310 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004311 *
4312 * returns FAIL if an error is detected, OK otherwise
4313 */
4314 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004315do_set(
4316 char_u *arg, /* option string (may be written to!) */
4317 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004318{
4319 int opt_idx;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004320 char *errmsg;
4321 char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00004322 char_u *startarg;
4323 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4324 int nextchar; /* next non-white char after option name */
4325 int afterchar; /* character just after option name */
4326 int len;
4327 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004328 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004329 int key;
4330 long_u flags; /* flags for current option */
4331 char_u *varp = NULL; /* pointer to variable for current option */
4332 int did_show = FALSE; /* already showed one value */
4333 int adding; /* "opt+=arg" */
4334 int prepending; /* "opt^=arg" */
4335 int removing; /* "opt-=arg" */
4336 int cp_val = 0;
4337 char_u key_name[2];
4338
4339 if (*arg == NUL)
4340 {
4341 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004342 did_show = TRUE;
4343 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004344 }
4345
4346 while (*arg != NUL) /* loop to process all options */
4347 {
4348 errmsg = NULL;
4349 startarg = arg; /* remember for error message */
4350
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004351 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4352 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004353 {
4354 /*
4355 * ":set all" show all options.
4356 * ":set all&" set all options to their default value.
4357 */
4358 arg += 3;
4359 if (*arg == '&')
4360 {
4361 ++arg;
4362 /* Only for :set command set global value of local options. */
4363 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004364 didset_options();
4365 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004366 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004367 }
4368 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004369 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004370 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004371 did_show = TRUE;
4372 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004373 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004374 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004375 {
4376 showoptions(2, opt_flags);
4377 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004378 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004379 arg += 7;
4380 }
4381 else
4382 {
4383 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004384 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004385 {
4386 prefix = 0;
4387 arg += 2;
4388 }
4389 else if (STRNCMP(arg, "inv", 3) == 0)
4390 {
4391 prefix = 2;
4392 arg += 3;
4393 }
4394
4395 /* find end of name */
4396 key = 0;
4397 if (*arg == '<')
4398 {
4399 nextchar = 0;
4400 opt_idx = -1;
4401 /* look out for <t_>;> */
4402 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4403 len = 5;
4404 else
4405 {
4406 len = 1;
4407 while (arg[len] != NUL && arg[len] != '>')
4408 ++len;
4409 }
4410 if (arg[len] != '>')
4411 {
4412 errmsg = e_invarg;
4413 goto skip;
4414 }
4415 arg[len] = NUL; /* put NUL after name */
4416 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4417 opt_idx = findoption(arg + 1);
4418 arg[len++] = '>'; /* restore '>' */
4419 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004420 key = find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004421 }
4422 else
4423 {
4424 len = 0;
4425 /*
4426 * The two characters after "t_" may not be alphanumeric.
4427 */
4428 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4429 len = 4;
4430 else
4431 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4432 ++len;
4433 nextchar = arg[len];
4434 arg[len] = NUL; /* put NUL after name */
4435 opt_idx = findoption(arg);
4436 arg[len] = nextchar; /* restore nextchar */
4437 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004438 key = find_key_option(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004439 }
4440
4441 /* remember character after option name */
4442 afterchar = arg[len];
4443
4444 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004445 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004446 ++len;
4447
4448 adding = FALSE;
4449 prepending = FALSE;
4450 removing = FALSE;
4451 if (arg[len] != NUL && arg[len + 1] == '=')
4452 {
4453 if (arg[len] == '+')
4454 {
4455 adding = TRUE; /* "+=" */
4456 ++len;
4457 }
4458 else if (arg[len] == '^')
4459 {
4460 prepending = TRUE; /* "^=" */
4461 ++len;
4462 }
4463 else if (arg[len] == '-')
4464 {
4465 removing = TRUE; /* "-=" */
4466 ++len;
4467 }
4468 }
4469 nextchar = arg[len];
4470
4471 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4472 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004473 errmsg = N_("E518: Unknown option");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004474 goto skip;
4475 }
4476
4477 if (opt_idx >= 0)
4478 {
4479 if (options[opt_idx].var == NULL) /* hidden option: skip */
4480 {
4481 /* Only give an error message when requesting the value of
4482 * a hidden option, ignore setting it. */
4483 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4484 && (!(options[opt_idx].flags & P_BOOL)
4485 || nextchar == '?'))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004486 errmsg = N_("E519: Option not supported");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004487 goto skip;
4488 }
4489
4490 flags = options[opt_idx].flags;
4491 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4492 }
4493 else
4494 {
4495 flags = P_STRING;
4496 if (key < 0)
4497 {
4498 key_name[0] = KEY2TERMCAP0(key);
4499 key_name[1] = KEY2TERMCAP1(key);
4500 }
4501 else
4502 {
4503 key_name[0] = KS_KEY;
4504 key_name[1] = (key & 0xff);
4505 }
4506 }
4507
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004508 /* Skip all options that are not window-local (used when showing
4509 * an already loaded buffer in a window). */
4510 if ((opt_flags & OPT_WINONLY)
4511 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4512 goto skip;
4513
Bram Moolenaara3227e22006-03-08 21:32:40 +00004514 /* Skip all options that are window-local (used for :vimgrep). */
4515 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4516 && options[opt_idx].var == VAR_WIN)
4517 goto skip;
4518
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004519 /* Disallow changing some options from modelines. */
4520 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004521 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004522 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004523 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004524 errmsg = _("E520: Not allowed in a modeline");
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004525 goto skip;
4526 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004527#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004528 /* In diff mode some options are overruled. This avoids that
4529 * 'foldmethod' becomes "marker" instead of "diff" and that
4530 * "wrap" gets set. */
4531 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004532 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004533 && (
4534#ifdef FEAT_FOLDING
4535 options[opt_idx].indir == PV_FDM ||
4536#endif
4537 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004538 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004539#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004540 }
4541
4542#ifdef HAVE_SANDBOX
4543 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004544 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004545 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004546 errmsg = _(e_sandbox);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004547 goto skip;
4548 }
4549#endif
4550
4551 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4552 {
4553 arg += len;
4554 cp_val = p_cp;
4555 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4556 {
4557 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4558 {
4559 cp_val = FALSE;
4560 arg += 3;
4561 }
4562 else /* "opt&vi": set to Vi default */
4563 {
4564 cp_val = TRUE;
4565 arg += 2;
4566 }
4567 }
4568 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004569 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004570 {
4571 errmsg = e_trailing;
4572 goto skip;
4573 }
4574 }
4575
4576 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004577 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4578 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004579 */
4580 if (nextchar == '?'
4581 || (prefix == 1
4582 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4583 && !(flags & P_BOOL)))
4584 {
4585 /*
4586 * print value
4587 */
4588 if (did_show)
4589 msg_putchar('\n'); /* cursor below last one */
4590 else
4591 {
4592 gotocmdline(TRUE); /* cursor at status line */
4593 did_show = TRUE; /* remember that we did a line */
4594 }
4595 if (opt_idx >= 0)
4596 {
4597 showoneopt(&options[opt_idx], opt_flags);
4598#ifdef FEAT_EVAL
4599 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004600 {
4601 /* Mention where the option was last set. */
4602 if (varp == options[opt_idx].var)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004603 last_set_msg(options[opt_idx].script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004604 else if ((int)options[opt_idx].indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004605 last_set_msg(curwin->w_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004606 (int)options[opt_idx].indir & PV_MASK]);
4607 else if ((int)options[opt_idx].indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004608 last_set_msg(curbuf->b_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004609 (int)options[opt_idx].indir & PV_MASK]);
4610 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004611#endif
4612 }
4613 else
4614 {
4615 char_u *p;
4616
4617 p = find_termcode(key_name);
4618 if (p == NULL)
4619 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004620 errmsg = N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004621 goto skip;
4622 }
4623 else
4624 (void)show_one_termcode(key_name, p, TRUE);
4625 }
4626 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004627 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004628 errmsg = e_trailing;
4629 }
4630 else
4631 {
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004632 int value_is_replaced = !prepending && !adding && !removing;
Bram Moolenaar916a8182018-11-25 02:18:29 +01004633 int value_checked = FALSE;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004634
Bram Moolenaar071d4272004-06-13 20:20:40 +00004635 if (flags & P_BOOL) /* boolean */
4636 {
4637 if (nextchar == '=' || nextchar == ':')
4638 {
4639 errmsg = e_invarg;
4640 goto skip;
4641 }
4642
4643 /*
4644 * ":set opt!": invert
4645 * ":set opt&": reset to default value
4646 * ":set opt<": reset to global value
4647 */
4648 if (nextchar == '!')
4649 value = *(int *)(varp) ^ 1;
4650 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004651 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004652 ((flags & P_VI_DEF) || cp_val)
4653 ? VI_DEFAULT : VIM_DEFAULT];
4654 else if (nextchar == '<')
4655 {
4656 /* For 'autoread' -1 means to use global value. */
4657 if ((int *)varp == &curbuf->b_p_ar
4658 && opt_flags == OPT_LOCAL)
4659 value = -1;
4660 else
4661 value = *(int *)get_varp_scope(&(options[opt_idx]),
4662 OPT_GLOBAL);
4663 }
4664 else
4665 {
4666 /*
4667 * ":set invopt": invert
4668 * ":set opt" or ":set noopt": set or reset
4669 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004670 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004671 {
4672 errmsg = e_trailing;
4673 goto skip;
4674 }
4675 if (prefix == 2) /* inv */
4676 value = *(int *)(varp) ^ 1;
4677 else
4678 value = prefix;
4679 }
4680
4681 errmsg = set_bool_option(opt_idx, varp, (int)value,
4682 opt_flags);
4683 }
4684 else /* numeric or string */
4685 {
4686 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4687 || prefix != 1)
4688 {
4689 errmsg = e_invarg;
4690 goto skip;
4691 }
4692
4693 if (flags & P_NUM) /* numeric */
4694 {
4695 /*
4696 * Different ways to set a number option:
4697 * & set to default value
4698 * < set to global value
4699 * <xx> accept special key codes for 'wildchar'
4700 * c accept any non-digit for 'wildchar'
4701 * [-]0-9 set number
4702 * other error
4703 */
4704 ++arg;
4705 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004706 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004707 ((flags & P_VI_DEF) || cp_val)
4708 ? VI_DEFAULT : VIM_DEFAULT];
4709 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004710 {
4711 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4712 * use the global value. */
4713 if ((long *)varp == &curbuf->b_p_ul
4714 && opt_flags == OPT_LOCAL)
4715 value = NO_LOCAL_UNDOLEVEL;
4716 else
4717 value = *(long *)get_varp_scope(
4718 &(options[opt_idx]), OPT_GLOBAL);
4719 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004720 else if (((long *)varp == &p_wc
4721 || (long *)varp == &p_wcm)
4722 && (*arg == '<'
4723 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004724 || (*arg != NUL
4725 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004726 && !VIM_ISDIGIT(*arg))))
4727 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004728 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004729 if (value == 0 && (long *)varp != &p_wcm)
4730 {
4731 errmsg = e_invarg;
4732 goto skip;
4733 }
4734 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004735 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4736 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004737 /* Allow negative (for 'undolevels'), octal and
4738 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004739 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4740 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004741 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004742 {
4743 errmsg = e_invarg;
4744 goto skip;
4745 }
4746 }
4747 else
4748 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004749 errmsg = N_("E521: Number required after =");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004750 goto skip;
4751 }
4752
4753 if (adding)
4754 value = *(long *)varp + value;
4755 if (prepending)
4756 value = *(long *)varp * value;
4757 if (removing)
4758 value = *(long *)varp - value;
4759 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004760 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004761 }
4762 else if (opt_idx >= 0) /* string */
4763 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004764 char_u *save_arg = NULL;
4765 char_u *s = NULL;
4766 char_u *oldval = NULL; /* previous value if *varp */
4767 char_u *newval;
4768 char_u *origval = NULL;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004769#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004770 char_u *saved_origval = NULL;
4771 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004772#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004773 unsigned newlen;
4774 int comma;
4775 int bs;
4776 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004777 was allocated */
4778
4779 /* When using ":set opt=val" for a global option
4780 * with a local value the local value will be
4781 * reset, use the global value here. */
4782 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004783 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004784 varp = options[opt_idx].var;
4785
4786 /* The old value is kept until we are sure that the
4787 * new value is valid. */
4788 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004789
4790 /* When setting the local value of a global
4791 * option, the old value may be the global value. */
4792 if (((int)options[opt_idx].indir & PV_BOTH)
4793 && (opt_flags & OPT_LOCAL))
4794 origval = *(char_u **)get_varp(
4795 &options[opt_idx]);
4796 else
4797 origval = oldval;
4798
Bram Moolenaar071d4272004-06-13 20:20:40 +00004799 if (nextchar == '&') /* set to default val */
4800 {
4801 newval = options[opt_idx].def_val[
4802 ((flags & P_VI_DEF) || cp_val)
4803 ? VI_DEFAULT : VIM_DEFAULT];
4804 if ((char_u **)varp == &p_bg)
4805 {
4806 /* guess the value of 'background' */
4807#ifdef FEAT_GUI
4808 if (gui.in_use)
4809 newval = gui_bg_default();
4810 else
4811#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004812 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004813 }
4814
4815 /* expand environment variables and ~ (since the
4816 * default value was already expanded, only
4817 * required when an environment variable was set
4818 * later */
4819 if (newval == NULL)
4820 newval = empty_option;
4821 else
4822 {
4823 s = option_expand(opt_idx, newval);
4824 if (s == NULL)
4825 s = newval;
4826 newval = vim_strsave(s);
4827 }
4828 new_value_alloced = TRUE;
4829 }
4830 else if (nextchar == '<') /* set to global val */
4831 {
4832 newval = vim_strsave(*(char_u **)get_varp_scope(
4833 &(options[opt_idx]), OPT_GLOBAL));
4834 new_value_alloced = TRUE;
4835 }
4836 else
4837 {
4838 ++arg; /* jump to after the '=' or ':' */
4839
4840 /*
4841 * Set 'keywordprg' to ":help" if an empty
4842 * value was passed to :set by the user.
4843 * Misuse errbuf[] for the resulting string.
4844 */
4845 if (varp == (char_u *)&p_kp
4846 && (*arg == NUL || *arg == ' '))
4847 {
4848 STRCPY(errbuf, ":help");
4849 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004850 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004851 }
4852 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004853 * Convert 'backspace' number to string, for
4854 * adding, prepending and removing string.
4855 */
4856 else if (varp == (char_u *)&p_bs
4857 && VIM_ISDIGIT(**(char_u **)varp))
4858 {
4859 i = getdigits((char_u **)varp);
4860 switch (i)
4861 {
4862 case 0:
4863 *(char_u **)varp = empty_option;
4864 break;
4865 case 1:
4866 *(char_u **)varp = vim_strsave(
4867 (char_u *)"indent,eol");
4868 break;
4869 case 2:
4870 *(char_u **)varp = vim_strsave(
4871 (char_u *)"indent,eol,start");
4872 break;
4873 }
4874 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004875 if (origval == oldval)
4876 origval = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004877 oldval = *(char_u **)varp;
4878 }
4879 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004880 * Convert 'whichwrap' number to string, for
4881 * backwards compatibility with Vim 3.0.
4882 * Misuse errbuf[] for the resulting string.
4883 */
4884 else if (varp == (char_u *)&p_ww
4885 && VIM_ISDIGIT(*arg))
4886 {
4887 *errbuf = NUL;
4888 i = getdigits(&arg);
4889 if (i & 1)
4890 STRCAT(errbuf, "b,");
4891 if (i & 2)
4892 STRCAT(errbuf, "s,");
4893 if (i & 4)
4894 STRCAT(errbuf, "h,l,");
4895 if (i & 8)
4896 STRCAT(errbuf, "<,>,");
4897 if (i & 16)
4898 STRCAT(errbuf, "[,],");
4899 if (*errbuf != NUL) /* remove trailing , */
4900 errbuf[STRLEN(errbuf) - 1] = NUL;
4901 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004902 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004903 }
4904 /*
4905 * Remove '>' before 'dir' and 'bdir', for
4906 * backwards compatibility with version 3.0
4907 */
4908 else if ( *arg == '>'
4909 && (varp == (char_u *)&p_dir
4910 || varp == (char_u *)&p_bdir))
4911 {
4912 ++arg;
4913 }
4914
Bram Moolenaar071d4272004-06-13 20:20:40 +00004915 /*
4916 * Copy the new string into allocated memory.
4917 * Can't use set_string_option_direct(), because
4918 * we need to remove the backslashes.
4919 */
4920 /* get a bit too much */
4921 newlen = (unsigned)STRLEN(arg) + 1;
4922 if (adding || prepending || removing)
4923 newlen += (unsigned)STRLEN(origval) + 1;
4924 newval = alloc(newlen);
4925 if (newval == NULL) /* out of mem, don't change */
4926 break;
4927 s = newval;
4928
4929 /*
4930 * Copy the string, skip over escaped chars.
4931 * For MS-DOS and WIN32 backslashes before normal
4932 * file name characters are not removed, and keep
4933 * backslash at start, for "\\machine\path", but
4934 * do remove it for "\\\\machine\\path".
4935 * The reverse is found in ExpandOldSetting().
4936 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004937 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004938 {
4939 if (*arg == '\\' && arg[1] != NUL
4940#ifdef BACKSLASH_IN_FILENAME
4941 && !((flags & P_EXPAND)
4942 && vim_isfilec(arg[1])
4943 && (arg[1] != '\\'
4944 || (s == newval
4945 && arg[2] != '\\')))
4946#endif
4947 )
4948 ++arg; /* remove backslash */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004949 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004950 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004951 {
4952 /* copy multibyte char */
4953 mch_memmove(s, arg, (size_t)i);
4954 arg += i;
4955 s += i;
4956 }
4957 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004958 *s++ = *arg++;
4959 }
4960 *s = NUL;
4961
4962 /*
4963 * Expand environment variables and ~.
4964 * Don't do it when adding without inserting a
4965 * comma.
4966 */
4967 if (!(adding || prepending || removing)
4968 || (flags & P_COMMA))
4969 {
4970 s = option_expand(opt_idx, newval);
4971 if (s != NULL)
4972 {
4973 vim_free(newval);
4974 newlen = (unsigned)STRLEN(s) + 1;
4975 if (adding || prepending || removing)
4976 newlen += (unsigned)STRLEN(origval) + 1;
4977 newval = alloc(newlen);
4978 if (newval == NULL)
4979 break;
4980 STRCPY(newval, s);
4981 }
4982 }
4983
4984 /* locate newval[] in origval[] when removing it
4985 * and when adding to avoid duplicates */
4986 i = 0; /* init for GCC */
4987 if (removing || (flags & P_NODUP))
4988 {
4989 i = (int)STRLEN(newval);
4990 bs = 0;
4991 for (s = origval; *s; ++s)
4992 {
4993 if ((!(flags & P_COMMA)
4994 || s == origval
4995 || (s[-1] == ',' && !(bs & 1)))
4996 && STRNCMP(s, newval, i) == 0
4997 && (!(flags & P_COMMA)
4998 || s[i] == ','
4999 || s[i] == NUL))
5000 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005001 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005002 * even number of backslashes or a single
5003 * backslash preceded by a comma before it
5004 * is recognized as a separator */
5005 if ((s > origval + 1
5006 && s[-1] == '\\'
5007 && s[-2] != ',')
5008 || (s == origval + 1
5009 && s[-1] == '\\'))
5010
Bram Moolenaar071d4272004-06-13 20:20:40 +00005011 ++bs;
5012 else
5013 bs = 0;
5014 }
5015
5016 /* do not add if already there */
5017 if ((adding || prepending) && *s)
5018 {
5019 prepending = FALSE;
5020 adding = FALSE;
5021 STRCPY(newval, origval);
5022 }
5023 }
5024
5025 /* concatenate the two strings; add a ',' if
5026 * needed */
5027 if (adding || prepending)
5028 {
5029 comma = ((flags & P_COMMA) && *origval != NUL
5030 && *newval != NUL);
5031 if (adding)
5032 {
5033 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005034 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005035 if (comma && i > 1
5036 && (flags & P_ONECOMMA) == P_ONECOMMA
5037 && origval[i - 1] == ','
5038 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005039 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005040 mch_memmove(newval + i + comma, newval,
5041 STRLEN(newval) + 1);
5042 mch_memmove(newval, origval, (size_t)i);
5043 }
5044 else
5045 {
5046 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005047 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005048 }
5049 if (comma)
5050 newval[i] = ',';
5051 }
5052
5053 /* Remove newval[] from origval[]. (Note: "i" has
5054 * been set above and is used here). */
5055 if (removing)
5056 {
5057 STRCPY(newval, origval);
5058 if (*s)
5059 {
5060 /* may need to remove a comma */
5061 if (flags & P_COMMA)
5062 {
5063 if (s == origval)
5064 {
5065 /* include comma after string */
5066 if (s[i] == ',')
5067 ++i;
5068 }
5069 else
5070 {
5071 /* include comma before string */
5072 --s;
5073 ++i;
5074 }
5075 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005076 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005077 }
5078 }
5079
5080 if (flags & P_FLAGLIST)
5081 {
5082 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005083 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005084 {
5085 /* if options have P_FLAGLIST and
5086 * P_ONECOMMA such as 'whichwrap' */
5087 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005088 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005089 if (*s != ',' && *(s + 1) == ','
5090 && vim_strchr(s + 2, *s) != NULL)
5091 {
5092 /* Remove the duplicated value and
5093 * the next comma. */
5094 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005095 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005096 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005097 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005098 else
5099 {
5100 if ((!(flags & P_COMMA) || *s != ',')
5101 && vim_strchr(s + 1, *s) != NULL)
5102 {
5103 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005104 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005105 }
5106 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005107 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005108 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005109 }
5110
5111 if (save_arg != NULL) /* number for 'whichwrap' */
5112 arg = save_arg;
5113 new_value_alloced = TRUE;
5114 }
5115
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005116 /*
5117 * Set the new value.
5118 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005119 *(char_u **)(varp) = newval;
5120
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005121#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005122 if (!starting
5123# ifdef FEAT_CRYPT
5124 && options[opt_idx].indir != PV_KEY
5125# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005126 && origval != NULL && newval != NULL)
5127 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005128 /* origval may be freed by
5129 * did_set_string_option(), make a copy. */
5130 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005131 /* newval (and varp) may become invalid if the
5132 * buffer is closed by autocommands. */
5133 saved_newval = vim_strsave(newval);
5134 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005135#endif
5136
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005137 {
5138 long_u *p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005139 int secure_saved = secure;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005140
5141 // When an option is set in the sandbox, from a
5142 // modeline or in secure mode, then deal with side
5143 // effects in secure mode. Also when the value was
5144 // set with the P_INSECURE flag and is not
5145 // completely replaced.
5146 if (secure
5147#ifdef HAVE_SANDBOX
5148 || sandbox != 0
5149#endif
5150 || (opt_flags & OPT_MODELINE)
5151 || (!value_is_replaced && (*p & P_INSECURE)))
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005152 ++secure;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005153
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005154 // Handle side effects, and set the global value
5155 // for ":set" on local options. Note: when setting
5156 // 'syntax' or 'filetype' autocommands may be
5157 // triggered that can cause havoc.
5158 errmsg = did_set_string_option(
5159 opt_idx, (char_u **)varp,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005160 new_value_alloced, oldval, errbuf,
5161 opt_flags, &value_checked);
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005162
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005163 secure = secure_saved;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005164 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005165
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005166#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005167 if (errmsg == NULL)
5168 trigger_optionsset_string(opt_idx, opt_flags,
5169 saved_origval, saved_newval);
5170 vim_free(saved_origval);
5171 vim_free(saved_newval);
5172#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005173 /* If error detected, print the error message. */
5174 if (errmsg != NULL)
5175 goto skip;
5176 }
5177 else /* key code option */
5178 {
5179 char_u *p;
5180
5181 if (nextchar == '&')
5182 {
5183 if (add_termcap_entry(key_name, TRUE) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005184 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005185 }
5186 else
5187 {
5188 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005189 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005190 if (*p == '\\' && p[1] != NUL)
5191 ++p;
5192 nextchar = *p;
5193 *p = NUL;
5194 add_termcode(key_name, arg, FALSE);
5195 *p = nextchar;
5196 }
5197 if (full_screen)
5198 ttest(FALSE);
5199 redraw_all_later(CLEAR);
5200 }
5201 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005202
Bram Moolenaar071d4272004-06-13 20:20:40 +00005203 if (opt_idx >= 0)
Bram Moolenaar916a8182018-11-25 02:18:29 +01005204 did_set_option(
5205 opt_idx, opt_flags, value_is_replaced, value_checked);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005206 }
5207
5208skip:
5209 /*
5210 * Advance to next argument.
5211 * - skip until a blank found, taking care of backslashes
5212 * - skip blanks
5213 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5214 */
5215 for (i = 0; i < 2 ; ++i)
5216 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005217 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005218 if (*arg++ == '\\' && *arg != NUL)
5219 ++arg;
5220 arg = skipwhite(arg);
5221 if (*arg != '=')
5222 break;
5223 }
5224 }
5225
5226 if (errmsg != NULL)
5227 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005228 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005229 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005230 if (i + (arg - startarg) < IOSIZE)
5231 {
5232 /* append the argument with the error */
5233 STRCAT(IObuff, ": ");
5234 mch_memmove(IObuff + i, startarg, (arg - startarg));
5235 IObuff[i + (arg - startarg)] = NUL;
5236 }
5237 /* make sure all characters are printable */
5238 trans_characters(IObuff, IOSIZE);
5239
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005240 ++no_wait_return; // wait_return done later
5241 emsg((char *)IObuff); // show error highlighted
Bram Moolenaar071d4272004-06-13 20:20:40 +00005242 --no_wait_return;
5243
5244 return FAIL;
5245 }
5246
5247 arg = skipwhite(arg);
5248 }
5249
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005250theend:
5251 if (silent_mode && did_show)
5252 {
5253 /* After displaying option values in silent mode. */
5254 silent_mode = FALSE;
5255 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5256 msg_putchar('\n');
5257 cursor_on(); /* msg_start() switches it off */
5258 out_flush();
5259 silent_mode = TRUE;
5260 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5261 }
5262
Bram Moolenaar071d4272004-06-13 20:20:40 +00005263 return OK;
5264}
5265
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005266/*
5267 * Call this when an option has been given a new value through a user command.
5268 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5269 */
5270 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005271did_set_option(
5272 int opt_idx,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005273 int opt_flags, // possibly with OPT_MODELINE
5274 int new_value, // value was replaced completely
5275 int value_checked) // value was checked to be safe, no need to set the
5276 // P_INSECURE flag.
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005277{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005278 long_u *p;
5279
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005280 options[opt_idx].flags |= P_WAS_SET;
5281
5282 /* When an option is set in the sandbox, from a modeline or in secure mode
5283 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005284 * flag. */
5285 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar916a8182018-11-25 02:18:29 +01005286 if (!value_checked && (secure
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005287#ifdef HAVE_SANDBOX
5288 || sandbox != 0
5289#endif
Bram Moolenaar916a8182018-11-25 02:18:29 +01005290 || (opt_flags & OPT_MODELINE)))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005291 *p = *p | P_INSECURE;
5292 else if (new_value)
5293 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005294}
5295
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005296 static char *
5297illegal_char(char *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005298{
5299 if (errbuf == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005300 return "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00005301 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005302 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005303 return errbuf;
5304}
5305
5306/*
5307 * Convert a key name or string into a key value.
5308 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005309 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005310 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005311 int
5312string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005313{
5314 if (*arg == '<')
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02005315 return find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005316 if (*arg == '^')
5317 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005318 if (multi_byte)
5319 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005320 return *arg;
5321}
5322
5323#ifdef FEAT_CMDWIN
5324/*
5325 * Check value of 'cedit' and set cedit_key.
5326 * Returns NULL if value is OK, error message otherwise.
5327 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005328 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005329check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005330{
5331 int n;
5332
5333 if (*p_cedit == NUL)
5334 cedit_key = -1;
5335 else
5336 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005337 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005338 if (vim_isprintc(n))
5339 return e_invarg;
5340 cedit_key = n;
5341 }
5342 return NULL;
5343}
5344#endif
5345
5346#ifdef FEAT_TITLE
5347/*
5348 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5349 * maketitle() to create and display it.
5350 * When switching the title or icon off, call mch_restore_title() to get
5351 * the old value back.
5352 */
5353 static void
Bram Moolenaar84a93082018-06-16 22:58:15 +02005354did_set_title(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005355{
5356 if (starting != NO_SCREEN
5357#ifdef FEAT_GUI
5358 && !gui.starting
5359#endif
5360 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00005361 maketitle();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005362}
5363#endif
5364
5365/*
5366 * set_options_bin - called when 'bin' changes value.
5367 */
5368 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005369set_options_bin(
5370 int oldval,
5371 int newval,
5372 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005373{
5374 /*
5375 * The option values that are changed when 'bin' changes are
5376 * copied when 'bin is set and restored when 'bin' is reset.
5377 */
5378 if (newval)
5379 {
5380 if (!oldval) /* switched on */
5381 {
5382 if (!(opt_flags & OPT_GLOBAL))
5383 {
5384 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5385 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5386 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5387 curbuf->b_p_et_nobin = curbuf->b_p_et;
5388 }
5389 if (!(opt_flags & OPT_LOCAL))
5390 {
5391 p_tw_nobin = p_tw;
5392 p_wm_nobin = p_wm;
5393 p_ml_nobin = p_ml;
5394 p_et_nobin = p_et;
5395 }
5396 }
5397
5398 if (!(opt_flags & OPT_GLOBAL))
5399 {
5400 curbuf->b_p_tw = 0; /* no automatic line wrap */
5401 curbuf->b_p_wm = 0; /* no automatic line wrap */
5402 curbuf->b_p_ml = 0; /* no modelines */
5403 curbuf->b_p_et = 0; /* no expandtab */
5404 }
5405 if (!(opt_flags & OPT_LOCAL))
5406 {
5407 p_tw = 0;
5408 p_wm = 0;
5409 p_ml = FALSE;
5410 p_et = FALSE;
5411 p_bin = TRUE; /* needed when called for the "-b" argument */
5412 }
5413 }
5414 else if (oldval) /* switched off */
5415 {
5416 if (!(opt_flags & OPT_GLOBAL))
5417 {
5418 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5419 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5420 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5421 curbuf->b_p_et = curbuf->b_p_et_nobin;
5422 }
5423 if (!(opt_flags & OPT_LOCAL))
5424 {
5425 p_tw = p_tw_nobin;
5426 p_wm = p_wm_nobin;
5427 p_ml = p_ml_nobin;
5428 p_et = p_et_nobin;
5429 }
5430 }
5431}
5432
5433#ifdef FEAT_VIMINFO
5434/*
5435 * Find the parameter represented by the given character (eg ', :, ", or /),
5436 * and return its associated value in the 'viminfo' string.
5437 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005438 * If the parameter is not specified in the string or there is no following
5439 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005440 */
5441 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005442get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005443{
5444 char_u *p;
5445
5446 p = find_viminfo_parameter(type);
5447 if (p != NULL && VIM_ISDIGIT(*p))
5448 return atoi((char *)p);
5449 return -1;
5450}
5451
5452/*
5453 * Find the parameter represented by the given character (eg ''', ':', '"', or
5454 * '/') in the 'viminfo' option and return a pointer to the string after it.
5455 * Return NULL if the parameter is not specified in the string.
5456 */
5457 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005458find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005459{
5460 char_u *p;
5461
5462 for (p = p_viminfo; *p; ++p)
5463 {
5464 if (*p == type)
5465 return p + 1;
5466 if (*p == 'n') /* 'n' is always the last one */
5467 break;
5468 p = vim_strchr(p, ','); /* skip until next ',' */
5469 if (p == NULL) /* hit the end without finding parameter */
5470 break;
5471 }
5472 return NULL;
5473}
5474#endif
5475
5476/*
5477 * Expand environment variables for some string options.
5478 * These string options cannot be indirect!
5479 * If "val" is NULL expand the current value of the option.
5480 * Return pointer to NameBuff, or NULL when not expanded.
5481 */
5482 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005483option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005484{
5485 /* if option doesn't need expansion nothing to do */
5486 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5487 return NULL;
5488
5489 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5490 * expand_env() would truncate the string. */
5491 if (val != NULL && STRLEN(val) > MAXPATHL)
5492 return NULL;
5493
5494 if (val == NULL)
5495 val = *(char_u **)options[opt_idx].var;
5496
5497 /*
5498 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5499 * Escape spaces when expanding 'tags', they are used to separate file
5500 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005501 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005502 */
5503 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005504 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005505#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005506 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5507#endif
5508 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005509 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5510 return NULL;
5511
5512 return NameBuff;
5513}
5514
5515/*
5516 * After setting various option values: recompute variables that depend on
5517 * option values.
5518 */
5519 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005520didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005521{
5522 /* initialize the table for 'iskeyword' et.al. */
5523 (void)init_chartab();
5524
5525 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
5526 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005527 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005528#ifdef FEAT_SESSION
5529 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5530 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5531#endif
5532#ifdef FEAT_FOLDING
5533 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5534#endif
5535 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005536 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005537 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005538#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5539 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5540#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005541#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005542 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005543 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005544 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005545 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005546#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005547#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5548 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5549#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005550#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005551 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5552#endif
5553#ifdef FEAT_CMDWIN
5554 /* set cedit_key */
5555 (void)check_cedit();
5556#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005557#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005558 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005559#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005560#ifdef FEAT_LINEBREAK
5561 /* initialize the table for 'breakat'. */
5562 fill_breakat_flags();
5563#endif
5564
5565}
5566
5567/*
5568 * More side effects of setting options.
5569 */
5570 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005571didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005572{
5573 /* Initialize the highlight_attr[] table. */
5574 (void)highlight_changed();
5575
5576 /* Parse default for 'wildmode' */
5577 check_opt_wim();
5578
5579 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005580 /* Parse default for 'fillchars'. */
5581 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005582
5583#ifdef FEAT_CLIPBOARD
5584 /* Parse default for 'clipboard' */
5585 (void)check_clipboard_option();
5586#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005587#ifdef FEAT_VARTABS
5588 tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_array);
5589 tabstop_set(curbuf->b_p_vts, &curbuf->b_p_vts_array);
5590#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005591}
5592
5593/*
5594 * Check for string options that are NULL (normally only termcap options).
5595 */
5596 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005597check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005598{
5599 int opt_idx;
5600
5601 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5602 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5603 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5604}
5605
5606/*
5607 * Check string options in a buffer for NULL value.
5608 */
5609 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005610check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005611{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005612 check_string_option(&buf->b_p_bh);
5613 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005614 check_string_option(&buf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005615 check_string_option(&buf->b_p_ff);
5616#ifdef FEAT_FIND_ID
5617 check_string_option(&buf->b_p_def);
5618 check_string_option(&buf->b_p_inc);
5619# ifdef FEAT_EVAL
5620 check_string_option(&buf->b_p_inex);
5621# endif
5622#endif
5623#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5624 check_string_option(&buf->b_p_inde);
5625 check_string_option(&buf->b_p_indk);
5626#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005627#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5628 check_string_option(&buf->b_p_bexpr);
5629#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005630#if defined(FEAT_CRYPT)
5631 check_string_option(&buf->b_p_cm);
5632#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005633 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005634#if defined(FEAT_EVAL)
5635 check_string_option(&buf->b_p_fex);
5636#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005637#ifdef FEAT_CRYPT
5638 check_string_option(&buf->b_p_key);
5639#endif
5640 check_string_option(&buf->b_p_kp);
5641 check_string_option(&buf->b_p_mps);
5642 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005643 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005644 check_string_option(&buf->b_p_isk);
5645#ifdef FEAT_COMMENTS
5646 check_string_option(&buf->b_p_com);
5647#endif
5648#ifdef FEAT_FOLDING
5649 check_string_option(&buf->b_p_cms);
5650#endif
5651 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005652#ifdef FEAT_TEXTOBJ
5653 check_string_option(&buf->b_p_qe);
5654#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005655#ifdef FEAT_SYN_HL
5656 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005657 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005658#endif
5659#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005660 check_string_option(&buf->b_s.b_p_spc);
5661 check_string_option(&buf->b_s.b_p_spf);
5662 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005663#endif
5664#ifdef FEAT_SEARCHPATH
5665 check_string_option(&buf->b_p_sua);
5666#endif
5667#ifdef FEAT_CINDENT
5668 check_string_option(&buf->b_p_cink);
5669 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005670 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005671#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005672 check_string_option(&buf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005673#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5674 check_string_option(&buf->b_p_cinw);
5675#endif
5676#ifdef FEAT_INS_EXPAND
5677 check_string_option(&buf->b_p_cpt);
5678#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005679#ifdef FEAT_COMPL_FUNC
5680 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005681 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005682#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005683#ifdef FEAT_KEYMAP
5684 check_string_option(&buf->b_p_keymap);
5685#endif
5686#ifdef FEAT_QUICKFIX
5687 check_string_option(&buf->b_p_gp);
5688 check_string_option(&buf->b_p_mp);
5689 check_string_option(&buf->b_p_efm);
5690#endif
5691 check_string_option(&buf->b_p_ep);
5692 check_string_option(&buf->b_p_path);
5693 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005694 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005695#ifdef FEAT_INS_EXPAND
5696 check_string_option(&buf->b_p_dict);
5697 check_string_option(&buf->b_p_tsr);
5698#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005699#ifdef FEAT_LISP
5700 check_string_option(&buf->b_p_lw);
5701#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005702 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005703 check_string_option(&buf->b_p_menc);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005704#ifdef FEAT_VARTABS
5705 check_string_option(&buf->b_p_vsts);
5706 check_string_option(&buf->b_p_vts);
5707#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005708}
5709
5710/*
5711 * Free the string allocated for an option.
5712 * Checks for the string being empty_option. This may happen if we're out of
5713 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5714 * check_options().
5715 * Does NOT check for P_ALLOCED flag!
5716 */
5717 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005718free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005719{
5720 if (p != empty_option)
5721 vim_free(p);
5722}
5723
5724 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005725clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005726{
5727 if (*pp != empty_option)
5728 vim_free(*pp);
5729 *pp = empty_option;
5730}
5731
5732 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005733check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005734{
5735 if (*pp == NULL)
5736 *pp = empty_option;
5737}
5738
5739/*
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005740 * Return the option index found by a pointer into term_strings[].
5741 * Return -1 if not found.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005742 */
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005743 int
5744get_term_opt_idx(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005745{
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005746 int opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005747
5748 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5749 if (options[opt_idx].var == (char_u *)p)
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005750 return opt_idx;
5751 return -1; // cannot happen: didn't find it!
5752}
5753
5754/*
5755 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5756 * Return the option index or -1 if not found.
5757 */
5758 int
5759set_term_option_alloced(char_u **p)
5760{
5761 int opt_idx = get_term_opt_idx(p);
5762
5763 if (opt_idx >= 0)
5764 options[opt_idx].flags |= P_ALLOCED;
5765 return opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005766}
5767
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005768#if defined(FEAT_EVAL) || defined(PROTO)
5769/*
5770 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5771 * Return FALSE when it wasn't.
5772 * Return -1 for an unknown option.
5773 */
5774 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005775was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005776{
5777 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005778 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005779
5780 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005781 {
5782 flagp = insecure_flag(idx, opt_flags);
5783 return (*flagp & P_INSECURE) != 0;
5784 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005785 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005786 return -1;
5787}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005788
5789/*
5790 * Get a pointer to the flags used for the P_INSECURE flag of option
5791 * "opt_idx". For some local options a local flags field is used.
5792 */
5793 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005794insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005795{
5796 if (opt_flags & OPT_LOCAL)
5797 switch ((int)options[opt_idx].indir)
5798 {
5799#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005800 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005801#endif
5802#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005803# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005804 case PV_FDE: return &curwin->w_p_fde_flags;
5805 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005806# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005807# ifdef FEAT_BEVAL
5808 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5809# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005810# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005811 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005812# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005813 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005814# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005815 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005816# endif
5817#endif
5818 }
5819
5820 /* Nothing special, return global flags field. */
5821 return &options[opt_idx].flags;
5822}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005823#endif
5824
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005825#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005826/*
5827 * Redraw the window title and/or tab page text later.
5828 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005829static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005830{
5831 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005832 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005833}
5834#endif
5835
Bram Moolenaar071d4272004-06-13 20:20:40 +00005836/*
5837 * Set a string option to a new value (without checking the effect).
5838 * The string is copied into allocated memory.
5839 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005840 * When "set_sid" is zero set the scriptID to current_sctx.sc_sid. When
5841 * "set_sid" is SID_NONE don't set the scriptID. Otherwise set the scriptID to
5842 * "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005843 */
5844 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005845set_string_option_direct(
5846 char_u *name,
5847 int opt_idx,
5848 char_u *val,
5849 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5850 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005851{
5852 char_u *s;
5853 char_u **varp;
5854 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005855 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005856
Bram Moolenaar89d40322006-08-29 15:30:07 +00005857 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005858 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005859 idx = findoption(name);
5860 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005861 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005862 semsg(_(e_intern2), "set_string_option_direct()");
5863 siemsg(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005864 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005865 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005866 }
5867
Bram Moolenaar89d40322006-08-29 15:30:07 +00005868 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005869 return;
5870
5871 s = vim_strsave(val);
5872 if (s != NULL)
5873 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005874 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005875 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005876 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005877 free_string_option(*varp);
5878 *varp = s;
5879
5880 /* For buffer/window local option may also set the global value. */
5881 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005882 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005883
Bram Moolenaar89d40322006-08-29 15:30:07 +00005884 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005885
5886 /* When setting both values of a global option with a local value,
5887 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005888 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005889 {
5890 free_string_option(*varp);
5891 *varp = empty_option;
5892 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005893# ifdef FEAT_EVAL
5894 if (set_sid != SID_NONE)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005895 {
5896 sctx_T script_ctx;
5897
5898 if (set_sid == 0)
5899 script_ctx = current_sctx;
5900 else
5901 {
5902 script_ctx.sc_sid = set_sid;
Bram Moolenaarded5f1b2018-11-10 17:33:29 +01005903 script_ctx.sc_seq = 0;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005904 script_ctx.sc_lnum = 0;
5905 }
5906 set_option_sctx_idx(idx, opt_flags, script_ctx);
5907 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005908# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005909 }
5910}
5911
5912/*
5913 * Set global value for string option when it's a local option.
5914 */
5915 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005916set_string_option_global(
5917 int opt_idx, /* option index */
5918 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005919{
5920 char_u **p, *s;
5921
5922 /* the global value is always allocated */
5923 if (options[opt_idx].var == VAR_WIN)
5924 p = (char_u **)GLOBAL_WO(varp);
5925 else
5926 p = (char_u **)options[opt_idx].var;
5927 if (options[opt_idx].indir != PV_NONE
5928 && p != varp
5929 && (s = vim_strsave(*varp)) != NULL)
5930 {
5931 free_string_option(*p);
5932 *p = s;
5933 }
5934}
5935
5936/*
5937 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005938 *
5939 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005940 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005941 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005942set_string_option(
5943 int opt_idx,
5944 char_u *value,
5945 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005946{
5947 char_u *s;
5948 char_u **varp;
5949 char_u *oldval;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005950#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02005951 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005952 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02005953#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005954 char *r = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01005955 int value_checked = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005956
5957 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005958 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005959
5960 s = vim_strsave(value);
5961 if (s != NULL)
5962 {
5963 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5964 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005965 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005966 ? OPT_GLOBAL : OPT_LOCAL)
5967 : opt_flags);
5968 oldval = *varp;
5969 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005970
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005971#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005972 if (!starting
5973# ifdef FEAT_CRYPT
5974 && options[opt_idx].indir != PV_KEY
5975# endif
5976 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005977 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005978 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005979 saved_newval = vim_strsave(s);
5980 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005981#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005982 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005983 opt_flags, &value_checked)) == NULL)
5984 did_set_option(opt_idx, opt_flags, TRUE, value_checked);
Bram Moolenaar53744302015-07-17 17:38:22 +02005985
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005986#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005987 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005988 if (r == NULL)
5989 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005990 saved_oldval, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005991 vim_free(saved_oldval);
5992 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02005993#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005994 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005995 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005996}
5997
5998/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01005999 * Return TRUE if "val" is a valid 'filetype' name.
6000 * Also used for 'syntax' and 'keymap'.
6001 */
6002 static int
6003valid_filetype(char_u *val)
6004{
6005 char_u *s;
6006
6007 for (s = val; *s != NUL; ++s)
6008 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
6009 return FALSE;
6010 return TRUE;
6011}
6012
6013/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006014 * Handle string options that need some action to perform when changed.
6015 * Returns NULL for success, or an error message for an error.
6016 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006017 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006018did_set_string_option(
Bram Moolenaar916a8182018-11-25 02:18:29 +01006019 int opt_idx, // index in options[] table
6020 char_u **varp, // pointer to the option variable
6021 int new_value_alloced, // new value was allocated
6022 char_u *oldval, // previous value of the option
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006023 char *errbuf, // buffer for errors, or NULL
Bram Moolenaar916a8182018-11-25 02:18:29 +01006024 int opt_flags, // OPT_LOCAL and/or OPT_GLOBAL
6025 int *value_checked) // value was checked to be save, no
6026 // need to set P_INSECURE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006027{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006028 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006029 char_u *s, *p;
6030 int did_chartab = FALSE;
6031 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006032 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006033#ifdef FEAT_GUI
6034 /* set when changing an option that only requires a redraw in the GUI */
6035 int redraw_gui_only = FALSE;
6036#endif
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02006037 int value_changed = FALSE;
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006038#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6039 int did_swaptcap = FALSE;
6040#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006041
6042 /* Get the global option to compare with, otherwise we would have to check
6043 * two values for all local options. */
6044 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6045
6046 /* Disallow changing some options from secure mode */
6047 if ((secure
6048#ifdef HAVE_SANDBOX
6049 || sandbox != 0
6050#endif
6051 ) && (options[opt_idx].flags & P_SECURE))
6052 {
6053 errmsg = e_secure;
6054 }
6055
Bram Moolenaar916a8182018-11-25 02:18:29 +01006056 // Check for a "normal" directory or file name in some options. Disallow a
6057 // path separator (slash and/or backslash), wildcards and characters that
6058 // are often illegal in a file name. Be more permissive if "secure" is off.
Bram Moolenaar7554da42016-11-25 22:04:13 +01006059 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006060 && vim_strpbrk(*varp, (char_u *)(secure
6061 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006062 || ((options[opt_idx].flags & P_NDNAME)
6063 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006064 {
6065 errmsg = e_invarg;
6066 }
6067
Bram Moolenaar071d4272004-06-13 20:20:40 +00006068 /* 'term' */
6069 else if (varp == &T_NAME)
6070 {
6071 if (T_NAME[0] == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006072 errmsg = N_("E529: Cannot set 'term' to empty string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006073#ifdef FEAT_GUI
6074 if (gui.in_use)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006075 errmsg = N_("E530: Cannot change term in GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006076 else if (term_is_gui(T_NAME))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006077 errmsg = N_("E531: Use \":gui\" to start the GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006078#endif
6079 else if (set_termname(T_NAME) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006080 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006081 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006082 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006083 /* Screen colors may have changed. */
6084 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006085
6086 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6087 * P_ALLOCED flag on 'term'. */
6088 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006089 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006090 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006091 }
6092
6093 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006094 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006095 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006096 char_u *bkc = p_bkc;
6097 unsigned int *flags = &bkc_flags;
6098
6099 if (opt_flags & OPT_LOCAL)
6100 {
6101 bkc = curbuf->b_p_bkc;
6102 flags = &curbuf->b_bkc_flags;
6103 }
6104
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006105 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6106 /* make the local value empty: use the global value */
6107 *flags = 0;
6108 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006109 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006110 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6111 errmsg = e_invarg;
6112 if ((((int)*flags & BKC_AUTO) != 0)
6113 + (((int)*flags & BKC_YES) != 0)
6114 + (((int)*flags & BKC_NO) != 0) != 1)
6115 {
6116 /* Must have exactly one of "auto", "yes" and "no". */
6117 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6118 errmsg = e_invarg;
6119 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006120 }
6121 }
6122
6123 /* 'backupext' and 'patchmode' */
6124 else if (varp == &p_bex || varp == &p_pm)
6125 {
6126 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6127 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006128 errmsg = N_("E589: 'backupext' and 'patchmode' are equal");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006129 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006130#ifdef FEAT_LINEBREAK
6131 /* 'breakindentopt' */
6132 else if (varp == &curwin->w_p_briopt)
6133 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006134 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006135 errmsg = e_invarg;
6136 }
6137#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006138
6139 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006140 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006141 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006142 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006143 */
6144 else if ( varp == &p_isi
6145 || varp == &(curbuf->b_p_isk)
6146 || varp == &p_isp
6147 || varp == &p_isf)
6148 {
6149 if (init_chartab() == FAIL)
6150 {
6151 did_chartab = TRUE; /* need to restore it below */
6152 errmsg = e_invarg; /* error in value */
6153 }
6154 }
6155
6156 /* 'helpfile' */
6157 else if (varp == &p_hf)
6158 {
6159 /* May compute new values for $VIM and $VIMRUNTIME */
6160 if (didset_vim)
6161 {
6162 vim_setenv((char_u *)"VIM", (char_u *)"");
6163 didset_vim = FALSE;
6164 }
6165 if (didset_vimruntime)
6166 {
6167 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6168 didset_vimruntime = FALSE;
6169 }
6170 }
6171
Bram Moolenaar1a384422010-07-14 19:53:30 +02006172#ifdef FEAT_SYN_HL
6173 /* 'colorcolumn' */
6174 else if (varp == &curwin->w_p_cc)
6175 errmsg = check_colorcolumn(curwin);
6176#endif
6177
Bram Moolenaar071d4272004-06-13 20:20:40 +00006178#ifdef FEAT_MULTI_LANG
6179 /* 'helplang' */
6180 else if (varp == &p_hlg)
6181 {
6182 /* Check for "", "ab", "ab,cd", etc. */
6183 for (s = p_hlg; *s != NUL; s += 3)
6184 {
6185 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6186 {
6187 errmsg = e_invarg;
6188 break;
6189 }
6190 if (s[2] == NUL)
6191 break;
6192 }
6193 }
6194#endif
6195
6196 /* 'highlight' */
6197 else if (varp == &p_hl)
6198 {
6199 if (highlight_changed() == FAIL)
6200 errmsg = e_invarg; /* invalid flags */
6201 }
6202
6203 /* 'nrformats' */
6204 else if (gvarp == &p_nf)
6205 {
6206 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6207 errmsg = e_invarg;
6208 }
6209
6210#ifdef FEAT_SESSION
6211 /* 'sessionoptions' */
6212 else if (varp == &p_ssop)
6213 {
6214 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6215 errmsg = e_invarg;
6216 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6217 {
6218 /* Don't allow both "sesdir" and "curdir". */
6219 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6220 errmsg = e_invarg;
6221 }
6222 }
6223 /* 'viewoptions' */
6224 else if (varp == &p_vop)
6225 {
6226 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6227 errmsg = e_invarg;
6228 }
6229#endif
6230
6231 /* 'scrollopt' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006232 else if (varp == &p_sbo)
6233 {
6234 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6235 errmsg = e_invarg;
6236 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006237
6238 /* 'ambiwidth' */
Bram Moolenaar3848e002016-03-19 18:42:29 +01006239 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006240 {
6241 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6242 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006243 else if (set_chars_option(&p_lcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006244 errmsg = _("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006245 else if (set_chars_option(&p_fcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006246 errmsg = _("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006247 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006248
6249 /* 'background' */
6250 else if (varp == &p_bg)
6251 {
6252 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6253 {
6254#ifdef FEAT_EVAL
6255 int dark = (*p_bg == 'd');
6256#endif
6257
6258 init_highlight(FALSE, FALSE);
6259
6260#ifdef FEAT_EVAL
6261 if (dark != (*p_bg == 'd')
6262 && get_var_value((char_u *)"g:colors_name") != NULL)
6263 {
6264 /* The color scheme must have set 'background' back to another
6265 * value, that's not what we want here. Disable the color
6266 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006267 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006268 free_string_option(p_bg);
6269 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6270 check_string_option(&p_bg);
6271 init_highlight(FALSE, FALSE);
6272 }
6273#endif
6274 }
6275 else
6276 errmsg = e_invarg;
6277 }
6278
6279 /* 'wildmode' */
6280 else if (varp == &p_wim)
6281 {
6282 if (check_opt_wim() == FAIL)
6283 errmsg = e_invarg;
6284 }
6285
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006286#ifdef FEAT_CMDL_COMPL
6287 /* 'wildoptions' */
6288 else if (varp == &p_wop)
6289 {
6290 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6291 errmsg = e_invarg;
6292 }
6293#endif
6294
Bram Moolenaar071d4272004-06-13 20:20:40 +00006295#ifdef FEAT_WAK
6296 /* 'winaltkeys' */
6297 else if (varp == &p_wak)
6298 {
6299 if (*p_wak == NUL
6300 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6301 errmsg = e_invarg;
6302# ifdef FEAT_MENU
6303# ifdef FEAT_GUI_MOTIF
6304 else if (gui.in_use)
6305 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6306# else
6307# ifdef FEAT_GUI_GTK
6308 else if (gui.in_use)
6309 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6310# endif
6311# endif
6312# endif
6313 }
6314#endif
6315
Bram Moolenaar071d4272004-06-13 20:20:40 +00006316 /* 'eventignore' */
6317 else if (varp == &p_ei)
6318 {
6319 if (check_ei() == FAIL)
6320 errmsg = e_invarg;
6321 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006322
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006323 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6324 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6325 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006326 {
6327 if (gvarp == &p_fenc)
6328 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006329 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006330 errmsg = e_modifiable;
6331 else if (vim_strchr(*varp, ',') != NULL)
6332 /* No comma allowed in 'fileencoding'; catches confusing it
6333 * with 'fileencodings'. */
6334 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006335 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006336 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006337#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006338 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006339 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006340#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006341 /* Add 'fileencoding' to the swap file. */
6342 ml_setflags(curbuf);
6343 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006344 }
6345 if (errmsg == NULL)
6346 {
6347 /* canonize the value, so that STRCMP() can be used on it */
6348 p = enc_canonize(*varp);
6349 if (p != NULL)
6350 {
6351 vim_free(*varp);
6352 *varp = p;
6353 }
6354 if (varp == &p_enc)
6355 {
6356 errmsg = mb_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006357#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006358 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006359#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006360 }
6361 }
6362
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006363#if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006364 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6365 {
6366 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6367 if (STRCMP(p_tenc, "utf-8") != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006368 errmsg = N_("E617: Cannot be changed in the GTK+ 2 GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006369 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006370#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006371
6372 if (errmsg == NULL)
6373 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006374#ifdef FEAT_KEYMAP
Bram Moolenaar071d4272004-06-13 20:20:40 +00006375 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6376 * (with another encoding). */
6377 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6378 (void)keymap_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006379#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006380
6381 /* When 'termencoding' is not empty and 'encoding' changes or when
6382 * 'termencoding' changes, need to setup for keyboard input and
6383 * display output conversion. */
6384 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6385 {
Bram Moolenaar17471e82017-11-26 23:47:18 +01006386 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6387 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6388 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006389 semsg(_("E950: Cannot convert between %s and %s"),
Bram Moolenaar17471e82017-11-26 23:47:18 +01006390 p_tenc, p_enc);
6391 errmsg = e_invarg;
6392 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006393 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006394
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006395#if defined(WIN3264)
Bram Moolenaar05159a02005-02-26 23:04:13 +00006396 /* $HOME may have characters in active code page. */
6397 if (varp == &p_enc)
6398 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006399#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006400 }
6401 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006402
6403#if defined(FEAT_POSTSCRIPT)
6404 else if (varp == &p_penc)
6405 {
6406 /* Canonize printencoding if VIM standard one */
6407 p = enc_canonize(p_penc);
6408 if (p != NULL)
6409 {
6410 vim_free(p_penc);
6411 p_penc = p;
6412 }
6413 else
6414 {
6415 /* Ensure lower case and '-' for '_' */
6416 for (s = p_penc; *s != NUL; s++)
6417 {
6418 if (*s == '_')
6419 *s = '-';
6420 else
6421 *s = TOLOWER_ASC(*s);
6422 }
6423 }
6424 }
6425#endif
6426
Bram Moolenaar9372a112005-12-06 19:59:18 +00006427#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006428 else if (varp == &p_imak)
6429 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006430 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006431 errmsg = e_invarg;
6432 }
6433#endif
6434
6435#ifdef FEAT_KEYMAP
6436 else if (varp == &curbuf->b_p_keymap)
6437 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006438 if (!valid_filetype(*varp))
6439 errmsg = e_invarg;
6440 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01006441 {
6442 int secure_save = secure;
6443
6444 // Reset the secure flag, since the value of 'keymap' has
6445 // been checked to be safe.
6446 secure = 0;
6447
6448 // load or unload key mapping tables
Bram Moolenaard0b51382016-11-04 15:23:45 +01006449 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006450
Bram Moolenaar916a8182018-11-25 02:18:29 +01006451 secure = secure_save;
6452
6453 // Since we check the value, there is no need to set P_INSECURE,
6454 // even when the value comes from a modeline.
6455 *value_checked = TRUE;
6456 }
6457
Bram Moolenaarfab06232009-03-04 03:13:35 +00006458 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006459 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006460 if (*curbuf->b_p_keymap != NUL)
6461 {
6462 /* Installed a new keymap, switch on using it. */
6463 curbuf->b_p_iminsert = B_IMODE_LMAP;
6464 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6465 curbuf->b_p_imsearch = B_IMODE_LMAP;
6466 }
6467 else
6468 {
6469 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6470 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6471 curbuf->b_p_iminsert = B_IMODE_NONE;
6472 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6473 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6474 }
6475 if ((opt_flags & OPT_LOCAL) == 0)
6476 {
6477 set_iminsert_global();
6478 set_imsearch_global();
6479 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006480 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006481 }
6482 }
6483#endif
6484
6485 /* 'fileformat' */
6486 else if (gvarp == &p_ff)
6487 {
6488 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6489 errmsg = e_modifiable;
6490 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6491 errmsg = e_invarg;
6492 else
6493 {
6494 /* may also change 'textmode' */
6495 if (get_fileformat(curbuf) == EOL_DOS)
6496 curbuf->b_p_tx = TRUE;
6497 else
6498 curbuf->b_p_tx = FALSE;
6499#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006500 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006501#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006502 /* update flag in swap file */
6503 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006504 /* Redraw needed when switching to/from "mac": a CR in the text
6505 * will be displayed differently. */
6506 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6507 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006508 }
6509 }
6510
6511 /* 'fileformats' */
6512 else if (varp == &p_ffs)
6513 {
6514 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6515 errmsg = e_invarg;
6516 else
6517 {
6518 /* also change 'textauto' */
6519 if (*p_ffs == NUL)
6520 p_ta = FALSE;
6521 else
6522 p_ta = TRUE;
6523 }
6524 }
6525
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006526#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006527 /* 'cryptkey' */
6528 else if (gvarp == &p_key)
6529 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006530# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006531 /* Make sure the ":set" command doesn't show the new value in the
6532 * history. */
6533 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006534# endif
6535 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6536 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006537 ml_set_crypt_key(curbuf, oldval,
6538 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006539 }
6540
6541 else if (gvarp == &p_cm)
6542 {
6543 if (opt_flags & OPT_LOCAL)
6544 p = curbuf->b_p_cm;
6545 else
6546 p = p_cm;
6547 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6548 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006549 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006550 errmsg = e_invarg;
6551 else
6552 {
6553 /* When setting the global value to empty, make it "zip". */
6554 if (*p_cm == NUL)
6555 {
6556 if (new_value_alloced)
6557 free_string_option(p_cm);
6558 p_cm = vim_strsave((char_u *)"zip");
6559 new_value_alloced = TRUE;
6560 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006561 /* When using ":set cm=name" the local value is going to be empty.
6562 * Do that here, otherwise the crypt functions will still use the
6563 * local value. */
6564 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6565 {
6566 free_string_option(curbuf->b_p_cm);
6567 curbuf->b_p_cm = empty_option;
6568 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006569
6570 /* Need to update the swapfile when the effective method changed.
6571 * Set "s" to the effective old value, "p" to the effective new
6572 * method and compare. */
6573 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6574 s = p_cm; /* was previously using the global value */
6575 else
6576 s = oldval;
6577 if (*curbuf->b_p_cm == NUL)
6578 p = p_cm; /* is now using the global value */
6579 else
6580 p = curbuf->b_p_cm;
6581 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006582 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006583
6584 /* If the global value changes need to update the swapfile for all
6585 * buffers using that value. */
6586 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6587 {
6588 buf_T *buf;
6589
Bram Moolenaar29323592016-07-24 22:04:11 +02006590 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006591 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006592 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006593 }
6594 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006595 }
6596#endif
6597
6598 /* 'matchpairs' */
6599 else if (gvarp == &p_mps)
6600 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006601 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006602 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006603 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006604 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006605 int x2 = -1;
6606 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006607
6608 if (*p != NUL)
6609 p += mb_ptr2len(p);
6610 if (*p != NUL)
6611 x2 = *p++;
6612 if (*p != NUL)
6613 {
6614 x3 = mb_ptr2char(p);
6615 p += mb_ptr2len(p);
6616 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006617 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006618 {
6619 errmsg = e_invarg;
6620 break;
6621 }
6622 if (*p == NUL)
6623 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006624 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006625 }
6626 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006627 {
6628 /* Check for "x:y,x:y" */
6629 for (p = *varp; *p != NUL; p += 4)
6630 {
6631 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6632 {
6633 errmsg = e_invarg;
6634 break;
6635 }
6636 if (p[3] == NUL)
6637 break;
6638 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006639 }
6640 }
6641
6642#ifdef FEAT_COMMENTS
6643 /* 'comments' */
6644 else if (gvarp == &p_com)
6645 {
6646 for (s = *varp; *s; )
6647 {
6648 while (*s && *s != ':')
6649 {
6650 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6651 && !VIM_ISDIGIT(*s) && *s != '-')
6652 {
6653 errmsg = illegal_char(errbuf, *s);
6654 break;
6655 }
6656 ++s;
6657 }
6658 if (*s++ == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006659 errmsg = N_("E524: Missing colon");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006660 else if (*s == ',' || *s == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006661 errmsg = N_("E525: Zero length string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006662 if (errmsg != NULL)
6663 break;
6664 while (*s && *s != ',')
6665 {
6666 if (*s == '\\' && s[1] != NUL)
6667 ++s;
6668 ++s;
6669 }
6670 s = skip_to_option_part(s);
6671 }
6672 }
6673#endif
6674
6675 /* 'listchars' */
6676 else if (varp == &p_lcs)
6677 {
6678 errmsg = set_chars_option(varp);
6679 }
6680
Bram Moolenaar071d4272004-06-13 20:20:40 +00006681 /* 'fillchars' */
6682 else if (varp == &p_fcs)
6683 {
6684 errmsg = set_chars_option(varp);
6685 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006686
6687#ifdef FEAT_CMDWIN
6688 /* 'cedit' */
6689 else if (varp == &p_cedit)
6690 {
6691 errmsg = check_cedit();
6692 }
6693#endif
6694
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006695 /* 'verbosefile' */
6696 else if (varp == &p_vfile)
6697 {
6698 verbose_stop();
6699 if (*p_vfile != NUL && verbose_open() == FAIL)
6700 errmsg = e_invarg;
6701 }
6702
Bram Moolenaar071d4272004-06-13 20:20:40 +00006703#ifdef FEAT_VIMINFO
6704 /* 'viminfo' */
6705 else if (varp == &p_viminfo)
6706 {
6707 for (s = p_viminfo; *s;)
6708 {
6709 /* Check it's a valid character */
6710 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6711 {
6712 errmsg = illegal_char(errbuf, *s);
6713 break;
6714 }
6715 if (*s == 'n') /* name is always last one */
6716 {
6717 break;
6718 }
6719 else if (*s == 'r') /* skip until next ',' */
6720 {
6721 while (*++s && *s != ',')
6722 ;
6723 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006724 else if (*s == '%')
6725 {
6726 /* optional number */
6727 while (vim_isdigit(*++s))
6728 ;
6729 }
6730 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006731 ++s; /* no extra chars */
6732 else /* must have a number */
6733 {
6734 while (vim_isdigit(*++s))
6735 ;
6736
6737 if (!VIM_ISDIGIT(*(s - 1)))
6738 {
6739 if (errbuf != NULL)
6740 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006741 sprintf(errbuf, _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006742 transchar_byte(*(s - 1)));
6743 errmsg = errbuf;
6744 }
6745 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006746 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006747 break;
6748 }
6749 }
6750 if (*s == ',')
6751 ++s;
6752 else if (*s)
6753 {
6754 if (errbuf != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006755 errmsg = N_("E527: Missing comma");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006756 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006757 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006758 break;
6759 }
6760 }
6761 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006762 errmsg = N_("E528: Must specify a ' value");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006763 }
6764#endif /* FEAT_VIMINFO */
6765
6766 /* terminal options */
6767 else if (istermoption(&options[opt_idx]) && full_screen)
6768 {
6769 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6770 if (varp == &T_CCO)
6771 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006772 int colors = atoi((char *)T_CCO);
6773
6774 /* Only reinitialize colors if t_Co value has really changed to
6775 * avoid expensive reload of colorscheme if t_Co is set to the
6776 * same value multiple times. */
6777 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006778 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006779 t_colors = colors;
6780 if (t_colors <= 1)
6781 {
6782 if (new_value_alloced)
6783 vim_free(T_CCO);
6784 T_CCO = empty_option;
6785 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006786#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6787 if (is_term_win32())
6788 {
6789 swap_tcap();
6790 did_swaptcap = TRUE;
6791 }
6792#endif
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006793 /* We now have a different color setup, initialize it again. */
6794 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006795 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006796 }
6797 ttest(FALSE);
6798 if (varp == &T_ME)
6799 {
6800 out_str(T_ME);
6801 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006802#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006803 /* Since t_me has been set, this probably means that the user
6804 * wants to use this as default colors. Need to reset default
6805 * background/foreground colors. */
6806 mch_set_normal_colors();
6807#endif
6808 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006809 if (varp == &T_BE && termcap_active)
6810 {
6811 if (*T_BE == NUL)
6812 /* When clearing t_BE we assume the user no longer wants
6813 * bracketed paste, thus disable it by writing t_BD. */
6814 out_str(T_BD);
6815 else
6816 out_str(T_BE);
6817 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006818 }
6819
6820#ifdef FEAT_LINEBREAK
6821 /* 'showbreak' */
6822 else if (varp == &p_sbr)
6823 {
6824 for (s = p_sbr; *s; )
6825 {
6826 if (ptr2cells(s) != 1)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006827 errmsg = N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006828 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006829 }
6830 }
6831#endif
6832
6833#ifdef FEAT_GUI
6834 /* 'guifont' */
6835 else if (varp == &p_guifont)
6836 {
6837 if (gui.in_use)
6838 {
6839 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006840# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006841 /*
6842 * Put up a font dialog and let the user select a new value.
6843 * If this is cancelled go back to the old value but don't
6844 * give an error message.
6845 */
6846 if (STRCMP(p, "*") == 0)
6847 {
6848 p = gui_mch_font_dialog(oldval);
6849
6850 if (new_value_alloced)
6851 free_string_option(p_guifont);
6852
6853 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6854 new_value_alloced = TRUE;
6855 }
6856# endif
6857 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6858 {
6859# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6860 if (STRCMP(p_guifont, "*") == 0)
6861 {
6862 /* Dialog was cancelled: Keep the old value without giving
6863 * an error message. */
6864 if (new_value_alloced)
6865 free_string_option(p_guifont);
6866 p_guifont = vim_strsave(oldval);
6867 new_value_alloced = TRUE;
6868 }
6869 else
6870# endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006871 errmsg = N_("E596: Invalid font(s)");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006872 }
6873 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006874 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006875 }
6876# ifdef FEAT_XFONTSET
6877 else if (varp == &p_guifontset)
6878 {
6879 if (STRCMP(p_guifontset, "*") == 0)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01006880 errmsg = N_("E597: can't select fontset");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006881 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01006882 errmsg = N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006883 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006884 }
6885# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006886 else if (varp == &p_guifontwide)
6887 {
6888 if (STRCMP(p_guifontwide, "*") == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006889 errmsg = N_("E533: can't select wide font");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006890 else if (gui_get_wide_font() == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006891 errmsg = N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006892 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006893 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006894#endif
6895
6896#ifdef CURSOR_SHAPE
6897 /* 'guicursor' */
6898 else if (varp == &p_guicursor)
6899 errmsg = parse_shape_opt(SHAPE_CURSOR);
6900#endif
6901
6902#ifdef FEAT_MOUSESHAPE
6903 /* 'mouseshape' */
6904 else if (varp == &p_mouseshape)
6905 {
6906 errmsg = parse_shape_opt(SHAPE_MOUSE);
6907 update_mouseshape(-1);
6908 }
6909#endif
6910
6911#ifdef FEAT_PRINTER
6912 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006913 errmsg = parse_printoptions();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006914# if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006915 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006916 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006917# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006918#endif
6919
6920#ifdef FEAT_LANGMAP
6921 /* 'langmap' */
6922 else if (varp == &p_langmap)
6923 langmap_set();
6924#endif
6925
6926#ifdef FEAT_LINEBREAK
6927 /* 'breakat' */
6928 else if (varp == &p_breakat)
6929 fill_breakat_flags();
6930#endif
6931
6932#ifdef FEAT_TITLE
6933 /* 'titlestring' and 'iconstring' */
6934 else if (varp == &p_titlestring || varp == &p_iconstring)
6935 {
6936# ifdef FEAT_STL_OPT
6937 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6938
6939 /* NULL => statusline syntax */
6940 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6941 stl_syntax |= flagval;
6942 else
6943 stl_syntax &= ~flagval;
6944# endif
Bram Moolenaar84a93082018-06-16 22:58:15 +02006945 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006946 }
6947#endif
6948
6949#ifdef FEAT_GUI
6950 /* 'guioptions' */
6951 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006952 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006953 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006954 redraw_gui_only = TRUE;
6955 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006956#endif
6957
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006958#if defined(FEAT_GUI_TABLINE)
6959 /* 'guitablabel' */
6960 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006961 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006962 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006963 redraw_gui_only = TRUE;
6964 }
6965 /* 'guitabtooltip' */
6966 else if (varp == &p_gtt)
6967 {
6968 redraw_gui_only = TRUE;
6969 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006970#endif
6971
Bram Moolenaar071d4272004-06-13 20:20:40 +00006972#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6973 /* 'ttymouse' */
6974 else if (varp == &p_ttym)
6975 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006976 /* Switch the mouse off before changing the escape sequences used for
6977 * that. */
6978 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006979 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6980 errmsg = e_invarg;
6981 else
6982 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006983 if (termcap_active)
6984 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006985 }
6986#endif
6987
Bram Moolenaar071d4272004-06-13 20:20:40 +00006988 /* 'selection' */
6989 else if (varp == &p_sel)
6990 {
6991 if (*p_sel == NUL
6992 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6993 errmsg = e_invarg;
6994 }
6995
6996 /* 'selectmode' */
6997 else if (varp == &p_slm)
6998 {
6999 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
7000 errmsg = e_invarg;
7001 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007002
7003#ifdef FEAT_BROWSE
7004 /* 'browsedir' */
7005 else if (varp == &p_bsdir)
7006 {
7007 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7008 && !mch_isdir(p_bsdir))
7009 errmsg = e_invarg;
7010 }
7011#endif
7012
Bram Moolenaar071d4272004-06-13 20:20:40 +00007013 /* 'keymodel' */
7014 else if (varp == &p_km)
7015 {
7016 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7017 errmsg = e_invarg;
7018 else
7019 {
7020 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7021 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7022 }
7023 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007024
7025 /* 'mousemodel' */
7026 else if (varp == &p_mousem)
7027 {
7028 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7029 errmsg = e_invarg;
7030#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7031 else if (*p_mousem != *oldval)
7032 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7033 * to create or delete the popup menus. */
7034 gui_motif_update_mousemodel(root_menu);
7035#endif
7036 }
7037
7038 /* 'switchbuf' */
7039 else if (varp == &p_swb)
7040 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007041 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007042 errmsg = e_invarg;
7043 }
7044
7045 /* 'debug' */
7046 else if (varp == &p_debug)
7047 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007048 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007049 errmsg = e_invarg;
7050 }
7051
7052 /* 'display' */
7053 else if (varp == &p_dy)
7054 {
7055 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7056 errmsg = e_invarg;
7057 else
7058 (void)init_chartab();
7059
7060 }
7061
Bram Moolenaar071d4272004-06-13 20:20:40 +00007062 /* 'eadirection' */
7063 else if (varp == &p_ead)
7064 {
7065 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7066 errmsg = e_invarg;
7067 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007068
7069#ifdef FEAT_CLIPBOARD
7070 /* 'clipboard' */
7071 else if (varp == &p_cb)
7072 errmsg = check_clipboard_option();
7073#endif
7074
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007075#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007076 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7077 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007078 else if (varp == &(curwin->w_s->b_p_spl)
7079 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007080 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007081 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007082 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007083 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007084 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007085 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007086 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007087 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007088 /* 'spellsuggest' */
7089 else if (varp == &p_sps)
7090 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007091 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007092 errmsg = e_invarg;
7093 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007094 /* 'mkspellmem' */
7095 else if (varp == &p_msm)
7096 {
7097 if (spell_check_msm() != OK)
7098 errmsg = e_invarg;
7099 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007100#endif
7101
Bram Moolenaar071d4272004-06-13 20:20:40 +00007102 /* When 'bufhidden' is set, check for valid value. */
7103 else if (gvarp == &p_bh)
7104 {
7105 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7106 errmsg = e_invarg;
7107 }
7108
7109 /* When 'buftype' is set, check for valid value. */
7110 else if (gvarp == &p_bt)
7111 {
7112 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7113 errmsg = e_invarg;
7114 else
7115 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007116 if (curwin->w_status_height)
7117 {
7118 curwin->w_redr_status = TRUE;
7119 redraw_later(VALID);
7120 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007121 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007122#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007123 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007124#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007125 }
7126 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007127
7128#ifdef FEAT_STL_OPT
7129 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007130 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007131 {
7132 int wid;
7133
7134 if (varp == &p_ruf) /* reset ru_wid first */
7135 ru_wid = 0;
7136 s = *varp;
7137 if (varp == &p_ruf && *s == '%')
7138 {
7139 /* set ru_wid if 'ruf' starts with "%99(" */
7140 if (*++s == '-') /* ignore a '-' */
7141 s++;
7142 wid = getdigits(&s);
7143 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7144 ru_wid = wid;
7145 else
7146 errmsg = check_stl_option(p_ruf);
7147 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007148 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007149 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007150 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007151 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007152 comp_col();
7153 }
7154#endif
7155
7156#ifdef FEAT_INS_EXPAND
7157 /* check if it is a valid value for 'complete' -- Acevedo */
7158 else if (gvarp == &p_cpt)
7159 {
7160 for (s = *varp; *s;)
7161 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007162 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007163 s++;
7164 if (!*s)
7165 break;
7166 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7167 {
7168 errmsg = illegal_char(errbuf, *s);
7169 break;
7170 }
7171 if (*++s != NUL && *s != ',' && *s != ' ')
7172 {
7173 if (s[-1] == 'k' || s[-1] == 's')
7174 {
7175 /* skip optional filename after 'k' and 's' */
7176 while (*s && *s != ',' && *s != ' ')
7177 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007178 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007179 ++s;
7180 ++s;
7181 }
7182 }
7183 else
7184 {
7185 if (errbuf != NULL)
7186 {
7187 sprintf((char *)errbuf,
7188 _("E535: Illegal character after <%c>"),
7189 *--s);
7190 errmsg = errbuf;
7191 }
7192 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007193 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00007194 break;
7195 }
7196 }
7197 }
7198 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007199
7200 /* 'completeopt' */
7201 else if (varp == &p_cot)
7202 {
7203 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7204 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007205 else
7206 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007207 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007208#endif /* FEAT_INS_EXPAND */
7209
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007210#ifdef FEAT_SIGNS
7211 /* 'signcolumn' */
7212 else if (varp == &curwin->w_p_scl)
7213 {
7214 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7215 errmsg = e_invarg;
7216 }
7217#endif
7218
Bram Moolenaar071d4272004-06-13 20:20:40 +00007219
7220#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007221 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007222 else if (varp == &p_toolbar)
7223 {
7224 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7225 &toolbar_flags, TRUE) != OK)
7226 errmsg = e_invarg;
7227 else
7228 {
7229 out_flush();
7230 gui_mch_show_toolbar((toolbar_flags &
7231 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7232 }
7233 }
7234#endif
7235
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007236#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007237 /* 'toolbariconsize': GTK+ 2 only */
7238 else if (varp == &p_tbis)
7239 {
7240 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7241 errmsg = e_invarg;
7242 else
7243 {
7244 out_flush();
7245 gui_mch_show_toolbar((toolbar_flags &
7246 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7247 }
7248 }
7249#endif
7250
7251 /* 'pastetoggle': translate key codes like in a mapping */
7252 else if (varp == &p_pt)
7253 {
7254 if (*p_pt)
7255 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007256 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007257 if (p != NULL)
7258 {
7259 if (new_value_alloced)
7260 free_string_option(p_pt);
7261 p_pt = p;
7262 new_value_alloced = TRUE;
7263 }
7264 }
7265 }
7266
7267 /* 'backspace' */
7268 else if (varp == &p_bs)
7269 {
7270 if (VIM_ISDIGIT(*p_bs))
7271 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007272 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007273 errmsg = e_invarg;
7274 }
7275 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7276 errmsg = e_invarg;
7277 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007278 else if (varp == &p_bo)
7279 {
7280 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7281 errmsg = e_invarg;
7282 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007283
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007284 /* 'tagcase' */
7285 else if (gvarp == &p_tc)
7286 {
7287 unsigned int *flags;
7288
7289 if (opt_flags & OPT_LOCAL)
7290 {
7291 p = curbuf->b_p_tc;
7292 flags = &curbuf->b_tc_flags;
7293 }
7294 else
7295 {
7296 p = p_tc;
7297 flags = &tc_flags;
7298 }
7299
7300 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7301 /* make the local value empty: use the global value */
7302 *flags = 0;
7303 else if (*p == NUL
7304 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7305 errmsg = e_invarg;
7306 }
7307
Bram Moolenaar071d4272004-06-13 20:20:40 +00007308 /* 'casemap' */
7309 else if (varp == &p_cmp)
7310 {
7311 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7312 errmsg = e_invarg;
7313 }
7314
7315#ifdef FEAT_DIFF
7316 /* 'diffopt' */
7317 else if (varp == &p_dip)
7318 {
7319 if (diffopt_changed() == FAIL)
7320 errmsg = e_invarg;
7321 }
7322#endif
7323
7324#ifdef FEAT_FOLDING
7325 /* 'foldmethod' */
7326 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7327 {
7328 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7329 || *curwin->w_p_fdm == NUL)
7330 errmsg = e_invarg;
7331 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007332 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007333 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007334 if (foldmethodIsDiff(curwin))
7335 newFoldLevel();
7336 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007337 }
7338# ifdef FEAT_EVAL
7339 /* 'foldexpr' */
7340 else if (varp == &curwin->w_p_fde)
7341 {
7342 if (foldmethodIsExpr(curwin))
7343 foldUpdateAll(curwin);
7344 }
7345# endif
7346 /* 'foldmarker' */
7347 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7348 {
7349 p = vim_strchr(*varp, ',');
7350 if (p == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007351 errmsg = N_("E536: comma required");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007352 else if (p == *varp || p[1] == NUL)
7353 errmsg = e_invarg;
7354 else if (foldmethodIsMarker(curwin))
7355 foldUpdateAll(curwin);
7356 }
7357 /* 'commentstring' */
7358 else if (gvarp == &p_cms)
7359 {
7360 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007361 errmsg = N_("E537: 'commentstring' must be empty or contain %s");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007362 }
7363 /* 'foldopen' */
7364 else if (varp == &p_fdo)
7365 {
7366 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7367 errmsg = e_invarg;
7368 }
7369 /* 'foldclose' */
7370 else if (varp == &p_fcl)
7371 {
7372 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7373 errmsg = e_invarg;
7374 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007375 /* 'foldignore' */
7376 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7377 {
7378 if (foldmethodIsIndent(curwin))
7379 foldUpdateAll(curwin);
7380 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007381#endif
7382
Bram Moolenaar071d4272004-06-13 20:20:40 +00007383 /* 'virtualedit' */
7384 else if (varp == &p_ve)
7385 {
7386 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7387 errmsg = e_invarg;
7388 else if (STRCMP(p_ve, oldval) != 0)
7389 {
7390 /* Recompute cursor position in case the new 've' setting
7391 * changes something. */
7392 validate_virtcol();
7393 coladvance(curwin->w_virtcol);
7394 }
7395 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007396
7397#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7398 else if (varp == &p_csqf)
7399 {
7400 if (p_csqf != NULL)
7401 {
7402 p = p_csqf;
7403 while (*p != NUL)
7404 {
7405 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7406 || p[1] == NUL
7407 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7408 || (p[2] != NUL && p[2] != ','))
7409 {
7410 errmsg = e_invarg;
7411 break;
7412 }
7413 else if (p[2] == NUL)
7414 break;
7415 else
7416 p += 3;
7417 }
7418 }
7419 }
7420#endif
7421
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007422#ifdef FEAT_CINDENT
7423 /* 'cinoptions' */
7424 else if (gvarp == &p_cino)
7425 {
7426 /* TODO: recognize errors */
7427 parse_cino(curbuf);
7428 }
7429#endif
7430
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007431#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007432 /* 'renderoptions' */
Bram Moolenaar3767c6e2017-12-05 16:57:56 +01007433 else if (varp == &p_rop)
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007434 {
7435 if (!gui_mch_set_rendering_options(p_rop))
7436 errmsg = e_invarg;
7437 }
7438#endif
7439
Bram Moolenaard0b51382016-11-04 15:23:45 +01007440 else if (gvarp == &p_ft)
7441 {
7442 if (!valid_filetype(*varp))
7443 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007444 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007445 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007446 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007447
7448 // Since we check the value, there is no need to set P_INSECURE,
7449 // even when the value comes from a modeline.
7450 *value_checked = TRUE;
7451 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007452 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007453
7454#ifdef FEAT_SYN_HL
7455 else if (gvarp == &p_syn)
7456 {
7457 if (!valid_filetype(*varp))
7458 errmsg = e_invarg;
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007459 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007460 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007461 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007462
7463 // Since we check the value, there is no need to set P_INSECURE,
7464 // even when the value comes from a modeline.
7465 *value_checked = TRUE;
7466 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007467 }
7468#endif
7469
Bram Moolenaar825680f2017-07-22 17:04:02 +02007470#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007471 /* 'termwinkey' */
7472 else if (varp == &curwin->w_p_twk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007473 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007474 if (*curwin->w_p_twk != NUL
7475 && string_to_key(curwin->w_p_twk, TRUE) == 0)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007476 errmsg = e_invarg;
7477 }
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007478 /* 'termwinsize' */
7479 else if (varp == &curwin->w_p_tws)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007480 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007481 if (*curwin->w_p_tws != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007482 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007483 p = skipdigits(curwin->w_p_tws);
7484 if (p == curwin->w_p_tws
Bram Moolenaar498c2562018-04-15 23:45:15 +02007485 || (*p != 'x' && *p != '*')
7486 || *skipdigits(p + 1) != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007487 errmsg = e_invarg;
7488 }
7489 }
7490#endif
7491
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007492#ifdef FEAT_VARTABS
7493 /* 'varsofttabstop' */
7494 else if (varp == &(curbuf->b_p_vsts))
7495 {
7496 char_u *cp;
7497
7498 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7499 {
7500 if (curbuf->b_p_vsts_array)
7501 {
7502 vim_free(curbuf->b_p_vsts_array);
7503 curbuf->b_p_vsts_array = 0;
7504 }
7505 }
7506 else
7507 {
7508 for (cp = *varp; *cp; ++cp)
7509 {
7510 if (vim_isdigit(*cp))
7511 continue;
7512 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7513 continue;
7514 errmsg = e_invarg;
7515 break;
7516 }
7517 if (errmsg == NULL)
7518 {
7519 int *oldarray = curbuf->b_p_vsts_array;
7520 if (tabstop_set(*varp, &(curbuf->b_p_vsts_array)))
7521 {
7522 if (oldarray)
7523 vim_free(oldarray);
7524 }
7525 else
7526 errmsg = e_invarg;
7527 }
7528 }
7529 }
7530
7531 /* 'vartabstop' */
7532 else if (varp == &(curbuf->b_p_vts))
7533 {
7534 char_u *cp;
7535
7536 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7537 {
7538 if (curbuf->b_p_vts_array)
7539 {
7540 vim_free(curbuf->b_p_vts_array);
7541 curbuf->b_p_vts_array = NULL;
7542 }
7543 }
7544 else
7545 {
7546 for (cp = *varp; *cp; ++cp)
7547 {
7548 if (vim_isdigit(*cp))
7549 continue;
7550 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7551 continue;
7552 errmsg = e_invarg;
7553 break;
7554 }
7555 if (errmsg == NULL)
7556 {
7557 int *oldarray = curbuf->b_p_vts_array;
7558 if (tabstop_set(*varp, &(curbuf->b_p_vts_array)))
7559 {
7560 if (oldarray)
7561 vim_free(oldarray);
7562#ifdef FEAT_FOLDING
7563 if (foldmethodIsIndent(curwin))
7564 foldUpdateAll(curwin);
7565#endif /* FEAT_FOLDING */
7566 }
7567 else
7568 errmsg = e_invarg;
7569 }
7570 }
7571 }
7572#endif
7573
Bram Moolenaar071d4272004-06-13 20:20:40 +00007574 /* Options that are a list of flags. */
7575 else
7576 {
7577 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007578 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007579 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007580 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007581 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007582 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007583 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007584 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007585 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007586#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007587 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007588 p = (char_u *)COCU_ALL;
7589#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007590 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007591 {
7592#ifdef FEAT_MOUSE
7593 p = (char_u *)MOUSE_ALL;
7594#else
7595 if (*p_mouse != NUL)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007596 errmsg = N_("E538: No mouse support");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007597#endif
7598 }
7599#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007600 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007601 p = (char_u *)GO_ALL;
7602#endif
7603 if (p != NULL)
7604 {
7605 for (s = *varp; *s; ++s)
7606 if (vim_strchr(p, *s) == NULL)
7607 {
7608 errmsg = illegal_char(errbuf, *s);
7609 break;
7610 }
7611 }
7612 }
7613
7614 /*
7615 * If error detected, restore the previous value.
7616 */
7617 if (errmsg != NULL)
7618 {
7619 if (new_value_alloced)
7620 free_string_option(*varp);
7621 *varp = oldval;
7622 /*
7623 * When resetting some values, need to act on it.
7624 */
7625 if (did_chartab)
7626 (void)init_chartab();
7627 if (varp == &p_hl)
7628 (void)highlight_changed();
7629 }
7630 else
7631 {
7632#ifdef FEAT_EVAL
7633 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02007634 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007635#endif
7636 /*
7637 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007638 * Use "free_oldval", because recursiveness may change the flags under
7639 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007640 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007641 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007642 free_string_option(oldval);
7643 if (new_value_alloced)
7644 options[opt_idx].flags |= P_ALLOCED;
7645 else
7646 options[opt_idx].flags &= ~P_ALLOCED;
7647
7648 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007649 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007650 {
7651 /* global option with local value set to use global value; free
7652 * the local value and make it empty */
7653 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7654 free_string_option(*(char_u **)p);
7655 *(char_u **)p = empty_option;
7656 }
7657
7658 /* May set global value for local option. */
7659 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7660 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007661
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007662 /*
7663 * Trigger the autocommand only after setting the flags.
7664 */
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007665#ifdef FEAT_SYN_HL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007666 /* When 'syntax' is set, load the syntax of that name */
7667 if (varp == &(curbuf->b_p_syn))
7668 {
Bram Moolenaara5616b02018-06-17 19:08:30 +02007669 static int syn_recursive = 0;
7670
7671 ++syn_recursive;
7672 // Only pass TRUE for "force" when the value changed or not used
7673 // recursively, to avoid endless recurrence.
7674 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname,
7675 value_changed || syn_recursive == 1, curbuf);
7676 --syn_recursive;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007677 }
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007678#endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007679 else if (varp == &(curbuf->b_p_ft))
7680 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007681 /* 'filetype' is set, trigger the FileType autocommand.
7682 * Skip this when called from a modeline and the filetype was
Bram Moolenaara5616b02018-06-17 19:08:30 +02007683 * already set to this value. */
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007684 if (!(opt_flags & OPT_MODELINE) || value_changed)
Bram Moolenaar90492982017-06-22 14:16:31 +02007685 {
Bram Moolenaar916a8182018-11-25 02:18:29 +01007686 static int ft_recursive = 0;
7687 int secure_save = secure;
7688
7689 // Reset the secure flag, since the value of 'filetype' has
7690 // been checked to be safe.
7691 secure = 0;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007692
7693 ++ft_recursive;
Bram Moolenaar90492982017-06-22 14:16:31 +02007694 did_filetype = TRUE;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007695 // Only pass TRUE for "force" when the value changed or not
7696 // used recursively, to avoid endless recurrence.
7697 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname,
7698 value_changed || ft_recursive == 1, curbuf);
7699 --ft_recursive;
Bram Moolenaar163095f2017-07-09 15:41:53 +02007700 /* Just in case the old "curbuf" is now invalid. */
7701 if (varp != &(curbuf->b_p_ft))
7702 varp = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007703
7704 secure = secure_save;
Bram Moolenaar90492982017-06-22 14:16:31 +02007705 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007706 }
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007707#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007708 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007709 {
7710 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007711 char_u *q = curwin->w_s->b_p_spl;
7712
7713 /* Skip the first name if it is "cjk". */
7714 if (STRNCMP(q, "cjk,", 4) == 0)
7715 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007716
7717 /*
7718 * Source the spell/LANG.vim in 'runtimepath'.
7719 * They could set 'spellcapcheck' depending on the language.
7720 * Use the first name in 'spelllang' up to '_region' or
7721 * '.encoding'.
7722 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007723 for (p = q; *p != NUL; ++p)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01007724 if (!ASCII_ISALNUM(*p) && *p != '-')
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007725 break;
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007726 if (p > q)
7727 {
7728 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
7729 source_runtime(fname, DIP_ALL);
7730 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007731 }
7732#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007733 }
7734
7735#ifdef FEAT_MOUSE
7736 if (varp == &p_mouse)
7737 {
7738# ifdef FEAT_MOUSE_TTY
7739 if (*p_mouse == NUL)
7740 mch_setmouse(FALSE); /* switch mouse off */
7741 else
7742# endif
7743 setmouse(); /* in case 'mouse' changed */
7744 }
7745#endif
7746
Bram Moolenaar913077c2012-03-28 19:59:04 +02007747 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007748 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007749 curwin->w_set_curswant = TRUE;
7750
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007751#ifdef FEAT_GUI
7752 /* check redraw when it's not a GUI option or the GUI is active. */
7753 if (!redraw_gui_only || gui.in_use)
7754#endif
7755 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007756
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007757#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
7758 if (did_swaptcap)
7759 {
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007760 set_termname((char_u *)"win32");
7761 init_highlight(TRUE, FALSE);
7762 }
7763#endif
7764
Bram Moolenaar071d4272004-06-13 20:20:40 +00007765 return errmsg;
7766}
7767
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007768#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007769/*
7770 * Simple int comparison function for use with qsort()
7771 */
7772 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007773int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007774{
7775 return *(const int *)a - *(const int *)b;
7776}
7777
7778/*
7779 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7780 * Returns error message, NULL if it's OK.
7781 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007782 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007783check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007784{
7785 char_u *s;
7786 int col;
7787 int count = 0;
7788 int color_cols[256];
7789 int i;
7790 int j = 0;
7791
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007792 if (wp->w_buffer == NULL)
7793 return NULL; /* buffer was closed */
7794
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007795 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007796 {
7797 if (*s == '-' || *s == '+')
7798 {
7799 /* -N and +N: add to 'textwidth' */
7800 col = (*s == '-') ? -1 : 1;
7801 ++s;
7802 if (!VIM_ISDIGIT(*s))
7803 return e_invarg;
7804 col = col * getdigits(&s);
7805 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007806 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007807 col += wp->w_buffer->b_p_tw;
7808 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007809 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007810 }
7811 else if (VIM_ISDIGIT(*s))
7812 col = getdigits(&s);
7813 else
7814 return e_invarg;
7815 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007816skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007817 if (*s == NUL)
7818 break;
7819 if (*s != ',')
7820 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007821 if (*++s == NUL)
7822 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007823 }
7824
7825 vim_free(wp->w_p_cc_cols);
7826 if (count == 0)
7827 wp->w_p_cc_cols = NULL;
7828 else
7829 {
7830 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7831 if (wp->w_p_cc_cols != NULL)
7832 {
7833 /* sort the columns for faster usage on screen redraw inside
7834 * win_line() */
7835 qsort(color_cols, count, sizeof(int), int_cmp);
7836
7837 for (i = 0; i < count; ++i)
7838 /* skip duplicates */
7839 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7840 wp->w_p_cc_cols[j++] = color_cols[i];
7841 wp->w_p_cc_cols[j] = -1; /* end marker */
7842 }
7843 }
7844
7845 return NULL; /* no error */
7846}
7847#endif
7848
Bram Moolenaar071d4272004-06-13 20:20:40 +00007849/*
7850 * Handle setting 'listchars' or 'fillchars'.
7851 * Returns error message, NULL if it's OK.
7852 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007853 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007854set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007855{
7856 int round, i, len, entries;
7857 char_u *p, *s;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007858 int c1 = 0, c2 = 0, c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007859 struct charstab
7860 {
7861 int *cp;
7862 char *name;
7863 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007864 static struct charstab filltab[] =
7865 {
7866 {&fill_stl, "stl"},
7867 {&fill_stlnc, "stlnc"},
7868 {&fill_vert, "vert"},
7869 {&fill_fold, "fold"},
7870 {&fill_diff, "diff"},
7871 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007872 static struct charstab lcstab[] =
7873 {
7874 {&lcs_eol, "eol"},
7875 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007876 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007877 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007878 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007879 {&lcs_tab2, "tab"},
7880 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007881#ifdef FEAT_CONCEAL
7882 {&lcs_conceal, "conceal"},
7883#else
7884 {NULL, "conceal"},
7885#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007886 };
7887 struct charstab *tab;
7888
Bram Moolenaar071d4272004-06-13 20:20:40 +00007889 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007890 {
7891 tab = lcstab;
7892 entries = sizeof(lcstab) / sizeof(struct charstab);
7893 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007894 else
7895 {
7896 tab = filltab;
7897 entries = sizeof(filltab) / sizeof(struct charstab);
7898 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007899
7900 /* first round: check for valid value, second round: assign values */
7901 for (round = 0; round <= 1; ++round)
7902 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007903 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007904 {
7905 /* After checking that the value is valid: set defaults: space for
7906 * 'fillchars', NUL for 'listchars' */
7907 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007908 if (tab[i].cp != NULL)
7909 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar83a52172019-01-16 22:41:54 +01007910
Bram Moolenaar071d4272004-06-13 20:20:40 +00007911 if (varp == &p_lcs)
Bram Moolenaar83a52172019-01-16 22:41:54 +01007912 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007913 lcs_tab1 = NUL;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007914 lcs_tab3 = NUL;
7915 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007916 else
7917 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007918 }
7919 p = *varp;
7920 while (*p)
7921 {
7922 for (i = 0; i < entries; ++i)
7923 {
7924 len = (int)STRLEN(tab[i].name);
7925 if (STRNCMP(p, tab[i].name, len) == 0
7926 && p[len] == ':'
7927 && p[len + 1] != NUL)
7928 {
Bram Moolenaar83a52172019-01-16 22:41:54 +01007929 c1 = c2 = c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007930 s = p + len + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007931 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007932 if (mb_char2cells(c1) > 1)
7933 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007934 if (tab[i].cp == &lcs_tab2)
7935 {
7936 if (*s == NUL)
7937 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007938 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007939 if (mb_char2cells(c2) > 1)
7940 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007941 if (!(*s == ',' || *s == NUL))
7942 {
Bram Moolenaar83a52172019-01-16 22:41:54 +01007943 c3 = mb_ptr2char_adv(&s);
7944 if (mb_char2cells(c3) > 1)
7945 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007946 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007947 }
Bram Moolenaar83a52172019-01-16 22:41:54 +01007948
Bram Moolenaar071d4272004-06-13 20:20:40 +00007949 if (*s == ',' || *s == NUL)
7950 {
7951 if (round)
7952 {
7953 if (tab[i].cp == &lcs_tab2)
7954 {
7955 lcs_tab1 = c1;
7956 lcs_tab2 = c2;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007957 lcs_tab3 = c3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007958 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007959 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007960 *(tab[i].cp) = c1;
7961
7962 }
7963 p = s;
7964 break;
7965 }
7966 }
7967 }
7968
7969 if (i == entries)
7970 return e_invarg;
7971 if (*p == ',')
7972 ++p;
7973 }
7974 }
7975
7976 return NULL; /* no error */
7977}
7978
7979#ifdef FEAT_STL_OPT
7980/*
7981 * Check validity of options with the 'statusline' format.
7982 * Return error message or NULL.
7983 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007984 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007985check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007986{
7987 int itemcnt = 0;
7988 int groupdepth = 0;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007989 static char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00007990
7991 while (*s && itemcnt < STL_MAX_ITEM)
7992 {
7993 /* Check for valid keys after % sequences */
7994 while (*s && *s != '%')
7995 s++;
7996 if (!*s)
7997 break;
7998 s++;
7999 if (*s != '%' && *s != ')')
8000 ++itemcnt;
8001 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
8002 {
8003 s++;
8004 continue;
8005 }
8006 if (*s == ')')
8007 {
8008 s++;
8009 if (--groupdepth < 0)
8010 break;
8011 continue;
8012 }
8013 if (*s == '-')
8014 s++;
8015 while (VIM_ISDIGIT(*s))
8016 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00008017 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008018 continue;
8019 if (*s == '.')
8020 {
8021 s++;
8022 while (*s && VIM_ISDIGIT(*s))
8023 s++;
8024 }
8025 if (*s == '(')
8026 {
8027 groupdepth++;
8028 continue;
8029 }
8030 if (vim_strchr(STL_ALL, *s) == NULL)
8031 {
8032 return illegal_char(errbuf, *s);
8033 }
8034 if (*s == '{')
8035 {
8036 s++;
8037 while (*s != '}' && *s)
8038 s++;
8039 if (*s != '}')
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008040 return N_("E540: Unclosed expression sequence");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008041 }
8042 }
8043 if (itemcnt >= STL_MAX_ITEM)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008044 return N_("E541: too many items");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008045 if (groupdepth != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008046 return N_("E542: unbalanced groups");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008047 return NULL;
8048}
8049#endif
8050
8051#ifdef FEAT_CLIPBOARD
8052/*
8053 * Extract the items in the 'clipboard' option and set global values.
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008054 * Return an error message or NULL for success.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008055 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008056 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008057check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008058{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008059 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008060 int new_autoselect_star = FALSE;
8061 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008062 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008063 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008064 regprog_T *new_exclude_prog = NULL;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008065 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008066 char_u *p;
8067
8068 for (p = p_cb; *p != NUL; )
8069 {
8070 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
8071 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008072 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008073 p += 7;
8074 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02008075 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008076 && (p[11] == ',' || p[11] == NUL))
8077 {
8078 new_unnamed |= CLIP_UNNAMED_PLUS;
8079 p += 11;
8080 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008081 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008082 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008083 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02008084 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008085 p += 10;
8086 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02008087 else if (STRNCMP(p, "autoselectplus", 14) == 0
8088 && (p[14] == ',' || p[14] == NUL))
8089 {
8090 new_autoselect_plus = TRUE;
8091 p += 14;
8092 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008093 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008094 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008095 {
8096 new_autoselectml = TRUE;
8097 p += 12;
8098 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008099 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
8100 {
8101 new_html = TRUE;
8102 p += 4;
8103 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008104 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
8105 {
8106 p += 8;
8107 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
8108 if (new_exclude_prog == NULL)
8109 errmsg = e_invarg;
8110 break;
8111 }
8112 else
8113 {
8114 errmsg = e_invarg;
8115 break;
8116 }
8117 if (*p == ',')
8118 ++p;
8119 }
8120 if (errmsg == NULL)
8121 {
8122 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008123 clip_autoselect_star = new_autoselect_star;
8124 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008125 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008126 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008127 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008128 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008129#ifdef FEAT_GUI_GTK
8130 if (gui.in_use)
8131 {
8132 gui_gtk_set_selection_targets();
8133 gui_gtk_set_dnd_targets();
8134 }
8135#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008136 }
8137 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008138 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008139
8140 return errmsg;
8141}
8142#endif
8143
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008144#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008145/*
8146 * Handle side effects of setting 'spell'.
8147 * Return an error message or NULL for success.
8148 */
8149 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008150did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008151{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008152 char *errmsg = NULL;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008153 win_T *wp;
8154 int l;
8155
8156 if (is_spellfile)
8157 {
8158 l = (int)STRLEN(curwin->w_s->b_p_spf);
8159 if (l > 0 && (l < 4
8160 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8161 errmsg = e_invarg;
8162 }
8163
8164 if (errmsg == NULL)
8165 {
8166 FOR_ALL_WINDOWS(wp)
8167 if (wp->w_buffer == curbuf && wp->w_p_spell)
8168 {
8169 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008170 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008171 }
8172 }
8173 return errmsg;
8174}
8175
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008176/*
8177 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8178 * Return error message when failed, NULL when OK.
8179 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008180 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008181compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008182{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008183 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008184 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008185
Bram Moolenaar860cae12010-06-05 23:22:07 +02008186 if (*synblock->b_p_spc == NUL)
8187 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008188 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008189 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008190 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008191 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008192 if (re != NULL)
8193 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008194 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008195 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008196 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008197 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008198 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008199 return e_invarg;
8200 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008201 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008202 }
8203
Bram Moolenaar473de612013-06-08 18:19:48 +02008204 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008205 return NULL;
8206}
8207#endif
8208
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008209#if defined(FEAT_EVAL) || defined(PROTO)
8210/*
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008211 * Set the script_ctx for an option, taking care of setting the buffer- or
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008212 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008213 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008214 static void
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008215set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008216{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008217 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8218 int indir = (int)options[opt_idx].indir;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008219 sctx_T new_script_ctx = script_ctx;
8220
8221 new_script_ctx.sc_lnum += sourcing_lnum;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008222
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008223 /* Remember where the option was set. For local options need to do that
8224 * in the buffer or window structure. */
8225 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008226 options[opt_idx].script_ctx = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008227 if (both || (opt_flags & OPT_LOCAL))
8228 {
8229 if (indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008230 curbuf->b_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008231 else if (indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008232 curwin->w_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008233 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008234}
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02008235
8236/*
8237 * Set the script_ctx for a termcap option.
8238 * "name" must be the two character code, e.g. "RV".
8239 * When "name" is NULL use "opt_idx".
8240 */
8241 void
8242set_term_option_sctx_idx(char *name, int opt_idx)
8243{
8244 char_u buf[5];
8245 int idx;
8246
8247 if (name == NULL)
8248 idx = opt_idx;
8249 else
8250 {
8251 buf[0] = 't';
8252 buf[1] = '_';
8253 buf[2] = name[0];
8254 buf[3] = name[1];
8255 buf[4] = 0;
8256 idx = findoption(buf);
8257 }
8258 if (idx >= 0)
8259 set_option_sctx_idx(idx, OPT_GLOBAL, current_sctx);
8260}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008261#endif
8262
Bram Moolenaar071d4272004-06-13 20:20:40 +00008263/*
8264 * Set the value of a boolean option, and take care of side effects.
8265 * Returns NULL for success, or an error message for an error.
8266 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008267 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008268set_bool_option(
8269 int opt_idx, /* index in options[] table */
8270 char_u *varp, /* pointer to the option variable */
8271 int value, /* new value */
8272 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008273{
8274 int old_value = *(int *)varp;
8275
Bram Moolenaar071d4272004-06-13 20:20:40 +00008276 /* Disallow changing some options from secure mode */
8277 if ((secure
8278#ifdef HAVE_SANDBOX
8279 || sandbox != 0
8280#endif
8281 ) && (options[opt_idx].flags & P_SECURE))
8282 return e_secure;
8283
8284 *(int *)varp = value; /* set the new value */
8285#ifdef FEAT_EVAL
8286 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008287 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008288#endif
8289
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008290#ifdef FEAT_GUI
8291 need_mouse_correct = TRUE;
8292#endif
8293
Bram Moolenaar071d4272004-06-13 20:20:40 +00008294 /* May set global value for local option. */
8295 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8296 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8297
8298 /*
8299 * Handle side effects of changing a bool option.
8300 */
8301
8302 /* 'compatible' */
8303 if ((int *)varp == &p_cp)
8304 {
8305 compatible_set();
8306 }
8307
Bram Moolenaar920694c2016-08-21 17:45:02 +02008308#ifdef FEAT_LANGMAP
8309 if ((int *)varp == &p_lrm)
8310 /* 'langremap' -> !'langnoremap' */
8311 p_lnr = !p_lrm;
8312 else if ((int *)varp == &p_lnr)
8313 /* 'langnoremap' -> !'langremap' */
8314 p_lrm = !p_lnr;
8315#endif
8316
Bram Moolenaar8c63e0e2018-09-25 22:17:54 +02008317#ifdef FEAT_SYN_HL
8318 else if ((int *)varp == &curwin->w_p_cul && !value && old_value)
8319 reset_cursorline();
8320#endif
8321
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008322#ifdef FEAT_PERSISTENT_UNDO
8323 /* 'undofile' */
8324 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8325 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008326 /* Only take action when the option was set. When reset we do not
8327 * delete the undo file, the option may be set again without making
8328 * any changes in between. */
8329 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008330 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008331 char_u hash[UNDO_HASH_SIZE];
8332 buf_T *save_curbuf = curbuf;
8333
Bram Moolenaar29323592016-07-24 22:04:11 +02008334 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008335 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008336 /* When 'undofile' is set globally: for every buffer, otherwise
8337 * only for the current buffer: Try to read in the undofile,
8338 * if one exists, the buffer wasn't changed and the buffer was
8339 * loaded */
8340 if ((curbuf == save_curbuf
8341 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8342 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8343 {
8344 u_compute_hash(hash);
8345 u_read_undo(NULL, hash, curbuf->b_fname);
8346 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008347 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008348 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008349 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008350 }
8351#endif
8352
Bram Moolenaar071d4272004-06-13 20:20:40 +00008353 else if ((int *)varp == &curbuf->b_p_ro)
8354 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008355 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008356 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8357 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008358
8359 /* when 'readonly' is set may give W10 again */
8360 if (curbuf->b_p_ro)
8361 curbuf->b_did_warn = FALSE;
8362
Bram Moolenaar071d4272004-06-13 20:20:40 +00008363#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008364 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008365#endif
8366 }
8367
Bram Moolenaar9c449722010-07-20 18:44:27 +02008368#ifdef FEAT_GUI
8369 else if ((int *)varp == &p_mh)
8370 {
8371 if (!p_mh)
8372 gui_mch_mousehide(FALSE);
8373 }
8374#endif
8375
Bram Moolenaara539df02010-08-01 14:35:05 +02008376 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008377 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008378 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008379# ifdef FEAT_TERMINAL
8380 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaard7db27b2018-03-07 23:02:33 +01008381 if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf)
8382 && curbuf->b_term != NULL && !term_is_finished(curbuf))))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008383 {
8384 curbuf->b_p_ma = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008385 return N_("E946: Cannot make a terminal with running job modifiable");
Bram Moolenaar423802d2017-07-30 16:52:24 +02008386 }
8387# endif
8388# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008389 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008390# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008391 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008392#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008393 /* when 'endofline' is changed, redraw the window title */
8394 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008395 {
8396 redraw_titles();
8397 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008398 /* when 'fixeol' is changed, redraw the window title */
8399 else if ((int *)varp == &curbuf->b_p_fixeol)
8400 {
8401 redraw_titles();
8402 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008403 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008404 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008405 {
8406 redraw_titles();
8407 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008408#endif
8409
8410 /* when 'bin' is set also set some other options */
8411 else if ((int *)varp == &curbuf->b_p_bin)
8412 {
8413 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8414#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008415 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008416#endif
8417 }
8418
Bram Moolenaar071d4272004-06-13 20:20:40 +00008419 /* when 'buflisted' changes, trigger autocommands */
8420 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8421 {
8422 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8423 NULL, NULL, TRUE, curbuf);
8424 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008425
8426 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8427 else if ((int *)varp == &curbuf->b_p_swf)
8428 {
8429 if (curbuf->b_p_swf && p_uc)
8430 ml_open_file(curbuf); /* create the swap file */
8431 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008432 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8433 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008434 mf_close_file(curbuf, TRUE); /* remove the swap file */
8435 }
8436
8437 /* when 'terse' is set change 'shortmess' */
8438 else if ((int *)varp == &p_terse)
8439 {
8440 char_u *p;
8441
8442 p = vim_strchr(p_shm, SHM_SEARCH);
8443
8444 /* insert 's' in p_shm */
8445 if (p_terse && p == NULL)
8446 {
8447 STRCPY(IObuff, p_shm);
8448 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008449 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008450 }
8451 /* remove 's' from p_shm */
8452 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008453 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008454 }
8455
8456 /* when 'paste' is set or reset also change other options */
8457 else if ((int *)varp == &p_paste)
8458 {
8459 paste_option_changed();
8460 }
8461
8462 /* when 'insertmode' is set from an autocommand need to do work here */
8463 else if ((int *)varp == &p_im)
8464 {
8465 if (p_im)
8466 {
8467 if ((State & INSERT) == 0)
8468 need_start_insertmode = TRUE;
8469 stop_insert_mode = FALSE;
8470 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008471 /* only reset if it was set previously */
8472 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008473 {
8474 need_start_insertmode = FALSE;
8475 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008476 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008477 clear_cmdline = TRUE; /* remove "(insert)" */
8478 restart_edit = 0;
8479 }
8480 }
8481
8482 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8483 else if ((int *)varp == &p_ic && p_hls)
8484 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008485 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008486 }
8487
8488#ifdef FEAT_SEARCH_EXTRA
8489 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8490 else if ((int *)varp == &p_hls)
8491 {
Bram Moolenaar451fc7b2018-04-27 22:53:07 +02008492 set_no_hlsearch(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008493 }
8494#endif
8495
Bram Moolenaar071d4272004-06-13 20:20:40 +00008496 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8497 * at the end of normal_cmd() */
8498 else if ((int *)varp == &curwin->w_p_scb)
8499 {
8500 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008501 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008502 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008503 curwin->w_scbind_pos = curwin->w_topline;
8504 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008505 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008506
Bram Moolenaar4033c552017-09-16 20:54:51 +02008507#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008508 /* There can be only one window with 'previewwindow' set. */
8509 else if ((int *)varp == &curwin->w_p_pvw)
8510 {
8511 if (curwin->w_p_pvw)
8512 {
8513 win_T *win;
8514
Bram Moolenaar29323592016-07-24 22:04:11 +02008515 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008516 if (win->w_p_pvw && win != curwin)
8517 {
8518 curwin->w_p_pvw = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008519 return N_("E590: A preview window already exists");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008520 }
8521 }
8522 }
8523#endif
8524
8525 /* when 'textmode' is set or reset also change 'fileformat' */
8526 else if ((int *)varp == &curbuf->b_p_tx)
8527 {
8528 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8529 }
8530
8531 /* when 'textauto' is set or reset also change 'fileformats' */
8532 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008533 set_string_option_direct((char_u *)"ffs", -1,
8534 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008535 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008536
8537 /*
8538 * When 'lisp' option changes include/exclude '-' in
8539 * keyword characters.
8540 */
8541#ifdef FEAT_LISP
8542 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8543 {
8544 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8545 }
8546#endif
8547
8548#ifdef FEAT_TITLE
8549 /* when 'title' changed, may need to change the title; same for 'icon' */
Bram Moolenaar84a93082018-06-16 22:58:15 +02008550 else if ((int *)varp == &p_title || (int *)varp == &p_icon)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008551 {
Bram Moolenaar84a93082018-06-16 22:58:15 +02008552 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008553 }
8554#endif
8555
8556 else if ((int *)varp == &curbuf->b_changed)
8557 {
8558 if (!value)
8559 save_file_ff(curbuf); /* Buffer is unchanged */
8560#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008561 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008562#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008563 modified_was_set = value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008564 }
8565
8566#ifdef BACKSLASH_IN_FILENAME
8567 else if ((int *)varp == &p_ssl)
8568 {
8569 if (p_ssl)
8570 {
8571 psepc = '/';
8572 psepcN = '\\';
8573 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008574 }
8575 else
8576 {
8577 psepc = '\\';
8578 psepcN = '/';
8579 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008580 }
8581
8582 /* need to adjust the file name arguments and buffer names. */
8583 buflist_slash_adjust();
8584 alist_slash_adjust();
8585# ifdef FEAT_EVAL
8586 scriptnames_slash_adjust();
8587# endif
8588 }
8589#endif
8590
8591 /* If 'wrap' is set, set w_leftcol to zero. */
8592 else if ((int *)varp == &curwin->w_p_wrap)
8593 {
8594 if (curwin->w_p_wrap)
8595 curwin->w_leftcol = 0;
8596 }
8597
Bram Moolenaar071d4272004-06-13 20:20:40 +00008598 else if ((int *)varp == &p_ea)
8599 {
8600 if (p_ea && !old_value)
8601 win_equal(curwin, FALSE, 0);
8602 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008603
8604 else if ((int *)varp == &p_wiv)
8605 {
8606 /*
8607 * When 'weirdinvert' changed, set/reset 't_xs'.
8608 * Then set 'weirdinvert' according to value of 't_xs'.
8609 */
8610 if (p_wiv && !old_value)
8611 T_XS = (char_u *)"y";
8612 else if (!p_wiv && old_value)
8613 T_XS = empty_option;
8614 p_wiv = (*T_XS != NUL);
8615 }
8616
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008617#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008618 else if ((int *)varp == &p_beval)
8619 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008620 if (!balloonEvalForTerm)
8621 {
8622 if (p_beval && !old_value)
8623 gui_mch_enable_beval_area(balloonEval);
8624 else if (!p_beval && old_value)
8625 gui_mch_disable_beval_area(balloonEval);
8626 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008627 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008628#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008629#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008630 else if ((int *)varp == &p_bevalterm)
8631 {
8632 mch_bevalterm_changed();
8633 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008634#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008635
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008636#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008637 else if ((int *)varp == &p_acd)
8638 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008639 /* Change directories when the 'acd' option is set now. */
Bram Moolenaar6f470022018-04-10 18:47:20 +02008640 DO_AUTOCHDIR;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008641 }
8642#endif
8643
8644#ifdef FEAT_DIFF
8645 /* 'diff' */
8646 else if ((int *)varp == &curwin->w_p_diff)
8647 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008648 /* May add or remove the buffer from the list of diff buffers. */
8649 diff_buf_adjust(curwin);
8650# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008651 if (foldmethodIsDiff(curwin))
8652 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008653# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008654 }
8655#endif
8656
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008657#ifdef HAVE_INPUT_METHOD
Bram Moolenaar071d4272004-06-13 20:20:40 +00008658 /* 'imdisable' */
8659 else if ((int *)varp == &p_imdisable)
8660 {
8661 /* Only de-activate it here, it will be enabled when changing mode. */
8662 if (p_imdisable)
8663 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008664 else if (State & INSERT)
8665 /* When the option is set from an autocommand, it may need to take
8666 * effect right away. */
8667 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008668 }
8669#endif
8670
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008671#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008672 /* 'spell' */
8673 else if ((int *)varp == &curwin->w_p_spell)
8674 {
8675 if (curwin->w_p_spell)
8676 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008677 char *errmsg = did_set_spelllang(curwin);
8678
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008679 if (errmsg != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008680 emsg(_(errmsg));
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008681 }
8682 }
8683#endif
8684
Bram Moolenaar071d4272004-06-13 20:20:40 +00008685#ifdef FEAT_FKMAP
8686 else if ((int *)varp == &p_altkeymap)
8687 {
8688 if (old_value != p_altkeymap)
8689 {
8690 if (!p_altkeymap)
8691 {
8692 p_hkmap = p_fkmap;
8693 p_fkmap = 0;
8694 }
8695 else
8696 {
8697 p_fkmap = p_hkmap;
8698 p_hkmap = 0;
8699 }
8700 (void)init_chartab();
8701 }
8702 }
8703
8704 /*
8705 * In case some second language keymapping options have changed, check
8706 * and correct the setting in a consistent way.
8707 */
8708
8709 /*
8710 * If hkmap or fkmap are set, reset Arabic keymapping.
8711 */
8712 if ((p_hkmap || p_fkmap) && p_altkeymap)
8713 {
8714 p_altkeymap = p_fkmap;
8715# ifdef FEAT_ARABIC
8716 curwin->w_p_arab = FALSE;
8717# endif
8718 (void)init_chartab();
8719 }
8720
8721 /*
8722 * If hkmap set, reset Farsi keymapping.
8723 */
8724 if (p_hkmap && p_altkeymap)
8725 {
8726 p_altkeymap = 0;
8727 p_fkmap = 0;
8728# ifdef FEAT_ARABIC
8729 curwin->w_p_arab = FALSE;
8730# endif
8731 (void)init_chartab();
8732 }
8733
8734 /*
8735 * If fkmap set, reset Hebrew keymapping.
8736 */
8737 if (p_fkmap && !p_altkeymap)
8738 {
8739 p_altkeymap = 1;
8740 p_hkmap = 0;
8741# ifdef FEAT_ARABIC
8742 curwin->w_p_arab = FALSE;
8743# endif
8744 (void)init_chartab();
8745 }
8746#endif
8747
8748#ifdef FEAT_ARABIC
8749 if ((int *)varp == &curwin->w_p_arab)
8750 {
8751 if (curwin->w_p_arab)
8752 {
8753 /*
8754 * 'arabic' is set, handle various sub-settings.
8755 */
8756 if (!p_tbidi)
8757 {
8758 /* set rightleft mode */
8759 if (!curwin->w_p_rl)
8760 {
8761 curwin->w_p_rl = TRUE;
8762 changed_window_setting();
8763 }
8764
8765 /* Enable Arabic shaping (major part of what Arabic requires) */
8766 if (!p_arshape)
8767 {
8768 p_arshape = TRUE;
8769 redraw_later_clear();
8770 }
8771 }
8772
8773 /* Arabic requires a utf-8 encoding, inform the user if its not
8774 * set. */
8775 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008776 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008777 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8778
Bram Moolenaar8820b482017-03-16 17:23:31 +01008779 msg_source(HL_ATTR(HLF_W));
Bram Moolenaar32526b32019-01-19 17:43:09 +01008780 msg_attr(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008781#ifdef FEAT_EVAL
8782 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8783#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008784 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008785
Bram Moolenaar071d4272004-06-13 20:20:40 +00008786 /* set 'delcombine' */
8787 p_deco = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008788
8789# ifdef FEAT_KEYMAP
8790 /* Force-set the necessary keymap for arabic */
8791 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8792 OPT_LOCAL);
8793# endif
8794# ifdef FEAT_FKMAP
8795 p_altkeymap = 0;
8796 p_hkmap = 0;
8797 p_fkmap = 0;
8798 (void)init_chartab();
8799# endif
8800 }
8801 else
8802 {
8803 /*
8804 * 'arabic' is reset, handle various sub-settings.
8805 */
8806 if (!p_tbidi)
8807 {
8808 /* reset rightleft mode */
8809 if (curwin->w_p_rl)
8810 {
8811 curwin->w_p_rl = FALSE;
8812 changed_window_setting();
8813 }
8814
8815 /* 'arabicshape' isn't reset, it is a global option and
8816 * another window may still need it "on". */
8817 }
8818
8819 /* 'delcombine' isn't reset, it is a global option and another
8820 * window may still want it "on". */
8821
8822# ifdef FEAT_KEYMAP
8823 /* Revert to the default keymap */
8824 curbuf->b_p_iminsert = B_IMODE_NONE;
8825 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8826# endif
8827 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008828 }
8829
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008830#endif
8831
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008832#ifdef FEAT_TERMGUICOLORS
8833 /* 'termguicolors' */
8834 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008835 {
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008836# ifdef FEAT_VTP
8837 /* Do not turn on 'tgc' when 24-bit colors are not supported. */
8838 if (!has_vtp_working())
8839 {
8840 p_tgc = 0;
8841 return (char_u*)N_("E954: 24-bit colors are not supported on this environment");
8842 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008843 if (is_term_win32())
8844 swap_tcap();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008845# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008846# ifdef FEAT_GUI
8847 if (!gui.in_use && !gui.starting)
8848# endif
8849 highlight_gui_started();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008850# ifdef FEAT_VTP
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008851 /* reset t_Co */
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008852 if (is_term_win32())
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02008853 {
8854 control_console_color_rgb();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008855 set_termname(T_NAME);
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02008856 init_highlight(TRUE, FALSE);
8857 }
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008858# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008859 }
8860#endif
8861
Bram Moolenaar071d4272004-06-13 20:20:40 +00008862 /*
8863 * End of handling side effects for bool options.
8864 */
8865
Bram Moolenaar53744302015-07-17 17:38:22 +02008866 /* after handling side effects, call autocommand */
8867
Bram Moolenaar071d4272004-06-13 20:20:40 +00008868 options[opt_idx].flags |= P_WAS_SET;
8869
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008870#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02008871 // Don't do this while starting up or recursively.
8872 if (!starting && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02008873 {
8874 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02008875
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008876 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8877 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8878 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008879 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8880 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8881 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8882 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8883 reset_v_option_vars();
8884 }
8885#endif
8886
Bram Moolenaar071d4272004-06-13 20:20:40 +00008887 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008888 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008889 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008890 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008891 check_redraw(options[opt_idx].flags);
8892
8893 return NULL;
8894}
8895
8896/*
8897 * Set the value of a number option, and take care of side effects.
8898 * Returns NULL for success, or an error message for an error.
8899 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008900 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008901set_num_option(
8902 int opt_idx, /* index in options[] table */
8903 char_u *varp, /* pointer to the option variable */
8904 long value, /* new value */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008905 char *errbuf, /* buffer for error messages */
Bram Moolenaar9b578142016-01-30 19:39:49 +01008906 size_t errbuflen, /* length of "errbuf" */
8907 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008908 OPT_MODELINE */
8909{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008910 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008911 long old_value = *(long *)varp;
8912 long old_Rows = Rows; /* remember old Rows */
8913 long old_Columns = Columns; /* remember old Columns */
8914 long *pp = (long *)varp;
8915
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008916 /* Disallow changing some options from secure mode. */
8917 if ((secure
8918#ifdef HAVE_SANDBOX
8919 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008920#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008921 ) && (options[opt_idx].flags & P_SECURE))
8922 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008923
8924 *pp = value;
8925#ifdef FEAT_EVAL
8926 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008927 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008928#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008929#ifdef FEAT_GUI
8930 need_mouse_correct = TRUE;
8931#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008932
Bram Moolenaar14f24742012-08-08 18:01:05 +02008933 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008934 {
8935 errmsg = e_positive;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02008936#ifdef FEAT_VARTABS
8937 // Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use.
8938 curbuf->b_p_sw = tabstop_count(curbuf->b_p_vts_array) > 0
8939 ? tabstop_first(curbuf->b_p_vts_array)
8940 : curbuf->b_p_ts;
8941#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00008942 curbuf->b_p_sw = curbuf->b_p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02008943#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008944 }
8945
8946 /*
8947 * Number options that need some action when changed
8948 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008949 if (pp == &p_wh || pp == &p_hh)
8950 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008951 // 'winheight' and 'helpheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008952 if (p_wh < 1)
8953 {
8954 errmsg = e_positive;
8955 p_wh = 1;
8956 }
8957 if (p_wmh > p_wh)
8958 {
8959 errmsg = e_winheight;
8960 p_wh = p_wmh;
8961 }
8962 if (p_hh < 0)
8963 {
8964 errmsg = e_positive;
8965 p_hh = 0;
8966 }
8967
8968 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008969 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008970 {
8971 if (pp == &p_wh && curwin->w_height < p_wh)
8972 win_setheight((int)p_wh);
8973 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8974 win_setheight((int)p_hh);
8975 }
8976 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008977 else if (pp == &p_wmh)
8978 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008979 // 'winminheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008980 if (p_wmh < 0)
8981 {
8982 errmsg = e_positive;
8983 p_wmh = 0;
8984 }
8985 if (p_wmh > p_wh)
8986 {
8987 errmsg = e_winheight;
8988 p_wmh = p_wh;
8989 }
8990 win_setminheight();
8991 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008992 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008993 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008994 // 'winwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008995 if (p_wiw < 1)
8996 {
8997 errmsg = e_positive;
8998 p_wiw = 1;
8999 }
9000 if (p_wmw > p_wiw)
9001 {
9002 errmsg = e_winwidth;
9003 p_wiw = p_wmw;
9004 }
9005
9006 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01009007 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009008 win_setwidth((int)p_wiw);
9009 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009010 else if (pp == &p_wmw)
9011 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009012 // 'winminwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009013 if (p_wmw < 0)
9014 {
9015 errmsg = e_positive;
9016 p_wmw = 0;
9017 }
9018 if (p_wmw > p_wiw)
9019 {
9020 errmsg = e_winwidth;
9021 p_wmw = p_wiw;
9022 }
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009023 win_setminwidth();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009024 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009025
Bram Moolenaar071d4272004-06-13 20:20:40 +00009026 /* (re)set last window status line */
9027 else if (pp == &p_ls)
9028 {
9029 last_status(FALSE);
9030 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009031
9032 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00009033 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009034 {
9035 shell_new_rows(); /* recompute window positions and heights */
9036 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009037
9038#ifdef FEAT_GUI
9039 else if (pp == &p_linespace)
9040 {
Bram Moolenaar02743632005-07-25 20:42:36 +00009041 /* Recompute gui.char_height and resize the Vim window to keep the
9042 * same number of lines. */
9043 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00009044 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009045 }
9046#endif
9047
9048#ifdef FEAT_FOLDING
9049 /* 'foldlevel' */
9050 else if (pp == &curwin->w_p_fdl)
9051 {
9052 if (curwin->w_p_fdl < 0)
9053 curwin->w_p_fdl = 0;
9054 newFoldLevel();
9055 }
9056
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00009057 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009058 else if (pp == &curwin->w_p_fml)
9059 {
9060 foldUpdateAll(curwin);
9061 }
9062
9063 /* 'foldnestmax' */
9064 else if (pp == &curwin->w_p_fdn)
9065 {
9066 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
9067 foldUpdateAll(curwin);
9068 }
9069
9070 /* 'foldcolumn' */
9071 else if (pp == &curwin->w_p_fdc)
9072 {
9073 if (curwin->w_p_fdc < 0)
9074 {
9075 errmsg = e_positive;
9076 curwin->w_p_fdc = 0;
9077 }
9078 else if (curwin->w_p_fdc > 12)
9079 {
9080 errmsg = e_invarg;
9081 curwin->w_p_fdc = 12;
9082 }
9083 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009084#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009085
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009086#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009087 /* 'shiftwidth' or 'tabstop' */
9088 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
9089 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009090# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00009091 if (foldmethodIsIndent(curwin))
9092 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009093# endif
9094# ifdef FEAT_CINDENT
9095 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
9096 * parse 'cinoptions'. */
9097 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
9098 parse_cino(curbuf);
9099# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009100 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009101#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009102
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009103 /* 'maxcombine' */
9104 else if (pp == &p_mco)
9105 {
9106 if (p_mco > MAX_MCO)
9107 p_mco = MAX_MCO;
9108 else if (p_mco < 0)
9109 p_mco = 0;
9110 screenclear(); /* will re-allocate the screen */
9111 }
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009112
Bram Moolenaar071d4272004-06-13 20:20:40 +00009113 else if (pp == &curbuf->b_p_iminsert)
9114 {
9115 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
9116 {
9117 errmsg = e_invarg;
9118 curbuf->b_p_iminsert = B_IMODE_NONE;
9119 }
9120 p_iminsert = curbuf->b_p_iminsert;
9121 if (termcap_active) /* don't do this in the alternate screen */
9122 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02009123#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009124 /* Show/unshow value of 'keymap' in status lines. */
9125 status_redraw_curbuf();
9126#endif
9127 }
9128
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02009129#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
9130 /* 'imstyle' */
9131 else if (pp == &p_imst)
9132 {
9133 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
9134 errmsg = e_invarg;
9135 }
9136#endif
9137
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009138 else if (pp == &p_window)
9139 {
9140 if (p_window < 1)
9141 p_window = 1;
9142 else if (p_window >= Rows)
9143 p_window = Rows - 1;
9144 }
9145
Bram Moolenaar071d4272004-06-13 20:20:40 +00009146 else if (pp == &curbuf->b_p_imsearch)
9147 {
9148 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
9149 {
9150 errmsg = e_invarg;
9151 curbuf->b_p_imsearch = B_IMODE_NONE;
9152 }
9153 p_imsearch = curbuf->b_p_imsearch;
9154 }
9155
9156#ifdef FEAT_TITLE
9157 /* if 'titlelen' has changed, redraw the title */
9158 else if (pp == &p_titlelen)
9159 {
9160 if (p_titlelen < 0)
9161 {
9162 errmsg = e_positive;
9163 p_titlelen = 85;
9164 }
9165 if (starting != NO_SCREEN && old_value != p_titlelen)
9166 need_maketitle = TRUE;
9167 }
9168#endif
9169
9170 /* if p_ch changed value, change the command line height */
9171 else if (pp == &p_ch)
9172 {
9173 if (p_ch < 1)
9174 {
9175 errmsg = e_positive;
9176 p_ch = 1;
9177 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009178 if (p_ch > Rows - min_rows() + 1)
9179 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009180
9181 /* Only compute the new window layout when startup has been
9182 * completed. Otherwise the frame sizes may be wrong. */
9183 if (p_ch != old_value && full_screen
9184#ifdef FEAT_GUI
9185 && !gui.starting
9186#endif
9187 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009188 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009189 }
9190
9191 /* when 'updatecount' changes from zero to non-zero, open swap files */
9192 else if (pp == &p_uc)
9193 {
9194 if (p_uc < 0)
9195 {
9196 errmsg = e_positive;
9197 p_uc = 100;
9198 }
9199 if (p_uc && !old_value)
9200 ml_open_files();
9201 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009202#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009203 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009204 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009205 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009206 {
9207 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009208 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009209 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009210 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009211 {
9212 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009213 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009214 }
9215 }
9216#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009217#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009218 else if (pp == &p_mzq)
9219 mzvim_reset_timer();
9220#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009221
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009222#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9223 /* 'pyxversion' */
9224 else if (pp == &p_pyx)
9225 {
9226 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9227 errmsg = e_invarg;
9228 }
9229#endif
9230
Bram Moolenaar071d4272004-06-13 20:20:40 +00009231 /* sync undo before 'undolevels' changes */
9232 else if (pp == &p_ul)
9233 {
9234 /* use the old value, otherwise u_sync() may not work properly */
9235 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009236 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009237 p_ul = value;
9238 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009239 else if (pp == &curbuf->b_p_ul)
9240 {
9241 /* use the old value, otherwise u_sync() may not work properly */
9242 curbuf->b_p_ul = old_value;
9243 u_sync(TRUE);
9244 curbuf->b_p_ul = value;
9245 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009246
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009247#ifdef FEAT_LINEBREAK
9248 /* 'numberwidth' must be positive */
9249 else if (pp == &curwin->w_p_nuw)
9250 {
9251 if (curwin->w_p_nuw < 1)
9252 {
9253 errmsg = e_positive;
9254 curwin->w_p_nuw = 1;
9255 }
9256 if (curwin->w_p_nuw > 10)
9257 {
9258 errmsg = e_invarg;
9259 curwin->w_p_nuw = 10;
9260 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009261 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009262 }
9263#endif
9264
Bram Moolenaar1a384422010-07-14 19:53:30 +02009265 else if (pp == &curbuf->b_p_tw)
9266 {
9267 if (curbuf->b_p_tw < 0)
9268 {
9269 errmsg = e_positive;
9270 curbuf->b_p_tw = 0;
9271 }
9272#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009273 {
9274 win_T *wp;
9275 tabpage_T *tp;
9276
9277 FOR_ALL_TAB_WINDOWS(tp, wp)
9278 check_colorcolumn(wp);
9279 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009280#endif
9281 }
9282
Bram Moolenaar071d4272004-06-13 20:20:40 +00009283 /*
9284 * Check the bounds for numeric options here
9285 */
9286 if (Rows < min_rows() && full_screen)
9287 {
9288 if (errbuf != NULL)
9289 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009290 vim_snprintf((char *)errbuf, errbuflen,
9291 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009292 errmsg = errbuf;
9293 }
9294 Rows = min_rows();
9295 }
9296 if (Columns < MIN_COLUMNS && full_screen)
9297 {
9298 if (errbuf != NULL)
9299 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009300 vim_snprintf((char *)errbuf, errbuflen,
9301 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009302 errmsg = errbuf;
9303 }
9304 Columns = MIN_COLUMNS;
9305 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009306 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009307
Bram Moolenaar071d4272004-06-13 20:20:40 +00009308 /*
9309 * If the screen (shell) height has been changed, assume it is the
9310 * physical screenheight.
9311 */
9312 if (old_Rows != Rows || old_Columns != Columns)
9313 {
9314 /* Changing the screen size is not allowed while updating the screen. */
9315 if (updating_screen)
9316 *pp = old_value;
9317 else if (full_screen
9318#ifdef FEAT_GUI
9319 && !gui.starting
9320#endif
9321 )
9322 set_shellsize((int)Columns, (int)Rows, TRUE);
9323 else
9324 {
9325 /* Postpone the resizing; check the size and cmdline position for
9326 * messages. */
9327 check_shellsize();
9328 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9329 cmdline_row = Rows - p_ch;
9330 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009331 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009332 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009333 }
9334
Bram Moolenaar071d4272004-06-13 20:20:40 +00009335 if (curbuf->b_p_ts <= 0)
9336 {
9337 errmsg = e_positive;
9338 curbuf->b_p_ts = 8;
9339 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009340 if (p_tm < 0)
9341 {
9342 errmsg = e_positive;
9343 p_tm = 0;
9344 }
9345 if ((curwin->w_p_scr <= 0
9346 || (curwin->w_p_scr > curwin->w_height
9347 && curwin->w_height > 0))
9348 && full_screen)
9349 {
9350 if (pp == &(curwin->w_p_scr))
9351 {
9352 if (curwin->w_p_scr != 0)
9353 errmsg = e_scroll;
9354 win_comp_scroll(curwin);
9355 }
9356 /* If 'scroll' became invalid because of a side effect silently adjust
9357 * it. */
9358 else if (curwin->w_p_scr <= 0)
9359 curwin->w_p_scr = 1;
9360 else /* curwin->w_p_scr > curwin->w_height */
9361 curwin->w_p_scr = curwin->w_height;
9362 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009363 if (p_hi < 0)
9364 {
9365 errmsg = e_positive;
9366 p_hi = 0;
9367 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009368 else if (p_hi > 10000)
9369 {
9370 errmsg = e_invarg;
9371 p_hi = 10000;
9372 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009373 if (p_re < 0 || p_re > 2)
9374 {
9375 errmsg = e_invarg;
9376 p_re = 0;
9377 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009378 if (p_report < 0)
9379 {
9380 errmsg = e_positive;
9381 p_report = 1;
9382 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009383 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009384 {
9385 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9386 p_sj = Rows / 2;
9387 else
9388 {
9389 errmsg = e_scroll;
9390 p_sj = 1;
9391 }
9392 }
9393 if (p_so < 0 && full_screen)
9394 {
Bram Moolenaar375e3392019-01-31 18:26:10 +01009395 errmsg = e_positive;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009396 p_so = 0;
9397 }
9398 if (p_siso < 0 && full_screen)
9399 {
9400 errmsg = e_positive;
9401 p_siso = 0;
9402 }
9403#ifdef FEAT_CMDWIN
9404 if (p_cwh < 1)
9405 {
9406 errmsg = e_positive;
9407 p_cwh = 1;
9408 }
9409#endif
9410 if (p_ut < 0)
9411 {
9412 errmsg = e_positive;
9413 p_ut = 2000;
9414 }
9415 if (p_ss < 0)
9416 {
9417 errmsg = e_positive;
9418 p_ss = 0;
9419 }
9420
9421 /* May set global value for local option. */
9422 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9423 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9424
9425 options[opt_idx].flags |= P_WAS_SET;
9426
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009427#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009428 // Don't do this while starting up, failure or recursively.
9429 if (!starting && errmsg == NULL && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009430 {
9431 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009432 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9433 vim_snprintf((char *)buf_new, 10, "%ld", value);
9434 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009435 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9436 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9437 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9438 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9439 reset_v_option_vars();
9440 }
9441#endif
9442
Bram Moolenaar071d4272004-06-13 20:20:40 +00009443 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009444 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009445 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009446 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009447 check_redraw(options[opt_idx].flags);
9448
9449 return errmsg;
9450}
9451
9452/*
9453 * Called after an option changed: check if something needs to be redrawn.
9454 */
9455 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009456check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009457{
9458 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009459 int doclear = (flags & P_RCLR) == P_RCLR;
9460 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009461
Bram Moolenaar071d4272004-06-13 20:20:40 +00009462 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9463 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009464
9465 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9466 changed_window_setting();
9467 if (flags & P_RBUF)
9468 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009469 if (flags & P_RWINONLY)
9470 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009471 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009472 redraw_all_later(CLEAR);
9473 else if (all)
9474 redraw_all_later(NOT_VALID);
9475}
9476
9477/*
9478 * Find index for option 'arg'.
9479 * Return -1 if not found.
9480 */
9481 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009482findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009483{
9484 int opt_idx;
9485 char *s, *p;
9486 static short quick_tab[27] = {0, 0}; /* quick access table */
9487 int is_term_opt;
9488
9489 /*
9490 * For first call: Initialize the quick-access table.
9491 * It contains the index for the first option that starts with a certain
9492 * letter. There are 26 letters, plus the first "t_" option.
9493 */
9494 if (quick_tab[1] == 0)
9495 {
9496 p = options[0].fullname;
9497 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9498 {
9499 if (s[0] != p[0])
9500 {
9501 if (s[0] == 't' && s[1] == '_')
9502 quick_tab[26] = opt_idx;
9503 else
9504 quick_tab[CharOrdLow(s[0])] = opt_idx;
9505 }
9506 p = s;
9507 }
9508 }
9509
9510 /*
9511 * Check for name starting with an illegal character.
9512 */
9513#ifdef EBCDIC
9514 if (!islower(arg[0]))
9515#else
9516 if (arg[0] < 'a' || arg[0] > 'z')
9517#endif
9518 return -1;
9519
9520 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9521 if (is_term_opt)
9522 opt_idx = quick_tab[26];
9523 else
9524 opt_idx = quick_tab[CharOrdLow(arg[0])];
9525 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9526 {
9527 if (STRCMP(arg, s) == 0) /* match full name */
9528 break;
9529 }
9530 if (s == NULL && !is_term_opt)
9531 {
9532 opt_idx = quick_tab[CharOrdLow(arg[0])];
9533 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9534 {
9535 s = options[opt_idx].shortname;
9536 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9537 break;
9538 s = NULL;
9539 }
9540 }
9541 if (s == NULL)
9542 opt_idx = -1;
9543 return opt_idx;
9544}
9545
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009546#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009547/*
9548 * Get the value for an option.
9549 *
9550 * Returns:
9551 * Number or Toggle option: 1, *numval gets value.
9552 * String option: 0, *stringval gets allocated string.
9553 * Hidden Number or Toggle option: -1.
9554 * hidden String option: -2.
9555 * unknown option: -3.
9556 */
9557 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009558get_option_value(
9559 char_u *name,
9560 long *numval,
9561 char_u **stringval, /* NULL when only checking existence */
9562 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009563{
9564 int opt_idx;
9565 char_u *varp;
9566
9567 opt_idx = findoption(name);
9568 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009569 {
9570 int key;
9571
9572 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009573 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009574 {
9575 char_u key_name[2];
9576 char_u *p;
9577
9578 if (key < 0)
9579 {
9580 key_name[0] = KEY2TERMCAP0(key);
9581 key_name[1] = KEY2TERMCAP1(key);
9582 }
9583 else
9584 {
9585 key_name[0] = KS_KEY;
9586 key_name[1] = (key & 0xff);
9587 }
9588 p = find_termcode(key_name);
9589 if (p != NULL)
9590 {
9591 if (stringval != NULL)
9592 *stringval = vim_strsave(p);
9593 return 0;
9594 }
9595 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009596 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009597 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009598
9599 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9600
9601 if (options[opt_idx].flags & P_STRING)
9602 {
9603 if (varp == NULL) /* hidden option */
9604 return -2;
9605 if (stringval != NULL)
9606 {
9607#ifdef FEAT_CRYPT
9608 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009609 if ((char_u **)varp == &curbuf->b_p_key
9610 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009611 *stringval = vim_strsave((char_u *)"*****");
9612 else
9613#endif
9614 *stringval = vim_strsave(*(char_u **)(varp));
9615 }
9616 return 0;
9617 }
9618
9619 if (varp == NULL) /* hidden option */
9620 return -1;
9621 if (options[opt_idx].flags & P_NUM)
9622 *numval = *(long *)varp;
9623 else
9624 {
9625 /* Special case: 'modified' is b_changed, but we also want to consider
9626 * it set when 'ff' or 'fenc' changed. */
9627 if ((int *)varp == &curbuf->b_changed)
9628 *numval = curbufIsChanged();
9629 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009630 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009631 }
9632 return 1;
9633}
9634#endif
9635
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009636#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009637/*
9638 * Returns the option attributes and its value. Unlike the above function it
9639 * will return either global value or local value of the option depending on
9640 * what was requested, but it will never return global value if it was
9641 * requested to return local one and vice versa. Neither it will return
9642 * buffer-local value if it was requested to return window-local one.
9643 *
9644 * Pretends that option is absent if it is not present in the requested scope
9645 * (i.e. has no global, window-local or buffer-local value depending on
9646 * opt_type). Uses
9647 *
9648 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009649 * 0 hidden or unknown option, also option that does not have requested
9650 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009651 * see SOPT_* in vim.h for other flags
9652 *
9653 * Possible opt_type values: see SREQ_* in vim.h
9654 */
9655 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009656get_option_value_strict(
9657 char_u *name,
9658 long *numval,
9659 char_u **stringval, /* NULL when only obtaining attributes */
9660 int opt_type,
9661 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009662{
9663 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009664 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009665 struct vimoption *p;
9666 int r = 0;
9667
9668 opt_idx = findoption(name);
9669 if (opt_idx < 0)
9670 return 0;
9671
9672 p = &(options[opt_idx]);
9673
9674 /* Hidden option */
9675 if (p->var == NULL)
9676 return 0;
9677
9678 if (p->flags & P_BOOL)
9679 r |= SOPT_BOOL;
9680 else if (p->flags & P_NUM)
9681 r |= SOPT_NUM;
9682 else if (p->flags & P_STRING)
9683 r |= SOPT_STRING;
9684
9685 if (p->indir == PV_NONE)
9686 {
9687 if (opt_type == SREQ_GLOBAL)
9688 r |= SOPT_GLOBAL;
9689 else
9690 return 0; /* Did not request global-only option */
9691 }
9692 else
9693 {
9694 if (p->indir & PV_BOTH)
9695 r |= SOPT_GLOBAL;
9696 else if (opt_type == SREQ_GLOBAL)
9697 return 0; /* Requested global option */
9698
9699 if (p->indir & PV_WIN)
9700 {
9701 if (opt_type == SREQ_BUF)
9702 return 0; /* Did not request window-local option */
9703 else
9704 r |= SOPT_WIN;
9705 }
9706 else if (p->indir & PV_BUF)
9707 {
9708 if (opt_type == SREQ_WIN)
9709 return 0; /* Did not request buffer-local option */
9710 else
9711 r |= SOPT_BUF;
9712 }
9713 }
9714
9715 if (stringval == NULL)
9716 return r;
9717
9718 if (opt_type == SREQ_GLOBAL)
9719 varp = p->var;
9720 else
9721 {
9722 if (opt_type == SREQ_BUF)
9723 {
9724 /* Special case: 'modified' is b_changed, but we also want to
9725 * consider it set when 'ff' or 'fenc' changed. */
9726 if (p->indir == PV_MOD)
9727 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009728 *numval = bufIsChanged((buf_T *)from);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009729 varp = NULL;
9730 }
9731#ifdef FEAT_CRYPT
9732 else if (p->indir == PV_KEY)
9733 {
9734 /* never return the value of the crypt key */
9735 *stringval = NULL;
9736 varp = NULL;
9737 }
9738#endif
9739 else
9740 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009741 buf_T *save_curbuf = curbuf;
9742
9743 // only getting a pointer, no need to use aucmd_prepbuf()
9744 curbuf = (buf_T *)from;
9745 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009746 varp = get_varp(p);
Bram Moolenaardefe6422018-06-24 15:14:07 +02009747 curbuf = save_curbuf;
9748 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009749 }
9750 }
9751 else if (opt_type == SREQ_WIN)
9752 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009753 win_T *save_curwin = curwin;
9754
9755 curwin = (win_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009756 curbuf = curwin->w_buffer;
9757 varp = get_varp(p);
9758 curwin = save_curwin;
9759 curbuf = curwin->w_buffer;
9760 }
9761 if (varp == p->var)
9762 return (r | SOPT_UNSET);
9763 }
9764
9765 if (varp != NULL)
9766 {
9767 if (p->flags & P_STRING)
9768 *stringval = vim_strsave(*(char_u **)(varp));
9769 else if (p->flags & P_NUM)
9770 *numval = *(long *) varp;
9771 else
9772 *numval = *(int *)varp;
9773 }
9774
9775 return r;
9776}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009777
9778/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009779 * Iterate over options. First argument is a pointer to a pointer to a
9780 * structure inside options[] array, second is option type like in the above
9781 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009782 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009783 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009784 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009785 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009786 * first argument to NULL.
9787 *
9788 * Returns full option name for current option on each call.
9789 */
9790 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009791option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009792{
9793 struct vimoption *ret = NULL;
9794 do
9795 {
9796 if (*option == NULL)
9797 *option = (void *) options;
9798 else if (((struct vimoption *) (*option))->fullname == NULL)
9799 {
9800 *option = NULL;
9801 return NULL;
9802 }
9803 else
9804 *option = (void *) (((struct vimoption *) (*option)) + 1);
9805
9806 ret = ((struct vimoption *) (*option));
9807
9808 /* Hidden option */
9809 if (ret->var == NULL)
9810 {
9811 ret = NULL;
9812 continue;
9813 }
9814
9815 switch (opt_type)
9816 {
9817 case SREQ_GLOBAL:
9818 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9819 ret = NULL;
9820 break;
9821 case SREQ_BUF:
9822 if (!(ret->indir & PV_BUF))
9823 ret = NULL;
9824 break;
9825 case SREQ_WIN:
9826 if (!(ret->indir & PV_WIN))
9827 ret = NULL;
9828 break;
9829 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009830 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009831 return NULL;
9832 }
9833 }
9834 while (ret == NULL);
9835
9836 return (char_u *)ret->fullname;
9837}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009838#endif
9839
Bram Moolenaar071d4272004-06-13 20:20:40 +00009840/*
9841 * Set the value of option "name".
9842 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009843 *
9844 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009845 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009846 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009847set_option_value(
9848 char_u *name,
9849 long number,
9850 char_u *string,
9851 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009852{
9853 int opt_idx;
9854 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009855 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009856
9857 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009858 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009859 {
9860 int key;
9861
9862 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009863 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009864 {
9865 char_u key_name[2];
9866
9867 if (key < 0)
9868 {
9869 key_name[0] = KEY2TERMCAP0(key);
9870 key_name[1] = KEY2TERMCAP1(key);
9871 }
9872 else
9873 {
9874 key_name[0] = KS_KEY;
9875 key_name[1] = (key & 0xff);
9876 }
9877 add_termcode(key_name, string, FALSE);
9878 if (full_screen)
9879 ttest(FALSE);
9880 redraw_all_later(CLEAR);
9881 return NULL;
9882 }
9883
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009884 semsg(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009885 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009886 else
9887 {
9888 flags = options[opt_idx].flags;
9889#ifdef HAVE_SANDBOX
9890 /* Disallow changing some options in the sandbox */
9891 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009892 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009893 emsg(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009894 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009895 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009896#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009897 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009898 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009899 else
9900 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009901 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009902 if (varp != NULL) /* hidden option is not changed */
9903 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009904 if (number == 0 && string != NULL)
9905 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009906 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009907
9908 /* Either we are given a string or we are setting option
9909 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009910 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009911 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009912 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009913 {
9914 /* There's another character after zeros or the string
9915 * is empty. In both cases, we are trying to set a
9916 * num option using a string. */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009917 semsg(_("E521: Number required: &%s = '%s'"),
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009918 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009919 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009920
9921 }
9922 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009923 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009924 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009925 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009926 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009927 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009928 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009929 }
9930 }
9931 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009932 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009933}
9934
9935/*
9936 * Get the terminal code for a terminal option.
9937 * Returns NULL when not found.
9938 */
9939 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009940get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009941{
9942 int opt_idx;
9943 char_u *varp;
9944
9945 if (tname[0] != 't' || tname[1] != '_' ||
9946 tname[2] == NUL || tname[3] == NUL)
9947 return NULL;
9948 if ((opt_idx = findoption(tname)) >= 0)
9949 {
9950 varp = get_varp(&(options[opt_idx]));
9951 if (varp != NULL)
9952 varp = *(char_u **)(varp);
9953 return varp;
9954 }
9955 return find_termcode(tname + 2);
9956}
9957
9958 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009959get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009960{
9961 int i;
9962
9963 i = findoption((char_u *)"hl");
9964 if (i >= 0)
9965 return options[i].def_val[VI_DEFAULT];
9966 return (char_u *)NULL;
9967}
9968
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009969 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009970get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009971{
9972 int i;
9973
9974 i = findoption((char_u *)"enc");
9975 if (i >= 0)
9976 return options[i].def_val[VI_DEFAULT];
9977 return (char_u *)NULL;
9978}
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009979
Bram Moolenaar071d4272004-06-13 20:20:40 +00009980/*
9981 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009982 * When "has_lt" is true there is a '<' before "*arg_arg".
9983 * Returns 0 when the key is not recognized.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009984 */
9985 static int
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009986find_key_option(char_u *arg_arg, int has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009987{
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009988 int key = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009989 int modifiers;
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009990 char_u *arg = arg_arg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009991
9992 /*
9993 * Don't use get_special_key_code() for t_xx, we don't want it to call
9994 * add_termcap_entry().
9995 */
9996 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9997 key = TERMCAP2KEY(arg[2], arg[3]);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009998 else if (has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009999 {
10000 --arg; /* put arg at the '<' */
10001 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +020010002 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010003 if (modifiers) /* can't handle modifiers here */
10004 key = 0;
10005 }
10006 return key;
10007}
10008
10009/*
10010 * if 'all' == 0: show changed options
10011 * if 'all' == 1: show all normal options
10012 * if 'all' == 2: show all terminal options
10013 */
10014 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010015showoptions(
10016 int all,
10017 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010018{
10019 struct vimoption *p;
10020 int col;
10021 int isterm;
10022 char_u *varp;
10023 struct vimoption **items;
10024 int item_count;
10025 int run;
10026 int row, rows;
10027 int cols;
10028 int i;
10029 int len;
10030
10031#define INC 20
10032#define GAP 3
10033
10034 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
10035 PARAM_COUNT));
10036 if (items == NULL)
10037 return;
10038
10039 /* Highlight title */
10040 if (all == 2)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010041 msg_puts_title(_("\n--- Terminal codes ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010042 else if (opt_flags & OPT_GLOBAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010043 msg_puts_title(_("\n--- Global option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010044 else if (opt_flags & OPT_LOCAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010045 msg_puts_title(_("\n--- Local option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010046 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010047 msg_puts_title(_("\n--- Options ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010048
10049 /*
10050 * do the loop two times:
10051 * 1. display the short items
10052 * 2. display the long items (only strings and numbers)
10053 */
10054 for (run = 1; run <= 2 && !got_int; ++run)
10055 {
10056 /*
10057 * collect the items in items[]
10058 */
10059 item_count = 0;
10060 for (p = &options[0]; p->fullname != NULL; p++)
10061 {
Bram Moolenaarf86db782018-10-25 13:31:37 +020010062 // apply :filter /pat/
10063 if (message_filtered((char_u *) p->fullname))
10064 continue;
10065
Bram Moolenaar071d4272004-06-13 20:20:40 +000010066 varp = NULL;
10067 isterm = istermoption(p);
10068 if (opt_flags != 0)
10069 {
10070 if (p->indir != PV_NONE && !isterm)
10071 varp = get_varp_scope(p, opt_flags);
10072 }
10073 else
10074 varp = get_varp(p);
10075 if (varp != NULL
10076 && ((all == 2 && isterm)
10077 || (all == 1 && !isterm)
10078 || (all == 0 && !optval_default(p, varp))))
10079 {
10080 if (p->flags & P_BOOL)
10081 len = 1; /* a toggle option fits always */
10082 else
10083 {
10084 option_value2string(p, opt_flags);
10085 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
10086 }
10087 if ((len <= INC - GAP && run == 1) ||
10088 (len > INC - GAP && run == 2))
10089 items[item_count++] = p;
10090 }
10091 }
10092
10093 /*
10094 * display the items
10095 */
10096 if (run == 1)
10097 {
10098 cols = (Columns + GAP - 3) / INC;
10099 if (cols == 0)
10100 cols = 1;
10101 rows = (item_count + cols - 1) / cols;
10102 }
10103 else /* run == 2 */
10104 rows = item_count;
10105 for (row = 0; row < rows && !got_int; ++row)
10106 {
10107 msg_putchar('\n'); /* go to next line */
10108 if (got_int) /* 'q' typed in more */
10109 break;
10110 col = 0;
10111 for (i = row; i < item_count; i += rows)
10112 {
10113 msg_col = col; /* make columns */
10114 showoneopt(items[i], opt_flags);
10115 col += INC;
10116 }
10117 out_flush();
10118 ui_breakcheck();
10119 }
10120 }
10121 vim_free(items);
10122}
10123
10124/*
10125 * Return TRUE if option "p" has its default value.
10126 */
10127 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010128optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010129{
10130 int dvi;
10131
10132 if (varp == NULL)
10133 return TRUE; /* hidden option is always at default */
10134 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
10135 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010136 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010137 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010138 /* the cast to long is required for Manx C, long_i is
10139 * needed for MSVC */
10140 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010141 /* P_STRING */
10142 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
10143}
10144
10145/*
10146 * showoneopt: show the value of one option
10147 * must not be called with a hidden option!
10148 */
10149 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010150showoneopt(
10151 struct vimoption *p,
10152 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010153{
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010154 char_u *varp;
10155 int save_silent = silent_mode;
10156
10157 silent_mode = FALSE;
10158 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010159
10160 varp = get_varp_scope(p, opt_flags);
10161
10162 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
10163 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
10164 ? !curbufIsChanged() : !*(int *)varp))
Bram Moolenaar32526b32019-01-19 17:43:09 +010010165 msg_puts("no");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010166 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010167 msg_puts("--");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010168 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010169 msg_puts(" ");
10170 msg_puts(p->fullname);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010171 if (!(p->flags & P_BOOL))
10172 {
10173 msg_putchar('=');
10174 /* put value string in NameBuff */
10175 option_value2string(p, opt_flags);
10176 msg_outtrans(NameBuff);
10177 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010178
10179 silent_mode = save_silent;
10180 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010181}
10182
10183/*
10184 * Write modified options as ":set" commands to a file.
10185 *
10186 * There are three values for "opt_flags":
10187 * OPT_GLOBAL: Write global option values and fresh values of
10188 * buffer-local options (used for start of a session
10189 * file).
10190 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10191 * curwin (used for a vimrc file).
10192 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10193 * and local values for window-local options of
10194 * curwin. Local values are also written when at the
10195 * default value, because a modeline or autocommand
10196 * may have set them when doing ":edit file" and the
10197 * user has set them back at the default or fresh
10198 * value.
10199 * When "local_only" is TRUE, don't write fresh
10200 * values, only local values (for ":mkview").
10201 * (fresh value = value used for a new buffer or window for a local option).
10202 *
10203 * Return FAIL on error, OK otherwise.
10204 */
10205 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010206makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010207{
10208 struct vimoption *p;
10209 char_u *varp; /* currently used value */
10210 char_u *varp_fresh; /* local value */
10211 char_u *varp_local = NULL; /* fresh value */
10212 char *cmd;
10213 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010214 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010215
10216 /*
10217 * The options that don't have a default (terminal name, columns, lines)
10218 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010219 * Do the loop over "options[]" twice: once for options with the
10220 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010221 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010222 for (pri = 1; pri >= 0; --pri)
10223 {
10224 for (p = &options[0]; !istermoption(p); p++)
10225 if (!(p->flags & P_NO_MKRC)
10226 && !istermoption(p)
10227 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010228 {
10229 /* skip global option when only doing locals */
10230 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10231 continue;
10232
10233 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10234 * file, they are always buffer-specific. */
10235 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10236 continue;
10237
10238 /* Global values are only written when not at the default value. */
10239 varp = get_varp_scope(p, opt_flags);
10240 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10241 continue;
10242
10243 round = 2;
10244 if (p->indir != PV_NONE)
10245 {
10246 if (p->var == VAR_WIN)
10247 {
10248 /* skip window-local option when only doing globals */
10249 if (!(opt_flags & OPT_LOCAL))
10250 continue;
10251 /* When fresh value of window-local option is not at the
10252 * default, need to write it too. */
10253 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10254 {
10255 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10256 if (!optval_default(p, varp_fresh))
10257 {
10258 round = 1;
10259 varp_local = varp;
10260 varp = varp_fresh;
10261 }
10262 }
10263 }
10264 }
10265
10266 /* Round 1: fresh value for window-local options.
10267 * Round 2: other values */
10268 for ( ; round <= 2; varp = varp_local, ++round)
10269 {
10270 if (round == 1 || (opt_flags & OPT_GLOBAL))
10271 cmd = "set";
10272 else
10273 cmd = "setlocal";
10274
10275 if (p->flags & P_BOOL)
10276 {
10277 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10278 return FAIL;
10279 }
10280 else if (p->flags & P_NUM)
10281 {
10282 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10283 return FAIL;
10284 }
10285 else /* P_STRING */
10286 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010287 int do_endif = FALSE;
10288
Bram Moolenaar071d4272004-06-13 20:20:40 +000010289 /* Don't set 'syntax' and 'filetype' again if the value is
10290 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010291 if (
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +010010292#if defined(FEAT_SYN_HL)
10293 p->indir == PV_SYN ||
10294#endif
10295 p->indir == PV_FT)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010296 {
10297 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10298 *(char_u **)(varp)) < 0
10299 || put_eol(fd) < 0)
10300 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010301 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010302 }
10303 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010304 p->flags) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010305 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010306 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010307 {
10308 if (put_line(fd, "endif") == FAIL)
10309 return FAIL;
10310 }
10311 }
10312 }
10313 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010314 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010315 return OK;
10316}
10317
10318#if defined(FEAT_FOLDING) || defined(PROTO)
10319/*
10320 * Generate set commands for the local fold options only. Used when
10321 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10322 */
10323 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010324makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010325{
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010326 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, 0) == FAIL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010327# ifdef FEAT_EVAL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010328 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010329 == FAIL
10330# endif
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010331 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010332 == FAIL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010333 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010334 == FAIL
10335 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10336 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10337 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10338 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10339 )
10340 return FAIL;
10341
10342 return OK;
10343}
10344#endif
10345
10346 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010347put_setstring(
10348 FILE *fd,
10349 char *cmd,
10350 char *name,
10351 char_u **valuep,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010352 long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010353{
10354 char_u *s;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010355 char_u *buf = NULL;
10356 char_u *part = NULL;
10357 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010358
10359 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10360 return FAIL;
10361 if (*valuep != NULL)
10362 {
10363 /* Output 'pastetoggle' as key names. For other
10364 * options some characters have to be escaped with
10365 * CTRL-V or backslash */
10366 if (valuep == &p_pt)
10367 {
10368 s = *valuep;
10369 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010370 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010371 return FAIL;
10372 }
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010373 // expand the option value, replace $HOME by ~
10374 else if ((flags & P_EXPAND) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010375 {
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010376 int size = (int)STRLEN(*valuep) + 1;
10377
10378 // replace home directory in the whole option value into "buf"
10379 buf = alloc(size);
Bram Moolenaarf8441472011-04-28 17:24:58 +020010380 if (buf == NULL)
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010381 goto fail;
10382 home_replace(NULL, *valuep, buf, size, FALSE);
10383
10384 // If the option value is longer than MAXPATHL, we need to append
10385 // earch comma separated part of the option separately, so that it
10386 // can be expanded when read back.
10387 if (size >= MAXPATHL && (flags & P_COMMA) != 0
10388 && vim_strchr(*valuep, ',') != NULL)
10389 {
10390 part = alloc(size);
10391 if (part == NULL)
10392 goto fail;
10393
10394 // write line break to clear the option, e.g. ':set rtp='
10395 if (put_eol(fd) == FAIL)
10396 goto fail;
10397
10398 p = buf;
10399 while (*p != NUL)
10400 {
10401 // for each comma separated option part, append value to
10402 // the option, :set rtp+=value
10403 if (fprintf(fd, "%s %s+=", cmd, name) < 0)
10404 goto fail;
10405 (void)copy_option_part(&p, part, size, ",");
10406 if (put_escstr(fd, part, 2) == FAIL || put_eol(fd) == FAIL)
10407 goto fail;
10408 }
10409 vim_free(buf);
10410 vim_free(part);
10411 return OK;
10412 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010413 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010414 {
10415 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010416 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010417 }
10418 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010419 }
10420 else if (put_escstr(fd, *valuep, 2) == FAIL)
10421 return FAIL;
10422 }
10423 if (put_eol(fd) < 0)
10424 return FAIL;
10425 return OK;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010426fail:
10427 vim_free(buf);
10428 vim_free(part);
10429 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010430}
10431
10432 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010433put_setnum(
10434 FILE *fd,
10435 char *cmd,
10436 char *name,
10437 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010438{
10439 long wc;
10440
10441 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10442 return FAIL;
10443 if (wc_use_keyname((char_u *)valuep, &wc))
10444 {
10445 /* print 'wildchar' and 'wildcharm' as a key name */
10446 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10447 return FAIL;
10448 }
10449 else if (fprintf(fd, "%ld", *valuep) < 0)
10450 return FAIL;
10451 if (put_eol(fd) < 0)
10452 return FAIL;
10453 return OK;
10454}
10455
10456 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010457put_setbool(
10458 FILE *fd,
10459 char *cmd,
10460 char *name,
10461 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010462{
Bram Moolenaar893de922007-10-02 18:40:57 +000010463 if (value < 0) /* global/local option using global value */
10464 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010465 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10466 || put_eol(fd) < 0)
10467 return FAIL;
10468 return OK;
10469}
10470
10471/*
10472 * Clear all the terminal options.
10473 * If the option has been allocated, free the memory.
10474 * Terminal options are never hidden or indirect.
10475 */
10476 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010477clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010478{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010479 /*
10480 * Reset a few things before clearing the old options. This may cause
10481 * outputting a few things that the terminal doesn't understand, but the
10482 * screen will be cleared later, so this is OK.
10483 */
10484#ifdef FEAT_MOUSE_TTY
10485 mch_setmouse(FALSE); /* switch mouse off */
10486#endif
10487#ifdef FEAT_TITLE
Bram Moolenaar40385db2018-08-07 22:31:44 +020010488 mch_restore_title(SAVE_RESTORE_BOTH); /* restore window titles */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010489#endif
10490#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10491 /* When starting the GUI close the display opened for the clipboard.
10492 * After restoring the title, because that will need the display. */
10493 if (gui.starting)
10494 clear_xterm_clip();
10495#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010496 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010497
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010498 free_termoptions();
10499}
10500
10501 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010502free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010503{
10504 struct vimoption *p;
10505
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010506 for (p = options; p->fullname != NULL; p++)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010507 if (istermoption(p))
10508 {
10509 if (p->flags & P_ALLOCED)
10510 free_string_option(*(char_u **)(p->var));
10511 if (p->flags & P_DEF_ALLOCED)
10512 free_string_option(p->def_val[VI_DEFAULT]);
10513 *(char_u **)(p->var) = empty_option;
10514 p->def_val[VI_DEFAULT] = empty_option;
10515 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010516#ifdef FEAT_EVAL
10517 // remember where the option was cleared
10518 set_option_sctx_idx((int)(p - options), OPT_GLOBAL, current_sctx);
10519#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010520 }
10521 clear_termcodes();
10522}
10523
10524/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010525 * Free the string for one term option, if it was allocated.
10526 * Set the string to empty_option and clear allocated flag.
10527 * "var" points to the option value.
10528 */
10529 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010530free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010531{
10532 struct vimoption *p;
10533
10534 for (p = &options[0]; p->fullname != NULL; p++)
10535 if (p->var == var)
10536 {
10537 if (p->flags & P_ALLOCED)
10538 free_string_option(*(char_u **)(p->var));
10539 *(char_u **)(p->var) = empty_option;
10540 p->flags &= ~P_ALLOCED;
10541 break;
10542 }
10543}
10544
10545/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010546 * Set the terminal option defaults to the current value.
10547 * Used after setting the terminal name.
10548 */
10549 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010550set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010551{
10552 struct vimoption *p;
10553
10554 for (p = &options[0]; p->fullname != NULL; p++)
10555 {
10556 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10557 {
10558 if (p->flags & P_DEF_ALLOCED)
10559 {
10560 free_string_option(p->def_val[VI_DEFAULT]);
10561 p->flags &= ~P_DEF_ALLOCED;
10562 }
10563 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10564 if (p->flags & P_ALLOCED)
10565 {
10566 p->flags |= P_DEF_ALLOCED;
10567 p->flags &= ~P_ALLOCED; /* don't free the value now */
10568 }
10569 }
10570 }
10571}
10572
10573/*
10574 * return TRUE if 'p' starts with 't_'
10575 */
10576 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010577istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010578{
10579 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10580}
10581
10582/*
10583 * Compute columns for ruler and shown command. 'sc_col' is also used to
10584 * decide what the maximum length of a message on the status line can be.
10585 * If there is a status line for the last window, 'sc_col' is independent
10586 * of 'ru_col'.
10587 */
10588
10589#define COL_RULER 17 /* columns needed by standard ruler */
10590
10591 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010592comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010593{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010594#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010595 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010596
10597 sc_col = 0;
10598 ru_col = 0;
10599 if (p_ru)
10600 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010601# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010602 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010603# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010604 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010605# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010606 /* no last status line, adjust sc_col */
10607 if (!last_has_status)
10608 sc_col = ru_col;
10609 }
10610 if (p_sc)
10611 {
10612 sc_col += SHOWCMD_COLS;
10613 if (!p_ru || last_has_status) /* no need for separating space */
10614 ++sc_col;
10615 }
10616 sc_col = Columns - sc_col;
10617 ru_col = Columns - ru_col;
10618 if (sc_col <= 0) /* screen too narrow, will become a mess */
10619 sc_col = 1;
10620 if (ru_col <= 0)
10621 ru_col = 1;
10622#else
10623 sc_col = Columns;
10624 ru_col = Columns;
10625#endif
10626}
10627
Bram Moolenaar113e1072019-01-20 15:30:40 +010010628#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010629/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010630 * Unset local option value, similar to ":set opt<".
10631 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010632 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010633unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010634{
10635 struct vimoption *p;
10636 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010637 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010638
10639 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010640 if (opt_idx < 0)
10641 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010642 p = &(options[opt_idx]);
10643
10644 switch ((int)p->indir)
10645 {
10646 /* global option with local value: use local value if it's been set */
10647 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010648 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010649 break;
10650 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010651 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010652 break;
10653 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010654 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010655 break;
10656 case PV_AR:
10657 buf->b_p_ar = -1;
10658 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010659 case PV_BKC:
10660 clear_string_option(&buf->b_p_bkc);
10661 buf->b_bkc_flags = 0;
10662 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010663 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010664 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010665 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010666 case PV_TC:
10667 clear_string_option(&buf->b_p_tc);
10668 buf->b_tc_flags = 0;
10669 break;
Bram Moolenaar375e3392019-01-31 18:26:10 +010010670 case PV_SISO:
10671 curwin->w_p_siso = -1;
10672 break;
10673 case PV_SO:
10674 curwin->w_p_so = -1;
10675 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010676#ifdef FEAT_FIND_ID
10677 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010678 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010679 break;
10680 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010681 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010682 break;
10683#endif
10684#ifdef FEAT_INS_EXPAND
10685 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010686 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010687 break;
10688 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010689 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010690 break;
10691#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010692 case PV_FP:
10693 clear_string_option(&buf->b_p_fp);
10694 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010695#ifdef FEAT_QUICKFIX
10696 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010697 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010698 break;
10699 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010700 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010701 break;
10702 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010703 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010704 break;
10705#endif
10706#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10707 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010708 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010709 break;
10710#endif
10711#if defined(FEAT_CRYPT)
10712 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010713 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010714 break;
10715#endif
10716#ifdef FEAT_STL_OPT
10717 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010718 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010719 break;
10720#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010721 case PV_UL:
10722 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10723 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010724#ifdef FEAT_LISP
10725 case PV_LW:
10726 clear_string_option(&buf->b_p_lw);
10727 break;
10728#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010729 case PV_MENC:
10730 clear_string_option(&buf->b_p_menc);
10731 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010732 }
10733}
Bram Moolenaar113e1072019-01-20 15:30:40 +010010734#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010735
10736/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010737 * Get pointer to option variable, depending on local or global scope.
10738 */
10739 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010740get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010741{
10742 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10743 {
10744 if (p->var == VAR_WIN)
10745 return (char_u *)GLOBAL_WO(get_varp(p));
10746 return p->var;
10747 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010748 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010749 {
10750 switch ((int)p->indir)
10751 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010752 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010753#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010754 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10755 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10756 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010757#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010758 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10759 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10760 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010761 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010762 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010763 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar375e3392019-01-31 18:26:10 +010010764 case PV_SISO: return (char_u *)&(curwin->w_p_siso);
10765 case PV_SO: return (char_u *)&(curwin->w_p_so);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010766#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010767 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10768 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010769#endif
10770#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010771 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10772 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010773#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010774#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10775 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10776#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010777#if defined(FEAT_CRYPT)
10778 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10779#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010780#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010781 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010782#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010783 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010784#ifdef FEAT_LISP
10785 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10786#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010787 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010788 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010789 }
10790 return NULL; /* "cannot happen" */
10791 }
10792 return get_varp(p);
10793}
10794
10795/*
10796 * Get pointer to option variable.
10797 */
10798 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010799get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010800{
10801 /* hidden option, always return NULL */
10802 if (p->var == NULL)
10803 return NULL;
10804
10805 switch ((int)p->indir)
10806 {
10807 case PV_NONE: return p->var;
10808
10809 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010810 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010811 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010812 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010813 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010814 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010815 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010816 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010817 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010818 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010819 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010820 case PV_TC: return *curbuf->b_p_tc != NUL
10821 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010822 case PV_BKC: return *curbuf->b_p_bkc != NUL
10823 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar375e3392019-01-31 18:26:10 +010010824 case PV_SISO: return curwin->w_p_siso >= 0
10825 ? (char_u *)&(curwin->w_p_siso) : p->var;
10826 case PV_SO: return curwin->w_p_so >= 0
10827 ? (char_u *)&(curwin->w_p_so) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010828#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010829 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010830 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010831 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010832 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10833#endif
10834#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010835 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010836 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010837 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010838 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10839#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010840 case PV_FP: return *curbuf->b_p_fp != NUL
10841 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010842#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010843 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010844 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010845 case PV_GP: return *curbuf->b_p_gp != NUL
10846 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10847 case PV_MP: return *curbuf->b_p_mp != NUL
10848 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010849#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010850#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10851 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10852 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10853#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010854#if defined(FEAT_CRYPT)
10855 case PV_CM: return *curbuf->b_p_cm != NUL
10856 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10857#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010858#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010859 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010860 ? (char_u *)&(curwin->w_p_stl) : p->var;
10861#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010862 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10863 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010864#ifdef FEAT_LISP
10865 case PV_LW: return *curbuf->b_p_lw != NUL
10866 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10867#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010868 case PV_MENC: return *curbuf->b_p_menc != NUL
10869 ? (char_u *)&(curbuf->b_p_menc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010870
10871#ifdef FEAT_ARABIC
10872 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10873#endif
10874 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010875#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010876 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10877#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010878#ifdef FEAT_SYN_HL
10879 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10880 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010881 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010882#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010883#ifdef FEAT_DIFF
10884 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10885#endif
10886#ifdef FEAT_FOLDING
10887 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10888 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10889 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10890 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10891 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10892 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10893 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10894# ifdef FEAT_EVAL
10895 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10896 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10897# endif
10898 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10899#endif
10900 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010901 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010902#ifdef FEAT_LINEBREAK
10903 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10904#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010905 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010906 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020010907#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010908 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10909#endif
10910#ifdef FEAT_RIGHTLEFT
10911 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10912 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10913#endif
10914 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10915 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10916#ifdef FEAT_LINEBREAK
10917 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010918 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10919 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010920#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010921 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010922 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010923#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010924 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10925 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10926#endif
10927#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020010928 case PV_TWK: return (char_u *)&(curwin->w_p_twk);
10929 case PV_TWS: return (char_u *)&(curwin->w_p_tws);
10930 case PV_TWSL: return (char_u *)&(curbuf->b_p_twsl);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010931#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010932
10933 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10934 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010935 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010936 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10937 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010938 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10939 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10940#ifdef FEAT_CINDENT
10941 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10942 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10943 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10944#endif
10945#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10946 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10947#endif
10948#ifdef FEAT_COMMENTS
10949 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10950#endif
10951#ifdef FEAT_FOLDING
10952 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10953#endif
10954#ifdef FEAT_INS_EXPAND
10955 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10956#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010957#ifdef FEAT_COMPL_FUNC
10958 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010959 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010960#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010961 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010962 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010963 case PV_ET: return (char_u *)&(curbuf->b_p_et);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010964 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010965 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010966 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010967 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010968 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010969 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10970 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10971 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10972 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10973#ifdef FEAT_FIND_ID
10974# ifdef FEAT_EVAL
10975 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10976# endif
10977#endif
10978#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10979 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10980 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10981#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010982#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010983 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10984#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010985#ifdef FEAT_CRYPT
10986 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10987#endif
10988#ifdef FEAT_LISP
10989 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10990#endif
10991 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10992 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10993 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10994 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10995 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010996 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010997#ifdef FEAT_TEXTOBJ
10998 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10999#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011000 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
11001#ifdef FEAT_SMARTINDENT
11002 case PV_SI: return (char_u *)&(curbuf->b_p_si);
11003#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011004 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011005 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
11006#ifdef FEAT_SEARCHPATH
11007 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
11008#endif
11009 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
11010#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011011 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011012 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
11013#endif
11014#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020011015 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
11016 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
11017 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011018#endif
11019 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
11020 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
11021 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
11022 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011023#ifdef FEAT_PERSISTENT_UNDO
11024 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
11025#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011026 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
11027#ifdef FEAT_KEYMAP
11028 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
11029#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011030#ifdef FEAT_SIGNS
11031 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
11032#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011033#ifdef FEAT_VARTABS
11034 case PV_VSTS: return (char_u *)&(curbuf->b_p_vsts);
11035 case PV_VTS: return (char_u *)&(curbuf->b_p_vts);
11036#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010011037 default: iemsg(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011038 }
11039 /* always return a valid pointer to avoid a crash! */
11040 return (char_u *)&(curbuf->b_p_wm);
11041}
11042
11043/*
11044 * Get the value of 'equalprg', either the buffer-local one or the global one.
11045 */
11046 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011047get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011048{
11049 if (*curbuf->b_p_ep == NUL)
11050 return p_ep;
11051 return curbuf->b_p_ep;
11052}
11053
Bram Moolenaar071d4272004-06-13 20:20:40 +000011054/*
11055 * Copy options from one window to another.
11056 * Used when splitting a window.
11057 */
11058 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011059win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011060{
11061 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
11062 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
11063# ifdef FEAT_RIGHTLEFT
11064# ifdef FEAT_FKMAP
11065 /* Is this right? */
11066 wp_to->w_farsi = wp_from->w_farsi;
11067# endif
11068# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020011069#if defined(FEAT_LINEBREAK)
11070 briopt_check(wp_to);
11071#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011072}
Bram Moolenaar071d4272004-06-13 20:20:40 +000011073
11074/*
11075 * Copy the options from one winopt_T to another.
11076 * Doesn't free the old option values in "to", use clear_winopt() for that.
11077 * The 'scroll' option is not copied, because it depends on the window height.
11078 * The 'previewwindow' option is reset, there can be only one preview window.
11079 */
11080 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011081copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011082{
11083#ifdef FEAT_ARABIC
11084 to->wo_arab = from->wo_arab;
11085#endif
11086 to->wo_list = from->wo_list;
11087 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020011088 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011089#ifdef FEAT_LINEBREAK
11090 to->wo_nuw = from->wo_nuw;
11091#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011092#ifdef FEAT_RIGHTLEFT
11093 to->wo_rl = from->wo_rl;
11094 to->wo_rlc = vim_strsave(from->wo_rlc);
11095#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011096#ifdef FEAT_STL_OPT
11097 to->wo_stl = vim_strsave(from->wo_stl);
11098#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011099 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011100#ifdef FEAT_DIFF
11101 to->wo_wrap_save = from->wo_wrap_save;
11102#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011103#ifdef FEAT_LINEBREAK
11104 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020011105 to->wo_bri = from->wo_bri;
11106 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011107#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011108 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011109 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010011110 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011111 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011112#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000011113 to->wo_spell = from->wo_spell;
11114#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011115#ifdef FEAT_SYN_HL
11116 to->wo_cuc = from->wo_cuc;
11117 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020011118 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011119#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011120#ifdef FEAT_DIFF
11121 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011122 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011123#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011124#ifdef FEAT_CONCEAL
11125 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020011126 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011127#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011128#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011129 to->wo_twk = vim_strsave(from->wo_twk);
11130 to->wo_tws = vim_strsave(from->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011131#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011132#ifdef FEAT_FOLDING
11133 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011134 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011135 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011136 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011137 to->wo_fdi = vim_strsave(from->wo_fdi);
11138 to->wo_fml = from->wo_fml;
11139 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011140 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011141 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011142 to->wo_fdm_save = from->wo_diff_saved
11143 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011144 to->wo_fdn = from->wo_fdn;
11145# ifdef FEAT_EVAL
11146 to->wo_fde = vim_strsave(from->wo_fde);
11147 to->wo_fdt = vim_strsave(from->wo_fdt);
11148# endif
11149 to->wo_fmr = vim_strsave(from->wo_fmr);
11150#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011151#ifdef FEAT_SIGNS
11152 to->wo_scl = vim_strsave(from->wo_scl);
11153#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011154 check_winopt(to); /* don't want NULL pointers */
11155}
11156
11157/*
11158 * Check string options in a window for a NULL value.
11159 */
11160 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011161check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011162{
11163 check_winopt(&win->w_onebuf_opt);
11164 check_winopt(&win->w_allbuf_opt);
11165}
11166
11167/*
11168 * Check for NULL pointers in a winopt_T and replace them with empty_option.
11169 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020011170 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011171check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011172{
11173#ifdef FEAT_FOLDING
11174 check_string_option(&wop->wo_fdi);
11175 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011176 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011177# ifdef FEAT_EVAL
11178 check_string_option(&wop->wo_fde);
11179 check_string_option(&wop->wo_fdt);
11180# endif
11181 check_string_option(&wop->wo_fmr);
11182#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011183#ifdef FEAT_SIGNS
11184 check_string_option(&wop->wo_scl);
11185#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011186#ifdef FEAT_RIGHTLEFT
11187 check_string_option(&wop->wo_rlc);
11188#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011189#ifdef FEAT_STL_OPT
11190 check_string_option(&wop->wo_stl);
11191#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011192#ifdef FEAT_SYN_HL
11193 check_string_option(&wop->wo_cc);
11194#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011195#ifdef FEAT_CONCEAL
11196 check_string_option(&wop->wo_cocu);
11197#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011198#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011199 check_string_option(&wop->wo_twk);
11200 check_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011201#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011202#ifdef FEAT_LINEBREAK
11203 check_string_option(&wop->wo_briopt);
11204#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011205}
11206
11207/*
11208 * Free the allocated memory inside a winopt_T.
11209 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011210 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011211clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011212{
11213#ifdef FEAT_FOLDING
11214 clear_string_option(&wop->wo_fdi);
11215 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011216 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011217# ifdef FEAT_EVAL
11218 clear_string_option(&wop->wo_fde);
11219 clear_string_option(&wop->wo_fdt);
11220# endif
11221 clear_string_option(&wop->wo_fmr);
11222#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011223#ifdef FEAT_SIGNS
11224 clear_string_option(&wop->wo_scl);
11225#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011226#ifdef FEAT_LINEBREAK
11227 clear_string_option(&wop->wo_briopt);
11228#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011229#ifdef FEAT_RIGHTLEFT
11230 clear_string_option(&wop->wo_rlc);
11231#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011232#ifdef FEAT_STL_OPT
11233 clear_string_option(&wop->wo_stl);
11234#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011235#ifdef FEAT_SYN_HL
11236 clear_string_option(&wop->wo_cc);
11237#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011238#ifdef FEAT_CONCEAL
11239 clear_string_option(&wop->wo_cocu);
11240#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011241#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011242 clear_string_option(&wop->wo_twk);
11243 clear_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011244#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011245}
11246
11247/*
11248 * Copy global option values to local options for one buffer.
11249 * Used when creating a new buffer and sometimes when entering a buffer.
11250 * flags:
11251 * BCO_ENTER We will enter the buf buffer.
11252 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11253 * appropriate.
11254 * BCO_NOHELP Don't copy the values to a help buffer.
11255 */
11256 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011257buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011258{
11259 int should_copy = TRUE;
11260 char_u *save_p_isk = NULL; /* init for GCC */
11261 int dont_do_help;
11262 int did_isk = FALSE;
11263
11264 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011265 * Skip this when the option defaults have not been set yet. Happens when
11266 * main() allocates the first buffer.
11267 */
11268 if (p_cpo != NULL)
11269 {
11270 /*
11271 * Always copy when entering and 'cpo' contains 'S'.
11272 * Don't copy when already initialized.
11273 * Don't copy when 'cpo' contains 's' and not entering.
11274 * 'S' BCO_ENTER initialized 's' should_copy
11275 * yes yes X X TRUE
11276 * yes no yes X FALSE
11277 * no X yes X FALSE
11278 * X no no yes FALSE
11279 * X no no no TRUE
11280 * no yes no X TRUE
11281 */
11282 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11283 && (buf->b_p_initialized
11284 || (!(flags & BCO_ENTER)
11285 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11286 should_copy = FALSE;
11287
11288 if (should_copy || (flags & BCO_ALWAYS))
11289 {
11290 /* Don't copy the options specific to a help buffer when
11291 * BCO_NOHELP is given or the options were initialized already
11292 * (jumping back to a help file with CTRL-T or CTRL-O) */
11293 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11294 || buf->b_p_initialized;
11295 if (dont_do_help) /* don't free b_p_isk */
11296 {
11297 save_p_isk = buf->b_p_isk;
11298 buf->b_p_isk = NULL;
11299 }
11300 /*
Bram Moolenaar40385db2018-08-07 22:31:44 +020011301 * Always free the allocated strings. If not already initialized,
11302 * reset 'readonly' and copy 'fileformat'.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011303 */
11304 if (!buf->b_p_initialized)
11305 {
11306 free_buf_options(buf, TRUE);
11307 buf->b_p_ro = FALSE; /* don't copy readonly */
11308 buf->b_p_tx = p_tx;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011309 buf->b_p_fenc = vim_strsave(p_fenc);
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011310 switch (*p_ffs)
11311 {
11312 case 'm':
11313 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11314 case 'd':
11315 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11316 case 'u':
11317 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11318 default:
11319 buf->b_p_ff = vim_strsave(p_ff);
11320 }
11321 if (buf->b_p_ff != NULL)
11322 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011323 buf->b_p_bh = empty_option;
11324 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011325 }
11326 else
11327 free_buf_options(buf, FALSE);
11328
11329 buf->b_p_ai = p_ai;
11330 buf->b_p_ai_nopaste = p_ai_nopaste;
11331 buf->b_p_sw = p_sw;
11332 buf->b_p_tw = p_tw;
11333 buf->b_p_tw_nopaste = p_tw_nopaste;
11334 buf->b_p_tw_nobin = p_tw_nobin;
11335 buf->b_p_wm = p_wm;
11336 buf->b_p_wm_nopaste = p_wm_nopaste;
11337 buf->b_p_wm_nobin = p_wm_nobin;
11338 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011339 buf->b_p_bomb = p_bomb;
Bram Moolenaarb388be02015-07-22 22:19:38 +020011340 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011341 buf->b_p_et = p_et;
11342 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011343 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011344 buf->b_p_ml = p_ml;
11345 buf->b_p_ml_nobin = p_ml_nobin;
11346 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011347 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011348#ifdef FEAT_INS_EXPAND
11349 buf->b_p_cpt = vim_strsave(p_cpt);
11350#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011351#ifdef FEAT_COMPL_FUNC
11352 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011353 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011354#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011355 buf->b_p_sts = p_sts;
11356 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011357#ifdef FEAT_VARTABS
11358 buf->b_p_vsts = vim_strsave(p_vsts);
11359 if (p_vsts && p_vsts != empty_option)
11360 tabstop_set(p_vsts, &buf->b_p_vsts_array);
11361 else
11362 buf->b_p_vsts_array = 0;
11363 buf->b_p_vsts_nopaste = p_vsts_nopaste
11364 ? vim_strsave(p_vsts_nopaste) : NULL;
11365#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011366 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011367#ifdef FEAT_COMMENTS
11368 buf->b_p_com = vim_strsave(p_com);
11369#endif
11370#ifdef FEAT_FOLDING
11371 buf->b_p_cms = vim_strsave(p_cms);
11372#endif
11373 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011374 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011375 buf->b_p_nf = vim_strsave(p_nf);
11376 buf->b_p_mps = vim_strsave(p_mps);
11377#ifdef FEAT_SMARTINDENT
11378 buf->b_p_si = p_si;
11379#endif
11380 buf->b_p_ci = p_ci;
11381#ifdef FEAT_CINDENT
11382 buf->b_p_cin = p_cin;
11383 buf->b_p_cink = vim_strsave(p_cink);
11384 buf->b_p_cino = vim_strsave(p_cino);
11385#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011386 /* Don't copy 'filetype', it must be detected */
11387 buf->b_p_ft = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011388 buf->b_p_pi = p_pi;
11389#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11390 buf->b_p_cinw = vim_strsave(p_cinw);
11391#endif
11392#ifdef FEAT_LISP
11393 buf->b_p_lisp = p_lisp;
11394#endif
11395#ifdef FEAT_SYN_HL
11396 /* Don't copy 'syntax', it must be set */
11397 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011398 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011399 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011400#endif
11401#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011402 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011403 (void)compile_cap_prog(&buf->b_s);
11404 buf->b_s.b_p_spf = vim_strsave(p_spf);
11405 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011406#endif
11407#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11408 buf->b_p_inde = vim_strsave(p_inde);
11409 buf->b_p_indk = vim_strsave(p_indk);
11410#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011411 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011412#if defined(FEAT_EVAL)
11413 buf->b_p_fex = vim_strsave(p_fex);
11414#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011415#ifdef FEAT_CRYPT
11416 buf->b_p_key = vim_strsave(p_key);
11417#endif
11418#ifdef FEAT_SEARCHPATH
11419 buf->b_p_sua = vim_strsave(p_sua);
11420#endif
11421#ifdef FEAT_KEYMAP
11422 buf->b_p_keymap = vim_strsave(p_keymap);
11423 buf->b_kmap_state |= KEYMAP_INIT;
11424#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011425#ifdef FEAT_TERMINAL
11426 buf->b_p_twsl = p_twsl;
11427#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011428 /* This isn't really an option, but copying the langmap and IME
11429 * state from the current buffer is better than resetting it. */
11430 buf->b_p_iminsert = p_iminsert;
11431 buf->b_p_imsearch = p_imsearch;
11432
11433 /* options that are normally global but also have a local value
11434 * are not copied, start using the global value */
11435 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011436 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011437 buf->b_p_bkc = empty_option;
11438 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011439#ifdef FEAT_QUICKFIX
11440 buf->b_p_gp = empty_option;
11441 buf->b_p_mp = empty_option;
11442 buf->b_p_efm = empty_option;
11443#endif
11444 buf->b_p_ep = empty_option;
11445 buf->b_p_kp = empty_option;
11446 buf->b_p_path = empty_option;
11447 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011448 buf->b_p_tc = empty_option;
11449 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011450#ifdef FEAT_FIND_ID
11451 buf->b_p_def = empty_option;
11452 buf->b_p_inc = empty_option;
11453# ifdef FEAT_EVAL
11454 buf->b_p_inex = vim_strsave(p_inex);
11455# endif
11456#endif
11457#ifdef FEAT_INS_EXPAND
11458 buf->b_p_dict = empty_option;
11459 buf->b_p_tsr = empty_option;
11460#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011461#ifdef FEAT_TEXTOBJ
11462 buf->b_p_qe = vim_strsave(p_qe);
11463#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011464#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11465 buf->b_p_bexpr = empty_option;
11466#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011467#if defined(FEAT_CRYPT)
11468 buf->b_p_cm = empty_option;
11469#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011470#ifdef FEAT_PERSISTENT_UNDO
11471 buf->b_p_udf = p_udf;
11472#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011473#ifdef FEAT_LISP
11474 buf->b_p_lw = empty_option;
11475#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011476 buf->b_p_menc = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011477
11478 /*
11479 * Don't copy the options set by ex_help(), use the saved values,
11480 * when going from a help buffer to a non-help buffer.
11481 * Don't touch these at all when BCO_NOHELP is used and going from
11482 * or to a help buffer.
11483 */
11484 if (dont_do_help)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011485 {
Bram Moolenaar071d4272004-06-13 20:20:40 +000011486 buf->b_p_isk = save_p_isk;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011487#ifdef FEAT_VARTABS
11488 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11489 tabstop_set(p_vts, &buf->b_p_vts_array);
11490 else
11491 buf->b_p_vts_array = NULL;
11492#endif
11493 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011494 else
11495 {
11496 buf->b_p_isk = vim_strsave(p_isk);
11497 did_isk = TRUE;
11498 buf->b_p_ts = p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011499#ifdef FEAT_VARTABS
11500 buf->b_p_vts = vim_strsave(p_vts);
11501 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11502 tabstop_set(p_vts, &buf->b_p_vts_array);
11503 else
11504 buf->b_p_vts_array = NULL;
11505#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011506 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011507 if (buf->b_p_bt[0] == 'h')
11508 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011509 buf->b_p_ma = p_ma;
11510 }
11511 }
11512
11513 /*
11514 * When the options should be copied (ignoring BCO_ALWAYS), set the
11515 * flag that indicates that the options have been initialized.
11516 */
11517 if (should_copy)
11518 buf->b_p_initialized = TRUE;
11519 }
11520
11521 check_buf_options(buf); /* make sure we don't have NULLs */
11522 if (did_isk)
11523 (void)buf_init_chartab(buf, FALSE);
11524}
11525
11526/*
11527 * Reset the 'modifiable' option and its default value.
11528 */
11529 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011530reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011531{
11532 int opt_idx;
11533
11534 curbuf->b_p_ma = FALSE;
11535 p_ma = FALSE;
11536 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011537 if (opt_idx >= 0)
11538 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011539}
11540
11541/*
11542 * Set the global value for 'iminsert' to the local value.
11543 */
11544 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011545set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011546{
11547 p_iminsert = curbuf->b_p_iminsert;
11548}
11549
11550/*
11551 * Set the global value for 'imsearch' to the local value.
11552 */
11553 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011554set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011555{
11556 p_imsearch = curbuf->b_p_imsearch;
11557}
11558
11559#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11560static int expand_option_idx = -1;
11561static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11562static int expand_option_flags = 0;
11563
11564 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011565set_context_in_set_cmd(
11566 expand_T *xp,
11567 char_u *arg,
11568 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011569{
11570 int nextchar;
11571 long_u flags = 0; /* init for GCC */
11572 int opt_idx = 0; /* init for GCC */
11573 char_u *p;
11574 char_u *s;
11575 int is_term_option = FALSE;
11576 int key;
11577
11578 expand_option_flags = opt_flags;
11579
11580 xp->xp_context = EXPAND_SETTINGS;
11581 if (*arg == NUL)
11582 {
11583 xp->xp_pattern = arg;
11584 return;
11585 }
11586 p = arg + STRLEN(arg) - 1;
11587 if (*p == ' ' && *(p - 1) != '\\')
11588 {
11589 xp->xp_pattern = p + 1;
11590 return;
11591 }
11592 while (p > arg)
11593 {
11594 s = p;
11595 /* count number of backslashes before ' ' or ',' */
11596 if (*p == ' ' || *p == ',')
11597 {
11598 while (s > arg && *(s - 1) == '\\')
11599 --s;
11600 }
11601 /* break at a space with an even number of backslashes */
11602 if (*p == ' ' && ((p - s) & 1) == 0)
11603 {
11604 ++p;
11605 break;
11606 }
11607 --p;
11608 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011609 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011610 {
11611 xp->xp_context = EXPAND_BOOL_SETTINGS;
11612 p += 2;
11613 }
11614 if (STRNCMP(p, "inv", 3) == 0)
11615 {
11616 xp->xp_context = EXPAND_BOOL_SETTINGS;
11617 p += 3;
11618 }
11619 xp->xp_pattern = arg = p;
11620 if (*arg == '<')
11621 {
11622 while (*p != '>')
11623 if (*p++ == NUL) /* expand terminal option name */
11624 return;
11625 key = get_special_key_code(arg + 1);
11626 if (key == 0) /* unknown name */
11627 {
11628 xp->xp_context = EXPAND_NOTHING;
11629 return;
11630 }
11631 nextchar = *++p;
11632 is_term_option = TRUE;
11633 expand_option_name[2] = KEY2TERMCAP0(key);
11634 expand_option_name[3] = KEY2TERMCAP1(key);
11635 }
11636 else
11637 {
11638 if (p[0] == 't' && p[1] == '_')
11639 {
11640 p += 2;
11641 if (*p != NUL)
11642 ++p;
11643 if (*p == NUL)
11644 return; /* expand option name */
11645 nextchar = *++p;
11646 is_term_option = TRUE;
11647 expand_option_name[2] = p[-2];
11648 expand_option_name[3] = p[-1];
11649 }
11650 else
11651 {
11652 /* Allow * wildcard */
11653 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11654 p++;
11655 if (*p == NUL)
11656 return;
11657 nextchar = *p;
11658 *p = NUL;
11659 opt_idx = findoption(arg);
11660 *p = nextchar;
11661 if (opt_idx == -1 || options[opt_idx].var == NULL)
11662 {
11663 xp->xp_context = EXPAND_NOTHING;
11664 return;
11665 }
11666 flags = options[opt_idx].flags;
11667 if (flags & P_BOOL)
11668 {
11669 xp->xp_context = EXPAND_NOTHING;
11670 return;
11671 }
11672 }
11673 }
11674 /* handle "-=" and "+=" */
11675 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11676 {
11677 ++p;
11678 nextchar = '=';
11679 }
11680 if ((nextchar != '=' && nextchar != ':')
11681 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11682 {
11683 xp->xp_context = EXPAND_UNSUCCESSFUL;
11684 return;
11685 }
11686 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11687 {
11688 xp->xp_context = EXPAND_OLD_SETTING;
11689 if (is_term_option)
11690 expand_option_idx = -1;
11691 else
11692 expand_option_idx = opt_idx;
11693 xp->xp_pattern = p + 1;
11694 return;
11695 }
11696 xp->xp_context = EXPAND_NOTHING;
11697 if (is_term_option || (flags & P_NUM))
11698 return;
11699
11700 xp->xp_pattern = p + 1;
11701
11702 if (flags & P_EXPAND)
11703 {
11704 p = options[opt_idx].var;
11705 if (p == (char_u *)&p_bdir
11706 || p == (char_u *)&p_dir
11707 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011708 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011709 || p == (char_u *)&p_rtp
11710#ifdef FEAT_SEARCHPATH
11711 || p == (char_u *)&p_cdpath
11712#endif
11713#ifdef FEAT_SESSION
11714 || p == (char_u *)&p_vdir
11715#endif
11716 )
11717 {
11718 xp->xp_context = EXPAND_DIRECTORIES;
11719 if (p == (char_u *)&p_path
11720#ifdef FEAT_SEARCHPATH
11721 || p == (char_u *)&p_cdpath
11722#endif
11723 )
11724 xp->xp_backslash = XP_BS_THREE;
11725 else
11726 xp->xp_backslash = XP_BS_ONE;
11727 }
11728 else
11729 {
11730 xp->xp_context = EXPAND_FILES;
11731 /* for 'tags' need three backslashes for a space */
11732 if (p == (char_u *)&p_tags)
11733 xp->xp_backslash = XP_BS_THREE;
11734 else
11735 xp->xp_backslash = XP_BS_ONE;
11736 }
11737 }
11738
11739 /* For an option that is a list of file names, find the start of the
11740 * last file name. */
11741 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11742 {
11743 /* count number of backslashes before ' ' or ',' */
11744 if (*p == ' ' || *p == ',')
11745 {
11746 s = p;
11747 while (s > xp->xp_pattern && *(s - 1) == '\\')
11748 --s;
11749 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11750 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11751 {
11752 xp->xp_pattern = p + 1;
11753 break;
11754 }
11755 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011756
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011757#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011758 /* for 'spellsuggest' start at "file:" */
11759 if (options[opt_idx].var == (char_u *)&p_sps
11760 && STRNCMP(p, "file:", 5) == 0)
11761 {
11762 xp->xp_pattern = p + 5;
11763 break;
11764 }
11765#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011766 }
11767
11768 return;
11769}
11770
11771 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011772ExpandSettings(
11773 expand_T *xp,
11774 regmatch_T *regmatch,
11775 int *num_file,
11776 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011777{
11778 int num_normal = 0; /* Nr of matching non-term-code settings */
11779 int num_term = 0; /* Nr of matching terminal code settings */
11780 int opt_idx;
11781 int match;
11782 int count = 0;
11783 char_u *str;
11784 int loop;
11785 int is_term_opt;
11786 char_u name_buf[MAX_KEY_NAME_LEN];
11787 static char *(names[]) = {"all", "termcap"};
11788 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11789
11790 /* do this loop twice:
11791 * loop == 0: count the number of matching options
11792 * loop == 1: copy the matching options into allocated memory
11793 */
11794 for (loop = 0; loop <= 1; ++loop)
11795 {
11796 regmatch->rm_ic = ic;
11797 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11798 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011799 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11800 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011801 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11802 {
11803 if (loop == 0)
11804 num_normal++;
11805 else
11806 (*file)[count++] = vim_strsave((char_u *)names[match]);
11807 }
11808 }
11809 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11810 opt_idx++)
11811 {
11812 if (options[opt_idx].var == NULL)
11813 continue;
11814 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11815 && !(options[opt_idx].flags & P_BOOL))
11816 continue;
11817 is_term_opt = istermoption(&options[opt_idx]);
11818 if (is_term_opt && num_normal > 0)
11819 continue;
11820 match = FALSE;
11821 if (vim_regexec(regmatch, str, (colnr_T)0)
11822 || (options[opt_idx].shortname != NULL
11823 && vim_regexec(regmatch,
11824 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11825 match = TRUE;
11826 else if (is_term_opt)
11827 {
11828 name_buf[0] = '<';
11829 name_buf[1] = 't';
11830 name_buf[2] = '_';
11831 name_buf[3] = str[2];
11832 name_buf[4] = str[3];
11833 name_buf[5] = '>';
11834 name_buf[6] = NUL;
11835 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11836 {
11837 match = TRUE;
11838 str = name_buf;
11839 }
11840 }
11841 if (match)
11842 {
11843 if (loop == 0)
11844 {
11845 if (is_term_opt)
11846 num_term++;
11847 else
11848 num_normal++;
11849 }
11850 else
11851 (*file)[count++] = vim_strsave(str);
11852 }
11853 }
11854 /*
11855 * Check terminal key codes, these are not in the option table
11856 */
11857 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11858 {
11859 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11860 {
11861 if (!isprint(str[0]) || !isprint(str[1]))
11862 continue;
11863
11864 name_buf[0] = 't';
11865 name_buf[1] = '_';
11866 name_buf[2] = str[0];
11867 name_buf[3] = str[1];
11868 name_buf[4] = NUL;
11869
11870 match = FALSE;
11871 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11872 match = TRUE;
11873 else
11874 {
11875 name_buf[0] = '<';
11876 name_buf[1] = 't';
11877 name_buf[2] = '_';
11878 name_buf[3] = str[0];
11879 name_buf[4] = str[1];
11880 name_buf[5] = '>';
11881 name_buf[6] = NUL;
11882
11883 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11884 match = TRUE;
11885 }
11886 if (match)
11887 {
11888 if (loop == 0)
11889 num_term++;
11890 else
11891 (*file)[count++] = vim_strsave(name_buf);
11892 }
11893 }
11894
11895 /*
11896 * Check special key names.
11897 */
11898 regmatch->rm_ic = TRUE; /* ignore case here */
11899 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11900 {
11901 name_buf[0] = '<';
11902 STRCPY(name_buf + 1, str);
11903 STRCAT(name_buf, ">");
11904
11905 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11906 {
11907 if (loop == 0)
11908 num_term++;
11909 else
11910 (*file)[count++] = vim_strsave(name_buf);
11911 }
11912 }
11913 }
11914 if (loop == 0)
11915 {
11916 if (num_normal > 0)
11917 *num_file = num_normal;
11918 else if (num_term > 0)
11919 *num_file = num_term;
11920 else
11921 return OK;
11922 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11923 if (*file == NULL)
11924 {
11925 *file = (char_u **)"";
11926 return FAIL;
11927 }
11928 }
11929 }
11930 return OK;
11931}
11932
11933 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011934ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011935{
11936 char_u *var = NULL; /* init for GCC */
11937 char_u *buf;
11938
11939 *num_file = 0;
11940 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11941 if (*file == NULL)
11942 return FAIL;
11943
11944 /*
11945 * For a terminal key code expand_option_idx is < 0.
11946 */
11947 if (expand_option_idx < 0)
11948 {
11949 var = find_termcode(expand_option_name + 2);
11950 if (var == NULL)
11951 expand_option_idx = findoption(expand_option_name);
11952 }
11953
11954 if (expand_option_idx >= 0)
11955 {
11956 /* put string of option value in NameBuff */
11957 option_value2string(&options[expand_option_idx], expand_option_flags);
11958 var = NameBuff;
11959 }
11960 else if (var == NULL)
11961 var = (char_u *)"";
11962
11963 /* A backslash is required before some characters. This is the reverse of
11964 * what happens in do_set(). */
11965 buf = vim_strsave_escaped(var, escape_chars);
11966
11967 if (buf == NULL)
11968 {
Bram Moolenaard23a8232018-02-10 18:45:26 +010011969 VIM_CLEAR(*file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011970 return FAIL;
11971 }
11972
11973#ifdef BACKSLASH_IN_FILENAME
11974 /* For MS-Windows et al. we don't double backslashes at the start and
11975 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011976 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011977 if (var[0] == '\\' && var[1] == '\\'
11978 && expand_option_idx >= 0
11979 && (options[expand_option_idx].flags & P_EXPAND)
11980 && vim_isfilec(var[2])
11981 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011982 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011983#endif
11984
11985 *file[0] = buf;
11986 *num_file = 1;
11987 return OK;
11988}
11989#endif
11990
11991/*
11992 * Get the value for the numeric or string option *opp in a nice format into
11993 * NameBuff[]. Must not be called with a hidden option!
11994 */
11995 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011996option_value2string(
11997 struct vimoption *opp,
11998 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011999{
12000 char_u *varp;
12001
12002 varp = get_varp_scope(opp, opt_flags);
12003
12004 if (opp->flags & P_NUM)
12005 {
12006 long wc = 0;
12007
12008 if (wc_use_keyname(varp, &wc))
12009 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
12010 else if (wc != 0)
12011 STRCPY(NameBuff, transchar((int)wc));
12012 else
12013 sprintf((char *)NameBuff, "%ld", *(long *)varp);
12014 }
12015 else /* P_STRING */
12016 {
12017 varp = *(char_u **)(varp);
12018 if (varp == NULL) /* just in case */
12019 NameBuff[0] = NUL;
12020#ifdef FEAT_CRYPT
12021 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000012022 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012023 STRCPY(NameBuff, "*****");
12024#endif
12025 else if (opp->flags & P_EXPAND)
12026 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
12027 /* Translate 'pastetoggle' into special key names */
12028 else if ((char_u **)opp->var == &p_pt)
12029 str2specialbuf(p_pt, NameBuff, MAXPATHL);
12030 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000012031 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012032 }
12033}
12034
12035/*
12036 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
12037 * printed as a keyname.
12038 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
12039 */
12040 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012041wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012042{
12043 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
12044 {
12045 *wcp = *(long *)varp;
12046 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
12047 return TRUE;
12048 }
12049 return FALSE;
12050}
12051
Bram Moolenaar01615492015-02-03 13:00:38 +010012052#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012053/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012054 * Any character has an equivalent 'langmap' character. This is used for
12055 * keyboards that have a special language mode that sends characters above
12056 * 128 (although other characters can be translated too). The "to" field is a
12057 * Vim command character. This avoids having to switch the keyboard back to
12058 * ASCII mode when leaving Insert mode.
12059 *
12060 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
12061 * commands.
Bram Moolenaarfc3abf42019-01-24 15:54:21 +010012062 * langmap_mapga.ga_data is a sorted table of langmap_entry_T. This does the
12063 * same as langmap_mapchar[] for characters >= 256.
12064 *
12065 * Use growarray for 'langmap' chars >= 256
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012066 */
12067typedef struct
12068{
12069 int from;
12070 int to;
12071} langmap_entry_T;
12072
12073static garray_T langmap_mapga;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012074
12075/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012076 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
12077 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012078 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012079 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012080langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012081{
12082 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020012083 int a = 0;
12084 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012085
12086 /* Do a binary search for an existing entry. */
12087 while (a != b)
12088 {
12089 int i = (a + b) / 2;
12090 int d = entries[i].from - from;
12091
12092 if (d == 0)
12093 {
12094 entries[i].to = to;
12095 return;
12096 }
12097 if (d < 0)
12098 a = i + 1;
12099 else
12100 b = i;
12101 }
12102
12103 if (ga_grow(&langmap_mapga, 1) != OK)
12104 return; /* out of memory */
12105
12106 /* insert new entry at position "a" */
12107 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
12108 mch_memmove(entries + 1, entries,
12109 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
12110 ++langmap_mapga.ga_len;
12111 entries[0].from = from;
12112 entries[0].to = to;
12113}
12114
12115/*
12116 * Apply 'langmap' to multi-byte character "c" and return the result.
12117 */
12118 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012119langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012120{
12121 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
12122 int a = 0;
12123 int b = langmap_mapga.ga_len;
12124
12125 while (a != b)
12126 {
12127 int i = (a + b) / 2;
12128 int d = entries[i].from - c;
12129
12130 if (d == 0)
12131 return entries[i].to; /* found matching entry */
12132 if (d < 0)
12133 a = i + 1;
12134 else
12135 b = i;
12136 }
12137 return c; /* no entry found, return "c" unmodified */
12138}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012139
12140 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012141langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012142{
12143 int i;
12144
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012145 for (i = 0; i < 256; i++)
12146 langmap_mapchar[i] = i; /* we init with a one-to-one map */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012147 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012148}
12149
12150/*
12151 * Called when langmap option is set; the language map can be
12152 * changed at any time!
12153 */
12154 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012155langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012156{
12157 char_u *p;
12158 char_u *p2;
12159 int from, to;
12160
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012161 ga_clear(&langmap_mapga); /* clear the previous map first */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012162 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012163
12164 for (p = p_langmap; p[0] != NUL; )
12165 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000012166 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012167 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012168 {
12169 if (p2[0] == '\\' && p2[1] != NUL)
12170 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012171 }
12172 if (p2[0] == ';')
12173 ++p2; /* abcd;ABCD form, p2 points to A */
12174 else
12175 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
12176 while (p[0])
12177 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012178 if (p[0] == ',')
12179 {
12180 ++p;
12181 break;
12182 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012183 if (p[0] == '\\' && p[1] != NUL)
12184 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012185 from = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012186 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012187 if (p2 == NULL)
12188 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012189 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012190 if (p[0] != ',')
12191 {
12192 if (p[0] == '\\')
12193 ++p;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012194 to = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012195 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012196 }
12197 else
12198 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012199 if (p2[0] != ',')
12200 {
12201 if (p2[0] == '\\')
12202 ++p2;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012203 to = (*mb_ptr2char)(p2);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012204 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012205 }
12206 if (to == NUL)
12207 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012208 semsg(_("E357: 'langmap': Matching character missing for %s"),
Bram Moolenaar071d4272004-06-13 20:20:40 +000012209 transchar(from));
12210 return;
12211 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012212
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012213 if (from >= 256)
12214 langmap_set_entry(from, to);
12215 else
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012216 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012217
12218 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012219 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012220 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012221 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012222 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012223 if (*p == ';')
12224 {
12225 p = p2;
12226 if (p[0] != NUL)
12227 {
12228 if (p[0] != ',')
12229 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012230 semsg(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012231 return;
12232 }
12233 ++p;
12234 }
12235 break;
12236 }
12237 }
12238 }
12239 }
12240}
12241#endif
12242
12243/*
12244 * Return TRUE if format option 'x' is in effect.
12245 * Take care of no formatting when 'paste' is set.
12246 */
12247 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012248has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012249{
12250 if (p_paste)
12251 return FALSE;
12252 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12253}
12254
12255/*
12256 * Return TRUE if "x" is present in 'shortmess' option, or
12257 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12258 */
12259 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012260shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012261{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012262 return p_shm != NULL &&
12263 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012264 || (vim_strchr(p_shm, 'a') != NULL
12265 && vim_strchr((char_u *)SHM_A, x) != NULL));
12266}
12267
12268/*
12269 * paste_option_changed() - Called after p_paste was set or reset.
12270 */
12271 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012272paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012273{
12274 static int old_p_paste = FALSE;
12275 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012276 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012277#ifdef FEAT_CMDL_INFO
12278 static int save_ru = 0;
12279#endif
12280#ifdef FEAT_RIGHTLEFT
12281 static int save_ri = 0;
12282 static int save_hkmap = 0;
12283#endif
12284 buf_T *buf;
12285
12286 if (p_paste)
12287 {
12288 /*
12289 * Paste switched from off to on.
12290 * Save the current values, so they can be restored later.
12291 */
12292 if (!old_p_paste)
12293 {
12294 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012295 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012296 {
12297 buf->b_p_tw_nopaste = buf->b_p_tw;
12298 buf->b_p_wm_nopaste = buf->b_p_wm;
12299 buf->b_p_sts_nopaste = buf->b_p_sts;
12300 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012301 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012302#ifdef FEAT_VARTABS
12303 if (buf->b_p_vsts_nopaste)
12304 vim_free(buf->b_p_vsts_nopaste);
12305 buf->b_p_vsts_nopaste = buf->b_p_vsts && buf->b_p_vsts != empty_option
12306 ? vim_strsave(buf->b_p_vsts) : NULL;
12307#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012308 }
12309
12310 /* save global options */
12311 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012312 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012313#ifdef FEAT_CMDL_INFO
12314 save_ru = p_ru;
12315#endif
12316#ifdef FEAT_RIGHTLEFT
12317 save_ri = p_ri;
12318 save_hkmap = p_hkmap;
12319#endif
12320 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012321 p_ai_nopaste = p_ai;
12322 p_et_nopaste = p_et;
12323 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012324 p_tw_nopaste = p_tw;
12325 p_wm_nopaste = p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012326#ifdef FEAT_VARTABS
12327 if (p_vsts_nopaste)
12328 vim_free(p_vsts_nopaste);
12329 p_vsts_nopaste = p_vsts && p_vsts != empty_option ? vim_strsave(p_vsts) : NULL;
12330#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012331 }
12332
12333 /*
12334 * Always set the option values, also when 'paste' is set when it is
12335 * already on.
12336 */
12337 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012338 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012339 {
12340 buf->b_p_tw = 0; /* textwidth is 0 */
12341 buf->b_p_wm = 0; /* wrapmargin is 0 */
12342 buf->b_p_sts = 0; /* softtabstop is 0 */
12343 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012344 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012345#ifdef FEAT_VARTABS
12346 if (buf->b_p_vsts)
12347 free_string_option(buf->b_p_vsts);
12348 buf->b_p_vsts = empty_option;
12349 if (buf->b_p_vsts_array)
12350 vim_free(buf->b_p_vsts_array);
12351 buf->b_p_vsts_array = 0;
12352#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012353 }
12354
12355 /* set global options */
12356 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012357 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012358#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012359 if (p_ru)
12360 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012361 p_ru = 0; /* no ruler */
12362#endif
12363#ifdef FEAT_RIGHTLEFT
12364 p_ri = 0; /* no reverse insert */
12365 p_hkmap = 0; /* no Hebrew keyboard */
12366#endif
12367 /* set global values for local buffer options */
12368 p_tw = 0;
12369 p_wm = 0;
12370 p_sts = 0;
12371 p_ai = 0;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012372#ifdef FEAT_VARTABS
12373 if (p_vsts)
12374 free_string_option(p_vsts);
12375 p_vsts = empty_option;
12376#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012377 }
12378
12379 /*
12380 * Paste switched from on to off: Restore saved values.
12381 */
12382 else if (old_p_paste)
12383 {
12384 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012385 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012386 {
12387 buf->b_p_tw = buf->b_p_tw_nopaste;
12388 buf->b_p_wm = buf->b_p_wm_nopaste;
12389 buf->b_p_sts = buf->b_p_sts_nopaste;
12390 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012391 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012392#ifdef FEAT_VARTABS
12393 if (buf->b_p_vsts)
12394 free_string_option(buf->b_p_vsts);
12395 buf->b_p_vsts = buf->b_p_vsts_nopaste
12396 ? vim_strsave(buf->b_p_vsts_nopaste) : empty_option;
12397 if (buf->b_p_vsts_array)
12398 vim_free(buf->b_p_vsts_array);
12399 if (buf->b_p_vsts && buf->b_p_vsts != empty_option)
12400 tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array);
12401 else
12402 buf->b_p_vsts_array = 0;
12403#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012404 }
12405
12406 /* restore global options */
12407 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012408 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012409#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012410 if (p_ru != save_ru)
12411 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012412 p_ru = save_ru;
12413#endif
12414#ifdef FEAT_RIGHTLEFT
12415 p_ri = save_ri;
12416 p_hkmap = save_hkmap;
12417#endif
12418 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012419 p_ai = p_ai_nopaste;
12420 p_et = p_et_nopaste;
12421 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012422 p_tw = p_tw_nopaste;
12423 p_wm = p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012424#ifdef FEAT_VARTABS
12425 if (p_vsts)
12426 free_string_option(p_vsts);
12427 p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option;
12428#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012429 }
12430
12431 old_p_paste = p_paste;
12432}
12433
12434/*
12435 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12436 *
12437 * Reset 'compatible' and set the values for options that didn't get set yet
12438 * to the Vim defaults.
12439 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012440 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012441 */
12442 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012443vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012444{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012445 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012446 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012447 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012448
12449 if (!option_was_set((char_u *)"cp"))
12450 {
12451 p_cp = FALSE;
12452 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12453 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12454 set_option_default(opt_idx, OPT_FREE, FALSE);
12455 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012456 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012457 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012458
12459 if (fname != NULL)
12460 {
12461 p = vim_getenv(envname, &dofree);
12462 if (p == NULL)
12463 {
12464 /* Set $MYVIMRC to the first vimrc file found. */
12465 p = FullName_save(fname, FALSE);
12466 if (p != NULL)
12467 {
12468 vim_setenv(envname, p);
12469 vim_free(p);
12470 }
12471 }
12472 else if (dofree)
12473 vim_free(p);
12474 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012475}
12476
12477/*
12478 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12479 */
12480 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012481change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012482{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012483 int opt_idx;
12484
Bram Moolenaar071d4272004-06-13 20:20:40 +000012485 if (p_cp != on)
12486 {
12487 p_cp = on;
12488 compatible_set();
12489 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012490 opt_idx = findoption((char_u *)"cp");
12491 if (opt_idx >= 0)
12492 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012493}
12494
12495/*
12496 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012497 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012498 */
12499 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012500option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012501{
12502 int idx;
12503
12504 idx = findoption(name);
12505 if (idx < 0) /* unknown option */
12506 return FALSE;
12507 if (options[idx].flags & P_WAS_SET)
12508 return TRUE;
12509 return FALSE;
12510}
12511
12512/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012513 * Reset the flag indicating option "name" was set.
12514 */
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012515 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012516reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012517{
12518 int idx = findoption(name);
12519
12520 if (idx >= 0)
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012521 {
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012522 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012523 return OK;
12524 }
12525 return FAIL;
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012526}
12527
12528/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012529 * compatible_set() - Called when 'compatible' has been set or unset.
12530 *
12531 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12532 * flag) to a Vi compatible value.
12533 * When 'compatible' is unset: Set all options that have a different default
12534 * for Vim (without the P_VI_DEF flag) to that default.
12535 */
12536 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012537compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012538{
12539 int opt_idx;
12540
12541 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12542 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12543 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12544 set_option_default(opt_idx, OPT_FREE, p_cp);
12545 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012546 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012547}
12548
12549#ifdef FEAT_LINEBREAK
12550
12551# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12552 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012553 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012554# endif
12555
12556/*
12557 * fill_breakat_flags() -- called when 'breakat' changes value.
12558 */
12559 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012560fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012561{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012562 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012563 int i;
12564
12565 for (i = 0; i < 256; i++)
12566 breakat_flags[i] = FALSE;
12567
12568 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012569 for (p = p_breakat; *p; p++)
12570 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012571}
12572
12573# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012574 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012575# endif
12576
12577#endif
12578
12579/*
12580 * Check an option that can be a range of string values.
12581 *
12582 * Return OK for correct value, FAIL otherwise.
12583 * Empty is always OK.
12584 */
12585 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012586check_opt_strings(
12587 char_u *val,
12588 char **values,
12589 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012590{
12591 return opt_strings_flags(val, values, NULL, list);
12592}
12593
12594/*
12595 * Handle an option that can be a range of string values.
12596 * Set a flag in "*flagp" for each string present.
12597 *
12598 * Return OK for correct value, FAIL otherwise.
12599 * Empty is always OK.
12600 */
12601 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012602opt_strings_flags(
12603 char_u *val, /* new value */
12604 char **values, /* array of valid string values */
12605 unsigned *flagp,
12606 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012607{
12608 int i;
12609 int len;
12610 unsigned new_flags = 0;
12611
12612 while (*val)
12613 {
12614 for (i = 0; ; ++i)
12615 {
12616 if (values[i] == NULL) /* val not found in values[] */
12617 return FAIL;
12618
12619 len = (int)STRLEN(values[i]);
12620 if (STRNCMP(values[i], val, len) == 0
12621 && ((list && val[len] == ',') || val[len] == NUL))
12622 {
12623 val += len + (val[len] == ',');
12624 new_flags |= (1 << i);
12625 break; /* check next item in val list */
12626 }
12627 }
12628 }
12629 if (flagp != NULL)
12630 *flagp = new_flags;
12631
12632 return OK;
12633}
12634
12635/*
12636 * Read the 'wildmode' option, fill wim_flags[].
12637 */
12638 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012639check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012640{
12641 char_u new_wim_flags[4];
12642 char_u *p;
12643 int i;
12644 int idx = 0;
12645
12646 for (i = 0; i < 4; ++i)
12647 new_wim_flags[i] = 0;
12648
12649 for (p = p_wim; *p; ++p)
12650 {
12651 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12652 ;
12653 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12654 return FAIL;
12655 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12656 new_wim_flags[idx] |= WIM_LONGEST;
12657 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12658 new_wim_flags[idx] |= WIM_FULL;
12659 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12660 new_wim_flags[idx] |= WIM_LIST;
12661 else
12662 return FAIL;
12663 p += i;
12664 if (*p == NUL)
12665 break;
12666 if (*p == ',')
12667 {
12668 if (idx == 3)
12669 return FAIL;
12670 ++idx;
12671 }
12672 }
12673
12674 /* fill remaining entries with last flag */
12675 while (idx < 3)
12676 {
12677 new_wim_flags[idx + 1] = new_wim_flags[idx];
12678 ++idx;
12679 }
12680
12681 /* only when there are no errors, wim_flags[] is changed */
12682 for (i = 0; i < 4; ++i)
12683 wim_flags[i] = new_wim_flags[i];
12684 return OK;
12685}
12686
12687/*
12688 * Check if backspacing over something is allowed.
12689 */
12690 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012691can_bs(
12692 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012693{
Bram Moolenaar6b810d92018-06-04 17:28:44 +020012694#ifdef FEAT_JOB_CHANNEL
12695 if (what == BS_START && bt_prompt(curbuf))
12696 return FALSE;
12697#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012698 switch (*p_bs)
12699 {
12700 case '2': return TRUE;
12701 case '1': return (what != BS_START);
12702 case '0': return FALSE;
12703 }
12704 return vim_strchr(p_bs, what) != NULL;
12705}
12706
12707/*
12708 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12709 * the file must be considered changed when the value is different.
12710 */
12711 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012712save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012713{
12714 buf->b_start_ffc = *buf->b_p_ff;
12715 buf->b_start_eol = buf->b_p_eol;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012716 buf->b_start_bomb = buf->b_p_bomb;
12717
Bram Moolenaar071d4272004-06-13 20:20:40 +000012718 /* Only use free/alloc when necessary, they take time. */
12719 if (buf->b_start_fenc == NULL
12720 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12721 {
12722 vim_free(buf->b_start_fenc);
12723 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12724 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012725}
12726
12727/*
12728 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12729 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012730 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12731 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012732 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012733 * When "ignore_empty" is true don't consider a new, empty buffer to be
12734 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012735 */
12736 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012737file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012738{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012739 /* In a buffer that was never loaded the options are not valid. */
12740 if (buf->b_flags & BF_NEVERLOADED)
12741 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012742 if (ignore_empty
12743 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012744 && buf->b_ml.ml_line_count == 1
12745 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12746 return FALSE;
12747 if (buf->b_start_ffc != *buf->b_p_ff)
12748 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012749 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012750 return TRUE;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012751 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12752 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012753 if (buf->b_start_fenc == NULL)
12754 return (*buf->b_p_fenc != NUL);
12755 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012756}
12757
12758/*
12759 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12760 */
12761 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012762check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012763{
12764 return check_opt_strings(p, p_ff_values, FALSE);
12765}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012766
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012767#ifdef FEAT_VARTABS
12768
12769/*
12770 * Set the integer values corresponding to the string setting of 'vartabstop'.
12771 */
12772 int
12773tabstop_set(char_u *var, int **array)
12774{
12775 int valcount = 1;
12776 int t;
12777 char_u *cp;
12778
Bram Moolenaar64f41072018-10-15 22:51:50 +020012779 if (var[0] == NUL || (var[0] == '0' && var[1] == NUL))
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012780 {
12781 *array = NULL;
12782 return TRUE;
12783 }
12784
Bram Moolenaar64f41072018-10-15 22:51:50 +020012785 for (cp = var; *cp != NUL; ++cp)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012786 {
Bram Moolenaar64f41072018-10-15 22:51:50 +020012787 if (cp == var || cp[-1] == ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012788 {
12789 char_u *end;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012790
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012791 if (strtol((char *)cp, (char **)&end, 10) <= 0)
12792 {
12793 if (cp != end)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012794 emsg(_(e_positive));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012795 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012796 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012797 return FALSE;
12798 }
12799 }
12800
12801 if (VIM_ISDIGIT(*cp))
12802 continue;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012803 if (cp[0] == ',' && cp > var && cp[-1] != ',' && cp[1] != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012804 {
12805 ++valcount;
12806 continue;
12807 }
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012808 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012809 return FALSE;
12810 }
12811
Bram Moolenaar64f41072018-10-15 22:51:50 +020012812 *array = (int *)alloc((unsigned) ((valcount + 1) * sizeof(int)));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012813 (*array)[0] = valcount;
12814
12815 t = 1;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012816 for (cp = var; *cp != NUL;)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012817 {
12818 (*array)[t++] = atoi((char *)cp);
Bram Moolenaar64f41072018-10-15 22:51:50 +020012819 while (*cp != NUL && *cp != ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012820 ++cp;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012821 if (*cp != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012822 ++cp;
12823 }
12824
12825 return TRUE;
12826}
12827
12828/*
12829 * Calculate the number of screen spaces a tab will occupy.
12830 * If "vts" is set then the tab widths are taken from that array,
12831 * otherwise the value of ts is used.
12832 */
12833 int
12834tabstop_padding(colnr_T col, int ts_arg, int *vts)
12835{
12836 int ts = ts_arg == 0 ? 8 : ts_arg;
12837 int tabcount;
12838 colnr_T tabcol = 0;
12839 int t;
12840 int padding = 0;
12841
12842 if (vts == NULL || vts[0] == 0)
12843 return ts - (col % ts);
12844
12845 tabcount = vts[0];
12846
12847 for (t = 1; t <= tabcount; ++t)
12848 {
12849 tabcol += vts[t];
12850 if (tabcol > col)
12851 {
12852 padding = (int)(tabcol - col);
12853 break;
12854 }
12855 }
12856 if (t > tabcount)
12857 padding = vts[tabcount] - (int)((col - tabcol) % vts[tabcount]);
12858
12859 return padding;
12860}
12861
12862/*
12863 * Find the size of the tab that covers a particular column.
12864 */
12865 int
12866tabstop_at(colnr_T col, int ts, int *vts)
12867{
12868 int tabcount;
12869 colnr_T tabcol = 0;
12870 int t;
12871 int tab_size = 0;
12872
12873 if (vts == 0 || vts[0] == 0)
12874 return ts;
12875
12876 tabcount = vts[0];
12877 for (t = 1; t <= tabcount; ++t)
12878 {
12879 tabcol += vts[t];
12880 if (tabcol > col)
12881 {
12882 tab_size = vts[t];
12883 break;
12884 }
12885 }
12886 if (t > tabcount)
12887 tab_size = vts[tabcount];
12888
12889 return tab_size;
12890}
12891
12892/*
12893 * Find the column on which a tab starts.
12894 */
12895 colnr_T
12896tabstop_start(colnr_T col, int ts, int *vts)
12897{
12898 int tabcount;
12899 colnr_T tabcol = 0;
12900 int t;
12901 int excess;
12902
Bram Moolenaar0119a592018-06-24 23:53:28 +020012903 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012904 return (col / ts) * ts;
12905
12906 tabcount = vts[0];
12907 for (t = 1; t <= tabcount; ++t)
12908 {
12909 tabcol += vts[t];
12910 if (tabcol > col)
12911 return tabcol - vts[t];
12912 }
12913
12914 excess = tabcol % vts[tabcount];
12915 return excess + ((col - excess) / vts[tabcount]) * vts[tabcount];
12916}
12917
12918/*
12919 * Find the number of tabs and spaces necessary to get from one column
12920 * to another.
12921 */
12922 void
12923tabstop_fromto(
12924 colnr_T start_col,
12925 colnr_T end_col,
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012926 int ts_arg,
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012927 int *vts,
12928 int *ntabs,
12929 int *nspcs)
12930{
12931 int spaces = end_col - start_col;
12932 colnr_T tabcol = 0;
12933 int padding = 0;
12934 int tabcount;
12935 int t;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012936 int ts = ts_arg == 0 ? curbuf->b_p_ts : ts_arg;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012937
Bram Moolenaar0119a592018-06-24 23:53:28 +020012938 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012939 {
12940 int tabs = 0;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012941 int initspc = 0;
Bram Moolenaar0119a592018-06-24 23:53:28 +020012942
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012943 initspc = ts - (start_col % ts);
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012944 if (spaces >= initspc)
12945 {
12946 spaces -= initspc;
12947 tabs++;
12948 }
12949 tabs += spaces / ts;
12950 spaces -= (spaces / ts) * ts;
12951
12952 *ntabs = tabs;
12953 *nspcs = spaces;
12954 return;
12955 }
12956
12957 /* Find the padding needed to reach the next tabstop. */
12958 tabcount = vts[0];
12959 for (t = 1; t <= tabcount; ++t)
12960 {
12961 tabcol += vts[t];
12962 if (tabcol > start_col)
12963 {
12964 padding = (int)(tabcol - start_col);
12965 break;
12966 }
12967 }
12968 if (t > tabcount)
12969 padding = vts[tabcount] - (int)((start_col - tabcol) % vts[tabcount]);
12970
12971 /* If the space needed is less than the padding no tabs can be used. */
12972 if (spaces < padding)
12973 {
12974 *ntabs = 0;
12975 *nspcs = spaces;
12976 return;
12977 }
12978
12979 *ntabs = 1;
12980 spaces -= padding;
12981
12982 /* At least one tab has been used. See if any more will fit. */
12983 while (spaces != 0 && ++t <= tabcount)
12984 {
12985 padding = vts[t];
12986 if (spaces < padding)
12987 {
12988 *nspcs = spaces;
12989 return;
12990 }
12991 ++*ntabs;
12992 spaces -= padding;
12993 }
12994
12995 *ntabs += spaces / vts[tabcount];
12996 *nspcs = spaces % vts[tabcount];
12997}
12998
12999/*
13000 * See if two tabstop arrays contain the same values.
13001 */
13002 int
13003tabstop_eq(int *ts1, int *ts2)
13004{
13005 int t;
13006
13007 if ((ts1 == 0 && ts2) || (ts1 && ts2 == 0))
13008 return FALSE;
13009 if (ts1 == ts2)
13010 return TRUE;
13011 if (ts1[0] != ts2[0])
13012 return FALSE;
13013
13014 for (t = 1; t <= ts1[0]; ++t)
13015 if (ts1[t] != ts2[t])
13016 return FALSE;
13017
13018 return TRUE;
13019}
13020
Bram Moolenaar113e1072019-01-20 15:30:40 +010013021#if defined(FEAT_BEVAL) || defined(PROTO)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013022/*
13023 * Copy a tabstop array, allocating space for the new array.
13024 */
13025 int *
13026tabstop_copy(int *oldts)
13027{
13028 int *newts;
13029 int t;
13030
13031 if (oldts == 0)
13032 return 0;
13033
13034 newts = (int *) alloc((unsigned) ((oldts[0] + 1) * sizeof(int)));
13035 for (t = 0; t <= oldts[0]; ++t)
13036 newts[t] = oldts[t];
13037
13038 return newts;
13039}
Bram Moolenaar113e1072019-01-20 15:30:40 +010013040#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013041
13042/*
13043 * Return a count of the number of tabstops.
13044 */
13045 int
13046tabstop_count(int *ts)
13047{
13048 return ts != NULL ? ts[0] : 0;
13049}
13050
13051/*
13052 * Return the first tabstop, or 8 if there are no tabstops defined.
13053 */
13054 int
13055tabstop_first(int *ts)
13056{
13057 return ts != NULL ? ts[1] : 8;
13058}
13059
13060#endif
13061
Bram Moolenaar14f24742012-08-08 18:01:05 +020013062/*
13063 * Return the effective shiftwidth value for current buffer, using the
13064 * 'tabstop' value when 'shiftwidth' is zero.
13065 */
13066 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013067get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020013068{
Bram Moolenaarf9514162018-11-22 03:08:29 +010013069 return get_sw_value_col(buf, 0);
13070}
13071
13072/*
13073 * Idem, using the first non-black in the current line.
13074 */
13075 long
13076get_sw_value_indent(buf_T *buf)
13077{
13078 pos_T pos = curwin->w_cursor;
13079
13080 pos.col = getwhitecols_curline();
13081 return get_sw_value_pos(buf, &pos);
13082}
13083
13084/*
13085 * Idem, using "pos".
13086 */
13087 long
13088get_sw_value_pos(buf_T *buf, pos_T *pos)
13089{
13090 pos_T save_cursor = curwin->w_cursor;
13091 long sw_value;
13092
13093 curwin->w_cursor = *pos;
13094 sw_value = get_sw_value_col(buf, get_nolist_virtcol());
13095 curwin->w_cursor = save_cursor;
13096 return sw_value;
13097}
13098
13099/*
13100 * Idem, using virtual column "col".
13101 */
13102 long
13103get_sw_value_col(buf_T *buf, colnr_T col UNUSED)
13104{
13105 return buf->b_p_sw ? buf->b_p_sw :
13106 #ifdef FEAT_VARTABS
13107 tabstop_at(col, buf->b_p_ts, buf->b_p_vts_array);
13108 #else
13109 buf->b_p_ts;
13110 #endif
Bram Moolenaar14f24742012-08-08 18:01:05 +020013111}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013112
13113/*
13114 * Return the effective softtabstop value for the current buffer, using the
Bram Moolenaar33d5ab32018-07-02 20:51:24 +020013115 * 'shiftwidth' value when 'softtabstop' is negative.
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013116 */
13117 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013118get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013119{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010013120 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013121}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013122
13123/*
Bram Moolenaar375e3392019-01-31 18:26:10 +010013124 * Return the effective 'scrolloff' value for the current window, using the
13125 * global value when appropriate.
13126 */
13127 long
13128get_scrolloff_value(void)
13129{
13130 return curwin->w_p_so < 0 ? p_so : curwin->w_p_so;
13131}
13132
13133/*
13134 * Return the effective 'sidescrolloff' value for the current window, using the
13135 * global value when appropriate.
13136 */
13137 long
13138get_sidescrolloff_value(void)
13139{
13140 return curwin->w_p_siso < 0 ? p_siso : curwin->w_p_siso;
13141}
13142
13143/*
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013144 * Check matchpairs option for "*initc".
13145 * If there is a match set "*initc" to the matching character and "*findc" to
13146 * the opposite character. Set "*backwards" to the direction.
13147 * When "switchit" is TRUE swap the direction.
13148 */
13149 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010013150find_mps_values(
13151 int *initc,
13152 int *findc,
13153 int *backwards,
13154 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013155{
13156 char_u *ptr;
13157
13158 ptr = curbuf->b_p_mps;
13159 while (*ptr != NUL)
13160 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013161 if (has_mbyte)
13162 {
13163 char_u *prev;
13164
13165 if (mb_ptr2char(ptr) == *initc)
13166 {
13167 if (switchit)
13168 {
13169 *findc = *initc;
13170 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13171 *backwards = TRUE;
13172 }
13173 else
13174 {
13175 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13176 *backwards = FALSE;
13177 }
13178 return;
13179 }
13180 prev = ptr;
13181 ptr += mb_ptr2len(ptr) + 1;
13182 if (mb_ptr2char(ptr) == *initc)
13183 {
13184 if (switchit)
13185 {
13186 *findc = *initc;
13187 *initc = mb_ptr2char(prev);
13188 *backwards = FALSE;
13189 }
13190 else
13191 {
13192 *findc = mb_ptr2char(prev);
13193 *backwards = TRUE;
13194 }
13195 return;
13196 }
13197 ptr += mb_ptr2len(ptr);
13198 }
13199 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013200 {
13201 if (*ptr == *initc)
13202 {
13203 if (switchit)
13204 {
13205 *backwards = TRUE;
13206 *findc = *initc;
13207 *initc = ptr[2];
13208 }
13209 else
13210 {
13211 *backwards = FALSE;
13212 *findc = ptr[2];
13213 }
13214 return;
13215 }
13216 ptr += 2;
13217 if (*ptr == *initc)
13218 {
13219 if (switchit)
13220 {
13221 *backwards = FALSE;
13222 *findc = *initc;
13223 *initc = ptr[-2];
13224 }
13225 else
13226 {
13227 *backwards = TRUE;
13228 *findc = ptr[-2];
13229 }
13230 return;
13231 }
13232 ++ptr;
13233 }
13234 if (*ptr == ',')
13235 ++ptr;
13236 }
13237}
Bram Moolenaar597a4222014-06-25 14:39:50 +020013238
13239#if defined(FEAT_LINEBREAK) || defined(PROTO)
13240/*
13241 * This is called when 'breakindentopt' is changed and when a window is
13242 * initialized.
13243 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013244 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013245briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020013246{
13247 char_u *p;
13248 int bri_shift = 0;
13249 long bri_min = 20;
13250 int bri_sbr = FALSE;
13251
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013252 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013253 while (*p != NUL)
13254 {
13255 if (STRNCMP(p, "shift:", 6) == 0
13256 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
13257 {
13258 p += 6;
13259 bri_shift = getdigits(&p);
13260 }
13261 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
13262 {
13263 p += 4;
13264 bri_min = getdigits(&p);
13265 }
13266 else if (STRNCMP(p, "sbr", 3) == 0)
13267 {
13268 p += 3;
13269 bri_sbr = TRUE;
13270 }
13271 if (*p != ',' && *p != NUL)
13272 return FAIL;
13273 if (*p == ',')
13274 ++p;
13275 }
13276
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013277 wp->w_p_brishift = bri_shift;
13278 wp->w_p_brimin = bri_min;
13279 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013280
13281 return OK;
13282}
13283#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013284
13285/*
13286 * Get the local or global value of 'backupcopy'.
13287 */
13288 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013289get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013290{
13291 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
13292}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020013293
13294#if defined(FEAT_SIGNS) || defined(PROTO)
13295/*
13296 * Return TRUE when window "wp" has a column to draw signs in.
13297 */
13298 int
13299signcolumn_on(win_T *wp)
13300{
13301 if (*wp->w_p_scl == 'n')
13302 return FALSE;
13303 if (*wp->w_p_scl == 'y')
13304 return TRUE;
13305 return (wp->w_buffer->b_signlist != NULL
13306# ifdef FEAT_NETBEANS_INTG
13307 || wp->w_buffer->b_has_sign_column
13308# endif
13309 );
13310}
13311#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013312
13313#if defined(FEAT_EVAL) || defined(PROTO)
13314/*
13315 * Get window or buffer local options.
13316 */
13317 dict_T *
13318get_winbuf_options(int bufopt)
13319{
13320 dict_T *d;
13321 int opt_idx;
13322
13323 d = dict_alloc();
13324 if (d == NULL)
13325 return NULL;
13326
13327 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
13328 {
13329 struct vimoption *opt = &options[opt_idx];
13330
13331 if ((bufopt && (opt->indir & PV_BUF))
13332 || (!bufopt && (opt->indir & PV_WIN)))
13333 {
13334 char_u *varp = get_varp(opt);
13335
13336 if (varp != NULL)
13337 {
13338 if (opt->flags & P_STRING)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013339 dict_add_string(d, opt->fullname, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020013340 else if (opt->flags & P_NUM)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013341 dict_add_number(d, opt->fullname, *(long *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013342 else
Bram Moolenaare0be1672018-07-08 16:50:37 +020013343 dict_add_number(d, opt->fullname, *(int *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013344 }
13345 }
13346 }
13347
13348 return d;
13349}
13350#endif