blob: 2d4803e76f4edc37fe23b6327961930111040072 [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
Bram Moolenaarac3150d2019-07-28 16:36:39 +020091#define PV_CSL OPT_BUF(BV_CSL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000092#ifdef FEAT_COMPL_FUNC
93# define PV_CFU OPT_BUF(BV_CFU)
94#endif
95#ifdef FEAT_FIND_ID
96# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
97# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
98#endif
99#define PV_EOL OPT_BUF(BV_EOL)
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200100#define PV_FIXEOL OPT_BUF(BV_FIXEOL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000101#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
102#define PV_ET OPT_BUF(BV_ET)
Bram Moolenaarfc3abf42019-01-24 15:54:21 +0100103#define PV_FENC OPT_BUF(BV_FENC)
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000104#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
105# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
106#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100107#define PV_FP OPT_BOTH(OPT_BUF(BV_FP))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000108#ifdef FEAT_EVAL
109# define PV_FEX OPT_BUF(BV_FEX)
110#endif
111#define PV_FF OPT_BUF(BV_FF)
112#define PV_FLP OPT_BUF(BV_FLP)
113#define PV_FO OPT_BUF(BV_FO)
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +0100114#define PV_FT OPT_BUF(BV_FT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000115#define PV_IMI OPT_BUF(BV_IMI)
116#define PV_IMS OPT_BUF(BV_IMS)
117#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
118# define PV_INDE OPT_BUF(BV_INDE)
119# define PV_INDK OPT_BUF(BV_INDK)
120#endif
121#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
122# define PV_INEX OPT_BUF(BV_INEX)
123#endif
124#define PV_INF OPT_BUF(BV_INF)
125#define PV_ISK OPT_BUF(BV_ISK)
126#ifdef FEAT_CRYPT
127# define PV_KEY OPT_BUF(BV_KEY)
128#endif
129#ifdef FEAT_KEYMAP
130# define PV_KMAP OPT_BUF(BV_KMAP)
131#endif
132#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
133#ifdef FEAT_LISP
134# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100135# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000136#endif
Bram Moolenaarfc3abf42019-01-24 15:54:21 +0100137#define PV_MENC OPT_BOTH(OPT_BUF(BV_MENC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000138#define PV_MA OPT_BUF(BV_MA)
139#define PV_ML OPT_BUF(BV_ML)
140#define PV_MOD OPT_BUF(BV_MOD)
141#define PV_MPS OPT_BUF(BV_MPS)
142#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000143#ifdef FEAT_COMPL_FUNC
144# define PV_OFU OPT_BUF(BV_OFU)
145#endif
146#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
147#define PV_PI OPT_BUF(BV_PI)
148#ifdef FEAT_TEXTOBJ
149# define PV_QE OPT_BUF(BV_QE)
150#endif
151#define PV_RO OPT_BUF(BV_RO)
152#ifdef FEAT_SMARTINDENT
153# define PV_SI OPT_BUF(BV_SI)
154#endif
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100155#define PV_SN OPT_BUF(BV_SN)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000156#ifdef FEAT_SYN_HL
157# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000158# define PV_SYN OPT_BUF(BV_SYN)
159#endif
160#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000161# define PV_SPC OPT_BUF(BV_SPC)
162# define PV_SPF OPT_BUF(BV_SPF)
163# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000164#endif
165#define PV_STS OPT_BUF(BV_STS)
166#ifdef FEAT_SEARCHPATH
167# define PV_SUA OPT_BUF(BV_SUA)
168#endif
169#define PV_SW OPT_BUF(BV_SW)
170#define PV_SWF OPT_BUF(BV_SWF)
Bram Moolenaar45e18cb2019-04-28 18:05:35 +0200171#ifdef FEAT_EVAL
172# define PV_TFU OPT_BUF(BV_TFU)
173#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000174#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
Bram Moolenaar0f6562e2015-11-24 18:48:14 +0100175#define PV_TC OPT_BOTH(OPT_BUF(BV_TC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000176#define PV_TS OPT_BUF(BV_TS)
177#define PV_TW OPT_BUF(BV_TW)
178#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200179#ifdef FEAT_PERSISTENT_UNDO
180# define PV_UDF OPT_BUF(BV_UDF)
181#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000182#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200183#ifdef FEAT_VARTABS
184# define PV_VSTS OPT_BUF(BV_VSTS)
185# define PV_VTS OPT_BUF(BV_VTS)
186#endif
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000187
188/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000189 * Definition of the PV_ values for window-local options.
190 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000191 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000192#define PV_LIST OPT_WIN(WV_LIST)
193#ifdef FEAT_ARABIC
194# define PV_ARAB OPT_WIN(WV_ARAB)
195#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200196#ifdef FEAT_LINEBREAK
197# define PV_BRI OPT_WIN(WV_BRI)
198# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
199#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200200# define PV_WCR OPT_WIN(WV_WCR)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000201#ifdef FEAT_DIFF
202# define PV_DIFF OPT_WIN(WV_DIFF)
203#endif
204#ifdef FEAT_FOLDING
205# define PV_FDC OPT_WIN(WV_FDC)
206# define PV_FEN OPT_WIN(WV_FEN)
207# define PV_FDI OPT_WIN(WV_FDI)
208# define PV_FDL OPT_WIN(WV_FDL)
209# define PV_FDM OPT_WIN(WV_FDM)
210# define PV_FML OPT_WIN(WV_FML)
211# define PV_FDN OPT_WIN(WV_FDN)
212# ifdef FEAT_EVAL
213# define PV_FDE OPT_WIN(WV_FDE)
214# define PV_FDT OPT_WIN(WV_FDT)
215# endif
216# define PV_FMR OPT_WIN(WV_FMR)
217#endif
218#ifdef FEAT_LINEBREAK
219# define PV_LBR OPT_WIN(WV_LBR)
220#endif
221#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200222#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000223#ifdef FEAT_LINEBREAK
224# define PV_NUW OPT_WIN(WV_NUW)
225#endif
Bram Moolenaar4033c552017-09-16 20:54:51 +0200226#if defined(FEAT_QUICKFIX)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000227# define PV_PVW OPT_WIN(WV_PVW)
228#endif
229#ifdef FEAT_RIGHTLEFT
230# define PV_RL OPT_WIN(WV_RL)
231# define PV_RLC OPT_WIN(WV_RLC)
232#endif
Bram Moolenaar8a3bb562018-03-04 20:14:14 +0100233#define PV_SCBIND OPT_WIN(WV_SCBIND)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000234#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaar375e3392019-01-31 18:26:10 +0100235#define PV_SISO OPT_BOTH(OPT_WIN(WV_SISO))
236#define PV_SO OPT_BOTH(OPT_WIN(WV_SO))
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000237#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000238# define PV_SPELL OPT_WIN(WV_SPELL)
239#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000240#ifdef FEAT_SYN_HL
241# define PV_CUC OPT_WIN(WV_CUC)
242# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200243# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000244#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000245#ifdef FEAT_STL_OPT
246# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
247#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100248#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000249# define PV_WFH OPT_WIN(WV_WFH)
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000250# define PV_WFW OPT_WIN(WV_WFW)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000251#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar8a3bb562018-03-04 20:14:14 +0100252#define PV_CRBIND OPT_WIN(WV_CRBIND)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200253#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200254# define PV_COCU OPT_WIN(WV_COCU)
255# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200256#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200257#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200258# define PV_TWK OPT_WIN(WV_TWK)
259# define PV_TWS OPT_WIN(WV_TWS)
260# define PV_TWSL OPT_BUF(BV_TWSL)
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200261#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200262#ifdef FEAT_SIGNS
263# define PV_SCL OPT_WIN(WV_SCL)
264#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000265
266/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000267typedef enum
268{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000269 PV_NONE = 0,
270 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000271} idopt_T;
272
273/*
274 * Options local to a window have a value local to a buffer and global to all
275 * buffers. Indicate this by setting "var" to VAR_WIN.
276 */
277#define VAR_WIN ((char_u *)-1)
278
279/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000280 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000281 * Only to be used in option.c!
282 */
283static int p_ai;
284static int p_bin;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000285static int p_bomb;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000286static char_u *p_bh;
287static char_u *p_bt;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000288static int p_bl;
289static int p_ci;
290#ifdef FEAT_CINDENT
291static int p_cin;
292static char_u *p_cink;
293static char_u *p_cino;
294#endif
295#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
296static char_u *p_cinw;
297#endif
298#ifdef FEAT_COMMENTS
299static char_u *p_com;
300#endif
301#ifdef FEAT_FOLDING
302static char_u *p_cms;
303#endif
304#ifdef FEAT_INS_EXPAND
305static char_u *p_cpt;
306#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000307#ifdef FEAT_COMPL_FUNC
308static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000309static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000310#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +0200311#ifdef FEAT_EVAL
312static char_u *p_tfu;
313#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000314static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200315static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000316static int p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000317static char_u *p_fenc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000318static char_u *p_ff;
319static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000320static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000321static char_u *p_ft;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000322static long p_iminsert;
323static long p_imsearch;
324#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
325static char_u *p_inex;
326#endif
327#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
328static char_u *p_inde;
329static char_u *p_indk;
330#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000331#if defined(FEAT_EVAL)
332static char_u *p_fex;
333#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000334static int p_inf;
335static char_u *p_isk;
336#ifdef FEAT_CRYPT
337static char_u *p_key;
338#endif
339#ifdef FEAT_LISP
340static int p_lisp;
341#endif
342static int p_ml;
343static int p_ma;
344static int p_mod;
345static char_u *p_mps;
346static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000347static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000348#ifdef FEAT_TEXTOBJ
349static char_u *p_qe;
350#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000351static int p_ro;
352#ifdef FEAT_SMARTINDENT
353static int p_si;
354#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000355static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000356static long p_sts;
357#if defined(FEAT_SEARCHPATH)
358static char_u *p_sua;
359#endif
360static long p_sw;
361static int p_swf;
362#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000363static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000364static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000365#endif
366#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000367static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000368static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000369static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000370#endif
371static long p_ts;
372static long p_tw;
373static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200374#ifdef FEAT_PERSISTENT_UNDO
375static int p_udf;
376#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000377static long p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200378#ifdef FEAT_VARTABS
379static char_u *p_vsts;
380static char_u *p_vts;
381#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000382#ifdef FEAT_KEYMAP
383static char_u *p_keymap;
384#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200385#ifdef FEAT_TERMINAL
Bram Moolenaarb833c1e2018-05-05 16:36:06 +0200386static long p_twsl; /* 'termwinscroll' */
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200387#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000388
389/* Saved values for when 'bin' is set. */
390static int p_et_nobin;
391static int p_ml_nobin;
392static long p_tw_nobin;
393static long p_wm_nobin;
394
395/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200396static int p_ai_nopaste;
397static int p_et_nopaste;
398static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000399static long p_tw_nopaste;
400static long p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200401#ifdef FEAT_VARTABS
402static char_u *p_vsts_nopaste;
403#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000404
405struct vimoption
406{
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200407 char *fullname; // full option name
408 char *shortname; // permissible abbreviation
409 long_u flags; // see below
410 char_u *var; // global option: pointer to variable;
411 // window-local option: VAR_WIN;
412 // buffer-local option: global value
413 idopt_T indir; // global option: PV_NONE;
414 // local option: indirect option index
415 char_u *def_val[2]; // default values for variable (vi and vim)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000416#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200417 sctx_T script_ctx; // script context where the option was last set
Bram Moolenaar558ca4a2019-04-04 18:15:38 +0200418# define SCTX_INIT , {0, 0, 0, 1}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000419#else
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200420# define SCTX_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000421#endif
422};
423
424#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
425#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
426
427/*
428 * Flags
429 */
430#define P_BOOL 0x01 /* the option is boolean */
431#define P_NUM 0x02 /* the option is numeric */
432#define P_STRING 0x04 /* the option is a string */
433#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000434 must use free_string_option() when
435 assigning new value. Not set if default is
436 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000437#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
438 never be used for local or hidden options! */
439#define P_NODEFAULT 0x40 /* don't set to default value */
440#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
441 use vim_free() when assigning new value */
442#define P_WAS_SET 0x100 /* option has been set/reset */
443#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
444#define P_VI_DEF 0x400 /* Use Vi default for Vim */
445#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
446
447 /* when option changed, what to display: */
448#define P_RSTAT 0x1000 /* redraw status lines */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100449#define P_RWIN 0x2000 /* redraw current window and recompute text */
450#define P_RBUF 0x4000 /* redraw current buffer and recompute text */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000451#define P_RALL 0x6000 /* redraw all windows */
452#define P_RCLR 0x7000 /* clear and redraw all */
453
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200454#define P_COMMA 0x8000 /* comma separated list */
455#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
456 * commas */
457#define P_NODUP 0x20000L /* don't allow duplicate strings */
458#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000459
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200460#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
461#define P_GETTEXT 0x100000L /* expand default value with _() */
462#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
463#define P_NFNAME 0x400000L /* only normal file name chars allowed */
464#define P_INSECURE 0x800000L /* option was set from a modeline */
465#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7554da42016-11-25 22:04:13 +0100466 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200467#define P_NO_ML 0x2000000L /* not allowed in modeline */
468#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200469 * there is a redraw flag */
Bram Moolenaar7554da42016-11-25 22:04:13 +0100470#define P_NDNAME 0x8000000L /* only normal dir name chars allowed */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100471#define P_RWINONLY 0x10000000L /* only redraw current window */
Bram Moolenaar110289e2019-05-23 15:38:06 +0200472#define P_MLE 0x20000000L /* under control of 'modelineexpr' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000473
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000474#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
475
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000476/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
477 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100478#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000479# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000480#else
481# define ISP_LATIN1 (char_u *)"@,161-255"
482#endif
483
Bram Moolenaar05fbfdc2017-08-14 22:35:08 +0200484# 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 +0000485
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +0100486/* Default python version for pyx* commands */
487#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
488# define DEFAULT_PYTHON_VER 0
489#elif defined(FEAT_PYTHON3)
490# define DEFAULT_PYTHON_VER 3
491#elif defined(FEAT_PYTHON)
492# define DEFAULT_PYTHON_VER 2
493#else
494# define DEFAULT_PYTHON_VER 0
495#endif
496
Bram Moolenaarce655742019-01-31 14:12:57 +0100497// used for 'cinkeys' and 'indentkeys'
498#define INDENTKEYS_DEFAULT (char_u *)"0{,0},0),0],:,0#,!^F,o,O,e"
499
Bram Moolenaar071d4272004-06-13 20:20:40 +0000500/*
501 * options[] is initialized here.
502 * The order of the options MUST be alphabetic for ":set all" and findoption().
503 * All option names MUST start with a lowercase letter (for findoption()).
504 * Exception: "t_" options are at the end.
505 * The options with a NULL variable are 'hidden': a set command for them is
506 * ignored and they are not printed.
507 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100508static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000509{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200510 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000511#ifdef FEAT_RIGHTLEFT
512 (char_u *)&p_aleph, PV_NONE,
513#else
514 (char_u *)NULL, PV_NONE,
515#endif
516 {
Bram Moolenaar4f974752019-02-17 17:44:42 +0100517#if defined(MSWIN) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000518 (char_u *)128L,
519#else
520 (char_u *)224L,
521#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200522 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000523 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
Bram Moolenaard0573012017-10-28 21:11:06 +0200524#if defined(FEAT_GUI_MAC)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000525 (char_u *)&p_antialias, PV_NONE,
526 {(char_u *)FALSE, (char_u *)FALSE}
527#else
528 (char_u *)NULL, PV_NONE,
529 {(char_u *)FALSE, (char_u *)FALSE}
530#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200531 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200532 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000533#ifdef FEAT_ARABIC
534 (char_u *)VAR_WIN, PV_ARAB,
535#else
536 (char_u *)NULL, PV_NONE,
537#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200538 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000539 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
540#ifdef FEAT_ARABIC
541 (char_u *)&p_arshape, PV_NONE,
542#else
543 (char_u *)NULL, PV_NONE,
544#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200545 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000546 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
547#ifdef FEAT_RIGHTLEFT
548 (char_u *)&p_ari, PV_NONE,
549#else
550 (char_u *)NULL, PV_NONE,
551#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200552 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000553 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000554 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200555 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000556 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000557 (char_u *)&p_ambw, PV_NONE,
558 {(char_u *)"single", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200559 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000560 {"autochdir", "acd", P_BOOL|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100561#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000562 (char_u *)&p_acd, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100563 {(char_u *)FALSE, (char_u *)0L}
564#else
565 (char_u *)NULL, PV_NONE,
566 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000567#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200568 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000569 {"autoindent", "ai", P_BOOL|P_VI_DEF,
570 (char_u *)&p_ai, PV_AI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200571 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000572 {"autoprint", "ap", P_BOOL|P_VI_DEF,
573 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200574 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000575 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000576 (char_u *)&p_ar, PV_AR,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200577 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000578 {"autowrite", "aw", P_BOOL|P_VI_DEF,
579 (char_u *)&p_aw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200580 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000581 {"autowriteall","awa", P_BOOL|P_VI_DEF,
582 (char_u *)&p_awa, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200583 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000584 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
585 (char_u *)&p_bg, PV_NONE,
586 {
Bram Moolenaar4f974752019-02-17 17:44:42 +0100587#if (defined(MSWIN)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000588 (char_u *)"dark",
589#else
590 (char_u *)"light",
591#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200592 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200593 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000594 (char_u *)&p_bs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200595 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000596 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
597 (char_u *)&p_bk, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200598 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200599 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200600 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000601#ifdef UNIX
602 {(char_u *)"yes", (char_u *)"auto"}
603#else
604 {(char_u *)"auto", (char_u *)"auto"}
605#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200606 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200607 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
608 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000609 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200610 {(char_u *)DFLT_BDIR, (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000611 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000612 (char_u *)&p_bex, PV_NONE,
613 {
614#ifdef VMS
615 (char_u *)"_",
616#else
617 (char_u *)"~",
618#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200619 (char_u *)0L} SCTX_INIT},
Bram Moolenaar06e2c812019-06-12 19:05:48 +0200620 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000621#ifdef FEAT_WILDIGN
622 (char_u *)&p_bsk, PV_NONE,
623 {(char_u *)"", (char_u *)0L}
624#else
625 (char_u *)NULL, PV_NONE,
626 {(char_u *)0L, (char_u *)0L}
627#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200628 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000629 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100630#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000631 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100632 {(char_u *)600L, (char_u *)0L}
633#else
634 (char_u *)NULL, PV_NONE,
635 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000636#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200637 SCTX_INIT},
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100638 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100639#ifdef FEAT_BEVAL_GUI
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100640 (char_u *)&p_beval, PV_NONE,
641 {(char_u *)FALSE, (char_u *)0L}
642#else
643 (char_u *)NULL, PV_NONE,
644 {(char_u *)0L, (char_u *)0L}
645#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200646 SCTX_INIT},
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100647 {"balloonevalterm", "bevalterm",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100648#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100649 (char_u *)&p_bevalterm, PV_NONE,
650 {(char_u *)FALSE, (char_u *)0L}
651#else
652 (char_u *)NULL, PV_NONE,
653 {(char_u *)0L, (char_u *)0L}
654#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200655 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +0200656 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM|P_MLE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100657#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
658 (char_u *)&p_bexpr, PV_BEXPR,
659 {(char_u *)"", (char_u *)0L}
660#else
661 (char_u *)NULL, PV_NONE,
662 {(char_u *)0L, (char_u *)0L}
663#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200664 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000665 {"beautify", "bf", P_BOOL|P_VI_DEF,
666 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200667 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200668 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
669 (char_u *)&p_bo, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200670 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000671 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
672 (char_u *)&p_bin, PV_BIN,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200673 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000674 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000675 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200676 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000677 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000678 (char_u *)&p_bomb, PV_BOMB,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200679 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000680 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
681#ifdef FEAT_LINEBREAK
682 (char_u *)&p_breakat, PV_NONE,
683 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
684#else
685 (char_u *)NULL, PV_NONE,
686 {(char_u *)0L, (char_u *)0L}
687#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200688 SCTX_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200689 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
690#ifdef FEAT_LINEBREAK
691 (char_u *)VAR_WIN, PV_BRI,
692 {(char_u *)FALSE, (char_u *)0L}
693#else
694 (char_u *)NULL, PV_NONE,
695 {(char_u *)0L, (char_u *)0L}
696#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200697 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200698 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
699 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200700#ifdef FEAT_LINEBREAK
701 (char_u *)VAR_WIN, PV_BRIOPT,
702 {(char_u *)"", (char_u *)NULL}
703#else
704 (char_u *)NULL, PV_NONE,
705 {(char_u *)"", (char_u *)NULL}
706#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200707 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000708 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
709#ifdef FEAT_BROWSE
710 (char_u *)&p_bsdir, PV_NONE,
711 {(char_u *)"last", (char_u *)0L}
712#else
713 (char_u *)NULL, PV_NONE,
714 {(char_u *)0L, (char_u *)0L}
715#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200716 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000717 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000718 (char_u *)&p_bh, PV_BH,
719 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200720 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000721 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
722 (char_u *)&p_bl, PV_BL,
723 {(char_u *)1L, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200724 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000725 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000726 (char_u *)&p_bt, PV_BT,
727 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200728 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200729 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000730 (char_u *)&p_cmp, PV_NONE,
731 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200732 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +0200733 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE|P_COMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000734#ifdef FEAT_SEARCHPATH
735 (char_u *)&p_cdpath, PV_NONE,
736 {(char_u *)",,", (char_u *)0L}
737#else
738 (char_u *)NULL, PV_NONE,
739 {(char_u *)0L, (char_u *)0L}
740#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200741 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000742 {"cedit", NULL, P_STRING,
743#ifdef FEAT_CMDWIN
744 (char_u *)&p_cedit, PV_NONE,
745 {(char_u *)"", (char_u *)CTRL_F_STR}
746#else
747 (char_u *)NULL, PV_NONE,
748 {(char_u *)0L, (char_u *)0L}
749#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200750 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000751 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +0100752#if defined(FEAT_EVAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000753 (char_u *)&p_ccv, PV_NONE,
754 {(char_u *)"", (char_u *)0L}
755#else
756 (char_u *)NULL, PV_NONE,
757 {(char_u *)0L, (char_u *)0L}
758#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200759 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000760 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
761#ifdef FEAT_CINDENT
762 (char_u *)&p_cin, PV_CIN,
763#else
764 (char_u *)NULL, PV_NONE,
765#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200766 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200767 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000768#ifdef FEAT_CINDENT
769 (char_u *)&p_cink, PV_CINK,
Bram Moolenaarce655742019-01-31 14:12:57 +0100770 {INDENTKEYS_DEFAULT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000771#else
772 (char_u *)NULL, PV_NONE,
773 {(char_u *)0L, (char_u *)0L}
774#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200775 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200776 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000777#ifdef FEAT_CINDENT
778 (char_u *)&p_cino, PV_CINO,
779#else
780 (char_u *)NULL, PV_NONE,
781#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200782 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200783 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000784#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
785 (char_u *)&p_cinw, PV_CINW,
786 {(char_u *)"if,else,while,do,for,switch",
787 (char_u *)0L}
788#else
789 (char_u *)NULL, PV_NONE,
790 {(char_u *)0L, (char_u *)0L}
791#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200792 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200793 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000794#ifdef FEAT_CLIPBOARD
795 (char_u *)&p_cb, PV_NONE,
796# ifdef FEAT_XCLIPBOARD
797 {(char_u *)"autoselect,exclude:cons\\|linux",
798 (char_u *)0L}
799# else
800 {(char_u *)"", (char_u *)0L}
801# endif
802#else
803 (char_u *)NULL, PV_NONE,
804 {(char_u *)"", (char_u *)0L}
805#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200806 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000807 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
808 (char_u *)&p_ch, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200809 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000810 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
811#ifdef FEAT_CMDWIN
812 (char_u *)&p_cwh, PV_NONE,
813#else
814 (char_u *)NULL, PV_NONE,
815#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200816 {(char_u *)7L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200817 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200818#ifdef FEAT_SYN_HL
819 (char_u *)VAR_WIN, PV_CC,
820#else
821 (char_u *)NULL, PV_NONE,
822#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200823 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000824 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
825 (char_u *)&Columns, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200826 {(char_u *)80L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200827 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
828 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000829#ifdef FEAT_COMMENTS
830 (char_u *)&p_com, PV_COM,
831 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
832 (char_u *)0L}
833#else
834 (char_u *)NULL, PV_NONE,
835 {(char_u *)0L, (char_u *)0L}
836#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200837 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200838 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000839#ifdef FEAT_FOLDING
840 (char_u *)&p_cms, PV_CMS,
841 {(char_u *)"/*%s*/", (char_u *)0L}
842#else
843 (char_u *)NULL, PV_NONE,
844 {(char_u *)0L, (char_u *)0L}
845#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200846 SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000847 /* P_PRI_MKRC isn't needed here, optval_default()
848 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000849 {"compatible", "cp", P_BOOL|P_RALL,
850 (char_u *)&p_cp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200851 {(char_u *)TRUE, (char_u *)FALSE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200852 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000853#ifdef FEAT_INS_EXPAND
854 (char_u *)&p_cpt, PV_CPT,
855 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
856#else
857 (char_u *)NULL, PV_NONE,
858 {(char_u *)0L, (char_u *)0L}
859#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200860 SCTX_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200861 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200862#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200863 (char_u *)VAR_WIN, PV_COCU,
864 {(char_u *)"", (char_u *)NULL}
865#else
866 (char_u *)NULL, PV_NONE,
867 {(char_u *)NULL, (char_u *)0L}
868#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200869 SCTX_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200870 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
871#ifdef FEAT_CONCEAL
872 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200873#else
874 (char_u *)NULL, PV_NONE,
875#endif
876 {(char_u *)0L, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200877 SCTX_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000878 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
879#ifdef FEAT_COMPL_FUNC
880 (char_u *)&p_cfu, PV_CFU,
881 {(char_u *)"", (char_u *)0L}
882#else
883 (char_u *)NULL, PV_NONE,
884 {(char_u *)0L, (char_u *)0L}
885#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200886 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200887 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000888#ifdef FEAT_INS_EXPAND
889 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000890 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000891#else
892 (char_u *)NULL, PV_NONE,
893 {(char_u *)0L, (char_u *)0L}
894#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200895 SCTX_INIT},
Bram Moolenaar62a0cb42019-08-18 16:35:23 +0200896 {"completepopup", "cpp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
897#ifdef FEAT_TEXT_PROP
898 (char_u *)&p_cpp, PV_NONE,
899 {(char_u *)"", (char_u *)0L}
900#else
901 (char_u *)NULL, PV_NONE,
902 {(char_u *)NULL, (char_u *)0L}
903#endif
904 SCTX_INIT},
Bram Moolenaarac3150d2019-07-28 16:36:39 +0200905 {"completeslash", "csl", P_STRING|P_VI_DEF|P_VIM,
906#if defined(FEAT_INS_EXPAND) && defined(BACKSLASH_IN_FILENAME)
907 (char_u *)&p_csl, PV_CSL,
908 {(char_u *)"", (char_u *)0L}
909#else
910 (char_u *)NULL, PV_NONE,
911 {(char_u *)0L, (char_u *)0L}
912#endif
913 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000914 {"confirm", "cf", P_BOOL|P_VI_DEF,
915#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
916 (char_u *)&p_confirm, PV_NONE,
917#else
918 (char_u *)NULL, PV_NONE,
919#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200920 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000921 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000922 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200923 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000924 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
925 (char_u *)&p_ci, PV_CI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200926 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000927 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
928 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000929 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200930 SCTX_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200931 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200932#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200933 (char_u *)&p_cm, PV_CM,
Bram Moolenaara86187b2018-12-16 18:20:00 +0100934 {(char_u *)"blowfish2", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200935#else
936 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200937 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200938#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200939 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000940 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
941#ifdef FEAT_CSCOPE
942 (char_u *)&p_cspc, PV_NONE,
943#else
944 (char_u *)NULL, PV_NONE,
945#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200946 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000947 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
948#ifdef FEAT_CSCOPE
949 (char_u *)&p_csprg, PV_NONE,
950 {(char_u *)"cscope", (char_u *)0L}
951#else
952 (char_u *)NULL, PV_NONE,
953 {(char_u *)0L, (char_u *)0L}
954#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200955 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200956 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000957#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
958 (char_u *)&p_csqf, PV_NONE,
959 {(char_u *)"", (char_u *)0L}
960#else
961 (char_u *)NULL, PV_NONE,
962 {(char_u *)0L, (char_u *)0L}
963#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200964 SCTX_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200965 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
966#ifdef FEAT_CSCOPE
967 (char_u *)&p_csre, PV_NONE,
968#else
969 (char_u *)NULL, PV_NONE,
970#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200971 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000972 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
973#ifdef FEAT_CSCOPE
974 (char_u *)&p_cst, PV_NONE,
975#else
976 (char_u *)NULL, PV_NONE,
977#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200978 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000979 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
980#ifdef FEAT_CSCOPE
981 (char_u *)&p_csto, PV_NONE,
982#else
983 (char_u *)NULL, PV_NONE,
984#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200985 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000986 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
987#ifdef FEAT_CSCOPE
988 (char_u *)&p_csverbose, PV_NONE,
989#else
990 (char_u *)NULL, PV_NONE,
991#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200992 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200993 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200994 (char_u *)VAR_WIN, PV_CRBIND,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200995 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar177ab9e2019-01-15 21:12:57 +0100996 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000997#ifdef FEAT_SYN_HL
998 (char_u *)VAR_WIN, PV_CUC,
999#else
1000 (char_u *)NULL, PV_NONE,
1001#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001002 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +01001003 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001004#ifdef FEAT_SYN_HL
1005 (char_u *)VAR_WIN, PV_CUL,
1006#else
1007 (char_u *)NULL, PV_NONE,
1008#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001009 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001010 {"debug", NULL, P_STRING|P_VI_DEF,
1011 (char_u *)&p_debug, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001012 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001013 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001014#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001015 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001016 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001017#else
1018 (char_u *)NULL, PV_NONE,
1019 {(char_u *)NULL, (char_u *)0L}
1020#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001021 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001022 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001023 (char_u *)&p_deco, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001024 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001025 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001026#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001027 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001028#else
1029 (char_u *)NULL, PV_NONE,
1030#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001031 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001032 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1033#ifdef FEAT_DIFF
1034 (char_u *)VAR_WIN, PV_DIFF,
1035#else
1036 (char_u *)NULL, PV_NONE,
1037#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001038 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001039 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001040#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1041 (char_u *)&p_dex, PV_NONE,
1042 {(char_u *)"", (char_u *)0L}
1043#else
1044 (char_u *)NULL, PV_NONE,
1045 {(char_u *)0L, (char_u *)0L}
1046#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001047 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001048 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1049 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001050#ifdef FEAT_DIFF
1051 (char_u *)&p_dip, PV_NONE,
Bram Moolenaarc93262b2018-09-10 21:15:40 +02001052 {(char_u *)"internal,filler", (char_u *)NULL}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001053#else
1054 (char_u *)NULL, PV_NONE,
1055 {(char_u *)"", (char_u *)NULL}
1056#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001057 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001058 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1059#ifdef FEAT_DIGRAPHS
1060 (char_u *)&p_dg, PV_NONE,
1061#else
1062 (char_u *)NULL, PV_NONE,
1063#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001064 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001065 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1066 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001067 (char_u *)&p_dir, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001068 {(char_u *)DFLT_DIR, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001069 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001070 (char_u *)&p_dy, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001071 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001072 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001073 (char_u *)&p_ead, PV_NONE,
1074 {(char_u *)"both", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001075 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001076 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1077 (char_u *)&p_ed, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001078 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001079 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaar3848e002016-03-19 18:42:29 +01001080 (char_u *)&p_emoji, PV_NONE,
1081 {(char_u *)TRUE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001082 SCTX_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001083 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001084 (char_u *)&p_enc, PV_NONE,
1085 {(char_u *)ENC_DFLT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001086 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001087 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1088 (char_u *)&p_eol, PV_EOL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001089 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001090 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1091 (char_u *)&p_ea, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001092 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001093 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001094 (char_u *)&p_ep, PV_EP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001095 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001096 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1097 (char_u *)&p_eb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001098 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001099 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1100#ifdef FEAT_QUICKFIX
1101 (char_u *)&p_ef, PV_NONE,
1102 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1103#else
1104 (char_u *)NULL, PV_NONE,
1105 {(char_u *)NULL, (char_u *)0L}
1106#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001107 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001108 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001109#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001110 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001111 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001112#else
1113 (char_u *)NULL, PV_NONE,
1114 {(char_u *)NULL, (char_u *)0L}
1115#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001116 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001117 {"esckeys", "ek", P_BOOL|P_VIM,
1118 (char_u *)&p_ek, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001119 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001120 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001121 (char_u *)&p_ei, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001122 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001123 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1124 (char_u *)&p_et, PV_ET,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001125 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001126 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1127 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001128 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001129 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1130 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001131 (char_u *)&p_fenc, PV_FENC,
1132 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001133 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001134 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001135 (char_u *)&p_fencs, PV_NONE,
1136 {(char_u *)"ucs-bom", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001137 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001138 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1139 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001140 (char_u *)&p_ff, PV_FF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001141 {(char_u *)DFLT_FF, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001142 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001143 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001144 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001145 SCTX_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001146 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1147 (char_u *)&p_fic, PV_NONE,
1148 {
1149#ifdef CASE_INSENSITIVE_FILENAME
1150 (char_u *)TRUE,
1151#else
1152 (char_u *)FALSE,
1153#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001154 (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001155 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001156 (char_u *)&p_ft, PV_FT,
1157 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001158 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001159 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001160 (char_u *)&p_fcs, PV_NONE,
1161 {(char_u *)"vert:|,fold:-", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001162 SCTX_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001163 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1164 (char_u *)&p_fixeol, PV_FIXEOL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001165 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001166 {"fkmap", "fk", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001167 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001168 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001169 {"flash", "fl", P_BOOL|P_VI_DEF,
1170 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001171 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001172 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001173#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001174 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001175 {(char_u *)"", (char_u *)0L}
1176#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001177 (char_u *)NULL, PV_NONE,
1178 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001179#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001180 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001181 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1182#ifdef FEAT_FOLDING
1183 (char_u *)VAR_WIN, PV_FDC,
1184 {(char_u *)FALSE, (char_u *)0L}
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 Moolenaara713ff82017-02-25 22:18:43 +01001190 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1191#ifdef FEAT_FOLDING
1192 (char_u *)VAR_WIN, PV_FEN,
1193 {(char_u *)TRUE, (char_u *)0L}
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 Moolenaar110289e2019-05-23 15:38:06 +02001199 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN|P_MLE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001200#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1201 (char_u *)VAR_WIN, PV_FDE,
1202 {(char_u *)"0", (char_u *)NULL}
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 Moolenaar071d4272004-06-13 20:20:40 +00001208 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001209#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001210 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001211 {(char_u *)"#", (char_u *)NULL}
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 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001218#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001219 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001220 {(char_u *)0L, (char_u *)0L}
1221#else
1222 (char_u *)NULL, PV_NONE,
1223 {(char_u *)NULL, (char_u *)0L}
1224#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001225 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001226 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001227#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001228 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001229 {(char_u *)-1L, (char_u *)0L}
1230#else
1231 (char_u *)NULL, PV_NONE,
1232 {(char_u *)NULL, (char_u *)0L}
1233#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001234 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001235 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001236 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001237#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001238 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001239 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001240#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001241 (char_u *)NULL, PV_NONE,
1242 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001243#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001244 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001245 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1246#ifdef FEAT_FOLDING
1247 (char_u *)VAR_WIN, PV_FDM,
1248 {(char_u *)"manual", (char_u *)NULL}
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 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1255#ifdef FEAT_FOLDING
1256 (char_u *)VAR_WIN, PV_FML,
1257 {(char_u *)1L, (char_u *)0L}
1258#else
1259 (char_u *)NULL, PV_NONE,
1260 {(char_u *)NULL, (char_u *)0L}
1261#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001262 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001263 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1264#ifdef FEAT_FOLDING
1265 (char_u *)VAR_WIN, PV_FDN,
1266 {(char_u *)20L, (char_u *)0L}
1267#else
1268 (char_u *)NULL, PV_NONE,
1269 {(char_u *)NULL, (char_u *)0L}
1270#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001271 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001272 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1273#ifdef FEAT_FOLDING
1274 (char_u *)&p_fdo, PV_NONE,
1275 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1276 (char_u *)0L}
1277#else
1278 (char_u *)NULL, PV_NONE,
1279 {(char_u *)NULL, (char_u *)0L}
1280#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001281 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001282 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN|P_MLE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001283#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1284 (char_u *)VAR_WIN, PV_FDT,
1285 {(char_u *)"foldtext()", (char_u *)NULL}
1286#else
1287 (char_u *)NULL, PV_NONE,
1288 {(char_u *)NULL, (char_u *)0L}
1289#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001290 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001291 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM|P_MLE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001292#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001293 (char_u *)&p_fex, PV_FEX,
1294 {(char_u *)"", (char_u *)0L}
1295#else
1296 (char_u *)NULL, PV_NONE,
1297 {(char_u *)0L, (char_u *)0L}
1298#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001299 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001300 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1301 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001302 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001303 SCTX_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001304 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1305 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001306 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001307 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001308 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001309 (char_u *)&p_fp, PV_FP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001310 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001311 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1312#ifdef HAVE_FSYNC
1313 (char_u *)&p_fs, PV_NONE,
1314 {(char_u *)TRUE, (char_u *)0L}
1315#else
1316 (char_u *)NULL, PV_NONE,
1317 {(char_u *)FALSE, (char_u *)0L}
1318#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001319 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001320 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1321 (char_u *)&p_gd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001322 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001323 {"graphic", "gr", P_BOOL|P_VI_DEF,
1324 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001325 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001326 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001327#ifdef FEAT_QUICKFIX
1328 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001329 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001330#else
1331 (char_u *)NULL, PV_NONE,
1332 {(char_u *)NULL, (char_u *)0L}
1333#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001334 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001335 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1336#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001337 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001338 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01001339# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001340 /* may be changed to "grep -n" in os_win32.c */
1341 (char_u *)"findstr /n",
1342# else
1343# ifdef UNIX
1344 /* Add an extra file name so that grep will always
1345 * insert a file name in the match line. */
1346 (char_u *)"grep -n $* /dev/null",
1347# else
1348# ifdef VMS
1349 (char_u *)"SEARCH/NUMBERS ",
1350# else
1351 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001352# endif
1353# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001354# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001355 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001356#else
1357 (char_u *)NULL, PV_NONE,
1358 {(char_u *)NULL, (char_u *)0L}
1359#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001360 SCTX_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001361 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001362#ifdef CURSOR_SHAPE
1363 (char_u *)&p_guicursor, PV_NONE,
1364 {
1365# ifdef FEAT_GUI
1366 (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 +01001367# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001368 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1369# endif
1370 (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 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001377#ifdef FEAT_GUI
1378 (char_u *)&p_guifont, 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 Moolenaar0e7c4b92015-06-20 15:30:03 +02001385 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001386#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1387 (char_u *)&p_guifontset, PV_NONE,
1388 {(char_u *)"", (char_u *)0L}
1389#else
1390 (char_u *)NULL, PV_NONE,
1391 {(char_u *)NULL, (char_u *)0L}
1392#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001393 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001394 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001395#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001396 (char_u *)&p_guifontwide, PV_NONE,
1397 {(char_u *)"", (char_u *)0L}
1398#else
1399 (char_u *)NULL, PV_NONE,
1400 {(char_u *)NULL, (char_u *)0L}
1401#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001402 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001403 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001404#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001405 (char_u *)&p_ghr, PV_NONE,
1406#else
1407 (char_u *)NULL, PV_NONE,
1408#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001409 {(char_u *)50L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001410 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001411#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001412 (char_u *)&p_go, PV_NONE,
Bram Moolenaard0573012017-10-28 21:11:06 +02001413# if defined(UNIX) && !defined(FEAT_GUI_MAC)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001414 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001415# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001416 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001417# endif
1418#else
1419 (char_u *)NULL, PV_NONE,
1420 {(char_u *)NULL, (char_u *)0L}
1421#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001422 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001423 {"guipty", NULL, P_BOOL|P_VI_DEF,
1424#if defined(FEAT_GUI)
1425 (char_u *)&p_guipty, PV_NONE,
1426#else
1427 (char_u *)NULL, PV_NONE,
1428#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001429 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001430 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN|P_MLE,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001431#if defined(FEAT_GUI_TABLINE)
1432 (char_u *)&p_gtl, PV_NONE,
1433 {(char_u *)"", (char_u *)0L}
1434#else
1435 (char_u *)NULL, PV_NONE,
1436 {(char_u *)NULL, (char_u *)0L}
1437#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001438 SCTX_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001439 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001440#if defined(FEAT_GUI_TABLINE)
1441 (char_u *)&p_gtt, PV_NONE,
1442 {(char_u *)"", (char_u *)0L}
1443#else
1444 (char_u *)NULL, PV_NONE,
1445 {(char_u *)NULL, (char_u *)0L}
1446#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001447 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001448 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1449 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001450 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001451 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1452 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001453 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001454 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001455 {"helpheight", "hh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001456 (char_u *)&p_hh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001457 {(char_u *)20L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001458 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001459#ifdef FEAT_MULTI_LANG
1460 (char_u *)&p_hlg, PV_NONE,
1461 {(char_u *)"", (char_u *)0L}
1462#else
1463 (char_u *)NULL, PV_NONE,
1464 {(char_u *)0L, (char_u *)0L}
1465#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001466 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001467 {"hidden", "hid", P_BOOL|P_VI_DEF,
1468 (char_u *)&p_hid, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001469 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001470 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001471 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001472 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001473 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001474 {"history", "hi", P_NUM|P_VIM,
1475 (char_u *)&p_hi, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001476 {(char_u *)0L, (char_u *)50L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001477 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1478#ifdef FEAT_RIGHTLEFT
1479 (char_u *)&p_hkmap, PV_NONE,
1480#else
1481 (char_u *)NULL, PV_NONE,
1482#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001483 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001484 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1485#ifdef FEAT_RIGHTLEFT
1486 (char_u *)&p_hkmapp, PV_NONE,
1487#else
1488 (char_u *)NULL, PV_NONE,
1489#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001490 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001491 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1492 (char_u *)&p_hls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001493 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001494 {"icon", NULL, P_BOOL|P_VI_DEF,
1495#ifdef FEAT_TITLE
1496 (char_u *)&p_icon, PV_NONE,
1497#else
1498 (char_u *)NULL, PV_NONE,
1499#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001500 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001501 {"iconstring", NULL, P_STRING|P_VI_DEF|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001502#ifdef FEAT_TITLE
1503 (char_u *)&p_iconstring, PV_NONE,
1504#else
1505 (char_u *)NULL, PV_NONE,
1506#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001507 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001508 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1509 (char_u *)&p_ic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001510 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001511 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001512#if defined(FEAT_EVAL)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001513 (char_u *)&p_imaf, PV_NONE,
1514 {(char_u *)"", (char_u *)NULL}
1515# else
1516 (char_u *)NULL, PV_NONE,
1517 {(char_u *)NULL, (char_u *)0L}
1518# endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001519 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001520 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001521#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001522 (char_u *)&p_imak, PV_NONE,
1523#else
1524 (char_u *)NULL, PV_NONE,
1525#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001526 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001527 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001528 (char_u *)&p_imcmdline, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001529 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001530 {"imdisable", "imd", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001531 (char_u *)&p_imdisable, PV_NONE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001532#ifdef __sgi
1533 {(char_u *)TRUE, (char_u *)0L}
1534#else
1535 {(char_u *)FALSE, (char_u *)0L}
1536#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001537 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001538 {"iminsert", "imi", P_NUM|P_VI_DEF,
1539 (char_u *)&p_iminsert, PV_IMI,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001540 {(char_u *)B_IMODE_NONE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001541 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001542 {"imsearch", "ims", P_NUM|P_VI_DEF,
1543 (char_u *)&p_imsearch, PV_IMS,
Bram Moolenaar4cf56bb2017-09-16 15:50:32 +02001544 {(char_u *)B_IMODE_USE_INSERT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001545 SCTX_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001546 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001547#if defined(FEAT_EVAL)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001548 (char_u *)&p_imsf, PV_NONE,
1549 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001550#else
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001551 (char_u *)NULL, PV_NONE,
1552 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001553#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001554 SCTX_INIT},
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001555 {"imstyle", "imst", P_NUM|P_VI_DEF|P_SECURE,
1556#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1557 (char_u *)&p_imst, PV_NONE,
1558 {(char_u *)IM_OVER_THE_SPOT, (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 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1565#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001566 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001567 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1568#else
1569 (char_u *)NULL, PV_NONE,
1570 {(char_u *)0L, (char_u *)0L}
1571#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001572 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001573 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001574#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1575 (char_u *)&p_inex, PV_INEX,
1576 {(char_u *)"", (char_u *)0L}
1577#else
1578 (char_u *)NULL, PV_NONE,
1579 {(char_u *)0L, (char_u *)0L}
1580#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001581 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001582 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1583 (char_u *)&p_is, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001584 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001585 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001586#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1587 (char_u *)&p_inde, PV_INDE,
1588 {(char_u *)"", (char_u *)0L}
1589#else
1590 (char_u *)NULL, PV_NONE,
1591 {(char_u *)0L, (char_u *)0L}
1592#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001593 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001594 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001595#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1596 (char_u *)&p_indk, PV_INDK,
Bram Moolenaarce655742019-01-31 14:12:57 +01001597 {INDENTKEYS_DEFAULT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001598#else
1599 (char_u *)NULL, PV_NONE,
1600 {(char_u *)0L, (char_u *)0L}
1601#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001602 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001603 {"infercase", "inf", P_BOOL|P_VI_DEF,
1604 (char_u *)&p_inf, PV_INF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001605 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001606 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1607 (char_u *)&p_im, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001608 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001609 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1610 (char_u *)&p_isf, PV_NONE,
1611 {
1612#ifdef BACKSLASH_IN_FILENAME
1613 /* Excluded are: & and ^ are special in cmd.exe
1614 * ( and ) are used in text separating fnames */
1615 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1616#else
1617# ifdef AMIGA
1618 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1619# else
1620# ifdef VMS
1621 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1622# else /* UNIX et al. */
1623# ifdef EBCDIC
1624 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1625# else
1626 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1627# endif
1628# endif
1629# endif
1630#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001631 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001632 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1633 (char_u *)&p_isi, PV_NONE,
1634 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001635#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001636 (char_u *)"@,48-57,_,128-167,224-235",
1637#else
1638# ifdef EBCDIC
1639 /* TODO: EBCDIC Check this! @ == isalpha()*/
1640 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1641 "112-120,128,140-142,156,158,172,"
1642 "174,186,191,203-207,219-225,235-239,"
1643 "251-254",
1644# else
1645 (char_u *)"@,48-57,_,192-255",
1646# endif
1647#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001648 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001649 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1650 (char_u *)&p_isk, PV_ISK,
1651 {
1652#ifdef EBCDIC
1653 (char_u *)"@,240-249,_",
1654 /* TODO: EBCDIC Check this! @ == isalpha()*/
1655 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1656 "112-120,128,140-142,156,158,172,"
1657 "174,186,191,203-207,219-225,235-239,"
1658 "251-254",
1659#else
1660 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001661# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001662 (char_u *)"@,48-57,_,128-167,224-235"
1663# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001664 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001665# endif
1666#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001667 } SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001668 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1669 (char_u *)&p_isp, PV_NONE,
1670 {
Bram Moolenaard0573012017-10-28 21:11:06 +02001671#if defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001672 (char_u *)"@,~-255",
1673#else
1674# ifdef EBCDIC
1675 /* all chars above 63 are printable */
1676 (char_u *)"63-255",
1677# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001678 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001679# endif
1680#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001681 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001682 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1683 (char_u *)&p_js, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001684 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001685 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1686#ifdef FEAT_CRYPT
1687 (char_u *)&p_key, PV_KEY,
1688 {(char_u *)"", (char_u *)0L}
1689#else
1690 (char_u *)NULL, PV_NONE,
1691 {(char_u *)0L, (char_u *)0L}
1692#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001693 SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001694 {"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 +00001695#ifdef FEAT_KEYMAP
1696 (char_u *)&p_keymap, PV_KMAP,
1697 {(char_u *)"", (char_u *)0L}
1698#else
1699 (char_u *)NULL, PV_NONE,
1700 {(char_u *)"", (char_u *)0L}
1701#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001702 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001703 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001704 (char_u *)&p_km, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001705 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001706 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001707 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001708 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001709#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001710 (char_u *)":help",
1711#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001712# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001713 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001714# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001715# ifdef USEMAN_S
1716 (char_u *)"man -s",
1717# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001718 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001719# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001720# endif
1721#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001722 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001723 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001724#ifdef FEAT_LANGMAP
1725 (char_u *)&p_langmap, PV_NONE,
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001726 {(char_u *)"", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001727#else
1728 (char_u *)NULL, PV_NONE,
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001729 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001730#endif
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001731 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001732 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001733#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1734 (char_u *)&p_lm, PV_NONE,
1735#else
1736 (char_u *)NULL, PV_NONE,
1737#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001738 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001739 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1740#ifdef FEAT_LANGMAP
1741 (char_u *)&p_lnr, PV_NONE,
1742#else
1743 (char_u *)NULL, PV_NONE,
1744#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001745 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001746 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1747#ifdef FEAT_LANGMAP
1748 (char_u *)&p_lrm, PV_NONE,
1749#else
1750 (char_u *)NULL, PV_NONE,
1751#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001752 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001753 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001754 (char_u *)&p_ls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001755 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001756 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1757 (char_u *)&p_lz, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001758 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001759 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1760#ifdef FEAT_LINEBREAK
1761 (char_u *)VAR_WIN, PV_LBR,
1762#else
1763 (char_u *)NULL, PV_NONE,
1764#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001765 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001766 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1767 (char_u *)&Rows, PV_NONE,
1768 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01001769#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001770 (char_u *)25L,
1771#else
1772 (char_u *)24L,
1773#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001774 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001775 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1776#ifdef FEAT_GUI
1777 (char_u *)&p_linespace, PV_NONE,
1778#else
1779 (char_u *)NULL, PV_NONE,
1780#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01001781#ifdef FEAT_GUI_MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001782 {(char_u *)1L, (char_u *)0L}
1783#else
1784 {(char_u *)0L, (char_u *)0L}
1785#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001786 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001787 {"lisp", NULL, P_BOOL|P_VI_DEF,
1788#ifdef FEAT_LISP
1789 (char_u *)&p_lisp, PV_LISP,
1790#else
1791 (char_u *)NULL, PV_NONE,
1792#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001793 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001794 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001795#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001796 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001797 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1798#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 Moolenaar071d4272004-06-13 20:20:40 +00001803 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1804 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001805 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001806 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001807 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001808 {(char_u *)"eol:$", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001809 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1810 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001811 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001812 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001813#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001814 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001815 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001816#else
1817 (char_u *)NULL, PV_NONE,
1818 {(char_u *)"", (char_u *)0L}
1819#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001820 SCTX_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001821 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001822#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001823 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001824 {(char_u *)TRUE, (char_u *)0L}
1825#else
1826 (char_u *)NULL, PV_NONE,
1827 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001828#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001829 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001830 {"magic", NULL, P_BOOL|P_VI_DEF,
1831 (char_u *)&p_magic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001832 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001833 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001834#ifdef FEAT_QUICKFIX
1835 (char_u *)&p_mef, PV_NONE,
1836 {(char_u *)"", (char_u *)0L}
1837#else
1838 (char_u *)NULL, PV_NONE,
1839 {(char_u *)NULL, (char_u *)0L}
1840#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001841 SCTX_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001842 {"makeencoding","menc", P_STRING|P_VI_DEF,
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001843 (char_u *)&p_menc, PV_MENC,
1844 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001845 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001846 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1847#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001848 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001849# ifdef VMS
1850 {(char_u *)"MMS", (char_u *)0L}
1851# else
1852 {(char_u *)"make", (char_u *)0L}
1853# endif
1854#else
1855 (char_u *)NULL, PV_NONE,
1856 {(char_u *)NULL, (char_u *)0L}
1857#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001858 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001859 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001860 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001861 {(char_u *)"(:),{:},[:]", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001862 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001863 {"matchtime", "mat", P_NUM|P_VI_DEF,
1864 (char_u *)&p_mat, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001865 {(char_u *)5L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001866 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001867 (char_u *)&p_mco, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001868 {(char_u *)2, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001869 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1870#ifdef FEAT_EVAL
1871 (char_u *)&p_mfd, PV_NONE,
1872#else
1873 (char_u *)NULL, PV_NONE,
1874#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001875 {(char_u *)100L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001876 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1877 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001878 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001879 {"maxmem", "mm", P_NUM|P_VI_DEF,
1880 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001881 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001882 SCTX_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001883 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1884 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001885 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001886 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1887 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001888 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001889 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001890 {"menuitems", "mis", P_NUM|P_VI_DEF,
1891#ifdef FEAT_MENU
1892 (char_u *)&p_mis, PV_NONE,
1893#else
1894 (char_u *)NULL, PV_NONE,
1895#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001896 {(char_u *)25L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001897 {"mesg", NULL, P_BOOL|P_VI_DEF,
1898 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001899 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001900 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001901#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001902 (char_u *)&p_msm, PV_NONE,
1903 {(char_u *)"460000,2000,500", (char_u *)0L}
1904#else
1905 (char_u *)NULL, PV_NONE,
1906 {(char_u *)0L, (char_u *)0L}
1907#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001908 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001909 {"modeline", "ml", P_BOOL|P_VIM,
1910 (char_u *)&p_ml, PV_ML,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001911 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar7e800c62019-05-23 17:08:49 +02001912 {"modelineexpr", "mle", P_BOOL|P_VI_DEF|P_SECURE,
Bram Moolenaar110289e2019-05-23 15:38:06 +02001913 (char_u *)&p_mle, PV_NONE,
1914 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001915 {"modelines", "mls", P_NUM|P_VI_DEF,
1916 (char_u *)&p_mls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001917 {(char_u *)5L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001918 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1919 (char_u *)&p_ma, PV_MA,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001920 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001921 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1922 (char_u *)&p_mod, PV_MOD,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001923 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001924 {"more", NULL, P_BOOL|P_VIM,
1925 (char_u *)&p_more, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001926 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001927 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1928 (char_u *)&p_mouse, PV_NONE,
1929 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01001930#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001931 (char_u *)"a",
1932#else
1933 (char_u *)"",
1934#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001935 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001936 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1937#ifdef FEAT_GUI
1938 (char_u *)&p_mousef, PV_NONE,
1939#else
1940 (char_u *)NULL, PV_NONE,
1941#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001942 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001943 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1944#ifdef FEAT_GUI
1945 (char_u *)&p_mh, PV_NONE,
1946#else
1947 (char_u *)NULL, PV_NONE,
1948#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001949 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001950 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1951 (char_u *)&p_mousem, PV_NONE,
1952 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001953#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001954 (char_u *)"popup",
1955#else
Bram Moolenaard0573012017-10-28 21:11:06 +02001956# if defined(MACOS_X)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001957 (char_u *)"popup_setpos",
1958# else
1959 (char_u *)"extend",
1960# endif
1961#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001962 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001963 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001964#ifdef FEAT_MOUSESHAPE
1965 (char_u *)&p_mouseshape, PV_NONE,
1966 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1967#else
1968 (char_u *)NULL, PV_NONE,
1969 {(char_u *)NULL, (char_u *)0L}
1970#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001971 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001972 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1973 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001974 {(char_u *)500L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02001975 {"mzschemedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1976#if defined(DYNAMIC_MZSCHEME)
1977 (char_u *)&p_mzschemedll, PV_NONE,
1978 {(char_u *)DYNAMIC_MZSCH_DLL, (char_u *)0L}
1979#else
1980 (char_u *)NULL, PV_NONE,
1981 {(char_u *)"", (char_u *)0L}
1982#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001983 SCTX_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02001984 {"mzschemegcdll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1985#if defined(DYNAMIC_MZSCHEME)
1986 (char_u *)&p_mzschemegcdll, PV_NONE,
1987 {(char_u *)DYNAMIC_MZGC_DLL, (char_u *)0L}
1988#else
1989 (char_u *)NULL, PV_NONE,
1990 {(char_u *)"", (char_u *)0L}
1991#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001992 SCTX_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001993 {"mzquantum", "mzq", P_NUM,
1994#ifdef FEAT_MZSCHEME
1995 (char_u *)&p_mzq, PV_NONE,
1996#else
1997 (char_u *)NULL, PV_NONE,
1998#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001999 {(char_u *)100L, (char_u *)100L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002000 {"novice", NULL, P_BOOL|P_VI_DEF,
2001 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002002 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002003 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002004 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01002005 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002006 SCTX_INIT},
Bram Moolenaar2b044ff2019-06-24 05:45:14 +02002007 {"number", "nu", P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002008 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002009 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002010 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
2011#ifdef FEAT_LINEBREAK
2012 (char_u *)VAR_WIN, PV_NUW,
2013#else
2014 (char_u *)NULL, PV_NONE,
2015#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002016 {(char_u *)8L, (char_u *)4L} SCTX_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00002017 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00002018#ifdef FEAT_COMPL_FUNC
2019 (char_u *)&p_ofu, PV_OFU,
2020 {(char_u *)"", (char_u *)0L}
2021#else
2022 (char_u *)NULL, PV_NONE,
2023 {(char_u *)0L, (char_u *)0L}
2024#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002025 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002026 {"open", NULL, P_BOOL|P_VI_DEF,
2027 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002028 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002029 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002030#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002031 (char_u *)&p_odev, PV_NONE,
2032#else
2033 (char_u *)NULL, PV_NONE,
2034#endif
2035 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002036 SCTX_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002037 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2038 (char_u *)&p_opfunc, 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 {"optimize", "opt", P_BOOL|P_VI_DEF,
2041 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002042 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002043 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002044 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002045 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002046 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2047 |P_SECURE,
2048 (char_u *)&p_pp, PV_NONE,
2049 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002050 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002051 {"paragraphs", "para", P_STRING|P_VI_DEF,
2052 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002053 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002054 (char_u *)0L} SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002055 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002056 (char_u *)&p_paste, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002057 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002058 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2059 (char_u *)&p_pt, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002060 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002061 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2062#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2063 (char_u *)&p_pex, PV_NONE,
2064 {(char_u *)"", (char_u *)0L}
2065#else
2066 (char_u *)NULL, PV_NONE,
2067 {(char_u *)0L, (char_u *)0L}
2068#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002069 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002070 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002071 (char_u *)&p_pm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002072 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002073 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002074 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002075 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002076#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002077 (char_u *)".,,",
2078#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002079 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002080#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002081 (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002082 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002083#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002084 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002085 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002086#else
2087 (char_u *)NULL, PV_NONE,
2088 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002089#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002090 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002091 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2092 (char_u *)&p_pi, PV_PI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002093 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002094 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002095#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002096 (char_u *)&p_pvh, PV_NONE,
2097#else
2098 (char_u *)NULL, PV_NONE,
2099#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002100 {(char_u *)12L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar79648732019-07-18 21:43:07 +02002101 {"previewpopup", "pvp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2102#ifdef FEAT_TEXT_PROP
2103 (char_u *)&p_pvp, PV_NONE,
2104 {(char_u *)"", (char_u *)0L}
2105#else
2106 (char_u *)NULL, PV_NONE,
2107 {(char_u *)NULL, (char_u *)0L}
2108#endif
2109 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002110 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002111#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002112 (char_u *)VAR_WIN, PV_PVW,
2113#else
2114 (char_u *)NULL, PV_NONE,
2115#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002116 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002117 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002118#ifdef FEAT_PRINTER
2119 (char_u *)&p_pdev, PV_NONE,
2120 {(char_u *)"", (char_u *)0L}
2121#else
2122 (char_u *)NULL, PV_NONE,
2123 {(char_u *)NULL, (char_u *)0L}
2124#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002125 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002126 {"printencoding", "penc", P_STRING|P_VI_DEF,
2127#ifdef FEAT_POSTSCRIPT
2128 (char_u *)&p_penc, PV_NONE,
2129 {(char_u *)"", (char_u *)0L}
2130#else
2131 (char_u *)NULL, PV_NONE,
2132 {(char_u *)NULL, (char_u *)0L}
2133#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002134 SCTX_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002135 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002136#ifdef FEAT_POSTSCRIPT
2137 (char_u *)&p_pexpr, PV_NONE,
2138 {(char_u *)"", (char_u *)0L}
2139#else
2140 (char_u *)NULL, PV_NONE,
2141 {(char_u *)NULL, (char_u *)0L}
2142#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002143 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002144 {"printfont", "pfn", P_STRING|P_VI_DEF,
2145#ifdef FEAT_PRINTER
2146 (char_u *)&p_pfn, PV_NONE,
2147 {
2148# ifdef MSWIN
2149 (char_u *)"Courier_New:h10",
2150# else
2151 (char_u *)"courier",
2152# endif
2153 (char_u *)0L}
2154#else
2155 (char_u *)NULL, PV_NONE,
2156 {(char_u *)NULL, (char_u *)0L}
2157#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002158 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002159 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2160#ifdef FEAT_PRINTER
2161 (char_u *)&p_header, PV_NONE,
Bram Moolenaar0903d562017-08-26 22:30:15 +02002162 /* untranslated to avoid problems when 'encoding'
2163 * is changed */
2164 {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002165#else
2166 (char_u *)NULL, PV_NONE,
2167 {(char_u *)NULL, (char_u *)0L}
2168#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002169 SCTX_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002170 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01002171#if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002172 (char_u *)&p_pmcs, PV_NONE,
2173 {(char_u *)"", (char_u *)0L}
2174#else
2175 (char_u *)NULL, PV_NONE,
2176 {(char_u *)NULL, (char_u *)0L}
2177#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002178 SCTX_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002179 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01002180#if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002181 (char_u *)&p_pmfn, PV_NONE,
2182 {(char_u *)"", (char_u *)0L}
2183#else
2184 (char_u *)NULL, PV_NONE,
2185 {(char_u *)NULL, (char_u *)0L}
2186#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002187 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002188 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002189#ifdef FEAT_PRINTER
2190 (char_u *)&p_popt, PV_NONE,
2191 {(char_u *)"", (char_u *)0L}
2192#else
2193 (char_u *)NULL, PV_NONE,
2194 {(char_u *)NULL, (char_u *)0L}
2195#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002196 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002197 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002198 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002199 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002200 {"pumheight", "ph", P_NUM|P_VI_DEF,
2201#ifdef FEAT_INS_EXPAND
2202 (char_u *)&p_ph, PV_NONE,
2203#else
2204 (char_u *)NULL, PV_NONE,
2205#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002206 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaara8f04aa2018-02-10 15:36:55 +01002207 {"pumwidth", "pw", P_NUM|P_VI_DEF,
2208#ifdef FEAT_INS_EXPAND
2209 (char_u *)&p_pw, PV_NONE,
2210#else
2211 (char_u *)NULL, PV_NONE,
2212#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002213 {(char_u *)15L, (char_u *)15L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002214 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002215#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002216 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002217 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002218#else
2219 (char_u *)NULL, PV_NONE,
2220 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002221#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002222 SCTX_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002223 {"pythonthreehome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2224#if defined(FEAT_PYTHON3)
2225 (char_u *)&p_py3home, PV_NONE,
2226 {(char_u *)"", (char_u *)0L}
2227#else
2228 (char_u *)NULL, PV_NONE,
2229 {(char_u *)NULL, (char_u *)0L}
2230#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002231 SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002232 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002233#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002234 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002235 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002236#else
2237 (char_u *)NULL, PV_NONE,
2238 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002239#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002240 SCTX_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002241 {"pythonhome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2242#if defined(FEAT_PYTHON)
2243 (char_u *)&p_pyhome, PV_NONE,
2244 {(char_u *)"", (char_u *)0L}
2245#else
2246 (char_u *)NULL, PV_NONE,
2247 {(char_u *)NULL, (char_u *)0L}
2248#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002249 SCTX_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002250 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2251#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2252 (char_u *)&p_pyx, PV_NONE,
2253#else
2254 (char_u *)NULL, PV_NONE,
2255#endif
2256 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002257 SCTX_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002258 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2259#ifdef FEAT_TEXTOBJ
2260 (char_u *)&p_qe, PV_QE,
2261 {(char_u *)"\\", (char_u *)0L}
2262#else
2263 (char_u *)NULL, PV_NONE,
2264 {(char_u *)NULL, (char_u *)0L}
2265#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002266 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002267 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2268 (char_u *)&p_ro, PV_RO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002269 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002270 {"redraw", NULL, P_BOOL|P_VI_DEF,
2271 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002272 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002273 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2274#ifdef FEAT_RELTIME
2275 (char_u *)&p_rdt, PV_NONE,
2276#else
2277 (char_u *)NULL, PV_NONE,
2278#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002279 {(char_u *)2000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002280 {"regexpengine", "re", P_NUM|P_VI_DEF,
2281 (char_u *)&p_re, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002282 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar2b044ff2019-06-24 05:45:14 +02002283 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaar64486672010-05-16 15:46:46 +02002284 (char_u *)VAR_WIN, PV_RNU,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002285 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002286 {"remap", NULL, P_BOOL|P_VI_DEF,
2287 (char_u *)&p_remap, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002288 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002289 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002290#ifdef FEAT_RENDER_OPTIONS
2291 (char_u *)&p_rop, PV_NONE,
2292 {(char_u *)"", (char_u *)0L}
2293#else
2294 (char_u *)NULL, PV_NONE,
2295 {(char_u *)NULL, (char_u *)0L}
2296#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002297 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002298 {"report", NULL, P_NUM|P_VI_DEF,
2299 (char_u *)&p_report, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002300 {(char_u *)2L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002301 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
Bram Moolenaar4f974752019-02-17 17:44:42 +01002302#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00002303 (char_u *)&p_rs, PV_NONE,
2304#else
2305 (char_u *)NULL, PV_NONE,
2306#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002307 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002308 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2309#ifdef FEAT_RIGHTLEFT
2310 (char_u *)&p_ri, PV_NONE,
2311#else
2312 (char_u *)NULL, PV_NONE,
2313#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002314 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002315 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2316#ifdef FEAT_RIGHTLEFT
2317 (char_u *)VAR_WIN, PV_RL,
2318#else
2319 (char_u *)NULL, PV_NONE,
2320#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002321 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002322 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2323#ifdef FEAT_RIGHTLEFT
2324 (char_u *)VAR_WIN, PV_RLC,
2325 {(char_u *)"search", (char_u *)NULL}
2326#else
2327 (char_u *)NULL, PV_NONE,
2328 {(char_u *)NULL, (char_u *)0L}
2329#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002330 SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002331 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002332#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002333 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002334 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002335#else
2336 (char_u *)NULL, PV_NONE,
2337 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002338#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002339 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002340 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2341#ifdef FEAT_CMDL_INFO
2342 (char_u *)&p_ru, PV_NONE,
2343#else
2344 (char_u *)NULL, PV_NONE,
2345#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002346 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02002347 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002348#ifdef FEAT_STL_OPT
2349 (char_u *)&p_ruf, PV_NONE,
2350#else
2351 (char_u *)NULL, PV_NONE,
2352#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002353 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002354 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2355 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002356 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002357 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002358 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002359 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2360 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002361 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002362 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002363 (char_u *)VAR_WIN, PV_SCBIND,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002364 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002365 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2366 (char_u *)&p_sj, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002367 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002368 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
Bram Moolenaar375e3392019-01-31 18:26:10 +01002369 (char_u *)&p_so, PV_SO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002370 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002371 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002372 (char_u *)&p_sbo, PV_NONE,
2373 {(char_u *)"ver,jump", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002374 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002375 {"sections", "sect", P_STRING|P_VI_DEF,
2376 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002377 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002378 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002379 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2380 (char_u *)&p_secure, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002381 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002382 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002383 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002384 {(char_u *)"inclusive", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002385 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002386 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002387 (char_u *)&p_slm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002388 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002389 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002390#ifdef FEAT_SESSION
2391 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar4d8bac82018-03-09 21:33:34 +01002392 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize,terminal",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002393 (char_u *)0L}
2394#else
2395 (char_u *)NULL, PV_NONE,
2396 {(char_u *)0L, (char_u *)0L}
2397#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002398 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002399 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2400 (char_u *)&p_sh, PV_NONE,
2401 {
2402#ifdef VMS
2403 (char_u *)"-",
2404#else
Bram Moolenaar4f974752019-02-17 17:44:42 +01002405# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002406 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002407# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002408 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002409# endif
2410#endif /* VMS */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002411 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002412 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2413 (char_u *)&p_shcf, PV_NONE,
2414 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002415#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002416 (char_u *)"/c",
2417#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002418 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002419#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002420 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002421 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2422#ifdef FEAT_QUICKFIX
2423 (char_u *)&p_sp, PV_NONE,
2424 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002425#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002426 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002427#else
2428 (char_u *)">",
2429#endif
2430 (char_u *)0L}
2431#else
2432 (char_u *)NULL, PV_NONE,
2433 {(char_u *)0L, (char_u *)0L}
2434#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002435 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002436 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2437 (char_u *)&p_shq, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002438 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002439 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2440 (char_u *)&p_srr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002441 {(char_u *)">", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002442 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2443#ifdef BACKSLASH_IN_FILENAME
2444 (char_u *)&p_ssl, PV_NONE,
2445#else
2446 (char_u *)NULL, PV_NONE,
2447#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002448 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002449 {"shelltemp", "stmp", P_BOOL,
2450 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002451 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002452 {"shelltype", "st", P_NUM|P_VI_DEF,
2453#ifdef AMIGA
2454 (char_u *)&p_st, PV_NONE,
2455#else
2456 (char_u *)NULL, PV_NONE,
2457#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002458 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002459 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2460 (char_u *)&p_sxq, PV_NONE,
2461 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002462#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002463 (char_u *)"\"",
2464#else
2465 (char_u *)"",
2466#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002467 (char_u *)0L} SCTX_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002468 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2469 (char_u *)&p_sxe, PV_NONE,
2470 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01002471#if defined(MSWIN)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002472 (char_u *)"\"&|<>()@^",
2473#else
2474 (char_u *)"",
2475#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002476 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002477 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2478 (char_u *)&p_sr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002479 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002480 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2481 (char_u *)&p_sw, PV_SW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002482 {(char_u *)8L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002483 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2484 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar9dfa3132019-05-04 21:08:40 +02002485 {(char_u *)"S", (char_u *)"filnxtToOS"}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002486 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002487 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002488 (char_u *)&p_sn, PV_SN,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002489 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002490 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2491#ifdef FEAT_LINEBREAK
2492 (char_u *)&p_sbr, PV_NONE,
2493#else
2494 (char_u *)NULL, PV_NONE,
2495#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002496 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002497 {"showcmd", "sc", P_BOOL|P_VIM,
2498#ifdef FEAT_CMDL_INFO
2499 (char_u *)&p_sc, PV_NONE,
2500#else
2501 (char_u *)NULL, PV_NONE,
2502#endif
2503 {(char_u *)FALSE,
2504#ifdef UNIX
2505 (char_u *)FALSE
2506#else
2507 (char_u *)TRUE
2508#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002509 } SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002510 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2511 (char_u *)&p_sft, 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 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2514 (char_u *)&p_sm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002515 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002516 {"showmode", "smd", P_BOOL|P_VIM,
2517 (char_u *)&p_smd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002518 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002519 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002520 (char_u *)&p_stal, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002521 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002522 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2523 (char_u *)&p_ss, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002524 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002525 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar375e3392019-01-31 18:26:10 +01002526 (char_u *)&p_siso, PV_SISO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002527 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar2b044ff2019-06-24 05:45:14 +02002528 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RCLR,
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002529#ifdef FEAT_SIGNS
2530 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002531 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002532#else
2533 (char_u *)NULL, PV_NONE,
2534 {(char_u *)NULL, (char_u *)0L}
2535#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002536 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002537 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2538 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002539 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002540 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2541 (char_u *)&p_scs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002542 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002543 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2544#ifdef FEAT_SMARTINDENT
2545 (char_u *)&p_si, PV_SI,
2546#else
2547 (char_u *)NULL, PV_NONE,
2548#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002549 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002550 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2551 (char_u *)&p_sta, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002552 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002553 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2554 (char_u *)&p_sts, PV_STS,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002555 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002556 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2557 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002558 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002559 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002560#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002561 (char_u *)VAR_WIN, PV_SPELL,
2562#else
2563 (char_u *)NULL, PV_NONE,
2564#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002565 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002566 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002567#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002568 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002569 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002570#else
2571 (char_u *)NULL, PV_NONE,
2572 {(char_u *)0L, (char_u *)0L}
2573#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002574 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002575 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2576 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002577#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002578 (char_u *)&p_spf, PV_SPF,
2579 {(char_u *)"", (char_u *)0L}
2580#else
2581 (char_u *)NULL, PV_NONE,
2582 {(char_u *)0L, (char_u *)0L}
2583#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002584 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002585 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2586 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002587#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002588 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002589 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002590#else
2591 (char_u *)NULL, PV_NONE,
2592 {(char_u *)0L, (char_u *)0L}
2593#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002594 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002595 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002596#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002597 (char_u *)&p_sps, PV_NONE,
2598 {(char_u *)"best", (char_u *)0L}
2599#else
2600 (char_u *)NULL, PV_NONE,
2601 {(char_u *)0L, (char_u *)0L}
2602#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002603 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002604 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002605 (char_u *)&p_sb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002606 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002607 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002608 (char_u *)&p_spr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002609 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002610 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2611 (char_u *)&p_sol, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002612 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02002613 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002614#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002615 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002616#else
2617 (char_u *)NULL, PV_NONE,
2618#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002619 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002620 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002621 (char_u *)&p_su, PV_NONE,
2622 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002623 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002624 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002625#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002626 (char_u *)&p_sua, PV_SUA,
2627 {(char_u *)"", (char_u *)0L}
2628#else
2629 (char_u *)NULL, PV_NONE,
2630 {(char_u *)0L, (char_u *)0L}
2631#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002632 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002633 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2634 (char_u *)&p_swf, PV_SWF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002635 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002636 {"swapsync", "sws", P_STRING|P_VI_DEF,
2637 (char_u *)&p_sws, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002638 {(char_u *)"fsync", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002639 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002640 (char_u *)&p_swb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002641 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002642 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2643#ifdef FEAT_SYN_HL
2644 (char_u *)&p_smc, PV_SMC,
2645 {(char_u *)3000L, (char_u *)0L}
2646#else
2647 (char_u *)NULL, PV_NONE,
2648 {(char_u *)0L, (char_u *)0L}
2649#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002650 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002651 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002652#ifdef FEAT_SYN_HL
2653 (char_u *)&p_syn, PV_SYN,
2654 {(char_u *)"", (char_u *)0L}
2655#else
2656 (char_u *)NULL, PV_NONE,
2657 {(char_u *)0L, (char_u *)0L}
2658#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002659 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02002660 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL|P_MLE,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002661#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002662 (char_u *)&p_tal, PV_NONE,
2663#else
2664 (char_u *)NULL, PV_NONE,
2665#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002666 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002667 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002668 (char_u *)&p_tpm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002669 {(char_u *)10L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002670 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2671 (char_u *)&p_ts, PV_TS,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002672 {(char_u *)8L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002673 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2674 (char_u *)&p_tbs, PV_NONE,
2675#ifdef VMS /* binary searching doesn't appear to work on VMS */
2676 {(char_u *)0L, (char_u *)0L}
2677#else
2678 {(char_u *)TRUE, (char_u *)0L}
2679#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002680 SCTX_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002681 {"tagcase", "tc", P_STRING|P_VIM,
2682 (char_u *)&p_tc, PV_TC,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002683 {(char_u *)"followic", (char_u *)"followic"} SCTX_INIT},
Bram Moolenaar45e18cb2019-04-28 18:05:35 +02002684 {"tagfunc", "tfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
2685#ifdef FEAT_EVAL
2686 (char_u *)&p_tfu, PV_TFU,
2687 {(char_u *)"", (char_u *)0L}
2688#else
2689 (char_u *)NULL, PV_NONE,
2690 {(char_u *)0L, (char_u *)0L}
2691#endif
2692 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002693 {"taglength", "tl", P_NUM|P_VI_DEF,
2694 (char_u *)&p_tl, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002695 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002696 {"tagrelative", "tr", P_BOOL|P_VIM,
2697 (char_u *)&p_tr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002698 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002699 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002700 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002701 {
2702#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2703 (char_u *)"./tags,./TAGS,tags,TAGS",
2704#else
2705 (char_u *)"./tags,tags",
2706#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002707 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002708 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2709 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002710 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002711 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002712#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002713 (char_u *)&p_tcldll, PV_NONE,
2714 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002715#else
2716 (char_u *)NULL, PV_NONE,
2717 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002718#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002719 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002720 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2721 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002722 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002723 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2724#ifdef FEAT_ARABIC
2725 (char_u *)&p_tbidi, PV_NONE,
2726#else
2727 (char_u *)NULL, PV_NONE,
2728#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002729 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002730 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002731 (char_u *)&p_tenc, PV_NONE,
2732 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002733 SCTX_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002734 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2735#ifdef FEAT_TERMGUICOLORS
2736 (char_u *)&p_tgc, PV_NONE,
2737 {(char_u *)FALSE, (char_u *)FALSE}
2738#else
2739 (char_u*)NULL, PV_NONE,
2740 {(char_u *)FALSE, (char_u *)FALSE}
2741#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002742 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002743 {"termwinkey", "twk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2744#ifdef FEAT_TERMINAL
2745 (char_u *)VAR_WIN, PV_TWK,
2746 {(char_u *)"", (char_u *)NULL}
2747#else
2748 (char_u *)NULL, PV_NONE,
2749 {(char_u *)NULL, (char_u *)0L}
2750#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002751 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002752 {"termwinscroll", "twsl", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2753#ifdef FEAT_TERMINAL
2754 (char_u *)&p_twsl, PV_TWSL,
2755 {(char_u *)10000L, (char_u *)10000L}
2756#else
2757 (char_u *)NULL, PV_NONE,
2758 {(char_u *)NULL, (char_u *)0L}
2759#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002760 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002761 {"termwinsize", "tws", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2762#ifdef FEAT_TERMINAL
2763 (char_u *)VAR_WIN, PV_TWS,
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002764 {(char_u *)"", (char_u *)NULL}
2765#else
2766 (char_u *)NULL, PV_NONE,
2767 {(char_u *)NULL, (char_u *)0L}
2768#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002769 SCTX_INIT},
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01002770 {"termwintype", "twt", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar4f974752019-02-17 17:44:42 +01002771#if defined(MSWIN) && defined(FEAT_TERMINAL)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01002772 (char_u *)&p_twt, PV_NONE,
2773 {(char_u *)"", (char_u *)NULL}
2774#else
2775 (char_u *)NULL, PV_NONE,
2776 {(char_u *)NULL, (char_u *)0L}
2777#endif
2778 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002779 {"terse", NULL, P_BOOL|P_VI_DEF,
2780 (char_u *)&p_terse, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002781 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002782 {"textauto", "ta", P_BOOL|P_VIM,
2783 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002784 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002785 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002786 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2787 (char_u *)&p_tx, PV_TX,
2788 {
2789#ifdef USE_CRNL
2790 (char_u *)TRUE,
2791#else
2792 (char_u *)FALSE,
2793#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002794 (char_u *)0L} SCTX_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002795 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002796 (char_u *)&p_tw, PV_TW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002797 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002798 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002799#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002800 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002801#else
2802 (char_u *)NULL, PV_NONE,
2803#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002804 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002805 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2806 (char_u *)&p_to, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002807 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002808 {"timeout", "to", P_BOOL|P_VI_DEF,
2809 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002810 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002811 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2812 (char_u *)&p_tm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002813 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002814 {"title", NULL, P_BOOL|P_VI_DEF,
2815#ifdef FEAT_TITLE
2816 (char_u *)&p_title, PV_NONE,
2817#else
2818 (char_u *)NULL, PV_NONE,
2819#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002820 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002821 {"titlelen", NULL, P_NUM|P_VI_DEF,
2822#ifdef FEAT_TITLE
2823 (char_u *)&p_titlelen, PV_NONE,
2824#else
2825 (char_u *)NULL, PV_NONE,
2826#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002827 {(char_u *)85L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002828 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002829#ifdef FEAT_TITLE
2830 (char_u *)&p_titleold, PV_NONE,
2831 {(char_u *)N_("Thanks for flying Vim"),
2832 (char_u *)0L}
2833#else
2834 (char_u *)NULL, PV_NONE,
2835 {(char_u *)0L, (char_u *)0L}
2836#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002837 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02002838 {"titlestring", NULL, P_STRING|P_VI_DEF|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002839#ifdef FEAT_TITLE
2840 (char_u *)&p_titlestring, PV_NONE,
2841#else
2842 (char_u *)NULL, PV_NONE,
2843#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002844 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002845 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar4f974752019-02-17 17:44:42 +01002846#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002847 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002848 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002849#else
2850 (char_u *)NULL, PV_NONE,
2851 {(char_u *)0L, (char_u *)0L}
2852#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002853 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002854 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002855#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002856 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002857 {(char_u *)"small", (char_u *)0L}
2858#else
2859 (char_u *)NULL, PV_NONE,
2860 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002861#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002862 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002863 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2864 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002865 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002866 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2867 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002868 {(char_u *)-1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002869 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2870 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002871 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002872 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2873 (char_u *)&p_tf, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002874 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002875 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2876#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2877 (char_u *)&p_ttym, PV_NONE,
2878#else
2879 (char_u *)NULL, PV_NONE,
2880#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002881 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002882 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2883 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002884 {(char_u *)999L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002885 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2886 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002887 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002888 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2889 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002890#ifdef FEAT_PERSISTENT_UNDO
2891 (char_u *)&p_udir, PV_NONE,
2892 {(char_u *)".", (char_u *)0L}
2893#else
2894 (char_u *)NULL, PV_NONE,
2895 {(char_u *)0L, (char_u *)0L}
2896#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002897 SCTX_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002898 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2899#ifdef FEAT_PERSISTENT_UNDO
2900 (char_u *)&p_udf, PV_UDF,
2901#else
2902 (char_u *)NULL, PV_NONE,
2903#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002904 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002905 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002906 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002907 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01002908#if defined(UNIX) || defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002909 (char_u *)1000L,
2910#else
2911 (char_u *)100L,
2912#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002913 (char_u *)0L} SCTX_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002914 {"undoreload", "ur", P_NUM|P_VI_DEF,
2915 (char_u *)&p_ur, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002916 { (char_u *)10000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002917 {"updatecount", "uc", P_NUM|P_VI_DEF,
2918 (char_u *)&p_uc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002919 {(char_u *)200L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002920 {"updatetime", "ut", P_NUM|P_VI_DEF,
2921 (char_u *)&p_ut, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002922 {(char_u *)4000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar04958cb2018-06-23 19:23:02 +02002923 {"varsofttabstop", "vsts", P_STRING|P_VI_DEF|P_VIM|P_COMMA,
2924#ifdef FEAT_VARTABS
2925 (char_u *)&p_vsts, PV_VSTS,
2926 {(char_u *)"", (char_u *)0L}
2927#else
2928 (char_u *)NULL, PV_NONE,
2929 {(char_u *)"", (char_u *)NULL}
2930#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002931 SCTX_INIT},
Bram Moolenaar04958cb2018-06-23 19:23:02 +02002932 {"vartabstop", "vts", P_STRING|P_VI_DEF|P_VIM|P_RBUF|P_COMMA,
2933#ifdef FEAT_VARTABS
2934 (char_u *)&p_vts, PV_VTS,
2935 {(char_u *)"", (char_u *)0L}
2936#else
2937 (char_u *)NULL, PV_NONE,
2938 {(char_u *)"", (char_u *)NULL}
2939#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002940 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002941 {"verbose", "vbs", P_NUM|P_VI_DEF,
2942 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002943 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002944 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2945 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002946 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002947 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2948#ifdef FEAT_SESSION
2949 (char_u *)&p_vdir, PV_NONE,
2950 {(char_u *)DFLT_VDIR, (char_u *)0L}
2951#else
2952 (char_u *)NULL, PV_NONE,
2953 {(char_u *)0L, (char_u *)0L}
2954#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002955 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002956 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002957#ifdef FEAT_SESSION
2958 (char_u *)&p_vop, PV_NONE,
Bram Moolenaar13e90412017-11-11 18:16:48 +01002959 {(char_u *)"folds,options,cursor,curdir",
2960 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002961#else
2962 (char_u *)NULL, PV_NONE,
2963 {(char_u *)0L, (char_u *)0L}
2964#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002965 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002966 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002967#ifdef FEAT_VIMINFO
2968 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002969#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002970 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002971#else
2972# ifdef AMIGA
2973 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002974 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002975# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002976 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002977# endif
2978#endif
2979#else
2980 (char_u *)NULL, PV_NONE,
2981 {(char_u *)0L, (char_u *)0L}
2982#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002983 SCTX_INIT},
Bram Moolenaarc229e542018-07-08 21:46:56 +02002984 {"viminfofile", "vif", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP
2985 |P_SECURE|P_VI_DEF,
Bram Moolenaarc4da1132017-07-15 19:39:43 +02002986#ifdef FEAT_VIMINFO
2987 (char_u *)&p_viminfofile, PV_NONE,
2988 {(char_u *)"", (char_u *)0L}
2989#else
2990 (char_u *)NULL, PV_NONE,
2991 {(char_u *)0L, (char_u *)0L}
2992#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002993 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002994 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2995 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002996 (char_u *)&p_ve, PV_NONE,
2997 {(char_u *)"", (char_u *)""}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002998 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002999 {"visualbell", "vb", P_BOOL|P_VI_DEF,
3000 (char_u *)&p_vb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003001 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003002 {"w300", NULL, P_NUM|P_VI_DEF,
3003 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003004 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003005 {"w1200", NULL, P_NUM|P_VI_DEF,
3006 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003007 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003008 {"w9600", NULL, P_NUM|P_VI_DEF,
3009 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003010 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003011 {"warn", NULL, P_BOOL|P_VI_DEF,
3012 (char_u *)&p_warn, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003013 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003014 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
3015 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003016 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003017 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003018 (char_u *)&p_ww, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003019 {(char_u *)"", (char_u *)"b,s"} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003020 {"wildchar", "wc", P_NUM|P_VIM,
3021 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003022 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003023 SCTX_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003024 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003025 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003026 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003027 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003028#ifdef FEAT_WILDIGN
3029 (char_u *)&p_wig, PV_NONE,
3030#else
3031 (char_u *)NULL, PV_NONE,
3032#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003033 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003034 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3035 (char_u *)&p_wic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003036 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003037 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
3038#ifdef FEAT_WILDMENU
3039 (char_u *)&p_wmnu, PV_NONE,
3040#else
3041 (char_u *)NULL, PV_NONE,
3042#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003043 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003044 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003045 (char_u *)&p_wim, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003046 {(char_u *)"full", (char_u *)0L} SCTX_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003047 {"wildoptions", "wop", P_STRING|P_VI_DEF,
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003048 (char_u *)&p_wop, PV_NONE,
3049 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003050 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003051 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3052#ifdef FEAT_WAK
3053 (char_u *)&p_wak, PV_NONE,
3054 {(char_u *)"menu", (char_u *)0L}
3055#else
3056 (char_u *)NULL, PV_NONE,
3057 {(char_u *)NULL, (char_u *)0L}
3058#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003059 SCTX_INIT},
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003060 {"wincolor", "wcr", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
3061 (char_u *)VAR_WIN, PV_WCR,
3062 {(char_u *)"", (char_u *)NULL}
3063 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003064 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003065 (char_u *)&p_window, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003066 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003067 {"winheight", "wh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003068 (char_u *)&p_wh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003069 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003070 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003071 (char_u *)VAR_WIN, PV_WFH,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003072 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003073 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003074 (char_u *)VAR_WIN, PV_WFW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003075 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003076 {"winminheight", "wmh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003077 (char_u *)&p_wmh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003078 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003079 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003080 (char_u *)&p_wmw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003081 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003082 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar4f974752019-02-17 17:44:42 +01003083#if defined(MSWIN) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003084 (char_u *)&p_winptydll, PV_NONE, {
3085# ifdef _WIN64
3086 (char_u *)"winpty64.dll",
3087# else
3088 (char_u *)"winpty32.dll",
3089# endif
3090 (char_u *)0L}
3091#else
3092 (char_u *)NULL, PV_NONE,
3093 {(char_u *)0L, (char_u *)0L}
3094#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003095 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003096 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003097 (char_u *)&p_wiw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003098 {(char_u *)20L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003099 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3100 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003101 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003102 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3103 (char_u *)&p_wm, PV_WM,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003104 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003105 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3106 (char_u *)&p_ws, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003107 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003108 {"write", NULL, P_BOOL|P_VI_DEF,
3109 (char_u *)&p_write, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003110 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003111 {"writeany", "wa", P_BOOL|P_VI_DEF,
3112 (char_u *)&p_wa, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003113 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003114 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3115 (char_u *)&p_wb, PV_NONE,
3116 {
3117#ifdef FEAT_WRITEBACKUP
3118 (char_u *)TRUE,
3119#else
3120 (char_u *)FALSE,
3121#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003122 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003123 {"writedelay", "wd", P_NUM|P_VI_DEF,
3124 (char_u *)&p_wd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003125 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003126
3127/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003128#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003129 (char_u *)&vvv, PV_NONE, \
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003130 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003131
3132 p_term("t_AB", T_CAB)
3133 p_term("t_AF", T_CAF)
3134 p_term("t_AL", T_CAL)
3135 p_term("t_al", T_AL)
3136 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003137 p_term("t_BE", T_BE)
3138 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003139 p_term("t_cd", T_CD)
3140 p_term("t_ce", T_CE)
3141 p_term("t_cl", T_CL)
3142 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003143 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003144 p_term("t_Co", T_CCO)
3145 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003146 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003147 p_term("t_cs", T_CS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003148 p_term("t_CV", T_CSV)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003149 p_term("t_da", T_DA)
3150 p_term("t_db", T_DB)
3151 p_term("t_DL", T_CDL)
3152 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003153 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003154 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003155 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003156 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003157 p_term("t_IE", T_CIE)
3158 p_term("t_IS", T_CIS)
3159 p_term("t_ke", T_KE)
3160 p_term("t_ks", T_KS)
3161 p_term("t_le", T_LE)
3162 p_term("t_mb", T_MB)
3163 p_term("t_md", T_MD)
3164 p_term("t_me", T_ME)
3165 p_term("t_mr", T_MR)
3166 p_term("t_ms", T_MS)
3167 p_term("t_nd", T_ND)
3168 p_term("t_op", T_OP)
Bram Moolenaara20f83d2017-10-15 13:35:01 +02003169 p_term("t_RF", T_RFG)
Bram Moolenaare5401222015-06-25 19:16:56 +02003170 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003171 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003172 p_term("t_RI", T_CRI)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003173 p_term("t_Ri", T_SRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003174 p_term("t_RS", T_CRS)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003175 p_term("t_RT", T_CRT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003176 p_term("t_RV", T_CRV)
3177 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003178 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003179 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003180 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003181 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003182 p_term("t_SI", T_CSI)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003183 p_term("t_Si", T_SSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003184 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003185 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003186 p_term("t_sr", T_SR)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003187 p_term("t_ST", T_CST)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003188 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003189 p_term("t_te", T_TE)
3190 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003191 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003192 p_term("t_ts", T_TS)
3193 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003194 p_term("t_ue", T_UE)
3195 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003196 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003197 p_term("t_vb", T_VB)
3198 p_term("t_ve", T_VE)
3199 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003200 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003201 p_term("t_vs", T_VS)
3202 p_term("t_WP", T_CWP)
3203 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003204 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003205 p_term("t_xs", T_XS)
3206 p_term("t_ZH", T_CZH)
3207 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003208 p_term("t_8f", T_8F)
3209 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003210
3211/* terminal key codes are not in here */
3212
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003213 /* end marker */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003214 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCTX_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003215};
3216
3217#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3218
Bram Moolenaar071d4272004-06-13 20:20:40 +00003219static char *(p_ambw_values[]) = {"single", "double", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003220static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003221static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003222static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003223#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003224static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003225#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003226static char *(p_wop_values[]) = {"tagfile", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003227#ifdef FEAT_WAK
3228static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3229#endif
3230static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003231static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3232static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003233static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003234#ifdef FEAT_BROWSE
3235static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3236#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003237static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
Bram Moolenaar57657d82006-04-21 22:12:41 +00003238static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003239static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003240static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", "prompt", "popup", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003241static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003242static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3243#ifdef FEAT_FOLDING
3244static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003245# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003246 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003247# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003248 NULL};
3249static char *(p_fcl_values[]) = {"all", NULL};
3250#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003251#ifdef FEAT_INS_EXPAND
Bram Moolenaar576a4a62019-08-18 15:25:17 +02003252static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "popup", "noinsert", "noselect", NULL};
Bram Moolenaarac3150d2019-07-28 16:36:39 +02003253# ifdef BACKSLASH_IN_FILENAME
3254static char *(p_csl_values[]) = {"slash", "backslash", NULL};
3255# endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003256#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003257#ifdef FEAT_SIGNS
Bram Moolenaar394c5d82019-06-17 21:48:05 +02003258static char *(p_scl_values[]) = {"yes", "no", "auto", "number", NULL};
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003259#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01003260#if defined(MSWIN) && defined(FEAT_TERMINAL)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01003261static char *(p_twt_values[]) = {"winpty", "conpty", "", NULL};
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01003262#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003263
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003264static void set_options_default(int opt_flags);
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003265static void set_string_default_esc(char *name, char_u *val, int escape);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003266static char_u *term_bg_default(void);
Bram Moolenaar916a8182018-11-25 02:18:29 +01003267static void did_set_option(int opt_idx, int opt_flags, int new_value, int value_checked);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003268static char_u *option_expand(int opt_idx, char_u *val);
3269static void didset_options(void);
3270static void didset_options2(void);
3271static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003272#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003273static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003274#else
3275# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3276#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003277static void set_string_option_global(int opt_idx, char_u **varp);
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003278static 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);
3279static char *set_chars_option(char_u **varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003280#ifdef FEAT_CLIPBOARD
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003281static char *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003282#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003283#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003284static char *did_set_spell_option(int is_spellfile);
3285static char *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003286#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003287#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003288static void set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003289#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003290static char *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3291static 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 +01003292static void check_redraw(long_u flags);
3293static int findoption(char_u *);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02003294static int find_key_option(char_u *arg_arg, int has_lt);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003295static void showoptions(int all, int opt_flags);
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02003296static int optval_default(struct vimoption *, char_u *varp, int compatible);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003297static void showoneopt(struct vimoption *, int opt_flags);
Bram Moolenaared18f2c2019-01-24 20:30:52 +01003298static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, long_u flags);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003299static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3300static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3301static int istermoption(struct vimoption *);
3302static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3303static char_u *get_varp(struct vimoption *);
3304static void option_value2string(struct vimoption *, int opt_flags);
3305static void check_winopt(winopt_T *wop);
3306static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003307#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003308static void langmap_init(void);
3309static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003310#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003311static void paste_option_changed(void);
3312static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003313#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003314static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003315#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003316static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3317static int check_opt_strings(char_u *val, char **values, int);
3318static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003319#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003320static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003321#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003322
3323/*
3324 * Initialize the options, first part.
3325 *
3326 * Called only once from main(), just after creating the first buffer.
Bram Moolenaar07268702018-03-01 21:57:32 +01003327 * If "clean_arg" is TRUE Vim was started with --clean.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003328 */
3329 void
Bram Moolenaar07268702018-03-01 21:57:32 +01003330set_init_1(int clean_arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003331{
3332 char_u *p;
3333 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003334 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003335
3336#ifdef FEAT_LANGMAP
3337 langmap_init();
3338#endif
3339
3340 /* Be Vi compatible by default */
3341 p_cp = TRUE;
3342
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003343 /* Use POSIX compatibility when $VIM_POSIX is set. */
3344 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003345 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003346 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar9dfa3132019-05-04 21:08:40 +02003347 set_string_default("shm", (char_u *)SHM_POSIX);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003348 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003349
Bram Moolenaar071d4272004-06-13 20:20:40 +00003350 /*
3351 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003352 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003353 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003354 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003355#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003356 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003357 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003358#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003359 )
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003360 set_string_default_esc("sh", p, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003361
3362#ifdef FEAT_WILDIGN
3363 /*
3364 * Set the default for 'backupskip' to include environment variables for
3365 * temp files.
3366 */
3367 {
3368# ifdef UNIX
3369 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3370# else
3371 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3372# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003373 int len;
3374 garray_T ga;
3375 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003376
3377 ga_init2(&ga, 1, 100);
3378 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3379 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003380 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003381# ifdef UNIX
3382 if (*names[n] == NUL)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003383# ifdef MACOS_X
3384 p = (char_u *)"/private/tmp";
3385# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003386 p = (char_u *)"/tmp";
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003387# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003388 else
3389# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003390 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003391 if (p != NULL && *p != NUL)
3392 {
3393 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003394 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003395 if (ga_grow(&ga, len) == OK)
3396 {
3397 if (ga.ga_len > 0)
3398 STRCAT(ga.ga_data, ",");
3399 STRCAT(ga.ga_data, p);
3400 add_pathsep(ga.ga_data);
3401 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003402 ga.ga_len += len;
3403 }
3404 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003405 if (mustfree)
3406 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003407 }
3408 if (ga.ga_data != NULL)
3409 {
3410 set_string_default("bsk", ga.ga_data);
3411 vim_free(ga.ga_data);
3412 }
3413 }
3414#endif
3415
3416 /*
3417 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3418 */
3419 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003420 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003421 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003422#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3423 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3424#endif
3425 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003426#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003427 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003428 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003429#else
3430# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003431 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003432 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003433# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003434 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003435# endif
3436#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003437 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003438 opt_idx = findoption((char_u *)"maxmem");
3439 if (opt_idx >= 0)
3440 {
3441#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003442 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3443 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003444#endif
3445 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3446 }
3447 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003448 }
3449
Bram Moolenaar071d4272004-06-13 20:20:40 +00003450#ifdef FEAT_SEARCHPATH
3451 {
3452 char_u *cdpath;
3453 char_u *buf;
3454 int i;
3455 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003456 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003457
3458 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003459 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003460 if (cdpath != NULL)
3461 {
Bram Moolenaar964b3742019-05-24 18:54:09 +02003462 buf = alloc((STRLEN(cdpath) << 1) + 2);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003463 if (buf != NULL)
3464 {
3465 buf[0] = ','; /* start with ",", current dir first */
3466 j = 1;
3467 for (i = 0; cdpath[i] != NUL; ++i)
3468 {
3469 if (vim_ispathlistsep(cdpath[i]))
3470 buf[j++] = ',';
3471 else
3472 {
3473 if (cdpath[i] == ' ' || cdpath[i] == ',')
3474 buf[j++] = '\\';
3475 buf[j++] = cdpath[i];
3476 }
3477 }
3478 buf[j] = NUL;
3479 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003480 if (opt_idx >= 0)
3481 {
3482 options[opt_idx].def_val[VI_DEFAULT] = buf;
3483 options[opt_idx].flags |= P_DEF_ALLOCED;
3484 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003485 else
3486 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003487 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003488 if (mustfree)
3489 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003490 }
3491 }
3492#endif
3493
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003494#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003495 /* Set print encoding on platforms that don't default to latin1 */
3496 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003497# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003498 (char_u *)"cp1252"
3499# else
3500# ifdef VMS
3501 (char_u *)"dec-mcs"
3502# else
3503# ifdef EBCDIC
3504 (char_u *)"ebcdic-uk"
3505# else
3506# ifdef MAC
3507 (char_u *)"mac-roman"
3508# else /* HPUX */
3509 (char_u *)"hp-roman8"
3510# endif
3511# endif
3512# endif
3513# endif
3514 );
3515#endif
3516
3517#ifdef FEAT_POSTSCRIPT
3518 /* 'printexpr' must be allocated to be able to evaluate it. */
3519 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003520# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003521 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003522# else
3523# ifdef VMS
3524 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3525
3526# else
3527 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3528# endif
3529# endif
3530 );
3531#endif
3532
3533 /*
3534 * Set all the options (except the terminal options) to their default
3535 * value. Also set the global value for local options.
3536 */
3537 set_options_default(0);
3538
Bram Moolenaar07268702018-03-01 21:57:32 +01003539#ifdef CLEAN_RUNTIMEPATH
3540 if (clean_arg)
3541 {
3542 opt_idx = findoption((char_u *)"runtimepath");
3543 if (opt_idx >= 0)
3544 {
3545 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3546 p_rtp = (char_u *)CLEAN_RUNTIMEPATH;
3547 }
3548 opt_idx = findoption((char_u *)"packpath");
3549 if (opt_idx >= 0)
3550 {
3551 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3552 p_pp = (char_u *)CLEAN_RUNTIMEPATH;
3553 }
3554 }
3555#endif
3556
Bram Moolenaar071d4272004-06-13 20:20:40 +00003557#ifdef FEAT_GUI
3558 if (found_reverse_arg)
3559 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3560#endif
3561
3562 curbuf->b_p_initialized = TRUE;
3563 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003564 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003565 check_buf_options(curbuf);
3566 check_win_options(curwin);
3567 check_options();
3568
3569 /* Must be before option_expand(), because that one needs vim_isIDc() */
3570 didset_options();
3571
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003572#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003573 /* Use the current chartab for the generic chartab. This is not in
3574 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003575 init_spell_chartab();
3576#endif
3577
Bram Moolenaar071d4272004-06-13 20:20:40 +00003578 /*
3579 * Expand environment variables and things like "~" for the defaults.
3580 * If option_expand() returns non-NULL the variable is expanded. This can
3581 * only happen for non-indirect options.
3582 * Also set the default to the expanded value, so ":set" does not list
3583 * them.
3584 * Don't set the P_ALLOCED flag, because we don't want to free the
3585 * default.
3586 */
3587 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3588 {
3589 if ((options[opt_idx].flags & P_GETTEXT)
3590 && options[opt_idx].var != NULL)
3591 p = (char_u *)_(*(char **)options[opt_idx].var);
3592 else
3593 p = option_expand(opt_idx, NULL);
3594 if (p != NULL && (p = vim_strsave(p)) != NULL)
3595 {
3596 *(char_u **)options[opt_idx].var = p;
3597 /* VIMEXP
3598 * Defaults for all expanded options are currently the same for Vi
3599 * and Vim. When this changes, add some code here! Also need to
3600 * split P_DEF_ALLOCED in two.
3601 */
3602 if (options[opt_idx].flags & P_DEF_ALLOCED)
3603 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3604 options[opt_idx].def_val[VI_DEFAULT] = p;
3605 options[opt_idx].flags |= P_DEF_ALLOCED;
3606 }
3607 }
3608
Bram Moolenaar071d4272004-06-13 20:20:40 +00003609 save_file_ff(curbuf); /* Buffer is unchanged */
3610
Bram Moolenaar071d4272004-06-13 20:20:40 +00003611#if defined(FEAT_ARABIC)
3612 /* Detect use of mlterm.
3613 * Mlterm is a terminal emulator akin to xterm that has some special
3614 * abilities (bidi namely).
3615 * NOTE: mlterm's author is being asked to 'set' a variable
3616 * instead of an environment variable due to inheritance.
3617 */
3618 if (mch_getenv((char_u *)"MLTERM") != NULL)
3619 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3620#endif
3621
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003622 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003623
Bram Moolenaar4f974752019-02-17 17:44:42 +01003624# if defined(MSWIN) && defined(FEAT_GETTEXT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003625 /*
3626 * If $LANG isn't set, try to get a good value for it. This makes the
3627 * right language be used automatically. Don't do this for English.
3628 */
3629 if (mch_getenv((char_u *)"LANG") == NULL)
3630 {
3631 char buf[20];
3632
3633 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3634 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3635 * only the first two. */
3636 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3637 (LPTSTR)buf, 20);
3638 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3639 {
3640 /* There are a few exceptions (probably more) */
3641 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3642 STRCPY(buf, "zh_TW");
3643 else if (STRNICMP(buf, "chs", 3) == 0
3644 || STRNICMP(buf, "zhc", 3) == 0)
3645 STRCPY(buf, "zh_CN");
3646 else if (STRNICMP(buf, "jp", 2) == 0)
3647 STRCPY(buf, "ja");
3648 else
3649 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003650 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003651 }
3652 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003653# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003654# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003655 /* Moved to os_mac_conv.c to avoid dependency problems. */
3656 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003657# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003658# endif
3659
3660 /* enc_locale() will try to find the encoding of the current locale. */
3661 p = enc_locale();
3662 if (p != NULL)
3663 {
3664 char_u *save_enc;
3665
3666 /* Try setting 'encoding' and check if the value is valid.
3667 * If not, go back to the default "latin1". */
3668 save_enc = p_enc;
3669 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003670 if (STRCMP(p_enc, "gb18030") == 0)
3671 {
3672 /* We don't support "gb18030", but "cp936" is a good substitute
3673 * for practical purposes, thus use that. It's not an alias to
3674 * still support conversion between gb18030 and utf-8. */
3675 p_enc = vim_strsave((char_u *)"cp936");
3676 vim_free(p);
3677 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003678 if (mb_init() == NULL)
3679 {
3680 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003681 if (opt_idx >= 0)
3682 {
3683 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3684 options[opt_idx].flags |= P_DEF_ALLOCED;
3685 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003686
Bram Moolenaard0573012017-10-28 21:11:06 +02003687#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003688 if (STRCMP(p_enc, "latin1") == 0 || enc_utf8)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003689 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003690 /* Adjust the default for 'isprint' and 'iskeyword' to match
3691 * latin1. Also set the defaults for when 'nocompatible' is
3692 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003693 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003694 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003695 set_string_option_direct((char_u *)"isk", -1,
3696 ISK_LATIN1, OPT_FREE, SID_NONE);
3697 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003698 if (opt_idx >= 0)
3699 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003700 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003701 if (opt_idx >= 0)
3702 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003703 (void)init_chartab();
3704 }
3705#endif
3706
Bram Moolenaarafde13b2019-04-28 19:46:49 +02003707#if defined(MSWIN) && (!defined(FEAT_GUI) || defined(VIMDLL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003708 /* Win32 console: When GetACP() returns a different value from
3709 * GetConsoleCP() set 'termencoding'. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02003710 if (
3711# ifdef VIMDLL
3712 (!gui.in_use && !gui.starting) &&
3713# endif
3714 GetACP() != GetConsoleCP())
Bram Moolenaar071d4272004-06-13 20:20:40 +00003715 {
3716 char buf[50];
3717
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01003718 /* Win32 console: In ConPTY, GetConsoleCP() returns zero.
3719 * Use an alternative value. */
3720 if (GetConsoleCP() == 0)
3721 sprintf(buf, "cp%ld", (long)GetACP());
3722 else
3723 sprintf(buf, "cp%ld", (long)GetConsoleCP());
Bram Moolenaar071d4272004-06-13 20:20:40 +00003724 p_tenc = vim_strsave((char_u *)buf);
3725 if (p_tenc != NULL)
3726 {
3727 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003728 if (opt_idx >= 0)
3729 {
3730 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3731 options[opt_idx].flags |= P_DEF_ALLOCED;
3732 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003733 convert_setup(&input_conv, p_tenc, p_enc);
3734 convert_setup(&output_conv, p_enc, p_tenc);
3735 }
3736 else
3737 p_tenc = empty_option;
3738 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003739#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01003740#if defined(MSWIN)
Bram Moolenaar05159a02005-02-26 23:04:13 +00003741 /* $HOME may have characters in active code page. */
3742 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003743#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003744 }
3745 else
3746 {
3747 vim_free(p_enc);
3748 p_enc = save_enc;
3749 }
3750 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003751
3752#ifdef FEAT_MULTI_LANG
3753 /* Set the default for 'helplang'. */
3754 set_helplang_default(get_mess_lang());
3755#endif
3756}
3757
3758/*
3759 * Set an option to its default value.
3760 * This does not take care of side effects!
3761 */
3762 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003763set_option_default(
3764 int opt_idx,
3765 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3766 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003767{
3768 char_u *varp; /* pointer to variable for current option */
3769 int dvi; /* index in def_val[] */
3770 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003771 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003772 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3773
3774 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3775 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003776 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003777 {
3778 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3779 if (flags & P_STRING)
3780 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003781 /* Use set_string_option_direct() for local options to handle
3782 * freeing and allocating the value. */
3783 if (options[opt_idx].indir != PV_NONE)
3784 set_string_option_direct(NULL, opt_idx,
3785 options[opt_idx].def_val[dvi], opt_flags, 0);
3786 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003787 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003788 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3789 free_string_option(*(char_u **)(varp));
3790 *(char_u **)varp = options[opt_idx].def_val[dvi];
3791 options[opt_idx].flags &= ~P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003792 }
3793 }
3794 else if (flags & P_NUM)
3795 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003796 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003797 win_comp_scroll(curwin);
3798 else
3799 {
Bram Moolenaar375e3392019-01-31 18:26:10 +01003800 long def_val = (long)(long_i)options[opt_idx].def_val[dvi];
3801
3802 if ((long *)varp == &curwin->w_p_so
3803 || (long *)varp == &curwin->w_p_siso)
3804 // 'scrolloff' and 'sidescrolloff' local values have a
3805 // different default value than the global default.
3806 *(long *)varp = -1;
3807 else
3808 *(long *)varp = def_val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003809 /* May also set global value for local option. */
3810 if (both)
3811 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
Bram Moolenaar375e3392019-01-31 18:26:10 +01003812 def_val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003813 }
3814 }
3815 else /* P_BOOL */
3816 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003817 /* the cast to long is required for Manx C, long_i is needed for
3818 * MSVC */
3819 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003820#ifdef UNIX
3821 /* 'modeline' defaults to off for root */
3822 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3823 *(int *)varp = FALSE;
3824#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003825 /* May also set global value for local option. */
3826 if (both)
3827 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3828 *(int *)varp;
3829 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003830
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003831 /* The default value is not insecure. */
3832 flagsp = insecure_flag(opt_idx, opt_flags);
3833 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003834 }
3835
3836#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003837 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003838#endif
3839}
3840
3841/*
3842 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003843 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003844 */
3845 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003846set_options_default(
3847 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003848{
3849 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003850 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003851 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003852
3853 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003854 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003855 && (opt_flags == 0
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003856 || (options[i].var != (char_u *)&p_enc
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003857# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003858 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003859 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003860# endif
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003861 )))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003862 set_option_default(i, opt_flags, p_cp);
3863
Bram Moolenaar071d4272004-06-13 20:20:40 +00003864 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003865 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003866 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003867#ifdef FEAT_CINDENT
3868 parse_cino(curbuf);
3869#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003870}
3871
3872/*
3873 * Set the Vi-default value of a string option.
3874 * Used for 'sh', 'backupskip' and 'term'.
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003875 * When "escape" is TRUE escape spaces with a backslash.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003876 */
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003877 static void
3878set_string_default_esc(char *name, char_u *val, int escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003879{
3880 char_u *p;
3881 int opt_idx;
3882
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003883 if (escape && vim_strchr(val, ' ') != NULL)
3884 p = vim_strsave_escaped(val, (char_u *)" ");
3885 else
3886 p = vim_strsave(val);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003887 if (p != NULL) /* we don't want a NULL */
3888 {
3889 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003890 if (opt_idx >= 0)
3891 {
3892 if (options[opt_idx].flags & P_DEF_ALLOCED)
3893 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3894 options[opt_idx].def_val[VI_DEFAULT] = p;
3895 options[opt_idx].flags |= P_DEF_ALLOCED;
3896 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003897 }
3898}
3899
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003900 void
3901set_string_default(char *name, char_u *val)
3902{
3903 set_string_default_esc(name, val, FALSE);
3904}
3905
Bram Moolenaar071d4272004-06-13 20:20:40 +00003906/*
3907 * Set the Vi-default value of a number option.
3908 * Used for 'lines' and 'columns'.
3909 */
3910 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003911set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003912{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003913 int opt_idx;
3914
3915 opt_idx = findoption((char_u *)name);
3916 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003917 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003918}
3919
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02003920/*
3921 * Set all window-local and buffer-local options to the Vim default.
3922 * local-global options will use the global value.
3923 */
3924 void
3925set_local_options_default(win_T *wp)
3926{
3927 win_T *save_curwin = curwin;
3928 int i;
3929
3930 curwin = wp;
3931 curbuf = curwin->w_buffer;
3932 block_autocmds();
3933
3934 for (i = 0; !istermoption(&options[i]); i++)
3935 {
3936 struct vimoption *p = &(options[i]);
3937 char_u *varp = get_varp_scope(p, OPT_LOCAL);
3938
3939 if (p->indir != PV_NONE
3940 && !(options[i].flags & P_NODEFAULT)
3941 && !optval_default(p, varp, FALSE))
3942 set_option_default(i, OPT_LOCAL, FALSE);
3943 }
3944
3945 unblock_autocmds();
3946 curwin = save_curwin;
3947 curbuf = curwin->w_buffer;
3948}
3949
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003950#if defined(EXITFREE) || defined(PROTO)
3951/*
3952 * Free all options.
3953 */
3954 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003955free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003956{
3957 int i;
3958
3959 for (i = 0; !istermoption(&options[i]); i++)
3960 {
3961 if (options[i].indir == PV_NONE)
3962 {
3963 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003964 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003965 free_string_option(*(char_u **)options[i].var);
3966 if (options[i].flags & P_DEF_ALLOCED)
3967 free_string_option(options[i].def_val[VI_DEFAULT]);
3968 }
3969 else if (options[i].var != VAR_WIN
3970 && (options[i].flags & P_STRING))
3971 /* buffer-local option: free global value */
3972 free_string_option(*(char_u **)options[i].var);
3973 }
3974}
3975#endif
3976
3977
Bram Moolenaar071d4272004-06-13 20:20:40 +00003978/*
3979 * Initialize the options, part two: After getting Rows and Columns and
3980 * setting 'term'.
3981 */
3982 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003983set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003984{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003985 int idx;
3986
Bram Moolenaar071d4272004-06-13 20:20:40 +00003987 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003988 * 'scroll' defaults to half the window height. The stored default is zero,
3989 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003990 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003991 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003992 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003993 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003994 comp_col();
3995
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003996 /*
3997 * 'window' is only for backwards compatibility with Vi.
3998 * Default is Rows - 1.
3999 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00004000 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00004001 p_window = Rows - 1;
4002 set_number_default("window", Rows - 1);
4003
Bram Moolenaarf740b292006-02-16 22:11:02 +00004004 /* For DOS console the default is always black. */
Bram Moolenaar4f974752019-02-17 17:44:42 +01004005#if !((defined(MSWIN)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00004006 /*
4007 * If 'background' wasn't set by the user, try guessing the value,
4008 * depending on the terminal name. Only need to check for terminals
4009 * with a dark background, that can handle color.
4010 */
4011 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004012 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
4013 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00004014 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004015 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00004016 /* don't mark it as set, when starting the GUI it may be
4017 * changed again */
4018 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004019 }
4020#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00004021
4022#ifdef CURSOR_SHAPE
4023 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
4024#endif
4025#ifdef FEAT_MOUSESHAPE
4026 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
4027#endif
4028#ifdef FEAT_PRINTER
4029 (void)parse_printoptions(); /* parse 'printoptions' default value */
4030#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004031}
4032
4033/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00004034 * Return "dark" or "light" depending on the kind of terminal.
4035 * This is just guessing! Recognized are:
4036 * "linux" Linux console
4037 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004038 * "cygwin.*" Cygwin shell
4039 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00004040 * We also check the COLORFGBG environment variable, which is set by
4041 * rxvt and derivatives. This variable contains either two or three
4042 * values separated by semicolons; we want the last value in either
4043 * case. If this value is 0-6 or 8, our background is dark.
4044 */
4045 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004046term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00004047{
Bram Moolenaar4f974752019-02-17 17:44:42 +01004048#if defined(MSWIN)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004049 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00004050 return (char_u *)"dark";
4051#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00004052 char_u *p;
4053
Bram Moolenaarf740b292006-02-16 22:11:02 +00004054 if (STRCMP(T_NAME, "linux") == 0
4055 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004056 || STRNCMP(T_NAME, "cygwin", 6) == 0
4057 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00004058 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
4059 && (p = vim_strrchr(p, ';')) != NULL
4060 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
4061 && p[2] == NUL))
4062 return (char_u *)"dark";
4063 return (char_u *)"light";
4064#endif
4065}
4066
4067/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004068 * Initialize the options, part three: After reading the .vimrc
4069 */
4070 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004071set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004072{
Bram Moolenaar4f974752019-02-17 17:44:42 +01004073#if defined(UNIX) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004074/*
4075 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4076 * This is done after other initializations, where 'shell' might have been
4077 * set, but only if they have not been set before.
4078 */
4079 char_u *p;
4080 int idx_srr;
4081 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004082# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004083 int idx_sp;
4084 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004085# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004086
4087 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004088 if (idx_srr < 0)
4089 do_srr = FALSE;
4090 else
4091 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004092# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004093 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004094 if (idx_sp < 0)
4095 do_sp = FALSE;
4096 else
4097 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004098# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004099 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004100 if (p != NULL)
4101 {
4102 /*
4103 * Default for p_sp is "| tee", for p_srr is ">".
4104 * For known shells it is changed here to include stderr.
4105 */
4106 if ( fnamecmp(p, "csh") == 0
4107 || fnamecmp(p, "tcsh") == 0
Bram Moolenaar4f974752019-02-17 17:44:42 +01004108# if defined(MSWIN) // also check with .exe extension
Bram Moolenaar071d4272004-06-13 20:20:40 +00004109 || fnamecmp(p, "csh.exe") == 0
4110 || fnamecmp(p, "tcsh.exe") == 0
4111# endif
4112 )
4113 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004114# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004115 if (do_sp)
4116 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01004117# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004118 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004119# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004120 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004121# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004122 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4123 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004124# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004125 if (do_srr)
4126 {
4127 p_srr = (char_u *)">&";
4128 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4129 }
4130 }
4131 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004132 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004133 if ( fnamecmp(p, "sh") == 0
4134 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004135 || fnamecmp(p, "mksh") == 0
4136 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004137 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004138 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004139 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004140 || fnamecmp(p, "fish") == 0
Bram Moolenaar4f974752019-02-17 17:44:42 +01004141# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004142 || fnamecmp(p, "cmd") == 0
4143 || fnamecmp(p, "sh.exe") == 0
4144 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004145 || fnamecmp(p, "mksh.exe") == 0
4146 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004147 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004148 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004149 || fnamecmp(p, "bash.exe") == 0
4150 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004151# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004152 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004153 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004154# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004155 if (do_sp)
4156 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01004157# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004158 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004159# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004160 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004161# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004162 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4163 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004164# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004165 if (do_srr)
4166 {
4167 p_srr = (char_u *)">%s 2>&1";
4168 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4169 }
4170 }
4171 vim_free(p);
4172 }
4173#endif
4174
Bram Moolenaar4f974752019-02-17 17:44:42 +01004175#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004176 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004177 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4178 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004179 * This is done after other initializations, where 'shell' might have been
4180 * set, but only if they have not been set before. Default for p_shcf is
4181 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004182 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004183 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004184 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004185 {
4186 int idx3;
4187
4188 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004189 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004190 {
4191 p_shcf = (char_u *)"-c";
4192 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4193 }
4194
Bram Moolenaar071d4272004-06-13 20:20:40 +00004195 /* Somehow Win32 requires the quotes around the redirection too */
4196 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004197 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004198 {
4199 p_sxq = (char_u *)"\"";
4200 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4201 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004202 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004203 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4204 {
4205 int idx3;
4206
4207 /*
4208 * cmd.exe on Windows will strip the first and last double quote given
4209 * on the command line, e.g. most of the time things like:
4210 * cmd /c "my path/to/echo" "my args to echo"
4211 * become:
4212 * my path/to/echo" "my args to echo
4213 * when executed.
4214 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004215 * To avoid this, set shellxquote to surround the command in
4216 * parenthesis. This appears to make most commands work, without
4217 * breaking commands that worked previously, such as
4218 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004219 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004220 idx3 = findoption((char_u *)"sxq");
4221 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4222 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004223 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004224 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4225 }
4226
Bram Moolenaara64ba222012-02-12 23:23:31 +01004227 idx3 = findoption((char_u *)"shcf");
4228 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4229 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004230 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004231 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4232 }
4233 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004234#endif
4235
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004236 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004237 {
4238 int idx_ffs = findoption((char_u *)"ffs");
4239
4240 /* Apply the first entry of 'fileformats' to the initial buffer. */
4241 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4242 set_fileformat(default_fileformat(), OPT_LOCAL);
4243 }
4244
Bram Moolenaar071d4272004-06-13 20:20:40 +00004245#ifdef FEAT_TITLE
4246 set_title_defaults();
4247#endif
4248}
4249
4250#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4251/*
4252 * When 'helplang' is still at its default value, set it to "lang".
4253 * Only the first two characters of "lang" are used.
4254 */
4255 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004256set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004257{
4258 int idx;
4259
4260 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4261 return;
4262 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004263 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004264 {
4265 if (options[idx].flags & P_ALLOCED)
4266 free_string_option(p_hlg);
4267 p_hlg = vim_strsave(lang);
4268 if (p_hlg == NULL)
4269 p_hlg = empty_option;
4270 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004271 {
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004272 // zh_CN becomes "cn", zh_TW becomes "tw"
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004273 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4274 {
4275 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4276 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4277 }
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004278 // any C like setting, such as C.UTF-8, becomes "en"
4279 else if (STRLEN(p_hlg) >= 1 && *p_hlg == 'C')
4280 {
4281 p_hlg[0] = 'e';
4282 p_hlg[1] = 'n';
4283 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004284 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004285 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004286 options[idx].flags |= P_ALLOCED;
4287 }
4288}
4289#endif
4290
4291#ifdef FEAT_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00004292 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004293gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004294{
4295 if (gui_get_lightness(gui.back_pixel) < 127)
4296 return (char_u *)"dark";
4297 return (char_u *)"light";
4298}
4299
4300/*
4301 * Option initializations that can only be done after opening the GUI window.
4302 */
4303 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004304init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004305{
4306 /* Set the 'background' option according to the lightness of the
4307 * background color, unless the user has set it already. */
4308 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4309 {
4310 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4311 highlight_changed();
4312 }
4313}
4314#endif
4315
4316#ifdef FEAT_TITLE
4317/*
4318 * 'title' and 'icon' only default to true if they have not been set or reset
4319 * in .vimrc and we can read the old value.
4320 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4321 * they can be reset. This reduces startup time when using X on a remote
4322 * machine.
4323 */
4324 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004325set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004326{
4327 int idx1;
4328 long val;
4329
4330 /*
4331 * If GUI is (going to be) used, we can always set the window title and
4332 * icon name. Saves a bit of time, because the X11 display server does
4333 * not need to be contacted.
4334 */
4335 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004336 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004337 {
4338#ifdef FEAT_GUI
4339 if (gui.starting || gui.in_use)
4340 val = TRUE;
4341 else
4342#endif
4343 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004344 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004345 p_title = val;
4346 }
4347 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004348 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004349 {
4350#ifdef FEAT_GUI
4351 if (gui.starting || gui.in_use)
4352 val = TRUE;
4353 else
4354#endif
4355 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004356 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004357 p_icon = val;
4358 }
4359}
4360#endif
4361
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004362#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02004363/*
4364 * Trigger the OptionSet autocommand.
4365 * "opt_idx" is the index of the option being set.
4366 * "opt_flags" can be OPT_LOCAL etc.
4367 * "oldval" the old value
4368 * "oldval_l" the old local value (only non-NULL if global and local value
4369 * are set)
4370 * "oldval_g" the old global value (only non-NULL if global and local value
4371 * are set)
4372 * "newval" the new value
4373 */
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004374 static void
4375trigger_optionsset_string(
4376 int opt_idx,
4377 int opt_flags,
Bram Moolenaard7c96872019-06-15 17:12:48 +02004378 char_u *oldval,
4379 char_u *oldval_l,
4380 char_u *oldval_g,
4381 char_u *newval)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004382{
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02004383 // Don't do this recursively.
4384 if (oldval != NULL && newval != NULL
4385 && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004386 {
4387 char_u buf_type[7];
4388
4389 sprintf((char *)buf_type, "%s",
4390 (opt_flags & OPT_LOCAL) ? "local" : "global");
4391 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4392 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4393 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
Bram Moolenaard7c96872019-06-15 17:12:48 +02004394 if (opt_flags & OPT_LOCAL)
4395 {
4396 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
4397 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1);
4398 }
4399 if (opt_flags & OPT_GLOBAL)
4400 {
4401 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
4402 set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval, -1);
4403 }
4404 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
4405 {
4406 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
4407 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval_l, -1);
4408 set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval_g, -1);
4409 }
4410 if (opt_flags & OPT_MODELINE)
4411 {
4412 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
4413 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1);
4414 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004415 apply_autocmds(EVENT_OPTIONSET,
4416 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4417 reset_v_option_vars();
4418 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004419}
4420#endif
4421
Bram Moolenaar071d4272004-06-13 20:20:40 +00004422/*
4423 * Parse 'arg' for option settings.
4424 *
4425 * 'arg' may be IObuff, but only when no errors can be present and option
4426 * does not need to be expanded with option_expand().
4427 * "opt_flags":
4428 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004429 * OPT_GLOBAL for ":setglobal"
4430 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004431 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004432 * OPT_WINONLY to only set window-local options
4433 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004434 *
4435 * returns FAIL if an error is detected, OK otherwise
4436 */
4437 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004438do_set(
4439 char_u *arg, /* option string (may be written to!) */
4440 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004441{
4442 int opt_idx;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004443 char *errmsg;
4444 char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00004445 char_u *startarg;
4446 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4447 int nextchar; /* next non-white char after option name */
4448 int afterchar; /* character just after option name */
4449 int len;
4450 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004451 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004452 int key;
4453 long_u flags; /* flags for current option */
4454 char_u *varp = NULL; /* pointer to variable for current option */
4455 int did_show = FALSE; /* already showed one value */
4456 int adding; /* "opt+=arg" */
4457 int prepending; /* "opt^=arg" */
4458 int removing; /* "opt-=arg" */
4459 int cp_val = 0;
4460 char_u key_name[2];
4461
4462 if (*arg == NUL)
4463 {
4464 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004465 did_show = TRUE;
4466 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004467 }
4468
4469 while (*arg != NUL) /* loop to process all options */
4470 {
4471 errmsg = NULL;
4472 startarg = arg; /* remember for error message */
4473
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004474 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4475 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004476 {
4477 /*
4478 * ":set all" show all options.
4479 * ":set all&" set all options to their default value.
4480 */
4481 arg += 3;
4482 if (*arg == '&')
4483 {
4484 ++arg;
4485 /* Only for :set command set global value of local options. */
4486 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004487 didset_options();
4488 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004489 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004490 }
4491 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004492 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004493 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004494 did_show = TRUE;
4495 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004496 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004497 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004498 {
4499 showoptions(2, opt_flags);
4500 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004501 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004502 arg += 7;
4503 }
4504 else
4505 {
4506 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004507 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004508 {
4509 prefix = 0;
4510 arg += 2;
4511 }
4512 else if (STRNCMP(arg, "inv", 3) == 0)
4513 {
4514 prefix = 2;
4515 arg += 3;
4516 }
4517
4518 /* find end of name */
4519 key = 0;
4520 if (*arg == '<')
4521 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004522 opt_idx = -1;
4523 /* look out for <t_>;> */
4524 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4525 len = 5;
4526 else
4527 {
4528 len = 1;
4529 while (arg[len] != NUL && arg[len] != '>')
4530 ++len;
4531 }
4532 if (arg[len] != '>')
4533 {
4534 errmsg = e_invarg;
4535 goto skip;
4536 }
4537 arg[len] = NUL; /* put NUL after name */
4538 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4539 opt_idx = findoption(arg + 1);
4540 arg[len++] = '>'; /* restore '>' */
4541 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004542 key = find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004543 }
4544 else
4545 {
4546 len = 0;
4547 /*
4548 * The two characters after "t_" may not be alphanumeric.
4549 */
4550 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4551 len = 4;
4552 else
4553 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4554 ++len;
4555 nextchar = arg[len];
4556 arg[len] = NUL; /* put NUL after name */
4557 opt_idx = findoption(arg);
4558 arg[len] = nextchar; /* restore nextchar */
4559 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004560 key = find_key_option(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004561 }
4562
4563 /* remember character after option name */
4564 afterchar = arg[len];
4565
4566 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004567 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004568 ++len;
4569
4570 adding = FALSE;
4571 prepending = FALSE;
4572 removing = FALSE;
4573 if (arg[len] != NUL && arg[len + 1] == '=')
4574 {
4575 if (arg[len] == '+')
4576 {
4577 adding = TRUE; /* "+=" */
4578 ++len;
4579 }
4580 else if (arg[len] == '^')
4581 {
4582 prepending = TRUE; /* "^=" */
4583 ++len;
4584 }
4585 else if (arg[len] == '-')
4586 {
4587 removing = TRUE; /* "-=" */
4588 ++len;
4589 }
4590 }
4591 nextchar = arg[len];
4592
4593 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4594 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004595 errmsg = N_("E518: Unknown option");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004596 goto skip;
4597 }
4598
4599 if (opt_idx >= 0)
4600 {
4601 if (options[opt_idx].var == NULL) /* hidden option: skip */
4602 {
4603 /* Only give an error message when requesting the value of
4604 * a hidden option, ignore setting it. */
4605 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4606 && (!(options[opt_idx].flags & P_BOOL)
4607 || nextchar == '?'))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004608 errmsg = N_("E519: Option not supported");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004609 goto skip;
4610 }
4611
4612 flags = options[opt_idx].flags;
4613 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4614 }
4615 else
4616 {
4617 flags = P_STRING;
4618 if (key < 0)
4619 {
4620 key_name[0] = KEY2TERMCAP0(key);
4621 key_name[1] = KEY2TERMCAP1(key);
4622 }
4623 else
4624 {
4625 key_name[0] = KS_KEY;
4626 key_name[1] = (key & 0xff);
4627 }
4628 }
4629
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004630 /* Skip all options that are not window-local (used when showing
4631 * an already loaded buffer in a window). */
4632 if ((opt_flags & OPT_WINONLY)
4633 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4634 goto skip;
4635
Bram Moolenaara3227e22006-03-08 21:32:40 +00004636 /* Skip all options that are window-local (used for :vimgrep). */
4637 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4638 && options[opt_idx].var == VAR_WIN)
4639 goto skip;
4640
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004641 /* Disallow changing some options from modelines. */
4642 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004643 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004644 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004645 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004646 errmsg = _("E520: Not allowed in a modeline");
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004647 goto skip;
4648 }
Bram Moolenaar110289e2019-05-23 15:38:06 +02004649 if ((flags & P_MLE) && !p_mle)
4650 {
4651 errmsg = _("E992: Not allowed in a modeline when 'modelineexpr' is off");
4652 goto skip;
4653 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004654#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004655 /* In diff mode some options are overruled. This avoids that
4656 * 'foldmethod' becomes "marker" instead of "diff" and that
4657 * "wrap" gets set. */
4658 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004659 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004660 && (
4661#ifdef FEAT_FOLDING
4662 options[opt_idx].indir == PV_FDM ||
4663#endif
4664 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004665 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004666#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004667 }
4668
4669#ifdef HAVE_SANDBOX
4670 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004671 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004672 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004673 errmsg = _(e_sandbox);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004674 goto skip;
4675 }
4676#endif
4677
4678 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4679 {
4680 arg += len;
4681 cp_val = p_cp;
4682 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4683 {
4684 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4685 {
4686 cp_val = FALSE;
4687 arg += 3;
4688 }
4689 else /* "opt&vi": set to Vi default */
4690 {
4691 cp_val = TRUE;
4692 arg += 2;
4693 }
4694 }
4695 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004696 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004697 {
4698 errmsg = e_trailing;
4699 goto skip;
4700 }
4701 }
4702
4703 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004704 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4705 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004706 */
4707 if (nextchar == '?'
4708 || (prefix == 1
4709 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4710 && !(flags & P_BOOL)))
4711 {
4712 /*
4713 * print value
4714 */
4715 if (did_show)
4716 msg_putchar('\n'); /* cursor below last one */
4717 else
4718 {
4719 gotocmdline(TRUE); /* cursor at status line */
4720 did_show = TRUE; /* remember that we did a line */
4721 }
4722 if (opt_idx >= 0)
4723 {
4724 showoneopt(&options[opt_idx], opt_flags);
4725#ifdef FEAT_EVAL
4726 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004727 {
4728 /* Mention where the option was last set. */
4729 if (varp == options[opt_idx].var)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004730 last_set_msg(options[opt_idx].script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004731 else if ((int)options[opt_idx].indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004732 last_set_msg(curwin->w_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004733 (int)options[opt_idx].indir & PV_MASK]);
4734 else if ((int)options[opt_idx].indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004735 last_set_msg(curbuf->b_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004736 (int)options[opt_idx].indir & PV_MASK]);
4737 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004738#endif
4739 }
4740 else
4741 {
4742 char_u *p;
4743
4744 p = find_termcode(key_name);
4745 if (p == NULL)
4746 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004747 errmsg = N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004748 goto skip;
4749 }
4750 else
4751 (void)show_one_termcode(key_name, p, TRUE);
4752 }
4753 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004754 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004755 errmsg = e_trailing;
4756 }
4757 else
4758 {
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004759 int value_is_replaced = !prepending && !adding && !removing;
Bram Moolenaar916a8182018-11-25 02:18:29 +01004760 int value_checked = FALSE;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004761
Bram Moolenaar071d4272004-06-13 20:20:40 +00004762 if (flags & P_BOOL) /* boolean */
4763 {
4764 if (nextchar == '=' || nextchar == ':')
4765 {
4766 errmsg = e_invarg;
4767 goto skip;
4768 }
4769
4770 /*
4771 * ":set opt!": invert
4772 * ":set opt&": reset to default value
4773 * ":set opt<": reset to global value
4774 */
4775 if (nextchar == '!')
4776 value = *(int *)(varp) ^ 1;
4777 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004778 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004779 ((flags & P_VI_DEF) || cp_val)
4780 ? VI_DEFAULT : VIM_DEFAULT];
4781 else if (nextchar == '<')
4782 {
4783 /* For 'autoread' -1 means to use global value. */
4784 if ((int *)varp == &curbuf->b_p_ar
4785 && opt_flags == OPT_LOCAL)
4786 value = -1;
4787 else
4788 value = *(int *)get_varp_scope(&(options[opt_idx]),
4789 OPT_GLOBAL);
4790 }
4791 else
4792 {
4793 /*
4794 * ":set invopt": invert
4795 * ":set opt" or ":set noopt": set or reset
4796 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004797 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004798 {
4799 errmsg = e_trailing;
4800 goto skip;
4801 }
4802 if (prefix == 2) /* inv */
4803 value = *(int *)(varp) ^ 1;
4804 else
4805 value = prefix;
4806 }
4807
4808 errmsg = set_bool_option(opt_idx, varp, (int)value,
4809 opt_flags);
4810 }
4811 else /* numeric or string */
4812 {
4813 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4814 || prefix != 1)
4815 {
4816 errmsg = e_invarg;
4817 goto skip;
4818 }
4819
4820 if (flags & P_NUM) /* numeric */
4821 {
4822 /*
4823 * Different ways to set a number option:
4824 * & set to default value
4825 * < set to global value
4826 * <xx> accept special key codes for 'wildchar'
4827 * c accept any non-digit for 'wildchar'
4828 * [-]0-9 set number
4829 * other error
4830 */
4831 ++arg;
4832 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004833 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004834 ((flags & P_VI_DEF) || cp_val)
4835 ? VI_DEFAULT : VIM_DEFAULT];
4836 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004837 {
4838 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4839 * use the global value. */
4840 if ((long *)varp == &curbuf->b_p_ul
4841 && opt_flags == OPT_LOCAL)
4842 value = NO_LOCAL_UNDOLEVEL;
4843 else
4844 value = *(long *)get_varp_scope(
4845 &(options[opt_idx]), OPT_GLOBAL);
4846 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004847 else if (((long *)varp == &p_wc
4848 || (long *)varp == &p_wcm)
4849 && (*arg == '<'
4850 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004851 || (*arg != NUL
4852 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004853 && !VIM_ISDIGIT(*arg))))
4854 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004855 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004856 if (value == 0 && (long *)varp != &p_wcm)
4857 {
4858 errmsg = e_invarg;
4859 goto skip;
4860 }
4861 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004862 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4863 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004864 /* Allow negative (for 'undolevels'), octal and
4865 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004866 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
Bram Moolenaar16e9b852019-05-19 19:59:35 +02004867 &value, NULL, 0, TRUE);
Bram Moolenaar06e2c812019-06-12 19:05:48 +02004868 if (i == 0 || (arg[i] != NUL
4869 && !VIM_ISWHITE(arg[i])))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004870 {
Bram Moolenaar16e9b852019-05-19 19:59:35 +02004871 errmsg = N_("E521: Number required after =");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004872 goto skip;
4873 }
4874 }
4875 else
4876 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004877 errmsg = N_("E521: Number required after =");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004878 goto skip;
4879 }
4880
4881 if (adding)
4882 value = *(long *)varp + value;
4883 if (prepending)
4884 value = *(long *)varp * value;
4885 if (removing)
4886 value = *(long *)varp - value;
4887 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004888 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004889 }
4890 else if (opt_idx >= 0) /* string */
4891 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004892 char_u *save_arg = NULL;
4893 char_u *s = NULL;
4894 char_u *oldval = NULL; /* previous value if *varp */
4895 char_u *newval;
4896 char_u *origval = NULL;
Bram Moolenaard7c96872019-06-15 17:12:48 +02004897 char_u *origval_l = NULL;
4898 char_u *origval_g = NULL;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004899#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004900 char_u *saved_origval = NULL;
Bram Moolenaard7c96872019-06-15 17:12:48 +02004901 char_u *saved_origval_l = NULL;
4902 char_u *saved_origval_g = NULL;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004903 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004904#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004905 unsigned newlen;
4906 int comma;
4907 int bs;
4908 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004909 was allocated */
4910
4911 /* When using ":set opt=val" for a global option
4912 * with a local value the local value will be
4913 * reset, use the global value here. */
4914 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004915 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004916 varp = options[opt_idx].var;
4917
4918 /* The old value is kept until we are sure that the
4919 * new value is valid. */
4920 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004921
Bram Moolenaard7c96872019-06-15 17:12:48 +02004922 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
4923 {
4924 origval_l = *(char_u **)get_varp_scope(
4925 &(options[opt_idx]), OPT_LOCAL);
4926 origval_g = *(char_u **)get_varp_scope(
4927 &(options[opt_idx]), OPT_GLOBAL);
4928
4929 // A global-local string option might have an empty
4930 // option as value to indicate that the global
4931 // value should be used.
4932 if (((int)options[opt_idx].indir & PV_BOTH)
4933 && origval_l == empty_option)
4934 origval_l = origval_g;
4935 }
4936
4937 // When setting the local value of a global
4938 // option, the old value may be the global value.
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004939 if (((int)options[opt_idx].indir & PV_BOTH)
4940 && (opt_flags & OPT_LOCAL))
4941 origval = *(char_u **)get_varp(
4942 &options[opt_idx]);
4943 else
4944 origval = oldval;
4945
Bram Moolenaar071d4272004-06-13 20:20:40 +00004946 if (nextchar == '&') /* set to default val */
4947 {
4948 newval = options[opt_idx].def_val[
4949 ((flags & P_VI_DEF) || cp_val)
4950 ? VI_DEFAULT : VIM_DEFAULT];
4951 if ((char_u **)varp == &p_bg)
4952 {
4953 /* guess the value of 'background' */
4954#ifdef FEAT_GUI
4955 if (gui.in_use)
4956 newval = gui_bg_default();
4957 else
4958#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004959 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004960 }
4961
4962 /* expand environment variables and ~ (since the
4963 * default value was already expanded, only
4964 * required when an environment variable was set
4965 * later */
4966 if (newval == NULL)
4967 newval = empty_option;
4968 else
4969 {
4970 s = option_expand(opt_idx, newval);
4971 if (s == NULL)
4972 s = newval;
4973 newval = vim_strsave(s);
4974 }
4975 new_value_alloced = TRUE;
4976 }
4977 else if (nextchar == '<') /* set to global val */
4978 {
4979 newval = vim_strsave(*(char_u **)get_varp_scope(
4980 &(options[opt_idx]), OPT_GLOBAL));
4981 new_value_alloced = TRUE;
4982 }
4983 else
4984 {
4985 ++arg; /* jump to after the '=' or ':' */
4986
4987 /*
4988 * Set 'keywordprg' to ":help" if an empty
4989 * value was passed to :set by the user.
4990 * Misuse errbuf[] for the resulting string.
4991 */
4992 if (varp == (char_u *)&p_kp
4993 && (*arg == NUL || *arg == ' '))
4994 {
4995 STRCPY(errbuf, ":help");
4996 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004997 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004998 }
4999 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01005000 * Convert 'backspace' number to string, for
5001 * adding, prepending and removing string.
5002 */
5003 else if (varp == (char_u *)&p_bs
5004 && VIM_ISDIGIT(**(char_u **)varp))
5005 {
5006 i = getdigits((char_u **)varp);
5007 switch (i)
5008 {
5009 case 0:
5010 *(char_u **)varp = empty_option;
5011 break;
5012 case 1:
5013 *(char_u **)varp = vim_strsave(
5014 (char_u *)"indent,eol");
5015 break;
5016 case 2:
5017 *(char_u **)varp = vim_strsave(
5018 (char_u *)"indent,eol,start");
5019 break;
5020 }
5021 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02005022 if (origval == oldval)
5023 origval = *(char_u **)varp;
Bram Moolenaard7c96872019-06-15 17:12:48 +02005024 if (origval_l == oldval)
5025 origval_l = *(char_u **)varp;
5026 if (origval_g == oldval)
5027 origval_g = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01005028 oldval = *(char_u **)varp;
5029 }
5030 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00005031 * Convert 'whichwrap' number to string, for
5032 * backwards compatibility with Vim 3.0.
5033 * Misuse errbuf[] for the resulting string.
5034 */
5035 else if (varp == (char_u *)&p_ww
5036 && VIM_ISDIGIT(*arg))
5037 {
5038 *errbuf = NUL;
5039 i = getdigits(&arg);
5040 if (i & 1)
5041 STRCAT(errbuf, "b,");
5042 if (i & 2)
5043 STRCAT(errbuf, "s,");
5044 if (i & 4)
5045 STRCAT(errbuf, "h,l,");
5046 if (i & 8)
5047 STRCAT(errbuf, "<,>,");
5048 if (i & 16)
5049 STRCAT(errbuf, "[,],");
5050 if (*errbuf != NUL) /* remove trailing , */
5051 errbuf[STRLEN(errbuf) - 1] = NUL;
5052 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005053 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005054 }
5055 /*
5056 * Remove '>' before 'dir' and 'bdir', for
5057 * backwards compatibility with version 3.0
5058 */
5059 else if ( *arg == '>'
5060 && (varp == (char_u *)&p_dir
5061 || varp == (char_u *)&p_bdir))
5062 {
5063 ++arg;
5064 }
5065
Bram Moolenaar071d4272004-06-13 20:20:40 +00005066 /*
5067 * Copy the new string into allocated memory.
5068 * Can't use set_string_option_direct(), because
5069 * we need to remove the backslashes.
5070 */
5071 /* get a bit too much */
5072 newlen = (unsigned)STRLEN(arg) + 1;
5073 if (adding || prepending || removing)
5074 newlen += (unsigned)STRLEN(origval) + 1;
5075 newval = alloc(newlen);
5076 if (newval == NULL) /* out of mem, don't change */
5077 break;
5078 s = newval;
5079
5080 /*
5081 * Copy the string, skip over escaped chars.
5082 * For MS-DOS and WIN32 backslashes before normal
5083 * file name characters are not removed, and keep
5084 * backslash at start, for "\\machine\path", but
5085 * do remove it for "\\\\machine\\path".
5086 * The reverse is found in ExpandOldSetting().
5087 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005088 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005089 {
5090 if (*arg == '\\' && arg[1] != NUL
5091#ifdef BACKSLASH_IN_FILENAME
5092 && !((flags & P_EXPAND)
5093 && vim_isfilec(arg[1])
5094 && (arg[1] != '\\'
5095 || (s == newval
5096 && arg[2] != '\\')))
5097#endif
5098 )
5099 ++arg; /* remove backslash */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005100 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00005101 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005102 {
5103 /* copy multibyte char */
5104 mch_memmove(s, arg, (size_t)i);
5105 arg += i;
5106 s += i;
5107 }
5108 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005109 *s++ = *arg++;
5110 }
5111 *s = NUL;
5112
5113 /*
5114 * Expand environment variables and ~.
5115 * Don't do it when adding without inserting a
5116 * comma.
5117 */
5118 if (!(adding || prepending || removing)
5119 || (flags & P_COMMA))
5120 {
5121 s = option_expand(opt_idx, newval);
5122 if (s != NULL)
5123 {
5124 vim_free(newval);
5125 newlen = (unsigned)STRLEN(s) + 1;
5126 if (adding || prepending || removing)
5127 newlen += (unsigned)STRLEN(origval) + 1;
5128 newval = alloc(newlen);
5129 if (newval == NULL)
5130 break;
5131 STRCPY(newval, s);
5132 }
5133 }
5134
5135 /* locate newval[] in origval[] when removing it
5136 * and when adding to avoid duplicates */
5137 i = 0; /* init for GCC */
5138 if (removing || (flags & P_NODUP))
5139 {
5140 i = (int)STRLEN(newval);
5141 bs = 0;
5142 for (s = origval; *s; ++s)
5143 {
5144 if ((!(flags & P_COMMA)
5145 || s == origval
5146 || (s[-1] == ',' && !(bs & 1)))
5147 && STRNCMP(s, newval, i) == 0
5148 && (!(flags & P_COMMA)
5149 || s[i] == ','
5150 || s[i] == NUL))
5151 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005152 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005153 * even number of backslashes or a single
5154 * backslash preceded by a comma before it
5155 * is recognized as a separator */
5156 if ((s > origval + 1
5157 && s[-1] == '\\'
5158 && s[-2] != ',')
5159 || (s == origval + 1
5160 && s[-1] == '\\'))
5161
Bram Moolenaar071d4272004-06-13 20:20:40 +00005162 ++bs;
5163 else
5164 bs = 0;
5165 }
5166
5167 /* do not add if already there */
5168 if ((adding || prepending) && *s)
5169 {
5170 prepending = FALSE;
5171 adding = FALSE;
5172 STRCPY(newval, origval);
5173 }
5174 }
5175
5176 /* concatenate the two strings; add a ',' if
5177 * needed */
5178 if (adding || prepending)
5179 {
5180 comma = ((flags & P_COMMA) && *origval != NUL
5181 && *newval != NUL);
5182 if (adding)
5183 {
5184 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005185 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005186 if (comma && i > 1
5187 && (flags & P_ONECOMMA) == P_ONECOMMA
5188 && origval[i - 1] == ','
5189 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005190 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005191 mch_memmove(newval + i + comma, newval,
5192 STRLEN(newval) + 1);
5193 mch_memmove(newval, origval, (size_t)i);
5194 }
5195 else
5196 {
5197 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005198 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005199 }
5200 if (comma)
5201 newval[i] = ',';
5202 }
5203
5204 /* Remove newval[] from origval[]. (Note: "i" has
5205 * been set above and is used here). */
5206 if (removing)
5207 {
5208 STRCPY(newval, origval);
5209 if (*s)
5210 {
5211 /* may need to remove a comma */
5212 if (flags & P_COMMA)
5213 {
5214 if (s == origval)
5215 {
5216 /* include comma after string */
5217 if (s[i] == ',')
5218 ++i;
5219 }
5220 else
5221 {
5222 /* include comma before string */
5223 --s;
5224 ++i;
5225 }
5226 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005227 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005228 }
5229 }
5230
5231 if (flags & P_FLAGLIST)
5232 {
5233 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005234 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005235 {
5236 /* if options have P_FLAGLIST and
5237 * P_ONECOMMA such as 'whichwrap' */
5238 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005239 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005240 if (*s != ',' && *(s + 1) == ','
5241 && vim_strchr(s + 2, *s) != NULL)
5242 {
5243 /* Remove the duplicated value and
5244 * the next comma. */
5245 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005246 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005247 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005248 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005249 else
5250 {
5251 if ((!(flags & P_COMMA) || *s != ',')
5252 && vim_strchr(s + 1, *s) != NULL)
5253 {
5254 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005255 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005256 }
5257 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005258 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005259 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005260 }
5261
5262 if (save_arg != NULL) /* number for 'whichwrap' */
5263 arg = save_arg;
5264 new_value_alloced = TRUE;
5265 }
5266
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005267 /*
5268 * Set the new value.
5269 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005270 *(char_u **)(varp) = newval;
5271
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005272#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005273 if (!starting
5274# ifdef FEAT_CRYPT
5275 && options[opt_idx].indir != PV_KEY
5276# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005277 && origval != NULL && newval != NULL)
5278 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005279 /* origval may be freed by
5280 * did_set_string_option(), make a copy. */
5281 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005282 /* newval (and varp) may become invalid if the
5283 * buffer is closed by autocommands. */
5284 saved_newval = vim_strsave(newval);
Bram Moolenaard7c96872019-06-15 17:12:48 +02005285 if (origval_l != NULL)
5286 saved_origval_l = vim_strsave(origval_l);
5287 if (origval_g != NULL)
5288 saved_origval_g = vim_strsave(origval_g);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005289 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005290#endif
5291
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005292 {
5293 long_u *p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005294 int secure_saved = secure;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005295
5296 // When an option is set in the sandbox, from a
5297 // modeline or in secure mode, then deal with side
5298 // effects in secure mode. Also when the value was
5299 // set with the P_INSECURE flag and is not
5300 // completely replaced.
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005301 if ((opt_flags & OPT_MODELINE)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005302#ifdef HAVE_SANDBOX
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005303 || sandbox != 0
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005304#endif
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005305 || (!value_is_replaced && (*p & P_INSECURE)))
5306 secure = 1;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005307
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005308 // Handle side effects, and set the global value
5309 // for ":set" on local options. Note: when setting
5310 // 'syntax' or 'filetype' autocommands may be
5311 // triggered that can cause havoc.
5312 errmsg = did_set_string_option(
5313 opt_idx, (char_u **)varp,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005314 new_value_alloced, oldval, errbuf,
5315 opt_flags, &value_checked);
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005316
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005317 secure = secure_saved;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005318 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005319
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005320#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005321 if (errmsg == NULL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02005322 trigger_optionsset_string(
5323 opt_idx, opt_flags, saved_origval,
5324 saved_origval_l, saved_origval_g,
5325 saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005326 vim_free(saved_origval);
Bram Moolenaard7c96872019-06-15 17:12:48 +02005327 vim_free(saved_origval_l);
5328 vim_free(saved_origval_g);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005329 vim_free(saved_newval);
5330#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005331 /* If error detected, print the error message. */
5332 if (errmsg != NULL)
5333 goto skip;
5334 }
5335 else /* key code option */
5336 {
5337 char_u *p;
5338
5339 if (nextchar == '&')
5340 {
5341 if (add_termcap_entry(key_name, TRUE) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005342 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005343 }
5344 else
5345 {
5346 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005347 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005348 if (*p == '\\' && p[1] != NUL)
5349 ++p;
5350 nextchar = *p;
5351 *p = NUL;
5352 add_termcode(key_name, arg, FALSE);
5353 *p = nextchar;
5354 }
5355 if (full_screen)
5356 ttest(FALSE);
5357 redraw_all_later(CLEAR);
5358 }
5359 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005360
Bram Moolenaar071d4272004-06-13 20:20:40 +00005361 if (opt_idx >= 0)
Bram Moolenaar916a8182018-11-25 02:18:29 +01005362 did_set_option(
5363 opt_idx, opt_flags, value_is_replaced, value_checked);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005364 }
5365
5366skip:
5367 /*
5368 * Advance to next argument.
5369 * - skip until a blank found, taking care of backslashes
5370 * - skip blanks
5371 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5372 */
5373 for (i = 0; i < 2 ; ++i)
5374 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005375 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005376 if (*arg++ == '\\' && *arg != NUL)
5377 ++arg;
5378 arg = skipwhite(arg);
5379 if (*arg != '=')
5380 break;
5381 }
5382 }
5383
5384 if (errmsg != NULL)
5385 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005386 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005387 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005388 if (i + (arg - startarg) < IOSIZE)
5389 {
5390 /* append the argument with the error */
5391 STRCAT(IObuff, ": ");
5392 mch_memmove(IObuff + i, startarg, (arg - startarg));
5393 IObuff[i + (arg - startarg)] = NUL;
5394 }
5395 /* make sure all characters are printable */
5396 trans_characters(IObuff, IOSIZE);
5397
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005398 ++no_wait_return; // wait_return done later
5399 emsg((char *)IObuff); // show error highlighted
Bram Moolenaar071d4272004-06-13 20:20:40 +00005400 --no_wait_return;
5401
5402 return FAIL;
5403 }
5404
5405 arg = skipwhite(arg);
5406 }
5407
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005408theend:
5409 if (silent_mode && did_show)
5410 {
5411 /* After displaying option values in silent mode. */
5412 silent_mode = FALSE;
5413 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5414 msg_putchar('\n');
5415 cursor_on(); /* msg_start() switches it off */
5416 out_flush();
5417 silent_mode = TRUE;
5418 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5419 }
5420
Bram Moolenaar071d4272004-06-13 20:20:40 +00005421 return OK;
5422}
5423
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005424/*
5425 * Call this when an option has been given a new value through a user command.
5426 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5427 */
5428 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005429did_set_option(
5430 int opt_idx,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005431 int opt_flags, // possibly with OPT_MODELINE
5432 int new_value, // value was replaced completely
5433 int value_checked) // value was checked to be safe, no need to set the
5434 // P_INSECURE flag.
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005435{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005436 long_u *p;
5437
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005438 options[opt_idx].flags |= P_WAS_SET;
5439
5440 /* When an option is set in the sandbox, from a modeline or in secure mode
5441 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005442 * flag. */
5443 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar916a8182018-11-25 02:18:29 +01005444 if (!value_checked && (secure
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005445#ifdef HAVE_SANDBOX
5446 || sandbox != 0
5447#endif
Bram Moolenaar916a8182018-11-25 02:18:29 +01005448 || (opt_flags & OPT_MODELINE)))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005449 *p = *p | P_INSECURE;
5450 else if (new_value)
5451 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005452}
5453
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005454 static char *
5455illegal_char(char *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005456{
5457 if (errbuf == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005458 return "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00005459 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005460 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005461 return errbuf;
5462}
5463
5464/*
5465 * Convert a key name or string into a key value.
5466 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005467 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005468 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005469 int
5470string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005471{
5472 if (*arg == '<')
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02005473 return find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005474 if (*arg == '^')
5475 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005476 if (multi_byte)
5477 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005478 return *arg;
5479}
5480
5481#ifdef FEAT_CMDWIN
5482/*
5483 * Check value of 'cedit' and set cedit_key.
5484 * Returns NULL if value is OK, error message otherwise.
5485 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005486 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005487check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005488{
5489 int n;
5490
5491 if (*p_cedit == NUL)
5492 cedit_key = -1;
5493 else
5494 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005495 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005496 if (vim_isprintc(n))
5497 return e_invarg;
5498 cedit_key = n;
5499 }
5500 return NULL;
5501}
5502#endif
5503
5504#ifdef FEAT_TITLE
5505/*
5506 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5507 * maketitle() to create and display it.
5508 * When switching the title or icon off, call mch_restore_title() to get
5509 * the old value back.
5510 */
5511 static void
Bram Moolenaar84a93082018-06-16 22:58:15 +02005512did_set_title(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005513{
5514 if (starting != NO_SCREEN
5515#ifdef FEAT_GUI
5516 && !gui.starting
5517#endif
5518 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00005519 maketitle();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005520}
5521#endif
5522
5523/*
5524 * set_options_bin - called when 'bin' changes value.
5525 */
5526 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005527set_options_bin(
5528 int oldval,
5529 int newval,
5530 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005531{
5532 /*
5533 * The option values that are changed when 'bin' changes are
5534 * copied when 'bin is set and restored when 'bin' is reset.
5535 */
5536 if (newval)
5537 {
5538 if (!oldval) /* switched on */
5539 {
5540 if (!(opt_flags & OPT_GLOBAL))
5541 {
5542 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5543 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5544 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5545 curbuf->b_p_et_nobin = curbuf->b_p_et;
5546 }
5547 if (!(opt_flags & OPT_LOCAL))
5548 {
5549 p_tw_nobin = p_tw;
5550 p_wm_nobin = p_wm;
5551 p_ml_nobin = p_ml;
5552 p_et_nobin = p_et;
5553 }
5554 }
5555
5556 if (!(opt_flags & OPT_GLOBAL))
5557 {
5558 curbuf->b_p_tw = 0; /* no automatic line wrap */
5559 curbuf->b_p_wm = 0; /* no automatic line wrap */
5560 curbuf->b_p_ml = 0; /* no modelines */
5561 curbuf->b_p_et = 0; /* no expandtab */
5562 }
5563 if (!(opt_flags & OPT_LOCAL))
5564 {
5565 p_tw = 0;
5566 p_wm = 0;
5567 p_ml = FALSE;
5568 p_et = FALSE;
5569 p_bin = TRUE; /* needed when called for the "-b" argument */
5570 }
5571 }
5572 else if (oldval) /* switched off */
5573 {
5574 if (!(opt_flags & OPT_GLOBAL))
5575 {
5576 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5577 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5578 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5579 curbuf->b_p_et = curbuf->b_p_et_nobin;
5580 }
5581 if (!(opt_flags & OPT_LOCAL))
5582 {
5583 p_tw = p_tw_nobin;
5584 p_wm = p_wm_nobin;
5585 p_ml = p_ml_nobin;
5586 p_et = p_et_nobin;
5587 }
5588 }
5589}
5590
Bram Moolenaar071d4272004-06-13 20:20:40 +00005591/*
5592 * Expand environment variables for some string options.
5593 * These string options cannot be indirect!
5594 * If "val" is NULL expand the current value of the option.
5595 * Return pointer to NameBuff, or NULL when not expanded.
5596 */
5597 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005598option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005599{
5600 /* if option doesn't need expansion nothing to do */
5601 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5602 return NULL;
5603
5604 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5605 * expand_env() would truncate the string. */
5606 if (val != NULL && STRLEN(val) > MAXPATHL)
5607 return NULL;
5608
5609 if (val == NULL)
5610 val = *(char_u **)options[opt_idx].var;
5611
5612 /*
5613 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5614 * Escape spaces when expanding 'tags', they are used to separate file
5615 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005616 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005617 */
5618 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005619 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005620#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005621 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5622#endif
5623 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005624 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5625 return NULL;
5626
5627 return NameBuff;
5628}
5629
5630/*
5631 * After setting various option values: recompute variables that depend on
5632 * option values.
5633 */
5634 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005635didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005636{
5637 /* initialize the table for 'iskeyword' et.al. */
5638 (void)init_chartab();
5639
5640 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
5641 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005642 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005643#ifdef FEAT_SESSION
5644 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5645 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5646#endif
5647#ifdef FEAT_FOLDING
5648 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5649#endif
5650 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005651 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005652 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005653#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5654 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5655#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005656#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005657 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005658 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005659 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005660 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005661#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01005662#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005663 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5664#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005665#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005666 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5667#endif
5668#ifdef FEAT_CMDWIN
5669 /* set cedit_key */
5670 (void)check_cedit();
5671#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005672#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005673 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005674#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005675#ifdef FEAT_LINEBREAK
5676 /* initialize the table for 'breakat'. */
5677 fill_breakat_flags();
5678#endif
5679
5680}
5681
5682/*
5683 * More side effects of setting options.
5684 */
5685 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005686didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005687{
5688 /* Initialize the highlight_attr[] table. */
5689 (void)highlight_changed();
5690
5691 /* Parse default for 'wildmode' */
5692 check_opt_wim();
5693
5694 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005695 /* Parse default for 'fillchars'. */
5696 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005697
5698#ifdef FEAT_CLIPBOARD
5699 /* Parse default for 'clipboard' */
5700 (void)check_clipboard_option();
5701#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005702#ifdef FEAT_VARTABS
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01005703 vim_free(curbuf->b_p_vsts_array);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005704 tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_array);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01005705 vim_free(curbuf->b_p_vts_array);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005706 tabstop_set(curbuf->b_p_vts, &curbuf->b_p_vts_array);
5707#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005708}
5709
5710/*
5711 * Check for string options that are NULL (normally only termcap options).
5712 */
5713 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005714check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005715{
5716 int opt_idx;
5717
5718 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5719 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5720 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5721}
5722
5723/*
5724 * Check string options in a buffer for NULL value.
5725 */
5726 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005727check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005728{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005729 check_string_option(&buf->b_p_bh);
5730 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005731 check_string_option(&buf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005732 check_string_option(&buf->b_p_ff);
5733#ifdef FEAT_FIND_ID
5734 check_string_option(&buf->b_p_def);
5735 check_string_option(&buf->b_p_inc);
5736# ifdef FEAT_EVAL
5737 check_string_option(&buf->b_p_inex);
5738# endif
5739#endif
5740#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5741 check_string_option(&buf->b_p_inde);
5742 check_string_option(&buf->b_p_indk);
5743#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005744#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5745 check_string_option(&buf->b_p_bexpr);
5746#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005747#if defined(FEAT_CRYPT)
5748 check_string_option(&buf->b_p_cm);
5749#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005750 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005751#if defined(FEAT_EVAL)
5752 check_string_option(&buf->b_p_fex);
5753#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005754#ifdef FEAT_CRYPT
5755 check_string_option(&buf->b_p_key);
5756#endif
5757 check_string_option(&buf->b_p_kp);
5758 check_string_option(&buf->b_p_mps);
5759 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005760 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005761 check_string_option(&buf->b_p_isk);
5762#ifdef FEAT_COMMENTS
5763 check_string_option(&buf->b_p_com);
5764#endif
5765#ifdef FEAT_FOLDING
5766 check_string_option(&buf->b_p_cms);
5767#endif
5768 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005769#ifdef FEAT_TEXTOBJ
5770 check_string_option(&buf->b_p_qe);
5771#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005772#ifdef FEAT_SYN_HL
5773 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005774 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005775#endif
5776#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005777 check_string_option(&buf->b_s.b_p_spc);
5778 check_string_option(&buf->b_s.b_p_spf);
5779 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005780#endif
5781#ifdef FEAT_SEARCHPATH
5782 check_string_option(&buf->b_p_sua);
5783#endif
5784#ifdef FEAT_CINDENT
5785 check_string_option(&buf->b_p_cink);
5786 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005787 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005788#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005789 check_string_option(&buf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005790#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5791 check_string_option(&buf->b_p_cinw);
5792#endif
5793#ifdef FEAT_INS_EXPAND
5794 check_string_option(&buf->b_p_cpt);
5795#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005796#ifdef FEAT_COMPL_FUNC
5797 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005798 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005799#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +02005800#ifdef FEAT_EVAL
5801 check_string_option(&buf->b_p_tfu);
5802#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005803#ifdef FEAT_KEYMAP
5804 check_string_option(&buf->b_p_keymap);
5805#endif
5806#ifdef FEAT_QUICKFIX
5807 check_string_option(&buf->b_p_gp);
5808 check_string_option(&buf->b_p_mp);
5809 check_string_option(&buf->b_p_efm);
5810#endif
5811 check_string_option(&buf->b_p_ep);
5812 check_string_option(&buf->b_p_path);
5813 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005814 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005815#ifdef FEAT_INS_EXPAND
5816 check_string_option(&buf->b_p_dict);
5817 check_string_option(&buf->b_p_tsr);
5818#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005819#ifdef FEAT_LISP
5820 check_string_option(&buf->b_p_lw);
5821#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005822 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005823 check_string_option(&buf->b_p_menc);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005824#ifdef FEAT_VARTABS
5825 check_string_option(&buf->b_p_vsts);
5826 check_string_option(&buf->b_p_vts);
5827#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005828}
5829
5830/*
5831 * Free the string allocated for an option.
5832 * Checks for the string being empty_option. This may happen if we're out of
5833 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5834 * check_options().
5835 * Does NOT check for P_ALLOCED flag!
5836 */
5837 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005838free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005839{
5840 if (p != empty_option)
5841 vim_free(p);
5842}
5843
5844 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005845clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005846{
5847 if (*pp != empty_option)
5848 vim_free(*pp);
5849 *pp = empty_option;
5850}
5851
5852 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005853check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005854{
5855 if (*pp == NULL)
5856 *pp = empty_option;
5857}
5858
5859/*
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005860 * Return the option index found by a pointer into term_strings[].
5861 * Return -1 if not found.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005862 */
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005863 int
5864get_term_opt_idx(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005865{
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005866 int opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005867
5868 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5869 if (options[opt_idx].var == (char_u *)p)
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005870 return opt_idx;
5871 return -1; // cannot happen: didn't find it!
5872}
5873
5874/*
5875 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5876 * Return the option index or -1 if not found.
5877 */
5878 int
5879set_term_option_alloced(char_u **p)
5880{
5881 int opt_idx = get_term_opt_idx(p);
5882
5883 if (opt_idx >= 0)
5884 options[opt_idx].flags |= P_ALLOCED;
5885 return opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005886}
5887
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005888#if defined(FEAT_EVAL) || defined(PROTO)
5889/*
5890 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5891 * Return FALSE when it wasn't.
5892 * Return -1 for an unknown option.
5893 */
5894 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005895was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005896{
5897 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005898 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005899
5900 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005901 {
5902 flagp = insecure_flag(idx, opt_flags);
5903 return (*flagp & P_INSECURE) != 0;
5904 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005905 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005906 return -1;
5907}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005908
5909/*
5910 * Get a pointer to the flags used for the P_INSECURE flag of option
5911 * "opt_idx". For some local options a local flags field is used.
5912 */
5913 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005914insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005915{
5916 if (opt_flags & OPT_LOCAL)
5917 switch ((int)options[opt_idx].indir)
5918 {
5919#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005920 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005921#endif
5922#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005923# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005924 case PV_FDE: return &curwin->w_p_fde_flags;
5925 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005926# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005927# ifdef FEAT_BEVAL
5928 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5929# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005930# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005931 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005932# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005933 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005934# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005935 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005936# endif
5937#endif
5938 }
5939
5940 /* Nothing special, return global flags field. */
5941 return &options[opt_idx].flags;
5942}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005943#endif
5944
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005945#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005946/*
5947 * Redraw the window title and/or tab page text later.
5948 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005949static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005950{
5951 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005952 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005953}
5954#endif
5955
Bram Moolenaar071d4272004-06-13 20:20:40 +00005956/*
5957 * Set a string option to a new value (without checking the effect).
5958 * The string is copied into allocated memory.
5959 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005960 * When "set_sid" is zero set the scriptID to current_sctx.sc_sid. When
5961 * "set_sid" is SID_NONE don't set the scriptID. Otherwise set the scriptID to
5962 * "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005963 */
5964 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005965set_string_option_direct(
5966 char_u *name,
5967 int opt_idx,
5968 char_u *val,
5969 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5970 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005971{
5972 char_u *s;
5973 char_u **varp;
5974 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005975 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005976
Bram Moolenaar89d40322006-08-29 15:30:07 +00005977 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005978 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005979 idx = findoption(name);
5980 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005981 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005982 semsg(_(e_intern2), "set_string_option_direct()");
5983 siemsg(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005984 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005985 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005986 }
5987
Bram Moolenaar89d40322006-08-29 15:30:07 +00005988 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005989 return;
5990
5991 s = vim_strsave(val);
5992 if (s != NULL)
5993 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005994 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005995 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005996 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005997 free_string_option(*varp);
5998 *varp = s;
5999
6000 /* For buffer/window local option may also set the global value. */
6001 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00006002 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006003
Bram Moolenaar89d40322006-08-29 15:30:07 +00006004 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006005
6006 /* When setting both values of a global option with a local value,
6007 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00006008 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006009 {
6010 free_string_option(*varp);
6011 *varp = empty_option;
6012 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006013# ifdef FEAT_EVAL
6014 if (set_sid != SID_NONE)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02006015 {
6016 sctx_T script_ctx;
6017
6018 if (set_sid == 0)
6019 script_ctx = current_sctx;
6020 else
6021 {
6022 script_ctx.sc_sid = set_sid;
Bram Moolenaarded5f1b2018-11-10 17:33:29 +01006023 script_ctx.sc_seq = 0;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02006024 script_ctx.sc_lnum = 0;
Bram Moolenaar558ca4a2019-04-04 18:15:38 +02006025 script_ctx.sc_version = 1;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02006026 }
6027 set_option_sctx_idx(idx, opt_flags, script_ctx);
6028 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006029# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006030 }
6031}
6032
6033/*
Bram Moolenaar20c023a2019-05-26 21:03:24 +02006034 * Like set_string_option_direct(), but for a window-local option in "wp".
6035 * Blocks autocommands to avoid the old curwin becoming invalid.
6036 */
6037 void
6038set_string_option_direct_in_win(
6039 win_T *wp,
6040 char_u *name,
6041 int opt_idx,
6042 char_u *val,
6043 int opt_flags,
6044 int set_sid)
6045{
6046 win_T *save_curwin = curwin;
6047
6048 block_autocmds();
6049 curwin = wp;
6050 curbuf = curwin->w_buffer;
6051 set_string_option_direct(name, opt_idx, val, opt_flags, set_sid);
6052 curwin = save_curwin;
6053 curbuf = curwin->w_buffer;
6054 unblock_autocmds();
6055}
6056
6057/*
6058 * Like set_string_option_direct(), but for a buffer-local option in "buf".
6059 * Blocks autocommands to avoid the old curbuf becoming invalid.
6060 */
6061 void
6062set_string_option_direct_in_buf(
6063 buf_T *buf,
6064 char_u *name,
6065 int opt_idx,
6066 char_u *val,
6067 int opt_flags,
6068 int set_sid)
6069{
6070 buf_T *save_curbuf = curbuf;
6071
6072 block_autocmds();
6073 curbuf = buf;
6074 curwin->w_buffer = curbuf;
6075 set_string_option_direct(name, opt_idx, val, opt_flags, set_sid);
6076 curbuf = save_curbuf;
6077 curwin->w_buffer = curbuf;
6078 unblock_autocmds();
6079}
6080
6081/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006082 * Set global value for string option when it's a local option.
6083 */
6084 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01006085set_string_option_global(
6086 int opt_idx, /* option index */
6087 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006088{
6089 char_u **p, *s;
6090
6091 /* the global value is always allocated */
6092 if (options[opt_idx].var == VAR_WIN)
6093 p = (char_u **)GLOBAL_WO(varp);
6094 else
6095 p = (char_u **)options[opt_idx].var;
6096 if (options[opt_idx].indir != PV_NONE
6097 && p != varp
6098 && (s = vim_strsave(*varp)) != NULL)
6099 {
6100 free_string_option(*p);
6101 *p = s;
6102 }
6103}
6104
6105/*
6106 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006107 *
6108 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006109 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006110 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006111set_string_option(
6112 int opt_idx,
6113 char_u *value,
6114 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006115{
6116 char_u *s;
6117 char_u **varp;
6118 char_u *oldval;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02006119#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02006120 char_u *oldval_l = NULL;
6121 char_u *oldval_g = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02006122 char_u *saved_oldval = NULL;
Bram Moolenaard7c96872019-06-15 17:12:48 +02006123 char_u *saved_oldval_l = NULL;
6124 char_u *saved_oldval_g = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006125 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02006126#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006127 char *r = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01006128 int value_checked = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006129
6130 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006131 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006132
6133 s = vim_strsave(value);
6134 if (s != NULL)
6135 {
6136 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
6137 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006138 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006139 ? OPT_GLOBAL : OPT_LOCAL)
6140 : opt_flags);
6141 oldval = *varp;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02006142#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02006143 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6144 {
6145 oldval_l = *(char_u **)get_varp_scope(&(options[opt_idx]),
6146 OPT_LOCAL);
6147 oldval_g = *(char_u **)get_varp_scope(&(options[opt_idx]),
6148 OPT_GLOBAL);
6149 }
Bram Moolenaar983f2f12019-06-16 16:41:41 +02006150#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006151 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02006152
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006153#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02006154 if (!starting
6155# ifdef FEAT_CRYPT
6156 && options[opt_idx].indir != PV_KEY
6157# endif
6158 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006159 {
Bram Moolenaard7c96872019-06-15 17:12:48 +02006160 if (oldval_l != NULL)
6161 saved_oldval_l = vim_strsave(oldval_l);
6162 if (oldval_g != NULL)
6163 saved_oldval_g = vim_strsave(oldval_g);
Bram Moolenaar53744302015-07-17 17:38:22 +02006164 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006165 saved_newval = vim_strsave(s);
6166 }
Bram Moolenaar53744302015-07-17 17:38:22 +02006167#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006168 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
Bram Moolenaar916a8182018-11-25 02:18:29 +01006169 opt_flags, &value_checked)) == NULL)
6170 did_set_option(opt_idx, opt_flags, TRUE, value_checked);
Bram Moolenaar53744302015-07-17 17:38:22 +02006171
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006172#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006173 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006174 if (r == NULL)
6175 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaard7c96872019-06-15 17:12:48 +02006176 saved_oldval, saved_oldval_l,
6177 saved_oldval_g, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006178 vim_free(saved_oldval);
Bram Moolenaard7c96872019-06-15 17:12:48 +02006179 vim_free(saved_oldval_l);
6180 vim_free(saved_oldval_g);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006181 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02006182#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006183 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006184 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006185}
6186
6187/*
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006188 * Return TRUE if "val" is a valid name: only consists of alphanumeric ASCII
6189 * characters or characters in "allowed".
6190 */
6191 static int
6192valid_name(char_u *val, char *allowed)
6193{
6194 char_u *s;
6195
6196 for (s = val; *s != NUL; ++s)
6197 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)allowed, *s) == NULL)
6198 return FALSE;
6199 return TRUE;
6200}
6201
6202/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01006203 * Return TRUE if "val" is a valid 'filetype' name.
6204 * Also used for 'syntax' and 'keymap'.
6205 */
6206 static int
6207valid_filetype(char_u *val)
6208{
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006209 return valid_name(val, ".-_");
6210}
Bram Moolenaard0b51382016-11-04 15:23:45 +01006211
Bram Moolenaara7be0f22019-04-11 11:19:32 +02006212#if defined(FEAT_SPELL) || defined(PROTO)
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006213/*
6214 * Return TRUE if "val" is a valid 'spellang' value.
6215 */
6216 int
6217valid_spellang(char_u *val)
6218{
Bram Moolenaar9a061cb2019-05-05 16:55:03 +02006219 return valid_name(val, ".-_,@");
Bram Moolenaard0b51382016-11-04 15:23:45 +01006220}
6221
6222/*
Bram Moolenaar862f1e12019-04-10 22:33:41 +02006223 * Return TRUE if "val" is a valid 'spellfile' value.
6224 */
6225 static int
6226valid_spellfile(char_u *val)
6227{
6228 char_u *s;
6229
6230 for (s = val; *s != NUL; ++s)
6231 if (!vim_isfilec(*s) && *s != ',')
6232 return FALSE;
6233 return TRUE;
6234}
Bram Moolenaara7be0f22019-04-11 11:19:32 +02006235#endif
Bram Moolenaar862f1e12019-04-10 22:33:41 +02006236
6237/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006238 * Handle string options that need some action to perform when changed.
6239 * Returns NULL for success, or an error message for an error.
6240 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006241 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006242did_set_string_option(
Bram Moolenaar916a8182018-11-25 02:18:29 +01006243 int opt_idx, // index in options[] table
6244 char_u **varp, // pointer to the option variable
6245 int new_value_alloced, // new value was allocated
6246 char_u *oldval, // previous value of the option
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006247 char *errbuf, // buffer for errors, or NULL
Bram Moolenaar916a8182018-11-25 02:18:29 +01006248 int opt_flags, // OPT_LOCAL and/or OPT_GLOBAL
6249 int *value_checked) // value was checked to be save, no
6250 // need to set P_INSECURE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006251{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006252 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006253 char_u *s, *p;
6254 int did_chartab = FALSE;
6255 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006256 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006257#ifdef FEAT_GUI
6258 /* set when changing an option that only requires a redraw in the GUI */
6259 int redraw_gui_only = FALSE;
6260#endif
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02006261 int value_changed = FALSE;
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006262#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6263 int did_swaptcap = FALSE;
6264#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006265
6266 /* Get the global option to compare with, otherwise we would have to check
6267 * two values for all local options. */
6268 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6269
6270 /* Disallow changing some options from secure mode */
6271 if ((secure
6272#ifdef HAVE_SANDBOX
6273 || sandbox != 0
6274#endif
6275 ) && (options[opt_idx].flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006276 errmsg = e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006277
Bram Moolenaar916a8182018-11-25 02:18:29 +01006278 // Check for a "normal" directory or file name in some options. Disallow a
6279 // path separator (slash and/or backslash), wildcards and characters that
6280 // are often illegal in a file name. Be more permissive if "secure" is off.
Bram Moolenaar7554da42016-11-25 22:04:13 +01006281 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006282 && vim_strpbrk(*varp, (char_u *)(secure
6283 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006284 || ((options[opt_idx].flags & P_NDNAME)
6285 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006286 errmsg = e_invarg;
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006287
Bram Moolenaar071d4272004-06-13 20:20:40 +00006288 /* 'term' */
6289 else if (varp == &T_NAME)
6290 {
6291 if (T_NAME[0] == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006292 errmsg = N_("E529: Cannot set 'term' to empty string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006293#ifdef FEAT_GUI
6294 if (gui.in_use)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006295 errmsg = N_("E530: Cannot change term in GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006296 else if (term_is_gui(T_NAME))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006297 errmsg = N_("E531: Use \":gui\" to start the GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006298#endif
6299 else if (set_termname(T_NAME) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006300 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006301 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006302 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006303 /* Screen colors may have changed. */
6304 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006305
6306 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6307 * P_ALLOCED flag on 'term'. */
6308 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006309 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006310 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006311 }
6312
6313 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006314 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006315 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006316 char_u *bkc = p_bkc;
6317 unsigned int *flags = &bkc_flags;
6318
6319 if (opt_flags & OPT_LOCAL)
6320 {
6321 bkc = curbuf->b_p_bkc;
6322 flags = &curbuf->b_bkc_flags;
6323 }
6324
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006325 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6326 /* make the local value empty: use the global value */
6327 *flags = 0;
6328 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006329 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006330 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6331 errmsg = e_invarg;
6332 if ((((int)*flags & BKC_AUTO) != 0)
6333 + (((int)*flags & BKC_YES) != 0)
6334 + (((int)*flags & BKC_NO) != 0) != 1)
6335 {
6336 /* Must have exactly one of "auto", "yes" and "no". */
6337 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6338 errmsg = e_invarg;
6339 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006340 }
6341 }
6342
6343 /* 'backupext' and 'patchmode' */
6344 else if (varp == &p_bex || varp == &p_pm)
6345 {
6346 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6347 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006348 errmsg = N_("E589: 'backupext' and 'patchmode' are equal");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006349 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006350#ifdef FEAT_LINEBREAK
6351 /* 'breakindentopt' */
6352 else if (varp == &curwin->w_p_briopt)
6353 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006354 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006355 errmsg = e_invarg;
6356 }
6357#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006358
6359 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006360 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006361 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006362 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006363 */
6364 else if ( varp == &p_isi
6365 || varp == &(curbuf->b_p_isk)
6366 || varp == &p_isp
6367 || varp == &p_isf)
6368 {
6369 if (init_chartab() == FAIL)
6370 {
6371 did_chartab = TRUE; /* need to restore it below */
6372 errmsg = e_invarg; /* error in value */
6373 }
6374 }
6375
6376 /* 'helpfile' */
6377 else if (varp == &p_hf)
6378 {
6379 /* May compute new values for $VIM and $VIMRUNTIME */
6380 if (didset_vim)
6381 {
6382 vim_setenv((char_u *)"VIM", (char_u *)"");
6383 didset_vim = FALSE;
6384 }
6385 if (didset_vimruntime)
6386 {
6387 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6388 didset_vimruntime = FALSE;
6389 }
6390 }
6391
Bram Moolenaar1a384422010-07-14 19:53:30 +02006392#ifdef FEAT_SYN_HL
6393 /* 'colorcolumn' */
6394 else if (varp == &curwin->w_p_cc)
6395 errmsg = check_colorcolumn(curwin);
6396#endif
6397
Bram Moolenaar071d4272004-06-13 20:20:40 +00006398#ifdef FEAT_MULTI_LANG
6399 /* 'helplang' */
6400 else if (varp == &p_hlg)
6401 {
6402 /* Check for "", "ab", "ab,cd", etc. */
6403 for (s = p_hlg; *s != NUL; s += 3)
6404 {
6405 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6406 {
6407 errmsg = e_invarg;
6408 break;
6409 }
6410 if (s[2] == NUL)
6411 break;
6412 }
6413 }
6414#endif
6415
6416 /* 'highlight' */
6417 else if (varp == &p_hl)
6418 {
6419 if (highlight_changed() == FAIL)
6420 errmsg = e_invarg; /* invalid flags */
6421 }
6422
6423 /* 'nrformats' */
6424 else if (gvarp == &p_nf)
6425 {
6426 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6427 errmsg = e_invarg;
6428 }
6429
6430#ifdef FEAT_SESSION
6431 /* 'sessionoptions' */
6432 else if (varp == &p_ssop)
6433 {
6434 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6435 errmsg = e_invarg;
6436 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6437 {
6438 /* Don't allow both "sesdir" and "curdir". */
6439 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6440 errmsg = e_invarg;
6441 }
6442 }
6443 /* 'viewoptions' */
6444 else if (varp == &p_vop)
6445 {
6446 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6447 errmsg = e_invarg;
6448 }
6449#endif
6450
6451 /* 'scrollopt' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006452 else if (varp == &p_sbo)
6453 {
6454 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6455 errmsg = e_invarg;
6456 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006457
6458 /* 'ambiwidth' */
Bram Moolenaar3848e002016-03-19 18:42:29 +01006459 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006460 {
6461 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6462 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006463 else if (set_chars_option(&p_lcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006464 errmsg = _("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006465 else if (set_chars_option(&p_fcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006466 errmsg = _("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006467 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006468
6469 /* 'background' */
6470 else if (varp == &p_bg)
6471 {
6472 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6473 {
6474#ifdef FEAT_EVAL
6475 int dark = (*p_bg == 'd');
6476#endif
6477
6478 init_highlight(FALSE, FALSE);
6479
6480#ifdef FEAT_EVAL
6481 if (dark != (*p_bg == 'd')
6482 && get_var_value((char_u *)"g:colors_name") != NULL)
6483 {
6484 /* The color scheme must have set 'background' back to another
6485 * value, that's not what we want here. Disable the color
6486 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006487 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006488 free_string_option(p_bg);
6489 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6490 check_string_option(&p_bg);
6491 init_highlight(FALSE, FALSE);
6492 }
6493#endif
6494 }
6495 else
6496 errmsg = e_invarg;
6497 }
6498
6499 /* 'wildmode' */
6500 else if (varp == &p_wim)
6501 {
6502 if (check_opt_wim() == FAIL)
6503 errmsg = e_invarg;
6504 }
6505
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006506 /* 'wildoptions' */
6507 else if (varp == &p_wop)
6508 {
6509 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6510 errmsg = e_invarg;
6511 }
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006512
Bram Moolenaar071d4272004-06-13 20:20:40 +00006513#ifdef FEAT_WAK
6514 /* 'winaltkeys' */
6515 else if (varp == &p_wak)
6516 {
6517 if (*p_wak == NUL
6518 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6519 errmsg = e_invarg;
6520# ifdef FEAT_MENU
6521# ifdef FEAT_GUI_MOTIF
6522 else if (gui.in_use)
6523 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6524# else
6525# ifdef FEAT_GUI_GTK
6526 else if (gui.in_use)
6527 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6528# endif
6529# endif
6530# endif
6531 }
6532#endif
6533
Bram Moolenaar071d4272004-06-13 20:20:40 +00006534 /* 'eventignore' */
6535 else if (varp == &p_ei)
6536 {
6537 if (check_ei() == FAIL)
6538 errmsg = e_invarg;
6539 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006540
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006541 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6542 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6543 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006544 {
6545 if (gvarp == &p_fenc)
6546 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006547 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006548 errmsg = e_modifiable;
6549 else if (vim_strchr(*varp, ',') != NULL)
6550 /* No comma allowed in 'fileencoding'; catches confusing it
6551 * with 'fileencodings'. */
6552 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006553 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006554 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006555#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006556 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006557 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006558#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006559 /* Add 'fileencoding' to the swap file. */
6560 ml_setflags(curbuf);
6561 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006562 }
6563 if (errmsg == NULL)
6564 {
6565 /* canonize the value, so that STRCMP() can be used on it */
6566 p = enc_canonize(*varp);
6567 if (p != NULL)
6568 {
6569 vim_free(*varp);
6570 *varp = p;
6571 }
6572 if (varp == &p_enc)
6573 {
6574 errmsg = mb_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006575#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006576 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006577#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006578 }
6579 }
6580
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006581#if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006582 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6583 {
6584 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6585 if (STRCMP(p_tenc, "utf-8") != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006586 errmsg = N_("E617: Cannot be changed in the GTK+ 2 GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006587 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006588#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006589
6590 if (errmsg == NULL)
6591 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006592#ifdef FEAT_KEYMAP
Bram Moolenaar071d4272004-06-13 20:20:40 +00006593 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6594 * (with another encoding). */
6595 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6596 (void)keymap_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006597#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006598
6599 /* When 'termencoding' is not empty and 'encoding' changes or when
6600 * 'termencoding' changes, need to setup for keyboard input and
6601 * display output conversion. */
6602 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6603 {
Bram Moolenaar17471e82017-11-26 23:47:18 +01006604 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6605 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6606 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006607 semsg(_("E950: Cannot convert between %s and %s"),
Bram Moolenaar17471e82017-11-26 23:47:18 +01006608 p_tenc, p_enc);
6609 errmsg = e_invarg;
6610 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006611 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006612
Bram Moolenaar4f974752019-02-17 17:44:42 +01006613#if defined(MSWIN)
Bram Moolenaar05159a02005-02-26 23:04:13 +00006614 /* $HOME may have characters in active code page. */
6615 if (varp == &p_enc)
6616 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006617#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006618 }
6619 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006620
6621#if defined(FEAT_POSTSCRIPT)
6622 else if (varp == &p_penc)
6623 {
6624 /* Canonize printencoding if VIM standard one */
6625 p = enc_canonize(p_penc);
6626 if (p != NULL)
6627 {
6628 vim_free(p_penc);
6629 p_penc = p;
6630 }
6631 else
6632 {
6633 /* Ensure lower case and '-' for '_' */
6634 for (s = p_penc; *s != NUL; s++)
6635 {
6636 if (*s == '_')
6637 *s = '-';
6638 else
6639 *s = TOLOWER_ASC(*s);
6640 }
6641 }
6642 }
6643#endif
6644
Bram Moolenaar9372a112005-12-06 19:59:18 +00006645#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006646 else if (varp == &p_imak)
6647 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006648 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006649 errmsg = e_invarg;
6650 }
6651#endif
6652
6653#ifdef FEAT_KEYMAP
6654 else if (varp == &curbuf->b_p_keymap)
6655 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006656 if (!valid_filetype(*varp))
6657 errmsg = e_invarg;
6658 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01006659 {
6660 int secure_save = secure;
6661
6662 // Reset the secure flag, since the value of 'keymap' has
6663 // been checked to be safe.
6664 secure = 0;
6665
6666 // load or unload key mapping tables
Bram Moolenaard0b51382016-11-04 15:23:45 +01006667 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006668
Bram Moolenaar916a8182018-11-25 02:18:29 +01006669 secure = secure_save;
6670
6671 // Since we check the value, there is no need to set P_INSECURE,
6672 // even when the value comes from a modeline.
6673 *value_checked = TRUE;
6674 }
6675
Bram Moolenaarfab06232009-03-04 03:13:35 +00006676 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006677 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006678 if (*curbuf->b_p_keymap != NUL)
6679 {
6680 /* Installed a new keymap, switch on using it. */
6681 curbuf->b_p_iminsert = B_IMODE_LMAP;
6682 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6683 curbuf->b_p_imsearch = B_IMODE_LMAP;
6684 }
6685 else
6686 {
6687 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6688 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6689 curbuf->b_p_iminsert = B_IMODE_NONE;
6690 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6691 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6692 }
6693 if ((opt_flags & OPT_LOCAL) == 0)
6694 {
6695 set_iminsert_global();
6696 set_imsearch_global();
6697 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006698 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006699 }
6700 }
6701#endif
6702
6703 /* 'fileformat' */
6704 else if (gvarp == &p_ff)
6705 {
6706 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6707 errmsg = e_modifiable;
6708 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6709 errmsg = e_invarg;
6710 else
6711 {
6712 /* may also change 'textmode' */
6713 if (get_fileformat(curbuf) == EOL_DOS)
6714 curbuf->b_p_tx = TRUE;
6715 else
6716 curbuf->b_p_tx = FALSE;
6717#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006718 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006719#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006720 /* update flag in swap file */
6721 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006722 /* Redraw needed when switching to/from "mac": a CR in the text
6723 * will be displayed differently. */
6724 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6725 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006726 }
6727 }
6728
6729 /* 'fileformats' */
6730 else if (varp == &p_ffs)
6731 {
6732 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6733 errmsg = e_invarg;
6734 else
6735 {
6736 /* also change 'textauto' */
6737 if (*p_ffs == NUL)
6738 p_ta = FALSE;
6739 else
6740 p_ta = TRUE;
6741 }
6742 }
6743
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006744#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006745 /* 'cryptkey' */
6746 else if (gvarp == &p_key)
6747 {
Bram Moolenaard7663c22019-08-06 21:59:57 +02006748 // Make sure the ":set" command doesn't show the new value in the
6749 // history.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006750 remove_key_from_history();
Bram Moolenaard7663c22019-08-06 21:59:57 +02006751
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006752 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6753 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006754 ml_set_crypt_key(curbuf, oldval,
6755 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006756 }
6757
6758 else if (gvarp == &p_cm)
6759 {
6760 if (opt_flags & OPT_LOCAL)
6761 p = curbuf->b_p_cm;
6762 else
6763 p = p_cm;
6764 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6765 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006766 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006767 errmsg = e_invarg;
6768 else
6769 {
6770 /* When setting the global value to empty, make it "zip". */
6771 if (*p_cm == NUL)
6772 {
6773 if (new_value_alloced)
6774 free_string_option(p_cm);
6775 p_cm = vim_strsave((char_u *)"zip");
6776 new_value_alloced = TRUE;
6777 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006778 /* When using ":set cm=name" the local value is going to be empty.
6779 * Do that here, otherwise the crypt functions will still use the
6780 * local value. */
6781 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6782 {
6783 free_string_option(curbuf->b_p_cm);
6784 curbuf->b_p_cm = empty_option;
6785 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006786
6787 /* Need to update the swapfile when the effective method changed.
6788 * Set "s" to the effective old value, "p" to the effective new
6789 * method and compare. */
6790 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6791 s = p_cm; /* was previously using the global value */
6792 else
6793 s = oldval;
6794 if (*curbuf->b_p_cm == NUL)
6795 p = p_cm; /* is now using the global value */
6796 else
6797 p = curbuf->b_p_cm;
6798 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006799 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006800
6801 /* If the global value changes need to update the swapfile for all
6802 * buffers using that value. */
6803 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6804 {
6805 buf_T *buf;
6806
Bram Moolenaar29323592016-07-24 22:04:11 +02006807 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006808 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006809 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006810 }
6811 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006812 }
6813#endif
6814
6815 /* 'matchpairs' */
6816 else if (gvarp == &p_mps)
6817 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006818 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006819 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006820 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006821 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006822 int x2 = -1;
6823 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006824
6825 if (*p != NUL)
6826 p += mb_ptr2len(p);
6827 if (*p != NUL)
6828 x2 = *p++;
6829 if (*p != NUL)
6830 {
6831 x3 = mb_ptr2char(p);
6832 p += mb_ptr2len(p);
6833 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006834 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006835 {
6836 errmsg = e_invarg;
6837 break;
6838 }
6839 if (*p == NUL)
6840 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006841 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006842 }
6843 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006844 {
6845 /* Check for "x:y,x:y" */
6846 for (p = *varp; *p != NUL; p += 4)
6847 {
6848 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6849 {
6850 errmsg = e_invarg;
6851 break;
6852 }
6853 if (p[3] == NUL)
6854 break;
6855 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006856 }
6857 }
6858
6859#ifdef FEAT_COMMENTS
6860 /* 'comments' */
6861 else if (gvarp == &p_com)
6862 {
6863 for (s = *varp; *s; )
6864 {
6865 while (*s && *s != ':')
6866 {
6867 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6868 && !VIM_ISDIGIT(*s) && *s != '-')
6869 {
6870 errmsg = illegal_char(errbuf, *s);
6871 break;
6872 }
6873 ++s;
6874 }
6875 if (*s++ == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006876 errmsg = N_("E524: Missing colon");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006877 else if (*s == ',' || *s == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006878 errmsg = N_("E525: Zero length string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006879 if (errmsg != NULL)
6880 break;
6881 while (*s && *s != ',')
6882 {
6883 if (*s == '\\' && s[1] != NUL)
6884 ++s;
6885 ++s;
6886 }
6887 s = skip_to_option_part(s);
6888 }
6889 }
6890#endif
6891
6892 /* 'listchars' */
6893 else if (varp == &p_lcs)
6894 {
6895 errmsg = set_chars_option(varp);
6896 }
6897
Bram Moolenaar071d4272004-06-13 20:20:40 +00006898 /* 'fillchars' */
6899 else if (varp == &p_fcs)
6900 {
6901 errmsg = set_chars_option(varp);
6902 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006903
6904#ifdef FEAT_CMDWIN
6905 /* 'cedit' */
6906 else if (varp == &p_cedit)
6907 {
6908 errmsg = check_cedit();
6909 }
6910#endif
6911
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006912 /* 'verbosefile' */
6913 else if (varp == &p_vfile)
6914 {
6915 verbose_stop();
6916 if (*p_vfile != NUL && verbose_open() == FAIL)
6917 errmsg = e_invarg;
6918 }
6919
Bram Moolenaar071d4272004-06-13 20:20:40 +00006920#ifdef FEAT_VIMINFO
6921 /* 'viminfo' */
6922 else if (varp == &p_viminfo)
6923 {
6924 for (s = p_viminfo; *s;)
6925 {
6926 /* Check it's a valid character */
6927 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6928 {
6929 errmsg = illegal_char(errbuf, *s);
6930 break;
6931 }
6932 if (*s == 'n') /* name is always last one */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006933 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006934 else if (*s == 'r') /* skip until next ',' */
6935 {
6936 while (*++s && *s != ',')
6937 ;
6938 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006939 else if (*s == '%')
6940 {
6941 /* optional number */
6942 while (vim_isdigit(*++s))
6943 ;
6944 }
6945 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006946 ++s; /* no extra chars */
6947 else /* must have a number */
6948 {
6949 while (vim_isdigit(*++s))
6950 ;
6951
6952 if (!VIM_ISDIGIT(*(s - 1)))
6953 {
6954 if (errbuf != NULL)
6955 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006956 sprintf(errbuf, _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006957 transchar_byte(*(s - 1)));
6958 errmsg = errbuf;
6959 }
6960 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006961 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006962 break;
6963 }
6964 }
6965 if (*s == ',')
6966 ++s;
6967 else if (*s)
6968 {
6969 if (errbuf != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006970 errmsg = N_("E527: Missing comma");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006971 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006972 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006973 break;
6974 }
6975 }
6976 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006977 errmsg = N_("E528: Must specify a ' value");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006978 }
6979#endif /* FEAT_VIMINFO */
6980
6981 /* terminal options */
6982 else if (istermoption(&options[opt_idx]) && full_screen)
6983 {
6984 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6985 if (varp == &T_CCO)
6986 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006987 int colors = atoi((char *)T_CCO);
6988
6989 /* Only reinitialize colors if t_Co value has really changed to
6990 * avoid expensive reload of colorscheme if t_Co is set to the
6991 * same value multiple times. */
6992 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006993 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006994 t_colors = colors;
6995 if (t_colors <= 1)
6996 {
6997 if (new_value_alloced)
6998 vim_free(T_CCO);
6999 T_CCO = empty_option;
7000 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007001#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
7002 if (is_term_win32())
7003 {
7004 swap_tcap();
7005 did_swaptcap = TRUE;
7006 }
7007#endif
Bram Moolenaarc84e8952009-03-18 13:21:18 +00007008 /* We now have a different color setup, initialize it again. */
7009 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007010 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007011 }
7012 ttest(FALSE);
7013 if (varp == &T_ME)
7014 {
7015 out_str(T_ME);
7016 redraw_later(CLEAR);
Bram Moolenaarafde13b2019-04-28 19:46:49 +02007017#if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007018 /* Since t_me has been set, this probably means that the user
7019 * wants to use this as default colors. Need to reset default
7020 * background/foreground colors. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02007021# ifdef VIMDLL
7022 if (!gui.in_use && !gui.starting)
7023# endif
7024 mch_set_normal_colors();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007025#endif
7026 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01007027 if (varp == &T_BE && termcap_active)
7028 {
7029 if (*T_BE == NUL)
7030 /* When clearing t_BE we assume the user no longer wants
7031 * bracketed paste, thus disable it by writing t_BD. */
7032 out_str(T_BD);
7033 else
7034 out_str(T_BE);
7035 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007036 }
7037
7038#ifdef FEAT_LINEBREAK
7039 /* 'showbreak' */
7040 else if (varp == &p_sbr)
7041 {
7042 for (s = p_sbr; *s; )
7043 {
7044 if (ptr2cells(s) != 1)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007045 errmsg = N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01007046 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007047 }
7048 }
7049#endif
7050
7051#ifdef FEAT_GUI
7052 /* 'guifont' */
7053 else if (varp == &p_guifont)
7054 {
7055 if (gui.in_use)
7056 {
7057 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00007058# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007059 /*
7060 * Put up a font dialog and let the user select a new value.
7061 * If this is cancelled go back to the old value but don't
7062 * give an error message.
7063 */
7064 if (STRCMP(p, "*") == 0)
7065 {
7066 p = gui_mch_font_dialog(oldval);
7067
7068 if (new_value_alloced)
7069 free_string_option(p_guifont);
7070
7071 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
7072 new_value_alloced = TRUE;
7073 }
7074# endif
7075 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
7076 {
7077# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
7078 if (STRCMP(p_guifont, "*") == 0)
7079 {
7080 /* Dialog was cancelled: Keep the old value without giving
7081 * an error message. */
7082 if (new_value_alloced)
7083 free_string_option(p_guifont);
7084 p_guifont = vim_strsave(oldval);
7085 new_value_alloced = TRUE;
7086 }
7087 else
7088# endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007089 errmsg = N_("E596: Invalid font(s)");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007090 }
7091 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007092 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007093 }
7094# ifdef FEAT_XFONTSET
7095 else if (varp == &p_guifontset)
7096 {
7097 if (STRCMP(p_guifontset, "*") == 0)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007098 errmsg = N_("E597: can't select fontset");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007099 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007100 errmsg = N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007101 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007102 }
7103# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007104 else if (varp == &p_guifontwide)
7105 {
7106 if (STRCMP(p_guifontwide, "*") == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007107 errmsg = N_("E533: can't select wide font");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007108 else if (gui_get_wide_font() == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007109 errmsg = N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007110 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007111 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007112#endif
7113
7114#ifdef CURSOR_SHAPE
7115 /* 'guicursor' */
7116 else if (varp == &p_guicursor)
7117 errmsg = parse_shape_opt(SHAPE_CURSOR);
7118#endif
7119
7120#ifdef FEAT_MOUSESHAPE
7121 /* 'mouseshape' */
7122 else if (varp == &p_mouseshape)
7123 {
7124 errmsg = parse_shape_opt(SHAPE_MOUSE);
7125 update_mouseshape(-1);
7126 }
7127#endif
7128
7129#ifdef FEAT_PRINTER
7130 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00007131 errmsg = parse_printoptions();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01007132# if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00007133 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00007134 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00007135# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007136#endif
7137
7138#ifdef FEAT_LANGMAP
7139 /* 'langmap' */
7140 else if (varp == &p_langmap)
7141 langmap_set();
7142#endif
7143
7144#ifdef FEAT_LINEBREAK
7145 /* 'breakat' */
7146 else if (varp == &p_breakat)
7147 fill_breakat_flags();
7148#endif
7149
7150#ifdef FEAT_TITLE
7151 /* 'titlestring' and 'iconstring' */
7152 else if (varp == &p_titlestring || varp == &p_iconstring)
7153 {
7154# ifdef FEAT_STL_OPT
7155 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
7156
7157 /* NULL => statusline syntax */
7158 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
7159 stl_syntax |= flagval;
7160 else
7161 stl_syntax &= ~flagval;
7162# endif
Bram Moolenaar84a93082018-06-16 22:58:15 +02007163 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007164 }
7165#endif
7166
7167#ifdef FEAT_GUI
7168 /* 'guioptions' */
7169 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007170 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007171 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007172 redraw_gui_only = TRUE;
7173 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007174#endif
7175
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00007176#if defined(FEAT_GUI_TABLINE)
7177 /* 'guitablabel' */
7178 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007179 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00007180 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007181 redraw_gui_only = TRUE;
7182 }
7183 /* 'guitabtooltip' */
7184 else if (varp == &p_gtt)
7185 {
7186 redraw_gui_only = TRUE;
7187 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00007188#endif
7189
Bram Moolenaar071d4272004-06-13 20:20:40 +00007190#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
7191 /* 'ttymouse' */
7192 else if (varp == &p_ttym)
7193 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007194 /* Switch the mouse off before changing the escape sequences used for
7195 * that. */
7196 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007197 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
7198 errmsg = e_invarg;
7199 else
7200 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00007201 if (termcap_active)
7202 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007203 }
7204#endif
7205
Bram Moolenaar071d4272004-06-13 20:20:40 +00007206 /* 'selection' */
7207 else if (varp == &p_sel)
7208 {
7209 if (*p_sel == NUL
7210 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
7211 errmsg = e_invarg;
7212 }
7213
7214 /* 'selectmode' */
7215 else if (varp == &p_slm)
7216 {
7217 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
7218 errmsg = e_invarg;
7219 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007220
7221#ifdef FEAT_BROWSE
7222 /* 'browsedir' */
7223 else if (varp == &p_bsdir)
7224 {
7225 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7226 && !mch_isdir(p_bsdir))
7227 errmsg = e_invarg;
7228 }
7229#endif
7230
Bram Moolenaar071d4272004-06-13 20:20:40 +00007231 /* 'keymodel' */
7232 else if (varp == &p_km)
7233 {
7234 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7235 errmsg = e_invarg;
7236 else
7237 {
7238 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7239 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7240 }
7241 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007242
7243 /* 'mousemodel' */
7244 else if (varp == &p_mousem)
7245 {
7246 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7247 errmsg = e_invarg;
7248#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7249 else if (*p_mousem != *oldval)
7250 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7251 * to create or delete the popup menus. */
7252 gui_motif_update_mousemodel(root_menu);
7253#endif
7254 }
7255
7256 /* 'switchbuf' */
7257 else if (varp == &p_swb)
7258 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007259 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007260 errmsg = e_invarg;
7261 }
7262
7263 /* 'debug' */
7264 else if (varp == &p_debug)
7265 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007266 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007267 errmsg = e_invarg;
7268 }
7269
7270 /* 'display' */
7271 else if (varp == &p_dy)
7272 {
7273 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7274 errmsg = e_invarg;
7275 else
7276 (void)init_chartab();
7277
7278 }
7279
Bram Moolenaar071d4272004-06-13 20:20:40 +00007280 /* 'eadirection' */
7281 else if (varp == &p_ead)
7282 {
7283 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7284 errmsg = e_invarg;
7285 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007286
7287#ifdef FEAT_CLIPBOARD
7288 /* 'clipboard' */
7289 else if (varp == &p_cb)
7290 errmsg = check_clipboard_option();
7291#endif
7292
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007293#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007294 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7295 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007296 else if (varp == &(curwin->w_s->b_p_spl)
7297 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007298 {
Bram Moolenaar862f1e12019-04-10 22:33:41 +02007299 int is_spellfile = varp == &(curwin->w_s->b_p_spf);
7300
7301 if ((is_spellfile && !valid_spellfile(*varp))
7302 || (!is_spellfile && !valid_spellang(*varp)))
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02007303 errmsg = e_invarg;
7304 else
Bram Moolenaar862f1e12019-04-10 22:33:41 +02007305 errmsg = did_set_spell_option(is_spellfile);
Bram Moolenaar217ad922005-03-20 22:37:15 +00007306 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007307 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007308 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007309 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007310 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007311 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007312 /* 'spellsuggest' */
7313 else if (varp == &p_sps)
7314 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007315 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007316 errmsg = e_invarg;
7317 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007318 /* 'mkspellmem' */
7319 else if (varp == &p_msm)
7320 {
7321 if (spell_check_msm() != OK)
7322 errmsg = e_invarg;
7323 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007324#endif
7325
Bram Moolenaar071d4272004-06-13 20:20:40 +00007326 /* When 'bufhidden' is set, check for valid value. */
7327 else if (gvarp == &p_bh)
7328 {
7329 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7330 errmsg = e_invarg;
7331 }
7332
7333 /* When 'buftype' is set, check for valid value. */
7334 else if (gvarp == &p_bt)
7335 {
7336 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7337 errmsg = e_invarg;
7338 else
7339 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007340 if (curwin->w_status_height)
7341 {
7342 curwin->w_redr_status = TRUE;
7343 redraw_later(VALID);
7344 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007345 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007346#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007347 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007348#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007349 }
7350 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007351
7352#ifdef FEAT_STL_OPT
7353 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007354 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007355 {
7356 int wid;
7357
7358 if (varp == &p_ruf) /* reset ru_wid first */
7359 ru_wid = 0;
7360 s = *varp;
7361 if (varp == &p_ruf && *s == '%')
7362 {
7363 /* set ru_wid if 'ruf' starts with "%99(" */
7364 if (*++s == '-') /* ignore a '-' */
7365 s++;
7366 wid = getdigits(&s);
7367 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7368 ru_wid = wid;
7369 else
7370 errmsg = check_stl_option(p_ruf);
7371 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007372 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007373 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007374 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007375 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007376 comp_col();
7377 }
7378#endif
7379
7380#ifdef FEAT_INS_EXPAND
7381 /* check if it is a valid value for 'complete' -- Acevedo */
7382 else if (gvarp == &p_cpt)
7383 {
7384 for (s = *varp; *s;)
7385 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007386 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007387 s++;
7388 if (!*s)
7389 break;
7390 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7391 {
7392 errmsg = illegal_char(errbuf, *s);
7393 break;
7394 }
7395 if (*++s != NUL && *s != ',' && *s != ' ')
7396 {
7397 if (s[-1] == 'k' || s[-1] == 's')
7398 {
7399 /* skip optional filename after 'k' and 's' */
7400 while (*s && *s != ',' && *s != ' ')
7401 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007402 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007403 ++s;
7404 ++s;
7405 }
7406 }
7407 else
7408 {
7409 if (errbuf != NULL)
7410 {
7411 sprintf((char *)errbuf,
7412 _("E535: Illegal character after <%c>"),
7413 *--s);
7414 errmsg = errbuf;
7415 }
7416 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007417 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00007418 break;
7419 }
7420 }
7421 }
7422 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007423
Bram Moolenaarac3150d2019-07-28 16:36:39 +02007424 // 'completeopt'
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007425 else if (varp == &p_cot)
7426 {
7427 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7428 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007429 else
7430 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007431 }
Bram Moolenaarac3150d2019-07-28 16:36:39 +02007432
7433# ifdef BACKSLASH_IN_FILENAME
7434 // 'completeslash'
Bram Moolenaarb78564d2019-07-28 19:24:36 +02007435 else if (gvarp == &p_csl)
Bram Moolenaarac3150d2019-07-28 16:36:39 +02007436 {
Bram Moolenaarb78564d2019-07-28 19:24:36 +02007437 if (check_opt_strings(p_csl, p_csl_values, FALSE) != OK
7438 || check_opt_strings(curbuf->b_p_csl, p_csl_values, FALSE) != OK)
Bram Moolenaarac3150d2019-07-28 16:36:39 +02007439 errmsg = e_invarg;
7440 }
7441# endif
7442#endif // FEAT_INS_EXPAND
Bram Moolenaar071d4272004-06-13 20:20:40 +00007443
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007444#ifdef FEAT_SIGNS
Bram Moolenaare4b407f2019-07-04 11:59:28 +02007445 // 'signcolumn'
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007446 else if (varp == &curwin->w_p_scl)
7447 {
7448 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7449 errmsg = e_invarg;
Bram Moolenaare4b407f2019-07-04 11:59:28 +02007450 // When changing the 'signcolumn' to or from 'number', recompute the
7451 // width of the number column if 'number' or 'relativenumber' is set.
7452 if (((*oldval == 'n' && *(oldval + 1) == 'u')
7453 || (*curwin->w_p_scl == 'n' && *(curwin->w_p_scl + 1) =='u'))
7454 && (curwin->w_p_nu || curwin->w_p_rnu))
7455 curwin->w_nrwidth_line_count = 0;
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007456 }
7457#endif
7458
Bram Moolenaar071d4272004-06-13 20:20:40 +00007459
Bram Moolenaar4f974752019-02-17 17:44:42 +01007460#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007461 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007462 else if (varp == &p_toolbar)
7463 {
7464 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7465 &toolbar_flags, TRUE) != OK)
7466 errmsg = e_invarg;
7467 else
7468 {
7469 out_flush();
7470 gui_mch_show_toolbar((toolbar_flags &
7471 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7472 }
7473 }
7474#endif
7475
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007476#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007477 /* 'toolbariconsize': GTK+ 2 only */
7478 else if (varp == &p_tbis)
7479 {
7480 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7481 errmsg = e_invarg;
7482 else
7483 {
7484 out_flush();
7485 gui_mch_show_toolbar((toolbar_flags &
7486 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7487 }
7488 }
7489#endif
7490
7491 /* 'pastetoggle': translate key codes like in a mapping */
7492 else if (varp == &p_pt)
7493 {
7494 if (*p_pt)
7495 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007496 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007497 if (p != NULL)
7498 {
7499 if (new_value_alloced)
7500 free_string_option(p_pt);
7501 p_pt = p;
7502 new_value_alloced = TRUE;
7503 }
7504 }
7505 }
7506
7507 /* 'backspace' */
7508 else if (varp == &p_bs)
7509 {
7510 if (VIM_ISDIGIT(*p_bs))
7511 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007512 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007513 errmsg = e_invarg;
7514 }
7515 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7516 errmsg = e_invarg;
7517 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007518 else if (varp == &p_bo)
7519 {
7520 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7521 errmsg = e_invarg;
7522 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007523
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007524 /* 'tagcase' */
7525 else if (gvarp == &p_tc)
7526 {
7527 unsigned int *flags;
7528
7529 if (opt_flags & OPT_LOCAL)
7530 {
7531 p = curbuf->b_p_tc;
7532 flags = &curbuf->b_tc_flags;
7533 }
7534 else
7535 {
7536 p = p_tc;
7537 flags = &tc_flags;
7538 }
7539
7540 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7541 /* make the local value empty: use the global value */
7542 *flags = 0;
7543 else if (*p == NUL
7544 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7545 errmsg = e_invarg;
7546 }
7547
Bram Moolenaar071d4272004-06-13 20:20:40 +00007548 /* 'casemap' */
7549 else if (varp == &p_cmp)
7550 {
7551 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7552 errmsg = e_invarg;
7553 }
7554
7555#ifdef FEAT_DIFF
7556 /* 'diffopt' */
7557 else if (varp == &p_dip)
7558 {
7559 if (diffopt_changed() == FAIL)
7560 errmsg = e_invarg;
7561 }
7562#endif
7563
7564#ifdef FEAT_FOLDING
7565 /* 'foldmethod' */
7566 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7567 {
7568 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7569 || *curwin->w_p_fdm == NUL)
7570 errmsg = e_invarg;
7571 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007572 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007573 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007574 if (foldmethodIsDiff(curwin))
7575 newFoldLevel();
7576 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007577 }
7578# ifdef FEAT_EVAL
7579 /* 'foldexpr' */
7580 else if (varp == &curwin->w_p_fde)
7581 {
7582 if (foldmethodIsExpr(curwin))
7583 foldUpdateAll(curwin);
7584 }
7585# endif
7586 /* 'foldmarker' */
7587 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7588 {
7589 p = vim_strchr(*varp, ',');
7590 if (p == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007591 errmsg = N_("E536: comma required");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007592 else if (p == *varp || p[1] == NUL)
7593 errmsg = e_invarg;
7594 else if (foldmethodIsMarker(curwin))
7595 foldUpdateAll(curwin);
7596 }
7597 /* 'commentstring' */
7598 else if (gvarp == &p_cms)
7599 {
7600 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007601 errmsg = N_("E537: 'commentstring' must be empty or contain %s");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007602 }
7603 /* 'foldopen' */
7604 else if (varp == &p_fdo)
7605 {
7606 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7607 errmsg = e_invarg;
7608 }
7609 /* 'foldclose' */
7610 else if (varp == &p_fcl)
7611 {
7612 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7613 errmsg = e_invarg;
7614 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007615 /* 'foldignore' */
7616 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7617 {
7618 if (foldmethodIsIndent(curwin))
7619 foldUpdateAll(curwin);
7620 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007621#endif
7622
Bram Moolenaar071d4272004-06-13 20:20:40 +00007623 /* 'virtualedit' */
7624 else if (varp == &p_ve)
7625 {
7626 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7627 errmsg = e_invarg;
7628 else if (STRCMP(p_ve, oldval) != 0)
7629 {
7630 /* Recompute cursor position in case the new 've' setting
7631 * changes something. */
7632 validate_virtcol();
7633 coladvance(curwin->w_virtcol);
7634 }
7635 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007636
7637#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7638 else if (varp == &p_csqf)
7639 {
7640 if (p_csqf != NULL)
7641 {
7642 p = p_csqf;
7643 while (*p != NUL)
7644 {
7645 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7646 || p[1] == NUL
7647 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7648 || (p[2] != NUL && p[2] != ','))
7649 {
7650 errmsg = e_invarg;
7651 break;
7652 }
7653 else if (p[2] == NUL)
7654 break;
7655 else
7656 p += 3;
7657 }
7658 }
7659 }
7660#endif
7661
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007662#ifdef FEAT_CINDENT
7663 /* 'cinoptions' */
7664 else if (gvarp == &p_cino)
7665 {
7666 /* TODO: recognize errors */
7667 parse_cino(curbuf);
7668 }
7669#endif
7670
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007671#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007672 /* 'renderoptions' */
Bram Moolenaar3767c6e2017-12-05 16:57:56 +01007673 else if (varp == &p_rop)
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007674 {
7675 if (!gui_mch_set_rendering_options(p_rop))
7676 errmsg = e_invarg;
7677 }
7678#endif
7679
Bram Moolenaard0b51382016-11-04 15:23:45 +01007680 else if (gvarp == &p_ft)
7681 {
7682 if (!valid_filetype(*varp))
7683 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007684 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007685 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007686 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007687
7688 // Since we check the value, there is no need to set P_INSECURE,
7689 // even when the value comes from a modeline.
7690 *value_checked = TRUE;
7691 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007692 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007693
7694#ifdef FEAT_SYN_HL
7695 else if (gvarp == &p_syn)
7696 {
7697 if (!valid_filetype(*varp))
7698 errmsg = e_invarg;
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007699 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007700 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007701 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007702
7703 // Since we check the value, there is no need to set P_INSECURE,
7704 // even when the value comes from a modeline.
7705 *value_checked = TRUE;
7706 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007707 }
7708#endif
7709
Bram Moolenaar825680f2017-07-22 17:04:02 +02007710#ifdef FEAT_TERMINAL
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007711 // 'termwinkey'
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007712 else if (varp == &curwin->w_p_twk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007713 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007714 if (*curwin->w_p_twk != NUL
7715 && string_to_key(curwin->w_p_twk, TRUE) == 0)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007716 errmsg = e_invarg;
7717 }
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007718 // 'termwinsize'
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007719 else if (varp == &curwin->w_p_tws)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007720 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007721 if (*curwin->w_p_tws != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007722 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007723 p = skipdigits(curwin->w_p_tws);
7724 if (p == curwin->w_p_tws
Bram Moolenaar498c2562018-04-15 23:45:15 +02007725 || (*p != 'x' && *p != '*')
7726 || *skipdigits(p + 1) != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007727 errmsg = e_invarg;
7728 }
7729 }
Bram Moolenaar4f974752019-02-17 17:44:42 +01007730# if defined(MSWIN)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007731 // 'termwintype'
7732 else if (varp == &p_twt)
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007733 {
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007734 if (check_opt_strings(*varp, p_twt_values, FALSE) != OK)
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007735 errmsg = e_invarg;
7736 }
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007737# endif
Bram Moolenaar825680f2017-07-22 17:04:02 +02007738#endif
7739
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007740#ifdef FEAT_VARTABS
7741 /* 'varsofttabstop' */
7742 else if (varp == &(curbuf->b_p_vsts))
7743 {
7744 char_u *cp;
7745
7746 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7747 {
7748 if (curbuf->b_p_vsts_array)
7749 {
7750 vim_free(curbuf->b_p_vsts_array);
7751 curbuf->b_p_vsts_array = 0;
7752 }
7753 }
7754 else
7755 {
7756 for (cp = *varp; *cp; ++cp)
7757 {
7758 if (vim_isdigit(*cp))
7759 continue;
7760 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7761 continue;
7762 errmsg = e_invarg;
7763 break;
7764 }
7765 if (errmsg == NULL)
7766 {
7767 int *oldarray = curbuf->b_p_vsts_array;
7768 if (tabstop_set(*varp, &(curbuf->b_p_vsts_array)))
7769 {
7770 if (oldarray)
7771 vim_free(oldarray);
7772 }
7773 else
7774 errmsg = e_invarg;
7775 }
7776 }
7777 }
7778
7779 /* 'vartabstop' */
7780 else if (varp == &(curbuf->b_p_vts))
7781 {
7782 char_u *cp;
7783
7784 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7785 {
7786 if (curbuf->b_p_vts_array)
7787 {
7788 vim_free(curbuf->b_p_vts_array);
7789 curbuf->b_p_vts_array = NULL;
7790 }
7791 }
7792 else
7793 {
7794 for (cp = *varp; *cp; ++cp)
7795 {
7796 if (vim_isdigit(*cp))
7797 continue;
7798 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7799 continue;
7800 errmsg = e_invarg;
7801 break;
7802 }
7803 if (errmsg == NULL)
7804 {
7805 int *oldarray = curbuf->b_p_vts_array;
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007806
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007807 if (tabstop_set(*varp, &(curbuf->b_p_vts_array)))
7808 {
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007809 vim_free(oldarray);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007810#ifdef FEAT_FOLDING
7811 if (foldmethodIsIndent(curwin))
7812 foldUpdateAll(curwin);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007813#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007814 }
7815 else
7816 errmsg = e_invarg;
7817 }
7818 }
7819 }
7820#endif
7821
Bram Moolenaar79648732019-07-18 21:43:07 +02007822#ifdef FEAT_TEXT_PROP
7823 // 'previewpopup'
7824 else if (varp == &p_pvp)
7825 {
7826 if (parse_previewpopup(NULL) == FAIL)
7827 errmsg = e_invarg;
7828 }
Bram Moolenaar62a0cb42019-08-18 16:35:23 +02007829 // 'completepopup'
7830 else if (varp == &p_cpp)
7831 {
7832 if (parse_completepopup(NULL) == FAIL)
7833 errmsg = e_invarg;
7834 }
Bram Moolenaar79648732019-07-18 21:43:07 +02007835#endif
7836
Bram Moolenaar071d4272004-06-13 20:20:40 +00007837 /* Options that are a list of flags. */
7838 else
7839 {
7840 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007841 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007842 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007843 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007844 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007845 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007846 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007847 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007848 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007849#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007850 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007851 p = (char_u *)COCU_ALL;
7852#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007853 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007854 {
7855#ifdef FEAT_MOUSE
7856 p = (char_u *)MOUSE_ALL;
7857#else
7858 if (*p_mouse != NUL)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007859 errmsg = N_("E538: No mouse support");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007860#endif
7861 }
7862#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007863 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007864 p = (char_u *)GO_ALL;
7865#endif
7866 if (p != NULL)
7867 {
7868 for (s = *varp; *s; ++s)
7869 if (vim_strchr(p, *s) == NULL)
7870 {
7871 errmsg = illegal_char(errbuf, *s);
7872 break;
7873 }
7874 }
7875 }
7876
7877 /*
7878 * If error detected, restore the previous value.
7879 */
7880 if (errmsg != NULL)
7881 {
7882 if (new_value_alloced)
7883 free_string_option(*varp);
7884 *varp = oldval;
7885 /*
7886 * When resetting some values, need to act on it.
7887 */
7888 if (did_chartab)
7889 (void)init_chartab();
7890 if (varp == &p_hl)
7891 (void)highlight_changed();
7892 }
7893 else
7894 {
7895#ifdef FEAT_EVAL
7896 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02007897 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007898#endif
7899 /*
7900 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007901 * Use "free_oldval", because recursiveness may change the flags under
7902 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007903 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007904 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007905 free_string_option(oldval);
7906 if (new_value_alloced)
7907 options[opt_idx].flags |= P_ALLOCED;
7908 else
7909 options[opt_idx].flags &= ~P_ALLOCED;
7910
7911 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007912 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007913 {
7914 /* global option with local value set to use global value; free
7915 * the local value and make it empty */
7916 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7917 free_string_option(*(char_u **)p);
7918 *(char_u **)p = empty_option;
7919 }
7920
7921 /* May set global value for local option. */
7922 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7923 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007924
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007925 /*
7926 * Trigger the autocommand only after setting the flags.
7927 */
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007928#ifdef FEAT_SYN_HL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007929 /* When 'syntax' is set, load the syntax of that name */
7930 if (varp == &(curbuf->b_p_syn))
7931 {
Bram Moolenaara5616b02018-06-17 19:08:30 +02007932 static int syn_recursive = 0;
7933
7934 ++syn_recursive;
7935 // Only pass TRUE for "force" when the value changed or not used
7936 // recursively, to avoid endless recurrence.
7937 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname,
7938 value_changed || syn_recursive == 1, curbuf);
Bram Moolenaarc7f1e402019-08-03 13:29:46 +02007939 curbuf->b_flags |= BF_SYN_SET;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007940 --syn_recursive;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007941 }
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007942#endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007943 else if (varp == &(curbuf->b_p_ft))
7944 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007945 /* 'filetype' is set, trigger the FileType autocommand.
7946 * Skip this when called from a modeline and the filetype was
Bram Moolenaara5616b02018-06-17 19:08:30 +02007947 * already set to this value. */
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007948 if (!(opt_flags & OPT_MODELINE) || value_changed)
Bram Moolenaar90492982017-06-22 14:16:31 +02007949 {
Bram Moolenaar916a8182018-11-25 02:18:29 +01007950 static int ft_recursive = 0;
7951 int secure_save = secure;
7952
7953 // Reset the secure flag, since the value of 'filetype' has
7954 // been checked to be safe.
7955 secure = 0;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007956
7957 ++ft_recursive;
Bram Moolenaar90492982017-06-22 14:16:31 +02007958 did_filetype = TRUE;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007959 // Only pass TRUE for "force" when the value changed or not
7960 // used recursively, to avoid endless recurrence.
7961 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname,
7962 value_changed || ft_recursive == 1, curbuf);
7963 --ft_recursive;
Bram Moolenaar163095f2017-07-09 15:41:53 +02007964 /* Just in case the old "curbuf" is now invalid. */
7965 if (varp != &(curbuf->b_p_ft))
7966 varp = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007967
7968 secure = secure_save;
Bram Moolenaar90492982017-06-22 14:16:31 +02007969 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007970 }
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007971#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007972 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007973 {
7974 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007975 char_u *q = curwin->w_s->b_p_spl;
7976
7977 /* Skip the first name if it is "cjk". */
7978 if (STRNCMP(q, "cjk,", 4) == 0)
7979 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007980
7981 /*
7982 * Source the spell/LANG.vim in 'runtimepath'.
7983 * They could set 'spellcapcheck' depending on the language.
7984 * Use the first name in 'spelllang' up to '_region' or
7985 * '.encoding'.
7986 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007987 for (p = q; *p != NUL; ++p)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01007988 if (!ASCII_ISALNUM(*p) && *p != '-')
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007989 break;
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007990 if (p > q)
7991 {
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02007992 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
7993 (int)(p - q), q);
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007994 source_runtime(fname, DIP_ALL);
7995 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007996 }
7997#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007998 }
7999
8000#ifdef FEAT_MOUSE
8001 if (varp == &p_mouse)
8002 {
8003# ifdef FEAT_MOUSE_TTY
8004 if (*p_mouse == NUL)
8005 mch_setmouse(FALSE); /* switch mouse off */
8006 else
8007# endif
8008 setmouse(); /* in case 'mouse' changed */
8009 }
8010#endif
8011
Bram Moolenaar913077c2012-03-28 19:59:04 +02008012 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008013 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008014 curwin->w_set_curswant = TRUE;
8015
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00008016#ifdef FEAT_GUI
8017 /* check redraw when it's not a GUI option or the GUI is active. */
8018 if (!redraw_gui_only || gui.in_use)
8019#endif
8020 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008021
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008022#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
8023 if (did_swaptcap)
8024 {
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008025 set_termname((char_u *)"win32");
8026 init_highlight(TRUE, FALSE);
8027 }
8028#endif
8029
Bram Moolenaar071d4272004-06-13 20:20:40 +00008030 return errmsg;
8031}
8032
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01008033#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02008034/*
8035 * Simple int comparison function for use with qsort()
8036 */
8037 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01008038int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02008039{
8040 return *(const int *)a - *(const int *)b;
8041}
8042
8043/*
8044 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
8045 * Returns error message, NULL if it's OK.
8046 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008047 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008048check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02008049{
8050 char_u *s;
8051 int col;
8052 int count = 0;
8053 int color_cols[256];
8054 int i;
8055 int j = 0;
8056
Bram Moolenaar50f834d2011-09-21 13:40:17 +02008057 if (wp->w_buffer == NULL)
8058 return NULL; /* buffer was closed */
8059
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008060 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02008061 {
8062 if (*s == '-' || *s == '+')
8063 {
8064 /* -N and +N: add to 'textwidth' */
8065 col = (*s == '-') ? -1 : 1;
8066 ++s;
8067 if (!VIM_ISDIGIT(*s))
8068 return e_invarg;
8069 col = col * getdigits(&s);
8070 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008071 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02008072 col += wp->w_buffer->b_p_tw;
8073 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008074 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02008075 }
8076 else if (VIM_ISDIGIT(*s))
8077 col = getdigits(&s);
8078 else
8079 return e_invarg;
8080 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008081skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02008082 if (*s == NUL)
8083 break;
8084 if (*s != ',')
8085 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008086 if (*++s == NUL)
8087 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02008088 }
8089
8090 vim_free(wp->w_p_cc_cols);
8091 if (count == 0)
8092 wp->w_p_cc_cols = NULL;
8093 else
8094 {
Bram Moolenaarc799fe22019-05-28 23:08:19 +02008095 wp->w_p_cc_cols = ALLOC_MULT(int, count + 1);
Bram Moolenaar1a384422010-07-14 19:53:30 +02008096 if (wp->w_p_cc_cols != NULL)
8097 {
8098 /* sort the columns for faster usage on screen redraw inside
8099 * win_line() */
8100 qsort(color_cols, count, sizeof(int), int_cmp);
8101
8102 for (i = 0; i < count; ++i)
8103 /* skip duplicates */
8104 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
8105 wp->w_p_cc_cols[j++] = color_cols[i];
8106 wp->w_p_cc_cols[j] = -1; /* end marker */
8107 }
8108 }
8109
8110 return NULL; /* no error */
8111}
8112#endif
8113
Bram Moolenaar071d4272004-06-13 20:20:40 +00008114/*
8115 * Handle setting 'listchars' or 'fillchars'.
8116 * Returns error message, NULL if it's OK.
8117 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008118 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008119set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008120{
8121 int round, i, len, entries;
8122 char_u *p, *s;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008123 int c1 = 0, c2 = 0, c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008124 struct charstab
8125 {
8126 int *cp;
8127 char *name;
8128 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00008129 static struct charstab filltab[] =
8130 {
8131 {&fill_stl, "stl"},
8132 {&fill_stlnc, "stlnc"},
8133 {&fill_vert, "vert"},
8134 {&fill_fold, "fold"},
8135 {&fill_diff, "diff"},
8136 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00008137 static struct charstab lcstab[] =
8138 {
8139 {&lcs_eol, "eol"},
8140 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008141 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00008142 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02008143 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00008144 {&lcs_tab2, "tab"},
8145 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02008146#ifdef FEAT_CONCEAL
8147 {&lcs_conceal, "conceal"},
8148#else
8149 {NULL, "conceal"},
8150#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008151 };
8152 struct charstab *tab;
8153
Bram Moolenaar071d4272004-06-13 20:20:40 +00008154 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008155 {
8156 tab = lcstab;
8157 entries = sizeof(lcstab) / sizeof(struct charstab);
8158 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008159 else
8160 {
8161 tab = filltab;
8162 entries = sizeof(filltab) / sizeof(struct charstab);
8163 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008164
8165 /* first round: check for valid value, second round: assign values */
8166 for (round = 0; round <= 1; ++round)
8167 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008168 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008169 {
8170 /* After checking that the value is valid: set defaults: space for
8171 * 'fillchars', NUL for 'listchars' */
8172 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008173 if (tab[i].cp != NULL)
8174 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar83a52172019-01-16 22:41:54 +01008175
Bram Moolenaar071d4272004-06-13 20:20:40 +00008176 if (varp == &p_lcs)
Bram Moolenaar83a52172019-01-16 22:41:54 +01008177 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008178 lcs_tab1 = NUL;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008179 lcs_tab3 = NUL;
8180 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008181 else
8182 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008183 }
8184 p = *varp;
8185 while (*p)
8186 {
8187 for (i = 0; i < entries; ++i)
8188 {
8189 len = (int)STRLEN(tab[i].name);
8190 if (STRNCMP(p, tab[i].name, len) == 0
8191 && p[len] == ':'
8192 && p[len + 1] != NUL)
8193 {
Bram Moolenaar2c519cf2019-03-21 21:45:34 +01008194 c2 = c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008195 s = p + len + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008196 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00008197 if (mb_char2cells(c1) > 1)
8198 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008199 if (tab[i].cp == &lcs_tab2)
8200 {
8201 if (*s == NUL)
8202 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008203 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00008204 if (mb_char2cells(c2) > 1)
8205 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008206 if (!(*s == ',' || *s == NUL))
8207 {
Bram Moolenaar83a52172019-01-16 22:41:54 +01008208 c3 = mb_ptr2char_adv(&s);
8209 if (mb_char2cells(c3) > 1)
8210 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008211 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008212 }
Bram Moolenaar83a52172019-01-16 22:41:54 +01008213
Bram Moolenaar071d4272004-06-13 20:20:40 +00008214 if (*s == ',' || *s == NUL)
8215 {
8216 if (round)
8217 {
8218 if (tab[i].cp == &lcs_tab2)
8219 {
8220 lcs_tab1 = c1;
8221 lcs_tab2 = c2;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008222 lcs_tab3 = c3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008223 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008224 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008225 *(tab[i].cp) = c1;
8226
8227 }
8228 p = s;
8229 break;
8230 }
8231 }
8232 }
8233
8234 if (i == entries)
8235 return e_invarg;
8236 if (*p == ',')
8237 ++p;
8238 }
8239 }
8240
8241 return NULL; /* no error */
8242}
8243
8244#ifdef FEAT_STL_OPT
8245/*
8246 * Check validity of options with the 'statusline' format.
8247 * Return error message or NULL.
8248 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008249 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008250check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008251{
8252 int itemcnt = 0;
8253 int groupdepth = 0;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008254 static char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00008255
8256 while (*s && itemcnt < STL_MAX_ITEM)
8257 {
8258 /* Check for valid keys after % sequences */
8259 while (*s && *s != '%')
8260 s++;
8261 if (!*s)
8262 break;
8263 s++;
8264 if (*s != '%' && *s != ')')
8265 ++itemcnt;
8266 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
8267 {
8268 s++;
8269 continue;
8270 }
8271 if (*s == ')')
8272 {
8273 s++;
8274 if (--groupdepth < 0)
8275 break;
8276 continue;
8277 }
8278 if (*s == '-')
8279 s++;
8280 while (VIM_ISDIGIT(*s))
8281 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00008282 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008283 continue;
8284 if (*s == '.')
8285 {
8286 s++;
8287 while (*s && VIM_ISDIGIT(*s))
8288 s++;
8289 }
8290 if (*s == '(')
8291 {
8292 groupdepth++;
8293 continue;
8294 }
8295 if (vim_strchr(STL_ALL, *s) == NULL)
8296 {
8297 return illegal_char(errbuf, *s);
8298 }
8299 if (*s == '{')
8300 {
8301 s++;
8302 while (*s != '}' && *s)
8303 s++;
8304 if (*s != '}')
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008305 return N_("E540: Unclosed expression sequence");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008306 }
8307 }
8308 if (itemcnt >= STL_MAX_ITEM)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008309 return N_("E541: too many items");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008310 if (groupdepth != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008311 return N_("E542: unbalanced groups");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008312 return NULL;
8313}
8314#endif
8315
8316#ifdef FEAT_CLIPBOARD
8317/*
8318 * Extract the items in the 'clipboard' option and set global values.
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008319 * Return an error message or NULL for success.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008320 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008321 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008322check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008323{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008324 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008325 int new_autoselect_star = FALSE;
8326 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008327 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008328 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008329 regprog_T *new_exclude_prog = NULL;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008330 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008331 char_u *p;
8332
8333 for (p = p_cb; *p != NUL; )
8334 {
8335 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
8336 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008337 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008338 p += 7;
8339 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02008340 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008341 && (p[11] == ',' || p[11] == NUL))
8342 {
8343 new_unnamed |= CLIP_UNNAMED_PLUS;
8344 p += 11;
8345 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008346 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008347 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008348 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02008349 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008350 p += 10;
8351 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02008352 else if (STRNCMP(p, "autoselectplus", 14) == 0
8353 && (p[14] == ',' || p[14] == NUL))
8354 {
8355 new_autoselect_plus = TRUE;
8356 p += 14;
8357 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008358 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008359 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008360 {
8361 new_autoselectml = TRUE;
8362 p += 12;
8363 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008364 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
8365 {
8366 new_html = TRUE;
8367 p += 4;
8368 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008369 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
8370 {
8371 p += 8;
8372 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
8373 if (new_exclude_prog == NULL)
8374 errmsg = e_invarg;
8375 break;
8376 }
8377 else
8378 {
8379 errmsg = e_invarg;
8380 break;
8381 }
8382 if (*p == ',')
8383 ++p;
8384 }
8385 if (errmsg == NULL)
8386 {
8387 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008388 clip_autoselect_star = new_autoselect_star;
8389 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008390 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008391 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008392 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008393 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008394#ifdef FEAT_GUI_GTK
8395 if (gui.in_use)
8396 {
8397 gui_gtk_set_selection_targets();
8398 gui_gtk_set_dnd_targets();
8399 }
8400#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008401 }
8402 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008403 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008404
8405 return errmsg;
8406}
8407#endif
8408
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008409#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008410/*
8411 * Handle side effects of setting 'spell'.
8412 * Return an error message or NULL for success.
8413 */
8414 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008415did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008416{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008417 char *errmsg = NULL;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008418 win_T *wp;
8419 int l;
8420
8421 if (is_spellfile)
8422 {
8423 l = (int)STRLEN(curwin->w_s->b_p_spf);
8424 if (l > 0 && (l < 4
8425 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8426 errmsg = e_invarg;
8427 }
8428
8429 if (errmsg == NULL)
8430 {
8431 FOR_ALL_WINDOWS(wp)
8432 if (wp->w_buffer == curbuf && wp->w_p_spell)
8433 {
8434 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008435 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008436 }
8437 }
8438 return errmsg;
8439}
8440
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008441/*
8442 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8443 * Return error message when failed, NULL when OK.
8444 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008445 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008446compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008447{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008448 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008449 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008450
Bram Moolenaar860cae12010-06-05 23:22:07 +02008451 if (*synblock->b_p_spc == NUL)
8452 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008453 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008454 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008455 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008456 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008457 if (re != NULL)
8458 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008459 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008460 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008461 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008462 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008463 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008464 return e_invarg;
8465 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008466 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008467 }
8468
Bram Moolenaar473de612013-06-08 18:19:48 +02008469 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008470 return NULL;
8471}
8472#endif
8473
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008474#if defined(FEAT_EVAL) || defined(PROTO)
8475/*
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008476 * Set the script_ctx for an option, taking care of setting the buffer- or
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008477 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008478 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008479 static void
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008480set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008481{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008482 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8483 int indir = (int)options[opt_idx].indir;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008484 sctx_T new_script_ctx = script_ctx;
8485
8486 new_script_ctx.sc_lnum += sourcing_lnum;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008487
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008488 /* Remember where the option was set. For local options need to do that
8489 * in the buffer or window structure. */
8490 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008491 options[opt_idx].script_ctx = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008492 if (both || (opt_flags & OPT_LOCAL))
8493 {
8494 if (indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008495 curbuf->b_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008496 else if (indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008497 curwin->w_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008498 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008499}
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02008500
8501/*
8502 * Set the script_ctx for a termcap option.
8503 * "name" must be the two character code, e.g. "RV".
8504 * When "name" is NULL use "opt_idx".
8505 */
8506 void
8507set_term_option_sctx_idx(char *name, int opt_idx)
8508{
8509 char_u buf[5];
8510 int idx;
8511
8512 if (name == NULL)
8513 idx = opt_idx;
8514 else
8515 {
8516 buf[0] = 't';
8517 buf[1] = '_';
8518 buf[2] = name[0];
8519 buf[3] = name[1];
8520 buf[4] = 0;
8521 idx = findoption(buf);
8522 }
8523 if (idx >= 0)
8524 set_option_sctx_idx(idx, OPT_GLOBAL, current_sctx);
8525}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008526#endif
8527
Bram Moolenaar071d4272004-06-13 20:20:40 +00008528/*
8529 * Set the value of a boolean option, and take care of side effects.
8530 * Returns NULL for success, or an error message for an error.
8531 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008532 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008533set_bool_option(
8534 int opt_idx, /* index in options[] table */
8535 char_u *varp, /* pointer to the option variable */
8536 int value, /* new value */
8537 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008538{
8539 int old_value = *(int *)varp;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008540#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02008541 int old_global_value = 0;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008542#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008543
Bram Moolenaar071d4272004-06-13 20:20:40 +00008544 /* Disallow changing some options from secure mode */
8545 if ((secure
8546#ifdef HAVE_SANDBOX
8547 || sandbox != 0
8548#endif
8549 ) && (options[opt_idx].flags & P_SECURE))
8550 return e_secure;
8551
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008552#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02008553 // Save the global value before changing anything. This is needed as for
8554 // a global-only option setting the "local value" in fact sets the global
8555 // value (since there is only one value).
8556 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8557 old_global_value = *(int *)get_varp_scope(&(options[opt_idx]),
8558 OPT_GLOBAL);
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008559#endif
Bram Moolenaard7c96872019-06-15 17:12:48 +02008560
Bram Moolenaar071d4272004-06-13 20:20:40 +00008561 *(int *)varp = value; /* set the new value */
8562#ifdef FEAT_EVAL
8563 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008564 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008565#endif
8566
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008567#ifdef FEAT_GUI
8568 need_mouse_correct = TRUE;
8569#endif
8570
Bram Moolenaar071d4272004-06-13 20:20:40 +00008571 /* May set global value for local option. */
8572 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8573 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8574
8575 /*
8576 * Handle side effects of changing a bool option.
8577 */
8578
8579 /* 'compatible' */
8580 if ((int *)varp == &p_cp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008581 compatible_set();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008582
Bram Moolenaar920694c2016-08-21 17:45:02 +02008583#ifdef FEAT_LANGMAP
8584 if ((int *)varp == &p_lrm)
8585 /* 'langremap' -> !'langnoremap' */
8586 p_lnr = !p_lrm;
8587 else if ((int *)varp == &p_lnr)
8588 /* 'langnoremap' -> !'langremap' */
8589 p_lrm = !p_lnr;
8590#endif
8591
Bram Moolenaar8c63e0e2018-09-25 22:17:54 +02008592#ifdef FEAT_SYN_HL
8593 else if ((int *)varp == &curwin->w_p_cul && !value && old_value)
8594 reset_cursorline();
8595#endif
8596
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008597#ifdef FEAT_PERSISTENT_UNDO
8598 /* 'undofile' */
8599 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8600 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008601 /* Only take action when the option was set. When reset we do not
8602 * delete the undo file, the option may be set again without making
8603 * any changes in between. */
8604 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008605 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008606 char_u hash[UNDO_HASH_SIZE];
8607 buf_T *save_curbuf = curbuf;
8608
Bram Moolenaar29323592016-07-24 22:04:11 +02008609 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008610 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008611 /* When 'undofile' is set globally: for every buffer, otherwise
8612 * only for the current buffer: Try to read in the undofile,
8613 * if one exists, the buffer wasn't changed and the buffer was
8614 * loaded */
8615 if ((curbuf == save_curbuf
8616 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8617 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8618 {
8619 u_compute_hash(hash);
8620 u_read_undo(NULL, hash, curbuf->b_fname);
8621 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008622 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008623 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008624 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008625 }
8626#endif
8627
Bram Moolenaar071d4272004-06-13 20:20:40 +00008628 else if ((int *)varp == &curbuf->b_p_ro)
8629 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008630 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008631 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8632 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008633
8634 /* when 'readonly' is set may give W10 again */
8635 if (curbuf->b_p_ro)
8636 curbuf->b_did_warn = FALSE;
8637
Bram Moolenaar071d4272004-06-13 20:20:40 +00008638#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008639 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008640#endif
8641 }
8642
Bram Moolenaar9c449722010-07-20 18:44:27 +02008643#ifdef FEAT_GUI
8644 else if ((int *)varp == &p_mh)
8645 {
8646 if (!p_mh)
8647 gui_mch_mousehide(FALSE);
8648 }
8649#endif
8650
Bram Moolenaara539df02010-08-01 14:35:05 +02008651 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008652 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008653 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008654# ifdef FEAT_TERMINAL
8655 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaard7db27b2018-03-07 23:02:33 +01008656 if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf)
8657 && curbuf->b_term != NULL && !term_is_finished(curbuf))))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008658 {
8659 curbuf->b_p_ma = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008660 return N_("E946: Cannot make a terminal with running job modifiable");
Bram Moolenaar423802d2017-07-30 16:52:24 +02008661 }
8662# endif
8663# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008664 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008665# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008666 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008667#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008668 /* when 'endofline' is changed, redraw the window title */
8669 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008670 {
8671 redraw_titles();
8672 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008673 /* when 'fixeol' is changed, redraw the window title */
8674 else if ((int *)varp == &curbuf->b_p_fixeol)
8675 {
8676 redraw_titles();
8677 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008678 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008679 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008680 {
8681 redraw_titles();
8682 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008683#endif
8684
8685 /* when 'bin' is set also set some other options */
8686 else if ((int *)varp == &curbuf->b_p_bin)
8687 {
8688 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8689#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008690 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008691#endif
8692 }
8693
Bram Moolenaar071d4272004-06-13 20:20:40 +00008694 /* when 'buflisted' changes, trigger autocommands */
8695 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8696 {
8697 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8698 NULL, NULL, TRUE, curbuf);
8699 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008700
8701 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8702 else if ((int *)varp == &curbuf->b_p_swf)
8703 {
8704 if (curbuf->b_p_swf && p_uc)
8705 ml_open_file(curbuf); /* create the swap file */
8706 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008707 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8708 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008709 mf_close_file(curbuf, TRUE); /* remove the swap file */
8710 }
8711
8712 /* when 'terse' is set change 'shortmess' */
8713 else if ((int *)varp == &p_terse)
8714 {
8715 char_u *p;
8716
8717 p = vim_strchr(p_shm, SHM_SEARCH);
8718
8719 /* insert 's' in p_shm */
8720 if (p_terse && p == NULL)
8721 {
8722 STRCPY(IObuff, p_shm);
8723 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008724 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008725 }
8726 /* remove 's' from p_shm */
8727 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008728 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008729 }
8730
8731 /* when 'paste' is set or reset also change other options */
8732 else if ((int *)varp == &p_paste)
8733 {
8734 paste_option_changed();
8735 }
8736
8737 /* when 'insertmode' is set from an autocommand need to do work here */
8738 else if ((int *)varp == &p_im)
8739 {
8740 if (p_im)
8741 {
8742 if ((State & INSERT) == 0)
8743 need_start_insertmode = TRUE;
8744 stop_insert_mode = FALSE;
8745 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008746 /* only reset if it was set previously */
8747 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008748 {
8749 need_start_insertmode = FALSE;
8750 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008751 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008752 clear_cmdline = TRUE; /* remove "(insert)" */
8753 restart_edit = 0;
8754 }
8755 }
8756
8757 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8758 else if ((int *)varp == &p_ic && p_hls)
8759 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008760 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008761 }
8762
8763#ifdef FEAT_SEARCH_EXTRA
8764 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8765 else if ((int *)varp == &p_hls)
8766 {
Bram Moolenaar451fc7b2018-04-27 22:53:07 +02008767 set_no_hlsearch(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008768 }
8769#endif
8770
Bram Moolenaar071d4272004-06-13 20:20:40 +00008771 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8772 * at the end of normal_cmd() */
8773 else if ((int *)varp == &curwin->w_p_scb)
8774 {
8775 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008776 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008777 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008778 curwin->w_scbind_pos = curwin->w_topline;
8779 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008780 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008781
Bram Moolenaar4033c552017-09-16 20:54:51 +02008782#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008783 /* There can be only one window with 'previewwindow' set. */
8784 else if ((int *)varp == &curwin->w_p_pvw)
8785 {
8786 if (curwin->w_p_pvw)
8787 {
8788 win_T *win;
8789
Bram Moolenaar29323592016-07-24 22:04:11 +02008790 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008791 if (win->w_p_pvw && win != curwin)
8792 {
8793 curwin->w_p_pvw = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008794 return N_("E590: A preview window already exists");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008795 }
8796 }
8797 }
8798#endif
8799
8800 /* when 'textmode' is set or reset also change 'fileformat' */
8801 else if ((int *)varp == &curbuf->b_p_tx)
8802 {
8803 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8804 }
8805
8806 /* when 'textauto' is set or reset also change 'fileformats' */
8807 else if ((int *)varp == &p_ta)
Bram Moolenaarabab0b02019-03-30 18:47:01 +01008808 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008809 set_string_option_direct((char_u *)"ffs", -1,
8810 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008811 OPT_FREE | opt_flags, 0);
Bram Moolenaarabab0b02019-03-30 18:47:01 +01008812 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008813
8814 /*
8815 * When 'lisp' option changes include/exclude '-' in
8816 * keyword characters.
8817 */
8818#ifdef FEAT_LISP
8819 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8820 {
8821 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8822 }
8823#endif
8824
8825#ifdef FEAT_TITLE
8826 /* when 'title' changed, may need to change the title; same for 'icon' */
Bram Moolenaar84a93082018-06-16 22:58:15 +02008827 else if ((int *)varp == &p_title || (int *)varp == &p_icon)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008828 {
Bram Moolenaar84a93082018-06-16 22:58:15 +02008829 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008830 }
8831#endif
8832
8833 else if ((int *)varp == &curbuf->b_changed)
8834 {
8835 if (!value)
8836 save_file_ff(curbuf); /* Buffer is unchanged */
8837#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008838 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008839#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008840 modified_was_set = value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008841 }
8842
8843#ifdef BACKSLASH_IN_FILENAME
8844 else if ((int *)varp == &p_ssl)
8845 {
8846 if (p_ssl)
8847 {
8848 psepc = '/';
8849 psepcN = '\\';
8850 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008851 }
8852 else
8853 {
8854 psepc = '\\';
8855 psepcN = '/';
8856 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008857 }
8858
8859 /* need to adjust the file name arguments and buffer names. */
8860 buflist_slash_adjust();
8861 alist_slash_adjust();
8862# ifdef FEAT_EVAL
8863 scriptnames_slash_adjust();
8864# endif
8865 }
8866#endif
8867
8868 /* If 'wrap' is set, set w_leftcol to zero. */
8869 else if ((int *)varp == &curwin->w_p_wrap)
8870 {
8871 if (curwin->w_p_wrap)
8872 curwin->w_leftcol = 0;
8873 }
8874
Bram Moolenaar071d4272004-06-13 20:20:40 +00008875 else if ((int *)varp == &p_ea)
8876 {
8877 if (p_ea && !old_value)
8878 win_equal(curwin, FALSE, 0);
8879 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008880
8881 else if ((int *)varp == &p_wiv)
8882 {
8883 /*
8884 * When 'weirdinvert' changed, set/reset 't_xs'.
8885 * Then set 'weirdinvert' according to value of 't_xs'.
8886 */
8887 if (p_wiv && !old_value)
8888 T_XS = (char_u *)"y";
8889 else if (!p_wiv && old_value)
8890 T_XS = empty_option;
8891 p_wiv = (*T_XS != NUL);
8892 }
8893
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008894#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008895 else if ((int *)varp == &p_beval)
8896 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008897 if (!balloonEvalForTerm)
8898 {
8899 if (p_beval && !old_value)
8900 gui_mch_enable_beval_area(balloonEval);
8901 else if (!p_beval && old_value)
8902 gui_mch_disable_beval_area(balloonEval);
8903 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008904 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008905#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008906#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008907 else if ((int *)varp == &p_bevalterm)
8908 {
8909 mch_bevalterm_changed();
8910 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008911#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008912
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008913#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008914 else if ((int *)varp == &p_acd)
8915 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008916 /* Change directories when the 'acd' option is set now. */
Bram Moolenaar6f470022018-04-10 18:47:20 +02008917 DO_AUTOCHDIR;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008918 }
8919#endif
8920
8921#ifdef FEAT_DIFF
8922 /* 'diff' */
8923 else if ((int *)varp == &curwin->w_p_diff)
8924 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008925 /* May add or remove the buffer from the list of diff buffers. */
8926 diff_buf_adjust(curwin);
8927# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008928 if (foldmethodIsDiff(curwin))
8929 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008930# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008931 }
8932#endif
8933
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008934#ifdef HAVE_INPUT_METHOD
Bram Moolenaar071d4272004-06-13 20:20:40 +00008935 /* 'imdisable' */
8936 else if ((int *)varp == &p_imdisable)
8937 {
8938 /* Only de-activate it here, it will be enabled when changing mode. */
8939 if (p_imdisable)
8940 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008941 else if (State & INSERT)
8942 /* When the option is set from an autocommand, it may need to take
8943 * effect right away. */
8944 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008945 }
8946#endif
8947
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008948#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008949 /* 'spell' */
8950 else if ((int *)varp == &curwin->w_p_spell)
8951 {
8952 if (curwin->w_p_spell)
8953 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008954 char *errmsg = did_set_spelllang(curwin);
8955
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008956 if (errmsg != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008957 emsg(_(errmsg));
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008958 }
8959 }
8960#endif
8961
Bram Moolenaar071d4272004-06-13 20:20:40 +00008962#ifdef FEAT_ARABIC
8963 if ((int *)varp == &curwin->w_p_arab)
8964 {
8965 if (curwin->w_p_arab)
8966 {
8967 /*
8968 * 'arabic' is set, handle various sub-settings.
8969 */
8970 if (!p_tbidi)
8971 {
8972 /* set rightleft mode */
8973 if (!curwin->w_p_rl)
8974 {
8975 curwin->w_p_rl = TRUE;
8976 changed_window_setting();
8977 }
8978
8979 /* Enable Arabic shaping (major part of what Arabic requires) */
8980 if (!p_arshape)
8981 {
8982 p_arshape = TRUE;
8983 redraw_later_clear();
8984 }
8985 }
8986
8987 /* Arabic requires a utf-8 encoding, inform the user if its not
8988 * set. */
8989 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008990 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008991 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8992
Bram Moolenaar8820b482017-03-16 17:23:31 +01008993 msg_source(HL_ATTR(HLF_W));
Bram Moolenaar32526b32019-01-19 17:43:09 +01008994 msg_attr(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008995#ifdef FEAT_EVAL
8996 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8997#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008998 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008999
Bram Moolenaar071d4272004-06-13 20:20:40 +00009000 /* set 'delcombine' */
9001 p_deco = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009002
9003# ifdef FEAT_KEYMAP
9004 /* Force-set the necessary keymap for arabic */
9005 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
9006 OPT_LOCAL);
9007# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009008 }
9009 else
9010 {
9011 /*
9012 * 'arabic' is reset, handle various sub-settings.
9013 */
9014 if (!p_tbidi)
9015 {
9016 /* reset rightleft mode */
9017 if (curwin->w_p_rl)
9018 {
9019 curwin->w_p_rl = FALSE;
9020 changed_window_setting();
9021 }
9022
9023 /* 'arabicshape' isn't reset, it is a global option and
9024 * another window may still need it "on". */
9025 }
9026
9027 /* 'delcombine' isn't reset, it is a global option and another
9028 * window may still want it "on". */
9029
9030# ifdef FEAT_KEYMAP
9031 /* Revert to the default keymap */
9032 curbuf->b_p_iminsert = B_IMODE_NONE;
9033 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
9034# endif
9035 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00009036 }
9037
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00009038#endif
9039
Bram Moolenaar61be73b2016-04-29 22:59:22 +02009040#ifdef FEAT_TERMGUICOLORS
9041 /* 'termguicolors' */
9042 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02009043 {
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009044# ifdef FEAT_VTP
9045 /* Do not turn on 'tgc' when 24-bit colors are not supported. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02009046 if (
9047# ifdef VIMDLL
9048 !gui.in_use && !gui.starting &&
9049# endif
9050 !has_vtp_working())
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009051 {
9052 p_tgc = 0;
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01009053 return N_("E954: 24-bit colors are not supported on this environment");
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009054 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02009055 if (is_term_win32())
9056 swap_tcap();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009057# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02009058# ifdef FEAT_GUI
9059 if (!gui.in_use && !gui.starting)
9060# endif
9061 highlight_gui_started();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009062# ifdef FEAT_VTP
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009063 /* reset t_Co */
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02009064 if (is_term_win32())
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02009065 {
9066 control_console_color_rgb();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009067 set_termname(T_NAME);
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02009068 init_highlight(TRUE, FALSE);
9069 }
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009070# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02009071 }
9072#endif
9073
Bram Moolenaar071d4272004-06-13 20:20:40 +00009074 /*
9075 * End of handling side effects for bool options.
9076 */
9077
Bram Moolenaar53744302015-07-17 17:38:22 +02009078 /* after handling side effects, call autocommand */
9079
Bram Moolenaar071d4272004-06-13 20:20:40 +00009080 options[opt_idx].flags |= P_WAS_SET;
9081
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009082#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009083 // Don't do this while starting up or recursively.
9084 if (!starting && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009085 {
Bram Moolenaard7c96872019-06-15 17:12:48 +02009086 char_u buf_old[2], buf_old_global[2], buf_new[2], buf_type[7];
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009087
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009088 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009089 vim_snprintf((char *)buf_old_global, 2, "%d",
9090 old_global_value ? TRUE: FALSE);
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009091 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009092 vim_snprintf((char *)buf_type, 7, "%s",
9093 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009094 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9095 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9096 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009097 if (opt_flags & OPT_LOCAL)
9098 {
9099 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
9100 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9101 }
9102 if (opt_flags & OPT_GLOBAL)
9103 {
9104 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
9105 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old, -1);
9106 }
9107 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9108 {
9109 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
9110 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9111 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old_global, -1);
9112 }
9113 if (opt_flags & OPT_MODELINE)
9114 {
9115 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
9116 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9117 }
9118 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname,
9119 NULL, FALSE, NULL);
Bram Moolenaar53744302015-07-17 17:38:22 +02009120 reset_v_option_vars();
9121 }
9122#endif
9123
Bram Moolenaar071d4272004-06-13 20:20:40 +00009124 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009125 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009126 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009127 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009128 check_redraw(options[opt_idx].flags);
9129
9130 return NULL;
9131}
9132
9133/*
9134 * Set the value of a number option, and take care of side effects.
9135 * Returns NULL for success, or an error message for an error.
9136 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009137 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009138set_num_option(
9139 int opt_idx, /* index in options[] table */
9140 char_u *varp, /* pointer to the option variable */
9141 long value, /* new value */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009142 char *errbuf, /* buffer for error messages */
Bram Moolenaar9b578142016-01-30 19:39:49 +01009143 size_t errbuflen, /* length of "errbuf" */
9144 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00009145 OPT_MODELINE */
9146{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009147 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009148 long old_value = *(long *)varp;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02009149#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02009150 long old_global_value = 0; // only used when setting a local and
9151 // global option
Bram Moolenaar983f2f12019-06-16 16:41:41 +02009152#endif
Bram Moolenaard7c96872019-06-15 17:12:48 +02009153 long old_Rows = Rows; // remember old Rows
9154 long old_Columns = Columns; // remember old Columns
Bram Moolenaar071d4272004-06-13 20:20:40 +00009155 long *pp = (long *)varp;
9156
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009157 /* Disallow changing some options from secure mode. */
9158 if ((secure
9159#ifdef HAVE_SANDBOX
9160 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00009161#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009162 ) && (options[opt_idx].flags & P_SECURE))
9163 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009164
Bram Moolenaar983f2f12019-06-16 16:41:41 +02009165#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02009166 // Save the global value before changing anything. This is needed as for
9167 // a global-only option setting the "local value" infact sets the global
9168 // value (since there is only one value).
9169 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
Bram Moolenaar983f2f12019-06-16 16:41:41 +02009170 old_global_value = *(long *)get_varp_scope(&(options[opt_idx]),
9171 OPT_GLOBAL);
9172#endif
Bram Moolenaard7c96872019-06-15 17:12:48 +02009173
Bram Moolenaar071d4272004-06-13 20:20:40 +00009174 *pp = value;
9175#ifdef FEAT_EVAL
9176 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02009177 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009178#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009179#ifdef FEAT_GUI
9180 need_mouse_correct = TRUE;
9181#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009182
Bram Moolenaar14f24742012-08-08 18:01:05 +02009183 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009184 {
9185 errmsg = e_positive;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02009186#ifdef FEAT_VARTABS
9187 // Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use.
9188 curbuf->b_p_sw = tabstop_count(curbuf->b_p_vts_array) > 0
9189 ? tabstop_first(curbuf->b_p_vts_array)
9190 : curbuf->b_p_ts;
9191#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00009192 curbuf->b_p_sw = curbuf->b_p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02009193#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009194 }
9195
9196 /*
9197 * Number options that need some action when changed
9198 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009199 if (pp == &p_wh || pp == &p_hh)
9200 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009201 // 'winheight' and 'helpheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009202 if (p_wh < 1)
9203 {
9204 errmsg = e_positive;
9205 p_wh = 1;
9206 }
9207 if (p_wmh > p_wh)
9208 {
9209 errmsg = e_winheight;
9210 p_wh = p_wmh;
9211 }
9212 if (p_hh < 0)
9213 {
9214 errmsg = e_positive;
9215 p_hh = 0;
9216 }
9217
9218 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01009219 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009220 {
9221 if (pp == &p_wh && curwin->w_height < p_wh)
9222 win_setheight((int)p_wh);
9223 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
9224 win_setheight((int)p_hh);
9225 }
9226 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009227 else if (pp == &p_wmh)
9228 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009229 // 'winminheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009230 if (p_wmh < 0)
9231 {
9232 errmsg = e_positive;
9233 p_wmh = 0;
9234 }
9235 if (p_wmh > p_wh)
9236 {
9237 errmsg = e_winheight;
9238 p_wmh = p_wh;
9239 }
9240 win_setminheight();
9241 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009242 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009243 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009244 // 'winwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009245 if (p_wiw < 1)
9246 {
9247 errmsg = e_positive;
9248 p_wiw = 1;
9249 }
9250 if (p_wmw > p_wiw)
9251 {
9252 errmsg = e_winwidth;
9253 p_wiw = p_wmw;
9254 }
9255
9256 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01009257 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009258 win_setwidth((int)p_wiw);
9259 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009260 else if (pp == &p_wmw)
9261 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009262 // 'winminwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009263 if (p_wmw < 0)
9264 {
9265 errmsg = e_positive;
9266 p_wmw = 0;
9267 }
9268 if (p_wmw > p_wiw)
9269 {
9270 errmsg = e_winwidth;
9271 p_wmw = p_wiw;
9272 }
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009273 win_setminwidth();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009274 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009275
Bram Moolenaar071d4272004-06-13 20:20:40 +00009276 /* (re)set last window status line */
9277 else if (pp == &p_ls)
9278 {
9279 last_status(FALSE);
9280 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009281
9282 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00009283 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009284 {
9285 shell_new_rows(); /* recompute window positions and heights */
9286 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009287
9288#ifdef FEAT_GUI
9289 else if (pp == &p_linespace)
9290 {
Bram Moolenaar02743632005-07-25 20:42:36 +00009291 /* Recompute gui.char_height and resize the Vim window to keep the
9292 * same number of lines. */
9293 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00009294 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009295 }
9296#endif
9297
9298#ifdef FEAT_FOLDING
9299 /* 'foldlevel' */
9300 else if (pp == &curwin->w_p_fdl)
9301 {
9302 if (curwin->w_p_fdl < 0)
9303 curwin->w_p_fdl = 0;
9304 newFoldLevel();
9305 }
9306
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00009307 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009308 else if (pp == &curwin->w_p_fml)
9309 {
9310 foldUpdateAll(curwin);
9311 }
9312
9313 /* 'foldnestmax' */
9314 else if (pp == &curwin->w_p_fdn)
9315 {
9316 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
9317 foldUpdateAll(curwin);
9318 }
9319
9320 /* 'foldcolumn' */
9321 else if (pp == &curwin->w_p_fdc)
9322 {
9323 if (curwin->w_p_fdc < 0)
9324 {
9325 errmsg = e_positive;
9326 curwin->w_p_fdc = 0;
9327 }
9328 else if (curwin->w_p_fdc > 12)
9329 {
9330 errmsg = e_invarg;
9331 curwin->w_p_fdc = 12;
9332 }
9333 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009334#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009335
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009336#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009337 /* 'shiftwidth' or 'tabstop' */
9338 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
9339 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009340# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00009341 if (foldmethodIsIndent(curwin))
9342 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009343# endif
9344# ifdef FEAT_CINDENT
9345 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
9346 * parse 'cinoptions'. */
9347 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
9348 parse_cino(curbuf);
9349# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009350 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009351#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009352
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009353 /* 'maxcombine' */
9354 else if (pp == &p_mco)
9355 {
9356 if (p_mco > MAX_MCO)
9357 p_mco = MAX_MCO;
9358 else if (p_mco < 0)
9359 p_mco = 0;
9360 screenclear(); /* will re-allocate the screen */
9361 }
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009362
Bram Moolenaar071d4272004-06-13 20:20:40 +00009363 else if (pp == &curbuf->b_p_iminsert)
9364 {
9365 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
9366 {
9367 errmsg = e_invarg;
9368 curbuf->b_p_iminsert = B_IMODE_NONE;
9369 }
9370 p_iminsert = curbuf->b_p_iminsert;
9371 if (termcap_active) /* don't do this in the alternate screen */
9372 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02009373#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009374 /* Show/unshow value of 'keymap' in status lines. */
9375 status_redraw_curbuf();
9376#endif
9377 }
9378
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02009379#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
9380 /* 'imstyle' */
9381 else if (pp == &p_imst)
9382 {
9383 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
9384 errmsg = e_invarg;
9385 }
9386#endif
9387
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009388 else if (pp == &p_window)
9389 {
9390 if (p_window < 1)
9391 p_window = 1;
9392 else if (p_window >= Rows)
9393 p_window = Rows - 1;
9394 }
9395
Bram Moolenaar071d4272004-06-13 20:20:40 +00009396 else if (pp == &curbuf->b_p_imsearch)
9397 {
9398 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
9399 {
9400 errmsg = e_invarg;
9401 curbuf->b_p_imsearch = B_IMODE_NONE;
9402 }
9403 p_imsearch = curbuf->b_p_imsearch;
9404 }
9405
9406#ifdef FEAT_TITLE
9407 /* if 'titlelen' has changed, redraw the title */
9408 else if (pp == &p_titlelen)
9409 {
9410 if (p_titlelen < 0)
9411 {
9412 errmsg = e_positive;
9413 p_titlelen = 85;
9414 }
9415 if (starting != NO_SCREEN && old_value != p_titlelen)
9416 need_maketitle = TRUE;
9417 }
9418#endif
9419
9420 /* if p_ch changed value, change the command line height */
9421 else if (pp == &p_ch)
9422 {
9423 if (p_ch < 1)
9424 {
9425 errmsg = e_positive;
9426 p_ch = 1;
9427 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009428 if (p_ch > Rows - min_rows() + 1)
9429 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009430
9431 /* Only compute the new window layout when startup has been
9432 * completed. Otherwise the frame sizes may be wrong. */
9433 if (p_ch != old_value && full_screen
9434#ifdef FEAT_GUI
9435 && !gui.starting
9436#endif
9437 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009438 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009439 }
9440
9441 /* when 'updatecount' changes from zero to non-zero, open swap files */
9442 else if (pp == &p_uc)
9443 {
9444 if (p_uc < 0)
9445 {
9446 errmsg = e_positive;
9447 p_uc = 100;
9448 }
9449 if (p_uc && !old_value)
9450 ml_open_files();
9451 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009452#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009453 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009454 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009455 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009456 {
9457 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009458 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009459 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009460 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009461 {
9462 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009463 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009464 }
9465 }
9466#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009467#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009468 else if (pp == &p_mzq)
9469 mzvim_reset_timer();
9470#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009471
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009472#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9473 /* 'pyxversion' */
9474 else if (pp == &p_pyx)
9475 {
9476 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9477 errmsg = e_invarg;
9478 }
9479#endif
9480
Bram Moolenaar071d4272004-06-13 20:20:40 +00009481 /* sync undo before 'undolevels' changes */
9482 else if (pp == &p_ul)
9483 {
9484 /* use the old value, otherwise u_sync() may not work properly */
9485 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009486 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009487 p_ul = value;
9488 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009489 else if (pp == &curbuf->b_p_ul)
9490 {
9491 /* use the old value, otherwise u_sync() may not work properly */
9492 curbuf->b_p_ul = old_value;
9493 u_sync(TRUE);
9494 curbuf->b_p_ul = value;
9495 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009496
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009497#ifdef FEAT_LINEBREAK
9498 /* 'numberwidth' must be positive */
9499 else if (pp == &curwin->w_p_nuw)
9500 {
9501 if (curwin->w_p_nuw < 1)
9502 {
9503 errmsg = e_positive;
9504 curwin->w_p_nuw = 1;
9505 }
Bram Moolenaarf8a07122019-07-01 22:06:07 +02009506 if (curwin->w_p_nuw > 20)
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009507 {
9508 errmsg = e_invarg;
Bram Moolenaarf8a07122019-07-01 22:06:07 +02009509 curwin->w_p_nuw = 20;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009510 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009511 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009512 }
9513#endif
9514
Bram Moolenaar1a384422010-07-14 19:53:30 +02009515 else if (pp == &curbuf->b_p_tw)
9516 {
9517 if (curbuf->b_p_tw < 0)
9518 {
9519 errmsg = e_positive;
9520 curbuf->b_p_tw = 0;
9521 }
9522#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009523 {
9524 win_T *wp;
9525 tabpage_T *tp;
9526
9527 FOR_ALL_TAB_WINDOWS(tp, wp)
9528 check_colorcolumn(wp);
9529 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009530#endif
9531 }
9532
Bram Moolenaar071d4272004-06-13 20:20:40 +00009533 /*
9534 * Check the bounds for numeric options here
9535 */
9536 if (Rows < min_rows() && full_screen)
9537 {
9538 if (errbuf != NULL)
9539 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009540 vim_snprintf((char *)errbuf, errbuflen,
9541 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009542 errmsg = errbuf;
9543 }
9544 Rows = min_rows();
9545 }
9546 if (Columns < MIN_COLUMNS && full_screen)
9547 {
9548 if (errbuf != NULL)
9549 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009550 vim_snprintf((char *)errbuf, errbuflen,
9551 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009552 errmsg = errbuf;
9553 }
9554 Columns = MIN_COLUMNS;
9555 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009556 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009557
Bram Moolenaar071d4272004-06-13 20:20:40 +00009558 /*
9559 * If the screen (shell) height has been changed, assume it is the
9560 * physical screenheight.
9561 */
9562 if (old_Rows != Rows || old_Columns != Columns)
9563 {
9564 /* Changing the screen size is not allowed while updating the screen. */
9565 if (updating_screen)
9566 *pp = old_value;
9567 else if (full_screen
9568#ifdef FEAT_GUI
9569 && !gui.starting
9570#endif
9571 )
9572 set_shellsize((int)Columns, (int)Rows, TRUE);
9573 else
9574 {
9575 /* Postpone the resizing; check the size and cmdline position for
9576 * messages. */
9577 check_shellsize();
9578 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9579 cmdline_row = Rows - p_ch;
9580 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009581 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009582 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009583 }
9584
Bram Moolenaar071d4272004-06-13 20:20:40 +00009585 if (curbuf->b_p_ts <= 0)
9586 {
9587 errmsg = e_positive;
9588 curbuf->b_p_ts = 8;
9589 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009590 if (p_tm < 0)
9591 {
9592 errmsg = e_positive;
9593 p_tm = 0;
9594 }
9595 if ((curwin->w_p_scr <= 0
9596 || (curwin->w_p_scr > curwin->w_height
9597 && curwin->w_height > 0))
9598 && full_screen)
9599 {
9600 if (pp == &(curwin->w_p_scr))
9601 {
9602 if (curwin->w_p_scr != 0)
9603 errmsg = e_scroll;
9604 win_comp_scroll(curwin);
9605 }
9606 /* If 'scroll' became invalid because of a side effect silently adjust
9607 * it. */
9608 else if (curwin->w_p_scr <= 0)
9609 curwin->w_p_scr = 1;
9610 else /* curwin->w_p_scr > curwin->w_height */
9611 curwin->w_p_scr = curwin->w_height;
9612 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009613 if (p_hi < 0)
9614 {
9615 errmsg = e_positive;
9616 p_hi = 0;
9617 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009618 else if (p_hi > 10000)
9619 {
9620 errmsg = e_invarg;
9621 p_hi = 10000;
9622 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009623 if (p_re < 0 || p_re > 2)
9624 {
9625 errmsg = e_invarg;
9626 p_re = 0;
9627 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009628 if (p_report < 0)
9629 {
9630 errmsg = e_positive;
9631 p_report = 1;
9632 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009633 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009634 {
9635 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9636 p_sj = Rows / 2;
9637 else
9638 {
9639 errmsg = e_scroll;
9640 p_sj = 1;
9641 }
9642 }
9643 if (p_so < 0 && full_screen)
9644 {
Bram Moolenaar375e3392019-01-31 18:26:10 +01009645 errmsg = e_positive;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009646 p_so = 0;
9647 }
9648 if (p_siso < 0 && full_screen)
9649 {
9650 errmsg = e_positive;
9651 p_siso = 0;
9652 }
9653#ifdef FEAT_CMDWIN
9654 if (p_cwh < 1)
9655 {
9656 errmsg = e_positive;
9657 p_cwh = 1;
9658 }
9659#endif
9660 if (p_ut < 0)
9661 {
9662 errmsg = e_positive;
9663 p_ut = 2000;
9664 }
9665 if (p_ss < 0)
9666 {
9667 errmsg = e_positive;
9668 p_ss = 0;
9669 }
9670
9671 /* May set global value for local option. */
9672 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9673 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9674
9675 options[opt_idx].flags |= P_WAS_SET;
9676
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009677#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009678 // Don't do this while starting up, failure or recursively.
9679 if (!starting && errmsg == NULL && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009680 {
Bram Moolenaard7c96872019-06-15 17:12:48 +02009681 char_u buf_old[11], buf_old_global[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009682 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009683 vim_snprintf((char *)buf_old_global, 10, "%ld", old_global_value);
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009684 vim_snprintf((char *)buf_new, 10, "%ld", value);
9685 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009686 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9687 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9688 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009689 if (opt_flags & OPT_LOCAL)
9690 {
9691 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
9692 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9693 }
9694 if (opt_flags & OPT_GLOBAL)
9695 {
9696 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
9697 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old, -1);
9698 }
9699 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9700 {
9701 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
9702 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9703 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old_global, -1);
9704 }
9705 if (opt_flags & OPT_MODELINE)
9706 {
9707 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
9708 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9709 }
9710 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname,
9711 NULL, FALSE, NULL);
Bram Moolenaar53744302015-07-17 17:38:22 +02009712 reset_v_option_vars();
9713 }
9714#endif
9715
Bram Moolenaar071d4272004-06-13 20:20:40 +00009716 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009717 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009718 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009719 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009720 check_redraw(options[opt_idx].flags);
9721
9722 return errmsg;
9723}
9724
9725/*
9726 * Called after an option changed: check if something needs to be redrawn.
9727 */
9728 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009729check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009730{
9731 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009732 int doclear = (flags & P_RCLR) == P_RCLR;
9733 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009734
Bram Moolenaar071d4272004-06-13 20:20:40 +00009735 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9736 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009737
9738 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9739 changed_window_setting();
9740 if (flags & P_RBUF)
9741 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009742 if (flags & P_RWINONLY)
9743 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009744 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009745 redraw_all_later(CLEAR);
9746 else if (all)
9747 redraw_all_later(NOT_VALID);
9748}
9749
9750/*
9751 * Find index for option 'arg'.
9752 * Return -1 if not found.
9753 */
9754 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009755findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009756{
9757 int opt_idx;
9758 char *s, *p;
9759 static short quick_tab[27] = {0, 0}; /* quick access table */
9760 int is_term_opt;
9761
9762 /*
9763 * For first call: Initialize the quick-access table.
9764 * It contains the index for the first option that starts with a certain
9765 * letter. There are 26 letters, plus the first "t_" option.
9766 */
9767 if (quick_tab[1] == 0)
9768 {
9769 p = options[0].fullname;
9770 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9771 {
9772 if (s[0] != p[0])
9773 {
9774 if (s[0] == 't' && s[1] == '_')
9775 quick_tab[26] = opt_idx;
9776 else
9777 quick_tab[CharOrdLow(s[0])] = opt_idx;
9778 }
9779 p = s;
9780 }
9781 }
9782
9783 /*
9784 * Check for name starting with an illegal character.
9785 */
9786#ifdef EBCDIC
9787 if (!islower(arg[0]))
9788#else
9789 if (arg[0] < 'a' || arg[0] > 'z')
9790#endif
9791 return -1;
9792
9793 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9794 if (is_term_opt)
9795 opt_idx = quick_tab[26];
9796 else
9797 opt_idx = quick_tab[CharOrdLow(arg[0])];
9798 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9799 {
9800 if (STRCMP(arg, s) == 0) /* match full name */
9801 break;
9802 }
9803 if (s == NULL && !is_term_opt)
9804 {
9805 opt_idx = quick_tab[CharOrdLow(arg[0])];
9806 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9807 {
9808 s = options[opt_idx].shortname;
9809 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9810 break;
9811 s = NULL;
9812 }
9813 }
9814 if (s == NULL)
9815 opt_idx = -1;
9816 return opt_idx;
9817}
9818
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009819#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009820/*
9821 * Get the value for an option.
9822 *
9823 * Returns:
9824 * Number or Toggle option: 1, *numval gets value.
9825 * String option: 0, *stringval gets allocated string.
9826 * Hidden Number or Toggle option: -1.
9827 * hidden String option: -2.
9828 * unknown option: -3.
9829 */
9830 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009831get_option_value(
9832 char_u *name,
9833 long *numval,
9834 char_u **stringval, /* NULL when only checking existence */
9835 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009836{
9837 int opt_idx;
9838 char_u *varp;
9839
9840 opt_idx = findoption(name);
9841 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009842 {
9843 int key;
9844
9845 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009846 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009847 {
9848 char_u key_name[2];
9849 char_u *p;
9850
9851 if (key < 0)
9852 {
9853 key_name[0] = KEY2TERMCAP0(key);
9854 key_name[1] = KEY2TERMCAP1(key);
9855 }
9856 else
9857 {
9858 key_name[0] = KS_KEY;
9859 key_name[1] = (key & 0xff);
9860 }
9861 p = find_termcode(key_name);
9862 if (p != NULL)
9863 {
9864 if (stringval != NULL)
9865 *stringval = vim_strsave(p);
9866 return 0;
9867 }
9868 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009869 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009870 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009871
9872 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9873
9874 if (options[opt_idx].flags & P_STRING)
9875 {
9876 if (varp == NULL) /* hidden option */
9877 return -2;
9878 if (stringval != NULL)
9879 {
9880#ifdef FEAT_CRYPT
9881 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009882 if ((char_u **)varp == &curbuf->b_p_key
9883 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009884 *stringval = vim_strsave((char_u *)"*****");
9885 else
9886#endif
9887 *stringval = vim_strsave(*(char_u **)(varp));
9888 }
9889 return 0;
9890 }
9891
9892 if (varp == NULL) /* hidden option */
9893 return -1;
9894 if (options[opt_idx].flags & P_NUM)
9895 *numval = *(long *)varp;
9896 else
9897 {
9898 /* Special case: 'modified' is b_changed, but we also want to consider
9899 * it set when 'ff' or 'fenc' changed. */
9900 if ((int *)varp == &curbuf->b_changed)
9901 *numval = curbufIsChanged();
9902 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009903 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009904 }
9905 return 1;
9906}
9907#endif
9908
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009909#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009910/*
9911 * Returns the option attributes and its value. Unlike the above function it
9912 * will return either global value or local value of the option depending on
9913 * what was requested, but it will never return global value if it was
9914 * requested to return local one and vice versa. Neither it will return
9915 * buffer-local value if it was requested to return window-local one.
9916 *
9917 * Pretends that option is absent if it is not present in the requested scope
9918 * (i.e. has no global, window-local or buffer-local value depending on
9919 * opt_type). Uses
9920 *
9921 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009922 * 0 hidden or unknown option, also option that does not have requested
9923 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009924 * see SOPT_* in vim.h for other flags
9925 *
9926 * Possible opt_type values: see SREQ_* in vim.h
9927 */
9928 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009929get_option_value_strict(
9930 char_u *name,
9931 long *numval,
9932 char_u **stringval, /* NULL when only obtaining attributes */
9933 int opt_type,
9934 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009935{
9936 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009937 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009938 struct vimoption *p;
9939 int r = 0;
9940
9941 opt_idx = findoption(name);
9942 if (opt_idx < 0)
9943 return 0;
9944
9945 p = &(options[opt_idx]);
9946
9947 /* Hidden option */
9948 if (p->var == NULL)
9949 return 0;
9950
9951 if (p->flags & P_BOOL)
9952 r |= SOPT_BOOL;
9953 else if (p->flags & P_NUM)
9954 r |= SOPT_NUM;
9955 else if (p->flags & P_STRING)
9956 r |= SOPT_STRING;
9957
9958 if (p->indir == PV_NONE)
9959 {
9960 if (opt_type == SREQ_GLOBAL)
9961 r |= SOPT_GLOBAL;
9962 else
9963 return 0; /* Did not request global-only option */
9964 }
9965 else
9966 {
9967 if (p->indir & PV_BOTH)
9968 r |= SOPT_GLOBAL;
9969 else if (opt_type == SREQ_GLOBAL)
9970 return 0; /* Requested global option */
9971
9972 if (p->indir & PV_WIN)
9973 {
9974 if (opt_type == SREQ_BUF)
9975 return 0; /* Did not request window-local option */
9976 else
9977 r |= SOPT_WIN;
9978 }
9979 else if (p->indir & PV_BUF)
9980 {
9981 if (opt_type == SREQ_WIN)
9982 return 0; /* Did not request buffer-local option */
9983 else
9984 r |= SOPT_BUF;
9985 }
9986 }
9987
9988 if (stringval == NULL)
9989 return r;
9990
9991 if (opt_type == SREQ_GLOBAL)
9992 varp = p->var;
9993 else
9994 {
9995 if (opt_type == SREQ_BUF)
9996 {
9997 /* Special case: 'modified' is b_changed, but we also want to
9998 * consider it set when 'ff' or 'fenc' changed. */
9999 if (p->indir == PV_MOD)
10000 {
Bram Moolenaardefe6422018-06-24 15:14:07 +020010001 *numval = bufIsChanged((buf_T *)from);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010002 varp = NULL;
10003 }
10004#ifdef FEAT_CRYPT
10005 else if (p->indir == PV_KEY)
10006 {
10007 /* never return the value of the crypt key */
10008 *stringval = NULL;
10009 varp = NULL;
10010 }
10011#endif
10012 else
10013 {
Bram Moolenaardefe6422018-06-24 15:14:07 +020010014 buf_T *save_curbuf = curbuf;
10015
10016 // only getting a pointer, no need to use aucmd_prepbuf()
10017 curbuf = (buf_T *)from;
10018 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010019 varp = get_varp(p);
Bram Moolenaardefe6422018-06-24 15:14:07 +020010020 curbuf = save_curbuf;
10021 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010022 }
10023 }
10024 else if (opt_type == SREQ_WIN)
10025 {
Bram Moolenaardefe6422018-06-24 15:14:07 +020010026 win_T *save_curwin = curwin;
10027
10028 curwin = (win_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010029 curbuf = curwin->w_buffer;
10030 varp = get_varp(p);
10031 curwin = save_curwin;
10032 curbuf = curwin->w_buffer;
10033 }
10034 if (varp == p->var)
10035 return (r | SOPT_UNSET);
10036 }
10037
10038 if (varp != NULL)
10039 {
10040 if (p->flags & P_STRING)
10041 *stringval = vim_strsave(*(char_u **)(varp));
10042 else if (p->flags & P_NUM)
10043 *numval = *(long *) varp;
10044 else
10045 *numval = *(int *)varp;
10046 }
10047
10048 return r;
10049}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010050
10051/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010052 * Iterate over options. First argument is a pointer to a pointer to a
10053 * structure inside options[] array, second is option type like in the above
10054 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010055 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010056 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010057 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010058 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010059 * first argument to NULL.
10060 *
10061 * Returns full option name for current option on each call.
10062 */
10063 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010064option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010065{
10066 struct vimoption *ret = NULL;
10067 do
10068 {
10069 if (*option == NULL)
10070 *option = (void *) options;
10071 else if (((struct vimoption *) (*option))->fullname == NULL)
10072 {
10073 *option = NULL;
10074 return NULL;
10075 }
10076 else
10077 *option = (void *) (((struct vimoption *) (*option)) + 1);
10078
10079 ret = ((struct vimoption *) (*option));
10080
10081 /* Hidden option */
10082 if (ret->var == NULL)
10083 {
10084 ret = NULL;
10085 continue;
10086 }
10087
10088 switch (opt_type)
10089 {
10090 case SREQ_GLOBAL:
10091 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
10092 ret = NULL;
10093 break;
10094 case SREQ_BUF:
10095 if (!(ret->indir & PV_BUF))
10096 ret = NULL;
10097 break;
10098 case SREQ_WIN:
10099 if (!(ret->indir & PV_WIN))
10100 ret = NULL;
10101 break;
10102 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +010010103 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010104 return NULL;
10105 }
10106 }
10107 while (ret == NULL);
10108
10109 return (char_u *)ret->fullname;
10110}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010111#endif
10112
Bram Moolenaar071d4272004-06-13 20:20:40 +000010113/*
10114 * Set the value of option "name".
10115 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010116 *
10117 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010118 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010119 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010120set_option_value(
10121 char_u *name,
10122 long number,
10123 char_u *string,
10124 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010125{
10126 int opt_idx;
10127 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +000010128 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010129
10130 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010131 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +010010132 {
10133 int key;
10134
10135 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010136 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +010010137 {
10138 char_u key_name[2];
10139
10140 if (key < 0)
10141 {
10142 key_name[0] = KEY2TERMCAP0(key);
10143 key_name[1] = KEY2TERMCAP1(key);
10144 }
10145 else
10146 {
10147 key_name[0] = KS_KEY;
10148 key_name[1] = (key & 0xff);
10149 }
10150 add_termcode(key_name, string, FALSE);
10151 if (full_screen)
10152 ttest(FALSE);
10153 redraw_all_later(CLEAR);
10154 return NULL;
10155 }
10156
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010157 semsg(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +010010158 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010159 else
10160 {
10161 flags = options[opt_idx].flags;
10162#ifdef HAVE_SANDBOX
10163 /* Disallow changing some options in the sandbox */
10164 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010165 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010166 emsg(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010167 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010168 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010169#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010170 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010171 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010172 else
10173 {
Bram Moolenaarb3163762008-07-08 15:15:08 +000010174 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010175 if (varp != NULL) /* hidden option is not changed */
10176 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010177 if (number == 0 && string != NULL)
10178 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +000010179 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010180
10181 /* Either we are given a string or we are setting option
10182 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +000010183 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010184 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +000010185 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010186 {
10187 /* There's another character after zeros or the string
10188 * is empty. In both cases, we are trying to set a
10189 * num option using a string. */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010190 semsg(_("E521: Number required: &%s = '%s'"),
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010191 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010192 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010193
10194 }
10195 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010196 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010197 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +000010198 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010199 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010200 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010201 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010202 }
10203 }
10204 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010205 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010206}
10207
10208/*
10209 * Get the terminal code for a terminal option.
10210 * Returns NULL when not found.
10211 */
10212 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010213get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010214{
10215 int opt_idx;
10216 char_u *varp;
10217
10218 if (tname[0] != 't' || tname[1] != '_' ||
10219 tname[2] == NUL || tname[3] == NUL)
10220 return NULL;
10221 if ((opt_idx = findoption(tname)) >= 0)
10222 {
10223 varp = get_varp(&(options[opt_idx]));
10224 if (varp != NULL)
10225 varp = *(char_u **)(varp);
10226 return varp;
10227 }
10228 return find_termcode(tname + 2);
10229}
10230
10231 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010232get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010233{
10234 int i;
10235
10236 i = findoption((char_u *)"hl");
10237 if (i >= 0)
10238 return options[i].def_val[VI_DEFAULT];
10239 return (char_u *)NULL;
10240}
10241
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010242 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010243get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010244{
10245 int i;
10246
10247 i = findoption((char_u *)"enc");
10248 if (i >= 0)
10249 return options[i].def_val[VI_DEFAULT];
10250 return (char_u *)NULL;
10251}
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010252
Bram Moolenaar071d4272004-06-13 20:20:40 +000010253/*
10254 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010255 * When "has_lt" is true there is a '<' before "*arg_arg".
10256 * Returns 0 when the key is not recognized.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010257 */
10258 static int
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010259find_key_option(char_u *arg_arg, int has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010260{
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010261 int key = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010262 int modifiers;
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010263 char_u *arg = arg_arg;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010264
10265 /*
10266 * Don't use get_special_key_code() for t_xx, we don't want it to call
10267 * add_termcap_entry().
10268 */
10269 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
10270 key = TERMCAP2KEY(arg[2], arg[3]);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010271 else if (has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010272 {
10273 --arg; /* put arg at the '<' */
10274 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +020010275 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010276 if (modifiers) /* can't handle modifiers here */
10277 key = 0;
10278 }
10279 return key;
10280}
10281
10282/*
10283 * if 'all' == 0: show changed options
10284 * if 'all' == 1: show all normal options
10285 * if 'all' == 2: show all terminal options
10286 */
10287 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010288showoptions(
10289 int all,
10290 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010291{
10292 struct vimoption *p;
10293 int col;
10294 int isterm;
10295 char_u *varp;
10296 struct vimoption **items;
10297 int item_count;
10298 int run;
10299 int row, rows;
10300 int cols;
10301 int i;
10302 int len;
10303
10304#define INC 20
10305#define GAP 3
10306
Bram Moolenaarc799fe22019-05-28 23:08:19 +020010307 items = ALLOC_MULT(struct vimoption *, PARAM_COUNT);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010308 if (items == NULL)
10309 return;
10310
10311 /* Highlight title */
10312 if (all == 2)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010313 msg_puts_title(_("\n--- Terminal codes ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010314 else if (opt_flags & OPT_GLOBAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010315 msg_puts_title(_("\n--- Global option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010316 else if (opt_flags & OPT_LOCAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010317 msg_puts_title(_("\n--- Local option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010318 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010319 msg_puts_title(_("\n--- Options ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010320
10321 /*
10322 * do the loop two times:
10323 * 1. display the short items
10324 * 2. display the long items (only strings and numbers)
10325 */
10326 for (run = 1; run <= 2 && !got_int; ++run)
10327 {
10328 /*
10329 * collect the items in items[]
10330 */
10331 item_count = 0;
10332 for (p = &options[0]; p->fullname != NULL; p++)
10333 {
Bram Moolenaarf86db782018-10-25 13:31:37 +020010334 // apply :filter /pat/
10335 if (message_filtered((char_u *) p->fullname))
10336 continue;
10337
Bram Moolenaar071d4272004-06-13 20:20:40 +000010338 varp = NULL;
10339 isterm = istermoption(p);
10340 if (opt_flags != 0)
10341 {
10342 if (p->indir != PV_NONE && !isterm)
10343 varp = get_varp_scope(p, opt_flags);
10344 }
10345 else
10346 varp = get_varp(p);
10347 if (varp != NULL
10348 && ((all == 2 && isterm)
10349 || (all == 1 && !isterm)
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010350 || (all == 0 && !optval_default(p, varp, p_cp))))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010351 {
10352 if (p->flags & P_BOOL)
10353 len = 1; /* a toggle option fits always */
10354 else
10355 {
10356 option_value2string(p, opt_flags);
10357 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
10358 }
10359 if ((len <= INC - GAP && run == 1) ||
10360 (len > INC - GAP && run == 2))
10361 items[item_count++] = p;
10362 }
10363 }
10364
10365 /*
10366 * display the items
10367 */
10368 if (run == 1)
10369 {
10370 cols = (Columns + GAP - 3) / INC;
10371 if (cols == 0)
10372 cols = 1;
10373 rows = (item_count + cols - 1) / cols;
10374 }
10375 else /* run == 2 */
10376 rows = item_count;
10377 for (row = 0; row < rows && !got_int; ++row)
10378 {
10379 msg_putchar('\n'); /* go to next line */
10380 if (got_int) /* 'q' typed in more */
10381 break;
10382 col = 0;
10383 for (i = row; i < item_count; i += rows)
10384 {
10385 msg_col = col; /* make columns */
10386 showoneopt(items[i], opt_flags);
10387 col += INC;
10388 }
10389 out_flush();
10390 ui_breakcheck();
10391 }
10392 }
10393 vim_free(items);
10394}
10395
10396/*
10397 * Return TRUE if option "p" has its default value.
10398 */
10399 static int
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010400optval_default(struct vimoption *p, char_u *varp, int compatible)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010401{
10402 int dvi;
10403
10404 if (varp == NULL)
10405 return TRUE; /* hidden option is always at default */
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010406 dvi = ((p->flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010407 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010408 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010409 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010410 /* the cast to long is required for Manx C, long_i is
10411 * needed for MSVC */
10412 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010413 /* P_STRING */
10414 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
10415}
10416
10417/*
10418 * showoneopt: show the value of one option
10419 * must not be called with a hidden option!
10420 */
10421 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010422showoneopt(
10423 struct vimoption *p,
10424 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010425{
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010426 char_u *varp;
10427 int save_silent = silent_mode;
10428
10429 silent_mode = FALSE;
10430 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010431
10432 varp = get_varp_scope(p, opt_flags);
10433
10434 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
10435 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
10436 ? !curbufIsChanged() : !*(int *)varp))
Bram Moolenaar32526b32019-01-19 17:43:09 +010010437 msg_puts("no");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010438 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010439 msg_puts("--");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010440 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010441 msg_puts(" ");
10442 msg_puts(p->fullname);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010443 if (!(p->flags & P_BOOL))
10444 {
10445 msg_putchar('=');
10446 /* put value string in NameBuff */
10447 option_value2string(p, opt_flags);
10448 msg_outtrans(NameBuff);
10449 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010450
10451 silent_mode = save_silent;
10452 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010453}
10454
10455/*
10456 * Write modified options as ":set" commands to a file.
10457 *
10458 * There are three values for "opt_flags":
10459 * OPT_GLOBAL: Write global option values and fresh values of
10460 * buffer-local options (used for start of a session
10461 * file).
10462 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10463 * curwin (used for a vimrc file).
10464 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10465 * and local values for window-local options of
10466 * curwin. Local values are also written when at the
10467 * default value, because a modeline or autocommand
10468 * may have set them when doing ":edit file" and the
10469 * user has set them back at the default or fresh
10470 * value.
10471 * When "local_only" is TRUE, don't write fresh
10472 * values, only local values (for ":mkview").
10473 * (fresh value = value used for a new buffer or window for a local option).
10474 *
10475 * Return FAIL on error, OK otherwise.
10476 */
10477 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010478makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010479{
10480 struct vimoption *p;
10481 char_u *varp; /* currently used value */
10482 char_u *varp_fresh; /* local value */
10483 char_u *varp_local = NULL; /* fresh value */
10484 char *cmd;
10485 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010486 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010487
10488 /*
10489 * The options that don't have a default (terminal name, columns, lines)
10490 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010491 * Do the loop over "options[]" twice: once for options with the
10492 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010493 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010494 for (pri = 1; pri >= 0; --pri)
10495 {
10496 for (p = &options[0]; !istermoption(p); p++)
10497 if (!(p->flags & P_NO_MKRC)
10498 && !istermoption(p)
10499 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010500 {
10501 /* skip global option when only doing locals */
10502 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10503 continue;
10504
10505 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10506 * file, they are always buffer-specific. */
10507 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10508 continue;
10509
10510 /* Global values are only written when not at the default value. */
10511 varp = get_varp_scope(p, opt_flags);
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010512 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp, p_cp))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010513 continue;
10514
10515 round = 2;
10516 if (p->indir != PV_NONE)
10517 {
10518 if (p->var == VAR_WIN)
10519 {
10520 /* skip window-local option when only doing globals */
10521 if (!(opt_flags & OPT_LOCAL))
10522 continue;
10523 /* When fresh value of window-local option is not at the
10524 * default, need to write it too. */
10525 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10526 {
10527 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010528 if (!optval_default(p, varp_fresh, p_cp))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010529 {
10530 round = 1;
10531 varp_local = varp;
10532 varp = varp_fresh;
10533 }
10534 }
10535 }
10536 }
10537
10538 /* Round 1: fresh value for window-local options.
10539 * Round 2: other values */
10540 for ( ; round <= 2; varp = varp_local, ++round)
10541 {
10542 if (round == 1 || (opt_flags & OPT_GLOBAL))
10543 cmd = "set";
10544 else
10545 cmd = "setlocal";
10546
10547 if (p->flags & P_BOOL)
10548 {
10549 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10550 return FAIL;
10551 }
10552 else if (p->flags & P_NUM)
10553 {
10554 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10555 return FAIL;
10556 }
10557 else /* P_STRING */
10558 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010559 int do_endif = FALSE;
10560
Bram Moolenaar071d4272004-06-13 20:20:40 +000010561 /* Don't set 'syntax' and 'filetype' again if the value is
10562 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010563 if (
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +010010564#if defined(FEAT_SYN_HL)
10565 p->indir == PV_SYN ||
10566#endif
10567 p->indir == PV_FT)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010568 {
10569 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10570 *(char_u **)(varp)) < 0
10571 || put_eol(fd) < 0)
10572 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010573 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010574 }
10575 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010576 p->flags) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010577 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010578 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010579 {
10580 if (put_line(fd, "endif") == FAIL)
10581 return FAIL;
10582 }
10583 }
10584 }
10585 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010586 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010587 return OK;
10588}
10589
10590#if defined(FEAT_FOLDING) || defined(PROTO)
10591/*
10592 * Generate set commands for the local fold options only. Used when
10593 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10594 */
10595 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010596makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010597{
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010598 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, 0) == FAIL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010599# ifdef FEAT_EVAL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010600 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010601 == FAIL
10602# endif
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010603 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010604 == FAIL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010605 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010606 == FAIL
10607 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10608 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10609 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10610 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10611 )
10612 return FAIL;
10613
10614 return OK;
10615}
10616#endif
10617
10618 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010619put_setstring(
10620 FILE *fd,
10621 char *cmd,
10622 char *name,
10623 char_u **valuep,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010624 long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010625{
10626 char_u *s;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010627 char_u *buf = NULL;
10628 char_u *part = NULL;
10629 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010630
10631 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10632 return FAIL;
10633 if (*valuep != NULL)
10634 {
10635 /* Output 'pastetoggle' as key names. For other
10636 * options some characters have to be escaped with
10637 * CTRL-V or backslash */
10638 if (valuep == &p_pt)
10639 {
10640 s = *valuep;
10641 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010642 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010643 return FAIL;
10644 }
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010645 // expand the option value, replace $HOME by ~
10646 else if ((flags & P_EXPAND) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010647 {
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010648 int size = (int)STRLEN(*valuep) + 1;
10649
10650 // replace home directory in the whole option value into "buf"
10651 buf = alloc(size);
Bram Moolenaarf8441472011-04-28 17:24:58 +020010652 if (buf == NULL)
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010653 goto fail;
10654 home_replace(NULL, *valuep, buf, size, FALSE);
10655
10656 // If the option value is longer than MAXPATHL, we need to append
10657 // earch comma separated part of the option separately, so that it
10658 // can be expanded when read back.
10659 if (size >= MAXPATHL && (flags & P_COMMA) != 0
10660 && vim_strchr(*valuep, ',') != NULL)
10661 {
10662 part = alloc(size);
10663 if (part == NULL)
10664 goto fail;
10665
10666 // write line break to clear the option, e.g. ':set rtp='
10667 if (put_eol(fd) == FAIL)
10668 goto fail;
10669
10670 p = buf;
10671 while (*p != NUL)
10672 {
10673 // for each comma separated option part, append value to
10674 // the option, :set rtp+=value
10675 if (fprintf(fd, "%s %s+=", cmd, name) < 0)
10676 goto fail;
10677 (void)copy_option_part(&p, part, size, ",");
10678 if (put_escstr(fd, part, 2) == FAIL || put_eol(fd) == FAIL)
10679 goto fail;
10680 }
10681 vim_free(buf);
10682 vim_free(part);
10683 return OK;
10684 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010685 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010686 {
10687 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010688 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010689 }
10690 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010691 }
10692 else if (put_escstr(fd, *valuep, 2) == FAIL)
10693 return FAIL;
10694 }
10695 if (put_eol(fd) < 0)
10696 return FAIL;
10697 return OK;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010698fail:
10699 vim_free(buf);
10700 vim_free(part);
10701 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010702}
10703
10704 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010705put_setnum(
10706 FILE *fd,
10707 char *cmd,
10708 char *name,
10709 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010710{
10711 long wc;
10712
10713 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10714 return FAIL;
10715 if (wc_use_keyname((char_u *)valuep, &wc))
10716 {
10717 /* print 'wildchar' and 'wildcharm' as a key name */
10718 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10719 return FAIL;
10720 }
10721 else if (fprintf(fd, "%ld", *valuep) < 0)
10722 return FAIL;
10723 if (put_eol(fd) < 0)
10724 return FAIL;
10725 return OK;
10726}
10727
10728 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010729put_setbool(
10730 FILE *fd,
10731 char *cmd,
10732 char *name,
10733 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010734{
Bram Moolenaar893de922007-10-02 18:40:57 +000010735 if (value < 0) /* global/local option using global value */
10736 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010737 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10738 || put_eol(fd) < 0)
10739 return FAIL;
10740 return OK;
10741}
10742
10743/*
10744 * Clear all the terminal options.
10745 * If the option has been allocated, free the memory.
10746 * Terminal options are never hidden or indirect.
10747 */
10748 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010749clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010750{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010751 /*
10752 * Reset a few things before clearing the old options. This may cause
10753 * outputting a few things that the terminal doesn't understand, but the
10754 * screen will be cleared later, so this is OK.
10755 */
10756#ifdef FEAT_MOUSE_TTY
10757 mch_setmouse(FALSE); /* switch mouse off */
10758#endif
10759#ifdef FEAT_TITLE
Bram Moolenaar40385db2018-08-07 22:31:44 +020010760 mch_restore_title(SAVE_RESTORE_BOTH); /* restore window titles */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010761#endif
10762#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10763 /* When starting the GUI close the display opened for the clipboard.
10764 * After restoring the title, because that will need the display. */
10765 if (gui.starting)
10766 clear_xterm_clip();
10767#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010768 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010769
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010770 free_termoptions();
10771}
10772
10773 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010774free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010775{
10776 struct vimoption *p;
10777
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010778 for (p = options; p->fullname != NULL; p++)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010779 if (istermoption(p))
10780 {
10781 if (p->flags & P_ALLOCED)
10782 free_string_option(*(char_u **)(p->var));
10783 if (p->flags & P_DEF_ALLOCED)
10784 free_string_option(p->def_val[VI_DEFAULT]);
10785 *(char_u **)(p->var) = empty_option;
10786 p->def_val[VI_DEFAULT] = empty_option;
10787 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010788#ifdef FEAT_EVAL
10789 // remember where the option was cleared
10790 set_option_sctx_idx((int)(p - options), OPT_GLOBAL, current_sctx);
10791#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010792 }
10793 clear_termcodes();
10794}
10795
10796/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010797 * Free the string for one term option, if it was allocated.
10798 * Set the string to empty_option and clear allocated flag.
10799 * "var" points to the option value.
10800 */
10801 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010802free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010803{
10804 struct vimoption *p;
10805
10806 for (p = &options[0]; p->fullname != NULL; p++)
10807 if (p->var == var)
10808 {
10809 if (p->flags & P_ALLOCED)
10810 free_string_option(*(char_u **)(p->var));
10811 *(char_u **)(p->var) = empty_option;
10812 p->flags &= ~P_ALLOCED;
10813 break;
10814 }
10815}
10816
10817/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010818 * Set the terminal option defaults to the current value.
10819 * Used after setting the terminal name.
10820 */
10821 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010822set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010823{
10824 struct vimoption *p;
10825
10826 for (p = &options[0]; p->fullname != NULL; p++)
10827 {
10828 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10829 {
10830 if (p->flags & P_DEF_ALLOCED)
10831 {
10832 free_string_option(p->def_val[VI_DEFAULT]);
10833 p->flags &= ~P_DEF_ALLOCED;
10834 }
10835 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10836 if (p->flags & P_ALLOCED)
10837 {
10838 p->flags |= P_DEF_ALLOCED;
10839 p->flags &= ~P_ALLOCED; /* don't free the value now */
10840 }
10841 }
10842 }
10843}
10844
10845/*
10846 * return TRUE if 'p' starts with 't_'
10847 */
10848 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010849istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010850{
10851 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10852}
10853
10854/*
10855 * Compute columns for ruler and shown command. 'sc_col' is also used to
10856 * decide what the maximum length of a message on the status line can be.
10857 * If there is a status line for the last window, 'sc_col' is independent
10858 * of 'ru_col'.
10859 */
10860
10861#define COL_RULER 17 /* columns needed by standard ruler */
10862
10863 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010864comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010865{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010866#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010867 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010868
10869 sc_col = 0;
10870 ru_col = 0;
10871 if (p_ru)
10872 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010873# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010874 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010875# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010876 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010877# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010878 /* no last status line, adjust sc_col */
10879 if (!last_has_status)
10880 sc_col = ru_col;
10881 }
10882 if (p_sc)
10883 {
10884 sc_col += SHOWCMD_COLS;
10885 if (!p_ru || last_has_status) /* no need for separating space */
10886 ++sc_col;
10887 }
10888 sc_col = Columns - sc_col;
10889 ru_col = Columns - ru_col;
10890 if (sc_col <= 0) /* screen too narrow, will become a mess */
10891 sc_col = 1;
10892 if (ru_col <= 0)
10893 ru_col = 1;
10894#else
10895 sc_col = Columns;
10896 ru_col = Columns;
10897#endif
10898}
10899
Bram Moolenaar113e1072019-01-20 15:30:40 +010010900#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010901/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010902 * Unset local option value, similar to ":set opt<".
10903 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010904 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010905unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010906{
10907 struct vimoption *p;
10908 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010909 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010910
10911 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010912 if (opt_idx < 0)
10913 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010914 p = &(options[opt_idx]);
10915
10916 switch ((int)p->indir)
10917 {
10918 /* global option with local value: use local value if it's been set */
10919 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010920 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010921 break;
10922 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010923 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010924 break;
10925 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010926 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010927 break;
10928 case PV_AR:
10929 buf->b_p_ar = -1;
10930 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010931 case PV_BKC:
10932 clear_string_option(&buf->b_p_bkc);
10933 buf->b_bkc_flags = 0;
10934 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010935 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010936 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010937 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010938 case PV_TC:
10939 clear_string_option(&buf->b_p_tc);
10940 buf->b_tc_flags = 0;
10941 break;
Bram Moolenaar375e3392019-01-31 18:26:10 +010010942 case PV_SISO:
10943 curwin->w_p_siso = -1;
10944 break;
10945 case PV_SO:
10946 curwin->w_p_so = -1;
10947 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010948#ifdef FEAT_FIND_ID
10949 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010950 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010951 break;
10952 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010953 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010954 break;
10955#endif
10956#ifdef FEAT_INS_EXPAND
10957 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010958 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010959 break;
10960 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010961 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010962 break;
10963#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010964 case PV_FP:
10965 clear_string_option(&buf->b_p_fp);
10966 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010967#ifdef FEAT_QUICKFIX
10968 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010969 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010970 break;
10971 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010972 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010973 break;
10974 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010975 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010976 break;
10977#endif
10978#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10979 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010980 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010981 break;
10982#endif
10983#if defined(FEAT_CRYPT)
10984 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010985 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010986 break;
10987#endif
10988#ifdef FEAT_STL_OPT
10989 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010990 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010991 break;
10992#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010993 case PV_UL:
10994 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10995 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010996#ifdef FEAT_LISP
10997 case PV_LW:
10998 clear_string_option(&buf->b_p_lw);
10999 break;
11000#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011001 case PV_MENC:
11002 clear_string_option(&buf->b_p_menc);
11003 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020011004 }
11005}
Bram Moolenaar113e1072019-01-20 15:30:40 +010011006#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020011007
11008/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011009 * Get pointer to option variable, depending on local or global scope.
11010 */
11011 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011012get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011013{
11014 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
11015 {
11016 if (p->var == VAR_WIN)
11017 return (char_u *)GLOBAL_WO(get_varp(p));
11018 return p->var;
11019 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000011020 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011021 {
11022 switch ((int)p->indir)
11023 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011024 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011025#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011026 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
11027 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
11028 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011029#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011030 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
11031 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
11032 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000011033 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011034 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011035 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar375e3392019-01-31 18:26:10 +010011036 case PV_SISO: return (char_u *)&(curwin->w_p_siso);
11037 case PV_SO: return (char_u *)&(curwin->w_p_so);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011038#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011039 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
11040 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011041#endif
11042#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011043 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
11044 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011045#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011046#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11047 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
11048#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011049#if defined(FEAT_CRYPT)
11050 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
11051#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011052#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011053 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011054#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011055 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011056#ifdef FEAT_LISP
11057 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
11058#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011059 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011060 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011061 }
11062 return NULL; /* "cannot happen" */
11063 }
11064 return get_varp(p);
11065}
11066
11067/*
11068 * Get pointer to option variable.
11069 */
11070 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011071get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011072{
11073 /* hidden option, always return NULL */
11074 if (p->var == NULL)
11075 return NULL;
11076
11077 switch ((int)p->indir)
11078 {
11079 case PV_NONE: return p->var;
11080
11081 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011082 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011083 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011084 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011085 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011086 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011087 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000011088 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000011089 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011090 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011091 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011092 case PV_TC: return *curbuf->b_p_tc != NUL
11093 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011094 case PV_BKC: return *curbuf->b_p_bkc != NUL
11095 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar375e3392019-01-31 18:26:10 +010011096 case PV_SISO: return curwin->w_p_siso >= 0
11097 ? (char_u *)&(curwin->w_p_siso) : p->var;
11098 case PV_SO: return curwin->w_p_so >= 0
11099 ? (char_u *)&(curwin->w_p_so) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011100#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011101 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011102 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011103 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011104 ? (char_u *)&(curbuf->b_p_inc) : p->var;
11105#endif
11106#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011107 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011108 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011109 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011110 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
11111#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011112 case PV_FP: return *curbuf->b_p_fp != NUL
11113 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011114#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011115 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011116 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011117 case PV_GP: return *curbuf->b_p_gp != NUL
11118 ? (char_u *)&(curbuf->b_p_gp) : p->var;
11119 case PV_MP: return *curbuf->b_p_mp != NUL
11120 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011121#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011122#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11123 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
11124 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
11125#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011126#if defined(FEAT_CRYPT)
11127 case PV_CM: return *curbuf->b_p_cm != NUL
11128 ? (char_u *)&(curbuf->b_p_cm) : p->var;
11129#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011130#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011131 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011132 ? (char_u *)&(curwin->w_p_stl) : p->var;
11133#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011134 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
11135 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011136#ifdef FEAT_LISP
11137 case PV_LW: return *curbuf->b_p_lw != NUL
11138 ? (char_u *)&(curbuf->b_p_lw) : p->var;
11139#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011140 case PV_MENC: return *curbuf->b_p_menc != NUL
11141 ? (char_u *)&(curbuf->b_p_menc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011142#ifdef FEAT_ARABIC
11143 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
11144#endif
11145 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011146#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000011147 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
11148#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011149#ifdef FEAT_SYN_HL
11150 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
11151 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020011152 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011153#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011154#ifdef FEAT_DIFF
11155 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
11156#endif
11157#ifdef FEAT_FOLDING
11158 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
11159 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
11160 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
11161 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
11162 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
11163 case PV_FML: return (char_u *)&(curwin->w_p_fml);
11164 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
11165# ifdef FEAT_EVAL
11166 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
11167 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
11168# endif
11169 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
11170#endif
11171 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020011172 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011173#ifdef FEAT_LINEBREAK
11174 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
11175#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011176 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000011177 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020011178#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011179 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
11180#endif
11181#ifdef FEAT_RIGHTLEFT
11182 case PV_RL: return (char_u *)&(curwin->w_p_rl);
11183 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
11184#endif
11185 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
11186 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
11187#ifdef FEAT_LINEBREAK
11188 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020011189 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
11190 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011191#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011192 case PV_WCR: return (char_u *)&(curwin->w_p_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011193 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011194 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011195#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011196 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
11197 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
11198#endif
11199#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011200 case PV_TWK: return (char_u *)&(curwin->w_p_twk);
11201 case PV_TWS: return (char_u *)&(curwin->w_p_tws);
11202 case PV_TWSL: return (char_u *)&(curbuf->b_p_twsl);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011203#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011204
11205 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
11206 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011207 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011208 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
11209 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011210 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
11211 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
11212#ifdef FEAT_CINDENT
11213 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
11214 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
11215 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
11216#endif
11217#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11218 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
11219#endif
11220#ifdef FEAT_COMMENTS
11221 case PV_COM: return (char_u *)&(curbuf->b_p_com);
11222#endif
11223#ifdef FEAT_FOLDING
11224 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
11225#endif
11226#ifdef FEAT_INS_EXPAND
11227 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
Bram Moolenaarac3150d2019-07-28 16:36:39 +020011228# ifdef BACKSLASH_IN_FILENAME
11229 case PV_CSL: return (char_u *)&(curbuf->b_p_csl);
11230# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011231#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011232#ifdef FEAT_COMPL_FUNC
11233 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011234 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011235#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +020011236#ifdef FEAT_EVAL
11237 case PV_TFU: return (char_u *)&(curbuf->b_p_tfu);
11238#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011239 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020011240 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011241 case PV_ET: return (char_u *)&(curbuf->b_p_et);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011242 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011243 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011244 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011245 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011246 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011247 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
11248 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
11249 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
11250 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
11251#ifdef FEAT_FIND_ID
11252# ifdef FEAT_EVAL
11253 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
11254# endif
11255#endif
11256#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11257 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
11258 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
11259#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011260#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011261 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
11262#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011263#ifdef FEAT_CRYPT
11264 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
11265#endif
11266#ifdef FEAT_LISP
11267 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
11268#endif
11269 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
11270 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
11271 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
11272 case PV_MOD: return (char_u *)&(curbuf->b_changed);
11273 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011274 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011275#ifdef FEAT_TEXTOBJ
11276 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
11277#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011278 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
11279#ifdef FEAT_SMARTINDENT
11280 case PV_SI: return (char_u *)&(curbuf->b_p_si);
11281#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011282 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011283 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
11284#ifdef FEAT_SEARCHPATH
11285 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
11286#endif
11287 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
11288#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011289 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011290 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
11291#endif
11292#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020011293 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
11294 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
11295 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011296#endif
11297 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
11298 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
11299 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
11300 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011301#ifdef FEAT_PERSISTENT_UNDO
11302 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
11303#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011304 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
11305#ifdef FEAT_KEYMAP
11306 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
11307#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011308#ifdef FEAT_SIGNS
11309 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
11310#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011311#ifdef FEAT_VARTABS
11312 case PV_VSTS: return (char_u *)&(curbuf->b_p_vsts);
11313 case PV_VTS: return (char_u *)&(curbuf->b_p_vts);
11314#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010011315 default: iemsg(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011316 }
11317 /* always return a valid pointer to avoid a crash! */
11318 return (char_u *)&(curbuf->b_p_wm);
11319}
11320
11321/*
11322 * Get the value of 'equalprg', either the buffer-local one or the global one.
11323 */
11324 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011325get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011326{
11327 if (*curbuf->b_p_ep == NUL)
11328 return p_ep;
11329 return curbuf->b_p_ep;
11330}
11331
Bram Moolenaar071d4272004-06-13 20:20:40 +000011332/*
11333 * Copy options from one window to another.
11334 * Used when splitting a window.
11335 */
11336 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011337win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011338{
11339 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
11340 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020011341#if defined(FEAT_LINEBREAK)
11342 briopt_check(wp_to);
11343#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011344}
Bram Moolenaar071d4272004-06-13 20:20:40 +000011345
11346/*
11347 * Copy the options from one winopt_T to another.
11348 * Doesn't free the old option values in "to", use clear_winopt() for that.
11349 * The 'scroll' option is not copied, because it depends on the window height.
11350 * The 'previewwindow' option is reset, there can be only one preview window.
11351 */
11352 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011353copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011354{
11355#ifdef FEAT_ARABIC
11356 to->wo_arab = from->wo_arab;
11357#endif
11358 to->wo_list = from->wo_list;
11359 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020011360 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011361#ifdef FEAT_LINEBREAK
11362 to->wo_nuw = from->wo_nuw;
11363#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011364#ifdef FEAT_RIGHTLEFT
11365 to->wo_rl = from->wo_rl;
11366 to->wo_rlc = vim_strsave(from->wo_rlc);
11367#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011368#ifdef FEAT_STL_OPT
11369 to->wo_stl = vim_strsave(from->wo_stl);
11370#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011371 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011372#ifdef FEAT_DIFF
11373 to->wo_wrap_save = from->wo_wrap_save;
11374#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011375#ifdef FEAT_LINEBREAK
11376 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020011377 to->wo_bri = from->wo_bri;
11378 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011379#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011380 to->wo_wcr = vim_strsave(from->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011381 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011382 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010011383 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011384 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011385#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000011386 to->wo_spell = from->wo_spell;
11387#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011388#ifdef FEAT_SYN_HL
11389 to->wo_cuc = from->wo_cuc;
11390 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020011391 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011392#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011393#ifdef FEAT_DIFF
11394 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011395 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011396#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011397#ifdef FEAT_CONCEAL
11398 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020011399 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011400#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011401#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011402 to->wo_twk = vim_strsave(from->wo_twk);
11403 to->wo_tws = vim_strsave(from->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011404#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011405#ifdef FEAT_FOLDING
11406 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011407 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011408 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011409 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011410 to->wo_fdi = vim_strsave(from->wo_fdi);
11411 to->wo_fml = from->wo_fml;
11412 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011413 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011414 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011415 to->wo_fdm_save = from->wo_diff_saved
11416 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011417 to->wo_fdn = from->wo_fdn;
11418# ifdef FEAT_EVAL
11419 to->wo_fde = vim_strsave(from->wo_fde);
11420 to->wo_fdt = vim_strsave(from->wo_fdt);
11421# endif
11422 to->wo_fmr = vim_strsave(from->wo_fmr);
11423#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011424#ifdef FEAT_SIGNS
11425 to->wo_scl = vim_strsave(from->wo_scl);
11426#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011427 check_winopt(to); /* don't want NULL pointers */
11428}
11429
11430/*
11431 * Check string options in a window for a NULL value.
11432 */
11433 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011434check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011435{
11436 check_winopt(&win->w_onebuf_opt);
11437 check_winopt(&win->w_allbuf_opt);
11438}
11439
11440/*
11441 * Check for NULL pointers in a winopt_T and replace them with empty_option.
11442 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020011443 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011444check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011445{
11446#ifdef FEAT_FOLDING
11447 check_string_option(&wop->wo_fdi);
11448 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011449 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011450# ifdef FEAT_EVAL
11451 check_string_option(&wop->wo_fde);
11452 check_string_option(&wop->wo_fdt);
11453# endif
11454 check_string_option(&wop->wo_fmr);
11455#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011456#ifdef FEAT_SIGNS
11457 check_string_option(&wop->wo_scl);
11458#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011459#ifdef FEAT_RIGHTLEFT
11460 check_string_option(&wop->wo_rlc);
11461#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011462#ifdef FEAT_STL_OPT
11463 check_string_option(&wop->wo_stl);
11464#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011465#ifdef FEAT_SYN_HL
11466 check_string_option(&wop->wo_cc);
11467#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011468#ifdef FEAT_CONCEAL
11469 check_string_option(&wop->wo_cocu);
11470#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011471#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011472 check_string_option(&wop->wo_twk);
11473 check_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011474#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011475#ifdef FEAT_LINEBREAK
11476 check_string_option(&wop->wo_briopt);
11477#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011478 check_string_option(&wop->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011479}
11480
11481/*
11482 * Free the allocated memory inside a winopt_T.
11483 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011484 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011485clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011486{
11487#ifdef FEAT_FOLDING
11488 clear_string_option(&wop->wo_fdi);
11489 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011490 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011491# ifdef FEAT_EVAL
11492 clear_string_option(&wop->wo_fde);
11493 clear_string_option(&wop->wo_fdt);
11494# endif
11495 clear_string_option(&wop->wo_fmr);
11496#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011497#ifdef FEAT_SIGNS
11498 clear_string_option(&wop->wo_scl);
11499#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011500#ifdef FEAT_LINEBREAK
11501 clear_string_option(&wop->wo_briopt);
11502#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011503 clear_string_option(&wop->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011504#ifdef FEAT_RIGHTLEFT
11505 clear_string_option(&wop->wo_rlc);
11506#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011507#ifdef FEAT_STL_OPT
11508 clear_string_option(&wop->wo_stl);
11509#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011510#ifdef FEAT_SYN_HL
11511 clear_string_option(&wop->wo_cc);
11512#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011513#ifdef FEAT_CONCEAL
11514 clear_string_option(&wop->wo_cocu);
11515#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011516#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011517 clear_string_option(&wop->wo_twk);
11518 clear_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011519#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011520}
11521
11522/*
11523 * Copy global option values to local options for one buffer.
11524 * Used when creating a new buffer and sometimes when entering a buffer.
11525 * flags:
11526 * BCO_ENTER We will enter the buf buffer.
11527 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11528 * appropriate.
11529 * BCO_NOHELP Don't copy the values to a help buffer.
11530 */
11531 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011532buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011533{
11534 int should_copy = TRUE;
11535 char_u *save_p_isk = NULL; /* init for GCC */
11536 int dont_do_help;
11537 int did_isk = FALSE;
11538
11539 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011540 * Skip this when the option defaults have not been set yet. Happens when
11541 * main() allocates the first buffer.
11542 */
11543 if (p_cpo != NULL)
11544 {
11545 /*
11546 * Always copy when entering and 'cpo' contains 'S'.
11547 * Don't copy when already initialized.
11548 * Don't copy when 'cpo' contains 's' and not entering.
11549 * 'S' BCO_ENTER initialized 's' should_copy
11550 * yes yes X X TRUE
11551 * yes no yes X FALSE
11552 * no X yes X FALSE
11553 * X no no yes FALSE
11554 * X no no no TRUE
11555 * no yes no X TRUE
11556 */
11557 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11558 && (buf->b_p_initialized
11559 || (!(flags & BCO_ENTER)
11560 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11561 should_copy = FALSE;
11562
11563 if (should_copy || (flags & BCO_ALWAYS))
11564 {
11565 /* Don't copy the options specific to a help buffer when
11566 * BCO_NOHELP is given or the options were initialized already
11567 * (jumping back to a help file with CTRL-T or CTRL-O) */
11568 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11569 || buf->b_p_initialized;
11570 if (dont_do_help) /* don't free b_p_isk */
11571 {
11572 save_p_isk = buf->b_p_isk;
11573 buf->b_p_isk = NULL;
11574 }
11575 /*
Bram Moolenaar40385db2018-08-07 22:31:44 +020011576 * Always free the allocated strings. If not already initialized,
11577 * reset 'readonly' and copy 'fileformat'.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011578 */
11579 if (!buf->b_p_initialized)
11580 {
11581 free_buf_options(buf, TRUE);
11582 buf->b_p_ro = FALSE; /* don't copy readonly */
11583 buf->b_p_tx = p_tx;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011584 buf->b_p_fenc = vim_strsave(p_fenc);
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011585 switch (*p_ffs)
11586 {
11587 case 'm':
11588 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11589 case 'd':
11590 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11591 case 'u':
11592 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11593 default:
11594 buf->b_p_ff = vim_strsave(p_ff);
11595 }
11596 if (buf->b_p_ff != NULL)
11597 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011598 buf->b_p_bh = empty_option;
11599 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011600 }
11601 else
11602 free_buf_options(buf, FALSE);
11603
11604 buf->b_p_ai = p_ai;
11605 buf->b_p_ai_nopaste = p_ai_nopaste;
11606 buf->b_p_sw = p_sw;
11607 buf->b_p_tw = p_tw;
11608 buf->b_p_tw_nopaste = p_tw_nopaste;
11609 buf->b_p_tw_nobin = p_tw_nobin;
11610 buf->b_p_wm = p_wm;
11611 buf->b_p_wm_nopaste = p_wm_nopaste;
11612 buf->b_p_wm_nobin = p_wm_nobin;
11613 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011614 buf->b_p_bomb = p_bomb;
Bram Moolenaarb388be02015-07-22 22:19:38 +020011615 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011616 buf->b_p_et = p_et;
11617 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011618 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011619 buf->b_p_ml = p_ml;
11620 buf->b_p_ml_nobin = p_ml_nobin;
11621 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011622 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011623#ifdef FEAT_INS_EXPAND
11624 buf->b_p_cpt = vim_strsave(p_cpt);
Bram Moolenaarac3150d2019-07-28 16:36:39 +020011625# ifdef BACKSLASH_IN_FILENAME
11626 buf->b_p_csl = vim_strsave(p_csl);
11627# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011628#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011629#ifdef FEAT_COMPL_FUNC
11630 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011631 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011632#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +020011633#ifdef FEAT_EVAL
11634 buf->b_p_tfu = vim_strsave(p_tfu);
11635#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011636 buf->b_p_sts = p_sts;
11637 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011638#ifdef FEAT_VARTABS
11639 buf->b_p_vsts = vim_strsave(p_vsts);
11640 if (p_vsts && p_vsts != empty_option)
11641 tabstop_set(p_vsts, &buf->b_p_vsts_array);
11642 else
11643 buf->b_p_vsts_array = 0;
11644 buf->b_p_vsts_nopaste = p_vsts_nopaste
11645 ? vim_strsave(p_vsts_nopaste) : NULL;
11646#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011647 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011648#ifdef FEAT_COMMENTS
11649 buf->b_p_com = vim_strsave(p_com);
11650#endif
11651#ifdef FEAT_FOLDING
11652 buf->b_p_cms = vim_strsave(p_cms);
11653#endif
11654 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011655 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011656 buf->b_p_nf = vim_strsave(p_nf);
11657 buf->b_p_mps = vim_strsave(p_mps);
11658#ifdef FEAT_SMARTINDENT
11659 buf->b_p_si = p_si;
11660#endif
11661 buf->b_p_ci = p_ci;
11662#ifdef FEAT_CINDENT
11663 buf->b_p_cin = p_cin;
11664 buf->b_p_cink = vim_strsave(p_cink);
11665 buf->b_p_cino = vim_strsave(p_cino);
11666#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011667 /* Don't copy 'filetype', it must be detected */
11668 buf->b_p_ft = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011669 buf->b_p_pi = p_pi;
11670#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11671 buf->b_p_cinw = vim_strsave(p_cinw);
11672#endif
11673#ifdef FEAT_LISP
11674 buf->b_p_lisp = p_lisp;
11675#endif
11676#ifdef FEAT_SYN_HL
11677 /* Don't copy 'syntax', it must be set */
11678 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011679 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011680 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011681#endif
11682#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011683 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011684 (void)compile_cap_prog(&buf->b_s);
11685 buf->b_s.b_p_spf = vim_strsave(p_spf);
11686 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011687#endif
11688#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11689 buf->b_p_inde = vim_strsave(p_inde);
11690 buf->b_p_indk = vim_strsave(p_indk);
11691#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011692 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011693#if defined(FEAT_EVAL)
11694 buf->b_p_fex = vim_strsave(p_fex);
11695#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011696#ifdef FEAT_CRYPT
11697 buf->b_p_key = vim_strsave(p_key);
11698#endif
11699#ifdef FEAT_SEARCHPATH
11700 buf->b_p_sua = vim_strsave(p_sua);
11701#endif
11702#ifdef FEAT_KEYMAP
11703 buf->b_p_keymap = vim_strsave(p_keymap);
11704 buf->b_kmap_state |= KEYMAP_INIT;
11705#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011706#ifdef FEAT_TERMINAL
11707 buf->b_p_twsl = p_twsl;
11708#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011709 /* This isn't really an option, but copying the langmap and IME
11710 * state from the current buffer is better than resetting it. */
11711 buf->b_p_iminsert = p_iminsert;
11712 buf->b_p_imsearch = p_imsearch;
11713
11714 /* options that are normally global but also have a local value
11715 * are not copied, start using the global value */
11716 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011717 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011718 buf->b_p_bkc = empty_option;
11719 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011720#ifdef FEAT_QUICKFIX
11721 buf->b_p_gp = empty_option;
11722 buf->b_p_mp = empty_option;
11723 buf->b_p_efm = empty_option;
11724#endif
11725 buf->b_p_ep = empty_option;
11726 buf->b_p_kp = empty_option;
11727 buf->b_p_path = empty_option;
11728 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011729 buf->b_p_tc = empty_option;
11730 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011731#ifdef FEAT_FIND_ID
11732 buf->b_p_def = empty_option;
11733 buf->b_p_inc = empty_option;
11734# ifdef FEAT_EVAL
11735 buf->b_p_inex = vim_strsave(p_inex);
11736# endif
11737#endif
11738#ifdef FEAT_INS_EXPAND
11739 buf->b_p_dict = empty_option;
11740 buf->b_p_tsr = empty_option;
11741#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011742#ifdef FEAT_TEXTOBJ
11743 buf->b_p_qe = vim_strsave(p_qe);
11744#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011745#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11746 buf->b_p_bexpr = empty_option;
11747#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011748#if defined(FEAT_CRYPT)
11749 buf->b_p_cm = empty_option;
11750#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011751#ifdef FEAT_PERSISTENT_UNDO
11752 buf->b_p_udf = p_udf;
11753#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011754#ifdef FEAT_LISP
11755 buf->b_p_lw = empty_option;
11756#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011757 buf->b_p_menc = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011758
11759 /*
11760 * Don't copy the options set by ex_help(), use the saved values,
11761 * when going from a help buffer to a non-help buffer.
11762 * Don't touch these at all when BCO_NOHELP is used and going from
11763 * or to a help buffer.
11764 */
11765 if (dont_do_help)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011766 {
Bram Moolenaar071d4272004-06-13 20:20:40 +000011767 buf->b_p_isk = save_p_isk;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011768#ifdef FEAT_VARTABS
11769 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11770 tabstop_set(p_vts, &buf->b_p_vts_array);
11771 else
11772 buf->b_p_vts_array = NULL;
11773#endif
11774 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011775 else
11776 {
11777 buf->b_p_isk = vim_strsave(p_isk);
11778 did_isk = TRUE;
11779 buf->b_p_ts = p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011780#ifdef FEAT_VARTABS
11781 buf->b_p_vts = vim_strsave(p_vts);
11782 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11783 tabstop_set(p_vts, &buf->b_p_vts_array);
11784 else
11785 buf->b_p_vts_array = NULL;
11786#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011787 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011788 if (buf->b_p_bt[0] == 'h')
11789 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011790 buf->b_p_ma = p_ma;
11791 }
11792 }
11793
11794 /*
11795 * When the options should be copied (ignoring BCO_ALWAYS), set the
11796 * flag that indicates that the options have been initialized.
11797 */
11798 if (should_copy)
11799 buf->b_p_initialized = TRUE;
11800 }
11801
11802 check_buf_options(buf); /* make sure we don't have NULLs */
11803 if (did_isk)
11804 (void)buf_init_chartab(buf, FALSE);
11805}
11806
11807/*
11808 * Reset the 'modifiable' option and its default value.
11809 */
11810 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011811reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011812{
11813 int opt_idx;
11814
11815 curbuf->b_p_ma = FALSE;
11816 p_ma = FALSE;
11817 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011818 if (opt_idx >= 0)
11819 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011820}
11821
11822/*
11823 * Set the global value for 'iminsert' to the local value.
11824 */
11825 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011826set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011827{
11828 p_iminsert = curbuf->b_p_iminsert;
11829}
11830
11831/*
11832 * Set the global value for 'imsearch' to the local value.
11833 */
11834 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011835set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011836{
11837 p_imsearch = curbuf->b_p_imsearch;
11838}
11839
Bram Moolenaar071d4272004-06-13 20:20:40 +000011840static int expand_option_idx = -1;
11841static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11842static int expand_option_flags = 0;
11843
11844 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011845set_context_in_set_cmd(
11846 expand_T *xp,
11847 char_u *arg,
11848 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011849{
11850 int nextchar;
11851 long_u flags = 0; /* init for GCC */
11852 int opt_idx = 0; /* init for GCC */
11853 char_u *p;
11854 char_u *s;
11855 int is_term_option = FALSE;
11856 int key;
11857
11858 expand_option_flags = opt_flags;
11859
11860 xp->xp_context = EXPAND_SETTINGS;
11861 if (*arg == NUL)
11862 {
11863 xp->xp_pattern = arg;
11864 return;
11865 }
11866 p = arg + STRLEN(arg) - 1;
11867 if (*p == ' ' && *(p - 1) != '\\')
11868 {
11869 xp->xp_pattern = p + 1;
11870 return;
11871 }
11872 while (p > arg)
11873 {
11874 s = p;
11875 /* count number of backslashes before ' ' or ',' */
11876 if (*p == ' ' || *p == ',')
11877 {
11878 while (s > arg && *(s - 1) == '\\')
11879 --s;
11880 }
11881 /* break at a space with an even number of backslashes */
11882 if (*p == ' ' && ((p - s) & 1) == 0)
11883 {
11884 ++p;
11885 break;
11886 }
11887 --p;
11888 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011889 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011890 {
11891 xp->xp_context = EXPAND_BOOL_SETTINGS;
11892 p += 2;
11893 }
11894 if (STRNCMP(p, "inv", 3) == 0)
11895 {
11896 xp->xp_context = EXPAND_BOOL_SETTINGS;
11897 p += 3;
11898 }
11899 xp->xp_pattern = arg = p;
11900 if (*arg == '<')
11901 {
11902 while (*p != '>')
11903 if (*p++ == NUL) /* expand terminal option name */
11904 return;
11905 key = get_special_key_code(arg + 1);
11906 if (key == 0) /* unknown name */
11907 {
11908 xp->xp_context = EXPAND_NOTHING;
11909 return;
11910 }
11911 nextchar = *++p;
11912 is_term_option = TRUE;
11913 expand_option_name[2] = KEY2TERMCAP0(key);
11914 expand_option_name[3] = KEY2TERMCAP1(key);
11915 }
11916 else
11917 {
11918 if (p[0] == 't' && p[1] == '_')
11919 {
11920 p += 2;
11921 if (*p != NUL)
11922 ++p;
11923 if (*p == NUL)
11924 return; /* expand option name */
11925 nextchar = *++p;
11926 is_term_option = TRUE;
11927 expand_option_name[2] = p[-2];
11928 expand_option_name[3] = p[-1];
11929 }
11930 else
11931 {
11932 /* Allow * wildcard */
11933 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11934 p++;
11935 if (*p == NUL)
11936 return;
11937 nextchar = *p;
11938 *p = NUL;
11939 opt_idx = findoption(arg);
11940 *p = nextchar;
11941 if (opt_idx == -1 || options[opt_idx].var == NULL)
11942 {
11943 xp->xp_context = EXPAND_NOTHING;
11944 return;
11945 }
11946 flags = options[opt_idx].flags;
11947 if (flags & P_BOOL)
11948 {
11949 xp->xp_context = EXPAND_NOTHING;
11950 return;
11951 }
11952 }
11953 }
11954 /* handle "-=" and "+=" */
11955 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11956 {
11957 ++p;
11958 nextchar = '=';
11959 }
11960 if ((nextchar != '=' && nextchar != ':')
11961 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11962 {
11963 xp->xp_context = EXPAND_UNSUCCESSFUL;
11964 return;
11965 }
11966 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11967 {
11968 xp->xp_context = EXPAND_OLD_SETTING;
11969 if (is_term_option)
11970 expand_option_idx = -1;
11971 else
11972 expand_option_idx = opt_idx;
11973 xp->xp_pattern = p + 1;
11974 return;
11975 }
11976 xp->xp_context = EXPAND_NOTHING;
11977 if (is_term_option || (flags & P_NUM))
11978 return;
11979
11980 xp->xp_pattern = p + 1;
11981
11982 if (flags & P_EXPAND)
11983 {
11984 p = options[opt_idx].var;
11985 if (p == (char_u *)&p_bdir
11986 || p == (char_u *)&p_dir
11987 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011988 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011989 || p == (char_u *)&p_rtp
11990#ifdef FEAT_SEARCHPATH
11991 || p == (char_u *)&p_cdpath
11992#endif
11993#ifdef FEAT_SESSION
11994 || p == (char_u *)&p_vdir
11995#endif
11996 )
11997 {
11998 xp->xp_context = EXPAND_DIRECTORIES;
11999 if (p == (char_u *)&p_path
12000#ifdef FEAT_SEARCHPATH
12001 || p == (char_u *)&p_cdpath
12002#endif
12003 )
12004 xp->xp_backslash = XP_BS_THREE;
12005 else
12006 xp->xp_backslash = XP_BS_ONE;
12007 }
12008 else
12009 {
12010 xp->xp_context = EXPAND_FILES;
12011 /* for 'tags' need three backslashes for a space */
12012 if (p == (char_u *)&p_tags)
12013 xp->xp_backslash = XP_BS_THREE;
12014 else
12015 xp->xp_backslash = XP_BS_ONE;
12016 }
12017 }
12018
12019 /* For an option that is a list of file names, find the start of the
12020 * last file name. */
12021 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
12022 {
12023 /* count number of backslashes before ' ' or ',' */
12024 if (*p == ' ' || *p == ',')
12025 {
12026 s = p;
12027 while (s > xp->xp_pattern && *(s - 1) == '\\')
12028 --s;
12029 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
12030 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
12031 {
12032 xp->xp_pattern = p + 1;
12033 break;
12034 }
12035 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000012036
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000012037#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000012038 /* for 'spellsuggest' start at "file:" */
12039 if (options[opt_idx].var == (char_u *)&p_sps
12040 && STRNCMP(p, "file:", 5) == 0)
12041 {
12042 xp->xp_pattern = p + 5;
12043 break;
12044 }
12045#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012046 }
12047
12048 return;
12049}
12050
12051 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012052ExpandSettings(
12053 expand_T *xp,
12054 regmatch_T *regmatch,
12055 int *num_file,
12056 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012057{
12058 int num_normal = 0; /* Nr of matching non-term-code settings */
12059 int num_term = 0; /* Nr of matching terminal code settings */
12060 int opt_idx;
12061 int match;
12062 int count = 0;
12063 char_u *str;
12064 int loop;
12065 int is_term_opt;
12066 char_u name_buf[MAX_KEY_NAME_LEN];
12067 static char *(names[]) = {"all", "termcap"};
12068 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
12069
12070 /* do this loop twice:
12071 * loop == 0: count the number of matching options
12072 * loop == 1: copy the matching options into allocated memory
12073 */
12074 for (loop = 0; loop <= 1; ++loop)
12075 {
12076 regmatch->rm_ic = ic;
12077 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
12078 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000012079 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
12080 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012081 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
12082 {
12083 if (loop == 0)
12084 num_normal++;
12085 else
12086 (*file)[count++] = vim_strsave((char_u *)names[match]);
12087 }
12088 }
12089 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
12090 opt_idx++)
12091 {
12092 if (options[opt_idx].var == NULL)
12093 continue;
12094 if (xp->xp_context == EXPAND_BOOL_SETTINGS
12095 && !(options[opt_idx].flags & P_BOOL))
12096 continue;
12097 is_term_opt = istermoption(&options[opt_idx]);
12098 if (is_term_opt && num_normal > 0)
12099 continue;
12100 match = FALSE;
12101 if (vim_regexec(regmatch, str, (colnr_T)0)
12102 || (options[opt_idx].shortname != NULL
12103 && vim_regexec(regmatch,
12104 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
12105 match = TRUE;
12106 else if (is_term_opt)
12107 {
12108 name_buf[0] = '<';
12109 name_buf[1] = 't';
12110 name_buf[2] = '_';
12111 name_buf[3] = str[2];
12112 name_buf[4] = str[3];
12113 name_buf[5] = '>';
12114 name_buf[6] = NUL;
12115 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12116 {
12117 match = TRUE;
12118 str = name_buf;
12119 }
12120 }
12121 if (match)
12122 {
12123 if (loop == 0)
12124 {
12125 if (is_term_opt)
12126 num_term++;
12127 else
12128 num_normal++;
12129 }
12130 else
12131 (*file)[count++] = vim_strsave(str);
12132 }
12133 }
12134 /*
12135 * Check terminal key codes, these are not in the option table
12136 */
12137 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
12138 {
12139 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
12140 {
12141 if (!isprint(str[0]) || !isprint(str[1]))
12142 continue;
12143
12144 name_buf[0] = 't';
12145 name_buf[1] = '_';
12146 name_buf[2] = str[0];
12147 name_buf[3] = str[1];
12148 name_buf[4] = NUL;
12149
12150 match = FALSE;
12151 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12152 match = TRUE;
12153 else
12154 {
12155 name_buf[0] = '<';
12156 name_buf[1] = 't';
12157 name_buf[2] = '_';
12158 name_buf[3] = str[0];
12159 name_buf[4] = str[1];
12160 name_buf[5] = '>';
12161 name_buf[6] = NUL;
12162
12163 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12164 match = TRUE;
12165 }
12166 if (match)
12167 {
12168 if (loop == 0)
12169 num_term++;
12170 else
12171 (*file)[count++] = vim_strsave(name_buf);
12172 }
12173 }
12174
12175 /*
12176 * Check special key names.
12177 */
12178 regmatch->rm_ic = TRUE; /* ignore case here */
12179 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
12180 {
12181 name_buf[0] = '<';
12182 STRCPY(name_buf + 1, str);
12183 STRCAT(name_buf, ">");
12184
12185 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12186 {
12187 if (loop == 0)
12188 num_term++;
12189 else
12190 (*file)[count++] = vim_strsave(name_buf);
12191 }
12192 }
12193 }
12194 if (loop == 0)
12195 {
12196 if (num_normal > 0)
12197 *num_file = num_normal;
12198 else if (num_term > 0)
12199 *num_file = num_term;
12200 else
12201 return OK;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020012202 *file = ALLOC_MULT(char_u *, *num_file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012203 if (*file == NULL)
12204 {
12205 *file = (char_u **)"";
12206 return FAIL;
12207 }
12208 }
12209 }
12210 return OK;
12211}
12212
12213 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012214ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012215{
12216 char_u *var = NULL; /* init for GCC */
12217 char_u *buf;
12218
12219 *num_file = 0;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020012220 *file = ALLOC_ONE(char_u *);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012221 if (*file == NULL)
12222 return FAIL;
12223
12224 /*
12225 * For a terminal key code expand_option_idx is < 0.
12226 */
12227 if (expand_option_idx < 0)
12228 {
12229 var = find_termcode(expand_option_name + 2);
12230 if (var == NULL)
12231 expand_option_idx = findoption(expand_option_name);
12232 }
12233
12234 if (expand_option_idx >= 0)
12235 {
12236 /* put string of option value in NameBuff */
12237 option_value2string(&options[expand_option_idx], expand_option_flags);
12238 var = NameBuff;
12239 }
12240 else if (var == NULL)
12241 var = (char_u *)"";
12242
12243 /* A backslash is required before some characters. This is the reverse of
12244 * what happens in do_set(). */
12245 buf = vim_strsave_escaped(var, escape_chars);
12246
12247 if (buf == NULL)
12248 {
Bram Moolenaard23a8232018-02-10 18:45:26 +010012249 VIM_CLEAR(*file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012250 return FAIL;
12251 }
12252
12253#ifdef BACKSLASH_IN_FILENAME
12254 /* For MS-Windows et al. we don't double backslashes at the start and
12255 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012256 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012257 if (var[0] == '\\' && var[1] == '\\'
12258 && expand_option_idx >= 0
12259 && (options[expand_option_idx].flags & P_EXPAND)
12260 && vim_isfilec(var[2])
12261 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000012262 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012263#endif
12264
12265 *file[0] = buf;
12266 *num_file = 1;
12267 return OK;
12268}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012269
12270/*
12271 * Get the value for the numeric or string option *opp in a nice format into
12272 * NameBuff[]. Must not be called with a hidden option!
12273 */
12274 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012275option_value2string(
12276 struct vimoption *opp,
12277 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012278{
12279 char_u *varp;
12280
12281 varp = get_varp_scope(opp, opt_flags);
12282
12283 if (opp->flags & P_NUM)
12284 {
12285 long wc = 0;
12286
12287 if (wc_use_keyname(varp, &wc))
12288 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
12289 else if (wc != 0)
12290 STRCPY(NameBuff, transchar((int)wc));
12291 else
12292 sprintf((char *)NameBuff, "%ld", *(long *)varp);
12293 }
12294 else /* P_STRING */
12295 {
12296 varp = *(char_u **)(varp);
12297 if (varp == NULL) /* just in case */
12298 NameBuff[0] = NUL;
12299#ifdef FEAT_CRYPT
12300 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000012301 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012302 STRCPY(NameBuff, "*****");
12303#endif
12304 else if (opp->flags & P_EXPAND)
12305 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
12306 /* Translate 'pastetoggle' into special key names */
12307 else if ((char_u **)opp->var == &p_pt)
12308 str2specialbuf(p_pt, NameBuff, MAXPATHL);
12309 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000012310 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012311 }
12312}
12313
12314/*
12315 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
12316 * printed as a keyname.
12317 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
12318 */
12319 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012320wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012321{
12322 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
12323 {
12324 *wcp = *(long *)varp;
12325 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
12326 return TRUE;
12327 }
12328 return FALSE;
12329}
12330
Bram Moolenaar01615492015-02-03 13:00:38 +010012331#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012332/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012333 * Any character has an equivalent 'langmap' character. This is used for
12334 * keyboards that have a special language mode that sends characters above
12335 * 128 (although other characters can be translated too). The "to" field is a
12336 * Vim command character. This avoids having to switch the keyboard back to
12337 * ASCII mode when leaving Insert mode.
12338 *
12339 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
12340 * commands.
Bram Moolenaarfc3abf42019-01-24 15:54:21 +010012341 * langmap_mapga.ga_data is a sorted table of langmap_entry_T. This does the
12342 * same as langmap_mapchar[] for characters >= 256.
12343 *
12344 * Use growarray for 'langmap' chars >= 256
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012345 */
12346typedef struct
12347{
12348 int from;
12349 int to;
12350} langmap_entry_T;
12351
12352static garray_T langmap_mapga;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012353
12354/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012355 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
12356 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012357 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012358 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012359langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012360{
12361 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020012362 int a = 0;
12363 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012364
12365 /* Do a binary search for an existing entry. */
12366 while (a != b)
12367 {
12368 int i = (a + b) / 2;
12369 int d = entries[i].from - from;
12370
12371 if (d == 0)
12372 {
12373 entries[i].to = to;
12374 return;
12375 }
12376 if (d < 0)
12377 a = i + 1;
12378 else
12379 b = i;
12380 }
12381
12382 if (ga_grow(&langmap_mapga, 1) != OK)
12383 return; /* out of memory */
12384
12385 /* insert new entry at position "a" */
12386 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
12387 mch_memmove(entries + 1, entries,
12388 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
12389 ++langmap_mapga.ga_len;
12390 entries[0].from = from;
12391 entries[0].to = to;
12392}
12393
12394/*
12395 * Apply 'langmap' to multi-byte character "c" and return the result.
12396 */
12397 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012398langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012399{
12400 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
12401 int a = 0;
12402 int b = langmap_mapga.ga_len;
12403
12404 while (a != b)
12405 {
12406 int i = (a + b) / 2;
12407 int d = entries[i].from - c;
12408
12409 if (d == 0)
12410 return entries[i].to; /* found matching entry */
12411 if (d < 0)
12412 a = i + 1;
12413 else
12414 b = i;
12415 }
12416 return c; /* no entry found, return "c" unmodified */
12417}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012418
12419 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012420langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012421{
12422 int i;
12423
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012424 for (i = 0; i < 256; i++)
12425 langmap_mapchar[i] = i; /* we init with a one-to-one map */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012426 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012427}
12428
12429/*
12430 * Called when langmap option is set; the language map can be
12431 * changed at any time!
12432 */
12433 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012434langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012435{
12436 char_u *p;
12437 char_u *p2;
12438 int from, to;
12439
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012440 ga_clear(&langmap_mapga); /* clear the previous map first */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012441 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012442
12443 for (p = p_langmap; p[0] != NUL; )
12444 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000012445 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012446 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012447 {
12448 if (p2[0] == '\\' && p2[1] != NUL)
12449 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012450 }
12451 if (p2[0] == ';')
12452 ++p2; /* abcd;ABCD form, p2 points to A */
12453 else
12454 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
12455 while (p[0])
12456 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012457 if (p[0] == ',')
12458 {
12459 ++p;
12460 break;
12461 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012462 if (p[0] == '\\' && p[1] != NUL)
12463 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012464 from = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012465 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012466 if (p2 == NULL)
12467 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012468 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012469 if (p[0] != ',')
12470 {
12471 if (p[0] == '\\')
12472 ++p;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012473 to = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012474 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012475 }
12476 else
12477 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012478 if (p2[0] != ',')
12479 {
12480 if (p2[0] == '\\')
12481 ++p2;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012482 to = (*mb_ptr2char)(p2);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012483 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012484 }
12485 if (to == NUL)
12486 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012487 semsg(_("E357: 'langmap': Matching character missing for %s"),
Bram Moolenaar071d4272004-06-13 20:20:40 +000012488 transchar(from));
12489 return;
12490 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012491
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012492 if (from >= 256)
12493 langmap_set_entry(from, to);
12494 else
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012495 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012496
12497 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012498 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012499 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012500 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012501 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012502 if (*p == ';')
12503 {
12504 p = p2;
12505 if (p[0] != NUL)
12506 {
12507 if (p[0] != ',')
12508 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012509 semsg(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012510 return;
12511 }
12512 ++p;
12513 }
12514 break;
12515 }
12516 }
12517 }
12518 }
12519}
12520#endif
12521
12522/*
12523 * Return TRUE if format option 'x' is in effect.
12524 * Take care of no formatting when 'paste' is set.
12525 */
12526 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012527has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012528{
12529 if (p_paste)
12530 return FALSE;
12531 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12532}
12533
12534/*
12535 * Return TRUE if "x" is present in 'shortmess' option, or
12536 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12537 */
12538 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012539shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012540{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012541 return p_shm != NULL &&
12542 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012543 || (vim_strchr(p_shm, 'a') != NULL
12544 && vim_strchr((char_u *)SHM_A, x) != NULL));
12545}
12546
12547/*
12548 * paste_option_changed() - Called after p_paste was set or reset.
12549 */
12550 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012551paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012552{
12553 static int old_p_paste = FALSE;
12554 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012555 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012556#ifdef FEAT_CMDL_INFO
12557 static int save_ru = 0;
12558#endif
12559#ifdef FEAT_RIGHTLEFT
12560 static int save_ri = 0;
12561 static int save_hkmap = 0;
12562#endif
12563 buf_T *buf;
12564
12565 if (p_paste)
12566 {
12567 /*
12568 * Paste switched from off to on.
12569 * Save the current values, so they can be restored later.
12570 */
12571 if (!old_p_paste)
12572 {
12573 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012574 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012575 {
12576 buf->b_p_tw_nopaste = buf->b_p_tw;
12577 buf->b_p_wm_nopaste = buf->b_p_wm;
12578 buf->b_p_sts_nopaste = buf->b_p_sts;
12579 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012580 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012581#ifdef FEAT_VARTABS
12582 if (buf->b_p_vsts_nopaste)
12583 vim_free(buf->b_p_vsts_nopaste);
12584 buf->b_p_vsts_nopaste = buf->b_p_vsts && buf->b_p_vsts != empty_option
12585 ? vim_strsave(buf->b_p_vsts) : NULL;
12586#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012587 }
12588
12589 /* save global options */
12590 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012591 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012592#ifdef FEAT_CMDL_INFO
12593 save_ru = p_ru;
12594#endif
12595#ifdef FEAT_RIGHTLEFT
12596 save_ri = p_ri;
12597 save_hkmap = p_hkmap;
12598#endif
12599 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012600 p_ai_nopaste = p_ai;
12601 p_et_nopaste = p_et;
12602 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012603 p_tw_nopaste = p_tw;
12604 p_wm_nopaste = p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012605#ifdef FEAT_VARTABS
12606 if (p_vsts_nopaste)
12607 vim_free(p_vsts_nopaste);
12608 p_vsts_nopaste = p_vsts && p_vsts != empty_option ? vim_strsave(p_vsts) : NULL;
12609#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012610 }
12611
12612 /*
12613 * Always set the option values, also when 'paste' is set when it is
12614 * already on.
12615 */
12616 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012617 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012618 {
12619 buf->b_p_tw = 0; /* textwidth is 0 */
12620 buf->b_p_wm = 0; /* wrapmargin is 0 */
12621 buf->b_p_sts = 0; /* softtabstop is 0 */
12622 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012623 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012624#ifdef FEAT_VARTABS
12625 if (buf->b_p_vsts)
12626 free_string_option(buf->b_p_vsts);
12627 buf->b_p_vsts = empty_option;
12628 if (buf->b_p_vsts_array)
12629 vim_free(buf->b_p_vsts_array);
12630 buf->b_p_vsts_array = 0;
12631#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012632 }
12633
12634 /* set global options */
12635 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012636 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012637#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012638 if (p_ru)
12639 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012640 p_ru = 0; /* no ruler */
12641#endif
12642#ifdef FEAT_RIGHTLEFT
12643 p_ri = 0; /* no reverse insert */
12644 p_hkmap = 0; /* no Hebrew keyboard */
12645#endif
12646 /* set global values for local buffer options */
12647 p_tw = 0;
12648 p_wm = 0;
12649 p_sts = 0;
12650 p_ai = 0;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012651#ifdef FEAT_VARTABS
12652 if (p_vsts)
12653 free_string_option(p_vsts);
12654 p_vsts = empty_option;
12655#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012656 }
12657
12658 /*
12659 * Paste switched from on to off: Restore saved values.
12660 */
12661 else if (old_p_paste)
12662 {
12663 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012664 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012665 {
12666 buf->b_p_tw = buf->b_p_tw_nopaste;
12667 buf->b_p_wm = buf->b_p_wm_nopaste;
12668 buf->b_p_sts = buf->b_p_sts_nopaste;
12669 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012670 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012671#ifdef FEAT_VARTABS
12672 if (buf->b_p_vsts)
12673 free_string_option(buf->b_p_vsts);
12674 buf->b_p_vsts = buf->b_p_vsts_nopaste
12675 ? vim_strsave(buf->b_p_vsts_nopaste) : empty_option;
12676 if (buf->b_p_vsts_array)
12677 vim_free(buf->b_p_vsts_array);
12678 if (buf->b_p_vsts && buf->b_p_vsts != empty_option)
12679 tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array);
12680 else
12681 buf->b_p_vsts_array = 0;
12682#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012683 }
12684
12685 /* restore global options */
12686 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012687 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012688#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012689 if (p_ru != save_ru)
12690 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012691 p_ru = save_ru;
12692#endif
12693#ifdef FEAT_RIGHTLEFT
12694 p_ri = save_ri;
12695 p_hkmap = save_hkmap;
12696#endif
12697 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012698 p_ai = p_ai_nopaste;
12699 p_et = p_et_nopaste;
12700 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012701 p_tw = p_tw_nopaste;
12702 p_wm = p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012703#ifdef FEAT_VARTABS
12704 if (p_vsts)
12705 free_string_option(p_vsts);
12706 p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option;
12707#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012708 }
12709
12710 old_p_paste = p_paste;
12711}
12712
12713/*
12714 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12715 *
12716 * Reset 'compatible' and set the values for options that didn't get set yet
12717 * to the Vim defaults.
12718 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012719 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012720 */
12721 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012722vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012723{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012724 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012725 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012726 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012727
12728 if (!option_was_set((char_u *)"cp"))
12729 {
12730 p_cp = FALSE;
12731 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12732 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12733 set_option_default(opt_idx, OPT_FREE, FALSE);
12734 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012735 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012736 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012737
12738 if (fname != NULL)
12739 {
12740 p = vim_getenv(envname, &dofree);
12741 if (p == NULL)
12742 {
12743 /* Set $MYVIMRC to the first vimrc file found. */
12744 p = FullName_save(fname, FALSE);
12745 if (p != NULL)
12746 {
12747 vim_setenv(envname, p);
12748 vim_free(p);
12749 }
12750 }
12751 else if (dofree)
12752 vim_free(p);
12753 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012754}
12755
12756/*
12757 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12758 */
12759 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012760change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012761{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012762 int opt_idx;
12763
Bram Moolenaar071d4272004-06-13 20:20:40 +000012764 if (p_cp != on)
12765 {
12766 p_cp = on;
12767 compatible_set();
12768 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012769 opt_idx = findoption((char_u *)"cp");
12770 if (opt_idx >= 0)
12771 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012772}
12773
12774/*
12775 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012776 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012777 */
12778 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012779option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012780{
12781 int idx;
12782
12783 idx = findoption(name);
12784 if (idx < 0) /* unknown option */
12785 return FALSE;
12786 if (options[idx].flags & P_WAS_SET)
12787 return TRUE;
12788 return FALSE;
12789}
12790
12791/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012792 * Reset the flag indicating option "name" was set.
12793 */
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012794 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012795reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012796{
12797 int idx = findoption(name);
12798
12799 if (idx >= 0)
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012800 {
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012801 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012802 return OK;
12803 }
12804 return FAIL;
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012805}
12806
12807/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012808 * compatible_set() - Called when 'compatible' has been set or unset.
12809 *
12810 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12811 * flag) to a Vi compatible value.
12812 * When 'compatible' is unset: Set all options that have a different default
12813 * for Vim (without the P_VI_DEF flag) to that default.
12814 */
12815 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012816compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012817{
12818 int opt_idx;
12819
12820 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12821 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12822 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12823 set_option_default(opt_idx, OPT_FREE, p_cp);
12824 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012825 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012826}
12827
12828#ifdef FEAT_LINEBREAK
12829
Bram Moolenaar071d4272004-06-13 20:20:40 +000012830/*
12831 * fill_breakat_flags() -- called when 'breakat' changes value.
12832 */
12833 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012834fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012835{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012836 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012837 int i;
12838
12839 for (i = 0; i < 256; i++)
12840 breakat_flags[i] = FALSE;
12841
12842 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012843 for (p = p_breakat; *p; p++)
12844 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012845}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012846#endif
12847
12848/*
12849 * Check an option that can be a range of string values.
12850 *
12851 * Return OK for correct value, FAIL otherwise.
12852 * Empty is always OK.
12853 */
12854 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012855check_opt_strings(
12856 char_u *val,
12857 char **values,
12858 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012859{
12860 return opt_strings_flags(val, values, NULL, list);
12861}
12862
12863/*
12864 * Handle an option that can be a range of string values.
12865 * Set a flag in "*flagp" for each string present.
12866 *
12867 * Return OK for correct value, FAIL otherwise.
12868 * Empty is always OK.
12869 */
12870 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012871opt_strings_flags(
12872 char_u *val, /* new value */
12873 char **values, /* array of valid string values */
12874 unsigned *flagp,
12875 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012876{
12877 int i;
12878 int len;
12879 unsigned new_flags = 0;
12880
12881 while (*val)
12882 {
12883 for (i = 0; ; ++i)
12884 {
12885 if (values[i] == NULL) /* val not found in values[] */
12886 return FAIL;
12887
12888 len = (int)STRLEN(values[i]);
12889 if (STRNCMP(values[i], val, len) == 0
12890 && ((list && val[len] == ',') || val[len] == NUL))
12891 {
12892 val += len + (val[len] == ',');
12893 new_flags |= (1 << i);
12894 break; /* check next item in val list */
12895 }
12896 }
12897 }
12898 if (flagp != NULL)
12899 *flagp = new_flags;
12900
12901 return OK;
12902}
12903
12904/*
12905 * Read the 'wildmode' option, fill wim_flags[].
12906 */
12907 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012908check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012909{
12910 char_u new_wim_flags[4];
12911 char_u *p;
12912 int i;
12913 int idx = 0;
12914
12915 for (i = 0; i < 4; ++i)
12916 new_wim_flags[i] = 0;
12917
12918 for (p = p_wim; *p; ++p)
12919 {
12920 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12921 ;
12922 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12923 return FAIL;
12924 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12925 new_wim_flags[idx] |= WIM_LONGEST;
12926 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12927 new_wim_flags[idx] |= WIM_FULL;
12928 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12929 new_wim_flags[idx] |= WIM_LIST;
12930 else
12931 return FAIL;
12932 p += i;
12933 if (*p == NUL)
12934 break;
12935 if (*p == ',')
12936 {
12937 if (idx == 3)
12938 return FAIL;
12939 ++idx;
12940 }
12941 }
12942
12943 /* fill remaining entries with last flag */
12944 while (idx < 3)
12945 {
12946 new_wim_flags[idx + 1] = new_wim_flags[idx];
12947 ++idx;
12948 }
12949
12950 /* only when there are no errors, wim_flags[] is changed */
12951 for (i = 0; i < 4; ++i)
12952 wim_flags[i] = new_wim_flags[i];
12953 return OK;
12954}
12955
12956/*
12957 * Check if backspacing over something is allowed.
12958 */
12959 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012960can_bs(
12961 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012962{
Bram Moolenaar6b810d92018-06-04 17:28:44 +020012963#ifdef FEAT_JOB_CHANNEL
12964 if (what == BS_START && bt_prompt(curbuf))
12965 return FALSE;
12966#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012967 switch (*p_bs)
12968 {
12969 case '2': return TRUE;
12970 case '1': return (what != BS_START);
12971 case '0': return FALSE;
12972 }
12973 return vim_strchr(p_bs, what) != NULL;
12974}
12975
12976/*
12977 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12978 * the file must be considered changed when the value is different.
12979 */
12980 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012981save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012982{
12983 buf->b_start_ffc = *buf->b_p_ff;
12984 buf->b_start_eol = buf->b_p_eol;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012985 buf->b_start_bomb = buf->b_p_bomb;
12986
Bram Moolenaar071d4272004-06-13 20:20:40 +000012987 /* Only use free/alloc when necessary, they take time. */
12988 if (buf->b_start_fenc == NULL
12989 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12990 {
12991 vim_free(buf->b_start_fenc);
12992 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12993 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012994}
12995
12996/*
12997 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12998 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012999 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
13000 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020013001 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010013002 * When "ignore_empty" is true don't consider a new, empty buffer to be
13003 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000013004 */
13005 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013006file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000013007{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000013008 /* In a buffer that was never loaded the options are not valid. */
13009 if (buf->b_flags & BF_NEVERLOADED)
13010 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010013011 if (ignore_empty
13012 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000013013 && buf->b_ml.ml_line_count == 1
13014 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
13015 return FALSE;
13016 if (buf->b_start_ffc != *buf->b_p_ff)
13017 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020013018 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000013019 return TRUE;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000013020 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
13021 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000013022 if (buf->b_start_fenc == NULL)
13023 return (*buf->b_p_fenc != NUL);
13024 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +000013025}
13026
13027/*
13028 * return OK if "p" is a valid fileformat name, FAIL otherwise.
13029 */
13030 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013031check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000013032{
13033 return check_opt_strings(p, p_ff_values, FALSE);
13034}
Bram Moolenaar14f24742012-08-08 18:01:05 +020013035
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010013036#if defined(FEAT_VARTABS) || defined(PROTO)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013037
13038/*
13039 * Set the integer values corresponding to the string setting of 'vartabstop'.
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010013040 * "array" will be set, caller must free it if needed.
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013041 */
13042 int
13043tabstop_set(char_u *var, int **array)
13044{
13045 int valcount = 1;
13046 int t;
13047 char_u *cp;
13048
Bram Moolenaar64f41072018-10-15 22:51:50 +020013049 if (var[0] == NUL || (var[0] == '0' && var[1] == NUL))
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013050 {
13051 *array = NULL;
13052 return TRUE;
13053 }
13054
Bram Moolenaar64f41072018-10-15 22:51:50 +020013055 for (cp = var; *cp != NUL; ++cp)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013056 {
Bram Moolenaar64f41072018-10-15 22:51:50 +020013057 if (cp == var || cp[-1] == ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013058 {
13059 char_u *end;
Bram Moolenaar64f41072018-10-15 22:51:50 +020013060
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013061 if (strtol((char *)cp, (char **)&end, 10) <= 0)
13062 {
13063 if (cp != end)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010013064 emsg(_(e_positive));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013065 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010013066 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013067 return FALSE;
13068 }
13069 }
13070
13071 if (VIM_ISDIGIT(*cp))
13072 continue;
Bram Moolenaar64f41072018-10-15 22:51:50 +020013073 if (cp[0] == ',' && cp > var && cp[-1] != ',' && cp[1] != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013074 {
13075 ++valcount;
13076 continue;
13077 }
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010013078 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013079 return FALSE;
13080 }
13081
Bram Moolenaarc799fe22019-05-28 23:08:19 +020013082 *array = ALLOC_MULT(int, valcount + 1);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010013083 if (*array == NULL)
13084 return FALSE;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013085 (*array)[0] = valcount;
13086
13087 t = 1;
Bram Moolenaar64f41072018-10-15 22:51:50 +020013088 for (cp = var; *cp != NUL;)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013089 {
13090 (*array)[t++] = atoi((char *)cp);
Bram Moolenaar64f41072018-10-15 22:51:50 +020013091 while (*cp != NUL && *cp != ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013092 ++cp;
Bram Moolenaar64f41072018-10-15 22:51:50 +020013093 if (*cp != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013094 ++cp;
13095 }
13096
13097 return TRUE;
13098}
13099
13100/*
13101 * Calculate the number of screen spaces a tab will occupy.
13102 * If "vts" is set then the tab widths are taken from that array,
13103 * otherwise the value of ts is used.
13104 */
13105 int
13106tabstop_padding(colnr_T col, int ts_arg, int *vts)
13107{
13108 int ts = ts_arg == 0 ? 8 : ts_arg;
13109 int tabcount;
13110 colnr_T tabcol = 0;
13111 int t;
13112 int padding = 0;
13113
13114 if (vts == NULL || vts[0] == 0)
13115 return ts - (col % ts);
13116
13117 tabcount = vts[0];
13118
13119 for (t = 1; t <= tabcount; ++t)
13120 {
13121 tabcol += vts[t];
13122 if (tabcol > col)
13123 {
13124 padding = (int)(tabcol - col);
13125 break;
13126 }
13127 }
13128 if (t > tabcount)
13129 padding = vts[tabcount] - (int)((col - tabcol) % vts[tabcount]);
13130
13131 return padding;
13132}
13133
13134/*
13135 * Find the size of the tab that covers a particular column.
13136 */
13137 int
13138tabstop_at(colnr_T col, int ts, int *vts)
13139{
13140 int tabcount;
13141 colnr_T tabcol = 0;
13142 int t;
13143 int tab_size = 0;
13144
13145 if (vts == 0 || vts[0] == 0)
13146 return ts;
13147
13148 tabcount = vts[0];
13149 for (t = 1; t <= tabcount; ++t)
13150 {
13151 tabcol += vts[t];
13152 if (tabcol > col)
13153 {
13154 tab_size = vts[t];
13155 break;
13156 }
13157 }
13158 if (t > tabcount)
13159 tab_size = vts[tabcount];
13160
13161 return tab_size;
13162}
13163
13164/*
13165 * Find the column on which a tab starts.
13166 */
13167 colnr_T
13168tabstop_start(colnr_T col, int ts, int *vts)
13169{
13170 int tabcount;
13171 colnr_T tabcol = 0;
13172 int t;
13173 int excess;
13174
Bram Moolenaar0119a592018-06-24 23:53:28 +020013175 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013176 return (col / ts) * ts;
13177
13178 tabcount = vts[0];
13179 for (t = 1; t <= tabcount; ++t)
13180 {
13181 tabcol += vts[t];
13182 if (tabcol > col)
13183 return tabcol - vts[t];
13184 }
13185
13186 excess = tabcol % vts[tabcount];
13187 return excess + ((col - excess) / vts[tabcount]) * vts[tabcount];
13188}
13189
13190/*
13191 * Find the number of tabs and spaces necessary to get from one column
13192 * to another.
13193 */
13194 void
13195tabstop_fromto(
13196 colnr_T start_col,
13197 colnr_T end_col,
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013198 int ts_arg,
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013199 int *vts,
13200 int *ntabs,
13201 int *nspcs)
13202{
13203 int spaces = end_col - start_col;
13204 colnr_T tabcol = 0;
13205 int padding = 0;
13206 int tabcount;
13207 int t;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013208 int ts = ts_arg == 0 ? curbuf->b_p_ts : ts_arg;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013209
Bram Moolenaar0119a592018-06-24 23:53:28 +020013210 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013211 {
13212 int tabs = 0;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013213 int initspc = 0;
Bram Moolenaar0119a592018-06-24 23:53:28 +020013214
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013215 initspc = ts - (start_col % ts);
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013216 if (spaces >= initspc)
13217 {
13218 spaces -= initspc;
13219 tabs++;
13220 }
13221 tabs += spaces / ts;
13222 spaces -= (spaces / ts) * ts;
13223
13224 *ntabs = tabs;
13225 *nspcs = spaces;
13226 return;
13227 }
13228
13229 /* Find the padding needed to reach the next tabstop. */
13230 tabcount = vts[0];
13231 for (t = 1; t <= tabcount; ++t)
13232 {
13233 tabcol += vts[t];
13234 if (tabcol > start_col)
13235 {
13236 padding = (int)(tabcol - start_col);
13237 break;
13238 }
13239 }
13240 if (t > tabcount)
13241 padding = vts[tabcount] - (int)((start_col - tabcol) % vts[tabcount]);
13242
13243 /* If the space needed is less than the padding no tabs can be used. */
13244 if (spaces < padding)
13245 {
13246 *ntabs = 0;
13247 *nspcs = spaces;
13248 return;
13249 }
13250
13251 *ntabs = 1;
13252 spaces -= padding;
13253
13254 /* At least one tab has been used. See if any more will fit. */
13255 while (spaces != 0 && ++t <= tabcount)
13256 {
13257 padding = vts[t];
13258 if (spaces < padding)
13259 {
13260 *nspcs = spaces;
13261 return;
13262 }
13263 ++*ntabs;
13264 spaces -= padding;
13265 }
13266
13267 *ntabs += spaces / vts[tabcount];
13268 *nspcs = spaces % vts[tabcount];
13269}
13270
13271/*
13272 * See if two tabstop arrays contain the same values.
13273 */
13274 int
13275tabstop_eq(int *ts1, int *ts2)
13276{
13277 int t;
13278
13279 if ((ts1 == 0 && ts2) || (ts1 && ts2 == 0))
13280 return FALSE;
13281 if (ts1 == ts2)
13282 return TRUE;
13283 if (ts1[0] != ts2[0])
13284 return FALSE;
13285
13286 for (t = 1; t <= ts1[0]; ++t)
13287 if (ts1[t] != ts2[t])
13288 return FALSE;
13289
13290 return TRUE;
13291}
13292
Bram Moolenaar113e1072019-01-20 15:30:40 +010013293#if defined(FEAT_BEVAL) || defined(PROTO)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013294/*
13295 * Copy a tabstop array, allocating space for the new array.
13296 */
13297 int *
13298tabstop_copy(int *oldts)
13299{
13300 int *newts;
13301 int t;
13302
Bram Moolenaar6ee96582019-04-27 22:06:37 +020013303 if (oldts == NULL)
13304 return NULL;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020013305 newts = ALLOC_MULT(int, oldts[0] + 1);
Bram Moolenaar6ee96582019-04-27 22:06:37 +020013306 if (newts != NULL)
13307 for (t = 0; t <= oldts[0]; ++t)
13308 newts[t] = oldts[t];
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013309 return newts;
13310}
Bram Moolenaar113e1072019-01-20 15:30:40 +010013311#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013312
13313/*
13314 * Return a count of the number of tabstops.
13315 */
13316 int
13317tabstop_count(int *ts)
13318{
13319 return ts != NULL ? ts[0] : 0;
13320}
13321
13322/*
13323 * Return the first tabstop, or 8 if there are no tabstops defined.
13324 */
13325 int
13326tabstop_first(int *ts)
13327{
13328 return ts != NULL ? ts[1] : 8;
13329}
13330
13331#endif
13332
Bram Moolenaar14f24742012-08-08 18:01:05 +020013333/*
13334 * Return the effective shiftwidth value for current buffer, using the
13335 * 'tabstop' value when 'shiftwidth' is zero.
13336 */
13337 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013338get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020013339{
Bram Moolenaarf9514162018-11-22 03:08:29 +010013340 return get_sw_value_col(buf, 0);
13341}
13342
13343/*
13344 * Idem, using the first non-black in the current line.
13345 */
13346 long
13347get_sw_value_indent(buf_T *buf)
13348{
13349 pos_T pos = curwin->w_cursor;
13350
13351 pos.col = getwhitecols_curline();
13352 return get_sw_value_pos(buf, &pos);
13353}
13354
13355/*
13356 * Idem, using "pos".
13357 */
13358 long
13359get_sw_value_pos(buf_T *buf, pos_T *pos)
13360{
13361 pos_T save_cursor = curwin->w_cursor;
13362 long sw_value;
13363
13364 curwin->w_cursor = *pos;
13365 sw_value = get_sw_value_col(buf, get_nolist_virtcol());
13366 curwin->w_cursor = save_cursor;
13367 return sw_value;
13368}
13369
13370/*
13371 * Idem, using virtual column "col".
13372 */
13373 long
13374get_sw_value_col(buf_T *buf, colnr_T col UNUSED)
13375{
13376 return buf->b_p_sw ? buf->b_p_sw :
13377 #ifdef FEAT_VARTABS
13378 tabstop_at(col, buf->b_p_ts, buf->b_p_vts_array);
13379 #else
13380 buf->b_p_ts;
13381 #endif
Bram Moolenaar14f24742012-08-08 18:01:05 +020013382}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013383
13384/*
13385 * Return the effective softtabstop value for the current buffer, using the
Bram Moolenaar33d5ab32018-07-02 20:51:24 +020013386 * 'shiftwidth' value when 'softtabstop' is negative.
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013387 */
13388 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013389get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013390{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010013391 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013392}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013393
13394/*
Bram Moolenaar375e3392019-01-31 18:26:10 +010013395 * Return the effective 'scrolloff' value for the current window, using the
13396 * global value when appropriate.
13397 */
13398 long
13399get_scrolloff_value(void)
13400{
13401 return curwin->w_p_so < 0 ? p_so : curwin->w_p_so;
13402}
13403
13404/*
13405 * Return the effective 'sidescrolloff' value for the current window, using the
13406 * global value when appropriate.
13407 */
13408 long
13409get_sidescrolloff_value(void)
13410{
13411 return curwin->w_p_siso < 0 ? p_siso : curwin->w_p_siso;
13412}
13413
13414/*
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013415 * Check matchpairs option for "*initc".
13416 * If there is a match set "*initc" to the matching character and "*findc" to
13417 * the opposite character. Set "*backwards" to the direction.
13418 * When "switchit" is TRUE swap the direction.
13419 */
13420 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010013421find_mps_values(
13422 int *initc,
13423 int *findc,
13424 int *backwards,
13425 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013426{
13427 char_u *ptr;
13428
13429 ptr = curbuf->b_p_mps;
13430 while (*ptr != NUL)
13431 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013432 if (has_mbyte)
13433 {
13434 char_u *prev;
13435
13436 if (mb_ptr2char(ptr) == *initc)
13437 {
13438 if (switchit)
13439 {
13440 *findc = *initc;
13441 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13442 *backwards = TRUE;
13443 }
13444 else
13445 {
13446 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13447 *backwards = FALSE;
13448 }
13449 return;
13450 }
13451 prev = ptr;
13452 ptr += mb_ptr2len(ptr) + 1;
13453 if (mb_ptr2char(ptr) == *initc)
13454 {
13455 if (switchit)
13456 {
13457 *findc = *initc;
13458 *initc = mb_ptr2char(prev);
13459 *backwards = FALSE;
13460 }
13461 else
13462 {
13463 *findc = mb_ptr2char(prev);
13464 *backwards = TRUE;
13465 }
13466 return;
13467 }
13468 ptr += mb_ptr2len(ptr);
13469 }
13470 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013471 {
13472 if (*ptr == *initc)
13473 {
13474 if (switchit)
13475 {
13476 *backwards = TRUE;
13477 *findc = *initc;
13478 *initc = ptr[2];
13479 }
13480 else
13481 {
13482 *backwards = FALSE;
13483 *findc = ptr[2];
13484 }
13485 return;
13486 }
13487 ptr += 2;
13488 if (*ptr == *initc)
13489 {
13490 if (switchit)
13491 {
13492 *backwards = FALSE;
13493 *findc = *initc;
13494 *initc = ptr[-2];
13495 }
13496 else
13497 {
13498 *backwards = TRUE;
13499 *findc = ptr[-2];
13500 }
13501 return;
13502 }
13503 ++ptr;
13504 }
13505 if (*ptr == ',')
13506 ++ptr;
13507 }
13508}
Bram Moolenaar597a4222014-06-25 14:39:50 +020013509
13510#if defined(FEAT_LINEBREAK) || defined(PROTO)
13511/*
13512 * This is called when 'breakindentopt' is changed and when a window is
13513 * initialized.
13514 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013515 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013516briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020013517{
13518 char_u *p;
13519 int bri_shift = 0;
13520 long bri_min = 20;
13521 int bri_sbr = FALSE;
13522
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013523 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013524 while (*p != NUL)
13525 {
13526 if (STRNCMP(p, "shift:", 6) == 0
13527 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
13528 {
13529 p += 6;
13530 bri_shift = getdigits(&p);
13531 }
13532 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
13533 {
13534 p += 4;
13535 bri_min = getdigits(&p);
13536 }
13537 else if (STRNCMP(p, "sbr", 3) == 0)
13538 {
13539 p += 3;
13540 bri_sbr = TRUE;
13541 }
13542 if (*p != ',' && *p != NUL)
13543 return FAIL;
13544 if (*p == ',')
13545 ++p;
13546 }
13547
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013548 wp->w_p_brishift = bri_shift;
13549 wp->w_p_brimin = bri_min;
13550 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013551
13552 return OK;
13553}
13554#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013555
13556/*
13557 * Get the local or global value of 'backupcopy'.
13558 */
13559 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013560get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013561{
13562 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
13563}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020013564
13565#if defined(FEAT_SIGNS) || defined(PROTO)
13566/*
13567 * Return TRUE when window "wp" has a column to draw signs in.
13568 */
13569 int
13570signcolumn_on(win_T *wp)
13571{
Bram Moolenaar394c5d82019-06-17 21:48:05 +020013572 // If 'signcolumn' is set to 'number', signs are displayed in the 'number'
13573 // column (if present). Otherwise signs are to be displayed in the sign
13574 // column.
13575 if (*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
13576 return wp->w_buffer->b_signlist != NULL && !wp->w_p_nu && !wp->w_p_rnu;
13577
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020013578 if (*wp->w_p_scl == 'n')
13579 return FALSE;
13580 if (*wp->w_p_scl == 'y')
13581 return TRUE;
13582 return (wp->w_buffer->b_signlist != NULL
13583# ifdef FEAT_NETBEANS_INTG
13584 || wp->w_buffer->b_has_sign_column
13585# endif
13586 );
13587}
13588#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013589
13590#if defined(FEAT_EVAL) || defined(PROTO)
13591/*
13592 * Get window or buffer local options.
13593 */
13594 dict_T *
13595get_winbuf_options(int bufopt)
13596{
13597 dict_T *d;
13598 int opt_idx;
13599
13600 d = dict_alloc();
13601 if (d == NULL)
13602 return NULL;
13603
13604 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
13605 {
13606 struct vimoption *opt = &options[opt_idx];
13607
13608 if ((bufopt && (opt->indir & PV_BUF))
13609 || (!bufopt && (opt->indir & PV_WIN)))
13610 {
13611 char_u *varp = get_varp(opt);
13612
13613 if (varp != NULL)
13614 {
13615 if (opt->flags & P_STRING)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013616 dict_add_string(d, opt->fullname, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020013617 else if (opt->flags & P_NUM)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013618 dict_add_number(d, opt->fullname, *(long *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013619 else
Bram Moolenaare0be1672018-07-08 16:50:37 +020013620 dict_add_number(d, opt->fullname, *(int *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013621 }
13622 }
13623 }
13624
13625 return d;
13626}
13627#endif