blob: 77d1024ecddb41d0dcd8b46ddd56b5d1e3f56f09 [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 Moolenaaraa5df7e2019-02-03 14:53:10 +0100256# define PV_TMOD OPT_WIN(WV_TMOD)
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200257#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200258#ifdef FEAT_SIGNS
259# define PV_SCL OPT_WIN(WV_SCL)
260#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000261
262/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000263typedef enum
264{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000265 PV_NONE = 0,
266 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000267} idopt_T;
268
269/*
270 * Options local to a window have a value local to a buffer and global to all
271 * buffers. Indicate this by setting "var" to VAR_WIN.
272 */
273#define VAR_WIN ((char_u *)-1)
274
275/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000276 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000277 * Only to be used in option.c!
278 */
279static int p_ai;
280static int p_bin;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000281static int p_bomb;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000282static char_u *p_bh;
283static char_u *p_bt;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000284static int p_bl;
285static int p_ci;
286#ifdef FEAT_CINDENT
287static int p_cin;
288static char_u *p_cink;
289static char_u *p_cino;
290#endif
291#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
292static char_u *p_cinw;
293#endif
294#ifdef FEAT_COMMENTS
295static char_u *p_com;
296#endif
297#ifdef FEAT_FOLDING
298static char_u *p_cms;
299#endif
300#ifdef FEAT_INS_EXPAND
301static char_u *p_cpt;
302#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000303#ifdef FEAT_COMPL_FUNC
304static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000305static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000306#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000307static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200308static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000309static int p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000310static char_u *p_fenc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000311static char_u *p_ff;
312static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000313static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000314static char_u *p_ft;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000315static long p_iminsert;
316static long p_imsearch;
317#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
318static char_u *p_inex;
319#endif
320#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
321static char_u *p_inde;
322static char_u *p_indk;
323#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000324#if defined(FEAT_EVAL)
325static char_u *p_fex;
326#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000327static int p_inf;
328static char_u *p_isk;
329#ifdef FEAT_CRYPT
330static char_u *p_key;
331#endif
332#ifdef FEAT_LISP
333static int p_lisp;
334#endif
335static int p_ml;
336static int p_ma;
337static int p_mod;
338static char_u *p_mps;
339static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000340static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000341#ifdef FEAT_TEXTOBJ
342static char_u *p_qe;
343#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000344static int p_ro;
345#ifdef FEAT_SMARTINDENT
346static int p_si;
347#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000348static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000349static long p_sts;
350#if defined(FEAT_SEARCHPATH)
351static char_u *p_sua;
352#endif
353static long p_sw;
354static int p_swf;
355#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000356static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000357static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000358#endif
359#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000360static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000361static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000362static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000363#endif
364static long p_ts;
365static long p_tw;
366static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200367#ifdef FEAT_PERSISTENT_UNDO
368static int p_udf;
369#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000370static long p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200371#ifdef FEAT_VARTABS
372static char_u *p_vsts;
373static char_u *p_vts;
374#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000375#ifdef FEAT_KEYMAP
376static char_u *p_keymap;
377#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200378#ifdef FEAT_TERMINAL
Bram Moolenaarb833c1e2018-05-05 16:36:06 +0200379static long p_twsl; /* 'termwinscroll' */
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200380#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000381
382/* Saved values for when 'bin' is set. */
383static int p_et_nobin;
384static int p_ml_nobin;
385static long p_tw_nobin;
386static long p_wm_nobin;
387
388/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200389static int p_ai_nopaste;
390static int p_et_nopaste;
391static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000392static long p_tw_nopaste;
393static long p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200394#ifdef FEAT_VARTABS
395static char_u *p_vsts_nopaste;
396#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000397
398struct vimoption
399{
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200400 char *fullname; // full option name
401 char *shortname; // permissible abbreviation
402 long_u flags; // see below
403 char_u *var; // global option: pointer to variable;
404 // window-local option: VAR_WIN;
405 // buffer-local option: global value
406 idopt_T indir; // global option: PV_NONE;
407 // local option: indirect option index
408 char_u *def_val[2]; // default values for variable (vi and vim)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000409#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200410 sctx_T script_ctx; // script context where the option was last set
Bram Moolenaarded5f1b2018-11-10 17:33:29 +0100411# define SCTX_INIT , {0, 0, 0}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000412#else
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200413# define SCTX_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000414#endif
415};
416
417#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
418#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
419
420/*
421 * Flags
422 */
423#define P_BOOL 0x01 /* the option is boolean */
424#define P_NUM 0x02 /* the option is numeric */
425#define P_STRING 0x04 /* the option is a string */
426#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000427 must use free_string_option() when
428 assigning new value. Not set if default is
429 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000430#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
431 never be used for local or hidden options! */
432#define P_NODEFAULT 0x40 /* don't set to default value */
433#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
434 use vim_free() when assigning new value */
435#define P_WAS_SET 0x100 /* option has been set/reset */
436#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
437#define P_VI_DEF 0x400 /* Use Vi default for Vim */
438#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
439
440 /* when option changed, what to display: */
441#define P_RSTAT 0x1000 /* redraw status lines */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100442#define P_RWIN 0x2000 /* redraw current window and recompute text */
443#define P_RBUF 0x4000 /* redraw current buffer and recompute text */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000444#define P_RALL 0x6000 /* redraw all windows */
445#define P_RCLR 0x7000 /* clear and redraw all */
446
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200447#define P_COMMA 0x8000 /* comma separated list */
448#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
449 * commas */
450#define P_NODUP 0x20000L /* don't allow duplicate strings */
451#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000452
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200453#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
454#define P_GETTEXT 0x100000L /* expand default value with _() */
455#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
456#define P_NFNAME 0x400000L /* only normal file name chars allowed */
457#define P_INSECURE 0x800000L /* option was set from a modeline */
458#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7554da42016-11-25 22:04:13 +0100459 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200460#define P_NO_ML 0x2000000L /* not allowed in modeline */
461#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200462 * there is a redraw flag */
Bram Moolenaar7554da42016-11-25 22:04:13 +0100463#define P_NDNAME 0x8000000L /* only normal dir name chars allowed */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100464#define P_RWINONLY 0x10000000L /* only redraw current window */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000465
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000466#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
467
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000468/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
469 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100470#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000471# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000472#else
473# define ISP_LATIN1 (char_u *)"@,161-255"
474#endif
475
Bram Moolenaar05fbfdc2017-08-14 22:35:08 +0200476# 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 +0000477
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +0100478/* Default python version for pyx* commands */
479#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
480# define DEFAULT_PYTHON_VER 0
481#elif defined(FEAT_PYTHON3)
482# define DEFAULT_PYTHON_VER 3
483#elif defined(FEAT_PYTHON)
484# define DEFAULT_PYTHON_VER 2
485#else
486# define DEFAULT_PYTHON_VER 0
487#endif
488
Bram Moolenaarce655742019-01-31 14:12:57 +0100489// used for 'cinkeys' and 'indentkeys'
490#define INDENTKEYS_DEFAULT (char_u *)"0{,0},0),0],:,0#,!^F,o,O,e"
491
Bram Moolenaar071d4272004-06-13 20:20:40 +0000492/*
493 * options[] is initialized here.
494 * The order of the options MUST be alphabetic for ":set all" and findoption().
495 * All option names MUST start with a lowercase letter (for findoption()).
496 * Exception: "t_" options are at the end.
497 * The options with a NULL variable are 'hidden': a set command for them is
498 * ignored and they are not printed.
499 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100500static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000501{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200502 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000503#ifdef FEAT_RIGHTLEFT
504 (char_u *)&p_aleph, PV_NONE,
505#else
506 (char_u *)NULL, PV_NONE,
507#endif
508 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100509#if (defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000510 (char_u *)128L,
511#else
512 (char_u *)224L,
513#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200514 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000515 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
Bram Moolenaard0573012017-10-28 21:11:06 +0200516#if defined(FEAT_GUI_MAC)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000517 (char_u *)&p_antialias, PV_NONE,
518 {(char_u *)FALSE, (char_u *)FALSE}
519#else
520 (char_u *)NULL, PV_NONE,
521 {(char_u *)FALSE, (char_u *)FALSE}
522#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200523 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200524 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000525#ifdef FEAT_ARABIC
526 (char_u *)VAR_WIN, PV_ARAB,
527#else
528 (char_u *)NULL, PV_NONE,
529#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200530 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000531 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
532#ifdef FEAT_ARABIC
533 (char_u *)&p_arshape, PV_NONE,
534#else
535 (char_u *)NULL, PV_NONE,
536#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200537 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000538 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
539#ifdef FEAT_RIGHTLEFT
540 (char_u *)&p_ari, PV_NONE,
541#else
542 (char_u *)NULL, PV_NONE,
543#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200544 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000545 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
546#ifdef FEAT_FKMAP
547 (char_u *)&p_altkeymap, PV_NONE,
548#else
549 (char_u *)NULL, PV_NONE,
550#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200551 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000552 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000553 (char_u *)&p_ambw, PV_NONE,
554 {(char_u *)"single", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200555 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000556 {"autochdir", "acd", P_BOOL|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100557#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000558 (char_u *)&p_acd, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100559 {(char_u *)FALSE, (char_u *)0L}
560#else
561 (char_u *)NULL, PV_NONE,
562 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000563#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200564 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000565 {"autoindent", "ai", P_BOOL|P_VI_DEF,
566 (char_u *)&p_ai, PV_AI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200567 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000568 {"autoprint", "ap", P_BOOL|P_VI_DEF,
569 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200570 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000571 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000572 (char_u *)&p_ar, PV_AR,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200573 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000574 {"autowrite", "aw", P_BOOL|P_VI_DEF,
575 (char_u *)&p_aw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200576 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000577 {"autowriteall","awa", P_BOOL|P_VI_DEF,
578 (char_u *)&p_awa, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200579 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000580 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
581 (char_u *)&p_bg, PV_NONE,
582 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100583#if (defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000584 (char_u *)"dark",
585#else
586 (char_u *)"light",
587#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200588 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200589 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000590 (char_u *)&p_bs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200591 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000592 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
593 (char_u *)&p_bk, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200594 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200595 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200596 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000597#ifdef UNIX
598 {(char_u *)"yes", (char_u *)"auto"}
599#else
600 {(char_u *)"auto", (char_u *)"auto"}
601#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200602 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200603 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
604 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000605 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200606 {(char_u *)DFLT_BDIR, (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000607 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000608 (char_u *)&p_bex, PV_NONE,
609 {
610#ifdef VMS
611 (char_u *)"_",
612#else
613 (char_u *)"~",
614#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200615 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200616 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000617#ifdef FEAT_WILDIGN
618 (char_u *)&p_bsk, PV_NONE,
619 {(char_u *)"", (char_u *)0L}
620#else
621 (char_u *)NULL, PV_NONE,
622 {(char_u *)0L, (char_u *)0L}
623#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200624 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000625 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100626#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000627 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100628 {(char_u *)600L, (char_u *)0L}
629#else
630 (char_u *)NULL, PV_NONE,
631 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000632#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200633 SCTX_INIT},
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100634 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100635#ifdef FEAT_BEVAL_GUI
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100636 (char_u *)&p_beval, PV_NONE,
637 {(char_u *)FALSE, (char_u *)0L}
638#else
639 (char_u *)NULL, PV_NONE,
640 {(char_u *)0L, (char_u *)0L}
641#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200642 SCTX_INIT},
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100643 {"balloonevalterm", "bevalterm",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100644#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100645 (char_u *)&p_bevalterm, PV_NONE,
646 {(char_u *)FALSE, (char_u *)0L}
647#else
648 (char_u *)NULL, PV_NONE,
649 {(char_u *)0L, (char_u *)0L}
650#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200651 SCTX_INIT},
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100652 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
653#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
654 (char_u *)&p_bexpr, PV_BEXPR,
655 {(char_u *)"", (char_u *)0L}
656#else
657 (char_u *)NULL, PV_NONE,
658 {(char_u *)0L, (char_u *)0L}
659#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200660 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000661 {"beautify", "bf", P_BOOL|P_VI_DEF,
662 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200663 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200664 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
665 (char_u *)&p_bo, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200666 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000667 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
668 (char_u *)&p_bin, PV_BIN,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200669 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000670 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000671 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200672 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000673 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000674 (char_u *)&p_bomb, PV_BOMB,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200675 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000676 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
677#ifdef FEAT_LINEBREAK
678 (char_u *)&p_breakat, PV_NONE,
679 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
680#else
681 (char_u *)NULL, PV_NONE,
682 {(char_u *)0L, (char_u *)0L}
683#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200684 SCTX_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200685 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
686#ifdef FEAT_LINEBREAK
687 (char_u *)VAR_WIN, PV_BRI,
688 {(char_u *)FALSE, (char_u *)0L}
689#else
690 (char_u *)NULL, PV_NONE,
691 {(char_u *)0L, (char_u *)0L}
692#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200693 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200694 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
695 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200696#ifdef FEAT_LINEBREAK
697 (char_u *)VAR_WIN, PV_BRIOPT,
698 {(char_u *)"", (char_u *)NULL}
699#else
700 (char_u *)NULL, PV_NONE,
701 {(char_u *)"", (char_u *)NULL}
702#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200703 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000704 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
705#ifdef FEAT_BROWSE
706 (char_u *)&p_bsdir, PV_NONE,
707 {(char_u *)"last", (char_u *)0L}
708#else
709 (char_u *)NULL, PV_NONE,
710 {(char_u *)0L, (char_u *)0L}
711#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200712 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000713 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000714 (char_u *)&p_bh, PV_BH,
715 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200716 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000717 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
718 (char_u *)&p_bl, PV_BL,
719 {(char_u *)1L, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200720 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000721 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000722 (char_u *)&p_bt, PV_BT,
723 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200724 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200725 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000726 (char_u *)&p_cmp, PV_NONE,
727 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200728 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000729 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
730#ifdef FEAT_SEARCHPATH
731 (char_u *)&p_cdpath, PV_NONE,
732 {(char_u *)",,", (char_u *)0L}
733#else
734 (char_u *)NULL, PV_NONE,
735 {(char_u *)0L, (char_u *)0L}
736#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200737 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000738 {"cedit", NULL, P_STRING,
739#ifdef FEAT_CMDWIN
740 (char_u *)&p_cedit, PV_NONE,
741 {(char_u *)"", (char_u *)CTRL_F_STR}
742#else
743 (char_u *)NULL, PV_NONE,
744 {(char_u *)0L, (char_u *)0L}
745#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200746 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000747 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +0100748#if defined(FEAT_EVAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000749 (char_u *)&p_ccv, PV_NONE,
750 {(char_u *)"", (char_u *)0L}
751#else
752 (char_u *)NULL, PV_NONE,
753 {(char_u *)0L, (char_u *)0L}
754#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200755 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000756 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
757#ifdef FEAT_CINDENT
758 (char_u *)&p_cin, PV_CIN,
759#else
760 (char_u *)NULL, PV_NONE,
761#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200762 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200763 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000764#ifdef FEAT_CINDENT
765 (char_u *)&p_cink, PV_CINK,
Bram Moolenaarce655742019-01-31 14:12:57 +0100766 {INDENTKEYS_DEFAULT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000767#else
768 (char_u *)NULL, PV_NONE,
769 {(char_u *)0L, (char_u *)0L}
770#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200771 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200772 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000773#ifdef FEAT_CINDENT
774 (char_u *)&p_cino, PV_CINO,
775#else
776 (char_u *)NULL, PV_NONE,
777#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200778 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200779 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000780#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
781 (char_u *)&p_cinw, PV_CINW,
782 {(char_u *)"if,else,while,do,for,switch",
783 (char_u *)0L}
784#else
785 (char_u *)NULL, PV_NONE,
786 {(char_u *)0L, (char_u *)0L}
787#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200788 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200789 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000790#ifdef FEAT_CLIPBOARD
791 (char_u *)&p_cb, PV_NONE,
792# ifdef FEAT_XCLIPBOARD
793 {(char_u *)"autoselect,exclude:cons\\|linux",
794 (char_u *)0L}
795# else
796 {(char_u *)"", (char_u *)0L}
797# endif
798#else
799 (char_u *)NULL, PV_NONE,
800 {(char_u *)"", (char_u *)0L}
801#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200802 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000803 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
804 (char_u *)&p_ch, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200805 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000806 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
807#ifdef FEAT_CMDWIN
808 (char_u *)&p_cwh, PV_NONE,
809#else
810 (char_u *)NULL, PV_NONE,
811#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200812 {(char_u *)7L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200813 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200814#ifdef FEAT_SYN_HL
815 (char_u *)VAR_WIN, PV_CC,
816#else
817 (char_u *)NULL, PV_NONE,
818#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200819 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000820 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
821 (char_u *)&Columns, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200822 {(char_u *)80L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200823 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
824 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000825#ifdef FEAT_COMMENTS
826 (char_u *)&p_com, PV_COM,
827 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
828 (char_u *)0L}
829#else
830 (char_u *)NULL, PV_NONE,
831 {(char_u *)0L, (char_u *)0L}
832#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200833 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200834 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000835#ifdef FEAT_FOLDING
836 (char_u *)&p_cms, PV_CMS,
837 {(char_u *)"/*%s*/", (char_u *)0L}
838#else
839 (char_u *)NULL, PV_NONE,
840 {(char_u *)0L, (char_u *)0L}
841#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200842 SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000843 /* P_PRI_MKRC isn't needed here, optval_default()
844 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000845 {"compatible", "cp", P_BOOL|P_RALL,
846 (char_u *)&p_cp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200847 {(char_u *)TRUE, (char_u *)FALSE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200848 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000849#ifdef FEAT_INS_EXPAND
850 (char_u *)&p_cpt, PV_CPT,
851 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
852#else
853 (char_u *)NULL, PV_NONE,
854 {(char_u *)0L, (char_u *)0L}
855#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200856 SCTX_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200857 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200858#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200859 (char_u *)VAR_WIN, PV_COCU,
860 {(char_u *)"", (char_u *)NULL}
861#else
862 (char_u *)NULL, PV_NONE,
863 {(char_u *)NULL, (char_u *)0L}
864#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200865 SCTX_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200866 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
867#ifdef FEAT_CONCEAL
868 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200869#else
870 (char_u *)NULL, PV_NONE,
871#endif
872 {(char_u *)0L, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200873 SCTX_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000874 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
875#ifdef FEAT_COMPL_FUNC
876 (char_u *)&p_cfu, PV_CFU,
877 {(char_u *)"", (char_u *)0L}
878#else
879 (char_u *)NULL, PV_NONE,
880 {(char_u *)0L, (char_u *)0L}
881#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200882 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200883 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000884#ifdef FEAT_INS_EXPAND
885 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000886 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000887#else
888 (char_u *)NULL, PV_NONE,
889 {(char_u *)0L, (char_u *)0L}
890#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200891 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000892 {"confirm", "cf", P_BOOL|P_VI_DEF,
893#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
894 (char_u *)&p_confirm, PV_NONE,
895#else
896 (char_u *)NULL, PV_NONE,
897#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200898 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000899 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000900 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200901 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000902 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
903 (char_u *)&p_ci, PV_CI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200904 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000905 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
906 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000907 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200908 SCTX_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200909 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200910#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200911 (char_u *)&p_cm, PV_CM,
Bram Moolenaara86187b2018-12-16 18:20:00 +0100912 {(char_u *)"blowfish2", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200913#else
914 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200915 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200916#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200917 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000918 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
919#ifdef FEAT_CSCOPE
920 (char_u *)&p_cspc, PV_NONE,
921#else
922 (char_u *)NULL, PV_NONE,
923#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200924 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000925 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
926#ifdef FEAT_CSCOPE
927 (char_u *)&p_csprg, PV_NONE,
928 {(char_u *)"cscope", (char_u *)0L}
929#else
930 (char_u *)NULL, PV_NONE,
931 {(char_u *)0L, (char_u *)0L}
932#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200933 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200934 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000935#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
936 (char_u *)&p_csqf, PV_NONE,
937 {(char_u *)"", (char_u *)0L}
938#else
939 (char_u *)NULL, PV_NONE,
940 {(char_u *)0L, (char_u *)0L}
941#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200942 SCTX_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200943 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
944#ifdef FEAT_CSCOPE
945 (char_u *)&p_csre, PV_NONE,
946#else
947 (char_u *)NULL, PV_NONE,
948#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200949 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000950 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
951#ifdef FEAT_CSCOPE
952 (char_u *)&p_cst, PV_NONE,
953#else
954 (char_u *)NULL, PV_NONE,
955#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200956 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000957 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
958#ifdef FEAT_CSCOPE
959 (char_u *)&p_csto, PV_NONE,
960#else
961 (char_u *)NULL, PV_NONE,
962#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200963 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000964 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
965#ifdef FEAT_CSCOPE
966 (char_u *)&p_csverbose, PV_NONE,
967#else
968 (char_u *)NULL, PV_NONE,
969#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200970 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200971 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200972 (char_u *)VAR_WIN, PV_CRBIND,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200973 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar177ab9e2019-01-15 21:12:57 +0100974 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000975#ifdef FEAT_SYN_HL
976 (char_u *)VAR_WIN, PV_CUC,
977#else
978 (char_u *)NULL, PV_NONE,
979#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200980 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100981 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000982#ifdef FEAT_SYN_HL
983 (char_u *)VAR_WIN, PV_CUL,
984#else
985 (char_u *)NULL, PV_NONE,
986#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200987 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000988 {"debug", NULL, P_STRING|P_VI_DEF,
989 (char_u *)&p_debug, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200990 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200991 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000992#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000993 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000994 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000995#else
996 (char_u *)NULL, PV_NONE,
997 {(char_u *)NULL, (char_u *)0L}
998#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200999 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001000 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001001 (char_u *)&p_deco, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001002 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001003 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001004#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001005 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001006#else
1007 (char_u *)NULL, PV_NONE,
1008#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001009 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001010 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1011#ifdef FEAT_DIFF
1012 (char_u *)VAR_WIN, PV_DIFF,
1013#else
1014 (char_u *)NULL, PV_NONE,
1015#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001016 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001017 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001018#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1019 (char_u *)&p_dex, PV_NONE,
1020 {(char_u *)"", (char_u *)0L}
1021#else
1022 (char_u *)NULL, PV_NONE,
1023 {(char_u *)0L, (char_u *)0L}
1024#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001025 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001026 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1027 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001028#ifdef FEAT_DIFF
1029 (char_u *)&p_dip, PV_NONE,
Bram Moolenaarc93262b2018-09-10 21:15:40 +02001030 {(char_u *)"internal,filler", (char_u *)NULL}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001031#else
1032 (char_u *)NULL, PV_NONE,
1033 {(char_u *)"", (char_u *)NULL}
1034#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001035 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001036 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1037#ifdef FEAT_DIGRAPHS
1038 (char_u *)&p_dg, PV_NONE,
1039#else
1040 (char_u *)NULL, PV_NONE,
1041#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001042 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001043 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1044 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001045 (char_u *)&p_dir, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001046 {(char_u *)DFLT_DIR, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001047 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001048 (char_u *)&p_dy, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001049 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001050 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001051 (char_u *)&p_ead, PV_NONE,
1052 {(char_u *)"both", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001053 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001054 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1055 (char_u *)&p_ed, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001056 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001057 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaar3848e002016-03-19 18:42:29 +01001058 (char_u *)&p_emoji, PV_NONE,
1059 {(char_u *)TRUE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001060 SCTX_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001061 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001062 (char_u *)&p_enc, PV_NONE,
1063 {(char_u *)ENC_DFLT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001064 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001065 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1066 (char_u *)&p_eol, PV_EOL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001067 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001068 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1069 (char_u *)&p_ea, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001070 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001071 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001072 (char_u *)&p_ep, PV_EP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001073 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001074 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1075 (char_u *)&p_eb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001076 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001077 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1078#ifdef FEAT_QUICKFIX
1079 (char_u *)&p_ef, PV_NONE,
1080 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1081#else
1082 (char_u *)NULL, PV_NONE,
1083 {(char_u *)NULL, (char_u *)0L}
1084#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001085 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001086 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001087#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001088 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001089 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001090#else
1091 (char_u *)NULL, PV_NONE,
1092 {(char_u *)NULL, (char_u *)0L}
1093#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001094 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001095 {"esckeys", "ek", P_BOOL|P_VIM,
1096 (char_u *)&p_ek, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001097 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001098 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001099 (char_u *)&p_ei, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001100 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001101 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1102 (char_u *)&p_et, PV_ET,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001103 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001104 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1105 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001106 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001107 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1108 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001109 (char_u *)&p_fenc, PV_FENC,
1110 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001111 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001112 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001113 (char_u *)&p_fencs, PV_NONE,
1114 {(char_u *)"ucs-bom", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001115 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001116 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1117 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001118 (char_u *)&p_ff, PV_FF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001119 {(char_u *)DFLT_FF, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001120 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001121 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001122 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001123 SCTX_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001124 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1125 (char_u *)&p_fic, PV_NONE,
1126 {
1127#ifdef CASE_INSENSITIVE_FILENAME
1128 (char_u *)TRUE,
1129#else
1130 (char_u *)FALSE,
1131#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001132 (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001133 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001134 (char_u *)&p_ft, PV_FT,
1135 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001136 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001137 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001138 (char_u *)&p_fcs, PV_NONE,
1139 {(char_u *)"vert:|,fold:-", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001140 SCTX_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001141 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1142 (char_u *)&p_fixeol, PV_FIXEOL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001143 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001144 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1145#ifdef FEAT_FKMAP
1146 (char_u *)&p_fkmap, PV_NONE,
1147#else
1148 (char_u *)NULL, PV_NONE,
1149#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001150 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001151 {"flash", "fl", P_BOOL|P_VI_DEF,
1152 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001153 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001154 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001155#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001156 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001157 {(char_u *)"", (char_u *)0L}
1158#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001159 (char_u *)NULL, PV_NONE,
1160 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001161#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001162 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001163 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1164#ifdef FEAT_FOLDING
1165 (char_u *)VAR_WIN, PV_FDC,
1166 {(char_u *)FALSE, (char_u *)0L}
1167#else
1168 (char_u *)NULL, PV_NONE,
1169 {(char_u *)NULL, (char_u *)0L}
1170#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001171 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001172 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1173#ifdef FEAT_FOLDING
1174 (char_u *)VAR_WIN, PV_FEN,
1175 {(char_u *)TRUE, (char_u *)0L}
1176#else
1177 (char_u *)NULL, PV_NONE,
1178 {(char_u *)NULL, (char_u *)0L}
1179#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001180 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001181 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1182#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1183 (char_u *)VAR_WIN, PV_FDE,
1184 {(char_u *)"0", (char_u *)NULL}
1185#else
1186 (char_u *)NULL, PV_NONE,
1187 {(char_u *)NULL, (char_u *)0L}
1188#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001189 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001190 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001191#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001192 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001193 {(char_u *)"#", (char_u *)NULL}
1194#else
1195 (char_u *)NULL, PV_NONE,
1196 {(char_u *)NULL, (char_u *)0L}
1197#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001198 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001199 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001200#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001201 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001202 {(char_u *)0L, (char_u *)0L}
1203#else
1204 (char_u *)NULL, PV_NONE,
1205 {(char_u *)NULL, (char_u *)0L}
1206#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001207 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001208 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001209#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001210 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001211 {(char_u *)-1L, (char_u *)0L}
1212#else
1213 (char_u *)NULL, PV_NONE,
1214 {(char_u *)NULL, (char_u *)0L}
1215#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001216 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001217 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001218 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001219#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001220 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001221 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001222#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001223 (char_u *)NULL, PV_NONE,
1224 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001225#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001226 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001227 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1228#ifdef FEAT_FOLDING
1229 (char_u *)VAR_WIN, PV_FDM,
1230 {(char_u *)"manual", (char_u *)NULL}
1231#else
1232 (char_u *)NULL, PV_NONE,
1233 {(char_u *)NULL, (char_u *)0L}
1234#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001235 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001236 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1237#ifdef FEAT_FOLDING
1238 (char_u *)VAR_WIN, PV_FML,
1239 {(char_u *)1L, (char_u *)0L}
1240#else
1241 (char_u *)NULL, PV_NONE,
1242 {(char_u *)NULL, (char_u *)0L}
1243#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001244 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001245 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1246#ifdef FEAT_FOLDING
1247 (char_u *)VAR_WIN, PV_FDN,
1248 {(char_u *)20L, (char_u *)0L}
1249#else
1250 (char_u *)NULL, PV_NONE,
1251 {(char_u *)NULL, (char_u *)0L}
1252#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001253 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001254 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1255#ifdef FEAT_FOLDING
1256 (char_u *)&p_fdo, PV_NONE,
1257 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1258 (char_u *)0L}
1259#else
1260 (char_u *)NULL, PV_NONE,
1261 {(char_u *)NULL, (char_u *)0L}
1262#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001263 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001264 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1265#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1266 (char_u *)VAR_WIN, PV_FDT,
1267 {(char_u *)"foldtext()", (char_u *)NULL}
1268#else
1269 (char_u *)NULL, PV_NONE,
1270 {(char_u *)NULL, (char_u *)0L}
1271#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001272 SCTX_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001273 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001274#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001275 (char_u *)&p_fex, PV_FEX,
1276 {(char_u *)"", (char_u *)0L}
1277#else
1278 (char_u *)NULL, PV_NONE,
1279 {(char_u *)0L, (char_u *)0L}
1280#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001281 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001282 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1283 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001284 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001285 SCTX_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001286 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1287 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001288 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001289 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001290 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001291 (char_u *)&p_fp, PV_FP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001292 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001293 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1294#ifdef HAVE_FSYNC
1295 (char_u *)&p_fs, PV_NONE,
1296 {(char_u *)TRUE, (char_u *)0L}
1297#else
1298 (char_u *)NULL, PV_NONE,
1299 {(char_u *)FALSE, (char_u *)0L}
1300#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001301 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001302 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1303 (char_u *)&p_gd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001304 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001305 {"graphic", "gr", P_BOOL|P_VI_DEF,
1306 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001307 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001308 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001309#ifdef FEAT_QUICKFIX
1310 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001311 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001312#else
1313 (char_u *)NULL, PV_NONE,
1314 {(char_u *)NULL, (char_u *)0L}
1315#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001316 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001317 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1318#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001319 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001320 {
1321# ifdef WIN3264
1322 /* may be changed to "grep -n" in os_win32.c */
1323 (char_u *)"findstr /n",
1324# else
1325# ifdef UNIX
1326 /* Add an extra file name so that grep will always
1327 * insert a file name in the match line. */
1328 (char_u *)"grep -n $* /dev/null",
1329# else
1330# ifdef VMS
1331 (char_u *)"SEARCH/NUMBERS ",
1332# else
1333 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001334# endif
1335# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001336# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001337 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001338#else
1339 (char_u *)NULL, PV_NONE,
1340 {(char_u *)NULL, (char_u *)0L}
1341#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001342 SCTX_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001343 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001344#ifdef CURSOR_SHAPE
1345 (char_u *)&p_guicursor, PV_NONE,
1346 {
1347# ifdef FEAT_GUI
1348 (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 +01001349# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001350 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1351# endif
1352 (char_u *)0L}
1353#else
1354 (char_u *)NULL, PV_NONE,
1355 {(char_u *)NULL, (char_u *)0L}
1356#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001357 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001358 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001359#ifdef FEAT_GUI
1360 (char_u *)&p_guifont, PV_NONE,
1361 {(char_u *)"", (char_u *)0L}
1362#else
1363 (char_u *)NULL, PV_NONE,
1364 {(char_u *)NULL, (char_u *)0L}
1365#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001366 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001367 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001368#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1369 (char_u *)&p_guifontset, PV_NONE,
1370 {(char_u *)"", (char_u *)0L}
1371#else
1372 (char_u *)NULL, PV_NONE,
1373 {(char_u *)NULL, (char_u *)0L}
1374#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001375 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001376 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001377#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001378 (char_u *)&p_guifontwide, PV_NONE,
1379 {(char_u *)"", (char_u *)0L}
1380#else
1381 (char_u *)NULL, PV_NONE,
1382 {(char_u *)NULL, (char_u *)0L}
1383#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001384 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001385 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001386#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001387 (char_u *)&p_ghr, PV_NONE,
1388#else
1389 (char_u *)NULL, PV_NONE,
1390#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001391 {(char_u *)50L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001392 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001393#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001394 (char_u *)&p_go, PV_NONE,
Bram Moolenaard0573012017-10-28 21:11:06 +02001395# if defined(UNIX) && !defined(FEAT_GUI_MAC)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001396 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001397# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001398 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001399# endif
1400#else
1401 (char_u *)NULL, PV_NONE,
1402 {(char_u *)NULL, (char_u *)0L}
1403#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001404 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001405 {"guipty", NULL, P_BOOL|P_VI_DEF,
1406#if defined(FEAT_GUI)
1407 (char_u *)&p_guipty, PV_NONE,
1408#else
1409 (char_u *)NULL, PV_NONE,
1410#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001411 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001412 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001413#if defined(FEAT_GUI_TABLINE)
1414 (char_u *)&p_gtl, PV_NONE,
1415 {(char_u *)"", (char_u *)0L}
1416#else
1417 (char_u *)NULL, PV_NONE,
1418 {(char_u *)NULL, (char_u *)0L}
1419#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001420 SCTX_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001421 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001422#if defined(FEAT_GUI_TABLINE)
1423 (char_u *)&p_gtt, PV_NONE,
1424 {(char_u *)"", (char_u *)0L}
1425#else
1426 (char_u *)NULL, PV_NONE,
1427 {(char_u *)NULL, (char_u *)0L}
1428#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001429 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001430 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1431 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001432 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001433 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1434 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001435 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001436 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001437 {"helpheight", "hh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001438 (char_u *)&p_hh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001439 {(char_u *)20L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001440 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001441#ifdef FEAT_MULTI_LANG
1442 (char_u *)&p_hlg, PV_NONE,
1443 {(char_u *)"", (char_u *)0L}
1444#else
1445 (char_u *)NULL, PV_NONE,
1446 {(char_u *)0L, (char_u *)0L}
1447#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001448 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001449 {"hidden", "hid", P_BOOL|P_VI_DEF,
1450 (char_u *)&p_hid, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001451 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001452 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001453 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001454 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001455 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001456 {"history", "hi", P_NUM|P_VIM,
1457 (char_u *)&p_hi, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001458 {(char_u *)0L, (char_u *)50L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001459 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1460#ifdef FEAT_RIGHTLEFT
1461 (char_u *)&p_hkmap, PV_NONE,
1462#else
1463 (char_u *)NULL, PV_NONE,
1464#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001465 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001466 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1467#ifdef FEAT_RIGHTLEFT
1468 (char_u *)&p_hkmapp, PV_NONE,
1469#else
1470 (char_u *)NULL, PV_NONE,
1471#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001472 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001473 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1474 (char_u *)&p_hls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001475 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001476 {"icon", NULL, P_BOOL|P_VI_DEF,
1477#ifdef FEAT_TITLE
1478 (char_u *)&p_icon, PV_NONE,
1479#else
1480 (char_u *)NULL, PV_NONE,
1481#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001482 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001483 {"iconstring", NULL, P_STRING|P_VI_DEF,
1484#ifdef FEAT_TITLE
1485 (char_u *)&p_iconstring, PV_NONE,
1486#else
1487 (char_u *)NULL, PV_NONE,
1488#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001489 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001490 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1491 (char_u *)&p_ic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001492 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001493 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001494#if defined(FEAT_EVAL)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001495 (char_u *)&p_imaf, PV_NONE,
1496 {(char_u *)"", (char_u *)NULL}
1497# else
1498 (char_u *)NULL, PV_NONE,
1499 {(char_u *)NULL, (char_u *)0L}
1500# endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001501 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001502 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001503#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001504 (char_u *)&p_imak, PV_NONE,
1505#else
1506 (char_u *)NULL, PV_NONE,
1507#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001508 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001509 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001510 (char_u *)&p_imcmdline, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001511 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001512 {"imdisable", "imd", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001513 (char_u *)&p_imdisable, PV_NONE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001514#ifdef __sgi
1515 {(char_u *)TRUE, (char_u *)0L}
1516#else
1517 {(char_u *)FALSE, (char_u *)0L}
1518#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001519 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001520 {"iminsert", "imi", P_NUM|P_VI_DEF,
1521 (char_u *)&p_iminsert, PV_IMI,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001522 {(char_u *)B_IMODE_NONE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001523 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001524 {"imsearch", "ims", P_NUM|P_VI_DEF,
1525 (char_u *)&p_imsearch, PV_IMS,
Bram Moolenaar4cf56bb2017-09-16 15:50:32 +02001526 {(char_u *)B_IMODE_USE_INSERT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001527 SCTX_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001528 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001529#if defined(FEAT_EVAL)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001530 (char_u *)&p_imsf, PV_NONE,
1531 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001532#else
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001533 (char_u *)NULL, PV_NONE,
1534 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001535#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001536 SCTX_INIT},
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001537 {"imstyle", "imst", P_NUM|P_VI_DEF|P_SECURE,
1538#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1539 (char_u *)&p_imst, PV_NONE,
1540 {(char_u *)IM_OVER_THE_SPOT, (char_u *)0L}
1541#else
1542 (char_u *)NULL, PV_NONE,
1543 {(char_u *)0L, (char_u *)0L}
1544#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001545 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001546 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1547#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001548 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001549 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1550#else
1551 (char_u *)NULL, PV_NONE,
1552 {(char_u *)0L, (char_u *)0L}
1553#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001554 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001555 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1556#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1557 (char_u *)&p_inex, PV_INEX,
1558 {(char_u *)"", (char_u *)0L}
1559#else
1560 (char_u *)NULL, PV_NONE,
1561 {(char_u *)0L, (char_u *)0L}
1562#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001563 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001564 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1565 (char_u *)&p_is, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001566 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001567 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1568#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1569 (char_u *)&p_inde, PV_INDE,
1570 {(char_u *)"", (char_u *)0L}
1571#else
1572 (char_u *)NULL, PV_NONE,
1573 {(char_u *)0L, (char_u *)0L}
1574#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001575 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001576 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001577#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1578 (char_u *)&p_indk, PV_INDK,
Bram Moolenaarce655742019-01-31 14:12:57 +01001579 {INDENTKEYS_DEFAULT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001580#else
1581 (char_u *)NULL, PV_NONE,
1582 {(char_u *)0L, (char_u *)0L}
1583#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001584 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001585 {"infercase", "inf", P_BOOL|P_VI_DEF,
1586 (char_u *)&p_inf, PV_INF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001587 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001588 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1589 (char_u *)&p_im, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001590 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001591 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1592 (char_u *)&p_isf, PV_NONE,
1593 {
1594#ifdef BACKSLASH_IN_FILENAME
1595 /* Excluded are: & and ^ are special in cmd.exe
1596 * ( and ) are used in text separating fnames */
1597 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1598#else
1599# ifdef AMIGA
1600 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1601# else
1602# ifdef VMS
1603 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1604# else /* UNIX et al. */
1605# ifdef EBCDIC
1606 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1607# else
1608 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1609# endif
1610# endif
1611# endif
1612#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001613 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001614 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1615 (char_u *)&p_isi, PV_NONE,
1616 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001617#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001618 (char_u *)"@,48-57,_,128-167,224-235",
1619#else
1620# ifdef EBCDIC
1621 /* TODO: EBCDIC Check this! @ == isalpha()*/
1622 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1623 "112-120,128,140-142,156,158,172,"
1624 "174,186,191,203-207,219-225,235-239,"
1625 "251-254",
1626# else
1627 (char_u *)"@,48-57,_,192-255",
1628# endif
1629#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001630 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001631 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1632 (char_u *)&p_isk, PV_ISK,
1633 {
1634#ifdef EBCDIC
1635 (char_u *)"@,240-249,_",
1636 /* TODO: EBCDIC Check this! @ == isalpha()*/
1637 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1638 "112-120,128,140-142,156,158,172,"
1639 "174,186,191,203-207,219-225,235-239,"
1640 "251-254",
1641#else
1642 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001643# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001644 (char_u *)"@,48-57,_,128-167,224-235"
1645# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001646 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001647# endif
1648#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001649 } SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001650 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1651 (char_u *)&p_isp, PV_NONE,
1652 {
Bram Moolenaard0573012017-10-28 21:11:06 +02001653#if defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001654 (char_u *)"@,~-255",
1655#else
1656# ifdef EBCDIC
1657 /* all chars above 63 are printable */
1658 (char_u *)"63-255",
1659# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001660 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001661# endif
1662#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001663 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001664 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1665 (char_u *)&p_js, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001666 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001667 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1668#ifdef FEAT_CRYPT
1669 (char_u *)&p_key, PV_KEY,
1670 {(char_u *)"", (char_u *)0L}
1671#else
1672 (char_u *)NULL, PV_NONE,
1673 {(char_u *)0L, (char_u *)0L}
1674#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001675 SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001676 {"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 +00001677#ifdef FEAT_KEYMAP
1678 (char_u *)&p_keymap, PV_KMAP,
1679 {(char_u *)"", (char_u *)0L}
1680#else
1681 (char_u *)NULL, PV_NONE,
1682 {(char_u *)"", (char_u *)0L}
1683#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001684 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001685 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001686 (char_u *)&p_km, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001687 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001688 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001689 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001690 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001691#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001692 (char_u *)":help",
1693#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001694# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001695 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001696# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001697# ifdef USEMAN_S
1698 (char_u *)"man -s",
1699# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001700 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001701# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001702# endif
1703#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001704 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001705 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001706#ifdef FEAT_LANGMAP
1707 (char_u *)&p_langmap, PV_NONE,
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001708 {(char_u *)"", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001709#else
1710 (char_u *)NULL, PV_NONE,
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001711 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001712#endif
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001713 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001714 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001715#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1716 (char_u *)&p_lm, PV_NONE,
1717#else
1718 (char_u *)NULL, PV_NONE,
1719#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001720 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001721 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1722#ifdef FEAT_LANGMAP
1723 (char_u *)&p_lnr, PV_NONE,
1724#else
1725 (char_u *)NULL, PV_NONE,
1726#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001727 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001728 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1729#ifdef FEAT_LANGMAP
1730 (char_u *)&p_lrm, PV_NONE,
1731#else
1732 (char_u *)NULL, PV_NONE,
1733#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001734 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001735 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001736 (char_u *)&p_ls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001737 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001738 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1739 (char_u *)&p_lz, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001740 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001741 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1742#ifdef FEAT_LINEBREAK
1743 (char_u *)VAR_WIN, PV_LBR,
1744#else
1745 (char_u *)NULL, PV_NONE,
1746#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001747 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001748 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1749 (char_u *)&Rows, PV_NONE,
1750 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001751#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001752 (char_u *)25L,
1753#else
1754 (char_u *)24L,
1755#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001756 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001757 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1758#ifdef FEAT_GUI
1759 (char_u *)&p_linespace, PV_NONE,
1760#else
1761 (char_u *)NULL, PV_NONE,
1762#endif
1763#ifdef FEAT_GUI_W32
1764 {(char_u *)1L, (char_u *)0L}
1765#else
1766 {(char_u *)0L, (char_u *)0L}
1767#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001768 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001769 {"lisp", NULL, P_BOOL|P_VI_DEF,
1770#ifdef FEAT_LISP
1771 (char_u *)&p_lisp, PV_LISP,
1772#else
1773 (char_u *)NULL, PV_NONE,
1774#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001775 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001776 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001777#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001778 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001779 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1780#else
1781 (char_u *)NULL, PV_NONE,
1782 {(char_u *)"", (char_u *)0L}
1783#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001784 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001785 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1786 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001787 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001788 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001789 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001790 {(char_u *)"eol:$", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001791 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1792 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001793 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001794 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001795#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001796 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001797 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001798#else
1799 (char_u *)NULL, PV_NONE,
1800 {(char_u *)"", (char_u *)0L}
1801#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001802 SCTX_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001803 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001804#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001805 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001806 {(char_u *)TRUE, (char_u *)0L}
1807#else
1808 (char_u *)NULL, PV_NONE,
1809 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001810#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001811 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001812 {"magic", NULL, P_BOOL|P_VI_DEF,
1813 (char_u *)&p_magic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001814 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001815 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001816#ifdef FEAT_QUICKFIX
1817 (char_u *)&p_mef, PV_NONE,
1818 {(char_u *)"", (char_u *)0L}
1819#else
1820 (char_u *)NULL, PV_NONE,
1821 {(char_u *)NULL, (char_u *)0L}
1822#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001823 SCTX_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001824 {"makeencoding","menc", P_STRING|P_VI_DEF,
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001825 (char_u *)&p_menc, PV_MENC,
1826 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001827 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001828 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1829#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001830 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001831# ifdef VMS
1832 {(char_u *)"MMS", (char_u *)0L}
1833# else
1834 {(char_u *)"make", (char_u *)0L}
1835# endif
1836#else
1837 (char_u *)NULL, PV_NONE,
1838 {(char_u *)NULL, (char_u *)0L}
1839#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001840 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001841 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001842 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001843 {(char_u *)"(:),{:},[:]", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001844 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001845 {"matchtime", "mat", P_NUM|P_VI_DEF,
1846 (char_u *)&p_mat, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001847 {(char_u *)5L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001848 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001849 (char_u *)&p_mco, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001850 {(char_u *)2, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001851 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1852#ifdef FEAT_EVAL
1853 (char_u *)&p_mfd, PV_NONE,
1854#else
1855 (char_u *)NULL, PV_NONE,
1856#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001857 {(char_u *)100L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001858 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1859 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001860 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001861 {"maxmem", "mm", P_NUM|P_VI_DEF,
1862 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001863 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001864 SCTX_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001865 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1866 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001867 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001868 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1869 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001870 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001871 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001872 {"menuitems", "mis", P_NUM|P_VI_DEF,
1873#ifdef FEAT_MENU
1874 (char_u *)&p_mis, PV_NONE,
1875#else
1876 (char_u *)NULL, PV_NONE,
1877#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001878 {(char_u *)25L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001879 {"mesg", NULL, P_BOOL|P_VI_DEF,
1880 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001881 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001882 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001883#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001884 (char_u *)&p_msm, PV_NONE,
1885 {(char_u *)"460000,2000,500", (char_u *)0L}
1886#else
1887 (char_u *)NULL, PV_NONE,
1888 {(char_u *)0L, (char_u *)0L}
1889#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001890 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001891 {"modeline", "ml", P_BOOL|P_VIM,
1892 (char_u *)&p_ml, PV_ML,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001893 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001894 {"modelines", "mls", P_NUM|P_VI_DEF,
1895 (char_u *)&p_mls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001896 {(char_u *)5L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001897 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1898 (char_u *)&p_ma, PV_MA,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001899 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001900 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1901 (char_u *)&p_mod, PV_MOD,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001902 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001903 {"more", NULL, P_BOOL|P_VIM,
1904 (char_u *)&p_more, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001905 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001906 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1907 (char_u *)&p_mouse, PV_NONE,
1908 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001909#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001910 (char_u *)"a",
1911#else
1912 (char_u *)"",
1913#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001914 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001915 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1916#ifdef FEAT_GUI
1917 (char_u *)&p_mousef, PV_NONE,
1918#else
1919 (char_u *)NULL, PV_NONE,
1920#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001921 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001922 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1923#ifdef FEAT_GUI
1924 (char_u *)&p_mh, PV_NONE,
1925#else
1926 (char_u *)NULL, PV_NONE,
1927#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001928 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001929 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1930 (char_u *)&p_mousem, PV_NONE,
1931 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001932#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001933 (char_u *)"popup",
1934#else
Bram Moolenaard0573012017-10-28 21:11:06 +02001935# if defined(MACOS_X)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001936 (char_u *)"popup_setpos",
1937# else
1938 (char_u *)"extend",
1939# endif
1940#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001941 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001942 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001943#ifdef FEAT_MOUSESHAPE
1944 (char_u *)&p_mouseshape, PV_NONE,
1945 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1946#else
1947 (char_u *)NULL, PV_NONE,
1948 {(char_u *)NULL, (char_u *)0L}
1949#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001950 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001951 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1952 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001953 {(char_u *)500L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02001954 {"mzschemedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1955#if defined(DYNAMIC_MZSCHEME)
1956 (char_u *)&p_mzschemedll, PV_NONE,
1957 {(char_u *)DYNAMIC_MZSCH_DLL, (char_u *)0L}
1958#else
1959 (char_u *)NULL, PV_NONE,
1960 {(char_u *)"", (char_u *)0L}
1961#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001962 SCTX_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02001963 {"mzschemegcdll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1964#if defined(DYNAMIC_MZSCHEME)
1965 (char_u *)&p_mzschemegcdll, PV_NONE,
1966 {(char_u *)DYNAMIC_MZGC_DLL, (char_u *)0L}
1967#else
1968 (char_u *)NULL, PV_NONE,
1969 {(char_u *)"", (char_u *)0L}
1970#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001971 SCTX_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001972 {"mzquantum", "mzq", P_NUM,
1973#ifdef FEAT_MZSCHEME
1974 (char_u *)&p_mzq, PV_NONE,
1975#else
1976 (char_u *)NULL, PV_NONE,
1977#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001978 {(char_u *)100L, (char_u *)100L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001979 {"novice", NULL, P_BOOL|P_VI_DEF,
1980 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001981 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001982 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001983 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01001984 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001985 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001986 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1987 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001988 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001989 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1990#ifdef FEAT_LINEBREAK
1991 (char_u *)VAR_WIN, PV_NUW,
1992#else
1993 (char_u *)NULL, PV_NONE,
1994#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001995 {(char_u *)8L, (char_u *)4L} SCTX_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001996 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001997#ifdef FEAT_COMPL_FUNC
1998 (char_u *)&p_ofu, PV_OFU,
1999 {(char_u *)"", (char_u *)0L}
2000#else
2001 (char_u *)NULL, PV_NONE,
2002 {(char_u *)0L, (char_u *)0L}
2003#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002004 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002005 {"open", NULL, P_BOOL|P_VI_DEF,
2006 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002007 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002008 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002009#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002010 (char_u *)&p_odev, PV_NONE,
2011#else
2012 (char_u *)NULL, PV_NONE,
2013#endif
2014 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002015 SCTX_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002016 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2017 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002018 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002019 {"optimize", "opt", P_BOOL|P_VI_DEF,
2020 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002021 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002022 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002023 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002024 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002025 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2026 |P_SECURE,
2027 (char_u *)&p_pp, PV_NONE,
2028 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002029 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002030 {"paragraphs", "para", P_STRING|P_VI_DEF,
2031 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002032 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002033 (char_u *)0L} SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002034 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002035 (char_u *)&p_paste, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002036 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002037 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2038 (char_u *)&p_pt, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002039 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002040 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2041#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2042 (char_u *)&p_pex, PV_NONE,
2043 {(char_u *)"", (char_u *)0L}
2044#else
2045 (char_u *)NULL, PV_NONE,
2046 {(char_u *)0L, (char_u *)0L}
2047#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002048 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002049 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002050 (char_u *)&p_pm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002051 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002052 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002053 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002054 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002055#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002056 (char_u *)".,,",
2057#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002058 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002059#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002060 (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002061 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002062#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002063 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002064 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002065#else
2066 (char_u *)NULL, PV_NONE,
2067 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002068#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002069 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002070 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2071 (char_u *)&p_pi, PV_PI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002072 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002073 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002074#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002075 (char_u *)&p_pvh, PV_NONE,
2076#else
2077 (char_u *)NULL, PV_NONE,
2078#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002079 {(char_u *)12L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002080 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002081#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002082 (char_u *)VAR_WIN, PV_PVW,
2083#else
2084 (char_u *)NULL, PV_NONE,
2085#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002086 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002087 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002088#ifdef FEAT_PRINTER
2089 (char_u *)&p_pdev, PV_NONE,
2090 {(char_u *)"", (char_u *)0L}
2091#else
2092 (char_u *)NULL, PV_NONE,
2093 {(char_u *)NULL, (char_u *)0L}
2094#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002095 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002096 {"printencoding", "penc", P_STRING|P_VI_DEF,
2097#ifdef FEAT_POSTSCRIPT
2098 (char_u *)&p_penc, PV_NONE,
2099 {(char_u *)"", (char_u *)0L}
2100#else
2101 (char_u *)NULL, PV_NONE,
2102 {(char_u *)NULL, (char_u *)0L}
2103#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002104 SCTX_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002105 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002106#ifdef FEAT_POSTSCRIPT
2107 (char_u *)&p_pexpr, PV_NONE,
2108 {(char_u *)"", (char_u *)0L}
2109#else
2110 (char_u *)NULL, PV_NONE,
2111 {(char_u *)NULL, (char_u *)0L}
2112#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002113 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002114 {"printfont", "pfn", P_STRING|P_VI_DEF,
2115#ifdef FEAT_PRINTER
2116 (char_u *)&p_pfn, PV_NONE,
2117 {
2118# ifdef MSWIN
2119 (char_u *)"Courier_New:h10",
2120# else
2121 (char_u *)"courier",
2122# endif
2123 (char_u *)0L}
2124#else
2125 (char_u *)NULL, PV_NONE,
2126 {(char_u *)NULL, (char_u *)0L}
2127#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002128 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002129 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2130#ifdef FEAT_PRINTER
2131 (char_u *)&p_header, PV_NONE,
Bram Moolenaar0903d562017-08-26 22:30:15 +02002132 /* untranslated to avoid problems when 'encoding'
2133 * is changed */
2134 {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002135#else
2136 (char_u *)NULL, PV_NONE,
2137 {(char_u *)NULL, (char_u *)0L}
2138#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002139 SCTX_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002140 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01002141#if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002142 (char_u *)&p_pmcs, PV_NONE,
2143 {(char_u *)"", (char_u *)0L}
2144#else
2145 (char_u *)NULL, PV_NONE,
2146 {(char_u *)NULL, (char_u *)0L}
2147#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002148 SCTX_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002149 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01002150#if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002151 (char_u *)&p_pmfn, PV_NONE,
2152 {(char_u *)"", (char_u *)0L}
2153#else
2154 (char_u *)NULL, PV_NONE,
2155 {(char_u *)NULL, (char_u *)0L}
2156#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002157 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002158 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002159#ifdef FEAT_PRINTER
2160 (char_u *)&p_popt, PV_NONE,
2161 {(char_u *)"", (char_u *)0L}
2162#else
2163 (char_u *)NULL, PV_NONE,
2164 {(char_u *)NULL, (char_u *)0L}
2165#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002166 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002167 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002168 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002169 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002170 {"pumheight", "ph", P_NUM|P_VI_DEF,
2171#ifdef FEAT_INS_EXPAND
2172 (char_u *)&p_ph, PV_NONE,
2173#else
2174 (char_u *)NULL, PV_NONE,
2175#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002176 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaara8f04aa2018-02-10 15:36:55 +01002177 {"pumwidth", "pw", P_NUM|P_VI_DEF,
2178#ifdef FEAT_INS_EXPAND
2179 (char_u *)&p_pw, PV_NONE,
2180#else
2181 (char_u *)NULL, PV_NONE,
2182#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002183 {(char_u *)15L, (char_u *)15L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002184 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002185#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002186 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002187 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002188#else
2189 (char_u *)NULL, PV_NONE,
2190 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002191#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002192 SCTX_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002193 {"pythonthreehome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2194#if defined(FEAT_PYTHON3)
2195 (char_u *)&p_py3home, PV_NONE,
2196 {(char_u *)"", (char_u *)0L}
2197#else
2198 (char_u *)NULL, PV_NONE,
2199 {(char_u *)NULL, (char_u *)0L}
2200#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002201 SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002202 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002203#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002204 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002205 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002206#else
2207 (char_u *)NULL, PV_NONE,
2208 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002209#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002210 SCTX_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002211 {"pythonhome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2212#if defined(FEAT_PYTHON)
2213 (char_u *)&p_pyhome, PV_NONE,
2214 {(char_u *)"", (char_u *)0L}
2215#else
2216 (char_u *)NULL, PV_NONE,
2217 {(char_u *)NULL, (char_u *)0L}
2218#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002219 SCTX_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002220 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2221#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2222 (char_u *)&p_pyx, PV_NONE,
2223#else
2224 (char_u *)NULL, PV_NONE,
2225#endif
2226 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002227 SCTX_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002228 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2229#ifdef FEAT_TEXTOBJ
2230 (char_u *)&p_qe, PV_QE,
2231 {(char_u *)"\\", (char_u *)0L}
2232#else
2233 (char_u *)NULL, PV_NONE,
2234 {(char_u *)NULL, (char_u *)0L}
2235#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002236 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002237 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2238 (char_u *)&p_ro, PV_RO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002239 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002240 {"redraw", NULL, P_BOOL|P_VI_DEF,
2241 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002242 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002243 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2244#ifdef FEAT_RELTIME
2245 (char_u *)&p_rdt, PV_NONE,
2246#else
2247 (char_u *)NULL, PV_NONE,
2248#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002249 {(char_u *)2000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002250 {"regexpengine", "re", P_NUM|P_VI_DEF,
2251 (char_u *)&p_re, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002252 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002253 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2254 (char_u *)VAR_WIN, PV_RNU,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002255 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002256 {"remap", NULL, P_BOOL|P_VI_DEF,
2257 (char_u *)&p_remap, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002258 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002259 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002260#ifdef FEAT_RENDER_OPTIONS
2261 (char_u *)&p_rop, PV_NONE,
2262 {(char_u *)"", (char_u *)0L}
2263#else
2264 (char_u *)NULL, PV_NONE,
2265 {(char_u *)NULL, (char_u *)0L}
2266#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002267 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002268 {"report", NULL, P_NUM|P_VI_DEF,
2269 (char_u *)&p_report, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002270 {(char_u *)2L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002271 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2272#ifdef WIN3264
2273 (char_u *)&p_rs, PV_NONE,
2274#else
2275 (char_u *)NULL, PV_NONE,
2276#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002277 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002278 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2279#ifdef FEAT_RIGHTLEFT
2280 (char_u *)&p_ri, PV_NONE,
2281#else
2282 (char_u *)NULL, PV_NONE,
2283#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002284 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002285 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2286#ifdef FEAT_RIGHTLEFT
2287 (char_u *)VAR_WIN, PV_RL,
2288#else
2289 (char_u *)NULL, PV_NONE,
2290#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002291 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002292 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2293#ifdef FEAT_RIGHTLEFT
2294 (char_u *)VAR_WIN, PV_RLC,
2295 {(char_u *)"search", (char_u *)NULL}
2296#else
2297 (char_u *)NULL, PV_NONE,
2298 {(char_u *)NULL, (char_u *)0L}
2299#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002300 SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002301 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002302#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002303 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002304 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002305#else
2306 (char_u *)NULL, PV_NONE,
2307 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002308#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002309 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002310 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2311#ifdef FEAT_CMDL_INFO
2312 (char_u *)&p_ru, PV_NONE,
2313#else
2314 (char_u *)NULL, PV_NONE,
2315#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002316 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002317 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2318#ifdef FEAT_STL_OPT
2319 (char_u *)&p_ruf, PV_NONE,
2320#else
2321 (char_u *)NULL, PV_NONE,
2322#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002323 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002324 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2325 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002326 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002327 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002328 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002329 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2330 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002331 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002332 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002333 (char_u *)VAR_WIN, PV_SCBIND,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002334 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002335 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2336 (char_u *)&p_sj, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002337 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002338 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
Bram Moolenaar375e3392019-01-31 18:26:10 +01002339 (char_u *)&p_so, PV_SO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002340 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002341 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002342 (char_u *)&p_sbo, PV_NONE,
2343 {(char_u *)"ver,jump", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002344 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002345 {"sections", "sect", P_STRING|P_VI_DEF,
2346 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002347 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002348 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002349 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2350 (char_u *)&p_secure, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002351 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002352 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002353 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002354 {(char_u *)"inclusive", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002355 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002356 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002357 (char_u *)&p_slm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002358 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002359 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002360#ifdef FEAT_SESSION
2361 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar4d8bac82018-03-09 21:33:34 +01002362 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize,terminal",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002363 (char_u *)0L}
2364#else
2365 (char_u *)NULL, PV_NONE,
2366 {(char_u *)0L, (char_u *)0L}
2367#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002368 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002369 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2370 (char_u *)&p_sh, PV_NONE,
2371 {
2372#ifdef VMS
2373 (char_u *)"-",
2374#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002375# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002376 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002377# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002378 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002379# endif
2380#endif /* VMS */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002381 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002382 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2383 (char_u *)&p_shcf, PV_NONE,
2384 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002385#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002386 (char_u *)"/c",
2387#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002388 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002389#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002390 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002391 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2392#ifdef FEAT_QUICKFIX
2393 (char_u *)&p_sp, PV_NONE,
2394 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002395#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002396 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002397#else
2398 (char_u *)">",
2399#endif
2400 (char_u *)0L}
2401#else
2402 (char_u *)NULL, PV_NONE,
2403 {(char_u *)0L, (char_u *)0L}
2404#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002405 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002406 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2407 (char_u *)&p_shq, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002408 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002409 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2410 (char_u *)&p_srr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002411 {(char_u *)">", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002412 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2413#ifdef BACKSLASH_IN_FILENAME
2414 (char_u *)&p_ssl, PV_NONE,
2415#else
2416 (char_u *)NULL, PV_NONE,
2417#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002418 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002419 {"shelltemp", "stmp", P_BOOL,
2420 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002421 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002422 {"shelltype", "st", P_NUM|P_VI_DEF,
2423#ifdef AMIGA
2424 (char_u *)&p_st, PV_NONE,
2425#else
2426 (char_u *)NULL, PV_NONE,
2427#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002428 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002429 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2430 (char_u *)&p_sxq, PV_NONE,
2431 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002432#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002433 (char_u *)"\"",
2434#else
2435 (char_u *)"",
2436#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002437 (char_u *)0L} SCTX_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002438 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2439 (char_u *)&p_sxe, PV_NONE,
2440 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002441#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002442 (char_u *)"\"&|<>()@^",
2443#else
2444 (char_u *)"",
2445#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002446 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002447 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2448 (char_u *)&p_sr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002449 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002450 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2451 (char_u *)&p_sw, PV_SW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002452 {(char_u *)8L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002453 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2454 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002455 {(char_u *)"", (char_u *)"filnxtToO"}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002456 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002457 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002458 (char_u *)&p_sn, PV_SN,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002459 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002460 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2461#ifdef FEAT_LINEBREAK
2462 (char_u *)&p_sbr, PV_NONE,
2463#else
2464 (char_u *)NULL, PV_NONE,
2465#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002466 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002467 {"showcmd", "sc", P_BOOL|P_VIM,
2468#ifdef FEAT_CMDL_INFO
2469 (char_u *)&p_sc, PV_NONE,
2470#else
2471 (char_u *)NULL, PV_NONE,
2472#endif
2473 {(char_u *)FALSE,
2474#ifdef UNIX
2475 (char_u *)FALSE
2476#else
2477 (char_u *)TRUE
2478#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002479 } SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002480 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2481 (char_u *)&p_sft, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002482 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002483 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2484 (char_u *)&p_sm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002485 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002486 {"showmode", "smd", P_BOOL|P_VIM,
2487 (char_u *)&p_smd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002488 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002489 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002490 (char_u *)&p_stal, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002491 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002492 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2493 (char_u *)&p_ss, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002494 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002495 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar375e3392019-01-31 18:26:10 +01002496 (char_u *)&p_siso, PV_SISO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002497 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002498 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2499#ifdef FEAT_SIGNS
2500 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002501 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002502#else
2503 (char_u *)NULL, PV_NONE,
2504 {(char_u *)NULL, (char_u *)0L}
2505#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002506 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002507 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2508 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002509 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002510 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2511 (char_u *)&p_scs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002512 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002513 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2514#ifdef FEAT_SMARTINDENT
2515 (char_u *)&p_si, PV_SI,
2516#else
2517 (char_u *)NULL, PV_NONE,
2518#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002519 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002520 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2521 (char_u *)&p_sta, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002522 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002523 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2524 (char_u *)&p_sts, PV_STS,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002525 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002526 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2527 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002528 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002529 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002530#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002531 (char_u *)VAR_WIN, PV_SPELL,
2532#else
2533 (char_u *)NULL, PV_NONE,
2534#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002535 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002536 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002537#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002538 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002539 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002540#else
2541 (char_u *)NULL, PV_NONE,
2542 {(char_u *)0L, (char_u *)0L}
2543#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002544 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002545 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2546 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002547#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002548 (char_u *)&p_spf, PV_SPF,
2549 {(char_u *)"", (char_u *)0L}
2550#else
2551 (char_u *)NULL, PV_NONE,
2552 {(char_u *)0L, (char_u *)0L}
2553#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002554 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002555 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2556 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002557#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002558 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002559 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002560#else
2561 (char_u *)NULL, PV_NONE,
2562 {(char_u *)0L, (char_u *)0L}
2563#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002564 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002565 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002566#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002567 (char_u *)&p_sps, PV_NONE,
2568 {(char_u *)"best", (char_u *)0L}
2569#else
2570 (char_u *)NULL, PV_NONE,
2571 {(char_u *)0L, (char_u *)0L}
2572#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002573 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002574 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002575 (char_u *)&p_sb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002576 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002577 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002578 (char_u *)&p_spr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002579 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002580 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2581 (char_u *)&p_sol, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002582 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002583 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2584#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002585 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002586#else
2587 (char_u *)NULL, PV_NONE,
2588#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002589 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002590 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002591 (char_u *)&p_su, PV_NONE,
2592 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002593 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002594 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002595#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002596 (char_u *)&p_sua, PV_SUA,
2597 {(char_u *)"", (char_u *)0L}
2598#else
2599 (char_u *)NULL, PV_NONE,
2600 {(char_u *)0L, (char_u *)0L}
2601#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002602 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002603 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2604 (char_u *)&p_swf, PV_SWF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002605 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002606 {"swapsync", "sws", P_STRING|P_VI_DEF,
2607 (char_u *)&p_sws, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002608 {(char_u *)"fsync", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002609 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002610 (char_u *)&p_swb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002611 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002612 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2613#ifdef FEAT_SYN_HL
2614 (char_u *)&p_smc, PV_SMC,
2615 {(char_u *)3000L, (char_u *)0L}
2616#else
2617 (char_u *)NULL, PV_NONE,
2618 {(char_u *)0L, (char_u *)0L}
2619#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002620 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002621 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002622#ifdef FEAT_SYN_HL
2623 (char_u *)&p_syn, PV_SYN,
2624 {(char_u *)"", (char_u *)0L}
2625#else
2626 (char_u *)NULL, PV_NONE,
2627 {(char_u *)0L, (char_u *)0L}
2628#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002629 SCTX_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002630 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2631#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002632 (char_u *)&p_tal, PV_NONE,
2633#else
2634 (char_u *)NULL, PV_NONE,
2635#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002636 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002637 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002638 (char_u *)&p_tpm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002639 {(char_u *)10L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002640 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2641 (char_u *)&p_ts, PV_TS,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002642 {(char_u *)8L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002643 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2644 (char_u *)&p_tbs, PV_NONE,
2645#ifdef VMS /* binary searching doesn't appear to work on VMS */
2646 {(char_u *)0L, (char_u *)0L}
2647#else
2648 {(char_u *)TRUE, (char_u *)0L}
2649#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002650 SCTX_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002651 {"tagcase", "tc", P_STRING|P_VIM,
2652 (char_u *)&p_tc, PV_TC,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002653 {(char_u *)"followic", (char_u *)"followic"} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002654 {"taglength", "tl", P_NUM|P_VI_DEF,
2655 (char_u *)&p_tl, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002656 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002657 {"tagrelative", "tr", P_BOOL|P_VIM,
2658 (char_u *)&p_tr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002659 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002660 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002661 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002662 {
2663#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2664 (char_u *)"./tags,./TAGS,tags,TAGS",
2665#else
2666 (char_u *)"./tags,tags",
2667#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002668 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002669 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2670 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002671 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002672 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002673#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002674 (char_u *)&p_tcldll, PV_NONE,
2675 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002676#else
2677 (char_u *)NULL, PV_NONE,
2678 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002679#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002680 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002681 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2682 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002683 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002684 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2685#ifdef FEAT_ARABIC
2686 (char_u *)&p_tbidi, PV_NONE,
2687#else
2688 (char_u *)NULL, PV_NONE,
2689#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002690 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002691 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002692 (char_u *)&p_tenc, PV_NONE,
2693 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002694 SCTX_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002695 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2696#ifdef FEAT_TERMGUICOLORS
2697 (char_u *)&p_tgc, PV_NONE,
2698 {(char_u *)FALSE, (char_u *)FALSE}
2699#else
2700 (char_u*)NULL, PV_NONE,
2701 {(char_u *)FALSE, (char_u *)FALSE}
2702#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002703 SCTX_INIT},
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01002704 {"termmode", "tmod", P_STRING|P_ALLOCED|P_VI_DEF,
2705#ifdef FEAT_TERMINAL
2706 (char_u *)VAR_WIN, PV_TMOD,
2707 {(char_u *)"", (char_u *)NULL}
2708#else
2709 (char_u *)NULL, PV_NONE,
2710 {(char_u *)NULL, (char_u *)0L}
2711#endif
2712 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002713 {"termwinkey", "twk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2714#ifdef FEAT_TERMINAL
2715 (char_u *)VAR_WIN, PV_TWK,
2716 {(char_u *)"", (char_u *)NULL}
2717#else
2718 (char_u *)NULL, PV_NONE,
2719 {(char_u *)NULL, (char_u *)0L}
2720#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002721 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002722 {"termwinscroll", "twsl", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2723#ifdef FEAT_TERMINAL
2724 (char_u *)&p_twsl, PV_TWSL,
2725 {(char_u *)10000L, (char_u *)10000L}
2726#else
2727 (char_u *)NULL, PV_NONE,
2728 {(char_u *)NULL, (char_u *)0L}
2729#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002730 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002731 {"termwinsize", "tws", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2732#ifdef FEAT_TERMINAL
2733 (char_u *)VAR_WIN, PV_TWS,
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002734 {(char_u *)"", (char_u *)NULL}
2735#else
2736 (char_u *)NULL, PV_NONE,
2737 {(char_u *)NULL, (char_u *)0L}
2738#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002739 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002740 {"terse", NULL, P_BOOL|P_VI_DEF,
2741 (char_u *)&p_terse, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002742 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002743 {"textauto", "ta", P_BOOL|P_VIM,
2744 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002745 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002746 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002747 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2748 (char_u *)&p_tx, PV_TX,
2749 {
2750#ifdef USE_CRNL
2751 (char_u *)TRUE,
2752#else
2753 (char_u *)FALSE,
2754#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002755 (char_u *)0L} SCTX_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002756 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002757 (char_u *)&p_tw, PV_TW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002758 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002759 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002760#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002761 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002762#else
2763 (char_u *)NULL, PV_NONE,
2764#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002765 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002766 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2767 (char_u *)&p_to, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002768 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002769 {"timeout", "to", P_BOOL|P_VI_DEF,
2770 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002771 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002772 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2773 (char_u *)&p_tm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002774 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002775 {"title", NULL, P_BOOL|P_VI_DEF,
2776#ifdef FEAT_TITLE
2777 (char_u *)&p_title, PV_NONE,
2778#else
2779 (char_u *)NULL, PV_NONE,
2780#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002781 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002782 {"titlelen", NULL, P_NUM|P_VI_DEF,
2783#ifdef FEAT_TITLE
2784 (char_u *)&p_titlelen, PV_NONE,
2785#else
2786 (char_u *)NULL, PV_NONE,
2787#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002788 {(char_u *)85L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002789 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002790#ifdef FEAT_TITLE
2791 (char_u *)&p_titleold, PV_NONE,
2792 {(char_u *)N_("Thanks for flying Vim"),
2793 (char_u *)0L}
2794#else
2795 (char_u *)NULL, PV_NONE,
2796 {(char_u *)0L, (char_u *)0L}
2797#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002798 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002799 {"titlestring", NULL, P_STRING|P_VI_DEF,
2800#ifdef FEAT_TITLE
2801 (char_u *)&p_titlestring, PV_NONE,
2802#else
2803 (char_u *)NULL, PV_NONE,
2804#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002805 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002806 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002807#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002808 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002809 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002810#else
2811 (char_u *)NULL, PV_NONE,
2812 {(char_u *)0L, (char_u *)0L}
2813#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002814 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002815 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002816#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002817 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002818 {(char_u *)"small", (char_u *)0L}
2819#else
2820 (char_u *)NULL, PV_NONE,
2821 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002822#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002823 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002824 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2825 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002826 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002827 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2828 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002829 {(char_u *)-1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002830 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2831 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002832 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002833 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2834 (char_u *)&p_tf, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002835 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002836 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2837#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2838 (char_u *)&p_ttym, PV_NONE,
2839#else
2840 (char_u *)NULL, PV_NONE,
2841#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002842 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002843 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2844 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002845 {(char_u *)999L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002846 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2847 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002848 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002849 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2850 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002851#ifdef FEAT_PERSISTENT_UNDO
2852 (char_u *)&p_udir, PV_NONE,
2853 {(char_u *)".", (char_u *)0L}
2854#else
2855 (char_u *)NULL, PV_NONE,
2856 {(char_u *)0L, (char_u *)0L}
2857#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002858 SCTX_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002859 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2860#ifdef FEAT_PERSISTENT_UNDO
2861 (char_u *)&p_udf, PV_UDF,
2862#else
2863 (char_u *)NULL, PV_NONE,
2864#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002865 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002866 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002867 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002868 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002869#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002870 (char_u *)1000L,
2871#else
2872 (char_u *)100L,
2873#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002874 (char_u *)0L} SCTX_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002875 {"undoreload", "ur", P_NUM|P_VI_DEF,
2876 (char_u *)&p_ur, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002877 { (char_u *)10000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002878 {"updatecount", "uc", P_NUM|P_VI_DEF,
2879 (char_u *)&p_uc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002880 {(char_u *)200L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002881 {"updatetime", "ut", P_NUM|P_VI_DEF,
2882 (char_u *)&p_ut, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002883 {(char_u *)4000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar04958cb2018-06-23 19:23:02 +02002884 {"varsofttabstop", "vsts", P_STRING|P_VI_DEF|P_VIM|P_COMMA,
2885#ifdef FEAT_VARTABS
2886 (char_u *)&p_vsts, PV_VSTS,
2887 {(char_u *)"", (char_u *)0L}
2888#else
2889 (char_u *)NULL, PV_NONE,
2890 {(char_u *)"", (char_u *)NULL}
2891#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002892 SCTX_INIT},
Bram Moolenaar04958cb2018-06-23 19:23:02 +02002893 {"vartabstop", "vts", P_STRING|P_VI_DEF|P_VIM|P_RBUF|P_COMMA,
2894#ifdef FEAT_VARTABS
2895 (char_u *)&p_vts, PV_VTS,
2896 {(char_u *)"", (char_u *)0L}
2897#else
2898 (char_u *)NULL, PV_NONE,
2899 {(char_u *)"", (char_u *)NULL}
2900#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002901 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002902 {"verbose", "vbs", P_NUM|P_VI_DEF,
2903 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002904 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002905 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2906 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002907 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002908 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2909#ifdef FEAT_SESSION
2910 (char_u *)&p_vdir, PV_NONE,
2911 {(char_u *)DFLT_VDIR, (char_u *)0L}
2912#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 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002918#ifdef FEAT_SESSION
2919 (char_u *)&p_vop, PV_NONE,
Bram Moolenaar13e90412017-11-11 18:16:48 +01002920 {(char_u *)"folds,options,cursor,curdir",
2921 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002922#else
2923 (char_u *)NULL, PV_NONE,
2924 {(char_u *)0L, (char_u *)0L}
2925#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002926 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002927 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002928#ifdef FEAT_VIMINFO
2929 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002930#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002931 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002932#else
2933# ifdef AMIGA
2934 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002935 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002936# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002937 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002938# endif
2939#endif
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 Moolenaarc229e542018-07-08 21:46:56 +02002945 {"viminfofile", "vif", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP
2946 |P_SECURE|P_VI_DEF,
Bram Moolenaarc4da1132017-07-15 19:39:43 +02002947#ifdef FEAT_VIMINFO
2948 (char_u *)&p_viminfofile, PV_NONE,
2949 {(char_u *)"", (char_u *)0L}
2950#else
2951 (char_u *)NULL, PV_NONE,
2952 {(char_u *)0L, (char_u *)0L}
2953#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002954 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002955 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2956 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002957 (char_u *)&p_ve, PV_NONE,
2958 {(char_u *)"", (char_u *)""}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002959 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002960 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2961 (char_u *)&p_vb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002962 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002963 {"w300", NULL, P_NUM|P_VI_DEF,
2964 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002965 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002966 {"w1200", NULL, P_NUM|P_VI_DEF,
2967 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002968 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002969 {"w9600", NULL, P_NUM|P_VI_DEF,
2970 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002971 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002972 {"warn", NULL, P_BOOL|P_VI_DEF,
2973 (char_u *)&p_warn, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002974 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002975 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2976 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002977 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002978 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002979 (char_u *)&p_ww, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002980 {(char_u *)"", (char_u *)"b,s"} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002981 {"wildchar", "wc", P_NUM|P_VIM,
2982 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002983 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002984 SCTX_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002985 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002986 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002987 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002988 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002989#ifdef FEAT_WILDIGN
2990 (char_u *)&p_wig, PV_NONE,
2991#else
2992 (char_u *)NULL, PV_NONE,
2993#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002994 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002995 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2996 (char_u *)&p_wic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002997 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002998 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2999#ifdef FEAT_WILDMENU
3000 (char_u *)&p_wmnu, PV_NONE,
3001#else
3002 (char_u *)NULL, PV_NONE,
3003#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003004 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003005 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003006 (char_u *)&p_wim, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003007 {(char_u *)"full", (char_u *)0L} SCTX_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003008 {"wildoptions", "wop", P_STRING|P_VI_DEF,
3009#ifdef FEAT_CMDL_COMPL
3010 (char_u *)&p_wop, PV_NONE,
3011 {(char_u *)"", (char_u *)0L}
3012#else
3013 (char_u *)NULL, PV_NONE,
3014 {(char_u *)NULL, (char_u *)0L}
3015#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003016 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003017 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3018#ifdef FEAT_WAK
3019 (char_u *)&p_wak, PV_NONE,
3020 {(char_u *)"menu", (char_u *)0L}
3021#else
3022 (char_u *)NULL, PV_NONE,
3023 {(char_u *)NULL, (char_u *)0L}
3024#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003025 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003026 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003027 (char_u *)&p_window, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003028 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003029 {"winheight", "wh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003030 (char_u *)&p_wh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003031 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003032 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003033 (char_u *)VAR_WIN, PV_WFH,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003034 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003035 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003036 (char_u *)VAR_WIN, PV_WFW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003037 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003038 {"winminheight", "wmh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003039 (char_u *)&p_wmh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003040 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003041 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003042 (char_u *)&p_wmw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003043 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003044 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar84ed4ad2017-08-17 11:33:42 +02003045#if defined(WIN3264) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003046 (char_u *)&p_winptydll, PV_NONE, {
3047# ifdef _WIN64
3048 (char_u *)"winpty64.dll",
3049# else
3050 (char_u *)"winpty32.dll",
3051# endif
3052 (char_u *)0L}
3053#else
3054 (char_u *)NULL, PV_NONE,
3055 {(char_u *)0L, (char_u *)0L}
3056#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003057 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003058 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003059 (char_u *)&p_wiw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003060 {(char_u *)20L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003061 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3062 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003063 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003064 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3065 (char_u *)&p_wm, PV_WM,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003066 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003067 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3068 (char_u *)&p_ws, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003069 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003070 {"write", NULL, P_BOOL|P_VI_DEF,
3071 (char_u *)&p_write, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003072 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003073 {"writeany", "wa", P_BOOL|P_VI_DEF,
3074 (char_u *)&p_wa, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003075 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003076 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3077 (char_u *)&p_wb, PV_NONE,
3078 {
3079#ifdef FEAT_WRITEBACKUP
3080 (char_u *)TRUE,
3081#else
3082 (char_u *)FALSE,
3083#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003084 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003085 {"writedelay", "wd", P_NUM|P_VI_DEF,
3086 (char_u *)&p_wd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003087 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003088
3089/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003090#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003091 (char_u *)&vvv, PV_NONE, \
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003092 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003093
3094 p_term("t_AB", T_CAB)
3095 p_term("t_AF", T_CAF)
3096 p_term("t_AL", T_CAL)
3097 p_term("t_al", T_AL)
3098 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003099 p_term("t_BE", T_BE)
3100 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003101 p_term("t_cd", T_CD)
3102 p_term("t_ce", T_CE)
3103 p_term("t_cl", T_CL)
3104 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003105 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003106 p_term("t_Co", T_CCO)
3107 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003108 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003109 p_term("t_cs", T_CS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003110 p_term("t_CV", T_CSV)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003111 p_term("t_da", T_DA)
3112 p_term("t_db", T_DB)
3113 p_term("t_DL", T_CDL)
3114 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003115 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003116 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003117 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003118 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003119 p_term("t_IE", T_CIE)
3120 p_term("t_IS", T_CIS)
3121 p_term("t_ke", T_KE)
3122 p_term("t_ks", T_KS)
3123 p_term("t_le", T_LE)
3124 p_term("t_mb", T_MB)
3125 p_term("t_md", T_MD)
3126 p_term("t_me", T_ME)
3127 p_term("t_mr", T_MR)
3128 p_term("t_ms", T_MS)
3129 p_term("t_nd", T_ND)
3130 p_term("t_op", T_OP)
Bram Moolenaara20f83d2017-10-15 13:35:01 +02003131 p_term("t_RF", T_RFG)
Bram Moolenaare5401222015-06-25 19:16:56 +02003132 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003133 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003134 p_term("t_RI", T_CRI)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003135 p_term("t_Ri", T_SRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003136 p_term("t_RS", T_CRS)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003137 p_term("t_RT", T_CRT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003138 p_term("t_RV", T_CRV)
3139 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003140 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003141 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003142 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003143 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003144 p_term("t_SI", T_CSI)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003145 p_term("t_Si", T_SSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003146 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003147 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003148 p_term("t_sr", T_SR)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003149 p_term("t_ST", T_CST)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003150 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003151 p_term("t_te", T_TE)
3152 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003153 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003154 p_term("t_ts", T_TS)
3155 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003156 p_term("t_ue", T_UE)
3157 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003158 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003159 p_term("t_vb", T_VB)
3160 p_term("t_ve", T_VE)
3161 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003162 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003163 p_term("t_vs", T_VS)
3164 p_term("t_WP", T_CWP)
3165 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003166 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003167 p_term("t_xs", T_XS)
3168 p_term("t_ZH", T_CZH)
3169 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003170 p_term("t_8f", T_8F)
3171 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003172
3173/* terminal key codes are not in here */
3174
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003175 /* end marker */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003176 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCTX_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003177};
3178
3179#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3180
Bram Moolenaar071d4272004-06-13 20:20:40 +00003181static char *(p_ambw_values[]) = {"single", "double", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003182static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003183static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003184static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003185#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003186static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003187#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003188#ifdef FEAT_CMDL_COMPL
3189static char *(p_wop_values[]) = {"tagfile", NULL};
3190#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003191#ifdef FEAT_WAK
3192static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3193#endif
3194static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003195static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3196static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003197static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003198#ifdef FEAT_BROWSE
3199static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3200#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003201static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
Bram Moolenaar57657d82006-04-21 22:12:41 +00003202static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003203static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
Bram Moolenaarf2732452018-06-03 14:47:35 +02003204static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", "prompt", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003205static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003206static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3207#ifdef FEAT_FOLDING
3208static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003209# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003210 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003211# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003212 NULL};
3213static char *(p_fcl_values[]) = {"all", NULL};
3214#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003215#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003216static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003217#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003218#ifdef FEAT_SIGNS
3219static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3220#endif
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01003221#ifdef FEAT_TERMINAL
3222static char *(p_tmod_values[]) = {"winpty", "conpty", "", NULL};
3223#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003224
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003225static void set_options_default(int opt_flags);
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003226static void set_string_default_esc(char *name, char_u *val, int escape);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003227static char_u *term_bg_default(void);
Bram Moolenaar916a8182018-11-25 02:18:29 +01003228static void did_set_option(int opt_idx, int opt_flags, int new_value, int value_checked);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003229static char_u *option_expand(int opt_idx, char_u *val);
3230static void didset_options(void);
3231static void didset_options2(void);
3232static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003233#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003234static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003235#else
3236# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3237#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003238static void set_string_option_global(int opt_idx, char_u **varp);
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003239static 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);
3240static char *set_chars_option(char_u **varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003241#ifdef FEAT_CLIPBOARD
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003242static char *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003243#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003244#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003245static char *did_set_spell_option(int is_spellfile);
3246static char *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003247#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003248#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003249static void set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003250#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003251static char *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3252static 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 +01003253static void check_redraw(long_u flags);
3254static int findoption(char_u *);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02003255static int find_key_option(char_u *arg_arg, int has_lt);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003256static void showoptions(int all, int opt_flags);
3257static int optval_default(struct vimoption *, char_u *varp);
3258static void showoneopt(struct vimoption *, int opt_flags);
Bram Moolenaared18f2c2019-01-24 20:30:52 +01003259static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, long_u flags);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003260static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3261static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3262static int istermoption(struct vimoption *);
3263static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3264static char_u *get_varp(struct vimoption *);
3265static void option_value2string(struct vimoption *, int opt_flags);
3266static void check_winopt(winopt_T *wop);
3267static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003268#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003269static void langmap_init(void);
3270static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003271#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003272static void paste_option_changed(void);
3273static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003274#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003275static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003276#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003277static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3278static int check_opt_strings(char_u *val, char **values, int);
3279static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003280#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003281static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003282#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003283
3284/*
3285 * Initialize the options, first part.
3286 *
3287 * Called only once from main(), just after creating the first buffer.
Bram Moolenaar07268702018-03-01 21:57:32 +01003288 * If "clean_arg" is TRUE Vim was started with --clean.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003289 */
3290 void
Bram Moolenaar07268702018-03-01 21:57:32 +01003291set_init_1(int clean_arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003292{
3293 char_u *p;
3294 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003295 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003296
3297#ifdef FEAT_LANGMAP
3298 langmap_init();
3299#endif
3300
3301 /* Be Vi compatible by default */
3302 p_cp = TRUE;
3303
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003304 /* Use POSIX compatibility when $VIM_POSIX is set. */
3305 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003306 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003307 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003308 set_string_default("shm", (char_u *)"A");
3309 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003310
Bram Moolenaar071d4272004-06-13 20:20:40 +00003311 /*
3312 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003313 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003314 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003315 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003316#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003317 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003318# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003319 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003320# endif
3321#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003322 )
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003323 set_string_default_esc("sh", p, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003324
3325#ifdef FEAT_WILDIGN
3326 /*
3327 * Set the default for 'backupskip' to include environment variables for
3328 * temp files.
3329 */
3330 {
3331# ifdef UNIX
3332 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3333# else
3334 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3335# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003336 int len;
3337 garray_T ga;
3338 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003339
3340 ga_init2(&ga, 1, 100);
3341 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3342 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003343 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003344# ifdef UNIX
3345 if (*names[n] == NUL)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003346# ifdef MACOS_X
3347 p = (char_u *)"/private/tmp";
3348# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003349 p = (char_u *)"/tmp";
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003350# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003351 else
3352# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003353 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003354 if (p != NULL && *p != NUL)
3355 {
3356 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003357 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003358 if (ga_grow(&ga, len) == OK)
3359 {
3360 if (ga.ga_len > 0)
3361 STRCAT(ga.ga_data, ",");
3362 STRCAT(ga.ga_data, p);
3363 add_pathsep(ga.ga_data);
3364 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003365 ga.ga_len += len;
3366 }
3367 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003368 if (mustfree)
3369 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003370 }
3371 if (ga.ga_data != NULL)
3372 {
3373 set_string_default("bsk", ga.ga_data);
3374 vim_free(ga.ga_data);
3375 }
3376 }
3377#endif
3378
3379 /*
3380 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3381 */
3382 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003383 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003384 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003385#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3386 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3387#endif
3388 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003389#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003390 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003391 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003392#else
3393# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003394 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003395 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003396# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003397 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003398# endif
3399#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003400 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003401 opt_idx = findoption((char_u *)"maxmem");
3402 if (opt_idx >= 0)
3403 {
3404#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003405 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3406 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003407#endif
3408 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3409 }
3410 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003411 }
3412
Bram Moolenaar071d4272004-06-13 20:20:40 +00003413#ifdef FEAT_SEARCHPATH
3414 {
3415 char_u *cdpath;
3416 char_u *buf;
3417 int i;
3418 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003419 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003420
3421 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003422 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003423 if (cdpath != NULL)
3424 {
3425 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3426 if (buf != NULL)
3427 {
3428 buf[0] = ','; /* start with ",", current dir first */
3429 j = 1;
3430 for (i = 0; cdpath[i] != NUL; ++i)
3431 {
3432 if (vim_ispathlistsep(cdpath[i]))
3433 buf[j++] = ',';
3434 else
3435 {
3436 if (cdpath[i] == ' ' || cdpath[i] == ',')
3437 buf[j++] = '\\';
3438 buf[j++] = cdpath[i];
3439 }
3440 }
3441 buf[j] = NUL;
3442 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003443 if (opt_idx >= 0)
3444 {
3445 options[opt_idx].def_val[VI_DEFAULT] = buf;
3446 options[opt_idx].flags |= P_DEF_ALLOCED;
3447 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003448 else
3449 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003450 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003451 if (mustfree)
3452 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003453 }
3454 }
3455#endif
3456
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003457#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003458 /* Set print encoding on platforms that don't default to latin1 */
3459 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003460# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003461 (char_u *)"cp1252"
3462# else
3463# ifdef VMS
3464 (char_u *)"dec-mcs"
3465# else
3466# ifdef EBCDIC
3467 (char_u *)"ebcdic-uk"
3468# else
3469# ifdef MAC
3470 (char_u *)"mac-roman"
3471# else /* HPUX */
3472 (char_u *)"hp-roman8"
3473# endif
3474# endif
3475# endif
3476# endif
3477 );
3478#endif
3479
3480#ifdef FEAT_POSTSCRIPT
3481 /* 'printexpr' must be allocated to be able to evaluate it. */
3482 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003483# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003484 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003485# else
3486# ifdef VMS
3487 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3488
3489# else
3490 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3491# endif
3492# endif
3493 );
3494#endif
3495
3496 /*
3497 * Set all the options (except the terminal options) to their default
3498 * value. Also set the global value for local options.
3499 */
3500 set_options_default(0);
3501
Bram Moolenaar07268702018-03-01 21:57:32 +01003502#ifdef CLEAN_RUNTIMEPATH
3503 if (clean_arg)
3504 {
3505 opt_idx = findoption((char_u *)"runtimepath");
3506 if (opt_idx >= 0)
3507 {
3508 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3509 p_rtp = (char_u *)CLEAN_RUNTIMEPATH;
3510 }
3511 opt_idx = findoption((char_u *)"packpath");
3512 if (opt_idx >= 0)
3513 {
3514 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3515 p_pp = (char_u *)CLEAN_RUNTIMEPATH;
3516 }
3517 }
3518#endif
3519
Bram Moolenaar071d4272004-06-13 20:20:40 +00003520#ifdef FEAT_GUI
3521 if (found_reverse_arg)
3522 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3523#endif
3524
3525 curbuf->b_p_initialized = TRUE;
3526 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003527 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003528 check_buf_options(curbuf);
3529 check_win_options(curwin);
3530 check_options();
3531
3532 /* Must be before option_expand(), because that one needs vim_isIDc() */
3533 didset_options();
3534
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003535#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003536 /* Use the current chartab for the generic chartab. This is not in
3537 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003538 init_spell_chartab();
3539#endif
3540
Bram Moolenaar071d4272004-06-13 20:20:40 +00003541 /*
3542 * Expand environment variables and things like "~" for the defaults.
3543 * If option_expand() returns non-NULL the variable is expanded. This can
3544 * only happen for non-indirect options.
3545 * Also set the default to the expanded value, so ":set" does not list
3546 * them.
3547 * Don't set the P_ALLOCED flag, because we don't want to free the
3548 * default.
3549 */
3550 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3551 {
3552 if ((options[opt_idx].flags & P_GETTEXT)
3553 && options[opt_idx].var != NULL)
3554 p = (char_u *)_(*(char **)options[opt_idx].var);
3555 else
3556 p = option_expand(opt_idx, NULL);
3557 if (p != NULL && (p = vim_strsave(p)) != NULL)
3558 {
3559 *(char_u **)options[opt_idx].var = p;
3560 /* VIMEXP
3561 * Defaults for all expanded options are currently the same for Vi
3562 * and Vim. When this changes, add some code here! Also need to
3563 * split P_DEF_ALLOCED in two.
3564 */
3565 if (options[opt_idx].flags & P_DEF_ALLOCED)
3566 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3567 options[opt_idx].def_val[VI_DEFAULT] = p;
3568 options[opt_idx].flags |= P_DEF_ALLOCED;
3569 }
3570 }
3571
Bram Moolenaar071d4272004-06-13 20:20:40 +00003572 save_file_ff(curbuf); /* Buffer is unchanged */
3573
Bram Moolenaar071d4272004-06-13 20:20:40 +00003574#if defined(FEAT_ARABIC)
3575 /* Detect use of mlterm.
3576 * Mlterm is a terminal emulator akin to xterm that has some special
3577 * abilities (bidi namely).
3578 * NOTE: mlterm's author is being asked to 'set' a variable
3579 * instead of an environment variable due to inheritance.
3580 */
3581 if (mch_getenv((char_u *)"MLTERM") != NULL)
3582 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3583#endif
3584
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003585 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003586
Bram Moolenaar071d4272004-06-13 20:20:40 +00003587# if defined(WIN3264) && defined(FEAT_GETTEXT)
3588 /*
3589 * If $LANG isn't set, try to get a good value for it. This makes the
3590 * right language be used automatically. Don't do this for English.
3591 */
3592 if (mch_getenv((char_u *)"LANG") == NULL)
3593 {
3594 char buf[20];
3595
3596 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3597 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3598 * only the first two. */
3599 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3600 (LPTSTR)buf, 20);
3601 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3602 {
3603 /* There are a few exceptions (probably more) */
3604 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3605 STRCPY(buf, "zh_TW");
3606 else if (STRNICMP(buf, "chs", 3) == 0
3607 || STRNICMP(buf, "zhc", 3) == 0)
3608 STRCPY(buf, "zh_CN");
3609 else if (STRNICMP(buf, "jp", 2) == 0)
3610 STRCPY(buf, "ja");
3611 else
3612 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003613 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003614 }
3615 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003616# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003617# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003618 /* Moved to os_mac_conv.c to avoid dependency problems. */
3619 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003620# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003621# endif
3622
3623 /* enc_locale() will try to find the encoding of the current locale. */
3624 p = enc_locale();
3625 if (p != NULL)
3626 {
3627 char_u *save_enc;
3628
3629 /* Try setting 'encoding' and check if the value is valid.
3630 * If not, go back to the default "latin1". */
3631 save_enc = p_enc;
3632 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003633 if (STRCMP(p_enc, "gb18030") == 0)
3634 {
3635 /* We don't support "gb18030", but "cp936" is a good substitute
3636 * for practical purposes, thus use that. It's not an alias to
3637 * still support conversion between gb18030 and utf-8. */
3638 p_enc = vim_strsave((char_u *)"cp936");
3639 vim_free(p);
3640 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003641 if (mb_init() == NULL)
3642 {
3643 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003644 if (opt_idx >= 0)
3645 {
3646 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3647 options[opt_idx].flags |= P_DEF_ALLOCED;
3648 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003649
Bram Moolenaard0573012017-10-28 21:11:06 +02003650#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003651 if (STRCMP(p_enc, "latin1") == 0 || enc_utf8)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003652 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003653 /* Adjust the default for 'isprint' and 'iskeyword' to match
3654 * latin1. Also set the defaults for when 'nocompatible' is
3655 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003656 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003657 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003658 set_string_option_direct((char_u *)"isk", -1,
3659 ISK_LATIN1, OPT_FREE, SID_NONE);
3660 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003661 if (opt_idx >= 0)
3662 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003663 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003664 if (opt_idx >= 0)
3665 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003666 (void)init_chartab();
3667 }
3668#endif
3669
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003670#if defined(WIN3264) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003671 /* Win32 console: When GetACP() returns a different value from
3672 * GetConsoleCP() set 'termencoding'. */
3673 if (GetACP() != GetConsoleCP())
3674 {
3675 char buf[50];
3676
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01003677 /* Win32 console: In ConPTY, GetConsoleCP() returns zero.
3678 * Use an alternative value. */
3679 if (GetConsoleCP() == 0)
3680 sprintf(buf, "cp%ld", (long)GetACP());
3681 else
3682 sprintf(buf, "cp%ld", (long)GetConsoleCP());
Bram Moolenaar071d4272004-06-13 20:20:40 +00003683 p_tenc = vim_strsave((char_u *)buf);
3684 if (p_tenc != NULL)
3685 {
3686 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003687 if (opt_idx >= 0)
3688 {
3689 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3690 options[opt_idx].flags |= P_DEF_ALLOCED;
3691 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003692 convert_setup(&input_conv, p_tenc, p_enc);
3693 convert_setup(&output_conv, p_enc, p_tenc);
3694 }
3695 else
3696 p_tenc = empty_option;
3697 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003698#endif
3699#if defined(WIN3264)
Bram Moolenaar05159a02005-02-26 23:04:13 +00003700 /* $HOME may have characters in active code page. */
3701 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003702#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003703 }
3704 else
3705 {
3706 vim_free(p_enc);
3707 p_enc = save_enc;
3708 }
3709 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003710
3711#ifdef FEAT_MULTI_LANG
3712 /* Set the default for 'helplang'. */
3713 set_helplang_default(get_mess_lang());
3714#endif
3715}
3716
3717/*
3718 * Set an option to its default value.
3719 * This does not take care of side effects!
3720 */
3721 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003722set_option_default(
3723 int opt_idx,
3724 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3725 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003726{
3727 char_u *varp; /* pointer to variable for current option */
3728 int dvi; /* index in def_val[] */
3729 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003730 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003731 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3732
3733 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3734 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003735 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003736 {
3737 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3738 if (flags & P_STRING)
3739 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003740 /* Use set_string_option_direct() for local options to handle
3741 * freeing and allocating the value. */
3742 if (options[opt_idx].indir != PV_NONE)
3743 set_string_option_direct(NULL, opt_idx,
3744 options[opt_idx].def_val[dvi], opt_flags, 0);
3745 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003746 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003747 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3748 free_string_option(*(char_u **)(varp));
3749 *(char_u **)varp = options[opt_idx].def_val[dvi];
3750 options[opt_idx].flags &= ~P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003751 }
3752 }
3753 else if (flags & P_NUM)
3754 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003755 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003756 win_comp_scroll(curwin);
3757 else
3758 {
Bram Moolenaar375e3392019-01-31 18:26:10 +01003759 long def_val = (long)(long_i)options[opt_idx].def_val[dvi];
3760
3761 if ((long *)varp == &curwin->w_p_so
3762 || (long *)varp == &curwin->w_p_siso)
3763 // 'scrolloff' and 'sidescrolloff' local values have a
3764 // different default value than the global default.
3765 *(long *)varp = -1;
3766 else
3767 *(long *)varp = def_val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003768 /* May also set global value for local option. */
3769 if (both)
3770 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
Bram Moolenaar375e3392019-01-31 18:26:10 +01003771 def_val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003772 }
3773 }
3774 else /* P_BOOL */
3775 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003776 /* the cast to long is required for Manx C, long_i is needed for
3777 * MSVC */
3778 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003779#ifdef UNIX
3780 /* 'modeline' defaults to off for root */
3781 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3782 *(int *)varp = FALSE;
3783#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003784 /* May also set global value for local option. */
3785 if (both)
3786 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3787 *(int *)varp;
3788 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003789
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003790 /* The default value is not insecure. */
3791 flagsp = insecure_flag(opt_idx, opt_flags);
3792 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003793 }
3794
3795#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003796 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003797#endif
3798}
3799
3800/*
3801 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003802 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003803 */
3804 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003805set_options_default(
3806 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003807{
3808 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003809 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003810 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003811
3812 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003813 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003814 && (opt_flags == 0
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003815 || (options[i].var != (char_u *)&p_enc
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003816# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003817 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003818 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003819# endif
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003820 )))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003821 set_option_default(i, opt_flags, p_cp);
3822
Bram Moolenaar071d4272004-06-13 20:20:40 +00003823 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003824 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003825 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003826#ifdef FEAT_CINDENT
3827 parse_cino(curbuf);
3828#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003829}
3830
3831/*
3832 * Set the Vi-default value of a string option.
3833 * Used for 'sh', 'backupskip' and 'term'.
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003834 * When "escape" is TRUE escape spaces with a backslash.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003835 */
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003836 static void
3837set_string_default_esc(char *name, char_u *val, int escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003838{
3839 char_u *p;
3840 int opt_idx;
3841
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003842 if (escape && vim_strchr(val, ' ') != NULL)
3843 p = vim_strsave_escaped(val, (char_u *)" ");
3844 else
3845 p = vim_strsave(val);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003846 if (p != NULL) /* we don't want a NULL */
3847 {
3848 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003849 if (opt_idx >= 0)
3850 {
3851 if (options[opt_idx].flags & P_DEF_ALLOCED)
3852 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3853 options[opt_idx].def_val[VI_DEFAULT] = p;
3854 options[opt_idx].flags |= P_DEF_ALLOCED;
3855 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003856 }
3857}
3858
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003859 void
3860set_string_default(char *name, char_u *val)
3861{
3862 set_string_default_esc(name, val, FALSE);
3863}
3864
Bram Moolenaar071d4272004-06-13 20:20:40 +00003865/*
3866 * Set the Vi-default value of a number option.
3867 * Used for 'lines' and 'columns'.
3868 */
3869 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003870set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003871{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003872 int opt_idx;
3873
3874 opt_idx = findoption((char_u *)name);
3875 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003876 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003877}
3878
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003879#if defined(EXITFREE) || defined(PROTO)
3880/*
3881 * Free all options.
3882 */
3883 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003884free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003885{
3886 int i;
3887
3888 for (i = 0; !istermoption(&options[i]); i++)
3889 {
3890 if (options[i].indir == PV_NONE)
3891 {
3892 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003893 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003894 free_string_option(*(char_u **)options[i].var);
3895 if (options[i].flags & P_DEF_ALLOCED)
3896 free_string_option(options[i].def_val[VI_DEFAULT]);
3897 }
3898 else if (options[i].var != VAR_WIN
3899 && (options[i].flags & P_STRING))
3900 /* buffer-local option: free global value */
3901 free_string_option(*(char_u **)options[i].var);
3902 }
3903}
3904#endif
3905
3906
Bram Moolenaar071d4272004-06-13 20:20:40 +00003907/*
3908 * Initialize the options, part two: After getting Rows and Columns and
3909 * setting 'term'.
3910 */
3911 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003912set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003913{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003914 int idx;
3915
Bram Moolenaar071d4272004-06-13 20:20:40 +00003916 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003917 * 'scroll' defaults to half the window height. The stored default is zero,
3918 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003919 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003920 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003921 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003922 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003923 comp_col();
3924
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003925 /*
3926 * 'window' is only for backwards compatibility with Vi.
3927 * Default is Rows - 1.
3928 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003929 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003930 p_window = Rows - 1;
3931 set_number_default("window", Rows - 1);
3932
Bram Moolenaarf740b292006-02-16 22:11:02 +00003933 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003934#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003935 /*
3936 * If 'background' wasn't set by the user, try guessing the value,
3937 * depending on the terminal name. Only need to check for terminals
3938 * with a dark background, that can handle color.
3939 */
3940 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003941 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3942 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003943 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003944 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003945 /* don't mark it as set, when starting the GUI it may be
3946 * changed again */
3947 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003948 }
3949#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003950
3951#ifdef CURSOR_SHAPE
3952 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3953#endif
3954#ifdef FEAT_MOUSESHAPE
3955 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3956#endif
3957#ifdef FEAT_PRINTER
3958 (void)parse_printoptions(); /* parse 'printoptions' default value */
3959#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003960}
3961
3962/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003963 * Return "dark" or "light" depending on the kind of terminal.
3964 * This is just guessing! Recognized are:
3965 * "linux" Linux console
3966 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003967 * "cygwin.*" Cygwin shell
3968 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00003969 * We also check the COLORFGBG environment variable, which is set by
3970 * rxvt and derivatives. This variable contains either two or three
3971 * values separated by semicolons; we want the last value in either
3972 * case. If this value is 0-6 or 8, our background is dark.
3973 */
3974 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003975term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003976{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003977#if defined(WIN3264)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003978 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003979 return (char_u *)"dark";
3980#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003981 char_u *p;
3982
Bram Moolenaarf740b292006-02-16 22:11:02 +00003983 if (STRCMP(T_NAME, "linux") == 0
3984 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003985 || STRNCMP(T_NAME, "cygwin", 6) == 0
3986 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00003987 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3988 && (p = vim_strrchr(p, ';')) != NULL
3989 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3990 && p[2] == NUL))
3991 return (char_u *)"dark";
3992 return (char_u *)"light";
3993#endif
3994}
3995
3996/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003997 * Initialize the options, part three: After reading the .vimrc
3998 */
3999 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004000set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004001{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004002#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004003/*
4004 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4005 * This is done after other initializations, where 'shell' might have been
4006 * set, but only if they have not been set before.
4007 */
4008 char_u *p;
4009 int idx_srr;
4010 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004011# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004012 int idx_sp;
4013 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004014# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004015
4016 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004017 if (idx_srr < 0)
4018 do_srr = FALSE;
4019 else
4020 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004021# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004022 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004023 if (idx_sp < 0)
4024 do_sp = FALSE;
4025 else
4026 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004027# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004028 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004029 if (p != NULL)
4030 {
4031 /*
4032 * Default for p_sp is "| tee", for p_srr is ">".
4033 * For known shells it is changed here to include stderr.
4034 */
4035 if ( fnamecmp(p, "csh") == 0
4036 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004037# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004038 || fnamecmp(p, "csh.exe") == 0
4039 || fnamecmp(p, "tcsh.exe") == 0
4040# endif
4041 )
4042 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004043# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004044 if (do_sp)
4045 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004046# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004047 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004048# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004049 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004050# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004051 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4052 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004053# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004054 if (do_srr)
4055 {
4056 p_srr = (char_u *)">&";
4057 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4058 }
4059 }
4060 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004061 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004062 if ( fnamecmp(p, "sh") == 0
4063 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004064 || fnamecmp(p, "mksh") == 0
4065 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004066 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004067 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004068 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004069 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004070# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004071 || fnamecmp(p, "cmd") == 0
4072 || fnamecmp(p, "sh.exe") == 0
4073 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004074 || fnamecmp(p, "mksh.exe") == 0
4075 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004076 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004077 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004078 || fnamecmp(p, "bash.exe") == 0
4079 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004080# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004081 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004082 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004083# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004084 if (do_sp)
4085 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004086# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004087 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004088# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004089 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004090# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004091 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4092 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004093# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004094 if (do_srr)
4095 {
4096 p_srr = (char_u *)">%s 2>&1";
4097 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4098 }
4099 }
4100 vim_free(p);
4101 }
4102#endif
4103
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004104#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004105 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004106 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4107 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004108 * This is done after other initializations, where 'shell' might have been
4109 * set, but only if they have not been set before. Default for p_shcf is
4110 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004111 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004112 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004113 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004114 {
4115 int idx3;
4116
4117 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004118 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004119 {
4120 p_shcf = (char_u *)"-c";
4121 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4122 }
4123
Bram Moolenaar071d4272004-06-13 20:20:40 +00004124 /* Somehow Win32 requires the quotes around the redirection too */
4125 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004126 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004127 {
4128 p_sxq = (char_u *)"\"";
4129 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4130 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004131 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004132 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4133 {
4134 int idx3;
4135
4136 /*
4137 * cmd.exe on Windows will strip the first and last double quote given
4138 * on the command line, e.g. most of the time things like:
4139 * cmd /c "my path/to/echo" "my args to echo"
4140 * become:
4141 * my path/to/echo" "my args to echo
4142 * when executed.
4143 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004144 * To avoid this, set shellxquote to surround the command in
4145 * parenthesis. This appears to make most commands work, without
4146 * breaking commands that worked previously, such as
4147 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004148 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004149 idx3 = findoption((char_u *)"sxq");
4150 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4151 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004152 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004153 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4154 }
4155
Bram Moolenaara64ba222012-02-12 23:23:31 +01004156 idx3 = findoption((char_u *)"shcf");
4157 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4158 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004159 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004160 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4161 }
4162 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004163#endif
4164
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004165 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004166 {
4167 int idx_ffs = findoption((char_u *)"ffs");
4168
4169 /* Apply the first entry of 'fileformats' to the initial buffer. */
4170 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4171 set_fileformat(default_fileformat(), OPT_LOCAL);
4172 }
4173
Bram Moolenaar071d4272004-06-13 20:20:40 +00004174#ifdef FEAT_TITLE
4175 set_title_defaults();
4176#endif
4177}
4178
4179#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4180/*
4181 * When 'helplang' is still at its default value, set it to "lang".
4182 * Only the first two characters of "lang" are used.
4183 */
4184 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004185set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004186{
4187 int idx;
4188
4189 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4190 return;
4191 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004192 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004193 {
4194 if (options[idx].flags & P_ALLOCED)
4195 free_string_option(p_hlg);
4196 p_hlg = vim_strsave(lang);
4197 if (p_hlg == NULL)
4198 p_hlg = empty_option;
4199 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004200 {
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004201 // zh_CN becomes "cn", zh_TW becomes "tw"
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004202 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4203 {
4204 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4205 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4206 }
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004207 // any C like setting, such as C.UTF-8, becomes "en"
4208 else if (STRLEN(p_hlg) >= 1 && *p_hlg == 'C')
4209 {
4210 p_hlg[0] = 'e';
4211 p_hlg[1] = 'n';
4212 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004213 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004214 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004215 options[idx].flags |= P_ALLOCED;
4216 }
4217}
4218#endif
4219
4220#ifdef FEAT_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00004221 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004222gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004223{
4224 if (gui_get_lightness(gui.back_pixel) < 127)
4225 return (char_u *)"dark";
4226 return (char_u *)"light";
4227}
4228
4229/*
4230 * Option initializations that can only be done after opening the GUI window.
4231 */
4232 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004233init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004234{
4235 /* Set the 'background' option according to the lightness of the
4236 * background color, unless the user has set it already. */
4237 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4238 {
4239 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4240 highlight_changed();
4241 }
4242}
4243#endif
4244
4245#ifdef FEAT_TITLE
4246/*
4247 * 'title' and 'icon' only default to true if they have not been set or reset
4248 * in .vimrc and we can read the old value.
4249 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4250 * they can be reset. This reduces startup time when using X on a remote
4251 * machine.
4252 */
4253 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004254set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004255{
4256 int idx1;
4257 long val;
4258
4259 /*
4260 * If GUI is (going to be) used, we can always set the window title and
4261 * icon name. Saves a bit of time, because the X11 display server does
4262 * not need to be contacted.
4263 */
4264 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004265 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004266 {
4267#ifdef FEAT_GUI
4268 if (gui.starting || gui.in_use)
4269 val = TRUE;
4270 else
4271#endif
4272 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004273 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004274 p_title = val;
4275 }
4276 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004277 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004278 {
4279#ifdef FEAT_GUI
4280 if (gui.starting || gui.in_use)
4281 val = TRUE;
4282 else
4283#endif
4284 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004285 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004286 p_icon = val;
4287 }
4288}
4289#endif
4290
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004291#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004292 static void
4293trigger_optionsset_string(
4294 int opt_idx,
4295 int opt_flags,
4296 char_u *oldval,
4297 char_u *newval)
4298{
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02004299 // Don't do this recursively.
4300 if (oldval != NULL && newval != NULL
4301 && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004302 {
4303 char_u buf_type[7];
4304
4305 sprintf((char *)buf_type, "%s",
4306 (opt_flags & OPT_LOCAL) ? "local" : "global");
4307 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4308 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4309 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4310 apply_autocmds(EVENT_OPTIONSET,
4311 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4312 reset_v_option_vars();
4313 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004314}
4315#endif
4316
Bram Moolenaar071d4272004-06-13 20:20:40 +00004317/*
4318 * Parse 'arg' for option settings.
4319 *
4320 * 'arg' may be IObuff, but only when no errors can be present and option
4321 * does not need to be expanded with option_expand().
4322 * "opt_flags":
4323 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004324 * OPT_GLOBAL for ":setglobal"
4325 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004326 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004327 * OPT_WINONLY to only set window-local options
4328 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004329 *
4330 * returns FAIL if an error is detected, OK otherwise
4331 */
4332 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004333do_set(
4334 char_u *arg, /* option string (may be written to!) */
4335 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004336{
4337 int opt_idx;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004338 char *errmsg;
4339 char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00004340 char_u *startarg;
4341 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4342 int nextchar; /* next non-white char after option name */
4343 int afterchar; /* character just after option name */
4344 int len;
4345 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004346 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004347 int key;
4348 long_u flags; /* flags for current option */
4349 char_u *varp = NULL; /* pointer to variable for current option */
4350 int did_show = FALSE; /* already showed one value */
4351 int adding; /* "opt+=arg" */
4352 int prepending; /* "opt^=arg" */
4353 int removing; /* "opt-=arg" */
4354 int cp_val = 0;
4355 char_u key_name[2];
4356
4357 if (*arg == NUL)
4358 {
4359 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004360 did_show = TRUE;
4361 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004362 }
4363
4364 while (*arg != NUL) /* loop to process all options */
4365 {
4366 errmsg = NULL;
4367 startarg = arg; /* remember for error message */
4368
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004369 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4370 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004371 {
4372 /*
4373 * ":set all" show all options.
4374 * ":set all&" set all options to their default value.
4375 */
4376 arg += 3;
4377 if (*arg == '&')
4378 {
4379 ++arg;
4380 /* Only for :set command set global value of local options. */
4381 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004382 didset_options();
4383 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004384 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004385 }
4386 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004387 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004388 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004389 did_show = TRUE;
4390 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004391 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004392 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004393 {
4394 showoptions(2, opt_flags);
4395 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004396 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004397 arg += 7;
4398 }
4399 else
4400 {
4401 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004402 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004403 {
4404 prefix = 0;
4405 arg += 2;
4406 }
4407 else if (STRNCMP(arg, "inv", 3) == 0)
4408 {
4409 prefix = 2;
4410 arg += 3;
4411 }
4412
4413 /* find end of name */
4414 key = 0;
4415 if (*arg == '<')
4416 {
4417 nextchar = 0;
4418 opt_idx = -1;
4419 /* look out for <t_>;> */
4420 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4421 len = 5;
4422 else
4423 {
4424 len = 1;
4425 while (arg[len] != NUL && arg[len] != '>')
4426 ++len;
4427 }
4428 if (arg[len] != '>')
4429 {
4430 errmsg = e_invarg;
4431 goto skip;
4432 }
4433 arg[len] = NUL; /* put NUL after name */
4434 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4435 opt_idx = findoption(arg + 1);
4436 arg[len++] = '>'; /* restore '>' */
4437 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004438 key = find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004439 }
4440 else
4441 {
4442 len = 0;
4443 /*
4444 * The two characters after "t_" may not be alphanumeric.
4445 */
4446 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4447 len = 4;
4448 else
4449 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4450 ++len;
4451 nextchar = arg[len];
4452 arg[len] = NUL; /* put NUL after name */
4453 opt_idx = findoption(arg);
4454 arg[len] = nextchar; /* restore nextchar */
4455 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004456 key = find_key_option(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004457 }
4458
4459 /* remember character after option name */
4460 afterchar = arg[len];
4461
4462 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004463 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004464 ++len;
4465
4466 adding = FALSE;
4467 prepending = FALSE;
4468 removing = FALSE;
4469 if (arg[len] != NUL && arg[len + 1] == '=')
4470 {
4471 if (arg[len] == '+')
4472 {
4473 adding = TRUE; /* "+=" */
4474 ++len;
4475 }
4476 else if (arg[len] == '^')
4477 {
4478 prepending = TRUE; /* "^=" */
4479 ++len;
4480 }
4481 else if (arg[len] == '-')
4482 {
4483 removing = TRUE; /* "-=" */
4484 ++len;
4485 }
4486 }
4487 nextchar = arg[len];
4488
4489 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4490 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004491 errmsg = N_("E518: Unknown option");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004492 goto skip;
4493 }
4494
4495 if (opt_idx >= 0)
4496 {
4497 if (options[opt_idx].var == NULL) /* hidden option: skip */
4498 {
4499 /* Only give an error message when requesting the value of
4500 * a hidden option, ignore setting it. */
4501 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4502 && (!(options[opt_idx].flags & P_BOOL)
4503 || nextchar == '?'))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004504 errmsg = N_("E519: Option not supported");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004505 goto skip;
4506 }
4507
4508 flags = options[opt_idx].flags;
4509 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4510 }
4511 else
4512 {
4513 flags = P_STRING;
4514 if (key < 0)
4515 {
4516 key_name[0] = KEY2TERMCAP0(key);
4517 key_name[1] = KEY2TERMCAP1(key);
4518 }
4519 else
4520 {
4521 key_name[0] = KS_KEY;
4522 key_name[1] = (key & 0xff);
4523 }
4524 }
4525
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004526 /* Skip all options that are not window-local (used when showing
4527 * an already loaded buffer in a window). */
4528 if ((opt_flags & OPT_WINONLY)
4529 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4530 goto skip;
4531
Bram Moolenaara3227e22006-03-08 21:32:40 +00004532 /* Skip all options that are window-local (used for :vimgrep). */
4533 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4534 && options[opt_idx].var == VAR_WIN)
4535 goto skip;
4536
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004537 /* Disallow changing some options from modelines. */
4538 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004539 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004540 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004541 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004542 errmsg = _("E520: Not allowed in a modeline");
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004543 goto skip;
4544 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004545#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004546 /* In diff mode some options are overruled. This avoids that
4547 * 'foldmethod' becomes "marker" instead of "diff" and that
4548 * "wrap" gets set. */
4549 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004550 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004551 && (
4552#ifdef FEAT_FOLDING
4553 options[opt_idx].indir == PV_FDM ||
4554#endif
4555 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004556 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004557#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004558 }
4559
4560#ifdef HAVE_SANDBOX
4561 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004562 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004563 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004564 errmsg = _(e_sandbox);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004565 goto skip;
4566 }
4567#endif
4568
4569 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4570 {
4571 arg += len;
4572 cp_val = p_cp;
4573 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4574 {
4575 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4576 {
4577 cp_val = FALSE;
4578 arg += 3;
4579 }
4580 else /* "opt&vi": set to Vi default */
4581 {
4582 cp_val = TRUE;
4583 arg += 2;
4584 }
4585 }
4586 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004587 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004588 {
4589 errmsg = e_trailing;
4590 goto skip;
4591 }
4592 }
4593
4594 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004595 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4596 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004597 */
4598 if (nextchar == '?'
4599 || (prefix == 1
4600 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4601 && !(flags & P_BOOL)))
4602 {
4603 /*
4604 * print value
4605 */
4606 if (did_show)
4607 msg_putchar('\n'); /* cursor below last one */
4608 else
4609 {
4610 gotocmdline(TRUE); /* cursor at status line */
4611 did_show = TRUE; /* remember that we did a line */
4612 }
4613 if (opt_idx >= 0)
4614 {
4615 showoneopt(&options[opt_idx], opt_flags);
4616#ifdef FEAT_EVAL
4617 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004618 {
4619 /* Mention where the option was last set. */
4620 if (varp == options[opt_idx].var)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004621 last_set_msg(options[opt_idx].script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004622 else if ((int)options[opt_idx].indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004623 last_set_msg(curwin->w_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004624 (int)options[opt_idx].indir & PV_MASK]);
4625 else if ((int)options[opt_idx].indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004626 last_set_msg(curbuf->b_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004627 (int)options[opt_idx].indir & PV_MASK]);
4628 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004629#endif
4630 }
4631 else
4632 {
4633 char_u *p;
4634
4635 p = find_termcode(key_name);
4636 if (p == NULL)
4637 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004638 errmsg = N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004639 goto skip;
4640 }
4641 else
4642 (void)show_one_termcode(key_name, p, TRUE);
4643 }
4644 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004645 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004646 errmsg = e_trailing;
4647 }
4648 else
4649 {
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004650 int value_is_replaced = !prepending && !adding && !removing;
Bram Moolenaar916a8182018-11-25 02:18:29 +01004651 int value_checked = FALSE;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004652
Bram Moolenaar071d4272004-06-13 20:20:40 +00004653 if (flags & P_BOOL) /* boolean */
4654 {
4655 if (nextchar == '=' || nextchar == ':')
4656 {
4657 errmsg = e_invarg;
4658 goto skip;
4659 }
4660
4661 /*
4662 * ":set opt!": invert
4663 * ":set opt&": reset to default value
4664 * ":set opt<": reset to global value
4665 */
4666 if (nextchar == '!')
4667 value = *(int *)(varp) ^ 1;
4668 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004669 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004670 ((flags & P_VI_DEF) || cp_val)
4671 ? VI_DEFAULT : VIM_DEFAULT];
4672 else if (nextchar == '<')
4673 {
4674 /* For 'autoread' -1 means to use global value. */
4675 if ((int *)varp == &curbuf->b_p_ar
4676 && opt_flags == OPT_LOCAL)
4677 value = -1;
4678 else
4679 value = *(int *)get_varp_scope(&(options[opt_idx]),
4680 OPT_GLOBAL);
4681 }
4682 else
4683 {
4684 /*
4685 * ":set invopt": invert
4686 * ":set opt" or ":set noopt": set or reset
4687 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004688 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004689 {
4690 errmsg = e_trailing;
4691 goto skip;
4692 }
4693 if (prefix == 2) /* inv */
4694 value = *(int *)(varp) ^ 1;
4695 else
4696 value = prefix;
4697 }
4698
4699 errmsg = set_bool_option(opt_idx, varp, (int)value,
4700 opt_flags);
4701 }
4702 else /* numeric or string */
4703 {
4704 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4705 || prefix != 1)
4706 {
4707 errmsg = e_invarg;
4708 goto skip;
4709 }
4710
4711 if (flags & P_NUM) /* numeric */
4712 {
4713 /*
4714 * Different ways to set a number option:
4715 * & set to default value
4716 * < set to global value
4717 * <xx> accept special key codes for 'wildchar'
4718 * c accept any non-digit for 'wildchar'
4719 * [-]0-9 set number
4720 * other error
4721 */
4722 ++arg;
4723 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004724 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004725 ((flags & P_VI_DEF) || cp_val)
4726 ? VI_DEFAULT : VIM_DEFAULT];
4727 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004728 {
4729 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4730 * use the global value. */
4731 if ((long *)varp == &curbuf->b_p_ul
4732 && opt_flags == OPT_LOCAL)
4733 value = NO_LOCAL_UNDOLEVEL;
4734 else
4735 value = *(long *)get_varp_scope(
4736 &(options[opt_idx]), OPT_GLOBAL);
4737 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004738 else if (((long *)varp == &p_wc
4739 || (long *)varp == &p_wcm)
4740 && (*arg == '<'
4741 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004742 || (*arg != NUL
4743 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004744 && !VIM_ISDIGIT(*arg))))
4745 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004746 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004747 if (value == 0 && (long *)varp != &p_wcm)
4748 {
4749 errmsg = e_invarg;
4750 goto skip;
4751 }
4752 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004753 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4754 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004755 /* Allow negative (for 'undolevels'), octal and
4756 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004757 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4758 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004759 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004760 {
4761 errmsg = e_invarg;
4762 goto skip;
4763 }
4764 }
4765 else
4766 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004767 errmsg = N_("E521: Number required after =");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004768 goto skip;
4769 }
4770
4771 if (adding)
4772 value = *(long *)varp + value;
4773 if (prepending)
4774 value = *(long *)varp * value;
4775 if (removing)
4776 value = *(long *)varp - value;
4777 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004778 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004779 }
4780 else if (opt_idx >= 0) /* string */
4781 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004782 char_u *save_arg = NULL;
4783 char_u *s = NULL;
4784 char_u *oldval = NULL; /* previous value if *varp */
4785 char_u *newval;
4786 char_u *origval = NULL;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004787#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004788 char_u *saved_origval = NULL;
4789 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004790#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004791 unsigned newlen;
4792 int comma;
4793 int bs;
4794 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004795 was allocated */
4796
4797 /* When using ":set opt=val" for a global option
4798 * with a local value the local value will be
4799 * reset, use the global value here. */
4800 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004801 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004802 varp = options[opt_idx].var;
4803
4804 /* The old value is kept until we are sure that the
4805 * new value is valid. */
4806 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004807
4808 /* When setting the local value of a global
4809 * option, the old value may be the global value. */
4810 if (((int)options[opt_idx].indir & PV_BOTH)
4811 && (opt_flags & OPT_LOCAL))
4812 origval = *(char_u **)get_varp(
4813 &options[opt_idx]);
4814 else
4815 origval = oldval;
4816
Bram Moolenaar071d4272004-06-13 20:20:40 +00004817 if (nextchar == '&') /* set to default val */
4818 {
4819 newval = options[opt_idx].def_val[
4820 ((flags & P_VI_DEF) || cp_val)
4821 ? VI_DEFAULT : VIM_DEFAULT];
4822 if ((char_u **)varp == &p_bg)
4823 {
4824 /* guess the value of 'background' */
4825#ifdef FEAT_GUI
4826 if (gui.in_use)
4827 newval = gui_bg_default();
4828 else
4829#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004830 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004831 }
4832
4833 /* expand environment variables and ~ (since the
4834 * default value was already expanded, only
4835 * required when an environment variable was set
4836 * later */
4837 if (newval == NULL)
4838 newval = empty_option;
4839 else
4840 {
4841 s = option_expand(opt_idx, newval);
4842 if (s == NULL)
4843 s = newval;
4844 newval = vim_strsave(s);
4845 }
4846 new_value_alloced = TRUE;
4847 }
4848 else if (nextchar == '<') /* set to global val */
4849 {
4850 newval = vim_strsave(*(char_u **)get_varp_scope(
4851 &(options[opt_idx]), OPT_GLOBAL));
4852 new_value_alloced = TRUE;
4853 }
4854 else
4855 {
4856 ++arg; /* jump to after the '=' or ':' */
4857
4858 /*
4859 * Set 'keywordprg' to ":help" if an empty
4860 * value was passed to :set by the user.
4861 * Misuse errbuf[] for the resulting string.
4862 */
4863 if (varp == (char_u *)&p_kp
4864 && (*arg == NUL || *arg == ' '))
4865 {
4866 STRCPY(errbuf, ":help");
4867 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004868 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004869 }
4870 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004871 * Convert 'backspace' number to string, for
4872 * adding, prepending and removing string.
4873 */
4874 else if (varp == (char_u *)&p_bs
4875 && VIM_ISDIGIT(**(char_u **)varp))
4876 {
4877 i = getdigits((char_u **)varp);
4878 switch (i)
4879 {
4880 case 0:
4881 *(char_u **)varp = empty_option;
4882 break;
4883 case 1:
4884 *(char_u **)varp = vim_strsave(
4885 (char_u *)"indent,eol");
4886 break;
4887 case 2:
4888 *(char_u **)varp = vim_strsave(
4889 (char_u *)"indent,eol,start");
4890 break;
4891 }
4892 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004893 if (origval == oldval)
4894 origval = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004895 oldval = *(char_u **)varp;
4896 }
4897 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004898 * Convert 'whichwrap' number to string, for
4899 * backwards compatibility with Vim 3.0.
4900 * Misuse errbuf[] for the resulting string.
4901 */
4902 else if (varp == (char_u *)&p_ww
4903 && VIM_ISDIGIT(*arg))
4904 {
4905 *errbuf = NUL;
4906 i = getdigits(&arg);
4907 if (i & 1)
4908 STRCAT(errbuf, "b,");
4909 if (i & 2)
4910 STRCAT(errbuf, "s,");
4911 if (i & 4)
4912 STRCAT(errbuf, "h,l,");
4913 if (i & 8)
4914 STRCAT(errbuf, "<,>,");
4915 if (i & 16)
4916 STRCAT(errbuf, "[,],");
4917 if (*errbuf != NUL) /* remove trailing , */
4918 errbuf[STRLEN(errbuf) - 1] = NUL;
4919 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004920 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004921 }
4922 /*
4923 * Remove '>' before 'dir' and 'bdir', for
4924 * backwards compatibility with version 3.0
4925 */
4926 else if ( *arg == '>'
4927 && (varp == (char_u *)&p_dir
4928 || varp == (char_u *)&p_bdir))
4929 {
4930 ++arg;
4931 }
4932
Bram Moolenaar071d4272004-06-13 20:20:40 +00004933 /*
4934 * Copy the new string into allocated memory.
4935 * Can't use set_string_option_direct(), because
4936 * we need to remove the backslashes.
4937 */
4938 /* get a bit too much */
4939 newlen = (unsigned)STRLEN(arg) + 1;
4940 if (adding || prepending || removing)
4941 newlen += (unsigned)STRLEN(origval) + 1;
4942 newval = alloc(newlen);
4943 if (newval == NULL) /* out of mem, don't change */
4944 break;
4945 s = newval;
4946
4947 /*
4948 * Copy the string, skip over escaped chars.
4949 * For MS-DOS and WIN32 backslashes before normal
4950 * file name characters are not removed, and keep
4951 * backslash at start, for "\\machine\path", but
4952 * do remove it for "\\\\machine\\path".
4953 * The reverse is found in ExpandOldSetting().
4954 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004955 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004956 {
4957 if (*arg == '\\' && arg[1] != NUL
4958#ifdef BACKSLASH_IN_FILENAME
4959 && !((flags & P_EXPAND)
4960 && vim_isfilec(arg[1])
4961 && (arg[1] != '\\'
4962 || (s == newval
4963 && arg[2] != '\\')))
4964#endif
4965 )
4966 ++arg; /* remove backslash */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004967 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004968 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004969 {
4970 /* copy multibyte char */
4971 mch_memmove(s, arg, (size_t)i);
4972 arg += i;
4973 s += i;
4974 }
4975 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004976 *s++ = *arg++;
4977 }
4978 *s = NUL;
4979
4980 /*
4981 * Expand environment variables and ~.
4982 * Don't do it when adding without inserting a
4983 * comma.
4984 */
4985 if (!(adding || prepending || removing)
4986 || (flags & P_COMMA))
4987 {
4988 s = option_expand(opt_idx, newval);
4989 if (s != NULL)
4990 {
4991 vim_free(newval);
4992 newlen = (unsigned)STRLEN(s) + 1;
4993 if (adding || prepending || removing)
4994 newlen += (unsigned)STRLEN(origval) + 1;
4995 newval = alloc(newlen);
4996 if (newval == NULL)
4997 break;
4998 STRCPY(newval, s);
4999 }
5000 }
5001
5002 /* locate newval[] in origval[] when removing it
5003 * and when adding to avoid duplicates */
5004 i = 0; /* init for GCC */
5005 if (removing || (flags & P_NODUP))
5006 {
5007 i = (int)STRLEN(newval);
5008 bs = 0;
5009 for (s = origval; *s; ++s)
5010 {
5011 if ((!(flags & P_COMMA)
5012 || s == origval
5013 || (s[-1] == ',' && !(bs & 1)))
5014 && STRNCMP(s, newval, i) == 0
5015 && (!(flags & P_COMMA)
5016 || s[i] == ','
5017 || s[i] == NUL))
5018 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005019 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005020 * even number of backslashes or a single
5021 * backslash preceded by a comma before it
5022 * is recognized as a separator */
5023 if ((s > origval + 1
5024 && s[-1] == '\\'
5025 && s[-2] != ',')
5026 || (s == origval + 1
5027 && s[-1] == '\\'))
5028
Bram Moolenaar071d4272004-06-13 20:20:40 +00005029 ++bs;
5030 else
5031 bs = 0;
5032 }
5033
5034 /* do not add if already there */
5035 if ((adding || prepending) && *s)
5036 {
5037 prepending = FALSE;
5038 adding = FALSE;
5039 STRCPY(newval, origval);
5040 }
5041 }
5042
5043 /* concatenate the two strings; add a ',' if
5044 * needed */
5045 if (adding || prepending)
5046 {
5047 comma = ((flags & P_COMMA) && *origval != NUL
5048 && *newval != NUL);
5049 if (adding)
5050 {
5051 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005052 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005053 if (comma && i > 1
5054 && (flags & P_ONECOMMA) == P_ONECOMMA
5055 && origval[i - 1] == ','
5056 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005057 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005058 mch_memmove(newval + i + comma, newval,
5059 STRLEN(newval) + 1);
5060 mch_memmove(newval, origval, (size_t)i);
5061 }
5062 else
5063 {
5064 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005065 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005066 }
5067 if (comma)
5068 newval[i] = ',';
5069 }
5070
5071 /* Remove newval[] from origval[]. (Note: "i" has
5072 * been set above and is used here). */
5073 if (removing)
5074 {
5075 STRCPY(newval, origval);
5076 if (*s)
5077 {
5078 /* may need to remove a comma */
5079 if (flags & P_COMMA)
5080 {
5081 if (s == origval)
5082 {
5083 /* include comma after string */
5084 if (s[i] == ',')
5085 ++i;
5086 }
5087 else
5088 {
5089 /* include comma before string */
5090 --s;
5091 ++i;
5092 }
5093 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005094 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005095 }
5096 }
5097
5098 if (flags & P_FLAGLIST)
5099 {
5100 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005101 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005102 {
5103 /* if options have P_FLAGLIST and
5104 * P_ONECOMMA such as 'whichwrap' */
5105 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005106 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005107 if (*s != ',' && *(s + 1) == ','
5108 && vim_strchr(s + 2, *s) != NULL)
5109 {
5110 /* Remove the duplicated value and
5111 * the next comma. */
5112 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005113 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005114 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005115 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005116 else
5117 {
5118 if ((!(flags & P_COMMA) || *s != ',')
5119 && vim_strchr(s + 1, *s) != NULL)
5120 {
5121 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005122 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005123 }
5124 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005125 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005126 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005127 }
5128
5129 if (save_arg != NULL) /* number for 'whichwrap' */
5130 arg = save_arg;
5131 new_value_alloced = TRUE;
5132 }
5133
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005134 /*
5135 * Set the new value.
5136 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005137 *(char_u **)(varp) = newval;
5138
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005139#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005140 if (!starting
5141# ifdef FEAT_CRYPT
5142 && options[opt_idx].indir != PV_KEY
5143# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005144 && origval != NULL && newval != NULL)
5145 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005146 /* origval may be freed by
5147 * did_set_string_option(), make a copy. */
5148 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005149 /* newval (and varp) may become invalid if the
5150 * buffer is closed by autocommands. */
5151 saved_newval = vim_strsave(newval);
5152 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005153#endif
5154
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005155 {
5156 long_u *p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005157 int secure_saved = secure;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005158
5159 // When an option is set in the sandbox, from a
5160 // modeline or in secure mode, then deal with side
5161 // effects in secure mode. Also when the value was
5162 // set with the P_INSECURE flag and is not
5163 // completely replaced.
5164 if (secure
5165#ifdef HAVE_SANDBOX
5166 || sandbox != 0
5167#endif
5168 || (opt_flags & OPT_MODELINE)
5169 || (!value_is_replaced && (*p & P_INSECURE)))
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005170 ++secure;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005171
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005172 // Handle side effects, and set the global value
5173 // for ":set" on local options. Note: when setting
5174 // 'syntax' or 'filetype' autocommands may be
5175 // triggered that can cause havoc.
5176 errmsg = did_set_string_option(
5177 opt_idx, (char_u **)varp,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005178 new_value_alloced, oldval, errbuf,
5179 opt_flags, &value_checked);
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005180
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005181 secure = secure_saved;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005182 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005183
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005184#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005185 if (errmsg == NULL)
5186 trigger_optionsset_string(opt_idx, opt_flags,
5187 saved_origval, saved_newval);
5188 vim_free(saved_origval);
5189 vim_free(saved_newval);
5190#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005191 /* If error detected, print the error message. */
5192 if (errmsg != NULL)
5193 goto skip;
5194 }
5195 else /* key code option */
5196 {
5197 char_u *p;
5198
5199 if (nextchar == '&')
5200 {
5201 if (add_termcap_entry(key_name, TRUE) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005202 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005203 }
5204 else
5205 {
5206 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005207 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005208 if (*p == '\\' && p[1] != NUL)
5209 ++p;
5210 nextchar = *p;
5211 *p = NUL;
5212 add_termcode(key_name, arg, FALSE);
5213 *p = nextchar;
5214 }
5215 if (full_screen)
5216 ttest(FALSE);
5217 redraw_all_later(CLEAR);
5218 }
5219 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005220
Bram Moolenaar071d4272004-06-13 20:20:40 +00005221 if (opt_idx >= 0)
Bram Moolenaar916a8182018-11-25 02:18:29 +01005222 did_set_option(
5223 opt_idx, opt_flags, value_is_replaced, value_checked);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005224 }
5225
5226skip:
5227 /*
5228 * Advance to next argument.
5229 * - skip until a blank found, taking care of backslashes
5230 * - skip blanks
5231 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5232 */
5233 for (i = 0; i < 2 ; ++i)
5234 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005235 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005236 if (*arg++ == '\\' && *arg != NUL)
5237 ++arg;
5238 arg = skipwhite(arg);
5239 if (*arg != '=')
5240 break;
5241 }
5242 }
5243
5244 if (errmsg != NULL)
5245 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005246 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005247 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005248 if (i + (arg - startarg) < IOSIZE)
5249 {
5250 /* append the argument with the error */
5251 STRCAT(IObuff, ": ");
5252 mch_memmove(IObuff + i, startarg, (arg - startarg));
5253 IObuff[i + (arg - startarg)] = NUL;
5254 }
5255 /* make sure all characters are printable */
5256 trans_characters(IObuff, IOSIZE);
5257
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005258 ++no_wait_return; // wait_return done later
5259 emsg((char *)IObuff); // show error highlighted
Bram Moolenaar071d4272004-06-13 20:20:40 +00005260 --no_wait_return;
5261
5262 return FAIL;
5263 }
5264
5265 arg = skipwhite(arg);
5266 }
5267
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005268theend:
5269 if (silent_mode && did_show)
5270 {
5271 /* After displaying option values in silent mode. */
5272 silent_mode = FALSE;
5273 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5274 msg_putchar('\n');
5275 cursor_on(); /* msg_start() switches it off */
5276 out_flush();
5277 silent_mode = TRUE;
5278 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5279 }
5280
Bram Moolenaar071d4272004-06-13 20:20:40 +00005281 return OK;
5282}
5283
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005284/*
5285 * Call this when an option has been given a new value through a user command.
5286 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5287 */
5288 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005289did_set_option(
5290 int opt_idx,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005291 int opt_flags, // possibly with OPT_MODELINE
5292 int new_value, // value was replaced completely
5293 int value_checked) // value was checked to be safe, no need to set the
5294 // P_INSECURE flag.
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005295{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005296 long_u *p;
5297
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005298 options[opt_idx].flags |= P_WAS_SET;
5299
5300 /* When an option is set in the sandbox, from a modeline or in secure mode
5301 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005302 * flag. */
5303 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar916a8182018-11-25 02:18:29 +01005304 if (!value_checked && (secure
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005305#ifdef HAVE_SANDBOX
5306 || sandbox != 0
5307#endif
Bram Moolenaar916a8182018-11-25 02:18:29 +01005308 || (opt_flags & OPT_MODELINE)))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005309 *p = *p | P_INSECURE;
5310 else if (new_value)
5311 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005312}
5313
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005314 static char *
5315illegal_char(char *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005316{
5317 if (errbuf == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005318 return "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00005319 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005320 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005321 return errbuf;
5322}
5323
5324/*
5325 * Convert a key name or string into a key value.
5326 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005327 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005328 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005329 int
5330string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005331{
5332 if (*arg == '<')
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02005333 return find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005334 if (*arg == '^')
5335 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005336 if (multi_byte)
5337 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005338 return *arg;
5339}
5340
5341#ifdef FEAT_CMDWIN
5342/*
5343 * Check value of 'cedit' and set cedit_key.
5344 * Returns NULL if value is OK, error message otherwise.
5345 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005346 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005347check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005348{
5349 int n;
5350
5351 if (*p_cedit == NUL)
5352 cedit_key = -1;
5353 else
5354 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005355 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005356 if (vim_isprintc(n))
5357 return e_invarg;
5358 cedit_key = n;
5359 }
5360 return NULL;
5361}
5362#endif
5363
5364#ifdef FEAT_TITLE
5365/*
5366 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5367 * maketitle() to create and display it.
5368 * When switching the title or icon off, call mch_restore_title() to get
5369 * the old value back.
5370 */
5371 static void
Bram Moolenaar84a93082018-06-16 22:58:15 +02005372did_set_title(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005373{
5374 if (starting != NO_SCREEN
5375#ifdef FEAT_GUI
5376 && !gui.starting
5377#endif
5378 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00005379 maketitle();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005380}
5381#endif
5382
5383/*
5384 * set_options_bin - called when 'bin' changes value.
5385 */
5386 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005387set_options_bin(
5388 int oldval,
5389 int newval,
5390 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005391{
5392 /*
5393 * The option values that are changed when 'bin' changes are
5394 * copied when 'bin is set and restored when 'bin' is reset.
5395 */
5396 if (newval)
5397 {
5398 if (!oldval) /* switched on */
5399 {
5400 if (!(opt_flags & OPT_GLOBAL))
5401 {
5402 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5403 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5404 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5405 curbuf->b_p_et_nobin = curbuf->b_p_et;
5406 }
5407 if (!(opt_flags & OPT_LOCAL))
5408 {
5409 p_tw_nobin = p_tw;
5410 p_wm_nobin = p_wm;
5411 p_ml_nobin = p_ml;
5412 p_et_nobin = p_et;
5413 }
5414 }
5415
5416 if (!(opt_flags & OPT_GLOBAL))
5417 {
5418 curbuf->b_p_tw = 0; /* no automatic line wrap */
5419 curbuf->b_p_wm = 0; /* no automatic line wrap */
5420 curbuf->b_p_ml = 0; /* no modelines */
5421 curbuf->b_p_et = 0; /* no expandtab */
5422 }
5423 if (!(opt_flags & OPT_LOCAL))
5424 {
5425 p_tw = 0;
5426 p_wm = 0;
5427 p_ml = FALSE;
5428 p_et = FALSE;
5429 p_bin = TRUE; /* needed when called for the "-b" argument */
5430 }
5431 }
5432 else if (oldval) /* switched off */
5433 {
5434 if (!(opt_flags & OPT_GLOBAL))
5435 {
5436 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5437 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5438 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5439 curbuf->b_p_et = curbuf->b_p_et_nobin;
5440 }
5441 if (!(opt_flags & OPT_LOCAL))
5442 {
5443 p_tw = p_tw_nobin;
5444 p_wm = p_wm_nobin;
5445 p_ml = p_ml_nobin;
5446 p_et = p_et_nobin;
5447 }
5448 }
5449}
5450
5451#ifdef FEAT_VIMINFO
5452/*
5453 * Find the parameter represented by the given character (eg ', :, ", or /),
5454 * and return its associated value in the 'viminfo' string.
5455 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005456 * If the parameter is not specified in the string or there is no following
5457 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005458 */
5459 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005460get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005461{
5462 char_u *p;
5463
5464 p = find_viminfo_parameter(type);
5465 if (p != NULL && VIM_ISDIGIT(*p))
5466 return atoi((char *)p);
5467 return -1;
5468}
5469
5470/*
5471 * Find the parameter represented by the given character (eg ''', ':', '"', or
5472 * '/') in the 'viminfo' option and return a pointer to the string after it.
5473 * Return NULL if the parameter is not specified in the string.
5474 */
5475 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005476find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005477{
5478 char_u *p;
5479
5480 for (p = p_viminfo; *p; ++p)
5481 {
5482 if (*p == type)
5483 return p + 1;
5484 if (*p == 'n') /* 'n' is always the last one */
5485 break;
5486 p = vim_strchr(p, ','); /* skip until next ',' */
5487 if (p == NULL) /* hit the end without finding parameter */
5488 break;
5489 }
5490 return NULL;
5491}
5492#endif
5493
5494/*
5495 * Expand environment variables for some string options.
5496 * These string options cannot be indirect!
5497 * If "val" is NULL expand the current value of the option.
5498 * Return pointer to NameBuff, or NULL when not expanded.
5499 */
5500 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005501option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005502{
5503 /* if option doesn't need expansion nothing to do */
5504 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5505 return NULL;
5506
5507 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5508 * expand_env() would truncate the string. */
5509 if (val != NULL && STRLEN(val) > MAXPATHL)
5510 return NULL;
5511
5512 if (val == NULL)
5513 val = *(char_u **)options[opt_idx].var;
5514
5515 /*
5516 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5517 * Escape spaces when expanding 'tags', they are used to separate file
5518 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005519 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005520 */
5521 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005522 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005523#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005524 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5525#endif
5526 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005527 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5528 return NULL;
5529
5530 return NameBuff;
5531}
5532
5533/*
5534 * After setting various option values: recompute variables that depend on
5535 * option values.
5536 */
5537 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005538didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005539{
5540 /* initialize the table for 'iskeyword' et.al. */
5541 (void)init_chartab();
5542
5543 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
5544 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005545 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005546#ifdef FEAT_SESSION
5547 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5548 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5549#endif
5550#ifdef FEAT_FOLDING
5551 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5552#endif
5553 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005554 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005555 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005556#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5557 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5558#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005559#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005560 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005561 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005562 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005563 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005564#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005565#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5566 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5567#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005568#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005569 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5570#endif
5571#ifdef FEAT_CMDWIN
5572 /* set cedit_key */
5573 (void)check_cedit();
5574#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005575#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005576 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005577#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005578#ifdef FEAT_LINEBREAK
5579 /* initialize the table for 'breakat'. */
5580 fill_breakat_flags();
5581#endif
5582
5583}
5584
5585/*
5586 * More side effects of setting options.
5587 */
5588 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005589didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005590{
5591 /* Initialize the highlight_attr[] table. */
5592 (void)highlight_changed();
5593
5594 /* Parse default for 'wildmode' */
5595 check_opt_wim();
5596
5597 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005598 /* Parse default for 'fillchars'. */
5599 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005600
5601#ifdef FEAT_CLIPBOARD
5602 /* Parse default for 'clipboard' */
5603 (void)check_clipboard_option();
5604#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005605#ifdef FEAT_VARTABS
5606 tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_array);
5607 tabstop_set(curbuf->b_p_vts, &curbuf->b_p_vts_array);
5608#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005609}
5610
5611/*
5612 * Check for string options that are NULL (normally only termcap options).
5613 */
5614 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005615check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005616{
5617 int opt_idx;
5618
5619 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5620 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5621 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5622}
5623
5624/*
5625 * Check string options in a buffer for NULL value.
5626 */
5627 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005628check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005629{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005630 check_string_option(&buf->b_p_bh);
5631 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005632 check_string_option(&buf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005633 check_string_option(&buf->b_p_ff);
5634#ifdef FEAT_FIND_ID
5635 check_string_option(&buf->b_p_def);
5636 check_string_option(&buf->b_p_inc);
5637# ifdef FEAT_EVAL
5638 check_string_option(&buf->b_p_inex);
5639# endif
5640#endif
5641#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5642 check_string_option(&buf->b_p_inde);
5643 check_string_option(&buf->b_p_indk);
5644#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005645#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5646 check_string_option(&buf->b_p_bexpr);
5647#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005648#if defined(FEAT_CRYPT)
5649 check_string_option(&buf->b_p_cm);
5650#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005651 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005652#if defined(FEAT_EVAL)
5653 check_string_option(&buf->b_p_fex);
5654#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005655#ifdef FEAT_CRYPT
5656 check_string_option(&buf->b_p_key);
5657#endif
5658 check_string_option(&buf->b_p_kp);
5659 check_string_option(&buf->b_p_mps);
5660 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005661 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005662 check_string_option(&buf->b_p_isk);
5663#ifdef FEAT_COMMENTS
5664 check_string_option(&buf->b_p_com);
5665#endif
5666#ifdef FEAT_FOLDING
5667 check_string_option(&buf->b_p_cms);
5668#endif
5669 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005670#ifdef FEAT_TEXTOBJ
5671 check_string_option(&buf->b_p_qe);
5672#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005673#ifdef FEAT_SYN_HL
5674 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005675 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005676#endif
5677#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005678 check_string_option(&buf->b_s.b_p_spc);
5679 check_string_option(&buf->b_s.b_p_spf);
5680 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005681#endif
5682#ifdef FEAT_SEARCHPATH
5683 check_string_option(&buf->b_p_sua);
5684#endif
5685#ifdef FEAT_CINDENT
5686 check_string_option(&buf->b_p_cink);
5687 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005688 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005689#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005690 check_string_option(&buf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005691#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5692 check_string_option(&buf->b_p_cinw);
5693#endif
5694#ifdef FEAT_INS_EXPAND
5695 check_string_option(&buf->b_p_cpt);
5696#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005697#ifdef FEAT_COMPL_FUNC
5698 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005699 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005700#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005701#ifdef FEAT_KEYMAP
5702 check_string_option(&buf->b_p_keymap);
5703#endif
5704#ifdef FEAT_QUICKFIX
5705 check_string_option(&buf->b_p_gp);
5706 check_string_option(&buf->b_p_mp);
5707 check_string_option(&buf->b_p_efm);
5708#endif
5709 check_string_option(&buf->b_p_ep);
5710 check_string_option(&buf->b_p_path);
5711 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005712 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005713#ifdef FEAT_INS_EXPAND
5714 check_string_option(&buf->b_p_dict);
5715 check_string_option(&buf->b_p_tsr);
5716#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005717#ifdef FEAT_LISP
5718 check_string_option(&buf->b_p_lw);
5719#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005720 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005721 check_string_option(&buf->b_p_menc);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005722#ifdef FEAT_VARTABS
5723 check_string_option(&buf->b_p_vsts);
5724 check_string_option(&buf->b_p_vts);
5725#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005726}
5727
5728/*
5729 * Free the string allocated for an option.
5730 * Checks for the string being empty_option. This may happen if we're out of
5731 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5732 * check_options().
5733 * Does NOT check for P_ALLOCED flag!
5734 */
5735 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005736free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005737{
5738 if (p != empty_option)
5739 vim_free(p);
5740}
5741
5742 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005743clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005744{
5745 if (*pp != empty_option)
5746 vim_free(*pp);
5747 *pp = empty_option;
5748}
5749
5750 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005751check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005752{
5753 if (*pp == NULL)
5754 *pp = empty_option;
5755}
5756
5757/*
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005758 * Return the option index found by a pointer into term_strings[].
5759 * Return -1 if not found.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005760 */
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005761 int
5762get_term_opt_idx(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005763{
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005764 int opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005765
5766 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5767 if (options[opt_idx].var == (char_u *)p)
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005768 return opt_idx;
5769 return -1; // cannot happen: didn't find it!
5770}
5771
5772/*
5773 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5774 * Return the option index or -1 if not found.
5775 */
5776 int
5777set_term_option_alloced(char_u **p)
5778{
5779 int opt_idx = get_term_opt_idx(p);
5780
5781 if (opt_idx >= 0)
5782 options[opt_idx].flags |= P_ALLOCED;
5783 return opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005784}
5785
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005786#if defined(FEAT_EVAL) || defined(PROTO)
5787/*
5788 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5789 * Return FALSE when it wasn't.
5790 * Return -1 for an unknown option.
5791 */
5792 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005793was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005794{
5795 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005796 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005797
5798 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005799 {
5800 flagp = insecure_flag(idx, opt_flags);
5801 return (*flagp & P_INSECURE) != 0;
5802 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005803 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005804 return -1;
5805}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005806
5807/*
5808 * Get a pointer to the flags used for the P_INSECURE flag of option
5809 * "opt_idx". For some local options a local flags field is used.
5810 */
5811 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005812insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005813{
5814 if (opt_flags & OPT_LOCAL)
5815 switch ((int)options[opt_idx].indir)
5816 {
5817#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005818 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005819#endif
5820#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005821# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005822 case PV_FDE: return &curwin->w_p_fde_flags;
5823 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005824# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005825# ifdef FEAT_BEVAL
5826 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5827# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005828# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005829 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005830# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005831 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005832# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005833 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005834# endif
5835#endif
5836 }
5837
5838 /* Nothing special, return global flags field. */
5839 return &options[opt_idx].flags;
5840}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005841#endif
5842
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005843#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005844/*
5845 * Redraw the window title and/or tab page text later.
5846 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005847static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005848{
5849 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005850 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005851}
5852#endif
5853
Bram Moolenaar071d4272004-06-13 20:20:40 +00005854/*
5855 * Set a string option to a new value (without checking the effect).
5856 * The string is copied into allocated memory.
5857 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005858 * When "set_sid" is zero set the scriptID to current_sctx.sc_sid. When
5859 * "set_sid" is SID_NONE don't set the scriptID. Otherwise set the scriptID to
5860 * "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005861 */
5862 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005863set_string_option_direct(
5864 char_u *name,
5865 int opt_idx,
5866 char_u *val,
5867 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5868 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005869{
5870 char_u *s;
5871 char_u **varp;
5872 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005873 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005874
Bram Moolenaar89d40322006-08-29 15:30:07 +00005875 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005876 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005877 idx = findoption(name);
5878 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005879 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005880 semsg(_(e_intern2), "set_string_option_direct()");
5881 siemsg(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005882 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005883 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005884 }
5885
Bram Moolenaar89d40322006-08-29 15:30:07 +00005886 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005887 return;
5888
5889 s = vim_strsave(val);
5890 if (s != NULL)
5891 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005892 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005893 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005894 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005895 free_string_option(*varp);
5896 *varp = s;
5897
5898 /* For buffer/window local option may also set the global value. */
5899 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005900 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005901
Bram Moolenaar89d40322006-08-29 15:30:07 +00005902 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005903
5904 /* When setting both values of a global option with a local value,
5905 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005906 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005907 {
5908 free_string_option(*varp);
5909 *varp = empty_option;
5910 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005911# ifdef FEAT_EVAL
5912 if (set_sid != SID_NONE)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005913 {
5914 sctx_T script_ctx;
5915
5916 if (set_sid == 0)
5917 script_ctx = current_sctx;
5918 else
5919 {
5920 script_ctx.sc_sid = set_sid;
Bram Moolenaarded5f1b2018-11-10 17:33:29 +01005921 script_ctx.sc_seq = 0;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005922 script_ctx.sc_lnum = 0;
5923 }
5924 set_option_sctx_idx(idx, opt_flags, script_ctx);
5925 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005926# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005927 }
5928}
5929
5930/*
5931 * Set global value for string option when it's a local option.
5932 */
5933 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005934set_string_option_global(
5935 int opt_idx, /* option index */
5936 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005937{
5938 char_u **p, *s;
5939
5940 /* the global value is always allocated */
5941 if (options[opt_idx].var == VAR_WIN)
5942 p = (char_u **)GLOBAL_WO(varp);
5943 else
5944 p = (char_u **)options[opt_idx].var;
5945 if (options[opt_idx].indir != PV_NONE
5946 && p != varp
5947 && (s = vim_strsave(*varp)) != NULL)
5948 {
5949 free_string_option(*p);
5950 *p = s;
5951 }
5952}
5953
5954/*
5955 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005956 *
5957 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005958 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005959 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005960set_string_option(
5961 int opt_idx,
5962 char_u *value,
5963 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005964{
5965 char_u *s;
5966 char_u **varp;
5967 char_u *oldval;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005968#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02005969 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005970 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02005971#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005972 char *r = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01005973 int value_checked = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005974
5975 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005976 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005977
5978 s = vim_strsave(value);
5979 if (s != NULL)
5980 {
5981 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5982 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005983 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005984 ? OPT_GLOBAL : OPT_LOCAL)
5985 : opt_flags);
5986 oldval = *varp;
5987 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005988
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005989#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005990 if (!starting
5991# ifdef FEAT_CRYPT
5992 && options[opt_idx].indir != PV_KEY
5993# endif
5994 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005995 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005996 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005997 saved_newval = vim_strsave(s);
5998 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005999#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006000 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
Bram Moolenaar916a8182018-11-25 02:18:29 +01006001 opt_flags, &value_checked)) == NULL)
6002 did_set_option(opt_idx, opt_flags, TRUE, value_checked);
Bram Moolenaar53744302015-07-17 17:38:22 +02006003
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006004#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006005 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006006 if (r == NULL)
6007 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006008 saved_oldval, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006009 vim_free(saved_oldval);
6010 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02006011#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006012 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006013 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006014}
6015
6016/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01006017 * Return TRUE if "val" is a valid 'filetype' name.
6018 * Also used for 'syntax' and 'keymap'.
6019 */
6020 static int
6021valid_filetype(char_u *val)
6022{
6023 char_u *s;
6024
6025 for (s = val; *s != NUL; ++s)
6026 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
6027 return FALSE;
6028 return TRUE;
6029}
6030
6031/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006032 * Handle string options that need some action to perform when changed.
6033 * Returns NULL for success, or an error message for an error.
6034 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006035 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006036did_set_string_option(
Bram Moolenaar916a8182018-11-25 02:18:29 +01006037 int opt_idx, // index in options[] table
6038 char_u **varp, // pointer to the option variable
6039 int new_value_alloced, // new value was allocated
6040 char_u *oldval, // previous value of the option
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006041 char *errbuf, // buffer for errors, or NULL
Bram Moolenaar916a8182018-11-25 02:18:29 +01006042 int opt_flags, // OPT_LOCAL and/or OPT_GLOBAL
6043 int *value_checked) // value was checked to be save, no
6044 // need to set P_INSECURE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006045{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006046 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006047 char_u *s, *p;
6048 int did_chartab = FALSE;
6049 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006050 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006051#ifdef FEAT_GUI
6052 /* set when changing an option that only requires a redraw in the GUI */
6053 int redraw_gui_only = FALSE;
6054#endif
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02006055 int value_changed = FALSE;
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006056#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6057 int did_swaptcap = FALSE;
6058#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006059
6060 /* Get the global option to compare with, otherwise we would have to check
6061 * two values for all local options. */
6062 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6063
6064 /* Disallow changing some options from secure mode */
6065 if ((secure
6066#ifdef HAVE_SANDBOX
6067 || sandbox != 0
6068#endif
6069 ) && (options[opt_idx].flags & P_SECURE))
6070 {
6071 errmsg = e_secure;
6072 }
6073
Bram Moolenaar916a8182018-11-25 02:18:29 +01006074 // Check for a "normal" directory or file name in some options. Disallow a
6075 // path separator (slash and/or backslash), wildcards and characters that
6076 // are often illegal in a file name. Be more permissive if "secure" is off.
Bram Moolenaar7554da42016-11-25 22:04:13 +01006077 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006078 && vim_strpbrk(*varp, (char_u *)(secure
6079 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006080 || ((options[opt_idx].flags & P_NDNAME)
6081 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006082 {
6083 errmsg = e_invarg;
6084 }
6085
Bram Moolenaar071d4272004-06-13 20:20:40 +00006086 /* 'term' */
6087 else if (varp == &T_NAME)
6088 {
6089 if (T_NAME[0] == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006090 errmsg = N_("E529: Cannot set 'term' to empty string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006091#ifdef FEAT_GUI
6092 if (gui.in_use)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006093 errmsg = N_("E530: Cannot change term in GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006094 else if (term_is_gui(T_NAME))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006095 errmsg = N_("E531: Use \":gui\" to start the GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006096#endif
6097 else if (set_termname(T_NAME) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006098 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006099 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006100 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006101 /* Screen colors may have changed. */
6102 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006103
6104 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6105 * P_ALLOCED flag on 'term'. */
6106 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006107 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006108 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006109 }
6110
6111 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006112 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006113 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006114 char_u *bkc = p_bkc;
6115 unsigned int *flags = &bkc_flags;
6116
6117 if (opt_flags & OPT_LOCAL)
6118 {
6119 bkc = curbuf->b_p_bkc;
6120 flags = &curbuf->b_bkc_flags;
6121 }
6122
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006123 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6124 /* make the local value empty: use the global value */
6125 *flags = 0;
6126 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006127 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006128 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6129 errmsg = e_invarg;
6130 if ((((int)*flags & BKC_AUTO) != 0)
6131 + (((int)*flags & BKC_YES) != 0)
6132 + (((int)*flags & BKC_NO) != 0) != 1)
6133 {
6134 /* Must have exactly one of "auto", "yes" and "no". */
6135 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6136 errmsg = e_invarg;
6137 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006138 }
6139 }
6140
6141 /* 'backupext' and 'patchmode' */
6142 else if (varp == &p_bex || varp == &p_pm)
6143 {
6144 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6145 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006146 errmsg = N_("E589: 'backupext' and 'patchmode' are equal");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006147 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006148#ifdef FEAT_LINEBREAK
6149 /* 'breakindentopt' */
6150 else if (varp == &curwin->w_p_briopt)
6151 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006152 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006153 errmsg = e_invarg;
6154 }
6155#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006156
6157 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006158 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006159 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006160 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006161 */
6162 else if ( varp == &p_isi
6163 || varp == &(curbuf->b_p_isk)
6164 || varp == &p_isp
6165 || varp == &p_isf)
6166 {
6167 if (init_chartab() == FAIL)
6168 {
6169 did_chartab = TRUE; /* need to restore it below */
6170 errmsg = e_invarg; /* error in value */
6171 }
6172 }
6173
6174 /* 'helpfile' */
6175 else if (varp == &p_hf)
6176 {
6177 /* May compute new values for $VIM and $VIMRUNTIME */
6178 if (didset_vim)
6179 {
6180 vim_setenv((char_u *)"VIM", (char_u *)"");
6181 didset_vim = FALSE;
6182 }
6183 if (didset_vimruntime)
6184 {
6185 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6186 didset_vimruntime = FALSE;
6187 }
6188 }
6189
Bram Moolenaar1a384422010-07-14 19:53:30 +02006190#ifdef FEAT_SYN_HL
6191 /* 'colorcolumn' */
6192 else if (varp == &curwin->w_p_cc)
6193 errmsg = check_colorcolumn(curwin);
6194#endif
6195
Bram Moolenaar071d4272004-06-13 20:20:40 +00006196#ifdef FEAT_MULTI_LANG
6197 /* 'helplang' */
6198 else if (varp == &p_hlg)
6199 {
6200 /* Check for "", "ab", "ab,cd", etc. */
6201 for (s = p_hlg; *s != NUL; s += 3)
6202 {
6203 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6204 {
6205 errmsg = e_invarg;
6206 break;
6207 }
6208 if (s[2] == NUL)
6209 break;
6210 }
6211 }
6212#endif
6213
6214 /* 'highlight' */
6215 else if (varp == &p_hl)
6216 {
6217 if (highlight_changed() == FAIL)
6218 errmsg = e_invarg; /* invalid flags */
6219 }
6220
6221 /* 'nrformats' */
6222 else if (gvarp == &p_nf)
6223 {
6224 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6225 errmsg = e_invarg;
6226 }
6227
6228#ifdef FEAT_SESSION
6229 /* 'sessionoptions' */
6230 else if (varp == &p_ssop)
6231 {
6232 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6233 errmsg = e_invarg;
6234 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6235 {
6236 /* Don't allow both "sesdir" and "curdir". */
6237 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6238 errmsg = e_invarg;
6239 }
6240 }
6241 /* 'viewoptions' */
6242 else if (varp == &p_vop)
6243 {
6244 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6245 errmsg = e_invarg;
6246 }
6247#endif
6248
6249 /* 'scrollopt' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006250 else if (varp == &p_sbo)
6251 {
6252 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6253 errmsg = e_invarg;
6254 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006255
6256 /* 'ambiwidth' */
Bram Moolenaar3848e002016-03-19 18:42:29 +01006257 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006258 {
6259 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6260 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006261 else if (set_chars_option(&p_lcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006262 errmsg = _("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006263 else if (set_chars_option(&p_fcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006264 errmsg = _("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006265 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006266
6267 /* 'background' */
6268 else if (varp == &p_bg)
6269 {
6270 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6271 {
6272#ifdef FEAT_EVAL
6273 int dark = (*p_bg == 'd');
6274#endif
6275
6276 init_highlight(FALSE, FALSE);
6277
6278#ifdef FEAT_EVAL
6279 if (dark != (*p_bg == 'd')
6280 && get_var_value((char_u *)"g:colors_name") != NULL)
6281 {
6282 /* The color scheme must have set 'background' back to another
6283 * value, that's not what we want here. Disable the color
6284 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006285 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006286 free_string_option(p_bg);
6287 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6288 check_string_option(&p_bg);
6289 init_highlight(FALSE, FALSE);
6290 }
6291#endif
6292 }
6293 else
6294 errmsg = e_invarg;
6295 }
6296
6297 /* 'wildmode' */
6298 else if (varp == &p_wim)
6299 {
6300 if (check_opt_wim() == FAIL)
6301 errmsg = e_invarg;
6302 }
6303
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006304#ifdef FEAT_CMDL_COMPL
6305 /* 'wildoptions' */
6306 else if (varp == &p_wop)
6307 {
6308 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6309 errmsg = e_invarg;
6310 }
6311#endif
6312
Bram Moolenaar071d4272004-06-13 20:20:40 +00006313#ifdef FEAT_WAK
6314 /* 'winaltkeys' */
6315 else if (varp == &p_wak)
6316 {
6317 if (*p_wak == NUL
6318 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6319 errmsg = e_invarg;
6320# ifdef FEAT_MENU
6321# ifdef FEAT_GUI_MOTIF
6322 else if (gui.in_use)
6323 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6324# else
6325# ifdef FEAT_GUI_GTK
6326 else if (gui.in_use)
6327 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6328# endif
6329# endif
6330# endif
6331 }
6332#endif
6333
Bram Moolenaar071d4272004-06-13 20:20:40 +00006334 /* 'eventignore' */
6335 else if (varp == &p_ei)
6336 {
6337 if (check_ei() == FAIL)
6338 errmsg = e_invarg;
6339 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006340
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006341 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6342 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6343 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006344 {
6345 if (gvarp == &p_fenc)
6346 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006347 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006348 errmsg = e_modifiable;
6349 else if (vim_strchr(*varp, ',') != NULL)
6350 /* No comma allowed in 'fileencoding'; catches confusing it
6351 * with 'fileencodings'. */
6352 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006353 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006354 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006355#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006356 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006357 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006358#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006359 /* Add 'fileencoding' to the swap file. */
6360 ml_setflags(curbuf);
6361 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006362 }
6363 if (errmsg == NULL)
6364 {
6365 /* canonize the value, so that STRCMP() can be used on it */
6366 p = enc_canonize(*varp);
6367 if (p != NULL)
6368 {
6369 vim_free(*varp);
6370 *varp = p;
6371 }
6372 if (varp == &p_enc)
6373 {
6374 errmsg = mb_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006375#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006376 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006377#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006378 }
6379 }
6380
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006381#if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006382 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6383 {
6384 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6385 if (STRCMP(p_tenc, "utf-8") != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006386 errmsg = N_("E617: Cannot be changed in the GTK+ 2 GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006387 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006388#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006389
6390 if (errmsg == NULL)
6391 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006392#ifdef FEAT_KEYMAP
Bram Moolenaar071d4272004-06-13 20:20:40 +00006393 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6394 * (with another encoding). */
6395 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6396 (void)keymap_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006397#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006398
6399 /* When 'termencoding' is not empty and 'encoding' changes or when
6400 * 'termencoding' changes, need to setup for keyboard input and
6401 * display output conversion. */
6402 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6403 {
Bram Moolenaar17471e82017-11-26 23:47:18 +01006404 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6405 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6406 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006407 semsg(_("E950: Cannot convert between %s and %s"),
Bram Moolenaar17471e82017-11-26 23:47:18 +01006408 p_tenc, p_enc);
6409 errmsg = e_invarg;
6410 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006411 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006412
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006413#if defined(WIN3264)
Bram Moolenaar05159a02005-02-26 23:04:13 +00006414 /* $HOME may have characters in active code page. */
6415 if (varp == &p_enc)
6416 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006417#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006418 }
6419 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006420
6421#if defined(FEAT_POSTSCRIPT)
6422 else if (varp == &p_penc)
6423 {
6424 /* Canonize printencoding if VIM standard one */
6425 p = enc_canonize(p_penc);
6426 if (p != NULL)
6427 {
6428 vim_free(p_penc);
6429 p_penc = p;
6430 }
6431 else
6432 {
6433 /* Ensure lower case and '-' for '_' */
6434 for (s = p_penc; *s != NUL; s++)
6435 {
6436 if (*s == '_')
6437 *s = '-';
6438 else
6439 *s = TOLOWER_ASC(*s);
6440 }
6441 }
6442 }
6443#endif
6444
Bram Moolenaar9372a112005-12-06 19:59:18 +00006445#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006446 else if (varp == &p_imak)
6447 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006448 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006449 errmsg = e_invarg;
6450 }
6451#endif
6452
6453#ifdef FEAT_KEYMAP
6454 else if (varp == &curbuf->b_p_keymap)
6455 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006456 if (!valid_filetype(*varp))
6457 errmsg = e_invarg;
6458 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01006459 {
6460 int secure_save = secure;
6461
6462 // Reset the secure flag, since the value of 'keymap' has
6463 // been checked to be safe.
6464 secure = 0;
6465
6466 // load or unload key mapping tables
Bram Moolenaard0b51382016-11-04 15:23:45 +01006467 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006468
Bram Moolenaar916a8182018-11-25 02:18:29 +01006469 secure = secure_save;
6470
6471 // Since we check the value, there is no need to set P_INSECURE,
6472 // even when the value comes from a modeline.
6473 *value_checked = TRUE;
6474 }
6475
Bram Moolenaarfab06232009-03-04 03:13:35 +00006476 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006477 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006478 if (*curbuf->b_p_keymap != NUL)
6479 {
6480 /* Installed a new keymap, switch on using it. */
6481 curbuf->b_p_iminsert = B_IMODE_LMAP;
6482 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6483 curbuf->b_p_imsearch = B_IMODE_LMAP;
6484 }
6485 else
6486 {
6487 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6488 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6489 curbuf->b_p_iminsert = B_IMODE_NONE;
6490 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6491 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6492 }
6493 if ((opt_flags & OPT_LOCAL) == 0)
6494 {
6495 set_iminsert_global();
6496 set_imsearch_global();
6497 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006498 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006499 }
6500 }
6501#endif
6502
6503 /* 'fileformat' */
6504 else if (gvarp == &p_ff)
6505 {
6506 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6507 errmsg = e_modifiable;
6508 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6509 errmsg = e_invarg;
6510 else
6511 {
6512 /* may also change 'textmode' */
6513 if (get_fileformat(curbuf) == EOL_DOS)
6514 curbuf->b_p_tx = TRUE;
6515 else
6516 curbuf->b_p_tx = FALSE;
6517#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006518 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006519#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006520 /* update flag in swap file */
6521 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006522 /* Redraw needed when switching to/from "mac": a CR in the text
6523 * will be displayed differently. */
6524 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6525 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006526 }
6527 }
6528
6529 /* 'fileformats' */
6530 else if (varp == &p_ffs)
6531 {
6532 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6533 errmsg = e_invarg;
6534 else
6535 {
6536 /* also change 'textauto' */
6537 if (*p_ffs == NUL)
6538 p_ta = FALSE;
6539 else
6540 p_ta = TRUE;
6541 }
6542 }
6543
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006544#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006545 /* 'cryptkey' */
6546 else if (gvarp == &p_key)
6547 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006548# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006549 /* Make sure the ":set" command doesn't show the new value in the
6550 * history. */
6551 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006552# endif
6553 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6554 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006555 ml_set_crypt_key(curbuf, oldval,
6556 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006557 }
6558
6559 else if (gvarp == &p_cm)
6560 {
6561 if (opt_flags & OPT_LOCAL)
6562 p = curbuf->b_p_cm;
6563 else
6564 p = p_cm;
6565 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6566 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006567 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006568 errmsg = e_invarg;
6569 else
6570 {
6571 /* When setting the global value to empty, make it "zip". */
6572 if (*p_cm == NUL)
6573 {
6574 if (new_value_alloced)
6575 free_string_option(p_cm);
6576 p_cm = vim_strsave((char_u *)"zip");
6577 new_value_alloced = TRUE;
6578 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006579 /* When using ":set cm=name" the local value is going to be empty.
6580 * Do that here, otherwise the crypt functions will still use the
6581 * local value. */
6582 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6583 {
6584 free_string_option(curbuf->b_p_cm);
6585 curbuf->b_p_cm = empty_option;
6586 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006587
6588 /* Need to update the swapfile when the effective method changed.
6589 * Set "s" to the effective old value, "p" to the effective new
6590 * method and compare. */
6591 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6592 s = p_cm; /* was previously using the global value */
6593 else
6594 s = oldval;
6595 if (*curbuf->b_p_cm == NUL)
6596 p = p_cm; /* is now using the global value */
6597 else
6598 p = curbuf->b_p_cm;
6599 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006600 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006601
6602 /* If the global value changes need to update the swapfile for all
6603 * buffers using that value. */
6604 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6605 {
6606 buf_T *buf;
6607
Bram Moolenaar29323592016-07-24 22:04:11 +02006608 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006609 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006610 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006611 }
6612 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006613 }
6614#endif
6615
6616 /* 'matchpairs' */
6617 else if (gvarp == &p_mps)
6618 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006619 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006620 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006621 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006622 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006623 int x2 = -1;
6624 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006625
6626 if (*p != NUL)
6627 p += mb_ptr2len(p);
6628 if (*p != NUL)
6629 x2 = *p++;
6630 if (*p != NUL)
6631 {
6632 x3 = mb_ptr2char(p);
6633 p += mb_ptr2len(p);
6634 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006635 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006636 {
6637 errmsg = e_invarg;
6638 break;
6639 }
6640 if (*p == NUL)
6641 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006642 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006643 }
6644 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006645 {
6646 /* Check for "x:y,x:y" */
6647 for (p = *varp; *p != NUL; p += 4)
6648 {
6649 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6650 {
6651 errmsg = e_invarg;
6652 break;
6653 }
6654 if (p[3] == NUL)
6655 break;
6656 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006657 }
6658 }
6659
6660#ifdef FEAT_COMMENTS
6661 /* 'comments' */
6662 else if (gvarp == &p_com)
6663 {
6664 for (s = *varp; *s; )
6665 {
6666 while (*s && *s != ':')
6667 {
6668 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6669 && !VIM_ISDIGIT(*s) && *s != '-')
6670 {
6671 errmsg = illegal_char(errbuf, *s);
6672 break;
6673 }
6674 ++s;
6675 }
6676 if (*s++ == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006677 errmsg = N_("E524: Missing colon");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006678 else if (*s == ',' || *s == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006679 errmsg = N_("E525: Zero length string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006680 if (errmsg != NULL)
6681 break;
6682 while (*s && *s != ',')
6683 {
6684 if (*s == '\\' && s[1] != NUL)
6685 ++s;
6686 ++s;
6687 }
6688 s = skip_to_option_part(s);
6689 }
6690 }
6691#endif
6692
6693 /* 'listchars' */
6694 else if (varp == &p_lcs)
6695 {
6696 errmsg = set_chars_option(varp);
6697 }
6698
Bram Moolenaar071d4272004-06-13 20:20:40 +00006699 /* 'fillchars' */
6700 else if (varp == &p_fcs)
6701 {
6702 errmsg = set_chars_option(varp);
6703 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006704
6705#ifdef FEAT_CMDWIN
6706 /* 'cedit' */
6707 else if (varp == &p_cedit)
6708 {
6709 errmsg = check_cedit();
6710 }
6711#endif
6712
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006713 /* 'verbosefile' */
6714 else if (varp == &p_vfile)
6715 {
6716 verbose_stop();
6717 if (*p_vfile != NUL && verbose_open() == FAIL)
6718 errmsg = e_invarg;
6719 }
6720
Bram Moolenaar071d4272004-06-13 20:20:40 +00006721#ifdef FEAT_VIMINFO
6722 /* 'viminfo' */
6723 else if (varp == &p_viminfo)
6724 {
6725 for (s = p_viminfo; *s;)
6726 {
6727 /* Check it's a valid character */
6728 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6729 {
6730 errmsg = illegal_char(errbuf, *s);
6731 break;
6732 }
6733 if (*s == 'n') /* name is always last one */
6734 {
6735 break;
6736 }
6737 else if (*s == 'r') /* skip until next ',' */
6738 {
6739 while (*++s && *s != ',')
6740 ;
6741 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006742 else if (*s == '%')
6743 {
6744 /* optional number */
6745 while (vim_isdigit(*++s))
6746 ;
6747 }
6748 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006749 ++s; /* no extra chars */
6750 else /* must have a number */
6751 {
6752 while (vim_isdigit(*++s))
6753 ;
6754
6755 if (!VIM_ISDIGIT(*(s - 1)))
6756 {
6757 if (errbuf != NULL)
6758 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006759 sprintf(errbuf, _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006760 transchar_byte(*(s - 1)));
6761 errmsg = errbuf;
6762 }
6763 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006764 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006765 break;
6766 }
6767 }
6768 if (*s == ',')
6769 ++s;
6770 else if (*s)
6771 {
6772 if (errbuf != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006773 errmsg = N_("E527: Missing comma");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006774 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006775 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006776 break;
6777 }
6778 }
6779 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006780 errmsg = N_("E528: Must specify a ' value");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006781 }
6782#endif /* FEAT_VIMINFO */
6783
6784 /* terminal options */
6785 else if (istermoption(&options[opt_idx]) && full_screen)
6786 {
6787 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6788 if (varp == &T_CCO)
6789 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006790 int colors = atoi((char *)T_CCO);
6791
6792 /* Only reinitialize colors if t_Co value has really changed to
6793 * avoid expensive reload of colorscheme if t_Co is set to the
6794 * same value multiple times. */
6795 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006796 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006797 t_colors = colors;
6798 if (t_colors <= 1)
6799 {
6800 if (new_value_alloced)
6801 vim_free(T_CCO);
6802 T_CCO = empty_option;
6803 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006804#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6805 if (is_term_win32())
6806 {
6807 swap_tcap();
6808 did_swaptcap = TRUE;
6809 }
6810#endif
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006811 /* We now have a different color setup, initialize it again. */
6812 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006813 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006814 }
6815 ttest(FALSE);
6816 if (varp == &T_ME)
6817 {
6818 out_str(T_ME);
6819 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006820#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006821 /* Since t_me has been set, this probably means that the user
6822 * wants to use this as default colors. Need to reset default
6823 * background/foreground colors. */
6824 mch_set_normal_colors();
6825#endif
6826 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006827 if (varp == &T_BE && termcap_active)
6828 {
6829 if (*T_BE == NUL)
6830 /* When clearing t_BE we assume the user no longer wants
6831 * bracketed paste, thus disable it by writing t_BD. */
6832 out_str(T_BD);
6833 else
6834 out_str(T_BE);
6835 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006836 }
6837
6838#ifdef FEAT_LINEBREAK
6839 /* 'showbreak' */
6840 else if (varp == &p_sbr)
6841 {
6842 for (s = p_sbr; *s; )
6843 {
6844 if (ptr2cells(s) != 1)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006845 errmsg = N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006846 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006847 }
6848 }
6849#endif
6850
6851#ifdef FEAT_GUI
6852 /* 'guifont' */
6853 else if (varp == &p_guifont)
6854 {
6855 if (gui.in_use)
6856 {
6857 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006858# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006859 /*
6860 * Put up a font dialog and let the user select a new value.
6861 * If this is cancelled go back to the old value but don't
6862 * give an error message.
6863 */
6864 if (STRCMP(p, "*") == 0)
6865 {
6866 p = gui_mch_font_dialog(oldval);
6867
6868 if (new_value_alloced)
6869 free_string_option(p_guifont);
6870
6871 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6872 new_value_alloced = TRUE;
6873 }
6874# endif
6875 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6876 {
6877# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6878 if (STRCMP(p_guifont, "*") == 0)
6879 {
6880 /* Dialog was cancelled: Keep the old value without giving
6881 * an error message. */
6882 if (new_value_alloced)
6883 free_string_option(p_guifont);
6884 p_guifont = vim_strsave(oldval);
6885 new_value_alloced = TRUE;
6886 }
6887 else
6888# endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006889 errmsg = N_("E596: Invalid font(s)");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006890 }
6891 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006892 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006893 }
6894# ifdef FEAT_XFONTSET
6895 else if (varp == &p_guifontset)
6896 {
6897 if (STRCMP(p_guifontset, "*") == 0)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01006898 errmsg = N_("E597: can't select fontset");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006899 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01006900 errmsg = N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006901 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006902 }
6903# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006904 else if (varp == &p_guifontwide)
6905 {
6906 if (STRCMP(p_guifontwide, "*") == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006907 errmsg = N_("E533: can't select wide font");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006908 else if (gui_get_wide_font() == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006909 errmsg = N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006910 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006911 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006912#endif
6913
6914#ifdef CURSOR_SHAPE
6915 /* 'guicursor' */
6916 else if (varp == &p_guicursor)
6917 errmsg = parse_shape_opt(SHAPE_CURSOR);
6918#endif
6919
6920#ifdef FEAT_MOUSESHAPE
6921 /* 'mouseshape' */
6922 else if (varp == &p_mouseshape)
6923 {
6924 errmsg = parse_shape_opt(SHAPE_MOUSE);
6925 update_mouseshape(-1);
6926 }
6927#endif
6928
6929#ifdef FEAT_PRINTER
6930 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006931 errmsg = parse_printoptions();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006932# if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006933 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006934 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006935# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006936#endif
6937
6938#ifdef FEAT_LANGMAP
6939 /* 'langmap' */
6940 else if (varp == &p_langmap)
6941 langmap_set();
6942#endif
6943
6944#ifdef FEAT_LINEBREAK
6945 /* 'breakat' */
6946 else if (varp == &p_breakat)
6947 fill_breakat_flags();
6948#endif
6949
6950#ifdef FEAT_TITLE
6951 /* 'titlestring' and 'iconstring' */
6952 else if (varp == &p_titlestring || varp == &p_iconstring)
6953 {
6954# ifdef FEAT_STL_OPT
6955 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6956
6957 /* NULL => statusline syntax */
6958 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6959 stl_syntax |= flagval;
6960 else
6961 stl_syntax &= ~flagval;
6962# endif
Bram Moolenaar84a93082018-06-16 22:58:15 +02006963 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006964 }
6965#endif
6966
6967#ifdef FEAT_GUI
6968 /* 'guioptions' */
6969 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006970 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006971 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006972 redraw_gui_only = TRUE;
6973 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006974#endif
6975
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006976#if defined(FEAT_GUI_TABLINE)
6977 /* 'guitablabel' */
6978 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006979 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006980 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006981 redraw_gui_only = TRUE;
6982 }
6983 /* 'guitabtooltip' */
6984 else if (varp == &p_gtt)
6985 {
6986 redraw_gui_only = TRUE;
6987 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006988#endif
6989
Bram Moolenaar071d4272004-06-13 20:20:40 +00006990#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6991 /* 'ttymouse' */
6992 else if (varp == &p_ttym)
6993 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006994 /* Switch the mouse off before changing the escape sequences used for
6995 * that. */
6996 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006997 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6998 errmsg = e_invarg;
6999 else
7000 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00007001 if (termcap_active)
7002 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007003 }
7004#endif
7005
Bram Moolenaar071d4272004-06-13 20:20:40 +00007006 /* 'selection' */
7007 else if (varp == &p_sel)
7008 {
7009 if (*p_sel == NUL
7010 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
7011 errmsg = e_invarg;
7012 }
7013
7014 /* 'selectmode' */
7015 else if (varp == &p_slm)
7016 {
7017 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
7018 errmsg = e_invarg;
7019 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007020
7021#ifdef FEAT_BROWSE
7022 /* 'browsedir' */
7023 else if (varp == &p_bsdir)
7024 {
7025 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7026 && !mch_isdir(p_bsdir))
7027 errmsg = e_invarg;
7028 }
7029#endif
7030
Bram Moolenaar071d4272004-06-13 20:20:40 +00007031 /* 'keymodel' */
7032 else if (varp == &p_km)
7033 {
7034 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7035 errmsg = e_invarg;
7036 else
7037 {
7038 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7039 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7040 }
7041 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007042
7043 /* 'mousemodel' */
7044 else if (varp == &p_mousem)
7045 {
7046 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7047 errmsg = e_invarg;
7048#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7049 else if (*p_mousem != *oldval)
7050 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7051 * to create or delete the popup menus. */
7052 gui_motif_update_mousemodel(root_menu);
7053#endif
7054 }
7055
7056 /* 'switchbuf' */
7057 else if (varp == &p_swb)
7058 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007059 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007060 errmsg = e_invarg;
7061 }
7062
7063 /* 'debug' */
7064 else if (varp == &p_debug)
7065 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007066 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007067 errmsg = e_invarg;
7068 }
7069
7070 /* 'display' */
7071 else if (varp == &p_dy)
7072 {
7073 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7074 errmsg = e_invarg;
7075 else
7076 (void)init_chartab();
7077
7078 }
7079
Bram Moolenaar071d4272004-06-13 20:20:40 +00007080 /* 'eadirection' */
7081 else if (varp == &p_ead)
7082 {
7083 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7084 errmsg = e_invarg;
7085 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007086
7087#ifdef FEAT_CLIPBOARD
7088 /* 'clipboard' */
7089 else if (varp == &p_cb)
7090 errmsg = check_clipboard_option();
7091#endif
7092
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007093#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007094 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7095 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007096 else if (varp == &(curwin->w_s->b_p_spl)
7097 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007098 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007099 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007100 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007101 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007102 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007103 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007104 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007105 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007106 /* 'spellsuggest' */
7107 else if (varp == &p_sps)
7108 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007109 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007110 errmsg = e_invarg;
7111 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007112 /* 'mkspellmem' */
7113 else if (varp == &p_msm)
7114 {
7115 if (spell_check_msm() != OK)
7116 errmsg = e_invarg;
7117 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007118#endif
7119
Bram Moolenaar071d4272004-06-13 20:20:40 +00007120 /* When 'bufhidden' is set, check for valid value. */
7121 else if (gvarp == &p_bh)
7122 {
7123 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7124 errmsg = e_invarg;
7125 }
7126
7127 /* When 'buftype' is set, check for valid value. */
7128 else if (gvarp == &p_bt)
7129 {
7130 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7131 errmsg = e_invarg;
7132 else
7133 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007134 if (curwin->w_status_height)
7135 {
7136 curwin->w_redr_status = TRUE;
7137 redraw_later(VALID);
7138 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007139 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007140#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007141 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007142#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007143 }
7144 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007145
7146#ifdef FEAT_STL_OPT
7147 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007148 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007149 {
7150 int wid;
7151
7152 if (varp == &p_ruf) /* reset ru_wid first */
7153 ru_wid = 0;
7154 s = *varp;
7155 if (varp == &p_ruf && *s == '%')
7156 {
7157 /* set ru_wid if 'ruf' starts with "%99(" */
7158 if (*++s == '-') /* ignore a '-' */
7159 s++;
7160 wid = getdigits(&s);
7161 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7162 ru_wid = wid;
7163 else
7164 errmsg = check_stl_option(p_ruf);
7165 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007166 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007167 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007168 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007169 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007170 comp_col();
7171 }
7172#endif
7173
7174#ifdef FEAT_INS_EXPAND
7175 /* check if it is a valid value for 'complete' -- Acevedo */
7176 else if (gvarp == &p_cpt)
7177 {
7178 for (s = *varp; *s;)
7179 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007180 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007181 s++;
7182 if (!*s)
7183 break;
7184 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7185 {
7186 errmsg = illegal_char(errbuf, *s);
7187 break;
7188 }
7189 if (*++s != NUL && *s != ',' && *s != ' ')
7190 {
7191 if (s[-1] == 'k' || s[-1] == 's')
7192 {
7193 /* skip optional filename after 'k' and 's' */
7194 while (*s && *s != ',' && *s != ' ')
7195 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007196 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007197 ++s;
7198 ++s;
7199 }
7200 }
7201 else
7202 {
7203 if (errbuf != NULL)
7204 {
7205 sprintf((char *)errbuf,
7206 _("E535: Illegal character after <%c>"),
7207 *--s);
7208 errmsg = errbuf;
7209 }
7210 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007211 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00007212 break;
7213 }
7214 }
7215 }
7216 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007217
7218 /* 'completeopt' */
7219 else if (varp == &p_cot)
7220 {
7221 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7222 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007223 else
7224 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007225 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007226#endif /* FEAT_INS_EXPAND */
7227
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007228#ifdef FEAT_SIGNS
7229 /* 'signcolumn' */
7230 else if (varp == &curwin->w_p_scl)
7231 {
7232 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7233 errmsg = e_invarg;
7234 }
7235#endif
7236
Bram Moolenaar071d4272004-06-13 20:20:40 +00007237
7238#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007239 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007240 else if (varp == &p_toolbar)
7241 {
7242 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7243 &toolbar_flags, TRUE) != OK)
7244 errmsg = e_invarg;
7245 else
7246 {
7247 out_flush();
7248 gui_mch_show_toolbar((toolbar_flags &
7249 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7250 }
7251 }
7252#endif
7253
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007254#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007255 /* 'toolbariconsize': GTK+ 2 only */
7256 else if (varp == &p_tbis)
7257 {
7258 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7259 errmsg = e_invarg;
7260 else
7261 {
7262 out_flush();
7263 gui_mch_show_toolbar((toolbar_flags &
7264 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7265 }
7266 }
7267#endif
7268
7269 /* 'pastetoggle': translate key codes like in a mapping */
7270 else if (varp == &p_pt)
7271 {
7272 if (*p_pt)
7273 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007274 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007275 if (p != NULL)
7276 {
7277 if (new_value_alloced)
7278 free_string_option(p_pt);
7279 p_pt = p;
7280 new_value_alloced = TRUE;
7281 }
7282 }
7283 }
7284
7285 /* 'backspace' */
7286 else if (varp == &p_bs)
7287 {
7288 if (VIM_ISDIGIT(*p_bs))
7289 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007290 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007291 errmsg = e_invarg;
7292 }
7293 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7294 errmsg = e_invarg;
7295 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007296 else if (varp == &p_bo)
7297 {
7298 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7299 errmsg = e_invarg;
7300 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007301
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007302 /* 'tagcase' */
7303 else if (gvarp == &p_tc)
7304 {
7305 unsigned int *flags;
7306
7307 if (opt_flags & OPT_LOCAL)
7308 {
7309 p = curbuf->b_p_tc;
7310 flags = &curbuf->b_tc_flags;
7311 }
7312 else
7313 {
7314 p = p_tc;
7315 flags = &tc_flags;
7316 }
7317
7318 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7319 /* make the local value empty: use the global value */
7320 *flags = 0;
7321 else if (*p == NUL
7322 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7323 errmsg = e_invarg;
7324 }
7325
Bram Moolenaar071d4272004-06-13 20:20:40 +00007326 /* 'casemap' */
7327 else if (varp == &p_cmp)
7328 {
7329 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7330 errmsg = e_invarg;
7331 }
7332
7333#ifdef FEAT_DIFF
7334 /* 'diffopt' */
7335 else if (varp == &p_dip)
7336 {
7337 if (diffopt_changed() == FAIL)
7338 errmsg = e_invarg;
7339 }
7340#endif
7341
7342#ifdef FEAT_FOLDING
7343 /* 'foldmethod' */
7344 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7345 {
7346 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7347 || *curwin->w_p_fdm == NUL)
7348 errmsg = e_invarg;
7349 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007350 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007351 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007352 if (foldmethodIsDiff(curwin))
7353 newFoldLevel();
7354 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007355 }
7356# ifdef FEAT_EVAL
7357 /* 'foldexpr' */
7358 else if (varp == &curwin->w_p_fde)
7359 {
7360 if (foldmethodIsExpr(curwin))
7361 foldUpdateAll(curwin);
7362 }
7363# endif
7364 /* 'foldmarker' */
7365 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7366 {
7367 p = vim_strchr(*varp, ',');
7368 if (p == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007369 errmsg = N_("E536: comma required");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007370 else if (p == *varp || p[1] == NUL)
7371 errmsg = e_invarg;
7372 else if (foldmethodIsMarker(curwin))
7373 foldUpdateAll(curwin);
7374 }
7375 /* 'commentstring' */
7376 else if (gvarp == &p_cms)
7377 {
7378 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007379 errmsg = N_("E537: 'commentstring' must be empty or contain %s");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007380 }
7381 /* 'foldopen' */
7382 else if (varp == &p_fdo)
7383 {
7384 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7385 errmsg = e_invarg;
7386 }
7387 /* 'foldclose' */
7388 else if (varp == &p_fcl)
7389 {
7390 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7391 errmsg = e_invarg;
7392 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007393 /* 'foldignore' */
7394 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7395 {
7396 if (foldmethodIsIndent(curwin))
7397 foldUpdateAll(curwin);
7398 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007399#endif
7400
Bram Moolenaar071d4272004-06-13 20:20:40 +00007401 /* 'virtualedit' */
7402 else if (varp == &p_ve)
7403 {
7404 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7405 errmsg = e_invarg;
7406 else if (STRCMP(p_ve, oldval) != 0)
7407 {
7408 /* Recompute cursor position in case the new 've' setting
7409 * changes something. */
7410 validate_virtcol();
7411 coladvance(curwin->w_virtcol);
7412 }
7413 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007414
7415#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7416 else if (varp == &p_csqf)
7417 {
7418 if (p_csqf != NULL)
7419 {
7420 p = p_csqf;
7421 while (*p != NUL)
7422 {
7423 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7424 || p[1] == NUL
7425 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7426 || (p[2] != NUL && p[2] != ','))
7427 {
7428 errmsg = e_invarg;
7429 break;
7430 }
7431 else if (p[2] == NUL)
7432 break;
7433 else
7434 p += 3;
7435 }
7436 }
7437 }
7438#endif
7439
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007440#ifdef FEAT_CINDENT
7441 /* 'cinoptions' */
7442 else if (gvarp == &p_cino)
7443 {
7444 /* TODO: recognize errors */
7445 parse_cino(curbuf);
7446 }
7447#endif
7448
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007449#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007450 /* 'renderoptions' */
Bram Moolenaar3767c6e2017-12-05 16:57:56 +01007451 else if (varp == &p_rop)
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007452 {
7453 if (!gui_mch_set_rendering_options(p_rop))
7454 errmsg = e_invarg;
7455 }
7456#endif
7457
Bram Moolenaard0b51382016-11-04 15:23:45 +01007458 else if (gvarp == &p_ft)
7459 {
7460 if (!valid_filetype(*varp))
7461 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007462 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007463 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007464 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007465
7466 // Since we check the value, there is no need to set P_INSECURE,
7467 // even when the value comes from a modeline.
7468 *value_checked = TRUE;
7469 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007470 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007471
7472#ifdef FEAT_SYN_HL
7473 else if (gvarp == &p_syn)
7474 {
7475 if (!valid_filetype(*varp))
7476 errmsg = e_invarg;
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007477 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007478 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007479 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007480
7481 // Since we check the value, there is no need to set P_INSECURE,
7482 // even when the value comes from a modeline.
7483 *value_checked = TRUE;
7484 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007485 }
7486#endif
7487
Bram Moolenaar825680f2017-07-22 17:04:02 +02007488#ifdef FEAT_TERMINAL
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007489 // 'termwinkey'
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007490 else if (varp == &curwin->w_p_twk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007491 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007492 if (*curwin->w_p_twk != NUL
7493 && string_to_key(curwin->w_p_twk, TRUE) == 0)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007494 errmsg = e_invarg;
7495 }
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007496 // 'termwinsize'
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007497 else if (varp == &curwin->w_p_tws)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007498 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007499 if (*curwin->w_p_tws != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007500 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007501 p = skipdigits(curwin->w_p_tws);
7502 if (p == curwin->w_p_tws
Bram Moolenaar498c2562018-04-15 23:45:15 +02007503 || (*p != 'x' && *p != '*')
7504 || *skipdigits(p + 1) != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007505 errmsg = e_invarg;
7506 }
7507 }
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007508 // 'termmode'
7509 else if (varp == &curwin->w_p_tmod)
7510 {
7511 if (check_opt_strings(*varp, p_tmod_values, FALSE) != OK)
7512 errmsg = e_invarg;
7513 }
Bram Moolenaar825680f2017-07-22 17:04:02 +02007514#endif
7515
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007516#ifdef FEAT_VARTABS
7517 /* 'varsofttabstop' */
7518 else if (varp == &(curbuf->b_p_vsts))
7519 {
7520 char_u *cp;
7521
7522 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7523 {
7524 if (curbuf->b_p_vsts_array)
7525 {
7526 vim_free(curbuf->b_p_vsts_array);
7527 curbuf->b_p_vsts_array = 0;
7528 }
7529 }
7530 else
7531 {
7532 for (cp = *varp; *cp; ++cp)
7533 {
7534 if (vim_isdigit(*cp))
7535 continue;
7536 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7537 continue;
7538 errmsg = e_invarg;
7539 break;
7540 }
7541 if (errmsg == NULL)
7542 {
7543 int *oldarray = curbuf->b_p_vsts_array;
7544 if (tabstop_set(*varp, &(curbuf->b_p_vsts_array)))
7545 {
7546 if (oldarray)
7547 vim_free(oldarray);
7548 }
7549 else
7550 errmsg = e_invarg;
7551 }
7552 }
7553 }
7554
7555 /* 'vartabstop' */
7556 else if (varp == &(curbuf->b_p_vts))
7557 {
7558 char_u *cp;
7559
7560 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7561 {
7562 if (curbuf->b_p_vts_array)
7563 {
7564 vim_free(curbuf->b_p_vts_array);
7565 curbuf->b_p_vts_array = NULL;
7566 }
7567 }
7568 else
7569 {
7570 for (cp = *varp; *cp; ++cp)
7571 {
7572 if (vim_isdigit(*cp))
7573 continue;
7574 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7575 continue;
7576 errmsg = e_invarg;
7577 break;
7578 }
7579 if (errmsg == NULL)
7580 {
7581 int *oldarray = curbuf->b_p_vts_array;
7582 if (tabstop_set(*varp, &(curbuf->b_p_vts_array)))
7583 {
7584 if (oldarray)
7585 vim_free(oldarray);
7586#ifdef FEAT_FOLDING
7587 if (foldmethodIsIndent(curwin))
7588 foldUpdateAll(curwin);
7589#endif /* FEAT_FOLDING */
7590 }
7591 else
7592 errmsg = e_invarg;
7593 }
7594 }
7595 }
7596#endif
7597
Bram Moolenaar071d4272004-06-13 20:20:40 +00007598 /* Options that are a list of flags. */
7599 else
7600 {
7601 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007602 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007603 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007604 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007605 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007606 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007607 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007608 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007609 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007610#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007611 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007612 p = (char_u *)COCU_ALL;
7613#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007614 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007615 {
7616#ifdef FEAT_MOUSE
7617 p = (char_u *)MOUSE_ALL;
7618#else
7619 if (*p_mouse != NUL)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007620 errmsg = N_("E538: No mouse support");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007621#endif
7622 }
7623#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007624 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007625 p = (char_u *)GO_ALL;
7626#endif
7627 if (p != NULL)
7628 {
7629 for (s = *varp; *s; ++s)
7630 if (vim_strchr(p, *s) == NULL)
7631 {
7632 errmsg = illegal_char(errbuf, *s);
7633 break;
7634 }
7635 }
7636 }
7637
7638 /*
7639 * If error detected, restore the previous value.
7640 */
7641 if (errmsg != NULL)
7642 {
7643 if (new_value_alloced)
7644 free_string_option(*varp);
7645 *varp = oldval;
7646 /*
7647 * When resetting some values, need to act on it.
7648 */
7649 if (did_chartab)
7650 (void)init_chartab();
7651 if (varp == &p_hl)
7652 (void)highlight_changed();
7653 }
7654 else
7655 {
7656#ifdef FEAT_EVAL
7657 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02007658 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007659#endif
7660 /*
7661 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007662 * Use "free_oldval", because recursiveness may change the flags under
7663 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007664 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007665 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007666 free_string_option(oldval);
7667 if (new_value_alloced)
7668 options[opt_idx].flags |= P_ALLOCED;
7669 else
7670 options[opt_idx].flags &= ~P_ALLOCED;
7671
7672 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007673 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007674 {
7675 /* global option with local value set to use global value; free
7676 * the local value and make it empty */
7677 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7678 free_string_option(*(char_u **)p);
7679 *(char_u **)p = empty_option;
7680 }
7681
7682 /* May set global value for local option. */
7683 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7684 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007685
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007686 /*
7687 * Trigger the autocommand only after setting the flags.
7688 */
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007689#ifdef FEAT_SYN_HL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007690 /* When 'syntax' is set, load the syntax of that name */
7691 if (varp == &(curbuf->b_p_syn))
7692 {
Bram Moolenaara5616b02018-06-17 19:08:30 +02007693 static int syn_recursive = 0;
7694
7695 ++syn_recursive;
7696 // Only pass TRUE for "force" when the value changed or not used
7697 // recursively, to avoid endless recurrence.
7698 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname,
7699 value_changed || syn_recursive == 1, curbuf);
7700 --syn_recursive;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007701 }
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007702#endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007703 else if (varp == &(curbuf->b_p_ft))
7704 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007705 /* 'filetype' is set, trigger the FileType autocommand.
7706 * Skip this when called from a modeline and the filetype was
Bram Moolenaara5616b02018-06-17 19:08:30 +02007707 * already set to this value. */
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007708 if (!(opt_flags & OPT_MODELINE) || value_changed)
Bram Moolenaar90492982017-06-22 14:16:31 +02007709 {
Bram Moolenaar916a8182018-11-25 02:18:29 +01007710 static int ft_recursive = 0;
7711 int secure_save = secure;
7712
7713 // Reset the secure flag, since the value of 'filetype' has
7714 // been checked to be safe.
7715 secure = 0;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007716
7717 ++ft_recursive;
Bram Moolenaar90492982017-06-22 14:16:31 +02007718 did_filetype = TRUE;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007719 // Only pass TRUE for "force" when the value changed or not
7720 // used recursively, to avoid endless recurrence.
7721 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname,
7722 value_changed || ft_recursive == 1, curbuf);
7723 --ft_recursive;
Bram Moolenaar163095f2017-07-09 15:41:53 +02007724 /* Just in case the old "curbuf" is now invalid. */
7725 if (varp != &(curbuf->b_p_ft))
7726 varp = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007727
7728 secure = secure_save;
Bram Moolenaar90492982017-06-22 14:16:31 +02007729 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007730 }
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007731#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007732 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007733 {
7734 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007735 char_u *q = curwin->w_s->b_p_spl;
7736
7737 /* Skip the first name if it is "cjk". */
7738 if (STRNCMP(q, "cjk,", 4) == 0)
7739 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007740
7741 /*
7742 * Source the spell/LANG.vim in 'runtimepath'.
7743 * They could set 'spellcapcheck' depending on the language.
7744 * Use the first name in 'spelllang' up to '_region' or
7745 * '.encoding'.
7746 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007747 for (p = q; *p != NUL; ++p)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01007748 if (!ASCII_ISALNUM(*p) && *p != '-')
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007749 break;
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007750 if (p > q)
7751 {
7752 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
7753 source_runtime(fname, DIP_ALL);
7754 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007755 }
7756#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007757 }
7758
7759#ifdef FEAT_MOUSE
7760 if (varp == &p_mouse)
7761 {
7762# ifdef FEAT_MOUSE_TTY
7763 if (*p_mouse == NUL)
7764 mch_setmouse(FALSE); /* switch mouse off */
7765 else
7766# endif
7767 setmouse(); /* in case 'mouse' changed */
7768 }
7769#endif
7770
Bram Moolenaar913077c2012-03-28 19:59:04 +02007771 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007772 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007773 curwin->w_set_curswant = TRUE;
7774
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007775#ifdef FEAT_GUI
7776 /* check redraw when it's not a GUI option or the GUI is active. */
7777 if (!redraw_gui_only || gui.in_use)
7778#endif
7779 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007780
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007781#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
7782 if (did_swaptcap)
7783 {
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007784 set_termname((char_u *)"win32");
7785 init_highlight(TRUE, FALSE);
7786 }
7787#endif
7788
Bram Moolenaar071d4272004-06-13 20:20:40 +00007789 return errmsg;
7790}
7791
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007792#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007793/*
7794 * Simple int comparison function for use with qsort()
7795 */
7796 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007797int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007798{
7799 return *(const int *)a - *(const int *)b;
7800}
7801
7802/*
7803 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7804 * Returns error message, NULL if it's OK.
7805 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007806 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007807check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007808{
7809 char_u *s;
7810 int col;
7811 int count = 0;
7812 int color_cols[256];
7813 int i;
7814 int j = 0;
7815
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007816 if (wp->w_buffer == NULL)
7817 return NULL; /* buffer was closed */
7818
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007819 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007820 {
7821 if (*s == '-' || *s == '+')
7822 {
7823 /* -N and +N: add to 'textwidth' */
7824 col = (*s == '-') ? -1 : 1;
7825 ++s;
7826 if (!VIM_ISDIGIT(*s))
7827 return e_invarg;
7828 col = col * getdigits(&s);
7829 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007830 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007831 col += wp->w_buffer->b_p_tw;
7832 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007833 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007834 }
7835 else if (VIM_ISDIGIT(*s))
7836 col = getdigits(&s);
7837 else
7838 return e_invarg;
7839 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007840skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007841 if (*s == NUL)
7842 break;
7843 if (*s != ',')
7844 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007845 if (*++s == NUL)
7846 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007847 }
7848
7849 vim_free(wp->w_p_cc_cols);
7850 if (count == 0)
7851 wp->w_p_cc_cols = NULL;
7852 else
7853 {
7854 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7855 if (wp->w_p_cc_cols != NULL)
7856 {
7857 /* sort the columns for faster usage on screen redraw inside
7858 * win_line() */
7859 qsort(color_cols, count, sizeof(int), int_cmp);
7860
7861 for (i = 0; i < count; ++i)
7862 /* skip duplicates */
7863 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7864 wp->w_p_cc_cols[j++] = color_cols[i];
7865 wp->w_p_cc_cols[j] = -1; /* end marker */
7866 }
7867 }
7868
7869 return NULL; /* no error */
7870}
7871#endif
7872
Bram Moolenaar071d4272004-06-13 20:20:40 +00007873/*
7874 * Handle setting 'listchars' or 'fillchars'.
7875 * Returns error message, NULL if it's OK.
7876 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007877 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007878set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007879{
7880 int round, i, len, entries;
7881 char_u *p, *s;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007882 int c1 = 0, c2 = 0, c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007883 struct charstab
7884 {
7885 int *cp;
7886 char *name;
7887 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007888 static struct charstab filltab[] =
7889 {
7890 {&fill_stl, "stl"},
7891 {&fill_stlnc, "stlnc"},
7892 {&fill_vert, "vert"},
7893 {&fill_fold, "fold"},
7894 {&fill_diff, "diff"},
7895 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007896 static struct charstab lcstab[] =
7897 {
7898 {&lcs_eol, "eol"},
7899 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007900 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007901 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007902 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007903 {&lcs_tab2, "tab"},
7904 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007905#ifdef FEAT_CONCEAL
7906 {&lcs_conceal, "conceal"},
7907#else
7908 {NULL, "conceal"},
7909#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007910 };
7911 struct charstab *tab;
7912
Bram Moolenaar071d4272004-06-13 20:20:40 +00007913 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007914 {
7915 tab = lcstab;
7916 entries = sizeof(lcstab) / sizeof(struct charstab);
7917 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007918 else
7919 {
7920 tab = filltab;
7921 entries = sizeof(filltab) / sizeof(struct charstab);
7922 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007923
7924 /* first round: check for valid value, second round: assign values */
7925 for (round = 0; round <= 1; ++round)
7926 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007927 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007928 {
7929 /* After checking that the value is valid: set defaults: space for
7930 * 'fillchars', NUL for 'listchars' */
7931 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007932 if (tab[i].cp != NULL)
7933 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar83a52172019-01-16 22:41:54 +01007934
Bram Moolenaar071d4272004-06-13 20:20:40 +00007935 if (varp == &p_lcs)
Bram Moolenaar83a52172019-01-16 22:41:54 +01007936 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007937 lcs_tab1 = NUL;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007938 lcs_tab3 = NUL;
7939 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007940 else
7941 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007942 }
7943 p = *varp;
7944 while (*p)
7945 {
7946 for (i = 0; i < entries; ++i)
7947 {
7948 len = (int)STRLEN(tab[i].name);
7949 if (STRNCMP(p, tab[i].name, len) == 0
7950 && p[len] == ':'
7951 && p[len + 1] != NUL)
7952 {
Bram Moolenaar83a52172019-01-16 22:41:54 +01007953 c1 = c2 = c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007954 s = p + len + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007955 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007956 if (mb_char2cells(c1) > 1)
7957 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007958 if (tab[i].cp == &lcs_tab2)
7959 {
7960 if (*s == NUL)
7961 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007962 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007963 if (mb_char2cells(c2) > 1)
7964 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007965 if (!(*s == ',' || *s == NUL))
7966 {
Bram Moolenaar83a52172019-01-16 22:41:54 +01007967 c3 = mb_ptr2char_adv(&s);
7968 if (mb_char2cells(c3) > 1)
7969 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007970 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007971 }
Bram Moolenaar83a52172019-01-16 22:41:54 +01007972
Bram Moolenaar071d4272004-06-13 20:20:40 +00007973 if (*s == ',' || *s == NUL)
7974 {
7975 if (round)
7976 {
7977 if (tab[i].cp == &lcs_tab2)
7978 {
7979 lcs_tab1 = c1;
7980 lcs_tab2 = c2;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007981 lcs_tab3 = c3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007982 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007983 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007984 *(tab[i].cp) = c1;
7985
7986 }
7987 p = s;
7988 break;
7989 }
7990 }
7991 }
7992
7993 if (i == entries)
7994 return e_invarg;
7995 if (*p == ',')
7996 ++p;
7997 }
7998 }
7999
8000 return NULL; /* no error */
8001}
8002
8003#ifdef FEAT_STL_OPT
8004/*
8005 * Check validity of options with the 'statusline' format.
8006 * Return error message or NULL.
8007 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008008 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008009check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008010{
8011 int itemcnt = 0;
8012 int groupdepth = 0;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008013 static char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00008014
8015 while (*s && itemcnt < STL_MAX_ITEM)
8016 {
8017 /* Check for valid keys after % sequences */
8018 while (*s && *s != '%')
8019 s++;
8020 if (!*s)
8021 break;
8022 s++;
8023 if (*s != '%' && *s != ')')
8024 ++itemcnt;
8025 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
8026 {
8027 s++;
8028 continue;
8029 }
8030 if (*s == ')')
8031 {
8032 s++;
8033 if (--groupdepth < 0)
8034 break;
8035 continue;
8036 }
8037 if (*s == '-')
8038 s++;
8039 while (VIM_ISDIGIT(*s))
8040 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00008041 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008042 continue;
8043 if (*s == '.')
8044 {
8045 s++;
8046 while (*s && VIM_ISDIGIT(*s))
8047 s++;
8048 }
8049 if (*s == '(')
8050 {
8051 groupdepth++;
8052 continue;
8053 }
8054 if (vim_strchr(STL_ALL, *s) == NULL)
8055 {
8056 return illegal_char(errbuf, *s);
8057 }
8058 if (*s == '{')
8059 {
8060 s++;
8061 while (*s != '}' && *s)
8062 s++;
8063 if (*s != '}')
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008064 return N_("E540: Unclosed expression sequence");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008065 }
8066 }
8067 if (itemcnt >= STL_MAX_ITEM)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008068 return N_("E541: too many items");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008069 if (groupdepth != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008070 return N_("E542: unbalanced groups");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008071 return NULL;
8072}
8073#endif
8074
8075#ifdef FEAT_CLIPBOARD
8076/*
8077 * Extract the items in the 'clipboard' option and set global values.
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008078 * Return an error message or NULL for success.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008079 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008080 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008081check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008082{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008083 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008084 int new_autoselect_star = FALSE;
8085 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008086 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008087 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008088 regprog_T *new_exclude_prog = NULL;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008089 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008090 char_u *p;
8091
8092 for (p = p_cb; *p != NUL; )
8093 {
8094 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
8095 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008096 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008097 p += 7;
8098 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02008099 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008100 && (p[11] == ',' || p[11] == NUL))
8101 {
8102 new_unnamed |= CLIP_UNNAMED_PLUS;
8103 p += 11;
8104 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008105 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008106 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008107 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02008108 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008109 p += 10;
8110 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02008111 else if (STRNCMP(p, "autoselectplus", 14) == 0
8112 && (p[14] == ',' || p[14] == NUL))
8113 {
8114 new_autoselect_plus = TRUE;
8115 p += 14;
8116 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008117 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008118 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008119 {
8120 new_autoselectml = TRUE;
8121 p += 12;
8122 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008123 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
8124 {
8125 new_html = TRUE;
8126 p += 4;
8127 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008128 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
8129 {
8130 p += 8;
8131 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
8132 if (new_exclude_prog == NULL)
8133 errmsg = e_invarg;
8134 break;
8135 }
8136 else
8137 {
8138 errmsg = e_invarg;
8139 break;
8140 }
8141 if (*p == ',')
8142 ++p;
8143 }
8144 if (errmsg == NULL)
8145 {
8146 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008147 clip_autoselect_star = new_autoselect_star;
8148 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008149 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008150 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008151 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008152 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008153#ifdef FEAT_GUI_GTK
8154 if (gui.in_use)
8155 {
8156 gui_gtk_set_selection_targets();
8157 gui_gtk_set_dnd_targets();
8158 }
8159#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008160 }
8161 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008162 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008163
8164 return errmsg;
8165}
8166#endif
8167
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008168#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008169/*
8170 * Handle side effects of setting 'spell'.
8171 * Return an error message or NULL for success.
8172 */
8173 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008174did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008175{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008176 char *errmsg = NULL;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008177 win_T *wp;
8178 int l;
8179
8180 if (is_spellfile)
8181 {
8182 l = (int)STRLEN(curwin->w_s->b_p_spf);
8183 if (l > 0 && (l < 4
8184 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8185 errmsg = e_invarg;
8186 }
8187
8188 if (errmsg == NULL)
8189 {
8190 FOR_ALL_WINDOWS(wp)
8191 if (wp->w_buffer == curbuf && wp->w_p_spell)
8192 {
8193 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008194 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008195 }
8196 }
8197 return errmsg;
8198}
8199
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008200/*
8201 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8202 * Return error message when failed, NULL when OK.
8203 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008204 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008205compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008206{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008207 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008208 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008209
Bram Moolenaar860cae12010-06-05 23:22:07 +02008210 if (*synblock->b_p_spc == NUL)
8211 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008212 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008213 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008214 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008215 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008216 if (re != NULL)
8217 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008218 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008219 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008220 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008221 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008222 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008223 return e_invarg;
8224 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008225 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008226 }
8227
Bram Moolenaar473de612013-06-08 18:19:48 +02008228 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008229 return NULL;
8230}
8231#endif
8232
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008233#if defined(FEAT_EVAL) || defined(PROTO)
8234/*
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008235 * Set the script_ctx for an option, taking care of setting the buffer- or
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008236 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008237 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008238 static void
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008239set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008240{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008241 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8242 int indir = (int)options[opt_idx].indir;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008243 sctx_T new_script_ctx = script_ctx;
8244
8245 new_script_ctx.sc_lnum += sourcing_lnum;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008246
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008247 /* Remember where the option was set. For local options need to do that
8248 * in the buffer or window structure. */
8249 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008250 options[opt_idx].script_ctx = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008251 if (both || (opt_flags & OPT_LOCAL))
8252 {
8253 if (indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008254 curbuf->b_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008255 else if (indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008256 curwin->w_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008257 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008258}
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02008259
8260/*
8261 * Set the script_ctx for a termcap option.
8262 * "name" must be the two character code, e.g. "RV".
8263 * When "name" is NULL use "opt_idx".
8264 */
8265 void
8266set_term_option_sctx_idx(char *name, int opt_idx)
8267{
8268 char_u buf[5];
8269 int idx;
8270
8271 if (name == NULL)
8272 idx = opt_idx;
8273 else
8274 {
8275 buf[0] = 't';
8276 buf[1] = '_';
8277 buf[2] = name[0];
8278 buf[3] = name[1];
8279 buf[4] = 0;
8280 idx = findoption(buf);
8281 }
8282 if (idx >= 0)
8283 set_option_sctx_idx(idx, OPT_GLOBAL, current_sctx);
8284}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008285#endif
8286
Bram Moolenaar071d4272004-06-13 20:20:40 +00008287/*
8288 * Set the value of a boolean option, and take care of side effects.
8289 * Returns NULL for success, or an error message for an error.
8290 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008291 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008292set_bool_option(
8293 int opt_idx, /* index in options[] table */
8294 char_u *varp, /* pointer to the option variable */
8295 int value, /* new value */
8296 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008297{
8298 int old_value = *(int *)varp;
8299
Bram Moolenaar071d4272004-06-13 20:20:40 +00008300 /* Disallow changing some options from secure mode */
8301 if ((secure
8302#ifdef HAVE_SANDBOX
8303 || sandbox != 0
8304#endif
8305 ) && (options[opt_idx].flags & P_SECURE))
8306 return e_secure;
8307
8308 *(int *)varp = value; /* set the new value */
8309#ifdef FEAT_EVAL
8310 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008311 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008312#endif
8313
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008314#ifdef FEAT_GUI
8315 need_mouse_correct = TRUE;
8316#endif
8317
Bram Moolenaar071d4272004-06-13 20:20:40 +00008318 /* May set global value for local option. */
8319 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8320 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8321
8322 /*
8323 * Handle side effects of changing a bool option.
8324 */
8325
8326 /* 'compatible' */
8327 if ((int *)varp == &p_cp)
8328 {
8329 compatible_set();
8330 }
8331
Bram Moolenaar920694c2016-08-21 17:45:02 +02008332#ifdef FEAT_LANGMAP
8333 if ((int *)varp == &p_lrm)
8334 /* 'langremap' -> !'langnoremap' */
8335 p_lnr = !p_lrm;
8336 else if ((int *)varp == &p_lnr)
8337 /* 'langnoremap' -> !'langremap' */
8338 p_lrm = !p_lnr;
8339#endif
8340
Bram Moolenaar8c63e0e2018-09-25 22:17:54 +02008341#ifdef FEAT_SYN_HL
8342 else if ((int *)varp == &curwin->w_p_cul && !value && old_value)
8343 reset_cursorline();
8344#endif
8345
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008346#ifdef FEAT_PERSISTENT_UNDO
8347 /* 'undofile' */
8348 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8349 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008350 /* Only take action when the option was set. When reset we do not
8351 * delete the undo file, the option may be set again without making
8352 * any changes in between. */
8353 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008354 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008355 char_u hash[UNDO_HASH_SIZE];
8356 buf_T *save_curbuf = curbuf;
8357
Bram Moolenaar29323592016-07-24 22:04:11 +02008358 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008359 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008360 /* When 'undofile' is set globally: for every buffer, otherwise
8361 * only for the current buffer: Try to read in the undofile,
8362 * if one exists, the buffer wasn't changed and the buffer was
8363 * loaded */
8364 if ((curbuf == save_curbuf
8365 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8366 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8367 {
8368 u_compute_hash(hash);
8369 u_read_undo(NULL, hash, curbuf->b_fname);
8370 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008371 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008372 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008373 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008374 }
8375#endif
8376
Bram Moolenaar071d4272004-06-13 20:20:40 +00008377 else if ((int *)varp == &curbuf->b_p_ro)
8378 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008379 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008380 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8381 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008382
8383 /* when 'readonly' is set may give W10 again */
8384 if (curbuf->b_p_ro)
8385 curbuf->b_did_warn = FALSE;
8386
Bram Moolenaar071d4272004-06-13 20:20:40 +00008387#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008388 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008389#endif
8390 }
8391
Bram Moolenaar9c449722010-07-20 18:44:27 +02008392#ifdef FEAT_GUI
8393 else if ((int *)varp == &p_mh)
8394 {
8395 if (!p_mh)
8396 gui_mch_mousehide(FALSE);
8397 }
8398#endif
8399
Bram Moolenaara539df02010-08-01 14:35:05 +02008400 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008401 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008402 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008403# ifdef FEAT_TERMINAL
8404 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaard7db27b2018-03-07 23:02:33 +01008405 if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf)
8406 && curbuf->b_term != NULL && !term_is_finished(curbuf))))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008407 {
8408 curbuf->b_p_ma = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008409 return N_("E946: Cannot make a terminal with running job modifiable");
Bram Moolenaar423802d2017-07-30 16:52:24 +02008410 }
8411# endif
8412# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008413 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008414# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008415 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008416#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008417 /* when 'endofline' is changed, redraw the window title */
8418 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008419 {
8420 redraw_titles();
8421 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008422 /* when 'fixeol' is changed, redraw the window title */
8423 else if ((int *)varp == &curbuf->b_p_fixeol)
8424 {
8425 redraw_titles();
8426 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008427 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008428 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008429 {
8430 redraw_titles();
8431 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008432#endif
8433
8434 /* when 'bin' is set also set some other options */
8435 else if ((int *)varp == &curbuf->b_p_bin)
8436 {
8437 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8438#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008439 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008440#endif
8441 }
8442
Bram Moolenaar071d4272004-06-13 20:20:40 +00008443 /* when 'buflisted' changes, trigger autocommands */
8444 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8445 {
8446 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8447 NULL, NULL, TRUE, curbuf);
8448 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008449
8450 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8451 else if ((int *)varp == &curbuf->b_p_swf)
8452 {
8453 if (curbuf->b_p_swf && p_uc)
8454 ml_open_file(curbuf); /* create the swap file */
8455 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008456 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8457 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008458 mf_close_file(curbuf, TRUE); /* remove the swap file */
8459 }
8460
8461 /* when 'terse' is set change 'shortmess' */
8462 else if ((int *)varp == &p_terse)
8463 {
8464 char_u *p;
8465
8466 p = vim_strchr(p_shm, SHM_SEARCH);
8467
8468 /* insert 's' in p_shm */
8469 if (p_terse && p == NULL)
8470 {
8471 STRCPY(IObuff, p_shm);
8472 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008473 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008474 }
8475 /* remove 's' from p_shm */
8476 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008477 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008478 }
8479
8480 /* when 'paste' is set or reset also change other options */
8481 else if ((int *)varp == &p_paste)
8482 {
8483 paste_option_changed();
8484 }
8485
8486 /* when 'insertmode' is set from an autocommand need to do work here */
8487 else if ((int *)varp == &p_im)
8488 {
8489 if (p_im)
8490 {
8491 if ((State & INSERT) == 0)
8492 need_start_insertmode = TRUE;
8493 stop_insert_mode = FALSE;
8494 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008495 /* only reset if it was set previously */
8496 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008497 {
8498 need_start_insertmode = FALSE;
8499 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008500 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008501 clear_cmdline = TRUE; /* remove "(insert)" */
8502 restart_edit = 0;
8503 }
8504 }
8505
8506 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8507 else if ((int *)varp == &p_ic && p_hls)
8508 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008509 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008510 }
8511
8512#ifdef FEAT_SEARCH_EXTRA
8513 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8514 else if ((int *)varp == &p_hls)
8515 {
Bram Moolenaar451fc7b2018-04-27 22:53:07 +02008516 set_no_hlsearch(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008517 }
8518#endif
8519
Bram Moolenaar071d4272004-06-13 20:20:40 +00008520 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8521 * at the end of normal_cmd() */
8522 else if ((int *)varp == &curwin->w_p_scb)
8523 {
8524 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008525 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008526 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008527 curwin->w_scbind_pos = curwin->w_topline;
8528 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008529 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008530
Bram Moolenaar4033c552017-09-16 20:54:51 +02008531#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008532 /* There can be only one window with 'previewwindow' set. */
8533 else if ((int *)varp == &curwin->w_p_pvw)
8534 {
8535 if (curwin->w_p_pvw)
8536 {
8537 win_T *win;
8538
Bram Moolenaar29323592016-07-24 22:04:11 +02008539 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008540 if (win->w_p_pvw && win != curwin)
8541 {
8542 curwin->w_p_pvw = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008543 return N_("E590: A preview window already exists");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008544 }
8545 }
8546 }
8547#endif
8548
8549 /* when 'textmode' is set or reset also change 'fileformat' */
8550 else if ((int *)varp == &curbuf->b_p_tx)
8551 {
8552 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8553 }
8554
8555 /* when 'textauto' is set or reset also change 'fileformats' */
8556 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008557 set_string_option_direct((char_u *)"ffs", -1,
8558 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008559 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008560
8561 /*
8562 * When 'lisp' option changes include/exclude '-' in
8563 * keyword characters.
8564 */
8565#ifdef FEAT_LISP
8566 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8567 {
8568 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8569 }
8570#endif
8571
8572#ifdef FEAT_TITLE
8573 /* when 'title' changed, may need to change the title; same for 'icon' */
Bram Moolenaar84a93082018-06-16 22:58:15 +02008574 else if ((int *)varp == &p_title || (int *)varp == &p_icon)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008575 {
Bram Moolenaar84a93082018-06-16 22:58:15 +02008576 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008577 }
8578#endif
8579
8580 else if ((int *)varp == &curbuf->b_changed)
8581 {
8582 if (!value)
8583 save_file_ff(curbuf); /* Buffer is unchanged */
8584#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008585 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008586#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008587 modified_was_set = value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008588 }
8589
8590#ifdef BACKSLASH_IN_FILENAME
8591 else if ((int *)varp == &p_ssl)
8592 {
8593 if (p_ssl)
8594 {
8595 psepc = '/';
8596 psepcN = '\\';
8597 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008598 }
8599 else
8600 {
8601 psepc = '\\';
8602 psepcN = '/';
8603 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008604 }
8605
8606 /* need to adjust the file name arguments and buffer names. */
8607 buflist_slash_adjust();
8608 alist_slash_adjust();
8609# ifdef FEAT_EVAL
8610 scriptnames_slash_adjust();
8611# endif
8612 }
8613#endif
8614
8615 /* If 'wrap' is set, set w_leftcol to zero. */
8616 else if ((int *)varp == &curwin->w_p_wrap)
8617 {
8618 if (curwin->w_p_wrap)
8619 curwin->w_leftcol = 0;
8620 }
8621
Bram Moolenaar071d4272004-06-13 20:20:40 +00008622 else if ((int *)varp == &p_ea)
8623 {
8624 if (p_ea && !old_value)
8625 win_equal(curwin, FALSE, 0);
8626 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008627
8628 else if ((int *)varp == &p_wiv)
8629 {
8630 /*
8631 * When 'weirdinvert' changed, set/reset 't_xs'.
8632 * Then set 'weirdinvert' according to value of 't_xs'.
8633 */
8634 if (p_wiv && !old_value)
8635 T_XS = (char_u *)"y";
8636 else if (!p_wiv && old_value)
8637 T_XS = empty_option;
8638 p_wiv = (*T_XS != NUL);
8639 }
8640
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008641#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008642 else if ((int *)varp == &p_beval)
8643 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008644 if (!balloonEvalForTerm)
8645 {
8646 if (p_beval && !old_value)
8647 gui_mch_enable_beval_area(balloonEval);
8648 else if (!p_beval && old_value)
8649 gui_mch_disable_beval_area(balloonEval);
8650 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008651 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008652#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008653#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008654 else if ((int *)varp == &p_bevalterm)
8655 {
8656 mch_bevalterm_changed();
8657 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008658#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008659
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008660#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008661 else if ((int *)varp == &p_acd)
8662 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008663 /* Change directories when the 'acd' option is set now. */
Bram Moolenaar6f470022018-04-10 18:47:20 +02008664 DO_AUTOCHDIR;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008665 }
8666#endif
8667
8668#ifdef FEAT_DIFF
8669 /* 'diff' */
8670 else if ((int *)varp == &curwin->w_p_diff)
8671 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008672 /* May add or remove the buffer from the list of diff buffers. */
8673 diff_buf_adjust(curwin);
8674# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008675 if (foldmethodIsDiff(curwin))
8676 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008677# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008678 }
8679#endif
8680
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008681#ifdef HAVE_INPUT_METHOD
Bram Moolenaar071d4272004-06-13 20:20:40 +00008682 /* 'imdisable' */
8683 else if ((int *)varp == &p_imdisable)
8684 {
8685 /* Only de-activate it here, it will be enabled when changing mode. */
8686 if (p_imdisable)
8687 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008688 else if (State & INSERT)
8689 /* When the option is set from an autocommand, it may need to take
8690 * effect right away. */
8691 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008692 }
8693#endif
8694
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008695#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008696 /* 'spell' */
8697 else if ((int *)varp == &curwin->w_p_spell)
8698 {
8699 if (curwin->w_p_spell)
8700 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008701 char *errmsg = did_set_spelllang(curwin);
8702
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008703 if (errmsg != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008704 emsg(_(errmsg));
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008705 }
8706 }
8707#endif
8708
Bram Moolenaar071d4272004-06-13 20:20:40 +00008709#ifdef FEAT_FKMAP
8710 else if ((int *)varp == &p_altkeymap)
8711 {
8712 if (old_value != p_altkeymap)
8713 {
8714 if (!p_altkeymap)
8715 {
8716 p_hkmap = p_fkmap;
8717 p_fkmap = 0;
8718 }
8719 else
8720 {
8721 p_fkmap = p_hkmap;
8722 p_hkmap = 0;
8723 }
8724 (void)init_chartab();
8725 }
8726 }
8727
8728 /*
8729 * In case some second language keymapping options have changed, check
8730 * and correct the setting in a consistent way.
8731 */
8732
8733 /*
8734 * If hkmap or fkmap are set, reset Arabic keymapping.
8735 */
8736 if ((p_hkmap || p_fkmap) && p_altkeymap)
8737 {
8738 p_altkeymap = p_fkmap;
8739# ifdef FEAT_ARABIC
8740 curwin->w_p_arab = FALSE;
8741# endif
8742 (void)init_chartab();
8743 }
8744
8745 /*
8746 * If hkmap set, reset Farsi keymapping.
8747 */
8748 if (p_hkmap && p_altkeymap)
8749 {
8750 p_altkeymap = 0;
8751 p_fkmap = 0;
8752# ifdef FEAT_ARABIC
8753 curwin->w_p_arab = FALSE;
8754# endif
8755 (void)init_chartab();
8756 }
8757
8758 /*
8759 * If fkmap set, reset Hebrew keymapping.
8760 */
8761 if (p_fkmap && !p_altkeymap)
8762 {
8763 p_altkeymap = 1;
8764 p_hkmap = 0;
8765# ifdef FEAT_ARABIC
8766 curwin->w_p_arab = FALSE;
8767# endif
8768 (void)init_chartab();
8769 }
8770#endif
8771
8772#ifdef FEAT_ARABIC
8773 if ((int *)varp == &curwin->w_p_arab)
8774 {
8775 if (curwin->w_p_arab)
8776 {
8777 /*
8778 * 'arabic' is set, handle various sub-settings.
8779 */
8780 if (!p_tbidi)
8781 {
8782 /* set rightleft mode */
8783 if (!curwin->w_p_rl)
8784 {
8785 curwin->w_p_rl = TRUE;
8786 changed_window_setting();
8787 }
8788
8789 /* Enable Arabic shaping (major part of what Arabic requires) */
8790 if (!p_arshape)
8791 {
8792 p_arshape = TRUE;
8793 redraw_later_clear();
8794 }
8795 }
8796
8797 /* Arabic requires a utf-8 encoding, inform the user if its not
8798 * set. */
8799 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008800 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008801 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8802
Bram Moolenaar8820b482017-03-16 17:23:31 +01008803 msg_source(HL_ATTR(HLF_W));
Bram Moolenaar32526b32019-01-19 17:43:09 +01008804 msg_attr(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008805#ifdef FEAT_EVAL
8806 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8807#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008808 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008809
Bram Moolenaar071d4272004-06-13 20:20:40 +00008810 /* set 'delcombine' */
8811 p_deco = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008812
8813# ifdef FEAT_KEYMAP
8814 /* Force-set the necessary keymap for arabic */
8815 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8816 OPT_LOCAL);
8817# endif
8818# ifdef FEAT_FKMAP
8819 p_altkeymap = 0;
8820 p_hkmap = 0;
8821 p_fkmap = 0;
8822 (void)init_chartab();
8823# endif
8824 }
8825 else
8826 {
8827 /*
8828 * 'arabic' is reset, handle various sub-settings.
8829 */
8830 if (!p_tbidi)
8831 {
8832 /* reset rightleft mode */
8833 if (curwin->w_p_rl)
8834 {
8835 curwin->w_p_rl = FALSE;
8836 changed_window_setting();
8837 }
8838
8839 /* 'arabicshape' isn't reset, it is a global option and
8840 * another window may still need it "on". */
8841 }
8842
8843 /* 'delcombine' isn't reset, it is a global option and another
8844 * window may still want it "on". */
8845
8846# ifdef FEAT_KEYMAP
8847 /* Revert to the default keymap */
8848 curbuf->b_p_iminsert = B_IMODE_NONE;
8849 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8850# endif
8851 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008852 }
8853
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008854#endif
8855
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008856#ifdef FEAT_TERMGUICOLORS
8857 /* 'termguicolors' */
8858 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008859 {
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008860# ifdef FEAT_VTP
8861 /* Do not turn on 'tgc' when 24-bit colors are not supported. */
8862 if (!has_vtp_working())
8863 {
8864 p_tgc = 0;
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01008865 return N_("E954: 24-bit colors are not supported on this environment");
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008866 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008867 if (is_term_win32())
8868 swap_tcap();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008869# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008870# ifdef FEAT_GUI
8871 if (!gui.in_use && !gui.starting)
8872# endif
8873 highlight_gui_started();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008874# ifdef FEAT_VTP
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008875 /* reset t_Co */
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008876 if (is_term_win32())
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02008877 {
8878 control_console_color_rgb();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008879 set_termname(T_NAME);
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02008880 init_highlight(TRUE, FALSE);
8881 }
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008882# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008883 }
8884#endif
8885
Bram Moolenaar071d4272004-06-13 20:20:40 +00008886 /*
8887 * End of handling side effects for bool options.
8888 */
8889
Bram Moolenaar53744302015-07-17 17:38:22 +02008890 /* after handling side effects, call autocommand */
8891
Bram Moolenaar071d4272004-06-13 20:20:40 +00008892 options[opt_idx].flags |= P_WAS_SET;
8893
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008894#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02008895 // Don't do this while starting up or recursively.
8896 if (!starting && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02008897 {
8898 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02008899
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008900 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8901 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8902 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008903 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8904 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8905 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8906 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8907 reset_v_option_vars();
8908 }
8909#endif
8910
Bram Moolenaar071d4272004-06-13 20:20:40 +00008911 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008912 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008913 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008914 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008915 check_redraw(options[opt_idx].flags);
8916
8917 return NULL;
8918}
8919
8920/*
8921 * Set the value of a number option, and take care of side effects.
8922 * Returns NULL for success, or an error message for an error.
8923 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008924 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008925set_num_option(
8926 int opt_idx, /* index in options[] table */
8927 char_u *varp, /* pointer to the option variable */
8928 long value, /* new value */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008929 char *errbuf, /* buffer for error messages */
Bram Moolenaar9b578142016-01-30 19:39:49 +01008930 size_t errbuflen, /* length of "errbuf" */
8931 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008932 OPT_MODELINE */
8933{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008934 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008935 long old_value = *(long *)varp;
8936 long old_Rows = Rows; /* remember old Rows */
8937 long old_Columns = Columns; /* remember old Columns */
8938 long *pp = (long *)varp;
8939
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008940 /* Disallow changing some options from secure mode. */
8941 if ((secure
8942#ifdef HAVE_SANDBOX
8943 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008944#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008945 ) && (options[opt_idx].flags & P_SECURE))
8946 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008947
8948 *pp = value;
8949#ifdef FEAT_EVAL
8950 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008951 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008952#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008953#ifdef FEAT_GUI
8954 need_mouse_correct = TRUE;
8955#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008956
Bram Moolenaar14f24742012-08-08 18:01:05 +02008957 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008958 {
8959 errmsg = e_positive;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02008960#ifdef FEAT_VARTABS
8961 // Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use.
8962 curbuf->b_p_sw = tabstop_count(curbuf->b_p_vts_array) > 0
8963 ? tabstop_first(curbuf->b_p_vts_array)
8964 : curbuf->b_p_ts;
8965#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00008966 curbuf->b_p_sw = curbuf->b_p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02008967#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008968 }
8969
8970 /*
8971 * Number options that need some action when changed
8972 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008973 if (pp == &p_wh || pp == &p_hh)
8974 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008975 // 'winheight' and 'helpheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008976 if (p_wh < 1)
8977 {
8978 errmsg = e_positive;
8979 p_wh = 1;
8980 }
8981 if (p_wmh > p_wh)
8982 {
8983 errmsg = e_winheight;
8984 p_wh = p_wmh;
8985 }
8986 if (p_hh < 0)
8987 {
8988 errmsg = e_positive;
8989 p_hh = 0;
8990 }
8991
8992 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008993 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008994 {
8995 if (pp == &p_wh && curwin->w_height < p_wh)
8996 win_setheight((int)p_wh);
8997 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8998 win_setheight((int)p_hh);
8999 }
9000 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009001 else if (pp == &p_wmh)
9002 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009003 // 'winminheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009004 if (p_wmh < 0)
9005 {
9006 errmsg = e_positive;
9007 p_wmh = 0;
9008 }
9009 if (p_wmh > p_wh)
9010 {
9011 errmsg = e_winheight;
9012 p_wmh = p_wh;
9013 }
9014 win_setminheight();
9015 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009016 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009017 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009018 // 'winwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009019 if (p_wiw < 1)
9020 {
9021 errmsg = e_positive;
9022 p_wiw = 1;
9023 }
9024 if (p_wmw > p_wiw)
9025 {
9026 errmsg = e_winwidth;
9027 p_wiw = p_wmw;
9028 }
9029
9030 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01009031 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009032 win_setwidth((int)p_wiw);
9033 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009034 else if (pp == &p_wmw)
9035 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009036 // 'winminwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009037 if (p_wmw < 0)
9038 {
9039 errmsg = e_positive;
9040 p_wmw = 0;
9041 }
9042 if (p_wmw > p_wiw)
9043 {
9044 errmsg = e_winwidth;
9045 p_wmw = p_wiw;
9046 }
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009047 win_setminwidth();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009048 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009049
Bram Moolenaar071d4272004-06-13 20:20:40 +00009050 /* (re)set last window status line */
9051 else if (pp == &p_ls)
9052 {
9053 last_status(FALSE);
9054 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009055
9056 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00009057 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009058 {
9059 shell_new_rows(); /* recompute window positions and heights */
9060 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009061
9062#ifdef FEAT_GUI
9063 else if (pp == &p_linespace)
9064 {
Bram Moolenaar02743632005-07-25 20:42:36 +00009065 /* Recompute gui.char_height and resize the Vim window to keep the
9066 * same number of lines. */
9067 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00009068 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009069 }
9070#endif
9071
9072#ifdef FEAT_FOLDING
9073 /* 'foldlevel' */
9074 else if (pp == &curwin->w_p_fdl)
9075 {
9076 if (curwin->w_p_fdl < 0)
9077 curwin->w_p_fdl = 0;
9078 newFoldLevel();
9079 }
9080
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00009081 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009082 else if (pp == &curwin->w_p_fml)
9083 {
9084 foldUpdateAll(curwin);
9085 }
9086
9087 /* 'foldnestmax' */
9088 else if (pp == &curwin->w_p_fdn)
9089 {
9090 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
9091 foldUpdateAll(curwin);
9092 }
9093
9094 /* 'foldcolumn' */
9095 else if (pp == &curwin->w_p_fdc)
9096 {
9097 if (curwin->w_p_fdc < 0)
9098 {
9099 errmsg = e_positive;
9100 curwin->w_p_fdc = 0;
9101 }
9102 else if (curwin->w_p_fdc > 12)
9103 {
9104 errmsg = e_invarg;
9105 curwin->w_p_fdc = 12;
9106 }
9107 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009108#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009109
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009110#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009111 /* 'shiftwidth' or 'tabstop' */
9112 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
9113 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009114# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00009115 if (foldmethodIsIndent(curwin))
9116 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009117# endif
9118# ifdef FEAT_CINDENT
9119 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
9120 * parse 'cinoptions'. */
9121 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
9122 parse_cino(curbuf);
9123# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009124 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009125#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009126
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009127 /* 'maxcombine' */
9128 else if (pp == &p_mco)
9129 {
9130 if (p_mco > MAX_MCO)
9131 p_mco = MAX_MCO;
9132 else if (p_mco < 0)
9133 p_mco = 0;
9134 screenclear(); /* will re-allocate the screen */
9135 }
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009136
Bram Moolenaar071d4272004-06-13 20:20:40 +00009137 else if (pp == &curbuf->b_p_iminsert)
9138 {
9139 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
9140 {
9141 errmsg = e_invarg;
9142 curbuf->b_p_iminsert = B_IMODE_NONE;
9143 }
9144 p_iminsert = curbuf->b_p_iminsert;
9145 if (termcap_active) /* don't do this in the alternate screen */
9146 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02009147#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009148 /* Show/unshow value of 'keymap' in status lines. */
9149 status_redraw_curbuf();
9150#endif
9151 }
9152
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02009153#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
9154 /* 'imstyle' */
9155 else if (pp == &p_imst)
9156 {
9157 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
9158 errmsg = e_invarg;
9159 }
9160#endif
9161
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009162 else if (pp == &p_window)
9163 {
9164 if (p_window < 1)
9165 p_window = 1;
9166 else if (p_window >= Rows)
9167 p_window = Rows - 1;
9168 }
9169
Bram Moolenaar071d4272004-06-13 20:20:40 +00009170 else if (pp == &curbuf->b_p_imsearch)
9171 {
9172 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
9173 {
9174 errmsg = e_invarg;
9175 curbuf->b_p_imsearch = B_IMODE_NONE;
9176 }
9177 p_imsearch = curbuf->b_p_imsearch;
9178 }
9179
9180#ifdef FEAT_TITLE
9181 /* if 'titlelen' has changed, redraw the title */
9182 else if (pp == &p_titlelen)
9183 {
9184 if (p_titlelen < 0)
9185 {
9186 errmsg = e_positive;
9187 p_titlelen = 85;
9188 }
9189 if (starting != NO_SCREEN && old_value != p_titlelen)
9190 need_maketitle = TRUE;
9191 }
9192#endif
9193
9194 /* if p_ch changed value, change the command line height */
9195 else if (pp == &p_ch)
9196 {
9197 if (p_ch < 1)
9198 {
9199 errmsg = e_positive;
9200 p_ch = 1;
9201 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009202 if (p_ch > Rows - min_rows() + 1)
9203 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009204
9205 /* Only compute the new window layout when startup has been
9206 * completed. Otherwise the frame sizes may be wrong. */
9207 if (p_ch != old_value && full_screen
9208#ifdef FEAT_GUI
9209 && !gui.starting
9210#endif
9211 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009212 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009213 }
9214
9215 /* when 'updatecount' changes from zero to non-zero, open swap files */
9216 else if (pp == &p_uc)
9217 {
9218 if (p_uc < 0)
9219 {
9220 errmsg = e_positive;
9221 p_uc = 100;
9222 }
9223 if (p_uc && !old_value)
9224 ml_open_files();
9225 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009226#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009227 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009228 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009229 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009230 {
9231 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009232 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009233 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009234 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009235 {
9236 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009237 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009238 }
9239 }
9240#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009241#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009242 else if (pp == &p_mzq)
9243 mzvim_reset_timer();
9244#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009245
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009246#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9247 /* 'pyxversion' */
9248 else if (pp == &p_pyx)
9249 {
9250 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9251 errmsg = e_invarg;
9252 }
9253#endif
9254
Bram Moolenaar071d4272004-06-13 20:20:40 +00009255 /* sync undo before 'undolevels' changes */
9256 else if (pp == &p_ul)
9257 {
9258 /* use the old value, otherwise u_sync() may not work properly */
9259 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009260 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009261 p_ul = value;
9262 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009263 else if (pp == &curbuf->b_p_ul)
9264 {
9265 /* use the old value, otherwise u_sync() may not work properly */
9266 curbuf->b_p_ul = old_value;
9267 u_sync(TRUE);
9268 curbuf->b_p_ul = value;
9269 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009270
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009271#ifdef FEAT_LINEBREAK
9272 /* 'numberwidth' must be positive */
9273 else if (pp == &curwin->w_p_nuw)
9274 {
9275 if (curwin->w_p_nuw < 1)
9276 {
9277 errmsg = e_positive;
9278 curwin->w_p_nuw = 1;
9279 }
9280 if (curwin->w_p_nuw > 10)
9281 {
9282 errmsg = e_invarg;
9283 curwin->w_p_nuw = 10;
9284 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009285 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009286 }
9287#endif
9288
Bram Moolenaar1a384422010-07-14 19:53:30 +02009289 else if (pp == &curbuf->b_p_tw)
9290 {
9291 if (curbuf->b_p_tw < 0)
9292 {
9293 errmsg = e_positive;
9294 curbuf->b_p_tw = 0;
9295 }
9296#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009297 {
9298 win_T *wp;
9299 tabpage_T *tp;
9300
9301 FOR_ALL_TAB_WINDOWS(tp, wp)
9302 check_colorcolumn(wp);
9303 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009304#endif
9305 }
9306
Bram Moolenaar071d4272004-06-13 20:20:40 +00009307 /*
9308 * Check the bounds for numeric options here
9309 */
9310 if (Rows < min_rows() && full_screen)
9311 {
9312 if (errbuf != NULL)
9313 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009314 vim_snprintf((char *)errbuf, errbuflen,
9315 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009316 errmsg = errbuf;
9317 }
9318 Rows = min_rows();
9319 }
9320 if (Columns < MIN_COLUMNS && full_screen)
9321 {
9322 if (errbuf != NULL)
9323 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009324 vim_snprintf((char *)errbuf, errbuflen,
9325 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009326 errmsg = errbuf;
9327 }
9328 Columns = MIN_COLUMNS;
9329 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009330 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009331
Bram Moolenaar071d4272004-06-13 20:20:40 +00009332 /*
9333 * If the screen (shell) height has been changed, assume it is the
9334 * physical screenheight.
9335 */
9336 if (old_Rows != Rows || old_Columns != Columns)
9337 {
9338 /* Changing the screen size is not allowed while updating the screen. */
9339 if (updating_screen)
9340 *pp = old_value;
9341 else if (full_screen
9342#ifdef FEAT_GUI
9343 && !gui.starting
9344#endif
9345 )
9346 set_shellsize((int)Columns, (int)Rows, TRUE);
9347 else
9348 {
9349 /* Postpone the resizing; check the size and cmdline position for
9350 * messages. */
9351 check_shellsize();
9352 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9353 cmdline_row = Rows - p_ch;
9354 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009355 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009356 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009357 }
9358
Bram Moolenaar071d4272004-06-13 20:20:40 +00009359 if (curbuf->b_p_ts <= 0)
9360 {
9361 errmsg = e_positive;
9362 curbuf->b_p_ts = 8;
9363 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009364 if (p_tm < 0)
9365 {
9366 errmsg = e_positive;
9367 p_tm = 0;
9368 }
9369 if ((curwin->w_p_scr <= 0
9370 || (curwin->w_p_scr > curwin->w_height
9371 && curwin->w_height > 0))
9372 && full_screen)
9373 {
9374 if (pp == &(curwin->w_p_scr))
9375 {
9376 if (curwin->w_p_scr != 0)
9377 errmsg = e_scroll;
9378 win_comp_scroll(curwin);
9379 }
9380 /* If 'scroll' became invalid because of a side effect silently adjust
9381 * it. */
9382 else if (curwin->w_p_scr <= 0)
9383 curwin->w_p_scr = 1;
9384 else /* curwin->w_p_scr > curwin->w_height */
9385 curwin->w_p_scr = curwin->w_height;
9386 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009387 if (p_hi < 0)
9388 {
9389 errmsg = e_positive;
9390 p_hi = 0;
9391 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009392 else if (p_hi > 10000)
9393 {
9394 errmsg = e_invarg;
9395 p_hi = 10000;
9396 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009397 if (p_re < 0 || p_re > 2)
9398 {
9399 errmsg = e_invarg;
9400 p_re = 0;
9401 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009402 if (p_report < 0)
9403 {
9404 errmsg = e_positive;
9405 p_report = 1;
9406 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009407 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009408 {
9409 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9410 p_sj = Rows / 2;
9411 else
9412 {
9413 errmsg = e_scroll;
9414 p_sj = 1;
9415 }
9416 }
9417 if (p_so < 0 && full_screen)
9418 {
Bram Moolenaar375e3392019-01-31 18:26:10 +01009419 errmsg = e_positive;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009420 p_so = 0;
9421 }
9422 if (p_siso < 0 && full_screen)
9423 {
9424 errmsg = e_positive;
9425 p_siso = 0;
9426 }
9427#ifdef FEAT_CMDWIN
9428 if (p_cwh < 1)
9429 {
9430 errmsg = e_positive;
9431 p_cwh = 1;
9432 }
9433#endif
9434 if (p_ut < 0)
9435 {
9436 errmsg = e_positive;
9437 p_ut = 2000;
9438 }
9439 if (p_ss < 0)
9440 {
9441 errmsg = e_positive;
9442 p_ss = 0;
9443 }
9444
9445 /* May set global value for local option. */
9446 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9447 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9448
9449 options[opt_idx].flags |= P_WAS_SET;
9450
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009451#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009452 // Don't do this while starting up, failure or recursively.
9453 if (!starting && errmsg == NULL && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009454 {
9455 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009456 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9457 vim_snprintf((char *)buf_new, 10, "%ld", value);
9458 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009459 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9460 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9461 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9462 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9463 reset_v_option_vars();
9464 }
9465#endif
9466
Bram Moolenaar071d4272004-06-13 20:20:40 +00009467 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009468 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009469 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009470 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009471 check_redraw(options[opt_idx].flags);
9472
9473 return errmsg;
9474}
9475
9476/*
9477 * Called after an option changed: check if something needs to be redrawn.
9478 */
9479 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009480check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009481{
9482 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009483 int doclear = (flags & P_RCLR) == P_RCLR;
9484 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009485
Bram Moolenaar071d4272004-06-13 20:20:40 +00009486 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9487 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009488
9489 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9490 changed_window_setting();
9491 if (flags & P_RBUF)
9492 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009493 if (flags & P_RWINONLY)
9494 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009495 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009496 redraw_all_later(CLEAR);
9497 else if (all)
9498 redraw_all_later(NOT_VALID);
9499}
9500
9501/*
9502 * Find index for option 'arg'.
9503 * Return -1 if not found.
9504 */
9505 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009506findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009507{
9508 int opt_idx;
9509 char *s, *p;
9510 static short quick_tab[27] = {0, 0}; /* quick access table */
9511 int is_term_opt;
9512
9513 /*
9514 * For first call: Initialize the quick-access table.
9515 * It contains the index for the first option that starts with a certain
9516 * letter. There are 26 letters, plus the first "t_" option.
9517 */
9518 if (quick_tab[1] == 0)
9519 {
9520 p = options[0].fullname;
9521 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9522 {
9523 if (s[0] != p[0])
9524 {
9525 if (s[0] == 't' && s[1] == '_')
9526 quick_tab[26] = opt_idx;
9527 else
9528 quick_tab[CharOrdLow(s[0])] = opt_idx;
9529 }
9530 p = s;
9531 }
9532 }
9533
9534 /*
9535 * Check for name starting with an illegal character.
9536 */
9537#ifdef EBCDIC
9538 if (!islower(arg[0]))
9539#else
9540 if (arg[0] < 'a' || arg[0] > 'z')
9541#endif
9542 return -1;
9543
9544 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9545 if (is_term_opt)
9546 opt_idx = quick_tab[26];
9547 else
9548 opt_idx = quick_tab[CharOrdLow(arg[0])];
9549 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9550 {
9551 if (STRCMP(arg, s) == 0) /* match full name */
9552 break;
9553 }
9554 if (s == NULL && !is_term_opt)
9555 {
9556 opt_idx = quick_tab[CharOrdLow(arg[0])];
9557 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9558 {
9559 s = options[opt_idx].shortname;
9560 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9561 break;
9562 s = NULL;
9563 }
9564 }
9565 if (s == NULL)
9566 opt_idx = -1;
9567 return opt_idx;
9568}
9569
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009570#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009571/*
9572 * Get the value for an option.
9573 *
9574 * Returns:
9575 * Number or Toggle option: 1, *numval gets value.
9576 * String option: 0, *stringval gets allocated string.
9577 * Hidden Number or Toggle option: -1.
9578 * hidden String option: -2.
9579 * unknown option: -3.
9580 */
9581 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009582get_option_value(
9583 char_u *name,
9584 long *numval,
9585 char_u **stringval, /* NULL when only checking existence */
9586 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009587{
9588 int opt_idx;
9589 char_u *varp;
9590
9591 opt_idx = findoption(name);
9592 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009593 {
9594 int key;
9595
9596 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009597 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009598 {
9599 char_u key_name[2];
9600 char_u *p;
9601
9602 if (key < 0)
9603 {
9604 key_name[0] = KEY2TERMCAP0(key);
9605 key_name[1] = KEY2TERMCAP1(key);
9606 }
9607 else
9608 {
9609 key_name[0] = KS_KEY;
9610 key_name[1] = (key & 0xff);
9611 }
9612 p = find_termcode(key_name);
9613 if (p != NULL)
9614 {
9615 if (stringval != NULL)
9616 *stringval = vim_strsave(p);
9617 return 0;
9618 }
9619 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009620 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009621 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009622
9623 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9624
9625 if (options[opt_idx].flags & P_STRING)
9626 {
9627 if (varp == NULL) /* hidden option */
9628 return -2;
9629 if (stringval != NULL)
9630 {
9631#ifdef FEAT_CRYPT
9632 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009633 if ((char_u **)varp == &curbuf->b_p_key
9634 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009635 *stringval = vim_strsave((char_u *)"*****");
9636 else
9637#endif
9638 *stringval = vim_strsave(*(char_u **)(varp));
9639 }
9640 return 0;
9641 }
9642
9643 if (varp == NULL) /* hidden option */
9644 return -1;
9645 if (options[opt_idx].flags & P_NUM)
9646 *numval = *(long *)varp;
9647 else
9648 {
9649 /* Special case: 'modified' is b_changed, but we also want to consider
9650 * it set when 'ff' or 'fenc' changed. */
9651 if ((int *)varp == &curbuf->b_changed)
9652 *numval = curbufIsChanged();
9653 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009654 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009655 }
9656 return 1;
9657}
9658#endif
9659
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009660#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009661/*
9662 * Returns the option attributes and its value. Unlike the above function it
9663 * will return either global value or local value of the option depending on
9664 * what was requested, but it will never return global value if it was
9665 * requested to return local one and vice versa. Neither it will return
9666 * buffer-local value if it was requested to return window-local one.
9667 *
9668 * Pretends that option is absent if it is not present in the requested scope
9669 * (i.e. has no global, window-local or buffer-local value depending on
9670 * opt_type). Uses
9671 *
9672 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009673 * 0 hidden or unknown option, also option that does not have requested
9674 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009675 * see SOPT_* in vim.h for other flags
9676 *
9677 * Possible opt_type values: see SREQ_* in vim.h
9678 */
9679 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009680get_option_value_strict(
9681 char_u *name,
9682 long *numval,
9683 char_u **stringval, /* NULL when only obtaining attributes */
9684 int opt_type,
9685 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009686{
9687 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009688 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009689 struct vimoption *p;
9690 int r = 0;
9691
9692 opt_idx = findoption(name);
9693 if (opt_idx < 0)
9694 return 0;
9695
9696 p = &(options[opt_idx]);
9697
9698 /* Hidden option */
9699 if (p->var == NULL)
9700 return 0;
9701
9702 if (p->flags & P_BOOL)
9703 r |= SOPT_BOOL;
9704 else if (p->flags & P_NUM)
9705 r |= SOPT_NUM;
9706 else if (p->flags & P_STRING)
9707 r |= SOPT_STRING;
9708
9709 if (p->indir == PV_NONE)
9710 {
9711 if (opt_type == SREQ_GLOBAL)
9712 r |= SOPT_GLOBAL;
9713 else
9714 return 0; /* Did not request global-only option */
9715 }
9716 else
9717 {
9718 if (p->indir & PV_BOTH)
9719 r |= SOPT_GLOBAL;
9720 else if (opt_type == SREQ_GLOBAL)
9721 return 0; /* Requested global option */
9722
9723 if (p->indir & PV_WIN)
9724 {
9725 if (opt_type == SREQ_BUF)
9726 return 0; /* Did not request window-local option */
9727 else
9728 r |= SOPT_WIN;
9729 }
9730 else if (p->indir & PV_BUF)
9731 {
9732 if (opt_type == SREQ_WIN)
9733 return 0; /* Did not request buffer-local option */
9734 else
9735 r |= SOPT_BUF;
9736 }
9737 }
9738
9739 if (stringval == NULL)
9740 return r;
9741
9742 if (opt_type == SREQ_GLOBAL)
9743 varp = p->var;
9744 else
9745 {
9746 if (opt_type == SREQ_BUF)
9747 {
9748 /* Special case: 'modified' is b_changed, but we also want to
9749 * consider it set when 'ff' or 'fenc' changed. */
9750 if (p->indir == PV_MOD)
9751 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009752 *numval = bufIsChanged((buf_T *)from);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009753 varp = NULL;
9754 }
9755#ifdef FEAT_CRYPT
9756 else if (p->indir == PV_KEY)
9757 {
9758 /* never return the value of the crypt key */
9759 *stringval = NULL;
9760 varp = NULL;
9761 }
9762#endif
9763 else
9764 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009765 buf_T *save_curbuf = curbuf;
9766
9767 // only getting a pointer, no need to use aucmd_prepbuf()
9768 curbuf = (buf_T *)from;
9769 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009770 varp = get_varp(p);
Bram Moolenaardefe6422018-06-24 15:14:07 +02009771 curbuf = save_curbuf;
9772 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009773 }
9774 }
9775 else if (opt_type == SREQ_WIN)
9776 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009777 win_T *save_curwin = curwin;
9778
9779 curwin = (win_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009780 curbuf = curwin->w_buffer;
9781 varp = get_varp(p);
9782 curwin = save_curwin;
9783 curbuf = curwin->w_buffer;
9784 }
9785 if (varp == p->var)
9786 return (r | SOPT_UNSET);
9787 }
9788
9789 if (varp != NULL)
9790 {
9791 if (p->flags & P_STRING)
9792 *stringval = vim_strsave(*(char_u **)(varp));
9793 else if (p->flags & P_NUM)
9794 *numval = *(long *) varp;
9795 else
9796 *numval = *(int *)varp;
9797 }
9798
9799 return r;
9800}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009801
9802/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009803 * Iterate over options. First argument is a pointer to a pointer to a
9804 * structure inside options[] array, second is option type like in the above
9805 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009806 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009807 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009808 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009809 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009810 * first argument to NULL.
9811 *
9812 * Returns full option name for current option on each call.
9813 */
9814 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009815option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009816{
9817 struct vimoption *ret = NULL;
9818 do
9819 {
9820 if (*option == NULL)
9821 *option = (void *) options;
9822 else if (((struct vimoption *) (*option))->fullname == NULL)
9823 {
9824 *option = NULL;
9825 return NULL;
9826 }
9827 else
9828 *option = (void *) (((struct vimoption *) (*option)) + 1);
9829
9830 ret = ((struct vimoption *) (*option));
9831
9832 /* Hidden option */
9833 if (ret->var == NULL)
9834 {
9835 ret = NULL;
9836 continue;
9837 }
9838
9839 switch (opt_type)
9840 {
9841 case SREQ_GLOBAL:
9842 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9843 ret = NULL;
9844 break;
9845 case SREQ_BUF:
9846 if (!(ret->indir & PV_BUF))
9847 ret = NULL;
9848 break;
9849 case SREQ_WIN:
9850 if (!(ret->indir & PV_WIN))
9851 ret = NULL;
9852 break;
9853 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009854 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009855 return NULL;
9856 }
9857 }
9858 while (ret == NULL);
9859
9860 return (char_u *)ret->fullname;
9861}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009862#endif
9863
Bram Moolenaar071d4272004-06-13 20:20:40 +00009864/*
9865 * Set the value of option "name".
9866 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009867 *
9868 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009869 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009870 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009871set_option_value(
9872 char_u *name,
9873 long number,
9874 char_u *string,
9875 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009876{
9877 int opt_idx;
9878 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009879 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009880
9881 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009882 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009883 {
9884 int key;
9885
9886 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009887 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009888 {
9889 char_u key_name[2];
9890
9891 if (key < 0)
9892 {
9893 key_name[0] = KEY2TERMCAP0(key);
9894 key_name[1] = KEY2TERMCAP1(key);
9895 }
9896 else
9897 {
9898 key_name[0] = KS_KEY;
9899 key_name[1] = (key & 0xff);
9900 }
9901 add_termcode(key_name, string, FALSE);
9902 if (full_screen)
9903 ttest(FALSE);
9904 redraw_all_later(CLEAR);
9905 return NULL;
9906 }
9907
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009908 semsg(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009909 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009910 else
9911 {
9912 flags = options[opt_idx].flags;
9913#ifdef HAVE_SANDBOX
9914 /* Disallow changing some options in the sandbox */
9915 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009916 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009917 emsg(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009918 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009919 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009920#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009921 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009922 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009923 else
9924 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009925 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009926 if (varp != NULL) /* hidden option is not changed */
9927 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009928 if (number == 0 && string != NULL)
9929 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009930 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009931
9932 /* Either we are given a string or we are setting option
9933 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009934 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009935 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009936 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009937 {
9938 /* There's another character after zeros or the string
9939 * is empty. In both cases, we are trying to set a
9940 * num option using a string. */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009941 semsg(_("E521: Number required: &%s = '%s'"),
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009942 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009943 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009944
9945 }
9946 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009947 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009948 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009949 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009950 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009951 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009952 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009953 }
9954 }
9955 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009956 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009957}
9958
9959/*
9960 * Get the terminal code for a terminal option.
9961 * Returns NULL when not found.
9962 */
9963 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009964get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009965{
9966 int opt_idx;
9967 char_u *varp;
9968
9969 if (tname[0] != 't' || tname[1] != '_' ||
9970 tname[2] == NUL || tname[3] == NUL)
9971 return NULL;
9972 if ((opt_idx = findoption(tname)) >= 0)
9973 {
9974 varp = get_varp(&(options[opt_idx]));
9975 if (varp != NULL)
9976 varp = *(char_u **)(varp);
9977 return varp;
9978 }
9979 return find_termcode(tname + 2);
9980}
9981
9982 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009983get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009984{
9985 int i;
9986
9987 i = findoption((char_u *)"hl");
9988 if (i >= 0)
9989 return options[i].def_val[VI_DEFAULT];
9990 return (char_u *)NULL;
9991}
9992
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009993 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009994get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009995{
9996 int i;
9997
9998 i = findoption((char_u *)"enc");
9999 if (i >= 0)
10000 return options[i].def_val[VI_DEFAULT];
10001 return (char_u *)NULL;
10002}
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010003
Bram Moolenaar071d4272004-06-13 20:20:40 +000010004/*
10005 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010006 * When "has_lt" is true there is a '<' before "*arg_arg".
10007 * Returns 0 when the key is not recognized.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010008 */
10009 static int
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010010find_key_option(char_u *arg_arg, int has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010011{
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010012 int key = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010013 int modifiers;
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010014 char_u *arg = arg_arg;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010015
10016 /*
10017 * Don't use get_special_key_code() for t_xx, we don't want it to call
10018 * add_termcap_entry().
10019 */
10020 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
10021 key = TERMCAP2KEY(arg[2], arg[3]);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010022 else if (has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010023 {
10024 --arg; /* put arg at the '<' */
10025 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +020010026 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010027 if (modifiers) /* can't handle modifiers here */
10028 key = 0;
10029 }
10030 return key;
10031}
10032
10033/*
10034 * if 'all' == 0: show changed options
10035 * if 'all' == 1: show all normal options
10036 * if 'all' == 2: show all terminal options
10037 */
10038 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010039showoptions(
10040 int all,
10041 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010042{
10043 struct vimoption *p;
10044 int col;
10045 int isterm;
10046 char_u *varp;
10047 struct vimoption **items;
10048 int item_count;
10049 int run;
10050 int row, rows;
10051 int cols;
10052 int i;
10053 int len;
10054
10055#define INC 20
10056#define GAP 3
10057
10058 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
10059 PARAM_COUNT));
10060 if (items == NULL)
10061 return;
10062
10063 /* Highlight title */
10064 if (all == 2)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010065 msg_puts_title(_("\n--- Terminal codes ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010066 else if (opt_flags & OPT_GLOBAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010067 msg_puts_title(_("\n--- Global option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010068 else if (opt_flags & OPT_LOCAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010069 msg_puts_title(_("\n--- Local option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010070 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010071 msg_puts_title(_("\n--- Options ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010072
10073 /*
10074 * do the loop two times:
10075 * 1. display the short items
10076 * 2. display the long items (only strings and numbers)
10077 */
10078 for (run = 1; run <= 2 && !got_int; ++run)
10079 {
10080 /*
10081 * collect the items in items[]
10082 */
10083 item_count = 0;
10084 for (p = &options[0]; p->fullname != NULL; p++)
10085 {
Bram Moolenaarf86db782018-10-25 13:31:37 +020010086 // apply :filter /pat/
10087 if (message_filtered((char_u *) p->fullname))
10088 continue;
10089
Bram Moolenaar071d4272004-06-13 20:20:40 +000010090 varp = NULL;
10091 isterm = istermoption(p);
10092 if (opt_flags != 0)
10093 {
10094 if (p->indir != PV_NONE && !isterm)
10095 varp = get_varp_scope(p, opt_flags);
10096 }
10097 else
10098 varp = get_varp(p);
10099 if (varp != NULL
10100 && ((all == 2 && isterm)
10101 || (all == 1 && !isterm)
10102 || (all == 0 && !optval_default(p, varp))))
10103 {
10104 if (p->flags & P_BOOL)
10105 len = 1; /* a toggle option fits always */
10106 else
10107 {
10108 option_value2string(p, opt_flags);
10109 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
10110 }
10111 if ((len <= INC - GAP && run == 1) ||
10112 (len > INC - GAP && run == 2))
10113 items[item_count++] = p;
10114 }
10115 }
10116
10117 /*
10118 * display the items
10119 */
10120 if (run == 1)
10121 {
10122 cols = (Columns + GAP - 3) / INC;
10123 if (cols == 0)
10124 cols = 1;
10125 rows = (item_count + cols - 1) / cols;
10126 }
10127 else /* run == 2 */
10128 rows = item_count;
10129 for (row = 0; row < rows && !got_int; ++row)
10130 {
10131 msg_putchar('\n'); /* go to next line */
10132 if (got_int) /* 'q' typed in more */
10133 break;
10134 col = 0;
10135 for (i = row; i < item_count; i += rows)
10136 {
10137 msg_col = col; /* make columns */
10138 showoneopt(items[i], opt_flags);
10139 col += INC;
10140 }
10141 out_flush();
10142 ui_breakcheck();
10143 }
10144 }
10145 vim_free(items);
10146}
10147
10148/*
10149 * Return TRUE if option "p" has its default value.
10150 */
10151 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010152optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010153{
10154 int dvi;
10155
10156 if (varp == NULL)
10157 return TRUE; /* hidden option is always at default */
10158 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
10159 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010160 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010161 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010162 /* the cast to long is required for Manx C, long_i is
10163 * needed for MSVC */
10164 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010165 /* P_STRING */
10166 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
10167}
10168
10169/*
10170 * showoneopt: show the value of one option
10171 * must not be called with a hidden option!
10172 */
10173 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010174showoneopt(
10175 struct vimoption *p,
10176 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010177{
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010178 char_u *varp;
10179 int save_silent = silent_mode;
10180
10181 silent_mode = FALSE;
10182 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010183
10184 varp = get_varp_scope(p, opt_flags);
10185
10186 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
10187 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
10188 ? !curbufIsChanged() : !*(int *)varp))
Bram Moolenaar32526b32019-01-19 17:43:09 +010010189 msg_puts("no");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010190 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010191 msg_puts("--");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010192 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010193 msg_puts(" ");
10194 msg_puts(p->fullname);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010195 if (!(p->flags & P_BOOL))
10196 {
10197 msg_putchar('=');
10198 /* put value string in NameBuff */
10199 option_value2string(p, opt_flags);
10200 msg_outtrans(NameBuff);
10201 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010202
10203 silent_mode = save_silent;
10204 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010205}
10206
10207/*
10208 * Write modified options as ":set" commands to a file.
10209 *
10210 * There are three values for "opt_flags":
10211 * OPT_GLOBAL: Write global option values and fresh values of
10212 * buffer-local options (used for start of a session
10213 * file).
10214 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10215 * curwin (used for a vimrc file).
10216 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10217 * and local values for window-local options of
10218 * curwin. Local values are also written when at the
10219 * default value, because a modeline or autocommand
10220 * may have set them when doing ":edit file" and the
10221 * user has set them back at the default or fresh
10222 * value.
10223 * When "local_only" is TRUE, don't write fresh
10224 * values, only local values (for ":mkview").
10225 * (fresh value = value used for a new buffer or window for a local option).
10226 *
10227 * Return FAIL on error, OK otherwise.
10228 */
10229 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010230makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010231{
10232 struct vimoption *p;
10233 char_u *varp; /* currently used value */
10234 char_u *varp_fresh; /* local value */
10235 char_u *varp_local = NULL; /* fresh value */
10236 char *cmd;
10237 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010238 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010239
10240 /*
10241 * The options that don't have a default (terminal name, columns, lines)
10242 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010243 * Do the loop over "options[]" twice: once for options with the
10244 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010245 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010246 for (pri = 1; pri >= 0; --pri)
10247 {
10248 for (p = &options[0]; !istermoption(p); p++)
10249 if (!(p->flags & P_NO_MKRC)
10250 && !istermoption(p)
10251 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010252 {
10253 /* skip global option when only doing locals */
10254 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10255 continue;
10256
10257 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10258 * file, they are always buffer-specific. */
10259 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10260 continue;
10261
10262 /* Global values are only written when not at the default value. */
10263 varp = get_varp_scope(p, opt_flags);
10264 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10265 continue;
10266
10267 round = 2;
10268 if (p->indir != PV_NONE)
10269 {
10270 if (p->var == VAR_WIN)
10271 {
10272 /* skip window-local option when only doing globals */
10273 if (!(opt_flags & OPT_LOCAL))
10274 continue;
10275 /* When fresh value of window-local option is not at the
10276 * default, need to write it too. */
10277 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10278 {
10279 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10280 if (!optval_default(p, varp_fresh))
10281 {
10282 round = 1;
10283 varp_local = varp;
10284 varp = varp_fresh;
10285 }
10286 }
10287 }
10288 }
10289
10290 /* Round 1: fresh value for window-local options.
10291 * Round 2: other values */
10292 for ( ; round <= 2; varp = varp_local, ++round)
10293 {
10294 if (round == 1 || (opt_flags & OPT_GLOBAL))
10295 cmd = "set";
10296 else
10297 cmd = "setlocal";
10298
10299 if (p->flags & P_BOOL)
10300 {
10301 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10302 return FAIL;
10303 }
10304 else if (p->flags & P_NUM)
10305 {
10306 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10307 return FAIL;
10308 }
10309 else /* P_STRING */
10310 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010311 int do_endif = FALSE;
10312
Bram Moolenaar071d4272004-06-13 20:20:40 +000010313 /* Don't set 'syntax' and 'filetype' again if the value is
10314 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010315 if (
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +010010316#if defined(FEAT_SYN_HL)
10317 p->indir == PV_SYN ||
10318#endif
10319 p->indir == PV_FT)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010320 {
10321 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10322 *(char_u **)(varp)) < 0
10323 || put_eol(fd) < 0)
10324 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010325 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010326 }
10327 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010328 p->flags) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010329 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010330 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010331 {
10332 if (put_line(fd, "endif") == FAIL)
10333 return FAIL;
10334 }
10335 }
10336 }
10337 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010338 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010339 return OK;
10340}
10341
10342#if defined(FEAT_FOLDING) || defined(PROTO)
10343/*
10344 * Generate set commands for the local fold options only. Used when
10345 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10346 */
10347 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010348makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010349{
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010350 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, 0) == FAIL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010351# ifdef FEAT_EVAL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010352 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010353 == FAIL
10354# endif
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010355 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010356 == FAIL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010357 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010358 == FAIL
10359 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10360 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10361 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10362 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10363 )
10364 return FAIL;
10365
10366 return OK;
10367}
10368#endif
10369
10370 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010371put_setstring(
10372 FILE *fd,
10373 char *cmd,
10374 char *name,
10375 char_u **valuep,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010376 long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010377{
10378 char_u *s;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010379 char_u *buf = NULL;
10380 char_u *part = NULL;
10381 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010382
10383 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10384 return FAIL;
10385 if (*valuep != NULL)
10386 {
10387 /* Output 'pastetoggle' as key names. For other
10388 * options some characters have to be escaped with
10389 * CTRL-V or backslash */
10390 if (valuep == &p_pt)
10391 {
10392 s = *valuep;
10393 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010394 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010395 return FAIL;
10396 }
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010397 // expand the option value, replace $HOME by ~
10398 else if ((flags & P_EXPAND) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010399 {
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010400 int size = (int)STRLEN(*valuep) + 1;
10401
10402 // replace home directory in the whole option value into "buf"
10403 buf = alloc(size);
Bram Moolenaarf8441472011-04-28 17:24:58 +020010404 if (buf == NULL)
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010405 goto fail;
10406 home_replace(NULL, *valuep, buf, size, FALSE);
10407
10408 // If the option value is longer than MAXPATHL, we need to append
10409 // earch comma separated part of the option separately, so that it
10410 // can be expanded when read back.
10411 if (size >= MAXPATHL && (flags & P_COMMA) != 0
10412 && vim_strchr(*valuep, ',') != NULL)
10413 {
10414 part = alloc(size);
10415 if (part == NULL)
10416 goto fail;
10417
10418 // write line break to clear the option, e.g. ':set rtp='
10419 if (put_eol(fd) == FAIL)
10420 goto fail;
10421
10422 p = buf;
10423 while (*p != NUL)
10424 {
10425 // for each comma separated option part, append value to
10426 // the option, :set rtp+=value
10427 if (fprintf(fd, "%s %s+=", cmd, name) < 0)
10428 goto fail;
10429 (void)copy_option_part(&p, part, size, ",");
10430 if (put_escstr(fd, part, 2) == FAIL || put_eol(fd) == FAIL)
10431 goto fail;
10432 }
10433 vim_free(buf);
10434 vim_free(part);
10435 return OK;
10436 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010437 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010438 {
10439 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010440 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010441 }
10442 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010443 }
10444 else if (put_escstr(fd, *valuep, 2) == FAIL)
10445 return FAIL;
10446 }
10447 if (put_eol(fd) < 0)
10448 return FAIL;
10449 return OK;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010450fail:
10451 vim_free(buf);
10452 vim_free(part);
10453 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010454}
10455
10456 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010457put_setnum(
10458 FILE *fd,
10459 char *cmd,
10460 char *name,
10461 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010462{
10463 long wc;
10464
10465 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10466 return FAIL;
10467 if (wc_use_keyname((char_u *)valuep, &wc))
10468 {
10469 /* print 'wildchar' and 'wildcharm' as a key name */
10470 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10471 return FAIL;
10472 }
10473 else if (fprintf(fd, "%ld", *valuep) < 0)
10474 return FAIL;
10475 if (put_eol(fd) < 0)
10476 return FAIL;
10477 return OK;
10478}
10479
10480 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010481put_setbool(
10482 FILE *fd,
10483 char *cmd,
10484 char *name,
10485 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010486{
Bram Moolenaar893de922007-10-02 18:40:57 +000010487 if (value < 0) /* global/local option using global value */
10488 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010489 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10490 || put_eol(fd) < 0)
10491 return FAIL;
10492 return OK;
10493}
10494
10495/*
10496 * Clear all the terminal options.
10497 * If the option has been allocated, free the memory.
10498 * Terminal options are never hidden or indirect.
10499 */
10500 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010501clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010502{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010503 /*
10504 * Reset a few things before clearing the old options. This may cause
10505 * outputting a few things that the terminal doesn't understand, but the
10506 * screen will be cleared later, so this is OK.
10507 */
10508#ifdef FEAT_MOUSE_TTY
10509 mch_setmouse(FALSE); /* switch mouse off */
10510#endif
10511#ifdef FEAT_TITLE
Bram Moolenaar40385db2018-08-07 22:31:44 +020010512 mch_restore_title(SAVE_RESTORE_BOTH); /* restore window titles */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010513#endif
10514#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10515 /* When starting the GUI close the display opened for the clipboard.
10516 * After restoring the title, because that will need the display. */
10517 if (gui.starting)
10518 clear_xterm_clip();
10519#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010520 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010521
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010522 free_termoptions();
10523}
10524
10525 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010526free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010527{
10528 struct vimoption *p;
10529
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010530 for (p = options; p->fullname != NULL; p++)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010531 if (istermoption(p))
10532 {
10533 if (p->flags & P_ALLOCED)
10534 free_string_option(*(char_u **)(p->var));
10535 if (p->flags & P_DEF_ALLOCED)
10536 free_string_option(p->def_val[VI_DEFAULT]);
10537 *(char_u **)(p->var) = empty_option;
10538 p->def_val[VI_DEFAULT] = empty_option;
10539 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010540#ifdef FEAT_EVAL
10541 // remember where the option was cleared
10542 set_option_sctx_idx((int)(p - options), OPT_GLOBAL, current_sctx);
10543#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010544 }
10545 clear_termcodes();
10546}
10547
10548/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010549 * Free the string for one term option, if it was allocated.
10550 * Set the string to empty_option and clear allocated flag.
10551 * "var" points to the option value.
10552 */
10553 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010554free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010555{
10556 struct vimoption *p;
10557
10558 for (p = &options[0]; p->fullname != NULL; p++)
10559 if (p->var == var)
10560 {
10561 if (p->flags & P_ALLOCED)
10562 free_string_option(*(char_u **)(p->var));
10563 *(char_u **)(p->var) = empty_option;
10564 p->flags &= ~P_ALLOCED;
10565 break;
10566 }
10567}
10568
10569/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010570 * Set the terminal option defaults to the current value.
10571 * Used after setting the terminal name.
10572 */
10573 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010574set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010575{
10576 struct vimoption *p;
10577
10578 for (p = &options[0]; p->fullname != NULL; p++)
10579 {
10580 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10581 {
10582 if (p->flags & P_DEF_ALLOCED)
10583 {
10584 free_string_option(p->def_val[VI_DEFAULT]);
10585 p->flags &= ~P_DEF_ALLOCED;
10586 }
10587 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10588 if (p->flags & P_ALLOCED)
10589 {
10590 p->flags |= P_DEF_ALLOCED;
10591 p->flags &= ~P_ALLOCED; /* don't free the value now */
10592 }
10593 }
10594 }
10595}
10596
10597/*
10598 * return TRUE if 'p' starts with 't_'
10599 */
10600 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010601istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010602{
10603 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10604}
10605
10606/*
10607 * Compute columns for ruler and shown command. 'sc_col' is also used to
10608 * decide what the maximum length of a message on the status line can be.
10609 * If there is a status line for the last window, 'sc_col' is independent
10610 * of 'ru_col'.
10611 */
10612
10613#define COL_RULER 17 /* columns needed by standard ruler */
10614
10615 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010616comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010617{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010618#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010619 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010620
10621 sc_col = 0;
10622 ru_col = 0;
10623 if (p_ru)
10624 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010625# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010626 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010627# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010628 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010629# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010630 /* no last status line, adjust sc_col */
10631 if (!last_has_status)
10632 sc_col = ru_col;
10633 }
10634 if (p_sc)
10635 {
10636 sc_col += SHOWCMD_COLS;
10637 if (!p_ru || last_has_status) /* no need for separating space */
10638 ++sc_col;
10639 }
10640 sc_col = Columns - sc_col;
10641 ru_col = Columns - ru_col;
10642 if (sc_col <= 0) /* screen too narrow, will become a mess */
10643 sc_col = 1;
10644 if (ru_col <= 0)
10645 ru_col = 1;
10646#else
10647 sc_col = Columns;
10648 ru_col = Columns;
10649#endif
10650}
10651
Bram Moolenaar113e1072019-01-20 15:30:40 +010010652#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010653/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010654 * Unset local option value, similar to ":set opt<".
10655 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010656 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010657unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010658{
10659 struct vimoption *p;
10660 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010661 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010662
10663 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010664 if (opt_idx < 0)
10665 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010666 p = &(options[opt_idx]);
10667
10668 switch ((int)p->indir)
10669 {
10670 /* global option with local value: use local value if it's been set */
10671 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010672 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010673 break;
10674 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010675 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010676 break;
10677 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010678 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010679 break;
10680 case PV_AR:
10681 buf->b_p_ar = -1;
10682 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010683 case PV_BKC:
10684 clear_string_option(&buf->b_p_bkc);
10685 buf->b_bkc_flags = 0;
10686 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010687 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010688 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010689 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010690 case PV_TC:
10691 clear_string_option(&buf->b_p_tc);
10692 buf->b_tc_flags = 0;
10693 break;
Bram Moolenaar375e3392019-01-31 18:26:10 +010010694 case PV_SISO:
10695 curwin->w_p_siso = -1;
10696 break;
10697 case PV_SO:
10698 curwin->w_p_so = -1;
10699 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010700#ifdef FEAT_FIND_ID
10701 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010702 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010703 break;
10704 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010705 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010706 break;
10707#endif
10708#ifdef FEAT_INS_EXPAND
10709 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010710 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010711 break;
10712 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010713 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010714 break;
10715#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010716 case PV_FP:
10717 clear_string_option(&buf->b_p_fp);
10718 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010719#ifdef FEAT_QUICKFIX
10720 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010721 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010722 break;
10723 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010724 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010725 break;
10726 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010727 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010728 break;
10729#endif
10730#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10731 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010732 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010733 break;
10734#endif
10735#if defined(FEAT_CRYPT)
10736 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010737 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010738 break;
10739#endif
10740#ifdef FEAT_STL_OPT
10741 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010742 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010743 break;
10744#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010745 case PV_UL:
10746 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10747 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010748#ifdef FEAT_LISP
10749 case PV_LW:
10750 clear_string_option(&buf->b_p_lw);
10751 break;
10752#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010753 case PV_MENC:
10754 clear_string_option(&buf->b_p_menc);
10755 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010756 }
10757}
Bram Moolenaar113e1072019-01-20 15:30:40 +010010758#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010759
10760/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010761 * Get pointer to option variable, depending on local or global scope.
10762 */
10763 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010764get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010765{
10766 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10767 {
10768 if (p->var == VAR_WIN)
10769 return (char_u *)GLOBAL_WO(get_varp(p));
10770 return p->var;
10771 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010772 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010773 {
10774 switch ((int)p->indir)
10775 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010776 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010777#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010778 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10779 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10780 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010781#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010782 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10783 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10784 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010785 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010786 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010787 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar375e3392019-01-31 18:26:10 +010010788 case PV_SISO: return (char_u *)&(curwin->w_p_siso);
10789 case PV_SO: return (char_u *)&(curwin->w_p_so);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010790#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010791 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10792 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010793#endif
10794#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010795 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10796 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010797#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010798#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10799 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10800#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010801#if defined(FEAT_CRYPT)
10802 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10803#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010804#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010805 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010806#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010807 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010808#ifdef FEAT_LISP
10809 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10810#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010811 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010812 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010813 }
10814 return NULL; /* "cannot happen" */
10815 }
10816 return get_varp(p);
10817}
10818
10819/*
10820 * Get pointer to option variable.
10821 */
10822 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010823get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010824{
10825 /* hidden option, always return NULL */
10826 if (p->var == NULL)
10827 return NULL;
10828
10829 switch ((int)p->indir)
10830 {
10831 case PV_NONE: return p->var;
10832
10833 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010834 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010835 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010836 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010837 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010838 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010839 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010840 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010841 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010842 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010843 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010844 case PV_TC: return *curbuf->b_p_tc != NUL
10845 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010846 case PV_BKC: return *curbuf->b_p_bkc != NUL
10847 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar375e3392019-01-31 18:26:10 +010010848 case PV_SISO: return curwin->w_p_siso >= 0
10849 ? (char_u *)&(curwin->w_p_siso) : p->var;
10850 case PV_SO: return curwin->w_p_so >= 0
10851 ? (char_u *)&(curwin->w_p_so) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010852#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010853 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010854 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010855 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010856 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10857#endif
10858#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010859 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010860 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010861 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010862 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10863#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010864 case PV_FP: return *curbuf->b_p_fp != NUL
10865 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010866#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010867 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010868 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010869 case PV_GP: return *curbuf->b_p_gp != NUL
10870 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10871 case PV_MP: return *curbuf->b_p_mp != NUL
10872 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010873#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010874#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10875 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10876 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10877#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010878#if defined(FEAT_CRYPT)
10879 case PV_CM: return *curbuf->b_p_cm != NUL
10880 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10881#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010882#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010883 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010884 ? (char_u *)&(curwin->w_p_stl) : p->var;
10885#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010886 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10887 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010888#ifdef FEAT_LISP
10889 case PV_LW: return *curbuf->b_p_lw != NUL
10890 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10891#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010892 case PV_MENC: return *curbuf->b_p_menc != NUL
10893 ? (char_u *)&(curbuf->b_p_menc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010894
10895#ifdef FEAT_ARABIC
10896 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10897#endif
10898 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010899#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010900 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10901#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010902#ifdef FEAT_SYN_HL
10903 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10904 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010905 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010906#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010907#ifdef FEAT_DIFF
10908 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10909#endif
10910#ifdef FEAT_FOLDING
10911 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10912 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10913 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10914 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10915 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10916 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10917 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10918# ifdef FEAT_EVAL
10919 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10920 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10921# endif
10922 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10923#endif
10924 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010925 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010926#ifdef FEAT_LINEBREAK
10927 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10928#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010929 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010930 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020010931#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010932 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10933#endif
10934#ifdef FEAT_RIGHTLEFT
10935 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10936 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10937#endif
10938 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10939 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10940#ifdef FEAT_LINEBREAK
10941 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010942 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10943 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010944#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010945 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010946 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010947#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010948 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10949 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10950#endif
10951#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020010952 case PV_TWK: return (char_u *)&(curwin->w_p_twk);
10953 case PV_TWS: return (char_u *)&(curwin->w_p_tws);
10954 case PV_TWSL: return (char_u *)&(curbuf->b_p_twsl);
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +010010955 case PV_TMOD: return (char_u *)&(curwin->w_p_tmod);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010956#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010957
10958 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10959 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010960 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010961 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10962 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010963 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10964 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10965#ifdef FEAT_CINDENT
10966 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10967 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10968 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10969#endif
10970#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10971 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10972#endif
10973#ifdef FEAT_COMMENTS
10974 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10975#endif
10976#ifdef FEAT_FOLDING
10977 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10978#endif
10979#ifdef FEAT_INS_EXPAND
10980 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10981#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010982#ifdef FEAT_COMPL_FUNC
10983 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010984 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010985#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010986 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010987 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010988 case PV_ET: return (char_u *)&(curbuf->b_p_et);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010989 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010990 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010991 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010992 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010993 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010994 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10995 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10996 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10997 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10998#ifdef FEAT_FIND_ID
10999# ifdef FEAT_EVAL
11000 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
11001# endif
11002#endif
11003#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11004 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
11005 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
11006#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011007#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011008 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
11009#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011010#ifdef FEAT_CRYPT
11011 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
11012#endif
11013#ifdef FEAT_LISP
11014 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
11015#endif
11016 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
11017 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
11018 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
11019 case PV_MOD: return (char_u *)&(curbuf->b_changed);
11020 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011021 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011022#ifdef FEAT_TEXTOBJ
11023 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
11024#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011025 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
11026#ifdef FEAT_SMARTINDENT
11027 case PV_SI: return (char_u *)&(curbuf->b_p_si);
11028#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011029 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011030 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
11031#ifdef FEAT_SEARCHPATH
11032 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
11033#endif
11034 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
11035#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011036 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011037 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
11038#endif
11039#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020011040 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
11041 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
11042 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011043#endif
11044 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
11045 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
11046 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
11047 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011048#ifdef FEAT_PERSISTENT_UNDO
11049 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
11050#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011051 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
11052#ifdef FEAT_KEYMAP
11053 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
11054#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011055#ifdef FEAT_SIGNS
11056 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
11057#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011058#ifdef FEAT_VARTABS
11059 case PV_VSTS: return (char_u *)&(curbuf->b_p_vsts);
11060 case PV_VTS: return (char_u *)&(curbuf->b_p_vts);
11061#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010011062 default: iemsg(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011063 }
11064 /* always return a valid pointer to avoid a crash! */
11065 return (char_u *)&(curbuf->b_p_wm);
11066}
11067
11068/*
11069 * Get the value of 'equalprg', either the buffer-local one or the global one.
11070 */
11071 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011072get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011073{
11074 if (*curbuf->b_p_ep == NUL)
11075 return p_ep;
11076 return curbuf->b_p_ep;
11077}
11078
Bram Moolenaar071d4272004-06-13 20:20:40 +000011079/*
11080 * Copy options from one window to another.
11081 * Used when splitting a window.
11082 */
11083 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011084win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011085{
11086 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
11087 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
11088# ifdef FEAT_RIGHTLEFT
11089# ifdef FEAT_FKMAP
11090 /* Is this right? */
11091 wp_to->w_farsi = wp_from->w_farsi;
11092# endif
11093# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020011094#if defined(FEAT_LINEBREAK)
11095 briopt_check(wp_to);
11096#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011097}
Bram Moolenaar071d4272004-06-13 20:20:40 +000011098
11099/*
11100 * Copy the options from one winopt_T to another.
11101 * Doesn't free the old option values in "to", use clear_winopt() for that.
11102 * The 'scroll' option is not copied, because it depends on the window height.
11103 * The 'previewwindow' option is reset, there can be only one preview window.
11104 */
11105 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011106copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011107{
11108#ifdef FEAT_ARABIC
11109 to->wo_arab = from->wo_arab;
11110#endif
11111 to->wo_list = from->wo_list;
11112 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020011113 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011114#ifdef FEAT_LINEBREAK
11115 to->wo_nuw = from->wo_nuw;
11116#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011117#ifdef FEAT_RIGHTLEFT
11118 to->wo_rl = from->wo_rl;
11119 to->wo_rlc = vim_strsave(from->wo_rlc);
11120#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011121#ifdef FEAT_STL_OPT
11122 to->wo_stl = vim_strsave(from->wo_stl);
11123#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011124 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011125#ifdef FEAT_DIFF
11126 to->wo_wrap_save = from->wo_wrap_save;
11127#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011128#ifdef FEAT_LINEBREAK
11129 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020011130 to->wo_bri = from->wo_bri;
11131 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011132#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011133 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011134 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010011135 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011136 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011137#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000011138 to->wo_spell = from->wo_spell;
11139#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011140#ifdef FEAT_SYN_HL
11141 to->wo_cuc = from->wo_cuc;
11142 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020011143 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011144#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011145#ifdef FEAT_DIFF
11146 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011147 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011148#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011149#ifdef FEAT_CONCEAL
11150 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020011151 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011152#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011153#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011154 to->wo_twk = vim_strsave(from->wo_twk);
11155 to->wo_tws = vim_strsave(from->wo_tws);
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +010011156 to->wo_tmod = vim_strsave(from->wo_tmod);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011157#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011158#ifdef FEAT_FOLDING
11159 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011160 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011161 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011162 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011163 to->wo_fdi = vim_strsave(from->wo_fdi);
11164 to->wo_fml = from->wo_fml;
11165 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011166 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011167 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011168 to->wo_fdm_save = from->wo_diff_saved
11169 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011170 to->wo_fdn = from->wo_fdn;
11171# ifdef FEAT_EVAL
11172 to->wo_fde = vim_strsave(from->wo_fde);
11173 to->wo_fdt = vim_strsave(from->wo_fdt);
11174# endif
11175 to->wo_fmr = vim_strsave(from->wo_fmr);
11176#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011177#ifdef FEAT_SIGNS
11178 to->wo_scl = vim_strsave(from->wo_scl);
11179#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011180 check_winopt(to); /* don't want NULL pointers */
11181}
11182
11183/*
11184 * Check string options in a window for a NULL value.
11185 */
11186 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011187check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011188{
11189 check_winopt(&win->w_onebuf_opt);
11190 check_winopt(&win->w_allbuf_opt);
11191}
11192
11193/*
11194 * Check for NULL pointers in a winopt_T and replace them with empty_option.
11195 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020011196 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011197check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011198{
11199#ifdef FEAT_FOLDING
11200 check_string_option(&wop->wo_fdi);
11201 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011202 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011203# ifdef FEAT_EVAL
11204 check_string_option(&wop->wo_fde);
11205 check_string_option(&wop->wo_fdt);
11206# endif
11207 check_string_option(&wop->wo_fmr);
11208#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011209#ifdef FEAT_SIGNS
11210 check_string_option(&wop->wo_scl);
11211#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011212#ifdef FEAT_RIGHTLEFT
11213 check_string_option(&wop->wo_rlc);
11214#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011215#ifdef FEAT_STL_OPT
11216 check_string_option(&wop->wo_stl);
11217#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011218#ifdef FEAT_SYN_HL
11219 check_string_option(&wop->wo_cc);
11220#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011221#ifdef FEAT_CONCEAL
11222 check_string_option(&wop->wo_cocu);
11223#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011224#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011225 check_string_option(&wop->wo_twk);
11226 check_string_option(&wop->wo_tws);
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +010011227 check_string_option(&wop->wo_tmod);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011228#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011229#ifdef FEAT_LINEBREAK
11230 check_string_option(&wop->wo_briopt);
11231#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011232}
11233
11234/*
11235 * Free the allocated memory inside a winopt_T.
11236 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011237 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011238clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011239{
11240#ifdef FEAT_FOLDING
11241 clear_string_option(&wop->wo_fdi);
11242 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011243 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011244# ifdef FEAT_EVAL
11245 clear_string_option(&wop->wo_fde);
11246 clear_string_option(&wop->wo_fdt);
11247# endif
11248 clear_string_option(&wop->wo_fmr);
11249#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011250#ifdef FEAT_SIGNS
11251 clear_string_option(&wop->wo_scl);
11252#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011253#ifdef FEAT_LINEBREAK
11254 clear_string_option(&wop->wo_briopt);
11255#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011256#ifdef FEAT_RIGHTLEFT
11257 clear_string_option(&wop->wo_rlc);
11258#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011259#ifdef FEAT_STL_OPT
11260 clear_string_option(&wop->wo_stl);
11261#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011262#ifdef FEAT_SYN_HL
11263 clear_string_option(&wop->wo_cc);
11264#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011265#ifdef FEAT_CONCEAL
11266 clear_string_option(&wop->wo_cocu);
11267#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011268#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011269 clear_string_option(&wop->wo_twk);
11270 clear_string_option(&wop->wo_tws);
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +010011271 clear_string_option(&wop->wo_tmod);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011272#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011273}
11274
11275/*
11276 * Copy global option values to local options for one buffer.
11277 * Used when creating a new buffer and sometimes when entering a buffer.
11278 * flags:
11279 * BCO_ENTER We will enter the buf buffer.
11280 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11281 * appropriate.
11282 * BCO_NOHELP Don't copy the values to a help buffer.
11283 */
11284 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011285buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011286{
11287 int should_copy = TRUE;
11288 char_u *save_p_isk = NULL; /* init for GCC */
11289 int dont_do_help;
11290 int did_isk = FALSE;
11291
11292 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011293 * Skip this when the option defaults have not been set yet. Happens when
11294 * main() allocates the first buffer.
11295 */
11296 if (p_cpo != NULL)
11297 {
11298 /*
11299 * Always copy when entering and 'cpo' contains 'S'.
11300 * Don't copy when already initialized.
11301 * Don't copy when 'cpo' contains 's' and not entering.
11302 * 'S' BCO_ENTER initialized 's' should_copy
11303 * yes yes X X TRUE
11304 * yes no yes X FALSE
11305 * no X yes X FALSE
11306 * X no no yes FALSE
11307 * X no no no TRUE
11308 * no yes no X TRUE
11309 */
11310 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11311 && (buf->b_p_initialized
11312 || (!(flags & BCO_ENTER)
11313 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11314 should_copy = FALSE;
11315
11316 if (should_copy || (flags & BCO_ALWAYS))
11317 {
11318 /* Don't copy the options specific to a help buffer when
11319 * BCO_NOHELP is given or the options were initialized already
11320 * (jumping back to a help file with CTRL-T or CTRL-O) */
11321 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11322 || buf->b_p_initialized;
11323 if (dont_do_help) /* don't free b_p_isk */
11324 {
11325 save_p_isk = buf->b_p_isk;
11326 buf->b_p_isk = NULL;
11327 }
11328 /*
Bram Moolenaar40385db2018-08-07 22:31:44 +020011329 * Always free the allocated strings. If not already initialized,
11330 * reset 'readonly' and copy 'fileformat'.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011331 */
11332 if (!buf->b_p_initialized)
11333 {
11334 free_buf_options(buf, TRUE);
11335 buf->b_p_ro = FALSE; /* don't copy readonly */
11336 buf->b_p_tx = p_tx;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011337 buf->b_p_fenc = vim_strsave(p_fenc);
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011338 switch (*p_ffs)
11339 {
11340 case 'm':
11341 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11342 case 'd':
11343 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11344 case 'u':
11345 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11346 default:
11347 buf->b_p_ff = vim_strsave(p_ff);
11348 }
11349 if (buf->b_p_ff != NULL)
11350 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011351 buf->b_p_bh = empty_option;
11352 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011353 }
11354 else
11355 free_buf_options(buf, FALSE);
11356
11357 buf->b_p_ai = p_ai;
11358 buf->b_p_ai_nopaste = p_ai_nopaste;
11359 buf->b_p_sw = p_sw;
11360 buf->b_p_tw = p_tw;
11361 buf->b_p_tw_nopaste = p_tw_nopaste;
11362 buf->b_p_tw_nobin = p_tw_nobin;
11363 buf->b_p_wm = p_wm;
11364 buf->b_p_wm_nopaste = p_wm_nopaste;
11365 buf->b_p_wm_nobin = p_wm_nobin;
11366 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011367 buf->b_p_bomb = p_bomb;
Bram Moolenaarb388be02015-07-22 22:19:38 +020011368 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011369 buf->b_p_et = p_et;
11370 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011371 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011372 buf->b_p_ml = p_ml;
11373 buf->b_p_ml_nobin = p_ml_nobin;
11374 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011375 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011376#ifdef FEAT_INS_EXPAND
11377 buf->b_p_cpt = vim_strsave(p_cpt);
11378#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011379#ifdef FEAT_COMPL_FUNC
11380 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011381 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011382#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011383 buf->b_p_sts = p_sts;
11384 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011385#ifdef FEAT_VARTABS
11386 buf->b_p_vsts = vim_strsave(p_vsts);
11387 if (p_vsts && p_vsts != empty_option)
11388 tabstop_set(p_vsts, &buf->b_p_vsts_array);
11389 else
11390 buf->b_p_vsts_array = 0;
11391 buf->b_p_vsts_nopaste = p_vsts_nopaste
11392 ? vim_strsave(p_vsts_nopaste) : NULL;
11393#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011394 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011395#ifdef FEAT_COMMENTS
11396 buf->b_p_com = vim_strsave(p_com);
11397#endif
11398#ifdef FEAT_FOLDING
11399 buf->b_p_cms = vim_strsave(p_cms);
11400#endif
11401 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011402 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011403 buf->b_p_nf = vim_strsave(p_nf);
11404 buf->b_p_mps = vim_strsave(p_mps);
11405#ifdef FEAT_SMARTINDENT
11406 buf->b_p_si = p_si;
11407#endif
11408 buf->b_p_ci = p_ci;
11409#ifdef FEAT_CINDENT
11410 buf->b_p_cin = p_cin;
11411 buf->b_p_cink = vim_strsave(p_cink);
11412 buf->b_p_cino = vim_strsave(p_cino);
11413#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011414 /* Don't copy 'filetype', it must be detected */
11415 buf->b_p_ft = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011416 buf->b_p_pi = p_pi;
11417#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11418 buf->b_p_cinw = vim_strsave(p_cinw);
11419#endif
11420#ifdef FEAT_LISP
11421 buf->b_p_lisp = p_lisp;
11422#endif
11423#ifdef FEAT_SYN_HL
11424 /* Don't copy 'syntax', it must be set */
11425 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011426 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011427 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011428#endif
11429#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011430 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011431 (void)compile_cap_prog(&buf->b_s);
11432 buf->b_s.b_p_spf = vim_strsave(p_spf);
11433 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011434#endif
11435#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11436 buf->b_p_inde = vim_strsave(p_inde);
11437 buf->b_p_indk = vim_strsave(p_indk);
11438#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011439 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011440#if defined(FEAT_EVAL)
11441 buf->b_p_fex = vim_strsave(p_fex);
11442#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011443#ifdef FEAT_CRYPT
11444 buf->b_p_key = vim_strsave(p_key);
11445#endif
11446#ifdef FEAT_SEARCHPATH
11447 buf->b_p_sua = vim_strsave(p_sua);
11448#endif
11449#ifdef FEAT_KEYMAP
11450 buf->b_p_keymap = vim_strsave(p_keymap);
11451 buf->b_kmap_state |= KEYMAP_INIT;
11452#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011453#ifdef FEAT_TERMINAL
11454 buf->b_p_twsl = p_twsl;
11455#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011456 /* This isn't really an option, but copying the langmap and IME
11457 * state from the current buffer is better than resetting it. */
11458 buf->b_p_iminsert = p_iminsert;
11459 buf->b_p_imsearch = p_imsearch;
11460
11461 /* options that are normally global but also have a local value
11462 * are not copied, start using the global value */
11463 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011464 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011465 buf->b_p_bkc = empty_option;
11466 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011467#ifdef FEAT_QUICKFIX
11468 buf->b_p_gp = empty_option;
11469 buf->b_p_mp = empty_option;
11470 buf->b_p_efm = empty_option;
11471#endif
11472 buf->b_p_ep = empty_option;
11473 buf->b_p_kp = empty_option;
11474 buf->b_p_path = empty_option;
11475 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011476 buf->b_p_tc = empty_option;
11477 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011478#ifdef FEAT_FIND_ID
11479 buf->b_p_def = empty_option;
11480 buf->b_p_inc = empty_option;
11481# ifdef FEAT_EVAL
11482 buf->b_p_inex = vim_strsave(p_inex);
11483# endif
11484#endif
11485#ifdef FEAT_INS_EXPAND
11486 buf->b_p_dict = empty_option;
11487 buf->b_p_tsr = empty_option;
11488#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011489#ifdef FEAT_TEXTOBJ
11490 buf->b_p_qe = vim_strsave(p_qe);
11491#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011492#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11493 buf->b_p_bexpr = empty_option;
11494#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011495#if defined(FEAT_CRYPT)
11496 buf->b_p_cm = empty_option;
11497#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011498#ifdef FEAT_PERSISTENT_UNDO
11499 buf->b_p_udf = p_udf;
11500#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011501#ifdef FEAT_LISP
11502 buf->b_p_lw = empty_option;
11503#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011504 buf->b_p_menc = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011505
11506 /*
11507 * Don't copy the options set by ex_help(), use the saved values,
11508 * when going from a help buffer to a non-help buffer.
11509 * Don't touch these at all when BCO_NOHELP is used and going from
11510 * or to a help buffer.
11511 */
11512 if (dont_do_help)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011513 {
Bram Moolenaar071d4272004-06-13 20:20:40 +000011514 buf->b_p_isk = save_p_isk;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011515#ifdef FEAT_VARTABS
11516 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11517 tabstop_set(p_vts, &buf->b_p_vts_array);
11518 else
11519 buf->b_p_vts_array = NULL;
11520#endif
11521 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011522 else
11523 {
11524 buf->b_p_isk = vim_strsave(p_isk);
11525 did_isk = TRUE;
11526 buf->b_p_ts = p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011527#ifdef FEAT_VARTABS
11528 buf->b_p_vts = vim_strsave(p_vts);
11529 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11530 tabstop_set(p_vts, &buf->b_p_vts_array);
11531 else
11532 buf->b_p_vts_array = NULL;
11533#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011534 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011535 if (buf->b_p_bt[0] == 'h')
11536 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011537 buf->b_p_ma = p_ma;
11538 }
11539 }
11540
11541 /*
11542 * When the options should be copied (ignoring BCO_ALWAYS), set the
11543 * flag that indicates that the options have been initialized.
11544 */
11545 if (should_copy)
11546 buf->b_p_initialized = TRUE;
11547 }
11548
11549 check_buf_options(buf); /* make sure we don't have NULLs */
11550 if (did_isk)
11551 (void)buf_init_chartab(buf, FALSE);
11552}
11553
11554/*
11555 * Reset the 'modifiable' option and its default value.
11556 */
11557 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011558reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011559{
11560 int opt_idx;
11561
11562 curbuf->b_p_ma = FALSE;
11563 p_ma = FALSE;
11564 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011565 if (opt_idx >= 0)
11566 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011567}
11568
11569/*
11570 * Set the global value for 'iminsert' to the local value.
11571 */
11572 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011573set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011574{
11575 p_iminsert = curbuf->b_p_iminsert;
11576}
11577
11578/*
11579 * Set the global value for 'imsearch' to the local value.
11580 */
11581 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011582set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011583{
11584 p_imsearch = curbuf->b_p_imsearch;
11585}
11586
11587#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11588static int expand_option_idx = -1;
11589static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11590static int expand_option_flags = 0;
11591
11592 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011593set_context_in_set_cmd(
11594 expand_T *xp,
11595 char_u *arg,
11596 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011597{
11598 int nextchar;
11599 long_u flags = 0; /* init for GCC */
11600 int opt_idx = 0; /* init for GCC */
11601 char_u *p;
11602 char_u *s;
11603 int is_term_option = FALSE;
11604 int key;
11605
11606 expand_option_flags = opt_flags;
11607
11608 xp->xp_context = EXPAND_SETTINGS;
11609 if (*arg == NUL)
11610 {
11611 xp->xp_pattern = arg;
11612 return;
11613 }
11614 p = arg + STRLEN(arg) - 1;
11615 if (*p == ' ' && *(p - 1) != '\\')
11616 {
11617 xp->xp_pattern = p + 1;
11618 return;
11619 }
11620 while (p > arg)
11621 {
11622 s = p;
11623 /* count number of backslashes before ' ' or ',' */
11624 if (*p == ' ' || *p == ',')
11625 {
11626 while (s > arg && *(s - 1) == '\\')
11627 --s;
11628 }
11629 /* break at a space with an even number of backslashes */
11630 if (*p == ' ' && ((p - s) & 1) == 0)
11631 {
11632 ++p;
11633 break;
11634 }
11635 --p;
11636 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011637 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011638 {
11639 xp->xp_context = EXPAND_BOOL_SETTINGS;
11640 p += 2;
11641 }
11642 if (STRNCMP(p, "inv", 3) == 0)
11643 {
11644 xp->xp_context = EXPAND_BOOL_SETTINGS;
11645 p += 3;
11646 }
11647 xp->xp_pattern = arg = p;
11648 if (*arg == '<')
11649 {
11650 while (*p != '>')
11651 if (*p++ == NUL) /* expand terminal option name */
11652 return;
11653 key = get_special_key_code(arg + 1);
11654 if (key == 0) /* unknown name */
11655 {
11656 xp->xp_context = EXPAND_NOTHING;
11657 return;
11658 }
11659 nextchar = *++p;
11660 is_term_option = TRUE;
11661 expand_option_name[2] = KEY2TERMCAP0(key);
11662 expand_option_name[3] = KEY2TERMCAP1(key);
11663 }
11664 else
11665 {
11666 if (p[0] == 't' && p[1] == '_')
11667 {
11668 p += 2;
11669 if (*p != NUL)
11670 ++p;
11671 if (*p == NUL)
11672 return; /* expand option name */
11673 nextchar = *++p;
11674 is_term_option = TRUE;
11675 expand_option_name[2] = p[-2];
11676 expand_option_name[3] = p[-1];
11677 }
11678 else
11679 {
11680 /* Allow * wildcard */
11681 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11682 p++;
11683 if (*p == NUL)
11684 return;
11685 nextchar = *p;
11686 *p = NUL;
11687 opt_idx = findoption(arg);
11688 *p = nextchar;
11689 if (opt_idx == -1 || options[opt_idx].var == NULL)
11690 {
11691 xp->xp_context = EXPAND_NOTHING;
11692 return;
11693 }
11694 flags = options[opt_idx].flags;
11695 if (flags & P_BOOL)
11696 {
11697 xp->xp_context = EXPAND_NOTHING;
11698 return;
11699 }
11700 }
11701 }
11702 /* handle "-=" and "+=" */
11703 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11704 {
11705 ++p;
11706 nextchar = '=';
11707 }
11708 if ((nextchar != '=' && nextchar != ':')
11709 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11710 {
11711 xp->xp_context = EXPAND_UNSUCCESSFUL;
11712 return;
11713 }
11714 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11715 {
11716 xp->xp_context = EXPAND_OLD_SETTING;
11717 if (is_term_option)
11718 expand_option_idx = -1;
11719 else
11720 expand_option_idx = opt_idx;
11721 xp->xp_pattern = p + 1;
11722 return;
11723 }
11724 xp->xp_context = EXPAND_NOTHING;
11725 if (is_term_option || (flags & P_NUM))
11726 return;
11727
11728 xp->xp_pattern = p + 1;
11729
11730 if (flags & P_EXPAND)
11731 {
11732 p = options[opt_idx].var;
11733 if (p == (char_u *)&p_bdir
11734 || p == (char_u *)&p_dir
11735 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011736 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011737 || p == (char_u *)&p_rtp
11738#ifdef FEAT_SEARCHPATH
11739 || p == (char_u *)&p_cdpath
11740#endif
11741#ifdef FEAT_SESSION
11742 || p == (char_u *)&p_vdir
11743#endif
11744 )
11745 {
11746 xp->xp_context = EXPAND_DIRECTORIES;
11747 if (p == (char_u *)&p_path
11748#ifdef FEAT_SEARCHPATH
11749 || p == (char_u *)&p_cdpath
11750#endif
11751 )
11752 xp->xp_backslash = XP_BS_THREE;
11753 else
11754 xp->xp_backslash = XP_BS_ONE;
11755 }
11756 else
11757 {
11758 xp->xp_context = EXPAND_FILES;
11759 /* for 'tags' need three backslashes for a space */
11760 if (p == (char_u *)&p_tags)
11761 xp->xp_backslash = XP_BS_THREE;
11762 else
11763 xp->xp_backslash = XP_BS_ONE;
11764 }
11765 }
11766
11767 /* For an option that is a list of file names, find the start of the
11768 * last file name. */
11769 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11770 {
11771 /* count number of backslashes before ' ' or ',' */
11772 if (*p == ' ' || *p == ',')
11773 {
11774 s = p;
11775 while (s > xp->xp_pattern && *(s - 1) == '\\')
11776 --s;
11777 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11778 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11779 {
11780 xp->xp_pattern = p + 1;
11781 break;
11782 }
11783 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011784
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011785#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011786 /* for 'spellsuggest' start at "file:" */
11787 if (options[opt_idx].var == (char_u *)&p_sps
11788 && STRNCMP(p, "file:", 5) == 0)
11789 {
11790 xp->xp_pattern = p + 5;
11791 break;
11792 }
11793#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011794 }
11795
11796 return;
11797}
11798
11799 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011800ExpandSettings(
11801 expand_T *xp,
11802 regmatch_T *regmatch,
11803 int *num_file,
11804 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011805{
11806 int num_normal = 0; /* Nr of matching non-term-code settings */
11807 int num_term = 0; /* Nr of matching terminal code settings */
11808 int opt_idx;
11809 int match;
11810 int count = 0;
11811 char_u *str;
11812 int loop;
11813 int is_term_opt;
11814 char_u name_buf[MAX_KEY_NAME_LEN];
11815 static char *(names[]) = {"all", "termcap"};
11816 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11817
11818 /* do this loop twice:
11819 * loop == 0: count the number of matching options
11820 * loop == 1: copy the matching options into allocated memory
11821 */
11822 for (loop = 0; loop <= 1; ++loop)
11823 {
11824 regmatch->rm_ic = ic;
11825 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11826 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011827 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11828 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011829 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11830 {
11831 if (loop == 0)
11832 num_normal++;
11833 else
11834 (*file)[count++] = vim_strsave((char_u *)names[match]);
11835 }
11836 }
11837 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11838 opt_idx++)
11839 {
11840 if (options[opt_idx].var == NULL)
11841 continue;
11842 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11843 && !(options[opt_idx].flags & P_BOOL))
11844 continue;
11845 is_term_opt = istermoption(&options[opt_idx]);
11846 if (is_term_opt && num_normal > 0)
11847 continue;
11848 match = FALSE;
11849 if (vim_regexec(regmatch, str, (colnr_T)0)
11850 || (options[opt_idx].shortname != NULL
11851 && vim_regexec(regmatch,
11852 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11853 match = TRUE;
11854 else if (is_term_opt)
11855 {
11856 name_buf[0] = '<';
11857 name_buf[1] = 't';
11858 name_buf[2] = '_';
11859 name_buf[3] = str[2];
11860 name_buf[4] = str[3];
11861 name_buf[5] = '>';
11862 name_buf[6] = NUL;
11863 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11864 {
11865 match = TRUE;
11866 str = name_buf;
11867 }
11868 }
11869 if (match)
11870 {
11871 if (loop == 0)
11872 {
11873 if (is_term_opt)
11874 num_term++;
11875 else
11876 num_normal++;
11877 }
11878 else
11879 (*file)[count++] = vim_strsave(str);
11880 }
11881 }
11882 /*
11883 * Check terminal key codes, these are not in the option table
11884 */
11885 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11886 {
11887 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11888 {
11889 if (!isprint(str[0]) || !isprint(str[1]))
11890 continue;
11891
11892 name_buf[0] = 't';
11893 name_buf[1] = '_';
11894 name_buf[2] = str[0];
11895 name_buf[3] = str[1];
11896 name_buf[4] = NUL;
11897
11898 match = FALSE;
11899 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11900 match = TRUE;
11901 else
11902 {
11903 name_buf[0] = '<';
11904 name_buf[1] = 't';
11905 name_buf[2] = '_';
11906 name_buf[3] = str[0];
11907 name_buf[4] = str[1];
11908 name_buf[5] = '>';
11909 name_buf[6] = NUL;
11910
11911 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11912 match = TRUE;
11913 }
11914 if (match)
11915 {
11916 if (loop == 0)
11917 num_term++;
11918 else
11919 (*file)[count++] = vim_strsave(name_buf);
11920 }
11921 }
11922
11923 /*
11924 * Check special key names.
11925 */
11926 regmatch->rm_ic = TRUE; /* ignore case here */
11927 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11928 {
11929 name_buf[0] = '<';
11930 STRCPY(name_buf + 1, str);
11931 STRCAT(name_buf, ">");
11932
11933 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11934 {
11935 if (loop == 0)
11936 num_term++;
11937 else
11938 (*file)[count++] = vim_strsave(name_buf);
11939 }
11940 }
11941 }
11942 if (loop == 0)
11943 {
11944 if (num_normal > 0)
11945 *num_file = num_normal;
11946 else if (num_term > 0)
11947 *num_file = num_term;
11948 else
11949 return OK;
11950 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11951 if (*file == NULL)
11952 {
11953 *file = (char_u **)"";
11954 return FAIL;
11955 }
11956 }
11957 }
11958 return OK;
11959}
11960
11961 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011962ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011963{
11964 char_u *var = NULL; /* init for GCC */
11965 char_u *buf;
11966
11967 *num_file = 0;
11968 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11969 if (*file == NULL)
11970 return FAIL;
11971
11972 /*
11973 * For a terminal key code expand_option_idx is < 0.
11974 */
11975 if (expand_option_idx < 0)
11976 {
11977 var = find_termcode(expand_option_name + 2);
11978 if (var == NULL)
11979 expand_option_idx = findoption(expand_option_name);
11980 }
11981
11982 if (expand_option_idx >= 0)
11983 {
11984 /* put string of option value in NameBuff */
11985 option_value2string(&options[expand_option_idx], expand_option_flags);
11986 var = NameBuff;
11987 }
11988 else if (var == NULL)
11989 var = (char_u *)"";
11990
11991 /* A backslash is required before some characters. This is the reverse of
11992 * what happens in do_set(). */
11993 buf = vim_strsave_escaped(var, escape_chars);
11994
11995 if (buf == NULL)
11996 {
Bram Moolenaard23a8232018-02-10 18:45:26 +010011997 VIM_CLEAR(*file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011998 return FAIL;
11999 }
12000
12001#ifdef BACKSLASH_IN_FILENAME
12002 /* For MS-Windows et al. we don't double backslashes at the start and
12003 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012004 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012005 if (var[0] == '\\' && var[1] == '\\'
12006 && expand_option_idx >= 0
12007 && (options[expand_option_idx].flags & P_EXPAND)
12008 && vim_isfilec(var[2])
12009 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000012010 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012011#endif
12012
12013 *file[0] = buf;
12014 *num_file = 1;
12015 return OK;
12016}
12017#endif
12018
12019/*
12020 * Get the value for the numeric or string option *opp in a nice format into
12021 * NameBuff[]. Must not be called with a hidden option!
12022 */
12023 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012024option_value2string(
12025 struct vimoption *opp,
12026 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012027{
12028 char_u *varp;
12029
12030 varp = get_varp_scope(opp, opt_flags);
12031
12032 if (opp->flags & P_NUM)
12033 {
12034 long wc = 0;
12035
12036 if (wc_use_keyname(varp, &wc))
12037 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
12038 else if (wc != 0)
12039 STRCPY(NameBuff, transchar((int)wc));
12040 else
12041 sprintf((char *)NameBuff, "%ld", *(long *)varp);
12042 }
12043 else /* P_STRING */
12044 {
12045 varp = *(char_u **)(varp);
12046 if (varp == NULL) /* just in case */
12047 NameBuff[0] = NUL;
12048#ifdef FEAT_CRYPT
12049 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000012050 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012051 STRCPY(NameBuff, "*****");
12052#endif
12053 else if (opp->flags & P_EXPAND)
12054 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
12055 /* Translate 'pastetoggle' into special key names */
12056 else if ((char_u **)opp->var == &p_pt)
12057 str2specialbuf(p_pt, NameBuff, MAXPATHL);
12058 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000012059 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012060 }
12061}
12062
12063/*
12064 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
12065 * printed as a keyname.
12066 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
12067 */
12068 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012069wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012070{
12071 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
12072 {
12073 *wcp = *(long *)varp;
12074 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
12075 return TRUE;
12076 }
12077 return FALSE;
12078}
12079
Bram Moolenaar01615492015-02-03 13:00:38 +010012080#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012081/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012082 * Any character has an equivalent 'langmap' character. This is used for
12083 * keyboards that have a special language mode that sends characters above
12084 * 128 (although other characters can be translated too). The "to" field is a
12085 * Vim command character. This avoids having to switch the keyboard back to
12086 * ASCII mode when leaving Insert mode.
12087 *
12088 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
12089 * commands.
Bram Moolenaarfc3abf42019-01-24 15:54:21 +010012090 * langmap_mapga.ga_data is a sorted table of langmap_entry_T. This does the
12091 * same as langmap_mapchar[] for characters >= 256.
12092 *
12093 * Use growarray for 'langmap' chars >= 256
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012094 */
12095typedef struct
12096{
12097 int from;
12098 int to;
12099} langmap_entry_T;
12100
12101static garray_T langmap_mapga;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012102
12103/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012104 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
12105 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012106 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012107 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012108langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012109{
12110 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020012111 int a = 0;
12112 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012113
12114 /* Do a binary search for an existing entry. */
12115 while (a != b)
12116 {
12117 int i = (a + b) / 2;
12118 int d = entries[i].from - from;
12119
12120 if (d == 0)
12121 {
12122 entries[i].to = to;
12123 return;
12124 }
12125 if (d < 0)
12126 a = i + 1;
12127 else
12128 b = i;
12129 }
12130
12131 if (ga_grow(&langmap_mapga, 1) != OK)
12132 return; /* out of memory */
12133
12134 /* insert new entry at position "a" */
12135 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
12136 mch_memmove(entries + 1, entries,
12137 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
12138 ++langmap_mapga.ga_len;
12139 entries[0].from = from;
12140 entries[0].to = to;
12141}
12142
12143/*
12144 * Apply 'langmap' to multi-byte character "c" and return the result.
12145 */
12146 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012147langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012148{
12149 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
12150 int a = 0;
12151 int b = langmap_mapga.ga_len;
12152
12153 while (a != b)
12154 {
12155 int i = (a + b) / 2;
12156 int d = entries[i].from - c;
12157
12158 if (d == 0)
12159 return entries[i].to; /* found matching entry */
12160 if (d < 0)
12161 a = i + 1;
12162 else
12163 b = i;
12164 }
12165 return c; /* no entry found, return "c" unmodified */
12166}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012167
12168 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012169langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012170{
12171 int i;
12172
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012173 for (i = 0; i < 256; i++)
12174 langmap_mapchar[i] = i; /* we init with a one-to-one map */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012175 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012176}
12177
12178/*
12179 * Called when langmap option is set; the language map can be
12180 * changed at any time!
12181 */
12182 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012183langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012184{
12185 char_u *p;
12186 char_u *p2;
12187 int from, to;
12188
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012189 ga_clear(&langmap_mapga); /* clear the previous map first */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012190 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012191
12192 for (p = p_langmap; p[0] != NUL; )
12193 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000012194 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012195 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012196 {
12197 if (p2[0] == '\\' && p2[1] != NUL)
12198 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012199 }
12200 if (p2[0] == ';')
12201 ++p2; /* abcd;ABCD form, p2 points to A */
12202 else
12203 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
12204 while (p[0])
12205 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012206 if (p[0] == ',')
12207 {
12208 ++p;
12209 break;
12210 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012211 if (p[0] == '\\' && p[1] != NUL)
12212 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012213 from = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012214 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012215 if (p2 == NULL)
12216 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012217 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012218 if (p[0] != ',')
12219 {
12220 if (p[0] == '\\')
12221 ++p;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012222 to = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012223 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012224 }
12225 else
12226 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012227 if (p2[0] != ',')
12228 {
12229 if (p2[0] == '\\')
12230 ++p2;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012231 to = (*mb_ptr2char)(p2);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012232 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012233 }
12234 if (to == NUL)
12235 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012236 semsg(_("E357: 'langmap': Matching character missing for %s"),
Bram Moolenaar071d4272004-06-13 20:20:40 +000012237 transchar(from));
12238 return;
12239 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012240
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012241 if (from >= 256)
12242 langmap_set_entry(from, to);
12243 else
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012244 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012245
12246 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012247 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012248 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012249 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012250 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012251 if (*p == ';')
12252 {
12253 p = p2;
12254 if (p[0] != NUL)
12255 {
12256 if (p[0] != ',')
12257 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012258 semsg(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012259 return;
12260 }
12261 ++p;
12262 }
12263 break;
12264 }
12265 }
12266 }
12267 }
12268}
12269#endif
12270
12271/*
12272 * Return TRUE if format option 'x' is in effect.
12273 * Take care of no formatting when 'paste' is set.
12274 */
12275 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012276has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012277{
12278 if (p_paste)
12279 return FALSE;
12280 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12281}
12282
12283/*
12284 * Return TRUE if "x" is present in 'shortmess' option, or
12285 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12286 */
12287 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012288shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012289{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012290 return p_shm != NULL &&
12291 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012292 || (vim_strchr(p_shm, 'a') != NULL
12293 && vim_strchr((char_u *)SHM_A, x) != NULL));
12294}
12295
12296/*
12297 * paste_option_changed() - Called after p_paste was set or reset.
12298 */
12299 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012300paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012301{
12302 static int old_p_paste = FALSE;
12303 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012304 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012305#ifdef FEAT_CMDL_INFO
12306 static int save_ru = 0;
12307#endif
12308#ifdef FEAT_RIGHTLEFT
12309 static int save_ri = 0;
12310 static int save_hkmap = 0;
12311#endif
12312 buf_T *buf;
12313
12314 if (p_paste)
12315 {
12316 /*
12317 * Paste switched from off to on.
12318 * Save the current values, so they can be restored later.
12319 */
12320 if (!old_p_paste)
12321 {
12322 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012323 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012324 {
12325 buf->b_p_tw_nopaste = buf->b_p_tw;
12326 buf->b_p_wm_nopaste = buf->b_p_wm;
12327 buf->b_p_sts_nopaste = buf->b_p_sts;
12328 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012329 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012330#ifdef FEAT_VARTABS
12331 if (buf->b_p_vsts_nopaste)
12332 vim_free(buf->b_p_vsts_nopaste);
12333 buf->b_p_vsts_nopaste = buf->b_p_vsts && buf->b_p_vsts != empty_option
12334 ? vim_strsave(buf->b_p_vsts) : NULL;
12335#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012336 }
12337
12338 /* save global options */
12339 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012340 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012341#ifdef FEAT_CMDL_INFO
12342 save_ru = p_ru;
12343#endif
12344#ifdef FEAT_RIGHTLEFT
12345 save_ri = p_ri;
12346 save_hkmap = p_hkmap;
12347#endif
12348 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012349 p_ai_nopaste = p_ai;
12350 p_et_nopaste = p_et;
12351 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012352 p_tw_nopaste = p_tw;
12353 p_wm_nopaste = p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012354#ifdef FEAT_VARTABS
12355 if (p_vsts_nopaste)
12356 vim_free(p_vsts_nopaste);
12357 p_vsts_nopaste = p_vsts && p_vsts != empty_option ? vim_strsave(p_vsts) : NULL;
12358#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012359 }
12360
12361 /*
12362 * Always set the option values, also when 'paste' is set when it is
12363 * already on.
12364 */
12365 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012366 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012367 {
12368 buf->b_p_tw = 0; /* textwidth is 0 */
12369 buf->b_p_wm = 0; /* wrapmargin is 0 */
12370 buf->b_p_sts = 0; /* softtabstop is 0 */
12371 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012372 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012373#ifdef FEAT_VARTABS
12374 if (buf->b_p_vsts)
12375 free_string_option(buf->b_p_vsts);
12376 buf->b_p_vsts = empty_option;
12377 if (buf->b_p_vsts_array)
12378 vim_free(buf->b_p_vsts_array);
12379 buf->b_p_vsts_array = 0;
12380#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012381 }
12382
12383 /* set global options */
12384 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012385 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012386#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012387 if (p_ru)
12388 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012389 p_ru = 0; /* no ruler */
12390#endif
12391#ifdef FEAT_RIGHTLEFT
12392 p_ri = 0; /* no reverse insert */
12393 p_hkmap = 0; /* no Hebrew keyboard */
12394#endif
12395 /* set global values for local buffer options */
12396 p_tw = 0;
12397 p_wm = 0;
12398 p_sts = 0;
12399 p_ai = 0;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012400#ifdef FEAT_VARTABS
12401 if (p_vsts)
12402 free_string_option(p_vsts);
12403 p_vsts = empty_option;
12404#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012405 }
12406
12407 /*
12408 * Paste switched from on to off: Restore saved values.
12409 */
12410 else if (old_p_paste)
12411 {
12412 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012413 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012414 {
12415 buf->b_p_tw = buf->b_p_tw_nopaste;
12416 buf->b_p_wm = buf->b_p_wm_nopaste;
12417 buf->b_p_sts = buf->b_p_sts_nopaste;
12418 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012419 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012420#ifdef FEAT_VARTABS
12421 if (buf->b_p_vsts)
12422 free_string_option(buf->b_p_vsts);
12423 buf->b_p_vsts = buf->b_p_vsts_nopaste
12424 ? vim_strsave(buf->b_p_vsts_nopaste) : empty_option;
12425 if (buf->b_p_vsts_array)
12426 vim_free(buf->b_p_vsts_array);
12427 if (buf->b_p_vsts && buf->b_p_vsts != empty_option)
12428 tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array);
12429 else
12430 buf->b_p_vsts_array = 0;
12431#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012432 }
12433
12434 /* restore global options */
12435 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012436 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012437#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012438 if (p_ru != save_ru)
12439 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012440 p_ru = save_ru;
12441#endif
12442#ifdef FEAT_RIGHTLEFT
12443 p_ri = save_ri;
12444 p_hkmap = save_hkmap;
12445#endif
12446 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012447 p_ai = p_ai_nopaste;
12448 p_et = p_et_nopaste;
12449 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012450 p_tw = p_tw_nopaste;
12451 p_wm = p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012452#ifdef FEAT_VARTABS
12453 if (p_vsts)
12454 free_string_option(p_vsts);
12455 p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option;
12456#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012457 }
12458
12459 old_p_paste = p_paste;
12460}
12461
12462/*
12463 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12464 *
12465 * Reset 'compatible' and set the values for options that didn't get set yet
12466 * to the Vim defaults.
12467 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012468 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012469 */
12470 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012471vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012472{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012473 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012474 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012475 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012476
12477 if (!option_was_set((char_u *)"cp"))
12478 {
12479 p_cp = FALSE;
12480 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12481 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12482 set_option_default(opt_idx, OPT_FREE, FALSE);
12483 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012484 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012485 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012486
12487 if (fname != NULL)
12488 {
12489 p = vim_getenv(envname, &dofree);
12490 if (p == NULL)
12491 {
12492 /* Set $MYVIMRC to the first vimrc file found. */
12493 p = FullName_save(fname, FALSE);
12494 if (p != NULL)
12495 {
12496 vim_setenv(envname, p);
12497 vim_free(p);
12498 }
12499 }
12500 else if (dofree)
12501 vim_free(p);
12502 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012503}
12504
12505/*
12506 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12507 */
12508 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012509change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012510{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012511 int opt_idx;
12512
Bram Moolenaar071d4272004-06-13 20:20:40 +000012513 if (p_cp != on)
12514 {
12515 p_cp = on;
12516 compatible_set();
12517 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012518 opt_idx = findoption((char_u *)"cp");
12519 if (opt_idx >= 0)
12520 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012521}
12522
12523/*
12524 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012525 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012526 */
12527 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012528option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012529{
12530 int idx;
12531
12532 idx = findoption(name);
12533 if (idx < 0) /* unknown option */
12534 return FALSE;
12535 if (options[idx].flags & P_WAS_SET)
12536 return TRUE;
12537 return FALSE;
12538}
12539
12540/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012541 * Reset the flag indicating option "name" was set.
12542 */
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012543 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012544reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012545{
12546 int idx = findoption(name);
12547
12548 if (idx >= 0)
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012549 {
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012550 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012551 return OK;
12552 }
12553 return FAIL;
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012554}
12555
12556/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012557 * compatible_set() - Called when 'compatible' has been set or unset.
12558 *
12559 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12560 * flag) to a Vi compatible value.
12561 * When 'compatible' is unset: Set all options that have a different default
12562 * for Vim (without the P_VI_DEF flag) to that default.
12563 */
12564 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012565compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012566{
12567 int opt_idx;
12568
12569 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12570 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12571 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12572 set_option_default(opt_idx, OPT_FREE, p_cp);
12573 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012574 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012575}
12576
12577#ifdef FEAT_LINEBREAK
12578
12579# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12580 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012581 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012582# endif
12583
12584/*
12585 * fill_breakat_flags() -- called when 'breakat' changes value.
12586 */
12587 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012588fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012589{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012590 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012591 int i;
12592
12593 for (i = 0; i < 256; i++)
12594 breakat_flags[i] = FALSE;
12595
12596 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012597 for (p = p_breakat; *p; p++)
12598 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012599}
12600
12601# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012602 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012603# endif
12604
12605#endif
12606
12607/*
12608 * Check an option that can be a range of string values.
12609 *
12610 * Return OK for correct value, FAIL otherwise.
12611 * Empty is always OK.
12612 */
12613 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012614check_opt_strings(
12615 char_u *val,
12616 char **values,
12617 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012618{
12619 return opt_strings_flags(val, values, NULL, list);
12620}
12621
12622/*
12623 * Handle an option that can be a range of string values.
12624 * Set a flag in "*flagp" for each string present.
12625 *
12626 * Return OK for correct value, FAIL otherwise.
12627 * Empty is always OK.
12628 */
12629 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012630opt_strings_flags(
12631 char_u *val, /* new value */
12632 char **values, /* array of valid string values */
12633 unsigned *flagp,
12634 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012635{
12636 int i;
12637 int len;
12638 unsigned new_flags = 0;
12639
12640 while (*val)
12641 {
12642 for (i = 0; ; ++i)
12643 {
12644 if (values[i] == NULL) /* val not found in values[] */
12645 return FAIL;
12646
12647 len = (int)STRLEN(values[i]);
12648 if (STRNCMP(values[i], val, len) == 0
12649 && ((list && val[len] == ',') || val[len] == NUL))
12650 {
12651 val += len + (val[len] == ',');
12652 new_flags |= (1 << i);
12653 break; /* check next item in val list */
12654 }
12655 }
12656 }
12657 if (flagp != NULL)
12658 *flagp = new_flags;
12659
12660 return OK;
12661}
12662
12663/*
12664 * Read the 'wildmode' option, fill wim_flags[].
12665 */
12666 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012667check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012668{
12669 char_u new_wim_flags[4];
12670 char_u *p;
12671 int i;
12672 int idx = 0;
12673
12674 for (i = 0; i < 4; ++i)
12675 new_wim_flags[i] = 0;
12676
12677 for (p = p_wim; *p; ++p)
12678 {
12679 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12680 ;
12681 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12682 return FAIL;
12683 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12684 new_wim_flags[idx] |= WIM_LONGEST;
12685 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12686 new_wim_flags[idx] |= WIM_FULL;
12687 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12688 new_wim_flags[idx] |= WIM_LIST;
12689 else
12690 return FAIL;
12691 p += i;
12692 if (*p == NUL)
12693 break;
12694 if (*p == ',')
12695 {
12696 if (idx == 3)
12697 return FAIL;
12698 ++idx;
12699 }
12700 }
12701
12702 /* fill remaining entries with last flag */
12703 while (idx < 3)
12704 {
12705 new_wim_flags[idx + 1] = new_wim_flags[idx];
12706 ++idx;
12707 }
12708
12709 /* only when there are no errors, wim_flags[] is changed */
12710 for (i = 0; i < 4; ++i)
12711 wim_flags[i] = new_wim_flags[i];
12712 return OK;
12713}
12714
12715/*
12716 * Check if backspacing over something is allowed.
12717 */
12718 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012719can_bs(
12720 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012721{
Bram Moolenaar6b810d92018-06-04 17:28:44 +020012722#ifdef FEAT_JOB_CHANNEL
12723 if (what == BS_START && bt_prompt(curbuf))
12724 return FALSE;
12725#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012726 switch (*p_bs)
12727 {
12728 case '2': return TRUE;
12729 case '1': return (what != BS_START);
12730 case '0': return FALSE;
12731 }
12732 return vim_strchr(p_bs, what) != NULL;
12733}
12734
12735/*
12736 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12737 * the file must be considered changed when the value is different.
12738 */
12739 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012740save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012741{
12742 buf->b_start_ffc = *buf->b_p_ff;
12743 buf->b_start_eol = buf->b_p_eol;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012744 buf->b_start_bomb = buf->b_p_bomb;
12745
Bram Moolenaar071d4272004-06-13 20:20:40 +000012746 /* Only use free/alloc when necessary, they take time. */
12747 if (buf->b_start_fenc == NULL
12748 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12749 {
12750 vim_free(buf->b_start_fenc);
12751 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12752 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012753}
12754
12755/*
12756 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12757 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012758 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12759 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012760 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012761 * When "ignore_empty" is true don't consider a new, empty buffer to be
12762 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012763 */
12764 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012765file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012766{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012767 /* In a buffer that was never loaded the options are not valid. */
12768 if (buf->b_flags & BF_NEVERLOADED)
12769 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012770 if (ignore_empty
12771 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012772 && buf->b_ml.ml_line_count == 1
12773 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12774 return FALSE;
12775 if (buf->b_start_ffc != *buf->b_p_ff)
12776 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012777 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012778 return TRUE;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012779 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12780 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012781 if (buf->b_start_fenc == NULL)
12782 return (*buf->b_p_fenc != NUL);
12783 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012784}
12785
12786/*
12787 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12788 */
12789 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012790check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012791{
12792 return check_opt_strings(p, p_ff_values, FALSE);
12793}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012794
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012795#ifdef FEAT_VARTABS
12796
12797/*
12798 * Set the integer values corresponding to the string setting of 'vartabstop'.
12799 */
12800 int
12801tabstop_set(char_u *var, int **array)
12802{
12803 int valcount = 1;
12804 int t;
12805 char_u *cp;
12806
Bram Moolenaar64f41072018-10-15 22:51:50 +020012807 if (var[0] == NUL || (var[0] == '0' && var[1] == NUL))
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012808 {
12809 *array = NULL;
12810 return TRUE;
12811 }
12812
Bram Moolenaar64f41072018-10-15 22:51:50 +020012813 for (cp = var; *cp != NUL; ++cp)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012814 {
Bram Moolenaar64f41072018-10-15 22:51:50 +020012815 if (cp == var || cp[-1] == ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012816 {
12817 char_u *end;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012818
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012819 if (strtol((char *)cp, (char **)&end, 10) <= 0)
12820 {
12821 if (cp != end)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012822 emsg(_(e_positive));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012823 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012824 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012825 return FALSE;
12826 }
12827 }
12828
12829 if (VIM_ISDIGIT(*cp))
12830 continue;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012831 if (cp[0] == ',' && cp > var && cp[-1] != ',' && cp[1] != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012832 {
12833 ++valcount;
12834 continue;
12835 }
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012836 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012837 return FALSE;
12838 }
12839
Bram Moolenaar64f41072018-10-15 22:51:50 +020012840 *array = (int *)alloc((unsigned) ((valcount + 1) * sizeof(int)));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012841 (*array)[0] = valcount;
12842
12843 t = 1;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012844 for (cp = var; *cp != NUL;)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012845 {
12846 (*array)[t++] = atoi((char *)cp);
Bram Moolenaar64f41072018-10-15 22:51:50 +020012847 while (*cp != NUL && *cp != ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012848 ++cp;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012849 if (*cp != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012850 ++cp;
12851 }
12852
12853 return TRUE;
12854}
12855
12856/*
12857 * Calculate the number of screen spaces a tab will occupy.
12858 * If "vts" is set then the tab widths are taken from that array,
12859 * otherwise the value of ts is used.
12860 */
12861 int
12862tabstop_padding(colnr_T col, int ts_arg, int *vts)
12863{
12864 int ts = ts_arg == 0 ? 8 : ts_arg;
12865 int tabcount;
12866 colnr_T tabcol = 0;
12867 int t;
12868 int padding = 0;
12869
12870 if (vts == NULL || vts[0] == 0)
12871 return ts - (col % ts);
12872
12873 tabcount = vts[0];
12874
12875 for (t = 1; t <= tabcount; ++t)
12876 {
12877 tabcol += vts[t];
12878 if (tabcol > col)
12879 {
12880 padding = (int)(tabcol - col);
12881 break;
12882 }
12883 }
12884 if (t > tabcount)
12885 padding = vts[tabcount] - (int)((col - tabcol) % vts[tabcount]);
12886
12887 return padding;
12888}
12889
12890/*
12891 * Find the size of the tab that covers a particular column.
12892 */
12893 int
12894tabstop_at(colnr_T col, int ts, int *vts)
12895{
12896 int tabcount;
12897 colnr_T tabcol = 0;
12898 int t;
12899 int tab_size = 0;
12900
12901 if (vts == 0 || vts[0] == 0)
12902 return ts;
12903
12904 tabcount = vts[0];
12905 for (t = 1; t <= tabcount; ++t)
12906 {
12907 tabcol += vts[t];
12908 if (tabcol > col)
12909 {
12910 tab_size = vts[t];
12911 break;
12912 }
12913 }
12914 if (t > tabcount)
12915 tab_size = vts[tabcount];
12916
12917 return tab_size;
12918}
12919
12920/*
12921 * Find the column on which a tab starts.
12922 */
12923 colnr_T
12924tabstop_start(colnr_T col, int ts, int *vts)
12925{
12926 int tabcount;
12927 colnr_T tabcol = 0;
12928 int t;
12929 int excess;
12930
Bram Moolenaar0119a592018-06-24 23:53:28 +020012931 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012932 return (col / ts) * ts;
12933
12934 tabcount = vts[0];
12935 for (t = 1; t <= tabcount; ++t)
12936 {
12937 tabcol += vts[t];
12938 if (tabcol > col)
12939 return tabcol - vts[t];
12940 }
12941
12942 excess = tabcol % vts[tabcount];
12943 return excess + ((col - excess) / vts[tabcount]) * vts[tabcount];
12944}
12945
12946/*
12947 * Find the number of tabs and spaces necessary to get from one column
12948 * to another.
12949 */
12950 void
12951tabstop_fromto(
12952 colnr_T start_col,
12953 colnr_T end_col,
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012954 int ts_arg,
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012955 int *vts,
12956 int *ntabs,
12957 int *nspcs)
12958{
12959 int spaces = end_col - start_col;
12960 colnr_T tabcol = 0;
12961 int padding = 0;
12962 int tabcount;
12963 int t;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012964 int ts = ts_arg == 0 ? curbuf->b_p_ts : ts_arg;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012965
Bram Moolenaar0119a592018-06-24 23:53:28 +020012966 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012967 {
12968 int tabs = 0;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012969 int initspc = 0;
Bram Moolenaar0119a592018-06-24 23:53:28 +020012970
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012971 initspc = ts - (start_col % ts);
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012972 if (spaces >= initspc)
12973 {
12974 spaces -= initspc;
12975 tabs++;
12976 }
12977 tabs += spaces / ts;
12978 spaces -= (spaces / ts) * ts;
12979
12980 *ntabs = tabs;
12981 *nspcs = spaces;
12982 return;
12983 }
12984
12985 /* Find the padding needed to reach the next tabstop. */
12986 tabcount = vts[0];
12987 for (t = 1; t <= tabcount; ++t)
12988 {
12989 tabcol += vts[t];
12990 if (tabcol > start_col)
12991 {
12992 padding = (int)(tabcol - start_col);
12993 break;
12994 }
12995 }
12996 if (t > tabcount)
12997 padding = vts[tabcount] - (int)((start_col - tabcol) % vts[tabcount]);
12998
12999 /* If the space needed is less than the padding no tabs can be used. */
13000 if (spaces < padding)
13001 {
13002 *ntabs = 0;
13003 *nspcs = spaces;
13004 return;
13005 }
13006
13007 *ntabs = 1;
13008 spaces -= padding;
13009
13010 /* At least one tab has been used. See if any more will fit. */
13011 while (spaces != 0 && ++t <= tabcount)
13012 {
13013 padding = vts[t];
13014 if (spaces < padding)
13015 {
13016 *nspcs = spaces;
13017 return;
13018 }
13019 ++*ntabs;
13020 spaces -= padding;
13021 }
13022
13023 *ntabs += spaces / vts[tabcount];
13024 *nspcs = spaces % vts[tabcount];
13025}
13026
13027/*
13028 * See if two tabstop arrays contain the same values.
13029 */
13030 int
13031tabstop_eq(int *ts1, int *ts2)
13032{
13033 int t;
13034
13035 if ((ts1 == 0 && ts2) || (ts1 && ts2 == 0))
13036 return FALSE;
13037 if (ts1 == ts2)
13038 return TRUE;
13039 if (ts1[0] != ts2[0])
13040 return FALSE;
13041
13042 for (t = 1; t <= ts1[0]; ++t)
13043 if (ts1[t] != ts2[t])
13044 return FALSE;
13045
13046 return TRUE;
13047}
13048
Bram Moolenaar113e1072019-01-20 15:30:40 +010013049#if defined(FEAT_BEVAL) || defined(PROTO)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013050/*
13051 * Copy a tabstop array, allocating space for the new array.
13052 */
13053 int *
13054tabstop_copy(int *oldts)
13055{
13056 int *newts;
13057 int t;
13058
13059 if (oldts == 0)
13060 return 0;
13061
13062 newts = (int *) alloc((unsigned) ((oldts[0] + 1) * sizeof(int)));
13063 for (t = 0; t <= oldts[0]; ++t)
13064 newts[t] = oldts[t];
13065
13066 return newts;
13067}
Bram Moolenaar113e1072019-01-20 15:30:40 +010013068#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013069
13070/*
13071 * Return a count of the number of tabstops.
13072 */
13073 int
13074tabstop_count(int *ts)
13075{
13076 return ts != NULL ? ts[0] : 0;
13077}
13078
13079/*
13080 * Return the first tabstop, or 8 if there are no tabstops defined.
13081 */
13082 int
13083tabstop_first(int *ts)
13084{
13085 return ts != NULL ? ts[1] : 8;
13086}
13087
13088#endif
13089
Bram Moolenaar14f24742012-08-08 18:01:05 +020013090/*
13091 * Return the effective shiftwidth value for current buffer, using the
13092 * 'tabstop' value when 'shiftwidth' is zero.
13093 */
13094 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013095get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020013096{
Bram Moolenaarf9514162018-11-22 03:08:29 +010013097 return get_sw_value_col(buf, 0);
13098}
13099
13100/*
13101 * Idem, using the first non-black in the current line.
13102 */
13103 long
13104get_sw_value_indent(buf_T *buf)
13105{
13106 pos_T pos = curwin->w_cursor;
13107
13108 pos.col = getwhitecols_curline();
13109 return get_sw_value_pos(buf, &pos);
13110}
13111
13112/*
13113 * Idem, using "pos".
13114 */
13115 long
13116get_sw_value_pos(buf_T *buf, pos_T *pos)
13117{
13118 pos_T save_cursor = curwin->w_cursor;
13119 long sw_value;
13120
13121 curwin->w_cursor = *pos;
13122 sw_value = get_sw_value_col(buf, get_nolist_virtcol());
13123 curwin->w_cursor = save_cursor;
13124 return sw_value;
13125}
13126
13127/*
13128 * Idem, using virtual column "col".
13129 */
13130 long
13131get_sw_value_col(buf_T *buf, colnr_T col UNUSED)
13132{
13133 return buf->b_p_sw ? buf->b_p_sw :
13134 #ifdef FEAT_VARTABS
13135 tabstop_at(col, buf->b_p_ts, buf->b_p_vts_array);
13136 #else
13137 buf->b_p_ts;
13138 #endif
Bram Moolenaar14f24742012-08-08 18:01:05 +020013139}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013140
13141/*
13142 * Return the effective softtabstop value for the current buffer, using the
Bram Moolenaar33d5ab32018-07-02 20:51:24 +020013143 * 'shiftwidth' value when 'softtabstop' is negative.
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013144 */
13145 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013146get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013147{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010013148 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013149}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013150
13151/*
Bram Moolenaar375e3392019-01-31 18:26:10 +010013152 * Return the effective 'scrolloff' value for the current window, using the
13153 * global value when appropriate.
13154 */
13155 long
13156get_scrolloff_value(void)
13157{
13158 return curwin->w_p_so < 0 ? p_so : curwin->w_p_so;
13159}
13160
13161/*
13162 * Return the effective 'sidescrolloff' value for the current window, using the
13163 * global value when appropriate.
13164 */
13165 long
13166get_sidescrolloff_value(void)
13167{
13168 return curwin->w_p_siso < 0 ? p_siso : curwin->w_p_siso;
13169}
13170
13171/*
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013172 * Check matchpairs option for "*initc".
13173 * If there is a match set "*initc" to the matching character and "*findc" to
13174 * the opposite character. Set "*backwards" to the direction.
13175 * When "switchit" is TRUE swap the direction.
13176 */
13177 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010013178find_mps_values(
13179 int *initc,
13180 int *findc,
13181 int *backwards,
13182 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013183{
13184 char_u *ptr;
13185
13186 ptr = curbuf->b_p_mps;
13187 while (*ptr != NUL)
13188 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013189 if (has_mbyte)
13190 {
13191 char_u *prev;
13192
13193 if (mb_ptr2char(ptr) == *initc)
13194 {
13195 if (switchit)
13196 {
13197 *findc = *initc;
13198 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13199 *backwards = TRUE;
13200 }
13201 else
13202 {
13203 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13204 *backwards = FALSE;
13205 }
13206 return;
13207 }
13208 prev = ptr;
13209 ptr += mb_ptr2len(ptr) + 1;
13210 if (mb_ptr2char(ptr) == *initc)
13211 {
13212 if (switchit)
13213 {
13214 *findc = *initc;
13215 *initc = mb_ptr2char(prev);
13216 *backwards = FALSE;
13217 }
13218 else
13219 {
13220 *findc = mb_ptr2char(prev);
13221 *backwards = TRUE;
13222 }
13223 return;
13224 }
13225 ptr += mb_ptr2len(ptr);
13226 }
13227 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013228 {
13229 if (*ptr == *initc)
13230 {
13231 if (switchit)
13232 {
13233 *backwards = TRUE;
13234 *findc = *initc;
13235 *initc = ptr[2];
13236 }
13237 else
13238 {
13239 *backwards = FALSE;
13240 *findc = ptr[2];
13241 }
13242 return;
13243 }
13244 ptr += 2;
13245 if (*ptr == *initc)
13246 {
13247 if (switchit)
13248 {
13249 *backwards = FALSE;
13250 *findc = *initc;
13251 *initc = ptr[-2];
13252 }
13253 else
13254 {
13255 *backwards = TRUE;
13256 *findc = ptr[-2];
13257 }
13258 return;
13259 }
13260 ++ptr;
13261 }
13262 if (*ptr == ',')
13263 ++ptr;
13264 }
13265}
Bram Moolenaar597a4222014-06-25 14:39:50 +020013266
13267#if defined(FEAT_LINEBREAK) || defined(PROTO)
13268/*
13269 * This is called when 'breakindentopt' is changed and when a window is
13270 * initialized.
13271 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013272 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013273briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020013274{
13275 char_u *p;
13276 int bri_shift = 0;
13277 long bri_min = 20;
13278 int bri_sbr = FALSE;
13279
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013280 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013281 while (*p != NUL)
13282 {
13283 if (STRNCMP(p, "shift:", 6) == 0
13284 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
13285 {
13286 p += 6;
13287 bri_shift = getdigits(&p);
13288 }
13289 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
13290 {
13291 p += 4;
13292 bri_min = getdigits(&p);
13293 }
13294 else if (STRNCMP(p, "sbr", 3) == 0)
13295 {
13296 p += 3;
13297 bri_sbr = TRUE;
13298 }
13299 if (*p != ',' && *p != NUL)
13300 return FAIL;
13301 if (*p == ',')
13302 ++p;
13303 }
13304
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013305 wp->w_p_brishift = bri_shift;
13306 wp->w_p_brimin = bri_min;
13307 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013308
13309 return OK;
13310}
13311#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013312
13313/*
13314 * Get the local or global value of 'backupcopy'.
13315 */
13316 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013317get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013318{
13319 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
13320}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020013321
13322#if defined(FEAT_SIGNS) || defined(PROTO)
13323/*
13324 * Return TRUE when window "wp" has a column to draw signs in.
13325 */
13326 int
13327signcolumn_on(win_T *wp)
13328{
13329 if (*wp->w_p_scl == 'n')
13330 return FALSE;
13331 if (*wp->w_p_scl == 'y')
13332 return TRUE;
13333 return (wp->w_buffer->b_signlist != NULL
13334# ifdef FEAT_NETBEANS_INTG
13335 || wp->w_buffer->b_has_sign_column
13336# endif
13337 );
13338}
13339#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013340
13341#if defined(FEAT_EVAL) || defined(PROTO)
13342/*
13343 * Get window or buffer local options.
13344 */
13345 dict_T *
13346get_winbuf_options(int bufopt)
13347{
13348 dict_T *d;
13349 int opt_idx;
13350
13351 d = dict_alloc();
13352 if (d == NULL)
13353 return NULL;
13354
13355 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
13356 {
13357 struct vimoption *opt = &options[opt_idx];
13358
13359 if ((bufopt && (opt->indir & PV_BUF))
13360 || (!bufopt && (opt->indir & PV_WIN)))
13361 {
13362 char_u *varp = get_varp(opt);
13363
13364 if (varp != NULL)
13365 {
13366 if (opt->flags & P_STRING)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013367 dict_add_string(d, opt->fullname, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020013368 else if (opt->flags & P_NUM)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013369 dict_add_number(d, opt->fullname, *(long *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013370 else
Bram Moolenaare0be1672018-07-08 16:50:37 +020013371 dict_add_number(d, opt->fullname, *(int *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013372 }
13373 }
13374 }
13375
13376 return d;
13377}
13378#endif