blob: 8d9b5783ff33bf461585fb4748d3f2abd563c4f2 [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,
Bram Moolenaar36e4d982019-08-20 21:12:16 +0200897#if defined(FEAT_TEXT_PROP) && defined(FEAT_QUICKFIX)
Bram Moolenaar62a0cb42019-08-18 16:35:23 +0200898 (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 Moolenaar5843f5f2019-08-20 20:13:45 +02003280#ifdef FEAT_STL_OPT
3281static char *check_stl_option(char_u *s);
3282#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003283#ifdef FEAT_CLIPBOARD
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003284static char *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003285#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003286#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003287static char *did_set_spell_option(int is_spellfile);
3288static char *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003289#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003290#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003291static void set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003292#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003293static char *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3294static 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 +01003295static void check_redraw(long_u flags);
3296static int findoption(char_u *);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02003297static int find_key_option(char_u *arg_arg, int has_lt);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003298static void showoptions(int all, int opt_flags);
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02003299static int optval_default(struct vimoption *, char_u *varp, int compatible);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003300static void showoneopt(struct vimoption *, int opt_flags);
Bram Moolenaared18f2c2019-01-24 20:30:52 +01003301static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, long_u flags);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003302static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3303static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3304static int istermoption(struct vimoption *);
3305static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3306static char_u *get_varp(struct vimoption *);
Bram Moolenaar5843f5f2019-08-20 20:13:45 +02003307static void check_win_options(win_T *win);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003308static void option_value2string(struct vimoption *, int opt_flags);
3309static void check_winopt(winopt_T *wop);
3310static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003311#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003312static void langmap_init(void);
3313static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003314#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003315static void paste_option_changed(void);
3316static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003317#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003318static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003319#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003320static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3321static int check_opt_strings(char_u *val, char **values, int);
3322static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003323#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003324static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003325#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003326
3327/*
3328 * Initialize the options, first part.
3329 *
3330 * Called only once from main(), just after creating the first buffer.
Bram Moolenaar07268702018-03-01 21:57:32 +01003331 * If "clean_arg" is TRUE Vim was started with --clean.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003332 */
3333 void
Bram Moolenaar07268702018-03-01 21:57:32 +01003334set_init_1(int clean_arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003335{
3336 char_u *p;
3337 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003338 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003339
3340#ifdef FEAT_LANGMAP
3341 langmap_init();
3342#endif
3343
3344 /* Be Vi compatible by default */
3345 p_cp = TRUE;
3346
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003347 /* Use POSIX compatibility when $VIM_POSIX is set. */
3348 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003349 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003350 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar9dfa3132019-05-04 21:08:40 +02003351 set_string_default("shm", (char_u *)SHM_POSIX);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003352 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003353
Bram Moolenaar071d4272004-06-13 20:20:40 +00003354 /*
3355 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003356 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003357 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003358 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003359#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003360 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003361 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003362#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003363 )
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003364 set_string_default_esc("sh", p, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003365
3366#ifdef FEAT_WILDIGN
3367 /*
3368 * Set the default for 'backupskip' to include environment variables for
3369 * temp files.
3370 */
3371 {
3372# ifdef UNIX
3373 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3374# else
3375 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3376# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003377 int len;
3378 garray_T ga;
3379 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003380
3381 ga_init2(&ga, 1, 100);
3382 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3383 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003384 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003385# ifdef UNIX
3386 if (*names[n] == NUL)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003387# ifdef MACOS_X
3388 p = (char_u *)"/private/tmp";
3389# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003390 p = (char_u *)"/tmp";
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003391# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003392 else
3393# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003394 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003395 if (p != NULL && *p != NUL)
3396 {
3397 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003398 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003399 if (ga_grow(&ga, len) == OK)
3400 {
3401 if (ga.ga_len > 0)
3402 STRCAT(ga.ga_data, ",");
3403 STRCAT(ga.ga_data, p);
3404 add_pathsep(ga.ga_data);
3405 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003406 ga.ga_len += len;
3407 }
3408 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003409 if (mustfree)
3410 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003411 }
3412 if (ga.ga_data != NULL)
3413 {
3414 set_string_default("bsk", ga.ga_data);
3415 vim_free(ga.ga_data);
3416 }
3417 }
3418#endif
3419
3420 /*
3421 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3422 */
3423 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003424 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003425 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003426#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3427 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3428#endif
3429 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003430#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003431 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003432 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003433#else
3434# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003435 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003436 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003437# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003438 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003439# endif
3440#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003441 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003442 opt_idx = findoption((char_u *)"maxmem");
3443 if (opt_idx >= 0)
3444 {
3445#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003446 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3447 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003448#endif
3449 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3450 }
3451 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003452 }
3453
Bram Moolenaar071d4272004-06-13 20:20:40 +00003454#ifdef FEAT_SEARCHPATH
3455 {
3456 char_u *cdpath;
3457 char_u *buf;
3458 int i;
3459 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003460 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003461
3462 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003463 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003464 if (cdpath != NULL)
3465 {
Bram Moolenaar964b3742019-05-24 18:54:09 +02003466 buf = alloc((STRLEN(cdpath) << 1) + 2);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003467 if (buf != NULL)
3468 {
3469 buf[0] = ','; /* start with ",", current dir first */
3470 j = 1;
3471 for (i = 0; cdpath[i] != NUL; ++i)
3472 {
3473 if (vim_ispathlistsep(cdpath[i]))
3474 buf[j++] = ',';
3475 else
3476 {
3477 if (cdpath[i] == ' ' || cdpath[i] == ',')
3478 buf[j++] = '\\';
3479 buf[j++] = cdpath[i];
3480 }
3481 }
3482 buf[j] = NUL;
3483 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003484 if (opt_idx >= 0)
3485 {
3486 options[opt_idx].def_val[VI_DEFAULT] = buf;
3487 options[opt_idx].flags |= P_DEF_ALLOCED;
3488 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003489 else
3490 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003491 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003492 if (mustfree)
3493 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003494 }
3495 }
3496#endif
3497
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003498#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003499 /* Set print encoding on platforms that don't default to latin1 */
3500 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003501# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003502 (char_u *)"cp1252"
3503# else
3504# ifdef VMS
3505 (char_u *)"dec-mcs"
3506# else
3507# ifdef EBCDIC
3508 (char_u *)"ebcdic-uk"
3509# else
3510# ifdef MAC
3511 (char_u *)"mac-roman"
3512# else /* HPUX */
3513 (char_u *)"hp-roman8"
3514# endif
3515# endif
3516# endif
3517# endif
3518 );
3519#endif
3520
3521#ifdef FEAT_POSTSCRIPT
3522 /* 'printexpr' must be allocated to be able to evaluate it. */
3523 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003524# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003525 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003526# else
3527# ifdef VMS
3528 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3529
3530# else
3531 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3532# endif
3533# endif
3534 );
3535#endif
3536
3537 /*
3538 * Set all the options (except the terminal options) to their default
3539 * value. Also set the global value for local options.
3540 */
3541 set_options_default(0);
3542
Bram Moolenaar07268702018-03-01 21:57:32 +01003543#ifdef CLEAN_RUNTIMEPATH
3544 if (clean_arg)
3545 {
3546 opt_idx = findoption((char_u *)"runtimepath");
3547 if (opt_idx >= 0)
3548 {
3549 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3550 p_rtp = (char_u *)CLEAN_RUNTIMEPATH;
3551 }
3552 opt_idx = findoption((char_u *)"packpath");
3553 if (opt_idx >= 0)
3554 {
3555 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3556 p_pp = (char_u *)CLEAN_RUNTIMEPATH;
3557 }
3558 }
3559#endif
3560
Bram Moolenaar071d4272004-06-13 20:20:40 +00003561#ifdef FEAT_GUI
3562 if (found_reverse_arg)
3563 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3564#endif
3565
3566 curbuf->b_p_initialized = TRUE;
3567 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003568 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003569 check_buf_options(curbuf);
3570 check_win_options(curwin);
3571 check_options();
3572
3573 /* Must be before option_expand(), because that one needs vim_isIDc() */
3574 didset_options();
3575
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003576#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003577 /* Use the current chartab for the generic chartab. This is not in
3578 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003579 init_spell_chartab();
3580#endif
3581
Bram Moolenaar071d4272004-06-13 20:20:40 +00003582 /*
3583 * Expand environment variables and things like "~" for the defaults.
3584 * If option_expand() returns non-NULL the variable is expanded. This can
3585 * only happen for non-indirect options.
3586 * Also set the default to the expanded value, so ":set" does not list
3587 * them.
3588 * Don't set the P_ALLOCED flag, because we don't want to free the
3589 * default.
3590 */
3591 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3592 {
3593 if ((options[opt_idx].flags & P_GETTEXT)
3594 && options[opt_idx].var != NULL)
3595 p = (char_u *)_(*(char **)options[opt_idx].var);
3596 else
3597 p = option_expand(opt_idx, NULL);
3598 if (p != NULL && (p = vim_strsave(p)) != NULL)
3599 {
3600 *(char_u **)options[opt_idx].var = p;
3601 /* VIMEXP
3602 * Defaults for all expanded options are currently the same for Vi
3603 * and Vim. When this changes, add some code here! Also need to
3604 * split P_DEF_ALLOCED in two.
3605 */
3606 if (options[opt_idx].flags & P_DEF_ALLOCED)
3607 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3608 options[opt_idx].def_val[VI_DEFAULT] = p;
3609 options[opt_idx].flags |= P_DEF_ALLOCED;
3610 }
3611 }
3612
Bram Moolenaar071d4272004-06-13 20:20:40 +00003613 save_file_ff(curbuf); /* Buffer is unchanged */
3614
Bram Moolenaar071d4272004-06-13 20:20:40 +00003615#if defined(FEAT_ARABIC)
3616 /* Detect use of mlterm.
3617 * Mlterm is a terminal emulator akin to xterm that has some special
3618 * abilities (bidi namely).
3619 * NOTE: mlterm's author is being asked to 'set' a variable
3620 * instead of an environment variable due to inheritance.
3621 */
3622 if (mch_getenv((char_u *)"MLTERM") != NULL)
3623 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3624#endif
3625
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003626 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003627
Bram Moolenaar4f974752019-02-17 17:44:42 +01003628# if defined(MSWIN) && defined(FEAT_GETTEXT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003629 /*
3630 * If $LANG isn't set, try to get a good value for it. This makes the
3631 * right language be used automatically. Don't do this for English.
3632 */
3633 if (mch_getenv((char_u *)"LANG") == NULL)
3634 {
3635 char buf[20];
3636
3637 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3638 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3639 * only the first two. */
3640 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3641 (LPTSTR)buf, 20);
3642 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3643 {
3644 /* There are a few exceptions (probably more) */
3645 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3646 STRCPY(buf, "zh_TW");
3647 else if (STRNICMP(buf, "chs", 3) == 0
3648 || STRNICMP(buf, "zhc", 3) == 0)
3649 STRCPY(buf, "zh_CN");
3650 else if (STRNICMP(buf, "jp", 2) == 0)
3651 STRCPY(buf, "ja");
3652 else
3653 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003654 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003655 }
3656 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003657# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003658# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003659 /* Moved to os_mac_conv.c to avoid dependency problems. */
3660 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003661# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003662# endif
3663
3664 /* enc_locale() will try to find the encoding of the current locale. */
3665 p = enc_locale();
3666 if (p != NULL)
3667 {
3668 char_u *save_enc;
3669
3670 /* Try setting 'encoding' and check if the value is valid.
3671 * If not, go back to the default "latin1". */
3672 save_enc = p_enc;
3673 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003674 if (STRCMP(p_enc, "gb18030") == 0)
3675 {
3676 /* We don't support "gb18030", but "cp936" is a good substitute
3677 * for practical purposes, thus use that. It's not an alias to
3678 * still support conversion between gb18030 and utf-8. */
3679 p_enc = vim_strsave((char_u *)"cp936");
3680 vim_free(p);
3681 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003682 if (mb_init() == NULL)
3683 {
3684 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003685 if (opt_idx >= 0)
3686 {
3687 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3688 options[opt_idx].flags |= P_DEF_ALLOCED;
3689 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003690
Bram Moolenaard0573012017-10-28 21:11:06 +02003691#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003692 if (STRCMP(p_enc, "latin1") == 0 || enc_utf8)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003693 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003694 /* Adjust the default for 'isprint' and 'iskeyword' to match
3695 * latin1. Also set the defaults for when 'nocompatible' is
3696 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003697 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003698 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003699 set_string_option_direct((char_u *)"isk", -1,
3700 ISK_LATIN1, OPT_FREE, SID_NONE);
3701 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003702 if (opt_idx >= 0)
3703 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003704 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003705 if (opt_idx >= 0)
3706 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003707 (void)init_chartab();
3708 }
3709#endif
3710
Bram Moolenaarafde13b2019-04-28 19:46:49 +02003711#if defined(MSWIN) && (!defined(FEAT_GUI) || defined(VIMDLL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003712 /* Win32 console: When GetACP() returns a different value from
3713 * GetConsoleCP() set 'termencoding'. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02003714 if (
3715# ifdef VIMDLL
3716 (!gui.in_use && !gui.starting) &&
3717# endif
3718 GetACP() != GetConsoleCP())
Bram Moolenaar071d4272004-06-13 20:20:40 +00003719 {
3720 char buf[50];
3721
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01003722 /* Win32 console: In ConPTY, GetConsoleCP() returns zero.
3723 * Use an alternative value. */
3724 if (GetConsoleCP() == 0)
3725 sprintf(buf, "cp%ld", (long)GetACP());
3726 else
3727 sprintf(buf, "cp%ld", (long)GetConsoleCP());
Bram Moolenaar071d4272004-06-13 20:20:40 +00003728 p_tenc = vim_strsave((char_u *)buf);
3729 if (p_tenc != NULL)
3730 {
3731 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003732 if (opt_idx >= 0)
3733 {
3734 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3735 options[opt_idx].flags |= P_DEF_ALLOCED;
3736 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003737 convert_setup(&input_conv, p_tenc, p_enc);
3738 convert_setup(&output_conv, p_enc, p_tenc);
3739 }
3740 else
3741 p_tenc = empty_option;
3742 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003743#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01003744#if defined(MSWIN)
Bram Moolenaar05159a02005-02-26 23:04:13 +00003745 /* $HOME may have characters in active code page. */
3746 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003747#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003748 }
3749 else
3750 {
3751 vim_free(p_enc);
3752 p_enc = save_enc;
3753 }
3754 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003755
3756#ifdef FEAT_MULTI_LANG
3757 /* Set the default for 'helplang'. */
3758 set_helplang_default(get_mess_lang());
3759#endif
3760}
3761
3762/*
3763 * Set an option to its default value.
3764 * This does not take care of side effects!
3765 */
3766 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003767set_option_default(
3768 int opt_idx,
3769 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3770 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003771{
3772 char_u *varp; /* pointer to variable for current option */
3773 int dvi; /* index in def_val[] */
3774 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003775 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003776 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3777
3778 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3779 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003780 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003781 {
3782 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3783 if (flags & P_STRING)
3784 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003785 /* Use set_string_option_direct() for local options to handle
3786 * freeing and allocating the value. */
3787 if (options[opt_idx].indir != PV_NONE)
3788 set_string_option_direct(NULL, opt_idx,
3789 options[opt_idx].def_val[dvi], opt_flags, 0);
3790 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003791 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003792 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3793 free_string_option(*(char_u **)(varp));
3794 *(char_u **)varp = options[opt_idx].def_val[dvi];
3795 options[opt_idx].flags &= ~P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003796 }
3797 }
3798 else if (flags & P_NUM)
3799 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003800 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003801 win_comp_scroll(curwin);
3802 else
3803 {
Bram Moolenaar375e3392019-01-31 18:26:10 +01003804 long def_val = (long)(long_i)options[opt_idx].def_val[dvi];
3805
3806 if ((long *)varp == &curwin->w_p_so
3807 || (long *)varp == &curwin->w_p_siso)
3808 // 'scrolloff' and 'sidescrolloff' local values have a
3809 // different default value than the global default.
3810 *(long *)varp = -1;
3811 else
3812 *(long *)varp = def_val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003813 /* May also set global value for local option. */
3814 if (both)
3815 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
Bram Moolenaar375e3392019-01-31 18:26:10 +01003816 def_val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003817 }
3818 }
3819 else /* P_BOOL */
3820 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003821 /* the cast to long is required for Manx C, long_i is needed for
3822 * MSVC */
3823 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003824#ifdef UNIX
3825 /* 'modeline' defaults to off for root */
3826 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3827 *(int *)varp = FALSE;
3828#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003829 /* May also set global value for local option. */
3830 if (both)
3831 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3832 *(int *)varp;
3833 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003834
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003835 /* The default value is not insecure. */
3836 flagsp = insecure_flag(opt_idx, opt_flags);
3837 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003838 }
3839
3840#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003841 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003842#endif
3843}
3844
3845/*
3846 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003847 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003848 */
3849 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003850set_options_default(
3851 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003852{
3853 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003854 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003855 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003856
3857 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003858 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003859 && (opt_flags == 0
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003860 || (options[i].var != (char_u *)&p_enc
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003861# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003862 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003863 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003864# endif
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003865 )))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003866 set_option_default(i, opt_flags, p_cp);
3867
Bram Moolenaar071d4272004-06-13 20:20:40 +00003868 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003869 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003870 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003871#ifdef FEAT_CINDENT
3872 parse_cino(curbuf);
3873#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003874}
3875
3876/*
3877 * Set the Vi-default value of a string option.
3878 * Used for 'sh', 'backupskip' and 'term'.
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003879 * When "escape" is TRUE escape spaces with a backslash.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003880 */
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003881 static void
3882set_string_default_esc(char *name, char_u *val, int escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003883{
3884 char_u *p;
3885 int opt_idx;
3886
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003887 if (escape && vim_strchr(val, ' ') != NULL)
3888 p = vim_strsave_escaped(val, (char_u *)" ");
3889 else
3890 p = vim_strsave(val);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003891 if (p != NULL) /* we don't want a NULL */
3892 {
3893 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003894 if (opt_idx >= 0)
3895 {
3896 if (options[opt_idx].flags & P_DEF_ALLOCED)
3897 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3898 options[opt_idx].def_val[VI_DEFAULT] = p;
3899 options[opt_idx].flags |= P_DEF_ALLOCED;
3900 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003901 }
3902}
3903
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003904 void
3905set_string_default(char *name, char_u *val)
3906{
3907 set_string_default_esc(name, val, FALSE);
3908}
3909
Bram Moolenaar071d4272004-06-13 20:20:40 +00003910/*
3911 * Set the Vi-default value of a number option.
3912 * Used for 'lines' and 'columns'.
3913 */
3914 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003915set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003916{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003917 int opt_idx;
3918
3919 opt_idx = findoption((char_u *)name);
3920 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003921 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003922}
3923
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02003924/*
3925 * Set all window-local and buffer-local options to the Vim default.
3926 * local-global options will use the global value.
3927 */
3928 void
3929set_local_options_default(win_T *wp)
3930{
3931 win_T *save_curwin = curwin;
3932 int i;
3933
3934 curwin = wp;
3935 curbuf = curwin->w_buffer;
3936 block_autocmds();
3937
3938 for (i = 0; !istermoption(&options[i]); i++)
3939 {
3940 struct vimoption *p = &(options[i]);
3941 char_u *varp = get_varp_scope(p, OPT_LOCAL);
3942
3943 if (p->indir != PV_NONE
3944 && !(options[i].flags & P_NODEFAULT)
3945 && !optval_default(p, varp, FALSE))
3946 set_option_default(i, OPT_LOCAL, FALSE);
3947 }
3948
3949 unblock_autocmds();
3950 curwin = save_curwin;
3951 curbuf = curwin->w_buffer;
3952}
3953
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003954#if defined(EXITFREE) || defined(PROTO)
3955/*
3956 * Free all options.
3957 */
3958 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003959free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003960{
3961 int i;
3962
3963 for (i = 0; !istermoption(&options[i]); i++)
3964 {
3965 if (options[i].indir == PV_NONE)
3966 {
3967 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003968 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003969 free_string_option(*(char_u **)options[i].var);
3970 if (options[i].flags & P_DEF_ALLOCED)
3971 free_string_option(options[i].def_val[VI_DEFAULT]);
3972 }
3973 else if (options[i].var != VAR_WIN
3974 && (options[i].flags & P_STRING))
3975 /* buffer-local option: free global value */
3976 free_string_option(*(char_u **)options[i].var);
3977 }
3978}
3979#endif
3980
3981
Bram Moolenaar071d4272004-06-13 20:20:40 +00003982/*
3983 * Initialize the options, part two: After getting Rows and Columns and
3984 * setting 'term'.
3985 */
3986 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003987set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003988{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003989 int idx;
3990
Bram Moolenaar071d4272004-06-13 20:20:40 +00003991 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003992 * 'scroll' defaults to half the window height. The stored default is zero,
3993 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003994 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003995 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003996 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003997 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003998 comp_col();
3999
Bram Moolenaar4399ef42005-02-12 14:29:27 +00004000 /*
4001 * 'window' is only for backwards compatibility with Vi.
4002 * Default is Rows - 1.
4003 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00004004 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00004005 p_window = Rows - 1;
4006 set_number_default("window", Rows - 1);
4007
Bram Moolenaarf740b292006-02-16 22:11:02 +00004008 /* For DOS console the default is always black. */
Bram Moolenaar4f974752019-02-17 17:44:42 +01004009#if !((defined(MSWIN)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00004010 /*
4011 * If 'background' wasn't set by the user, try guessing the value,
4012 * depending on the terminal name. Only need to check for terminals
4013 * with a dark background, that can handle color.
4014 */
4015 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004016 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
4017 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00004018 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004019 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00004020 /* don't mark it as set, when starting the GUI it may be
4021 * changed again */
4022 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004023 }
4024#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00004025
4026#ifdef CURSOR_SHAPE
4027 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
4028#endif
4029#ifdef FEAT_MOUSESHAPE
4030 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
4031#endif
4032#ifdef FEAT_PRINTER
4033 (void)parse_printoptions(); /* parse 'printoptions' default value */
4034#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004035}
4036
4037/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00004038 * Return "dark" or "light" depending on the kind of terminal.
4039 * This is just guessing! Recognized are:
4040 * "linux" Linux console
4041 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004042 * "cygwin.*" Cygwin shell
4043 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00004044 * We also check the COLORFGBG environment variable, which is set by
4045 * rxvt and derivatives. This variable contains either two or three
4046 * values separated by semicolons; we want the last value in either
4047 * case. If this value is 0-6 or 8, our background is dark.
4048 */
4049 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004050term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00004051{
Bram Moolenaar4f974752019-02-17 17:44:42 +01004052#if defined(MSWIN)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004053 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00004054 return (char_u *)"dark";
4055#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00004056 char_u *p;
4057
Bram Moolenaarf740b292006-02-16 22:11:02 +00004058 if (STRCMP(T_NAME, "linux") == 0
4059 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004060 || STRNCMP(T_NAME, "cygwin", 6) == 0
4061 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00004062 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
4063 && (p = vim_strrchr(p, ';')) != NULL
4064 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
4065 && p[2] == NUL))
4066 return (char_u *)"dark";
4067 return (char_u *)"light";
4068#endif
4069}
4070
4071/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004072 * Initialize the options, part three: After reading the .vimrc
4073 */
4074 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004075set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004076{
Bram Moolenaar4f974752019-02-17 17:44:42 +01004077#if defined(UNIX) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004078/*
4079 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4080 * This is done after other initializations, where 'shell' might have been
4081 * set, but only if they have not been set before.
4082 */
4083 char_u *p;
4084 int idx_srr;
4085 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004086# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004087 int idx_sp;
4088 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004089# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004090
4091 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004092 if (idx_srr < 0)
4093 do_srr = FALSE;
4094 else
4095 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004096# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004097 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004098 if (idx_sp < 0)
4099 do_sp = FALSE;
4100 else
4101 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004102# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004103 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004104 if (p != NULL)
4105 {
4106 /*
4107 * Default for p_sp is "| tee", for p_srr is ">".
4108 * For known shells it is changed here to include stderr.
4109 */
4110 if ( fnamecmp(p, "csh") == 0
4111 || fnamecmp(p, "tcsh") == 0
Bram Moolenaar4f974752019-02-17 17:44:42 +01004112# if defined(MSWIN) // also check with .exe extension
Bram Moolenaar071d4272004-06-13 20:20:40 +00004113 || fnamecmp(p, "csh.exe") == 0
4114 || fnamecmp(p, "tcsh.exe") == 0
4115# endif
4116 )
4117 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004118# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004119 if (do_sp)
4120 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01004121# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004122 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004123# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004124 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004125# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004126 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4127 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004128# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004129 if (do_srr)
4130 {
4131 p_srr = (char_u *)">&";
4132 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4133 }
4134 }
4135 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004136 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004137 if ( fnamecmp(p, "sh") == 0
4138 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004139 || fnamecmp(p, "mksh") == 0
4140 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004141 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004142 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004143 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004144 || fnamecmp(p, "fish") == 0
Bram Moolenaar4f974752019-02-17 17:44:42 +01004145# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004146 || fnamecmp(p, "cmd") == 0
4147 || fnamecmp(p, "sh.exe") == 0
4148 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004149 || fnamecmp(p, "mksh.exe") == 0
4150 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004151 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004152 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004153 || fnamecmp(p, "bash.exe") == 0
4154 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004155# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004156 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004157 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004158# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004159 if (do_sp)
4160 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01004161# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004162 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004163# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004164 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004165# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004166 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4167 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004168# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004169 if (do_srr)
4170 {
4171 p_srr = (char_u *)">%s 2>&1";
4172 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4173 }
4174 }
4175 vim_free(p);
4176 }
4177#endif
4178
Bram Moolenaar4f974752019-02-17 17:44:42 +01004179#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004180 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004181 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4182 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004183 * This is done after other initializations, where 'shell' might have been
4184 * set, but only if they have not been set before. Default for p_shcf is
4185 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004186 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004187 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004188 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004189 {
4190 int idx3;
4191
4192 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004193 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004194 {
4195 p_shcf = (char_u *)"-c";
4196 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4197 }
4198
Bram Moolenaar071d4272004-06-13 20:20:40 +00004199 /* Somehow Win32 requires the quotes around the redirection too */
4200 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004201 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004202 {
4203 p_sxq = (char_u *)"\"";
4204 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4205 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004206 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004207 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4208 {
4209 int idx3;
4210
4211 /*
4212 * cmd.exe on Windows will strip the first and last double quote given
4213 * on the command line, e.g. most of the time things like:
4214 * cmd /c "my path/to/echo" "my args to echo"
4215 * become:
4216 * my path/to/echo" "my args to echo
4217 * when executed.
4218 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004219 * To avoid this, set shellxquote to surround the command in
4220 * parenthesis. This appears to make most commands work, without
4221 * breaking commands that worked previously, such as
4222 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004223 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004224 idx3 = findoption((char_u *)"sxq");
4225 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4226 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004227 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004228 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4229 }
4230
Bram Moolenaara64ba222012-02-12 23:23:31 +01004231 idx3 = findoption((char_u *)"shcf");
4232 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4233 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004234 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004235 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4236 }
4237 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004238#endif
4239
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004240 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004241 {
4242 int idx_ffs = findoption((char_u *)"ffs");
4243
4244 /* Apply the first entry of 'fileformats' to the initial buffer. */
4245 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4246 set_fileformat(default_fileformat(), OPT_LOCAL);
4247 }
4248
Bram Moolenaar071d4272004-06-13 20:20:40 +00004249#ifdef FEAT_TITLE
4250 set_title_defaults();
4251#endif
4252}
4253
4254#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4255/*
4256 * When 'helplang' is still at its default value, set it to "lang".
4257 * Only the first two characters of "lang" are used.
4258 */
4259 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004260set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004261{
4262 int idx;
4263
4264 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4265 return;
4266 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004267 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004268 {
4269 if (options[idx].flags & P_ALLOCED)
4270 free_string_option(p_hlg);
4271 p_hlg = vim_strsave(lang);
4272 if (p_hlg == NULL)
4273 p_hlg = empty_option;
4274 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004275 {
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004276 // zh_CN becomes "cn", zh_TW becomes "tw"
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004277 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4278 {
4279 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4280 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4281 }
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004282 // any C like setting, such as C.UTF-8, becomes "en"
4283 else if (STRLEN(p_hlg) >= 1 && *p_hlg == 'C')
4284 {
4285 p_hlg[0] = 'e';
4286 p_hlg[1] = 'n';
4287 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004288 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004289 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004290 options[idx].flags |= P_ALLOCED;
4291 }
4292}
4293#endif
4294
4295#ifdef FEAT_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00004296 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004297gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004298{
4299 if (gui_get_lightness(gui.back_pixel) < 127)
4300 return (char_u *)"dark";
4301 return (char_u *)"light";
4302}
4303
4304/*
4305 * Option initializations that can only be done after opening the GUI window.
4306 */
4307 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004308init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004309{
4310 /* Set the 'background' option according to the lightness of the
4311 * background color, unless the user has set it already. */
4312 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4313 {
4314 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4315 highlight_changed();
4316 }
4317}
4318#endif
4319
4320#ifdef FEAT_TITLE
4321/*
4322 * 'title' and 'icon' only default to true if they have not been set or reset
4323 * in .vimrc and we can read the old value.
4324 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4325 * they can be reset. This reduces startup time when using X on a remote
4326 * machine.
4327 */
4328 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004329set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004330{
4331 int idx1;
4332 long val;
4333
4334 /*
4335 * If GUI is (going to be) used, we can always set the window title and
4336 * icon name. Saves a bit of time, because the X11 display server does
4337 * not need to be contacted.
4338 */
4339 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004340 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004341 {
4342#ifdef FEAT_GUI
4343 if (gui.starting || gui.in_use)
4344 val = TRUE;
4345 else
4346#endif
4347 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004348 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004349 p_title = val;
4350 }
4351 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004352 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004353 {
4354#ifdef FEAT_GUI
4355 if (gui.starting || gui.in_use)
4356 val = TRUE;
4357 else
4358#endif
4359 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004360 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004361 p_icon = val;
4362 }
4363}
4364#endif
4365
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004366#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02004367/*
4368 * Trigger the OptionSet autocommand.
4369 * "opt_idx" is the index of the option being set.
4370 * "opt_flags" can be OPT_LOCAL etc.
4371 * "oldval" the old value
4372 * "oldval_l" the old local value (only non-NULL if global and local value
4373 * are set)
4374 * "oldval_g" the old global value (only non-NULL if global and local value
4375 * are set)
4376 * "newval" the new value
4377 */
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004378 static void
4379trigger_optionsset_string(
4380 int opt_idx,
4381 int opt_flags,
Bram Moolenaard7c96872019-06-15 17:12:48 +02004382 char_u *oldval,
4383 char_u *oldval_l,
4384 char_u *oldval_g,
4385 char_u *newval)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004386{
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02004387 // Don't do this recursively.
4388 if (oldval != NULL && newval != NULL
4389 && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004390 {
4391 char_u buf_type[7];
4392
4393 sprintf((char *)buf_type, "%s",
4394 (opt_flags & OPT_LOCAL) ? "local" : "global");
4395 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4396 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4397 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
Bram Moolenaard7c96872019-06-15 17:12:48 +02004398 if (opt_flags & OPT_LOCAL)
4399 {
4400 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
4401 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1);
4402 }
4403 if (opt_flags & OPT_GLOBAL)
4404 {
4405 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
4406 set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval, -1);
4407 }
4408 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
4409 {
4410 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
4411 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval_l, -1);
4412 set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval_g, -1);
4413 }
4414 if (opt_flags & OPT_MODELINE)
4415 {
4416 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
4417 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1);
4418 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004419 apply_autocmds(EVENT_OPTIONSET,
4420 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4421 reset_v_option_vars();
4422 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004423}
4424#endif
4425
Bram Moolenaar071d4272004-06-13 20:20:40 +00004426/*
4427 * Parse 'arg' for option settings.
4428 *
4429 * 'arg' may be IObuff, but only when no errors can be present and option
4430 * does not need to be expanded with option_expand().
4431 * "opt_flags":
4432 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004433 * OPT_GLOBAL for ":setglobal"
4434 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004435 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004436 * OPT_WINONLY to only set window-local options
4437 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004438 *
4439 * returns FAIL if an error is detected, OK otherwise
4440 */
4441 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004442do_set(
4443 char_u *arg, /* option string (may be written to!) */
4444 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004445{
4446 int opt_idx;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004447 char *errmsg;
4448 char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00004449 char_u *startarg;
4450 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4451 int nextchar; /* next non-white char after option name */
4452 int afterchar; /* character just after option name */
4453 int len;
4454 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004455 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004456 int key;
4457 long_u flags; /* flags for current option */
4458 char_u *varp = NULL; /* pointer to variable for current option */
4459 int did_show = FALSE; /* already showed one value */
4460 int adding; /* "opt+=arg" */
4461 int prepending; /* "opt^=arg" */
4462 int removing; /* "opt-=arg" */
4463 int cp_val = 0;
4464 char_u key_name[2];
4465
4466 if (*arg == NUL)
4467 {
4468 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004469 did_show = TRUE;
4470 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004471 }
4472
4473 while (*arg != NUL) /* loop to process all options */
4474 {
4475 errmsg = NULL;
4476 startarg = arg; /* remember for error message */
4477
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004478 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4479 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004480 {
4481 /*
4482 * ":set all" show all options.
4483 * ":set all&" set all options to their default value.
4484 */
4485 arg += 3;
4486 if (*arg == '&')
4487 {
4488 ++arg;
4489 /* Only for :set command set global value of local options. */
4490 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004491 didset_options();
4492 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004493 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004494 }
4495 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004496 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004497 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004498 did_show = TRUE;
4499 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004500 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004501 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004502 {
4503 showoptions(2, opt_flags);
4504 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004505 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004506 arg += 7;
4507 }
4508 else
4509 {
4510 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004511 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004512 {
4513 prefix = 0;
4514 arg += 2;
4515 }
4516 else if (STRNCMP(arg, "inv", 3) == 0)
4517 {
4518 prefix = 2;
4519 arg += 3;
4520 }
4521
4522 /* find end of name */
4523 key = 0;
4524 if (*arg == '<')
4525 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004526 opt_idx = -1;
4527 /* look out for <t_>;> */
4528 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4529 len = 5;
4530 else
4531 {
4532 len = 1;
4533 while (arg[len] != NUL && arg[len] != '>')
4534 ++len;
4535 }
4536 if (arg[len] != '>')
4537 {
4538 errmsg = e_invarg;
4539 goto skip;
4540 }
4541 arg[len] = NUL; /* put NUL after name */
4542 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4543 opt_idx = findoption(arg + 1);
4544 arg[len++] = '>'; /* restore '>' */
4545 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004546 key = find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004547 }
4548 else
4549 {
4550 len = 0;
4551 /*
4552 * The two characters after "t_" may not be alphanumeric.
4553 */
4554 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4555 len = 4;
4556 else
4557 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4558 ++len;
4559 nextchar = arg[len];
4560 arg[len] = NUL; /* put NUL after name */
4561 opt_idx = findoption(arg);
4562 arg[len] = nextchar; /* restore nextchar */
4563 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004564 key = find_key_option(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004565 }
4566
4567 /* remember character after option name */
4568 afterchar = arg[len];
4569
4570 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004571 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004572 ++len;
4573
4574 adding = FALSE;
4575 prepending = FALSE;
4576 removing = FALSE;
4577 if (arg[len] != NUL && arg[len + 1] == '=')
4578 {
4579 if (arg[len] == '+')
4580 {
4581 adding = TRUE; /* "+=" */
4582 ++len;
4583 }
4584 else if (arg[len] == '^')
4585 {
4586 prepending = TRUE; /* "^=" */
4587 ++len;
4588 }
4589 else if (arg[len] == '-')
4590 {
4591 removing = TRUE; /* "-=" */
4592 ++len;
4593 }
4594 }
4595 nextchar = arg[len];
4596
4597 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4598 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004599 errmsg = N_("E518: Unknown option");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004600 goto skip;
4601 }
4602
4603 if (opt_idx >= 0)
4604 {
4605 if (options[opt_idx].var == NULL) /* hidden option: skip */
4606 {
4607 /* Only give an error message when requesting the value of
4608 * a hidden option, ignore setting it. */
4609 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4610 && (!(options[opt_idx].flags & P_BOOL)
4611 || nextchar == '?'))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004612 errmsg = N_("E519: Option not supported");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004613 goto skip;
4614 }
4615
4616 flags = options[opt_idx].flags;
4617 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4618 }
4619 else
4620 {
4621 flags = P_STRING;
4622 if (key < 0)
4623 {
4624 key_name[0] = KEY2TERMCAP0(key);
4625 key_name[1] = KEY2TERMCAP1(key);
4626 }
4627 else
4628 {
4629 key_name[0] = KS_KEY;
4630 key_name[1] = (key & 0xff);
4631 }
4632 }
4633
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004634 /* Skip all options that are not window-local (used when showing
4635 * an already loaded buffer in a window). */
4636 if ((opt_flags & OPT_WINONLY)
4637 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4638 goto skip;
4639
Bram Moolenaara3227e22006-03-08 21:32:40 +00004640 /* Skip all options that are window-local (used for :vimgrep). */
4641 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4642 && options[opt_idx].var == VAR_WIN)
4643 goto skip;
4644
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004645 /* Disallow changing some options from modelines. */
4646 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004647 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004648 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004649 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004650 errmsg = _("E520: Not allowed in a modeline");
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004651 goto skip;
4652 }
Bram Moolenaar110289e2019-05-23 15:38:06 +02004653 if ((flags & P_MLE) && !p_mle)
4654 {
4655 errmsg = _("E992: Not allowed in a modeline when 'modelineexpr' is off");
4656 goto skip;
4657 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004658#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004659 /* In diff mode some options are overruled. This avoids that
4660 * 'foldmethod' becomes "marker" instead of "diff" and that
4661 * "wrap" gets set. */
4662 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004663 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004664 && (
4665#ifdef FEAT_FOLDING
4666 options[opt_idx].indir == PV_FDM ||
4667#endif
4668 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004669 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004670#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004671 }
4672
4673#ifdef HAVE_SANDBOX
4674 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004675 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004676 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004677 errmsg = _(e_sandbox);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004678 goto skip;
4679 }
4680#endif
4681
4682 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4683 {
4684 arg += len;
4685 cp_val = p_cp;
4686 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4687 {
4688 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4689 {
4690 cp_val = FALSE;
4691 arg += 3;
4692 }
4693 else /* "opt&vi": set to Vi default */
4694 {
4695 cp_val = TRUE;
4696 arg += 2;
4697 }
4698 }
4699 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004700 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004701 {
4702 errmsg = e_trailing;
4703 goto skip;
4704 }
4705 }
4706
4707 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004708 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4709 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004710 */
4711 if (nextchar == '?'
4712 || (prefix == 1
4713 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4714 && !(flags & P_BOOL)))
4715 {
4716 /*
4717 * print value
4718 */
4719 if (did_show)
4720 msg_putchar('\n'); /* cursor below last one */
4721 else
4722 {
4723 gotocmdline(TRUE); /* cursor at status line */
4724 did_show = TRUE; /* remember that we did a line */
4725 }
4726 if (opt_idx >= 0)
4727 {
4728 showoneopt(&options[opt_idx], opt_flags);
4729#ifdef FEAT_EVAL
4730 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004731 {
4732 /* Mention where the option was last set. */
4733 if (varp == options[opt_idx].var)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004734 last_set_msg(options[opt_idx].script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004735 else if ((int)options[opt_idx].indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004736 last_set_msg(curwin->w_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004737 (int)options[opt_idx].indir & PV_MASK]);
4738 else if ((int)options[opt_idx].indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004739 last_set_msg(curbuf->b_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004740 (int)options[opt_idx].indir & PV_MASK]);
4741 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004742#endif
4743 }
4744 else
4745 {
4746 char_u *p;
4747
4748 p = find_termcode(key_name);
4749 if (p == NULL)
4750 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004751 errmsg = N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004752 goto skip;
4753 }
4754 else
4755 (void)show_one_termcode(key_name, p, TRUE);
4756 }
4757 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004758 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004759 errmsg = e_trailing;
4760 }
4761 else
4762 {
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004763 int value_is_replaced = !prepending && !adding && !removing;
Bram Moolenaar916a8182018-11-25 02:18:29 +01004764 int value_checked = FALSE;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004765
Bram Moolenaar071d4272004-06-13 20:20:40 +00004766 if (flags & P_BOOL) /* boolean */
4767 {
4768 if (nextchar == '=' || nextchar == ':')
4769 {
4770 errmsg = e_invarg;
4771 goto skip;
4772 }
4773
4774 /*
4775 * ":set opt!": invert
4776 * ":set opt&": reset to default value
4777 * ":set opt<": reset to global value
4778 */
4779 if (nextchar == '!')
4780 value = *(int *)(varp) ^ 1;
4781 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004782 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004783 ((flags & P_VI_DEF) || cp_val)
4784 ? VI_DEFAULT : VIM_DEFAULT];
4785 else if (nextchar == '<')
4786 {
4787 /* For 'autoread' -1 means to use global value. */
4788 if ((int *)varp == &curbuf->b_p_ar
4789 && opt_flags == OPT_LOCAL)
4790 value = -1;
4791 else
4792 value = *(int *)get_varp_scope(&(options[opt_idx]),
4793 OPT_GLOBAL);
4794 }
4795 else
4796 {
4797 /*
4798 * ":set invopt": invert
4799 * ":set opt" or ":set noopt": set or reset
4800 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004801 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004802 {
4803 errmsg = e_trailing;
4804 goto skip;
4805 }
4806 if (prefix == 2) /* inv */
4807 value = *(int *)(varp) ^ 1;
4808 else
4809 value = prefix;
4810 }
4811
4812 errmsg = set_bool_option(opt_idx, varp, (int)value,
4813 opt_flags);
4814 }
4815 else /* numeric or string */
4816 {
4817 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4818 || prefix != 1)
4819 {
4820 errmsg = e_invarg;
4821 goto skip;
4822 }
4823
4824 if (flags & P_NUM) /* numeric */
4825 {
4826 /*
4827 * Different ways to set a number option:
4828 * & set to default value
4829 * < set to global value
4830 * <xx> accept special key codes for 'wildchar'
4831 * c accept any non-digit for 'wildchar'
4832 * [-]0-9 set number
4833 * other error
4834 */
4835 ++arg;
4836 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004837 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004838 ((flags & P_VI_DEF) || cp_val)
4839 ? VI_DEFAULT : VIM_DEFAULT];
4840 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004841 {
4842 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4843 * use the global value. */
4844 if ((long *)varp == &curbuf->b_p_ul
4845 && opt_flags == OPT_LOCAL)
4846 value = NO_LOCAL_UNDOLEVEL;
4847 else
4848 value = *(long *)get_varp_scope(
4849 &(options[opt_idx]), OPT_GLOBAL);
4850 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004851 else if (((long *)varp == &p_wc
4852 || (long *)varp == &p_wcm)
4853 && (*arg == '<'
4854 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004855 || (*arg != NUL
4856 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004857 && !VIM_ISDIGIT(*arg))))
4858 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004859 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004860 if (value == 0 && (long *)varp != &p_wcm)
4861 {
4862 errmsg = e_invarg;
4863 goto skip;
4864 }
4865 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004866 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4867 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004868 /* Allow negative (for 'undolevels'), octal and
4869 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004870 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
Bram Moolenaar16e9b852019-05-19 19:59:35 +02004871 &value, NULL, 0, TRUE);
Bram Moolenaar06e2c812019-06-12 19:05:48 +02004872 if (i == 0 || (arg[i] != NUL
4873 && !VIM_ISWHITE(arg[i])))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004874 {
Bram Moolenaar16e9b852019-05-19 19:59:35 +02004875 errmsg = N_("E521: Number required after =");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004876 goto skip;
4877 }
4878 }
4879 else
4880 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004881 errmsg = N_("E521: Number required after =");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004882 goto skip;
4883 }
4884
4885 if (adding)
4886 value = *(long *)varp + value;
4887 if (prepending)
4888 value = *(long *)varp * value;
4889 if (removing)
4890 value = *(long *)varp - value;
4891 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004892 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004893 }
4894 else if (opt_idx >= 0) /* string */
4895 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004896 char_u *save_arg = NULL;
4897 char_u *s = NULL;
4898 char_u *oldval = NULL; /* previous value if *varp */
4899 char_u *newval;
4900 char_u *origval = NULL;
Bram Moolenaard7c96872019-06-15 17:12:48 +02004901 char_u *origval_l = NULL;
4902 char_u *origval_g = NULL;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004903#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004904 char_u *saved_origval = NULL;
Bram Moolenaard7c96872019-06-15 17:12:48 +02004905 char_u *saved_origval_l = NULL;
4906 char_u *saved_origval_g = NULL;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004907 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004908#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004909 unsigned newlen;
4910 int comma;
4911 int bs;
4912 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004913 was allocated */
4914
4915 /* When using ":set opt=val" for a global option
4916 * with a local value the local value will be
4917 * reset, use the global value here. */
4918 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004919 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004920 varp = options[opt_idx].var;
4921
4922 /* The old value is kept until we are sure that the
4923 * new value is valid. */
4924 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004925
Bram Moolenaard7c96872019-06-15 17:12:48 +02004926 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
4927 {
4928 origval_l = *(char_u **)get_varp_scope(
4929 &(options[opt_idx]), OPT_LOCAL);
4930 origval_g = *(char_u **)get_varp_scope(
4931 &(options[opt_idx]), OPT_GLOBAL);
4932
4933 // A global-local string option might have an empty
4934 // option as value to indicate that the global
4935 // value should be used.
4936 if (((int)options[opt_idx].indir & PV_BOTH)
4937 && origval_l == empty_option)
4938 origval_l = origval_g;
4939 }
4940
4941 // When setting the local value of a global
4942 // option, the old value may be the global value.
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004943 if (((int)options[opt_idx].indir & PV_BOTH)
4944 && (opt_flags & OPT_LOCAL))
4945 origval = *(char_u **)get_varp(
4946 &options[opt_idx]);
4947 else
4948 origval = oldval;
4949
Bram Moolenaar071d4272004-06-13 20:20:40 +00004950 if (nextchar == '&') /* set to default val */
4951 {
4952 newval = options[opt_idx].def_val[
4953 ((flags & P_VI_DEF) || cp_val)
4954 ? VI_DEFAULT : VIM_DEFAULT];
4955 if ((char_u **)varp == &p_bg)
4956 {
4957 /* guess the value of 'background' */
4958#ifdef FEAT_GUI
4959 if (gui.in_use)
4960 newval = gui_bg_default();
4961 else
4962#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004963 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004964 }
4965
4966 /* expand environment variables and ~ (since the
4967 * default value was already expanded, only
4968 * required when an environment variable was set
4969 * later */
4970 if (newval == NULL)
4971 newval = empty_option;
4972 else
4973 {
4974 s = option_expand(opt_idx, newval);
4975 if (s == NULL)
4976 s = newval;
4977 newval = vim_strsave(s);
4978 }
4979 new_value_alloced = TRUE;
4980 }
4981 else if (nextchar == '<') /* set to global val */
4982 {
4983 newval = vim_strsave(*(char_u **)get_varp_scope(
4984 &(options[opt_idx]), OPT_GLOBAL));
4985 new_value_alloced = TRUE;
4986 }
4987 else
4988 {
4989 ++arg; /* jump to after the '=' or ':' */
4990
4991 /*
4992 * Set 'keywordprg' to ":help" if an empty
4993 * value was passed to :set by the user.
4994 * Misuse errbuf[] for the resulting string.
4995 */
4996 if (varp == (char_u *)&p_kp
4997 && (*arg == NUL || *arg == ' '))
4998 {
4999 STRCPY(errbuf, ":help");
5000 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005001 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005002 }
5003 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01005004 * Convert 'backspace' number to string, for
5005 * adding, prepending and removing string.
5006 */
5007 else if (varp == (char_u *)&p_bs
5008 && VIM_ISDIGIT(**(char_u **)varp))
5009 {
5010 i = getdigits((char_u **)varp);
5011 switch (i)
5012 {
5013 case 0:
5014 *(char_u **)varp = empty_option;
5015 break;
5016 case 1:
5017 *(char_u **)varp = vim_strsave(
5018 (char_u *)"indent,eol");
5019 break;
5020 case 2:
5021 *(char_u **)varp = vim_strsave(
5022 (char_u *)"indent,eol,start");
5023 break;
5024 }
5025 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02005026 if (origval == oldval)
5027 origval = *(char_u **)varp;
Bram Moolenaard7c96872019-06-15 17:12:48 +02005028 if (origval_l == oldval)
5029 origval_l = *(char_u **)varp;
5030 if (origval_g == oldval)
5031 origval_g = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01005032 oldval = *(char_u **)varp;
5033 }
5034 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00005035 * Convert 'whichwrap' number to string, for
5036 * backwards compatibility with Vim 3.0.
5037 * Misuse errbuf[] for the resulting string.
5038 */
5039 else if (varp == (char_u *)&p_ww
5040 && VIM_ISDIGIT(*arg))
5041 {
5042 *errbuf = NUL;
5043 i = getdigits(&arg);
5044 if (i & 1)
5045 STRCAT(errbuf, "b,");
5046 if (i & 2)
5047 STRCAT(errbuf, "s,");
5048 if (i & 4)
5049 STRCAT(errbuf, "h,l,");
5050 if (i & 8)
5051 STRCAT(errbuf, "<,>,");
5052 if (i & 16)
5053 STRCAT(errbuf, "[,],");
5054 if (*errbuf != NUL) /* remove trailing , */
5055 errbuf[STRLEN(errbuf) - 1] = NUL;
5056 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005057 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005058 }
5059 /*
5060 * Remove '>' before 'dir' and 'bdir', for
5061 * backwards compatibility with version 3.0
5062 */
5063 else if ( *arg == '>'
5064 && (varp == (char_u *)&p_dir
5065 || varp == (char_u *)&p_bdir))
5066 {
5067 ++arg;
5068 }
5069
Bram Moolenaar071d4272004-06-13 20:20:40 +00005070 /*
5071 * Copy the new string into allocated memory.
5072 * Can't use set_string_option_direct(), because
5073 * we need to remove the backslashes.
5074 */
5075 /* get a bit too much */
5076 newlen = (unsigned)STRLEN(arg) + 1;
5077 if (adding || prepending || removing)
5078 newlen += (unsigned)STRLEN(origval) + 1;
5079 newval = alloc(newlen);
5080 if (newval == NULL) /* out of mem, don't change */
5081 break;
5082 s = newval;
5083
5084 /*
5085 * Copy the string, skip over escaped chars.
5086 * For MS-DOS and WIN32 backslashes before normal
5087 * file name characters are not removed, and keep
5088 * backslash at start, for "\\machine\path", but
5089 * do remove it for "\\\\machine\\path".
5090 * The reverse is found in ExpandOldSetting().
5091 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005092 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005093 {
5094 if (*arg == '\\' && arg[1] != NUL
5095#ifdef BACKSLASH_IN_FILENAME
5096 && !((flags & P_EXPAND)
5097 && vim_isfilec(arg[1])
5098 && (arg[1] != '\\'
5099 || (s == newval
5100 && arg[2] != '\\')))
5101#endif
5102 )
5103 ++arg; /* remove backslash */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005104 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00005105 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005106 {
5107 /* copy multibyte char */
5108 mch_memmove(s, arg, (size_t)i);
5109 arg += i;
5110 s += i;
5111 }
5112 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005113 *s++ = *arg++;
5114 }
5115 *s = NUL;
5116
5117 /*
5118 * Expand environment variables and ~.
5119 * Don't do it when adding without inserting a
5120 * comma.
5121 */
5122 if (!(adding || prepending || removing)
5123 || (flags & P_COMMA))
5124 {
5125 s = option_expand(opt_idx, newval);
5126 if (s != NULL)
5127 {
5128 vim_free(newval);
5129 newlen = (unsigned)STRLEN(s) + 1;
5130 if (adding || prepending || removing)
5131 newlen += (unsigned)STRLEN(origval) + 1;
5132 newval = alloc(newlen);
5133 if (newval == NULL)
5134 break;
5135 STRCPY(newval, s);
5136 }
5137 }
5138
5139 /* locate newval[] in origval[] when removing it
5140 * and when adding to avoid duplicates */
5141 i = 0; /* init for GCC */
5142 if (removing || (flags & P_NODUP))
5143 {
5144 i = (int)STRLEN(newval);
5145 bs = 0;
5146 for (s = origval; *s; ++s)
5147 {
5148 if ((!(flags & P_COMMA)
5149 || s == origval
5150 || (s[-1] == ',' && !(bs & 1)))
5151 && STRNCMP(s, newval, i) == 0
5152 && (!(flags & P_COMMA)
5153 || s[i] == ','
5154 || s[i] == NUL))
5155 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005156 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005157 * even number of backslashes or a single
5158 * backslash preceded by a comma before it
5159 * is recognized as a separator */
5160 if ((s > origval + 1
5161 && s[-1] == '\\'
5162 && s[-2] != ',')
5163 || (s == origval + 1
5164 && s[-1] == '\\'))
5165
Bram Moolenaar071d4272004-06-13 20:20:40 +00005166 ++bs;
5167 else
5168 bs = 0;
5169 }
5170
5171 /* do not add if already there */
5172 if ((adding || prepending) && *s)
5173 {
5174 prepending = FALSE;
5175 adding = FALSE;
5176 STRCPY(newval, origval);
5177 }
5178 }
5179
5180 /* concatenate the two strings; add a ',' if
5181 * needed */
5182 if (adding || prepending)
5183 {
5184 comma = ((flags & P_COMMA) && *origval != NUL
5185 && *newval != NUL);
5186 if (adding)
5187 {
5188 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005189 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005190 if (comma && i > 1
5191 && (flags & P_ONECOMMA) == P_ONECOMMA
5192 && origval[i - 1] == ','
5193 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005194 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005195 mch_memmove(newval + i + comma, newval,
5196 STRLEN(newval) + 1);
5197 mch_memmove(newval, origval, (size_t)i);
5198 }
5199 else
5200 {
5201 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005202 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005203 }
5204 if (comma)
5205 newval[i] = ',';
5206 }
5207
5208 /* Remove newval[] from origval[]. (Note: "i" has
5209 * been set above and is used here). */
5210 if (removing)
5211 {
5212 STRCPY(newval, origval);
5213 if (*s)
5214 {
5215 /* may need to remove a comma */
5216 if (flags & P_COMMA)
5217 {
5218 if (s == origval)
5219 {
5220 /* include comma after string */
5221 if (s[i] == ',')
5222 ++i;
5223 }
5224 else
5225 {
5226 /* include comma before string */
5227 --s;
5228 ++i;
5229 }
5230 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005231 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005232 }
5233 }
5234
5235 if (flags & P_FLAGLIST)
5236 {
5237 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005238 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005239 {
5240 /* if options have P_FLAGLIST and
5241 * P_ONECOMMA such as 'whichwrap' */
5242 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005243 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005244 if (*s != ',' && *(s + 1) == ','
5245 && vim_strchr(s + 2, *s) != NULL)
5246 {
5247 /* Remove the duplicated value and
5248 * the next comma. */
5249 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005250 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005251 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005252 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005253 else
5254 {
5255 if ((!(flags & P_COMMA) || *s != ',')
5256 && vim_strchr(s + 1, *s) != NULL)
5257 {
5258 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005259 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005260 }
5261 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005262 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005263 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005264 }
5265
5266 if (save_arg != NULL) /* number for 'whichwrap' */
5267 arg = save_arg;
5268 new_value_alloced = TRUE;
5269 }
5270
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005271 /*
5272 * Set the new value.
5273 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005274 *(char_u **)(varp) = newval;
5275
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005276#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005277 if (!starting
5278# ifdef FEAT_CRYPT
5279 && options[opt_idx].indir != PV_KEY
5280# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005281 && origval != NULL && newval != NULL)
5282 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005283 /* origval may be freed by
5284 * did_set_string_option(), make a copy. */
5285 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005286 /* newval (and varp) may become invalid if the
5287 * buffer is closed by autocommands. */
5288 saved_newval = vim_strsave(newval);
Bram Moolenaard7c96872019-06-15 17:12:48 +02005289 if (origval_l != NULL)
5290 saved_origval_l = vim_strsave(origval_l);
5291 if (origval_g != NULL)
5292 saved_origval_g = vim_strsave(origval_g);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005293 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005294#endif
5295
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005296 {
5297 long_u *p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005298 int secure_saved = secure;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005299
5300 // When an option is set in the sandbox, from a
5301 // modeline or in secure mode, then deal with side
5302 // effects in secure mode. Also when the value was
5303 // set with the P_INSECURE flag and is not
5304 // completely replaced.
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005305 if ((opt_flags & OPT_MODELINE)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005306#ifdef HAVE_SANDBOX
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005307 || sandbox != 0
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005308#endif
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005309 || (!value_is_replaced && (*p & P_INSECURE)))
5310 secure = 1;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005311
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005312 // Handle side effects, and set the global value
5313 // for ":set" on local options. Note: when setting
5314 // 'syntax' or 'filetype' autocommands may be
5315 // triggered that can cause havoc.
5316 errmsg = did_set_string_option(
5317 opt_idx, (char_u **)varp,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005318 new_value_alloced, oldval, errbuf,
5319 opt_flags, &value_checked);
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005320
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005321 secure = secure_saved;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005322 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005323
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005324#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005325 if (errmsg == NULL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02005326 trigger_optionsset_string(
5327 opt_idx, opt_flags, saved_origval,
5328 saved_origval_l, saved_origval_g,
5329 saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005330 vim_free(saved_origval);
Bram Moolenaard7c96872019-06-15 17:12:48 +02005331 vim_free(saved_origval_l);
5332 vim_free(saved_origval_g);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005333 vim_free(saved_newval);
5334#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005335 /* If error detected, print the error message. */
5336 if (errmsg != NULL)
5337 goto skip;
5338 }
5339 else /* key code option */
5340 {
5341 char_u *p;
5342
5343 if (nextchar == '&')
5344 {
5345 if (add_termcap_entry(key_name, TRUE) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005346 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005347 }
5348 else
5349 {
5350 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005351 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005352 if (*p == '\\' && p[1] != NUL)
5353 ++p;
5354 nextchar = *p;
5355 *p = NUL;
5356 add_termcode(key_name, arg, FALSE);
5357 *p = nextchar;
5358 }
5359 if (full_screen)
5360 ttest(FALSE);
5361 redraw_all_later(CLEAR);
5362 }
5363 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005364
Bram Moolenaar071d4272004-06-13 20:20:40 +00005365 if (opt_idx >= 0)
Bram Moolenaar916a8182018-11-25 02:18:29 +01005366 did_set_option(
5367 opt_idx, opt_flags, value_is_replaced, value_checked);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005368 }
5369
5370skip:
5371 /*
5372 * Advance to next argument.
5373 * - skip until a blank found, taking care of backslashes
5374 * - skip blanks
5375 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5376 */
5377 for (i = 0; i < 2 ; ++i)
5378 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005379 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005380 if (*arg++ == '\\' && *arg != NUL)
5381 ++arg;
5382 arg = skipwhite(arg);
5383 if (*arg != '=')
5384 break;
5385 }
5386 }
5387
5388 if (errmsg != NULL)
5389 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005390 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005391 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005392 if (i + (arg - startarg) < IOSIZE)
5393 {
5394 /* append the argument with the error */
5395 STRCAT(IObuff, ": ");
5396 mch_memmove(IObuff + i, startarg, (arg - startarg));
5397 IObuff[i + (arg - startarg)] = NUL;
5398 }
5399 /* make sure all characters are printable */
5400 trans_characters(IObuff, IOSIZE);
5401
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005402 ++no_wait_return; // wait_return done later
5403 emsg((char *)IObuff); // show error highlighted
Bram Moolenaar071d4272004-06-13 20:20:40 +00005404 --no_wait_return;
5405
5406 return FAIL;
5407 }
5408
5409 arg = skipwhite(arg);
5410 }
5411
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005412theend:
5413 if (silent_mode && did_show)
5414 {
5415 /* After displaying option values in silent mode. */
5416 silent_mode = FALSE;
5417 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5418 msg_putchar('\n');
5419 cursor_on(); /* msg_start() switches it off */
5420 out_flush();
5421 silent_mode = TRUE;
5422 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5423 }
5424
Bram Moolenaar071d4272004-06-13 20:20:40 +00005425 return OK;
5426}
5427
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005428/*
5429 * Call this when an option has been given a new value through a user command.
5430 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5431 */
5432 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005433did_set_option(
5434 int opt_idx,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005435 int opt_flags, // possibly with OPT_MODELINE
5436 int new_value, // value was replaced completely
5437 int value_checked) // value was checked to be safe, no need to set the
5438 // P_INSECURE flag.
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005439{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005440 long_u *p;
5441
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005442 options[opt_idx].flags |= P_WAS_SET;
5443
5444 /* When an option is set in the sandbox, from a modeline or in secure mode
5445 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005446 * flag. */
5447 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar916a8182018-11-25 02:18:29 +01005448 if (!value_checked && (secure
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005449#ifdef HAVE_SANDBOX
5450 || sandbox != 0
5451#endif
Bram Moolenaar916a8182018-11-25 02:18:29 +01005452 || (opt_flags & OPT_MODELINE)))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005453 *p = *p | P_INSECURE;
5454 else if (new_value)
5455 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005456}
5457
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005458 static char *
5459illegal_char(char *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005460{
5461 if (errbuf == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005462 return "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00005463 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005464 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005465 return errbuf;
5466}
5467
5468/*
5469 * Convert a key name or string into a key value.
5470 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005471 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005472 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005473 int
5474string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005475{
5476 if (*arg == '<')
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02005477 return find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005478 if (*arg == '^')
5479 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005480 if (multi_byte)
5481 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005482 return *arg;
5483}
5484
5485#ifdef FEAT_CMDWIN
5486/*
5487 * Check value of 'cedit' and set cedit_key.
5488 * Returns NULL if value is OK, error message otherwise.
5489 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005490 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005491check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005492{
5493 int n;
5494
5495 if (*p_cedit == NUL)
5496 cedit_key = -1;
5497 else
5498 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005499 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005500 if (vim_isprintc(n))
5501 return e_invarg;
5502 cedit_key = n;
5503 }
5504 return NULL;
5505}
5506#endif
5507
5508#ifdef FEAT_TITLE
5509/*
5510 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5511 * maketitle() to create and display it.
5512 * When switching the title or icon off, call mch_restore_title() to get
5513 * the old value back.
5514 */
5515 static void
Bram Moolenaar84a93082018-06-16 22:58:15 +02005516did_set_title(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005517{
5518 if (starting != NO_SCREEN
5519#ifdef FEAT_GUI
5520 && !gui.starting
5521#endif
5522 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00005523 maketitle();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005524}
5525#endif
5526
5527/*
5528 * set_options_bin - called when 'bin' changes value.
5529 */
5530 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005531set_options_bin(
5532 int oldval,
5533 int newval,
5534 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005535{
5536 /*
5537 * The option values that are changed when 'bin' changes are
5538 * copied when 'bin is set and restored when 'bin' is reset.
5539 */
5540 if (newval)
5541 {
5542 if (!oldval) /* switched on */
5543 {
5544 if (!(opt_flags & OPT_GLOBAL))
5545 {
5546 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5547 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5548 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5549 curbuf->b_p_et_nobin = curbuf->b_p_et;
5550 }
5551 if (!(opt_flags & OPT_LOCAL))
5552 {
5553 p_tw_nobin = p_tw;
5554 p_wm_nobin = p_wm;
5555 p_ml_nobin = p_ml;
5556 p_et_nobin = p_et;
5557 }
5558 }
5559
5560 if (!(opt_flags & OPT_GLOBAL))
5561 {
5562 curbuf->b_p_tw = 0; /* no automatic line wrap */
5563 curbuf->b_p_wm = 0; /* no automatic line wrap */
5564 curbuf->b_p_ml = 0; /* no modelines */
5565 curbuf->b_p_et = 0; /* no expandtab */
5566 }
5567 if (!(opt_flags & OPT_LOCAL))
5568 {
5569 p_tw = 0;
5570 p_wm = 0;
5571 p_ml = FALSE;
5572 p_et = FALSE;
5573 p_bin = TRUE; /* needed when called for the "-b" argument */
5574 }
5575 }
5576 else if (oldval) /* switched off */
5577 {
5578 if (!(opt_flags & OPT_GLOBAL))
5579 {
5580 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5581 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5582 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5583 curbuf->b_p_et = curbuf->b_p_et_nobin;
5584 }
5585 if (!(opt_flags & OPT_LOCAL))
5586 {
5587 p_tw = p_tw_nobin;
5588 p_wm = p_wm_nobin;
5589 p_ml = p_ml_nobin;
5590 p_et = p_et_nobin;
5591 }
5592 }
5593}
5594
Bram Moolenaar071d4272004-06-13 20:20:40 +00005595/*
5596 * Expand environment variables for some string options.
5597 * These string options cannot be indirect!
5598 * If "val" is NULL expand the current value of the option.
5599 * Return pointer to NameBuff, or NULL when not expanded.
5600 */
5601 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005602option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005603{
5604 /* if option doesn't need expansion nothing to do */
5605 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5606 return NULL;
5607
5608 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5609 * expand_env() would truncate the string. */
5610 if (val != NULL && STRLEN(val) > MAXPATHL)
5611 return NULL;
5612
5613 if (val == NULL)
5614 val = *(char_u **)options[opt_idx].var;
5615
5616 /*
5617 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5618 * Escape spaces when expanding 'tags', they are used to separate file
5619 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005620 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005621 */
5622 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005623 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005624#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005625 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5626#endif
5627 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005628 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5629 return NULL;
5630
5631 return NameBuff;
5632}
5633
5634/*
5635 * After setting various option values: recompute variables that depend on
5636 * option values.
5637 */
5638 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005639didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005640{
5641 /* initialize the table for 'iskeyword' et.al. */
5642 (void)init_chartab();
5643
5644 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
5645 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005646 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005647#ifdef FEAT_SESSION
5648 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5649 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5650#endif
5651#ifdef FEAT_FOLDING
5652 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5653#endif
5654 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005655 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005656 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005657#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5658 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5659#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005660#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005661 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005662 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005663 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005664 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005665#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01005666#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005667 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5668#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005669#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005670 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5671#endif
5672#ifdef FEAT_CMDWIN
5673 /* set cedit_key */
5674 (void)check_cedit();
5675#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005676#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005677 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005678#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005679#ifdef FEAT_LINEBREAK
5680 /* initialize the table for 'breakat'. */
5681 fill_breakat_flags();
5682#endif
5683
5684}
5685
5686/*
5687 * More side effects of setting options.
5688 */
5689 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005690didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005691{
5692 /* Initialize the highlight_attr[] table. */
5693 (void)highlight_changed();
5694
5695 /* Parse default for 'wildmode' */
5696 check_opt_wim();
5697
5698 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005699 /* Parse default for 'fillchars'. */
5700 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005701
5702#ifdef FEAT_CLIPBOARD
5703 /* Parse default for 'clipboard' */
5704 (void)check_clipboard_option();
5705#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005706#ifdef FEAT_VARTABS
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01005707 vim_free(curbuf->b_p_vsts_array);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005708 tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_array);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01005709 vim_free(curbuf->b_p_vts_array);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005710 tabstop_set(curbuf->b_p_vts, &curbuf->b_p_vts_array);
5711#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005712}
5713
5714/*
5715 * Check for string options that are NULL (normally only termcap options).
5716 */
5717 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005718check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005719{
5720 int opt_idx;
5721
5722 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5723 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5724 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5725}
5726
5727/*
5728 * Check string options in a buffer for NULL value.
5729 */
5730 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005731check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005732{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005733 check_string_option(&buf->b_p_bh);
5734 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005735 check_string_option(&buf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005736 check_string_option(&buf->b_p_ff);
5737#ifdef FEAT_FIND_ID
5738 check_string_option(&buf->b_p_def);
5739 check_string_option(&buf->b_p_inc);
5740# ifdef FEAT_EVAL
5741 check_string_option(&buf->b_p_inex);
5742# endif
5743#endif
5744#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5745 check_string_option(&buf->b_p_inde);
5746 check_string_option(&buf->b_p_indk);
5747#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005748#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5749 check_string_option(&buf->b_p_bexpr);
5750#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005751#if defined(FEAT_CRYPT)
5752 check_string_option(&buf->b_p_cm);
5753#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005754 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005755#if defined(FEAT_EVAL)
5756 check_string_option(&buf->b_p_fex);
5757#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005758#ifdef FEAT_CRYPT
5759 check_string_option(&buf->b_p_key);
5760#endif
5761 check_string_option(&buf->b_p_kp);
5762 check_string_option(&buf->b_p_mps);
5763 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005764 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005765 check_string_option(&buf->b_p_isk);
5766#ifdef FEAT_COMMENTS
5767 check_string_option(&buf->b_p_com);
5768#endif
5769#ifdef FEAT_FOLDING
5770 check_string_option(&buf->b_p_cms);
5771#endif
5772 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005773#ifdef FEAT_TEXTOBJ
5774 check_string_option(&buf->b_p_qe);
5775#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005776#ifdef FEAT_SYN_HL
5777 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005778 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005779#endif
5780#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005781 check_string_option(&buf->b_s.b_p_spc);
5782 check_string_option(&buf->b_s.b_p_spf);
5783 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005784#endif
5785#ifdef FEAT_SEARCHPATH
5786 check_string_option(&buf->b_p_sua);
5787#endif
5788#ifdef FEAT_CINDENT
5789 check_string_option(&buf->b_p_cink);
5790 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005791 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005792#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005793 check_string_option(&buf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005794#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5795 check_string_option(&buf->b_p_cinw);
5796#endif
5797#ifdef FEAT_INS_EXPAND
5798 check_string_option(&buf->b_p_cpt);
5799#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005800#ifdef FEAT_COMPL_FUNC
5801 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005802 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005803#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +02005804#ifdef FEAT_EVAL
5805 check_string_option(&buf->b_p_tfu);
5806#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005807#ifdef FEAT_KEYMAP
5808 check_string_option(&buf->b_p_keymap);
5809#endif
5810#ifdef FEAT_QUICKFIX
5811 check_string_option(&buf->b_p_gp);
5812 check_string_option(&buf->b_p_mp);
5813 check_string_option(&buf->b_p_efm);
5814#endif
5815 check_string_option(&buf->b_p_ep);
5816 check_string_option(&buf->b_p_path);
5817 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005818 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005819#ifdef FEAT_INS_EXPAND
5820 check_string_option(&buf->b_p_dict);
5821 check_string_option(&buf->b_p_tsr);
5822#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005823#ifdef FEAT_LISP
5824 check_string_option(&buf->b_p_lw);
5825#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005826 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005827 check_string_option(&buf->b_p_menc);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005828#ifdef FEAT_VARTABS
5829 check_string_option(&buf->b_p_vsts);
5830 check_string_option(&buf->b_p_vts);
5831#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005832}
5833
5834/*
5835 * Free the string allocated for an option.
5836 * Checks for the string being empty_option. This may happen if we're out of
5837 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5838 * check_options().
5839 * Does NOT check for P_ALLOCED flag!
5840 */
5841 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005842free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005843{
5844 if (p != empty_option)
5845 vim_free(p);
5846}
5847
5848 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005849clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005850{
5851 if (*pp != empty_option)
5852 vim_free(*pp);
5853 *pp = empty_option;
5854}
5855
5856 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005857check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005858{
5859 if (*pp == NULL)
5860 *pp = empty_option;
5861}
5862
5863/*
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005864 * Return the option index found by a pointer into term_strings[].
5865 * Return -1 if not found.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005866 */
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005867 int
5868get_term_opt_idx(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005869{
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005870 int opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005871
5872 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5873 if (options[opt_idx].var == (char_u *)p)
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005874 return opt_idx;
5875 return -1; // cannot happen: didn't find it!
5876}
5877
5878/*
5879 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5880 * Return the option index or -1 if not found.
5881 */
5882 int
5883set_term_option_alloced(char_u **p)
5884{
5885 int opt_idx = get_term_opt_idx(p);
5886
5887 if (opt_idx >= 0)
5888 options[opt_idx].flags |= P_ALLOCED;
5889 return opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005890}
5891
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005892#if defined(FEAT_EVAL) || defined(PROTO)
5893/*
5894 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5895 * Return FALSE when it wasn't.
5896 * Return -1 for an unknown option.
5897 */
5898 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005899was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005900{
5901 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005902 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005903
5904 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005905 {
5906 flagp = insecure_flag(idx, opt_flags);
5907 return (*flagp & P_INSECURE) != 0;
5908 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005909 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005910 return -1;
5911}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005912
5913/*
5914 * Get a pointer to the flags used for the P_INSECURE flag of option
5915 * "opt_idx". For some local options a local flags field is used.
5916 */
5917 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005918insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005919{
5920 if (opt_flags & OPT_LOCAL)
5921 switch ((int)options[opt_idx].indir)
5922 {
5923#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005924 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005925#endif
5926#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005927# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005928 case PV_FDE: return &curwin->w_p_fde_flags;
5929 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005930# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005931# ifdef FEAT_BEVAL
5932 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5933# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005934# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005935 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005936# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005937 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005938# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005939 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005940# endif
5941#endif
5942 }
5943
5944 /* Nothing special, return global flags field. */
5945 return &options[opt_idx].flags;
5946}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005947#endif
5948
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005949#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005950/*
5951 * Redraw the window title and/or tab page text later.
5952 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005953static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005954{
5955 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005956 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005957}
5958#endif
5959
Bram Moolenaar071d4272004-06-13 20:20:40 +00005960/*
5961 * Set a string option to a new value (without checking the effect).
5962 * The string is copied into allocated memory.
5963 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005964 * When "set_sid" is zero set the scriptID to current_sctx.sc_sid. When
5965 * "set_sid" is SID_NONE don't set the scriptID. Otherwise set the scriptID to
5966 * "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005967 */
5968 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005969set_string_option_direct(
5970 char_u *name,
5971 int opt_idx,
5972 char_u *val,
5973 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5974 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005975{
5976 char_u *s;
5977 char_u **varp;
5978 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005979 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005980
Bram Moolenaar89d40322006-08-29 15:30:07 +00005981 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005982 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005983 idx = findoption(name);
5984 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005985 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005986 semsg(_(e_intern2), "set_string_option_direct()");
5987 siemsg(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005988 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005989 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005990 }
5991
Bram Moolenaar89d40322006-08-29 15:30:07 +00005992 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005993 return;
5994
5995 s = vim_strsave(val);
5996 if (s != NULL)
5997 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005998 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005999 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00006000 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006001 free_string_option(*varp);
6002 *varp = s;
6003
6004 /* For buffer/window local option may also set the global value. */
6005 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00006006 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006007
Bram Moolenaar89d40322006-08-29 15:30:07 +00006008 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006009
6010 /* When setting both values of a global option with a local value,
6011 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00006012 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006013 {
6014 free_string_option(*varp);
6015 *varp = empty_option;
6016 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006017# ifdef FEAT_EVAL
6018 if (set_sid != SID_NONE)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02006019 {
6020 sctx_T script_ctx;
6021
6022 if (set_sid == 0)
6023 script_ctx = current_sctx;
6024 else
6025 {
6026 script_ctx.sc_sid = set_sid;
Bram Moolenaarded5f1b2018-11-10 17:33:29 +01006027 script_ctx.sc_seq = 0;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02006028 script_ctx.sc_lnum = 0;
Bram Moolenaar558ca4a2019-04-04 18:15:38 +02006029 script_ctx.sc_version = 1;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02006030 }
6031 set_option_sctx_idx(idx, opt_flags, script_ctx);
6032 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006033# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006034 }
6035}
6036
6037/*
Bram Moolenaar20c023a2019-05-26 21:03:24 +02006038 * Like set_string_option_direct(), but for a window-local option in "wp".
6039 * Blocks autocommands to avoid the old curwin becoming invalid.
6040 */
6041 void
6042set_string_option_direct_in_win(
6043 win_T *wp,
6044 char_u *name,
6045 int opt_idx,
6046 char_u *val,
6047 int opt_flags,
6048 int set_sid)
6049{
6050 win_T *save_curwin = curwin;
6051
6052 block_autocmds();
6053 curwin = wp;
6054 curbuf = curwin->w_buffer;
6055 set_string_option_direct(name, opt_idx, val, opt_flags, set_sid);
6056 curwin = save_curwin;
6057 curbuf = curwin->w_buffer;
6058 unblock_autocmds();
6059}
6060
6061/*
6062 * Like set_string_option_direct(), but for a buffer-local option in "buf".
6063 * Blocks autocommands to avoid the old curbuf becoming invalid.
6064 */
6065 void
6066set_string_option_direct_in_buf(
6067 buf_T *buf,
6068 char_u *name,
6069 int opt_idx,
6070 char_u *val,
6071 int opt_flags,
6072 int set_sid)
6073{
6074 buf_T *save_curbuf = curbuf;
6075
6076 block_autocmds();
6077 curbuf = buf;
6078 curwin->w_buffer = curbuf;
6079 set_string_option_direct(name, opt_idx, val, opt_flags, set_sid);
6080 curbuf = save_curbuf;
6081 curwin->w_buffer = curbuf;
6082 unblock_autocmds();
6083}
6084
6085/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006086 * Set global value for string option when it's a local option.
6087 */
6088 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01006089set_string_option_global(
6090 int opt_idx, /* option index */
6091 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006092{
6093 char_u **p, *s;
6094
6095 /* the global value is always allocated */
6096 if (options[opt_idx].var == VAR_WIN)
6097 p = (char_u **)GLOBAL_WO(varp);
6098 else
6099 p = (char_u **)options[opt_idx].var;
6100 if (options[opt_idx].indir != PV_NONE
6101 && p != varp
6102 && (s = vim_strsave(*varp)) != NULL)
6103 {
6104 free_string_option(*p);
6105 *p = s;
6106 }
6107}
6108
6109/*
6110 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006111 *
6112 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006113 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006114 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006115set_string_option(
6116 int opt_idx,
6117 char_u *value,
6118 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006119{
6120 char_u *s;
6121 char_u **varp;
6122 char_u *oldval;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02006123#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02006124 char_u *oldval_l = NULL;
6125 char_u *oldval_g = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02006126 char_u *saved_oldval = NULL;
Bram Moolenaard7c96872019-06-15 17:12:48 +02006127 char_u *saved_oldval_l = NULL;
6128 char_u *saved_oldval_g = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006129 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02006130#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006131 char *r = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01006132 int value_checked = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006133
6134 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006135 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006136
6137 s = vim_strsave(value);
6138 if (s != NULL)
6139 {
6140 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
6141 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006142 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006143 ? OPT_GLOBAL : OPT_LOCAL)
6144 : opt_flags);
6145 oldval = *varp;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02006146#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02006147 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6148 {
6149 oldval_l = *(char_u **)get_varp_scope(&(options[opt_idx]),
6150 OPT_LOCAL);
6151 oldval_g = *(char_u **)get_varp_scope(&(options[opt_idx]),
6152 OPT_GLOBAL);
6153 }
Bram Moolenaar983f2f12019-06-16 16:41:41 +02006154#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006155 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02006156
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006157#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02006158 if (!starting
6159# ifdef FEAT_CRYPT
6160 && options[opt_idx].indir != PV_KEY
6161# endif
6162 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006163 {
Bram Moolenaard7c96872019-06-15 17:12:48 +02006164 if (oldval_l != NULL)
6165 saved_oldval_l = vim_strsave(oldval_l);
6166 if (oldval_g != NULL)
6167 saved_oldval_g = vim_strsave(oldval_g);
Bram Moolenaar53744302015-07-17 17:38:22 +02006168 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006169 saved_newval = vim_strsave(s);
6170 }
Bram Moolenaar53744302015-07-17 17:38:22 +02006171#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006172 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
Bram Moolenaar916a8182018-11-25 02:18:29 +01006173 opt_flags, &value_checked)) == NULL)
6174 did_set_option(opt_idx, opt_flags, TRUE, value_checked);
Bram Moolenaar53744302015-07-17 17:38:22 +02006175
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006176#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006177 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006178 if (r == NULL)
6179 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaard7c96872019-06-15 17:12:48 +02006180 saved_oldval, saved_oldval_l,
6181 saved_oldval_g, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006182 vim_free(saved_oldval);
Bram Moolenaard7c96872019-06-15 17:12:48 +02006183 vim_free(saved_oldval_l);
6184 vim_free(saved_oldval_g);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006185 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02006186#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006187 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006188 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006189}
6190
6191/*
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006192 * Return TRUE if "val" is a valid name: only consists of alphanumeric ASCII
6193 * characters or characters in "allowed".
6194 */
6195 static int
6196valid_name(char_u *val, char *allowed)
6197{
6198 char_u *s;
6199
6200 for (s = val; *s != NUL; ++s)
6201 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)allowed, *s) == NULL)
6202 return FALSE;
6203 return TRUE;
6204}
6205
6206/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01006207 * Return TRUE if "val" is a valid 'filetype' name.
6208 * Also used for 'syntax' and 'keymap'.
6209 */
6210 static int
6211valid_filetype(char_u *val)
6212{
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006213 return valid_name(val, ".-_");
6214}
Bram Moolenaard0b51382016-11-04 15:23:45 +01006215
Bram Moolenaara7be0f22019-04-11 11:19:32 +02006216#if defined(FEAT_SPELL) || defined(PROTO)
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006217/*
6218 * Return TRUE if "val" is a valid 'spellang' value.
6219 */
6220 int
6221valid_spellang(char_u *val)
6222{
Bram Moolenaar9a061cb2019-05-05 16:55:03 +02006223 return valid_name(val, ".-_,@");
Bram Moolenaard0b51382016-11-04 15:23:45 +01006224}
6225
6226/*
Bram Moolenaar862f1e12019-04-10 22:33:41 +02006227 * Return TRUE if "val" is a valid 'spellfile' value.
6228 */
6229 static int
6230valid_spellfile(char_u *val)
6231{
6232 char_u *s;
6233
6234 for (s = val; *s != NUL; ++s)
6235 if (!vim_isfilec(*s) && *s != ',')
6236 return FALSE;
6237 return TRUE;
6238}
Bram Moolenaara7be0f22019-04-11 11:19:32 +02006239#endif
Bram Moolenaar862f1e12019-04-10 22:33:41 +02006240
6241/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006242 * Handle string options that need some action to perform when changed.
6243 * Returns NULL for success, or an error message for an error.
6244 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006245 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006246did_set_string_option(
Bram Moolenaar916a8182018-11-25 02:18:29 +01006247 int opt_idx, // index in options[] table
6248 char_u **varp, // pointer to the option variable
6249 int new_value_alloced, // new value was allocated
6250 char_u *oldval, // previous value of the option
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006251 char *errbuf, // buffer for errors, or NULL
Bram Moolenaar916a8182018-11-25 02:18:29 +01006252 int opt_flags, // OPT_LOCAL and/or OPT_GLOBAL
6253 int *value_checked) // value was checked to be save, no
6254 // need to set P_INSECURE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006255{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006256 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006257 char_u *s, *p;
6258 int did_chartab = FALSE;
6259 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006260 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006261#ifdef FEAT_GUI
6262 /* set when changing an option that only requires a redraw in the GUI */
6263 int redraw_gui_only = FALSE;
6264#endif
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02006265 int value_changed = FALSE;
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006266#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6267 int did_swaptcap = FALSE;
6268#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006269
6270 /* Get the global option to compare with, otherwise we would have to check
6271 * two values for all local options. */
6272 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6273
6274 /* Disallow changing some options from secure mode */
6275 if ((secure
6276#ifdef HAVE_SANDBOX
6277 || sandbox != 0
6278#endif
6279 ) && (options[opt_idx].flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006280 errmsg = e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006281
Bram Moolenaar916a8182018-11-25 02:18:29 +01006282 // Check for a "normal" directory or file name in some options. Disallow a
6283 // path separator (slash and/or backslash), wildcards and characters that
6284 // are often illegal in a file name. Be more permissive if "secure" is off.
Bram Moolenaar7554da42016-11-25 22:04:13 +01006285 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006286 && vim_strpbrk(*varp, (char_u *)(secure
6287 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006288 || ((options[opt_idx].flags & P_NDNAME)
6289 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006290 errmsg = e_invarg;
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006291
Bram Moolenaar071d4272004-06-13 20:20:40 +00006292 /* 'term' */
6293 else if (varp == &T_NAME)
6294 {
6295 if (T_NAME[0] == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006296 errmsg = N_("E529: Cannot set 'term' to empty string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006297#ifdef FEAT_GUI
6298 if (gui.in_use)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006299 errmsg = N_("E530: Cannot change term in GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006300 else if (term_is_gui(T_NAME))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006301 errmsg = N_("E531: Use \":gui\" to start the GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006302#endif
6303 else if (set_termname(T_NAME) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006304 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006305 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006306 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006307 /* Screen colors may have changed. */
6308 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006309
6310 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6311 * P_ALLOCED flag on 'term'. */
6312 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006313 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006314 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006315 }
6316
6317 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006318 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006319 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006320 char_u *bkc = p_bkc;
6321 unsigned int *flags = &bkc_flags;
6322
6323 if (opt_flags & OPT_LOCAL)
6324 {
6325 bkc = curbuf->b_p_bkc;
6326 flags = &curbuf->b_bkc_flags;
6327 }
6328
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006329 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6330 /* make the local value empty: use the global value */
6331 *flags = 0;
6332 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006333 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006334 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6335 errmsg = e_invarg;
6336 if ((((int)*flags & BKC_AUTO) != 0)
6337 + (((int)*flags & BKC_YES) != 0)
6338 + (((int)*flags & BKC_NO) != 0) != 1)
6339 {
6340 /* Must have exactly one of "auto", "yes" and "no". */
6341 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6342 errmsg = e_invarg;
6343 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006344 }
6345 }
6346
6347 /* 'backupext' and 'patchmode' */
6348 else if (varp == &p_bex || varp == &p_pm)
6349 {
6350 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6351 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006352 errmsg = N_("E589: 'backupext' and 'patchmode' are equal");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006353 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006354#ifdef FEAT_LINEBREAK
6355 /* 'breakindentopt' */
6356 else if (varp == &curwin->w_p_briopt)
6357 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006358 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006359 errmsg = e_invarg;
6360 }
6361#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006362
6363 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006364 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006365 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006366 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006367 */
6368 else if ( varp == &p_isi
6369 || varp == &(curbuf->b_p_isk)
6370 || varp == &p_isp
6371 || varp == &p_isf)
6372 {
6373 if (init_chartab() == FAIL)
6374 {
6375 did_chartab = TRUE; /* need to restore it below */
6376 errmsg = e_invarg; /* error in value */
6377 }
6378 }
6379
6380 /* 'helpfile' */
6381 else if (varp == &p_hf)
6382 {
6383 /* May compute new values for $VIM and $VIMRUNTIME */
6384 if (didset_vim)
6385 {
6386 vim_setenv((char_u *)"VIM", (char_u *)"");
6387 didset_vim = FALSE;
6388 }
6389 if (didset_vimruntime)
6390 {
6391 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6392 didset_vimruntime = FALSE;
6393 }
6394 }
6395
Bram Moolenaar1a384422010-07-14 19:53:30 +02006396#ifdef FEAT_SYN_HL
6397 /* 'colorcolumn' */
6398 else if (varp == &curwin->w_p_cc)
6399 errmsg = check_colorcolumn(curwin);
6400#endif
6401
Bram Moolenaar071d4272004-06-13 20:20:40 +00006402#ifdef FEAT_MULTI_LANG
6403 /* 'helplang' */
6404 else if (varp == &p_hlg)
6405 {
6406 /* Check for "", "ab", "ab,cd", etc. */
6407 for (s = p_hlg; *s != NUL; s += 3)
6408 {
6409 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6410 {
6411 errmsg = e_invarg;
6412 break;
6413 }
6414 if (s[2] == NUL)
6415 break;
6416 }
6417 }
6418#endif
6419
6420 /* 'highlight' */
6421 else if (varp == &p_hl)
6422 {
6423 if (highlight_changed() == FAIL)
6424 errmsg = e_invarg; /* invalid flags */
6425 }
6426
6427 /* 'nrformats' */
6428 else if (gvarp == &p_nf)
6429 {
6430 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6431 errmsg = e_invarg;
6432 }
6433
6434#ifdef FEAT_SESSION
6435 /* 'sessionoptions' */
6436 else if (varp == &p_ssop)
6437 {
6438 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6439 errmsg = e_invarg;
6440 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6441 {
6442 /* Don't allow both "sesdir" and "curdir". */
6443 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6444 errmsg = e_invarg;
6445 }
6446 }
6447 /* 'viewoptions' */
6448 else if (varp == &p_vop)
6449 {
6450 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6451 errmsg = e_invarg;
6452 }
6453#endif
6454
6455 /* 'scrollopt' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006456 else if (varp == &p_sbo)
6457 {
6458 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6459 errmsg = e_invarg;
6460 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006461
6462 /* 'ambiwidth' */
Bram Moolenaar3848e002016-03-19 18:42:29 +01006463 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006464 {
6465 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6466 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006467 else if (set_chars_option(&p_lcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006468 errmsg = _("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006469 else if (set_chars_option(&p_fcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006470 errmsg = _("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006471 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006472
6473 /* 'background' */
6474 else if (varp == &p_bg)
6475 {
6476 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6477 {
6478#ifdef FEAT_EVAL
6479 int dark = (*p_bg == 'd');
6480#endif
6481
6482 init_highlight(FALSE, FALSE);
6483
6484#ifdef FEAT_EVAL
6485 if (dark != (*p_bg == 'd')
6486 && get_var_value((char_u *)"g:colors_name") != NULL)
6487 {
6488 /* The color scheme must have set 'background' back to another
6489 * value, that's not what we want here. Disable the color
6490 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006491 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006492 free_string_option(p_bg);
6493 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6494 check_string_option(&p_bg);
6495 init_highlight(FALSE, FALSE);
6496 }
6497#endif
6498 }
6499 else
6500 errmsg = e_invarg;
6501 }
6502
6503 /* 'wildmode' */
6504 else if (varp == &p_wim)
6505 {
6506 if (check_opt_wim() == FAIL)
6507 errmsg = e_invarg;
6508 }
6509
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006510 /* 'wildoptions' */
6511 else if (varp == &p_wop)
6512 {
6513 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6514 errmsg = e_invarg;
6515 }
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006516
Bram Moolenaar071d4272004-06-13 20:20:40 +00006517#ifdef FEAT_WAK
6518 /* 'winaltkeys' */
6519 else if (varp == &p_wak)
6520 {
6521 if (*p_wak == NUL
6522 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6523 errmsg = e_invarg;
6524# ifdef FEAT_MENU
6525# ifdef FEAT_GUI_MOTIF
6526 else if (gui.in_use)
6527 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6528# else
6529# ifdef FEAT_GUI_GTK
6530 else if (gui.in_use)
6531 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6532# endif
6533# endif
6534# endif
6535 }
6536#endif
6537
Bram Moolenaar071d4272004-06-13 20:20:40 +00006538 /* 'eventignore' */
6539 else if (varp == &p_ei)
6540 {
6541 if (check_ei() == FAIL)
6542 errmsg = e_invarg;
6543 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006544
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006545 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6546 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6547 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006548 {
6549 if (gvarp == &p_fenc)
6550 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006551 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006552 errmsg = e_modifiable;
6553 else if (vim_strchr(*varp, ',') != NULL)
6554 /* No comma allowed in 'fileencoding'; catches confusing it
6555 * with 'fileencodings'. */
6556 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006557 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006558 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006559#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006560 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006561 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006562#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006563 /* Add 'fileencoding' to the swap file. */
6564 ml_setflags(curbuf);
6565 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006566 }
6567 if (errmsg == NULL)
6568 {
6569 /* canonize the value, so that STRCMP() can be used on it */
6570 p = enc_canonize(*varp);
6571 if (p != NULL)
6572 {
6573 vim_free(*varp);
6574 *varp = p;
6575 }
6576 if (varp == &p_enc)
6577 {
6578 errmsg = mb_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006579#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006580 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006581#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006582 }
6583 }
6584
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006585#if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006586 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6587 {
6588 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6589 if (STRCMP(p_tenc, "utf-8") != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006590 errmsg = N_("E617: Cannot be changed in the GTK+ 2 GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006591 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006592#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006593
6594 if (errmsg == NULL)
6595 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006596#ifdef FEAT_KEYMAP
Bram Moolenaar071d4272004-06-13 20:20:40 +00006597 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6598 * (with another encoding). */
6599 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6600 (void)keymap_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006601#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006602
6603 /* When 'termencoding' is not empty and 'encoding' changes or when
6604 * 'termencoding' changes, need to setup for keyboard input and
6605 * display output conversion. */
6606 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6607 {
Bram Moolenaar17471e82017-11-26 23:47:18 +01006608 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6609 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6610 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006611 semsg(_("E950: Cannot convert between %s and %s"),
Bram Moolenaar17471e82017-11-26 23:47:18 +01006612 p_tenc, p_enc);
6613 errmsg = e_invarg;
6614 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006615 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006616
Bram Moolenaar4f974752019-02-17 17:44:42 +01006617#if defined(MSWIN)
Bram Moolenaar05159a02005-02-26 23:04:13 +00006618 /* $HOME may have characters in active code page. */
6619 if (varp == &p_enc)
6620 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006621#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006622 }
6623 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006624
6625#if defined(FEAT_POSTSCRIPT)
6626 else if (varp == &p_penc)
6627 {
6628 /* Canonize printencoding if VIM standard one */
6629 p = enc_canonize(p_penc);
6630 if (p != NULL)
6631 {
6632 vim_free(p_penc);
6633 p_penc = p;
6634 }
6635 else
6636 {
6637 /* Ensure lower case and '-' for '_' */
6638 for (s = p_penc; *s != NUL; s++)
6639 {
6640 if (*s == '_')
6641 *s = '-';
6642 else
6643 *s = TOLOWER_ASC(*s);
6644 }
6645 }
6646 }
6647#endif
6648
Bram Moolenaar9372a112005-12-06 19:59:18 +00006649#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006650 else if (varp == &p_imak)
6651 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006652 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006653 errmsg = e_invarg;
6654 }
6655#endif
6656
6657#ifdef FEAT_KEYMAP
6658 else if (varp == &curbuf->b_p_keymap)
6659 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006660 if (!valid_filetype(*varp))
6661 errmsg = e_invarg;
6662 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01006663 {
6664 int secure_save = secure;
6665
6666 // Reset the secure flag, since the value of 'keymap' has
6667 // been checked to be safe.
6668 secure = 0;
6669
6670 // load or unload key mapping tables
Bram Moolenaard0b51382016-11-04 15:23:45 +01006671 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006672
Bram Moolenaar916a8182018-11-25 02:18:29 +01006673 secure = secure_save;
6674
6675 // Since we check the value, there is no need to set P_INSECURE,
6676 // even when the value comes from a modeline.
6677 *value_checked = TRUE;
6678 }
6679
Bram Moolenaarfab06232009-03-04 03:13:35 +00006680 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006681 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006682 if (*curbuf->b_p_keymap != NUL)
6683 {
6684 /* Installed a new keymap, switch on using it. */
6685 curbuf->b_p_iminsert = B_IMODE_LMAP;
6686 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6687 curbuf->b_p_imsearch = B_IMODE_LMAP;
6688 }
6689 else
6690 {
6691 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6692 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6693 curbuf->b_p_iminsert = B_IMODE_NONE;
6694 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6695 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6696 }
6697 if ((opt_flags & OPT_LOCAL) == 0)
6698 {
6699 set_iminsert_global();
6700 set_imsearch_global();
6701 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006702 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006703 }
6704 }
6705#endif
6706
6707 /* 'fileformat' */
6708 else if (gvarp == &p_ff)
6709 {
6710 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6711 errmsg = e_modifiable;
6712 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6713 errmsg = e_invarg;
6714 else
6715 {
6716 /* may also change 'textmode' */
6717 if (get_fileformat(curbuf) == EOL_DOS)
6718 curbuf->b_p_tx = TRUE;
6719 else
6720 curbuf->b_p_tx = FALSE;
6721#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006722 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006723#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006724 /* update flag in swap file */
6725 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006726 /* Redraw needed when switching to/from "mac": a CR in the text
6727 * will be displayed differently. */
6728 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6729 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006730 }
6731 }
6732
6733 /* 'fileformats' */
6734 else if (varp == &p_ffs)
6735 {
6736 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6737 errmsg = e_invarg;
6738 else
6739 {
6740 /* also change 'textauto' */
6741 if (*p_ffs == NUL)
6742 p_ta = FALSE;
6743 else
6744 p_ta = TRUE;
6745 }
6746 }
6747
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006748#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006749 /* 'cryptkey' */
6750 else if (gvarp == &p_key)
6751 {
Bram Moolenaard7663c22019-08-06 21:59:57 +02006752 // Make sure the ":set" command doesn't show the new value in the
6753 // history.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006754 remove_key_from_history();
Bram Moolenaard7663c22019-08-06 21:59:57 +02006755
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006756 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6757 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006758 ml_set_crypt_key(curbuf, oldval,
6759 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006760 }
6761
6762 else if (gvarp == &p_cm)
6763 {
6764 if (opt_flags & OPT_LOCAL)
6765 p = curbuf->b_p_cm;
6766 else
6767 p = p_cm;
6768 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6769 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006770 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006771 errmsg = e_invarg;
6772 else
6773 {
6774 /* When setting the global value to empty, make it "zip". */
6775 if (*p_cm == NUL)
6776 {
6777 if (new_value_alloced)
6778 free_string_option(p_cm);
6779 p_cm = vim_strsave((char_u *)"zip");
6780 new_value_alloced = TRUE;
6781 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006782 /* When using ":set cm=name" the local value is going to be empty.
6783 * Do that here, otherwise the crypt functions will still use the
6784 * local value. */
6785 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6786 {
6787 free_string_option(curbuf->b_p_cm);
6788 curbuf->b_p_cm = empty_option;
6789 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006790
6791 /* Need to update the swapfile when the effective method changed.
6792 * Set "s" to the effective old value, "p" to the effective new
6793 * method and compare. */
6794 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6795 s = p_cm; /* was previously using the global value */
6796 else
6797 s = oldval;
6798 if (*curbuf->b_p_cm == NUL)
6799 p = p_cm; /* is now using the global value */
6800 else
6801 p = curbuf->b_p_cm;
6802 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006803 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006804
6805 /* If the global value changes need to update the swapfile for all
6806 * buffers using that value. */
6807 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6808 {
6809 buf_T *buf;
6810
Bram Moolenaar29323592016-07-24 22:04:11 +02006811 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006812 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006813 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006814 }
6815 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006816 }
6817#endif
6818
6819 /* 'matchpairs' */
6820 else if (gvarp == &p_mps)
6821 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006822 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006823 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006824 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006825 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006826 int x2 = -1;
6827 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006828
6829 if (*p != NUL)
6830 p += mb_ptr2len(p);
6831 if (*p != NUL)
6832 x2 = *p++;
6833 if (*p != NUL)
6834 {
6835 x3 = mb_ptr2char(p);
6836 p += mb_ptr2len(p);
6837 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006838 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006839 {
6840 errmsg = e_invarg;
6841 break;
6842 }
6843 if (*p == NUL)
6844 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006845 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006846 }
6847 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006848 {
6849 /* Check for "x:y,x:y" */
6850 for (p = *varp; *p != NUL; p += 4)
6851 {
6852 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6853 {
6854 errmsg = e_invarg;
6855 break;
6856 }
6857 if (p[3] == NUL)
6858 break;
6859 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006860 }
6861 }
6862
6863#ifdef FEAT_COMMENTS
6864 /* 'comments' */
6865 else if (gvarp == &p_com)
6866 {
6867 for (s = *varp; *s; )
6868 {
6869 while (*s && *s != ':')
6870 {
6871 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6872 && !VIM_ISDIGIT(*s) && *s != '-')
6873 {
6874 errmsg = illegal_char(errbuf, *s);
6875 break;
6876 }
6877 ++s;
6878 }
6879 if (*s++ == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006880 errmsg = N_("E524: Missing colon");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006881 else if (*s == ',' || *s == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006882 errmsg = N_("E525: Zero length string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006883 if (errmsg != NULL)
6884 break;
6885 while (*s && *s != ',')
6886 {
6887 if (*s == '\\' && s[1] != NUL)
6888 ++s;
6889 ++s;
6890 }
6891 s = skip_to_option_part(s);
6892 }
6893 }
6894#endif
6895
6896 /* 'listchars' */
6897 else if (varp == &p_lcs)
6898 {
6899 errmsg = set_chars_option(varp);
6900 }
6901
Bram Moolenaar071d4272004-06-13 20:20:40 +00006902 /* 'fillchars' */
6903 else if (varp == &p_fcs)
6904 {
6905 errmsg = set_chars_option(varp);
6906 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006907
6908#ifdef FEAT_CMDWIN
6909 /* 'cedit' */
6910 else if (varp == &p_cedit)
6911 {
6912 errmsg = check_cedit();
6913 }
6914#endif
6915
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006916 /* 'verbosefile' */
6917 else if (varp == &p_vfile)
6918 {
6919 verbose_stop();
6920 if (*p_vfile != NUL && verbose_open() == FAIL)
6921 errmsg = e_invarg;
6922 }
6923
Bram Moolenaar071d4272004-06-13 20:20:40 +00006924#ifdef FEAT_VIMINFO
6925 /* 'viminfo' */
6926 else if (varp == &p_viminfo)
6927 {
6928 for (s = p_viminfo; *s;)
6929 {
6930 /* Check it's a valid character */
6931 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6932 {
6933 errmsg = illegal_char(errbuf, *s);
6934 break;
6935 }
6936 if (*s == 'n') /* name is always last one */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006937 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006938 else if (*s == 'r') /* skip until next ',' */
6939 {
6940 while (*++s && *s != ',')
6941 ;
6942 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006943 else if (*s == '%')
6944 {
6945 /* optional number */
6946 while (vim_isdigit(*++s))
6947 ;
6948 }
6949 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006950 ++s; /* no extra chars */
6951 else /* must have a number */
6952 {
6953 while (vim_isdigit(*++s))
6954 ;
6955
6956 if (!VIM_ISDIGIT(*(s - 1)))
6957 {
6958 if (errbuf != NULL)
6959 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006960 sprintf(errbuf, _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006961 transchar_byte(*(s - 1)));
6962 errmsg = errbuf;
6963 }
6964 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006965 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006966 break;
6967 }
6968 }
6969 if (*s == ',')
6970 ++s;
6971 else if (*s)
6972 {
6973 if (errbuf != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006974 errmsg = N_("E527: Missing comma");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006975 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006976 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006977 break;
6978 }
6979 }
6980 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006981 errmsg = N_("E528: Must specify a ' value");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006982 }
6983#endif /* FEAT_VIMINFO */
6984
6985 /* terminal options */
6986 else if (istermoption(&options[opt_idx]) && full_screen)
6987 {
6988 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6989 if (varp == &T_CCO)
6990 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006991 int colors = atoi((char *)T_CCO);
6992
6993 /* Only reinitialize colors if t_Co value has really changed to
6994 * avoid expensive reload of colorscheme if t_Co is set to the
6995 * same value multiple times. */
6996 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006997 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006998 t_colors = colors;
6999 if (t_colors <= 1)
7000 {
7001 if (new_value_alloced)
7002 vim_free(T_CCO);
7003 T_CCO = empty_option;
7004 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007005#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
7006 if (is_term_win32())
7007 {
7008 swap_tcap();
7009 did_swaptcap = TRUE;
7010 }
7011#endif
Bram Moolenaarc84e8952009-03-18 13:21:18 +00007012 /* We now have a different color setup, initialize it again. */
7013 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007014 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007015 }
7016 ttest(FALSE);
7017 if (varp == &T_ME)
7018 {
7019 out_str(T_ME);
7020 redraw_later(CLEAR);
Bram Moolenaarafde13b2019-04-28 19:46:49 +02007021#if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007022 /* Since t_me has been set, this probably means that the user
7023 * wants to use this as default colors. Need to reset default
7024 * background/foreground colors. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02007025# ifdef VIMDLL
7026 if (!gui.in_use && !gui.starting)
7027# endif
7028 mch_set_normal_colors();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007029#endif
7030 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01007031 if (varp == &T_BE && termcap_active)
7032 {
7033 if (*T_BE == NUL)
7034 /* When clearing t_BE we assume the user no longer wants
7035 * bracketed paste, thus disable it by writing t_BD. */
7036 out_str(T_BD);
7037 else
7038 out_str(T_BE);
7039 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007040 }
7041
7042#ifdef FEAT_LINEBREAK
7043 /* 'showbreak' */
7044 else if (varp == &p_sbr)
7045 {
7046 for (s = p_sbr; *s; )
7047 {
7048 if (ptr2cells(s) != 1)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007049 errmsg = N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01007050 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007051 }
7052 }
7053#endif
7054
7055#ifdef FEAT_GUI
7056 /* 'guifont' */
7057 else if (varp == &p_guifont)
7058 {
7059 if (gui.in_use)
7060 {
7061 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00007062# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007063 /*
7064 * Put up a font dialog and let the user select a new value.
7065 * If this is cancelled go back to the old value but don't
7066 * give an error message.
7067 */
7068 if (STRCMP(p, "*") == 0)
7069 {
7070 p = gui_mch_font_dialog(oldval);
7071
7072 if (new_value_alloced)
7073 free_string_option(p_guifont);
7074
7075 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
7076 new_value_alloced = TRUE;
7077 }
7078# endif
7079 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
7080 {
7081# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
7082 if (STRCMP(p_guifont, "*") == 0)
7083 {
7084 /* Dialog was cancelled: Keep the old value without giving
7085 * an error message. */
7086 if (new_value_alloced)
7087 free_string_option(p_guifont);
7088 p_guifont = vim_strsave(oldval);
7089 new_value_alloced = TRUE;
7090 }
7091 else
7092# endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007093 errmsg = N_("E596: Invalid font(s)");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007094 }
7095 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007096 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007097 }
7098# ifdef FEAT_XFONTSET
7099 else if (varp == &p_guifontset)
7100 {
7101 if (STRCMP(p_guifontset, "*") == 0)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007102 errmsg = N_("E597: can't select fontset");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007103 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007104 errmsg = N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007105 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007106 }
7107# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007108 else if (varp == &p_guifontwide)
7109 {
7110 if (STRCMP(p_guifontwide, "*") == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007111 errmsg = N_("E533: can't select wide font");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007112 else if (gui_get_wide_font() == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007113 errmsg = N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007114 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007115 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007116#endif
7117
7118#ifdef CURSOR_SHAPE
7119 /* 'guicursor' */
7120 else if (varp == &p_guicursor)
7121 errmsg = parse_shape_opt(SHAPE_CURSOR);
7122#endif
7123
7124#ifdef FEAT_MOUSESHAPE
7125 /* 'mouseshape' */
7126 else if (varp == &p_mouseshape)
7127 {
7128 errmsg = parse_shape_opt(SHAPE_MOUSE);
7129 update_mouseshape(-1);
7130 }
7131#endif
7132
7133#ifdef FEAT_PRINTER
7134 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00007135 errmsg = parse_printoptions();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01007136# if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00007137 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00007138 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00007139# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007140#endif
7141
7142#ifdef FEAT_LANGMAP
7143 /* 'langmap' */
7144 else if (varp == &p_langmap)
7145 langmap_set();
7146#endif
7147
7148#ifdef FEAT_LINEBREAK
7149 /* 'breakat' */
7150 else if (varp == &p_breakat)
7151 fill_breakat_flags();
7152#endif
7153
7154#ifdef FEAT_TITLE
7155 /* 'titlestring' and 'iconstring' */
7156 else if (varp == &p_titlestring || varp == &p_iconstring)
7157 {
7158# ifdef FEAT_STL_OPT
7159 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
7160
7161 /* NULL => statusline syntax */
7162 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
7163 stl_syntax |= flagval;
7164 else
7165 stl_syntax &= ~flagval;
7166# endif
Bram Moolenaar84a93082018-06-16 22:58:15 +02007167 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007168 }
7169#endif
7170
7171#ifdef FEAT_GUI
7172 /* 'guioptions' */
7173 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007174 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007175 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007176 redraw_gui_only = TRUE;
7177 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007178#endif
7179
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00007180#if defined(FEAT_GUI_TABLINE)
7181 /* 'guitablabel' */
7182 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007183 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00007184 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007185 redraw_gui_only = TRUE;
7186 }
7187 /* 'guitabtooltip' */
7188 else if (varp == &p_gtt)
7189 {
7190 redraw_gui_only = TRUE;
7191 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00007192#endif
7193
Bram Moolenaar071d4272004-06-13 20:20:40 +00007194#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
7195 /* 'ttymouse' */
7196 else if (varp == &p_ttym)
7197 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007198 /* Switch the mouse off before changing the escape sequences used for
7199 * that. */
7200 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007201 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
7202 errmsg = e_invarg;
7203 else
7204 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00007205 if (termcap_active)
7206 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007207 }
7208#endif
7209
Bram Moolenaar071d4272004-06-13 20:20:40 +00007210 /* 'selection' */
7211 else if (varp == &p_sel)
7212 {
7213 if (*p_sel == NUL
7214 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
7215 errmsg = e_invarg;
7216 }
7217
7218 /* 'selectmode' */
7219 else if (varp == &p_slm)
7220 {
7221 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
7222 errmsg = e_invarg;
7223 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007224
7225#ifdef FEAT_BROWSE
7226 /* 'browsedir' */
7227 else if (varp == &p_bsdir)
7228 {
7229 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7230 && !mch_isdir(p_bsdir))
7231 errmsg = e_invarg;
7232 }
7233#endif
7234
Bram Moolenaar071d4272004-06-13 20:20:40 +00007235 /* 'keymodel' */
7236 else if (varp == &p_km)
7237 {
7238 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7239 errmsg = e_invarg;
7240 else
7241 {
7242 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7243 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7244 }
7245 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007246
7247 /* 'mousemodel' */
7248 else if (varp == &p_mousem)
7249 {
7250 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7251 errmsg = e_invarg;
7252#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7253 else if (*p_mousem != *oldval)
7254 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7255 * to create or delete the popup menus. */
7256 gui_motif_update_mousemodel(root_menu);
7257#endif
7258 }
7259
7260 /* 'switchbuf' */
7261 else if (varp == &p_swb)
7262 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007263 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007264 errmsg = e_invarg;
7265 }
7266
7267 /* 'debug' */
7268 else if (varp == &p_debug)
7269 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007270 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007271 errmsg = e_invarg;
7272 }
7273
7274 /* 'display' */
7275 else if (varp == &p_dy)
7276 {
7277 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7278 errmsg = e_invarg;
7279 else
7280 (void)init_chartab();
7281
7282 }
7283
Bram Moolenaar071d4272004-06-13 20:20:40 +00007284 /* 'eadirection' */
7285 else if (varp == &p_ead)
7286 {
7287 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7288 errmsg = e_invarg;
7289 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007290
7291#ifdef FEAT_CLIPBOARD
7292 /* 'clipboard' */
7293 else if (varp == &p_cb)
7294 errmsg = check_clipboard_option();
7295#endif
7296
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007297#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007298 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7299 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007300 else if (varp == &(curwin->w_s->b_p_spl)
7301 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007302 {
Bram Moolenaar862f1e12019-04-10 22:33:41 +02007303 int is_spellfile = varp == &(curwin->w_s->b_p_spf);
7304
7305 if ((is_spellfile && !valid_spellfile(*varp))
7306 || (!is_spellfile && !valid_spellang(*varp)))
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02007307 errmsg = e_invarg;
7308 else
Bram Moolenaar862f1e12019-04-10 22:33:41 +02007309 errmsg = did_set_spell_option(is_spellfile);
Bram Moolenaar217ad922005-03-20 22:37:15 +00007310 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007311 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007312 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007313 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007314 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007315 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007316 /* 'spellsuggest' */
7317 else if (varp == &p_sps)
7318 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007319 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007320 errmsg = e_invarg;
7321 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007322 /* 'mkspellmem' */
7323 else if (varp == &p_msm)
7324 {
7325 if (spell_check_msm() != OK)
7326 errmsg = e_invarg;
7327 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007328#endif
7329
Bram Moolenaar071d4272004-06-13 20:20:40 +00007330 /* When 'bufhidden' is set, check for valid value. */
7331 else if (gvarp == &p_bh)
7332 {
7333 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7334 errmsg = e_invarg;
7335 }
7336
7337 /* When 'buftype' is set, check for valid value. */
7338 else if (gvarp == &p_bt)
7339 {
7340 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7341 errmsg = e_invarg;
7342 else
7343 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007344 if (curwin->w_status_height)
7345 {
7346 curwin->w_redr_status = TRUE;
7347 redraw_later(VALID);
7348 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007349 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007350#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007351 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007352#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007353 }
7354 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007355
7356#ifdef FEAT_STL_OPT
7357 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007358 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007359 {
7360 int wid;
7361
7362 if (varp == &p_ruf) /* reset ru_wid first */
7363 ru_wid = 0;
7364 s = *varp;
7365 if (varp == &p_ruf && *s == '%')
7366 {
7367 /* set ru_wid if 'ruf' starts with "%99(" */
7368 if (*++s == '-') /* ignore a '-' */
7369 s++;
7370 wid = getdigits(&s);
7371 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7372 ru_wid = wid;
7373 else
7374 errmsg = check_stl_option(p_ruf);
7375 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007376 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007377 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007378 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007379 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007380 comp_col();
7381 }
7382#endif
7383
7384#ifdef FEAT_INS_EXPAND
7385 /* check if it is a valid value for 'complete' -- Acevedo */
7386 else if (gvarp == &p_cpt)
7387 {
7388 for (s = *varp; *s;)
7389 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007390 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007391 s++;
7392 if (!*s)
7393 break;
7394 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7395 {
7396 errmsg = illegal_char(errbuf, *s);
7397 break;
7398 }
7399 if (*++s != NUL && *s != ',' && *s != ' ')
7400 {
7401 if (s[-1] == 'k' || s[-1] == 's')
7402 {
7403 /* skip optional filename after 'k' and 's' */
7404 while (*s && *s != ',' && *s != ' ')
7405 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007406 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007407 ++s;
7408 ++s;
7409 }
7410 }
7411 else
7412 {
7413 if (errbuf != NULL)
7414 {
7415 sprintf((char *)errbuf,
7416 _("E535: Illegal character after <%c>"),
7417 *--s);
7418 errmsg = errbuf;
7419 }
7420 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007421 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00007422 break;
7423 }
7424 }
7425 }
7426 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007427
Bram Moolenaarac3150d2019-07-28 16:36:39 +02007428 // 'completeopt'
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007429 else if (varp == &p_cot)
7430 {
7431 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7432 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007433 else
7434 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007435 }
Bram Moolenaarac3150d2019-07-28 16:36:39 +02007436
7437# ifdef BACKSLASH_IN_FILENAME
7438 // 'completeslash'
Bram Moolenaarb78564d2019-07-28 19:24:36 +02007439 else if (gvarp == &p_csl)
Bram Moolenaarac3150d2019-07-28 16:36:39 +02007440 {
Bram Moolenaarb78564d2019-07-28 19:24:36 +02007441 if (check_opt_strings(p_csl, p_csl_values, FALSE) != OK
7442 || check_opt_strings(curbuf->b_p_csl, p_csl_values, FALSE) != OK)
Bram Moolenaarac3150d2019-07-28 16:36:39 +02007443 errmsg = e_invarg;
7444 }
7445# endif
7446#endif // FEAT_INS_EXPAND
Bram Moolenaar071d4272004-06-13 20:20:40 +00007447
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007448#ifdef FEAT_SIGNS
Bram Moolenaare4b407f2019-07-04 11:59:28 +02007449 // 'signcolumn'
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007450 else if (varp == &curwin->w_p_scl)
7451 {
7452 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7453 errmsg = e_invarg;
Bram Moolenaare4b407f2019-07-04 11:59:28 +02007454 // When changing the 'signcolumn' to or from 'number', recompute the
7455 // width of the number column if 'number' or 'relativenumber' is set.
7456 if (((*oldval == 'n' && *(oldval + 1) == 'u')
7457 || (*curwin->w_p_scl == 'n' && *(curwin->w_p_scl + 1) =='u'))
7458 && (curwin->w_p_nu || curwin->w_p_rnu))
7459 curwin->w_nrwidth_line_count = 0;
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007460 }
7461#endif
7462
Bram Moolenaar071d4272004-06-13 20:20:40 +00007463
Bram Moolenaar4f974752019-02-17 17:44:42 +01007464#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007465 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007466 else if (varp == &p_toolbar)
7467 {
7468 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7469 &toolbar_flags, TRUE) != OK)
7470 errmsg = e_invarg;
7471 else
7472 {
7473 out_flush();
7474 gui_mch_show_toolbar((toolbar_flags &
7475 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7476 }
7477 }
7478#endif
7479
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007480#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007481 /* 'toolbariconsize': GTK+ 2 only */
7482 else if (varp == &p_tbis)
7483 {
7484 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7485 errmsg = e_invarg;
7486 else
7487 {
7488 out_flush();
7489 gui_mch_show_toolbar((toolbar_flags &
7490 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7491 }
7492 }
7493#endif
7494
7495 /* 'pastetoggle': translate key codes like in a mapping */
7496 else if (varp == &p_pt)
7497 {
7498 if (*p_pt)
7499 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007500 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007501 if (p != NULL)
7502 {
7503 if (new_value_alloced)
7504 free_string_option(p_pt);
7505 p_pt = p;
7506 new_value_alloced = TRUE;
7507 }
7508 }
7509 }
7510
7511 /* 'backspace' */
7512 else if (varp == &p_bs)
7513 {
7514 if (VIM_ISDIGIT(*p_bs))
7515 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007516 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007517 errmsg = e_invarg;
7518 }
7519 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7520 errmsg = e_invarg;
7521 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007522 else if (varp == &p_bo)
7523 {
7524 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7525 errmsg = e_invarg;
7526 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007527
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007528 /* 'tagcase' */
7529 else if (gvarp == &p_tc)
7530 {
7531 unsigned int *flags;
7532
7533 if (opt_flags & OPT_LOCAL)
7534 {
7535 p = curbuf->b_p_tc;
7536 flags = &curbuf->b_tc_flags;
7537 }
7538 else
7539 {
7540 p = p_tc;
7541 flags = &tc_flags;
7542 }
7543
7544 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7545 /* make the local value empty: use the global value */
7546 *flags = 0;
7547 else if (*p == NUL
7548 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7549 errmsg = e_invarg;
7550 }
7551
Bram Moolenaar071d4272004-06-13 20:20:40 +00007552 /* 'casemap' */
7553 else if (varp == &p_cmp)
7554 {
7555 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7556 errmsg = e_invarg;
7557 }
7558
7559#ifdef FEAT_DIFF
7560 /* 'diffopt' */
7561 else if (varp == &p_dip)
7562 {
7563 if (diffopt_changed() == FAIL)
7564 errmsg = e_invarg;
7565 }
7566#endif
7567
7568#ifdef FEAT_FOLDING
7569 /* 'foldmethod' */
7570 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7571 {
7572 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7573 || *curwin->w_p_fdm == NUL)
7574 errmsg = e_invarg;
7575 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007576 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007577 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007578 if (foldmethodIsDiff(curwin))
7579 newFoldLevel();
7580 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007581 }
7582# ifdef FEAT_EVAL
7583 /* 'foldexpr' */
7584 else if (varp == &curwin->w_p_fde)
7585 {
7586 if (foldmethodIsExpr(curwin))
7587 foldUpdateAll(curwin);
7588 }
7589# endif
7590 /* 'foldmarker' */
7591 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7592 {
7593 p = vim_strchr(*varp, ',');
7594 if (p == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007595 errmsg = N_("E536: comma required");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007596 else if (p == *varp || p[1] == NUL)
7597 errmsg = e_invarg;
7598 else if (foldmethodIsMarker(curwin))
7599 foldUpdateAll(curwin);
7600 }
7601 /* 'commentstring' */
7602 else if (gvarp == &p_cms)
7603 {
7604 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007605 errmsg = N_("E537: 'commentstring' must be empty or contain %s");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007606 }
7607 /* 'foldopen' */
7608 else if (varp == &p_fdo)
7609 {
7610 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7611 errmsg = e_invarg;
7612 }
7613 /* 'foldclose' */
7614 else if (varp == &p_fcl)
7615 {
7616 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7617 errmsg = e_invarg;
7618 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007619 /* 'foldignore' */
7620 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7621 {
7622 if (foldmethodIsIndent(curwin))
7623 foldUpdateAll(curwin);
7624 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007625#endif
7626
Bram Moolenaar071d4272004-06-13 20:20:40 +00007627 /* 'virtualedit' */
7628 else if (varp == &p_ve)
7629 {
7630 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7631 errmsg = e_invarg;
7632 else if (STRCMP(p_ve, oldval) != 0)
7633 {
7634 /* Recompute cursor position in case the new 've' setting
7635 * changes something. */
7636 validate_virtcol();
7637 coladvance(curwin->w_virtcol);
7638 }
7639 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007640
7641#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7642 else if (varp == &p_csqf)
7643 {
7644 if (p_csqf != NULL)
7645 {
7646 p = p_csqf;
7647 while (*p != NUL)
7648 {
7649 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7650 || p[1] == NUL
7651 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7652 || (p[2] != NUL && p[2] != ','))
7653 {
7654 errmsg = e_invarg;
7655 break;
7656 }
7657 else if (p[2] == NUL)
7658 break;
7659 else
7660 p += 3;
7661 }
7662 }
7663 }
7664#endif
7665
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007666#ifdef FEAT_CINDENT
7667 /* 'cinoptions' */
7668 else if (gvarp == &p_cino)
7669 {
7670 /* TODO: recognize errors */
7671 parse_cino(curbuf);
7672 }
7673#endif
7674
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007675#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007676 /* 'renderoptions' */
Bram Moolenaar3767c6e2017-12-05 16:57:56 +01007677 else if (varp == &p_rop)
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007678 {
7679 if (!gui_mch_set_rendering_options(p_rop))
7680 errmsg = e_invarg;
7681 }
7682#endif
7683
Bram Moolenaard0b51382016-11-04 15:23:45 +01007684 else if (gvarp == &p_ft)
7685 {
7686 if (!valid_filetype(*varp))
7687 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007688 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007689 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007690 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007691
7692 // Since we check the value, there is no need to set P_INSECURE,
7693 // even when the value comes from a modeline.
7694 *value_checked = TRUE;
7695 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007696 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007697
7698#ifdef FEAT_SYN_HL
7699 else if (gvarp == &p_syn)
7700 {
7701 if (!valid_filetype(*varp))
7702 errmsg = e_invarg;
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007703 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007704 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007705 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007706
7707 // Since we check the value, there is no need to set P_INSECURE,
7708 // even when the value comes from a modeline.
7709 *value_checked = TRUE;
7710 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007711 }
7712#endif
7713
Bram Moolenaar825680f2017-07-22 17:04:02 +02007714#ifdef FEAT_TERMINAL
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007715 // 'termwinkey'
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007716 else if (varp == &curwin->w_p_twk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007717 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007718 if (*curwin->w_p_twk != NUL
7719 && string_to_key(curwin->w_p_twk, TRUE) == 0)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007720 errmsg = e_invarg;
7721 }
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007722 // 'termwinsize'
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007723 else if (varp == &curwin->w_p_tws)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007724 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007725 if (*curwin->w_p_tws != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007726 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007727 p = skipdigits(curwin->w_p_tws);
7728 if (p == curwin->w_p_tws
Bram Moolenaar498c2562018-04-15 23:45:15 +02007729 || (*p != 'x' && *p != '*')
7730 || *skipdigits(p + 1) != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007731 errmsg = e_invarg;
7732 }
7733 }
Bram Moolenaar4f974752019-02-17 17:44:42 +01007734# if defined(MSWIN)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007735 // 'termwintype'
7736 else if (varp == &p_twt)
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007737 {
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007738 if (check_opt_strings(*varp, p_twt_values, FALSE) != OK)
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007739 errmsg = e_invarg;
7740 }
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007741# endif
Bram Moolenaar825680f2017-07-22 17:04:02 +02007742#endif
7743
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007744#ifdef FEAT_VARTABS
7745 /* 'varsofttabstop' */
7746 else if (varp == &(curbuf->b_p_vsts))
7747 {
7748 char_u *cp;
7749
7750 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7751 {
7752 if (curbuf->b_p_vsts_array)
7753 {
7754 vim_free(curbuf->b_p_vsts_array);
7755 curbuf->b_p_vsts_array = 0;
7756 }
7757 }
7758 else
7759 {
7760 for (cp = *varp; *cp; ++cp)
7761 {
7762 if (vim_isdigit(*cp))
7763 continue;
7764 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7765 continue;
7766 errmsg = e_invarg;
7767 break;
7768 }
7769 if (errmsg == NULL)
7770 {
7771 int *oldarray = curbuf->b_p_vsts_array;
7772 if (tabstop_set(*varp, &(curbuf->b_p_vsts_array)))
7773 {
7774 if (oldarray)
7775 vim_free(oldarray);
7776 }
7777 else
7778 errmsg = e_invarg;
7779 }
7780 }
7781 }
7782
7783 /* 'vartabstop' */
7784 else if (varp == &(curbuf->b_p_vts))
7785 {
7786 char_u *cp;
7787
7788 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7789 {
7790 if (curbuf->b_p_vts_array)
7791 {
7792 vim_free(curbuf->b_p_vts_array);
7793 curbuf->b_p_vts_array = NULL;
7794 }
7795 }
7796 else
7797 {
7798 for (cp = *varp; *cp; ++cp)
7799 {
7800 if (vim_isdigit(*cp))
7801 continue;
7802 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7803 continue;
7804 errmsg = e_invarg;
7805 break;
7806 }
7807 if (errmsg == NULL)
7808 {
7809 int *oldarray = curbuf->b_p_vts_array;
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007810
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007811 if (tabstop_set(*varp, &(curbuf->b_p_vts_array)))
7812 {
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007813 vim_free(oldarray);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007814#ifdef FEAT_FOLDING
7815 if (foldmethodIsIndent(curwin))
7816 foldUpdateAll(curwin);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007817#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007818 }
7819 else
7820 errmsg = e_invarg;
7821 }
7822 }
7823 }
7824#endif
7825
Bram Moolenaar79648732019-07-18 21:43:07 +02007826#ifdef FEAT_TEXT_PROP
7827 // 'previewpopup'
7828 else if (varp == &p_pvp)
7829 {
7830 if (parse_previewpopup(NULL) == FAIL)
7831 errmsg = e_invarg;
7832 }
Bram Moolenaar36e4d982019-08-20 21:12:16 +02007833# ifdef FEAT_QUICKFIX
Bram Moolenaar62a0cb42019-08-18 16:35:23 +02007834 // 'completepopup'
7835 else if (varp == &p_cpp)
7836 {
7837 if (parse_completepopup(NULL) == FAIL)
7838 errmsg = e_invarg;
7839 }
Bram Moolenaar36e4d982019-08-20 21:12:16 +02007840# endif
Bram Moolenaar79648732019-07-18 21:43:07 +02007841#endif
7842
Bram Moolenaar071d4272004-06-13 20:20:40 +00007843 /* Options that are a list of flags. */
7844 else
7845 {
7846 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007847 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007848 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007849 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007850 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007851 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007852 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007853 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007854 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007855#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007856 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007857 p = (char_u *)COCU_ALL;
7858#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007859 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007860 {
7861#ifdef FEAT_MOUSE
7862 p = (char_u *)MOUSE_ALL;
7863#else
7864 if (*p_mouse != NUL)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007865 errmsg = N_("E538: No mouse support");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007866#endif
7867 }
7868#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007869 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007870 p = (char_u *)GO_ALL;
7871#endif
7872 if (p != NULL)
7873 {
7874 for (s = *varp; *s; ++s)
7875 if (vim_strchr(p, *s) == NULL)
7876 {
7877 errmsg = illegal_char(errbuf, *s);
7878 break;
7879 }
7880 }
7881 }
7882
7883 /*
7884 * If error detected, restore the previous value.
7885 */
7886 if (errmsg != NULL)
7887 {
7888 if (new_value_alloced)
7889 free_string_option(*varp);
7890 *varp = oldval;
7891 /*
7892 * When resetting some values, need to act on it.
7893 */
7894 if (did_chartab)
7895 (void)init_chartab();
7896 if (varp == &p_hl)
7897 (void)highlight_changed();
7898 }
7899 else
7900 {
7901#ifdef FEAT_EVAL
7902 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02007903 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007904#endif
7905 /*
7906 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007907 * Use "free_oldval", because recursiveness may change the flags under
7908 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007909 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007910 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007911 free_string_option(oldval);
7912 if (new_value_alloced)
7913 options[opt_idx].flags |= P_ALLOCED;
7914 else
7915 options[opt_idx].flags &= ~P_ALLOCED;
7916
7917 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007918 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007919 {
7920 /* global option with local value set to use global value; free
7921 * the local value and make it empty */
7922 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7923 free_string_option(*(char_u **)p);
7924 *(char_u **)p = empty_option;
7925 }
7926
7927 /* May set global value for local option. */
7928 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7929 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007930
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007931 /*
7932 * Trigger the autocommand only after setting the flags.
7933 */
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007934#ifdef FEAT_SYN_HL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007935 /* When 'syntax' is set, load the syntax of that name */
7936 if (varp == &(curbuf->b_p_syn))
7937 {
Bram Moolenaara5616b02018-06-17 19:08:30 +02007938 static int syn_recursive = 0;
7939
7940 ++syn_recursive;
7941 // Only pass TRUE for "force" when the value changed or not used
7942 // recursively, to avoid endless recurrence.
7943 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname,
7944 value_changed || syn_recursive == 1, curbuf);
Bram Moolenaarc7f1e402019-08-03 13:29:46 +02007945 curbuf->b_flags |= BF_SYN_SET;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007946 --syn_recursive;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007947 }
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007948#endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007949 else if (varp == &(curbuf->b_p_ft))
7950 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007951 /* 'filetype' is set, trigger the FileType autocommand.
7952 * Skip this when called from a modeline and the filetype was
Bram Moolenaara5616b02018-06-17 19:08:30 +02007953 * already set to this value. */
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007954 if (!(opt_flags & OPT_MODELINE) || value_changed)
Bram Moolenaar90492982017-06-22 14:16:31 +02007955 {
Bram Moolenaar916a8182018-11-25 02:18:29 +01007956 static int ft_recursive = 0;
7957 int secure_save = secure;
7958
7959 // Reset the secure flag, since the value of 'filetype' has
7960 // been checked to be safe.
7961 secure = 0;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007962
7963 ++ft_recursive;
Bram Moolenaar90492982017-06-22 14:16:31 +02007964 did_filetype = TRUE;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007965 // Only pass TRUE for "force" when the value changed or not
7966 // used recursively, to avoid endless recurrence.
7967 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname,
7968 value_changed || ft_recursive == 1, curbuf);
7969 --ft_recursive;
Bram Moolenaar163095f2017-07-09 15:41:53 +02007970 /* Just in case the old "curbuf" is now invalid. */
7971 if (varp != &(curbuf->b_p_ft))
7972 varp = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007973
7974 secure = secure_save;
Bram Moolenaar90492982017-06-22 14:16:31 +02007975 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007976 }
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007977#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007978 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007979 {
7980 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007981 char_u *q = curwin->w_s->b_p_spl;
7982
7983 /* Skip the first name if it is "cjk". */
7984 if (STRNCMP(q, "cjk,", 4) == 0)
7985 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007986
7987 /*
7988 * Source the spell/LANG.vim in 'runtimepath'.
7989 * They could set 'spellcapcheck' depending on the language.
7990 * Use the first name in 'spelllang' up to '_region' or
7991 * '.encoding'.
7992 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007993 for (p = q; *p != NUL; ++p)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01007994 if (!ASCII_ISALNUM(*p) && *p != '-')
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007995 break;
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007996 if (p > q)
7997 {
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02007998 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
7999 (int)(p - q), q);
Bram Moolenaar82e8c922018-11-20 13:32:36 +01008000 source_runtime(fname, DIP_ALL);
8001 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00008002 }
8003#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008004 }
8005
8006#ifdef FEAT_MOUSE
8007 if (varp == &p_mouse)
8008 {
8009# ifdef FEAT_MOUSE_TTY
8010 if (*p_mouse == NUL)
8011 mch_setmouse(FALSE); /* switch mouse off */
8012 else
8013# endif
8014 setmouse(); /* in case 'mouse' changed */
8015 }
8016#endif
8017
Bram Moolenaar913077c2012-03-28 19:59:04 +02008018 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008019 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008020 curwin->w_set_curswant = TRUE;
8021
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00008022#ifdef FEAT_GUI
8023 /* check redraw when it's not a GUI option or the GUI is active. */
8024 if (!redraw_gui_only || gui.in_use)
8025#endif
8026 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008027
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008028#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
8029 if (did_swaptcap)
8030 {
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008031 set_termname((char_u *)"win32");
8032 init_highlight(TRUE, FALSE);
8033 }
8034#endif
8035
Bram Moolenaar071d4272004-06-13 20:20:40 +00008036 return errmsg;
8037}
8038
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01008039#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02008040/*
8041 * Simple int comparison function for use with qsort()
8042 */
8043 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01008044int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02008045{
8046 return *(const int *)a - *(const int *)b;
8047}
8048
8049/*
8050 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
8051 * Returns error message, NULL if it's OK.
8052 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008053 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008054check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02008055{
8056 char_u *s;
8057 int col;
8058 int count = 0;
8059 int color_cols[256];
8060 int i;
8061 int j = 0;
8062
Bram Moolenaar50f834d2011-09-21 13:40:17 +02008063 if (wp->w_buffer == NULL)
8064 return NULL; /* buffer was closed */
8065
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008066 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02008067 {
8068 if (*s == '-' || *s == '+')
8069 {
8070 /* -N and +N: add to 'textwidth' */
8071 col = (*s == '-') ? -1 : 1;
8072 ++s;
8073 if (!VIM_ISDIGIT(*s))
8074 return e_invarg;
8075 col = col * getdigits(&s);
8076 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008077 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02008078 col += wp->w_buffer->b_p_tw;
8079 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008080 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02008081 }
8082 else if (VIM_ISDIGIT(*s))
8083 col = getdigits(&s);
8084 else
8085 return e_invarg;
8086 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008087skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02008088 if (*s == NUL)
8089 break;
8090 if (*s != ',')
8091 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008092 if (*++s == NUL)
8093 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02008094 }
8095
8096 vim_free(wp->w_p_cc_cols);
8097 if (count == 0)
8098 wp->w_p_cc_cols = NULL;
8099 else
8100 {
Bram Moolenaarc799fe22019-05-28 23:08:19 +02008101 wp->w_p_cc_cols = ALLOC_MULT(int, count + 1);
Bram Moolenaar1a384422010-07-14 19:53:30 +02008102 if (wp->w_p_cc_cols != NULL)
8103 {
8104 /* sort the columns for faster usage on screen redraw inside
8105 * win_line() */
8106 qsort(color_cols, count, sizeof(int), int_cmp);
8107
8108 for (i = 0; i < count; ++i)
8109 /* skip duplicates */
8110 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
8111 wp->w_p_cc_cols[j++] = color_cols[i];
8112 wp->w_p_cc_cols[j] = -1; /* end marker */
8113 }
8114 }
8115
8116 return NULL; /* no error */
8117}
8118#endif
8119
Bram Moolenaar071d4272004-06-13 20:20:40 +00008120/*
8121 * Handle setting 'listchars' or 'fillchars'.
8122 * Returns error message, NULL if it's OK.
8123 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008124 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008125set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008126{
8127 int round, i, len, entries;
8128 char_u *p, *s;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008129 int c1 = 0, c2 = 0, c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008130 struct charstab
8131 {
8132 int *cp;
8133 char *name;
8134 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00008135 static struct charstab filltab[] =
8136 {
8137 {&fill_stl, "stl"},
8138 {&fill_stlnc, "stlnc"},
8139 {&fill_vert, "vert"},
8140 {&fill_fold, "fold"},
8141 {&fill_diff, "diff"},
8142 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00008143 static struct charstab lcstab[] =
8144 {
8145 {&lcs_eol, "eol"},
8146 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008147 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00008148 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02008149 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00008150 {&lcs_tab2, "tab"},
8151 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02008152#ifdef FEAT_CONCEAL
8153 {&lcs_conceal, "conceal"},
8154#else
8155 {NULL, "conceal"},
8156#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008157 };
8158 struct charstab *tab;
8159
Bram Moolenaar071d4272004-06-13 20:20:40 +00008160 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008161 {
8162 tab = lcstab;
8163 entries = sizeof(lcstab) / sizeof(struct charstab);
8164 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008165 else
8166 {
8167 tab = filltab;
8168 entries = sizeof(filltab) / sizeof(struct charstab);
8169 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008170
8171 /* first round: check for valid value, second round: assign values */
8172 for (round = 0; round <= 1; ++round)
8173 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008174 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008175 {
8176 /* After checking that the value is valid: set defaults: space for
8177 * 'fillchars', NUL for 'listchars' */
8178 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008179 if (tab[i].cp != NULL)
8180 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar83a52172019-01-16 22:41:54 +01008181
Bram Moolenaar071d4272004-06-13 20:20:40 +00008182 if (varp == &p_lcs)
Bram Moolenaar83a52172019-01-16 22:41:54 +01008183 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008184 lcs_tab1 = NUL;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008185 lcs_tab3 = NUL;
8186 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008187 else
8188 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008189 }
8190 p = *varp;
8191 while (*p)
8192 {
8193 for (i = 0; i < entries; ++i)
8194 {
8195 len = (int)STRLEN(tab[i].name);
8196 if (STRNCMP(p, tab[i].name, len) == 0
8197 && p[len] == ':'
8198 && p[len + 1] != NUL)
8199 {
Bram Moolenaar2c519cf2019-03-21 21:45:34 +01008200 c2 = c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008201 s = p + len + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008202 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00008203 if (mb_char2cells(c1) > 1)
8204 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008205 if (tab[i].cp == &lcs_tab2)
8206 {
8207 if (*s == NUL)
8208 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008209 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00008210 if (mb_char2cells(c2) > 1)
8211 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008212 if (!(*s == ',' || *s == NUL))
8213 {
Bram Moolenaar83a52172019-01-16 22:41:54 +01008214 c3 = mb_ptr2char_adv(&s);
8215 if (mb_char2cells(c3) > 1)
8216 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008217 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008218 }
Bram Moolenaar83a52172019-01-16 22:41:54 +01008219
Bram Moolenaar071d4272004-06-13 20:20:40 +00008220 if (*s == ',' || *s == NUL)
8221 {
8222 if (round)
8223 {
8224 if (tab[i].cp == &lcs_tab2)
8225 {
8226 lcs_tab1 = c1;
8227 lcs_tab2 = c2;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008228 lcs_tab3 = c3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008229 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008230 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008231 *(tab[i].cp) = c1;
8232
8233 }
8234 p = s;
8235 break;
8236 }
8237 }
8238 }
8239
8240 if (i == entries)
8241 return e_invarg;
8242 if (*p == ',')
8243 ++p;
8244 }
8245 }
8246
8247 return NULL; /* no error */
8248}
8249
8250#ifdef FEAT_STL_OPT
8251/*
8252 * Check validity of options with the 'statusline' format.
8253 * Return error message or NULL.
8254 */
Bram Moolenaar5843f5f2019-08-20 20:13:45 +02008255 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008256check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008257{
8258 int itemcnt = 0;
8259 int groupdepth = 0;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008260 static char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00008261
8262 while (*s && itemcnt < STL_MAX_ITEM)
8263 {
8264 /* Check for valid keys after % sequences */
8265 while (*s && *s != '%')
8266 s++;
8267 if (!*s)
8268 break;
8269 s++;
8270 if (*s != '%' && *s != ')')
8271 ++itemcnt;
8272 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
8273 {
8274 s++;
8275 continue;
8276 }
8277 if (*s == ')')
8278 {
8279 s++;
8280 if (--groupdepth < 0)
8281 break;
8282 continue;
8283 }
8284 if (*s == '-')
8285 s++;
8286 while (VIM_ISDIGIT(*s))
8287 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00008288 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008289 continue;
8290 if (*s == '.')
8291 {
8292 s++;
8293 while (*s && VIM_ISDIGIT(*s))
8294 s++;
8295 }
8296 if (*s == '(')
8297 {
8298 groupdepth++;
8299 continue;
8300 }
8301 if (vim_strchr(STL_ALL, *s) == NULL)
8302 {
8303 return illegal_char(errbuf, *s);
8304 }
8305 if (*s == '{')
8306 {
8307 s++;
8308 while (*s != '}' && *s)
8309 s++;
8310 if (*s != '}')
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008311 return N_("E540: Unclosed expression sequence");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008312 }
8313 }
8314 if (itemcnt >= STL_MAX_ITEM)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008315 return N_("E541: too many items");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008316 if (groupdepth != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008317 return N_("E542: unbalanced groups");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008318 return NULL;
8319}
8320#endif
8321
8322#ifdef FEAT_CLIPBOARD
8323/*
8324 * Extract the items in the 'clipboard' option and set global values.
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008325 * Return an error message or NULL for success.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008326 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008327 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008328check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008329{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008330 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008331 int new_autoselect_star = FALSE;
8332 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008333 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008334 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008335 regprog_T *new_exclude_prog = NULL;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008336 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008337 char_u *p;
8338
8339 for (p = p_cb; *p != NUL; )
8340 {
8341 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
8342 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008343 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008344 p += 7;
8345 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02008346 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008347 && (p[11] == ',' || p[11] == NUL))
8348 {
8349 new_unnamed |= CLIP_UNNAMED_PLUS;
8350 p += 11;
8351 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008352 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008353 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008354 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02008355 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008356 p += 10;
8357 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02008358 else if (STRNCMP(p, "autoselectplus", 14) == 0
8359 && (p[14] == ',' || p[14] == NUL))
8360 {
8361 new_autoselect_plus = TRUE;
8362 p += 14;
8363 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008364 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008365 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008366 {
8367 new_autoselectml = TRUE;
8368 p += 12;
8369 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008370 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
8371 {
8372 new_html = TRUE;
8373 p += 4;
8374 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008375 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
8376 {
8377 p += 8;
8378 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
8379 if (new_exclude_prog == NULL)
8380 errmsg = e_invarg;
8381 break;
8382 }
8383 else
8384 {
8385 errmsg = e_invarg;
8386 break;
8387 }
8388 if (*p == ',')
8389 ++p;
8390 }
8391 if (errmsg == NULL)
8392 {
8393 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008394 clip_autoselect_star = new_autoselect_star;
8395 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008396 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008397 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008398 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008399 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008400#ifdef FEAT_GUI_GTK
8401 if (gui.in_use)
8402 {
8403 gui_gtk_set_selection_targets();
8404 gui_gtk_set_dnd_targets();
8405 }
8406#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008407 }
8408 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008409 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008410
8411 return errmsg;
8412}
8413#endif
8414
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008415#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008416/*
8417 * Handle side effects of setting 'spell'.
8418 * Return an error message or NULL for success.
8419 */
8420 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008421did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008422{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008423 char *errmsg = NULL;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008424 win_T *wp;
8425 int l;
8426
8427 if (is_spellfile)
8428 {
8429 l = (int)STRLEN(curwin->w_s->b_p_spf);
8430 if (l > 0 && (l < 4
8431 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8432 errmsg = e_invarg;
8433 }
8434
8435 if (errmsg == NULL)
8436 {
8437 FOR_ALL_WINDOWS(wp)
8438 if (wp->w_buffer == curbuf && wp->w_p_spell)
8439 {
8440 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008441 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008442 }
8443 }
8444 return errmsg;
8445}
8446
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008447/*
8448 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8449 * Return error message when failed, NULL when OK.
8450 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008451 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008452compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008453{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008454 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008455 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008456
Bram Moolenaar860cae12010-06-05 23:22:07 +02008457 if (*synblock->b_p_spc == NUL)
8458 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008459 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008460 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008461 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008462 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008463 if (re != NULL)
8464 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008465 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008466 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008467 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008468 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008469 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008470 return e_invarg;
8471 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008472 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008473 }
8474
Bram Moolenaar473de612013-06-08 18:19:48 +02008475 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008476 return NULL;
8477}
8478#endif
8479
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008480#if defined(FEAT_EVAL) || defined(PROTO)
8481/*
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008482 * Set the script_ctx for an option, taking care of setting the buffer- or
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008483 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008484 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008485 static void
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008486set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008487{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008488 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8489 int indir = (int)options[opt_idx].indir;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008490 sctx_T new_script_ctx = script_ctx;
8491
8492 new_script_ctx.sc_lnum += sourcing_lnum;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008493
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008494 /* Remember where the option was set. For local options need to do that
8495 * in the buffer or window structure. */
8496 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008497 options[opt_idx].script_ctx = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008498 if (both || (opt_flags & OPT_LOCAL))
8499 {
8500 if (indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008501 curbuf->b_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008502 else if (indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008503 curwin->w_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008504 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008505}
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02008506
8507/*
8508 * Set the script_ctx for a termcap option.
8509 * "name" must be the two character code, e.g. "RV".
8510 * When "name" is NULL use "opt_idx".
8511 */
8512 void
8513set_term_option_sctx_idx(char *name, int opt_idx)
8514{
8515 char_u buf[5];
8516 int idx;
8517
8518 if (name == NULL)
8519 idx = opt_idx;
8520 else
8521 {
8522 buf[0] = 't';
8523 buf[1] = '_';
8524 buf[2] = name[0];
8525 buf[3] = name[1];
8526 buf[4] = 0;
8527 idx = findoption(buf);
8528 }
8529 if (idx >= 0)
8530 set_option_sctx_idx(idx, OPT_GLOBAL, current_sctx);
8531}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008532#endif
8533
Bram Moolenaar071d4272004-06-13 20:20:40 +00008534/*
8535 * Set the value of a boolean option, and take care of side effects.
8536 * Returns NULL for success, or an error message for an error.
8537 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008538 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008539set_bool_option(
8540 int opt_idx, /* index in options[] table */
8541 char_u *varp, /* pointer to the option variable */
8542 int value, /* new value */
8543 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008544{
8545 int old_value = *(int *)varp;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008546#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02008547 int old_global_value = 0;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008548#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008549
Bram Moolenaar071d4272004-06-13 20:20:40 +00008550 /* Disallow changing some options from secure mode */
8551 if ((secure
8552#ifdef HAVE_SANDBOX
8553 || sandbox != 0
8554#endif
8555 ) && (options[opt_idx].flags & P_SECURE))
8556 return e_secure;
8557
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008558#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02008559 // Save the global value before changing anything. This is needed as for
8560 // a global-only option setting the "local value" in fact sets the global
8561 // value (since there is only one value).
8562 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8563 old_global_value = *(int *)get_varp_scope(&(options[opt_idx]),
8564 OPT_GLOBAL);
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008565#endif
Bram Moolenaard7c96872019-06-15 17:12:48 +02008566
Bram Moolenaar071d4272004-06-13 20:20:40 +00008567 *(int *)varp = value; /* set the new value */
8568#ifdef FEAT_EVAL
8569 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008570 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008571#endif
8572
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008573#ifdef FEAT_GUI
8574 need_mouse_correct = TRUE;
8575#endif
8576
Bram Moolenaar071d4272004-06-13 20:20:40 +00008577 /* May set global value for local option. */
8578 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8579 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8580
8581 /*
8582 * Handle side effects of changing a bool option.
8583 */
8584
8585 /* 'compatible' */
8586 if ((int *)varp == &p_cp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008587 compatible_set();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008588
Bram Moolenaar920694c2016-08-21 17:45:02 +02008589#ifdef FEAT_LANGMAP
8590 if ((int *)varp == &p_lrm)
8591 /* 'langremap' -> !'langnoremap' */
8592 p_lnr = !p_lrm;
8593 else if ((int *)varp == &p_lnr)
8594 /* 'langnoremap' -> !'langremap' */
8595 p_lrm = !p_lnr;
8596#endif
8597
Bram Moolenaar8c63e0e2018-09-25 22:17:54 +02008598#ifdef FEAT_SYN_HL
8599 else if ((int *)varp == &curwin->w_p_cul && !value && old_value)
8600 reset_cursorline();
8601#endif
8602
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008603#ifdef FEAT_PERSISTENT_UNDO
8604 /* 'undofile' */
8605 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8606 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008607 /* Only take action when the option was set. When reset we do not
8608 * delete the undo file, the option may be set again without making
8609 * any changes in between. */
8610 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008611 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008612 char_u hash[UNDO_HASH_SIZE];
8613 buf_T *save_curbuf = curbuf;
8614
Bram Moolenaar29323592016-07-24 22:04:11 +02008615 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008616 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008617 /* When 'undofile' is set globally: for every buffer, otherwise
8618 * only for the current buffer: Try to read in the undofile,
8619 * if one exists, the buffer wasn't changed and the buffer was
8620 * loaded */
8621 if ((curbuf == save_curbuf
8622 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8623 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8624 {
8625 u_compute_hash(hash);
8626 u_read_undo(NULL, hash, curbuf->b_fname);
8627 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008628 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008629 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008630 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008631 }
8632#endif
8633
Bram Moolenaar071d4272004-06-13 20:20:40 +00008634 else if ((int *)varp == &curbuf->b_p_ro)
8635 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008636 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008637 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8638 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008639
8640 /* when 'readonly' is set may give W10 again */
8641 if (curbuf->b_p_ro)
8642 curbuf->b_did_warn = FALSE;
8643
Bram Moolenaar071d4272004-06-13 20:20:40 +00008644#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008645 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008646#endif
8647 }
8648
Bram Moolenaar9c449722010-07-20 18:44:27 +02008649#ifdef FEAT_GUI
8650 else if ((int *)varp == &p_mh)
8651 {
8652 if (!p_mh)
8653 gui_mch_mousehide(FALSE);
8654 }
8655#endif
8656
Bram Moolenaara539df02010-08-01 14:35:05 +02008657 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008658 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008659 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008660# ifdef FEAT_TERMINAL
8661 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaard7db27b2018-03-07 23:02:33 +01008662 if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf)
8663 && curbuf->b_term != NULL && !term_is_finished(curbuf))))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008664 {
8665 curbuf->b_p_ma = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008666 return N_("E946: Cannot make a terminal with running job modifiable");
Bram Moolenaar423802d2017-07-30 16:52:24 +02008667 }
8668# endif
8669# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008670 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008671# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008672 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008673#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008674 /* when 'endofline' is changed, redraw the window title */
8675 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008676 {
8677 redraw_titles();
8678 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008679 /* when 'fixeol' is changed, redraw the window title */
8680 else if ((int *)varp == &curbuf->b_p_fixeol)
8681 {
8682 redraw_titles();
8683 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008684 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008685 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008686 {
8687 redraw_titles();
8688 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008689#endif
8690
8691 /* when 'bin' is set also set some other options */
8692 else if ((int *)varp == &curbuf->b_p_bin)
8693 {
8694 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8695#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008696 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008697#endif
8698 }
8699
Bram Moolenaar071d4272004-06-13 20:20:40 +00008700 /* when 'buflisted' changes, trigger autocommands */
8701 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8702 {
8703 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8704 NULL, NULL, TRUE, curbuf);
8705 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008706
8707 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8708 else if ((int *)varp == &curbuf->b_p_swf)
8709 {
8710 if (curbuf->b_p_swf && p_uc)
8711 ml_open_file(curbuf); /* create the swap file */
8712 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008713 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8714 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008715 mf_close_file(curbuf, TRUE); /* remove the swap file */
8716 }
8717
8718 /* when 'terse' is set change 'shortmess' */
8719 else if ((int *)varp == &p_terse)
8720 {
8721 char_u *p;
8722
8723 p = vim_strchr(p_shm, SHM_SEARCH);
8724
8725 /* insert 's' in p_shm */
8726 if (p_terse && p == NULL)
8727 {
8728 STRCPY(IObuff, p_shm);
8729 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008730 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008731 }
8732 /* remove 's' from p_shm */
8733 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008734 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008735 }
8736
8737 /* when 'paste' is set or reset also change other options */
8738 else if ((int *)varp == &p_paste)
8739 {
8740 paste_option_changed();
8741 }
8742
8743 /* when 'insertmode' is set from an autocommand need to do work here */
8744 else if ((int *)varp == &p_im)
8745 {
8746 if (p_im)
8747 {
8748 if ((State & INSERT) == 0)
8749 need_start_insertmode = TRUE;
8750 stop_insert_mode = FALSE;
8751 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008752 /* only reset if it was set previously */
8753 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008754 {
8755 need_start_insertmode = FALSE;
8756 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008757 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008758 clear_cmdline = TRUE; /* remove "(insert)" */
8759 restart_edit = 0;
8760 }
8761 }
8762
8763 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8764 else if ((int *)varp == &p_ic && p_hls)
8765 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008766 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008767 }
8768
8769#ifdef FEAT_SEARCH_EXTRA
8770 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8771 else if ((int *)varp == &p_hls)
8772 {
Bram Moolenaar451fc7b2018-04-27 22:53:07 +02008773 set_no_hlsearch(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008774 }
8775#endif
8776
Bram Moolenaar071d4272004-06-13 20:20:40 +00008777 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8778 * at the end of normal_cmd() */
8779 else if ((int *)varp == &curwin->w_p_scb)
8780 {
8781 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008782 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008783 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008784 curwin->w_scbind_pos = curwin->w_topline;
8785 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008786 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008787
Bram Moolenaar4033c552017-09-16 20:54:51 +02008788#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008789 /* There can be only one window with 'previewwindow' set. */
8790 else if ((int *)varp == &curwin->w_p_pvw)
8791 {
8792 if (curwin->w_p_pvw)
8793 {
8794 win_T *win;
8795
Bram Moolenaar29323592016-07-24 22:04:11 +02008796 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008797 if (win->w_p_pvw && win != curwin)
8798 {
8799 curwin->w_p_pvw = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008800 return N_("E590: A preview window already exists");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008801 }
8802 }
8803 }
8804#endif
8805
8806 /* when 'textmode' is set or reset also change 'fileformat' */
8807 else if ((int *)varp == &curbuf->b_p_tx)
8808 {
8809 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8810 }
8811
8812 /* when 'textauto' is set or reset also change 'fileformats' */
8813 else if ((int *)varp == &p_ta)
Bram Moolenaarabab0b02019-03-30 18:47:01 +01008814 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008815 set_string_option_direct((char_u *)"ffs", -1,
8816 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008817 OPT_FREE | opt_flags, 0);
Bram Moolenaarabab0b02019-03-30 18:47:01 +01008818 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008819
8820 /*
8821 * When 'lisp' option changes include/exclude '-' in
8822 * keyword characters.
8823 */
8824#ifdef FEAT_LISP
8825 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8826 {
8827 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8828 }
8829#endif
8830
8831#ifdef FEAT_TITLE
8832 /* when 'title' changed, may need to change the title; same for 'icon' */
Bram Moolenaar84a93082018-06-16 22:58:15 +02008833 else if ((int *)varp == &p_title || (int *)varp == &p_icon)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008834 {
Bram Moolenaar84a93082018-06-16 22:58:15 +02008835 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008836 }
8837#endif
8838
8839 else if ((int *)varp == &curbuf->b_changed)
8840 {
8841 if (!value)
8842 save_file_ff(curbuf); /* Buffer is unchanged */
8843#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008844 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008845#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008846 modified_was_set = value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008847 }
8848
8849#ifdef BACKSLASH_IN_FILENAME
8850 else if ((int *)varp == &p_ssl)
8851 {
8852 if (p_ssl)
8853 {
8854 psepc = '/';
8855 psepcN = '\\';
8856 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008857 }
8858 else
8859 {
8860 psepc = '\\';
8861 psepcN = '/';
8862 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008863 }
8864
8865 /* need to adjust the file name arguments and buffer names. */
8866 buflist_slash_adjust();
8867 alist_slash_adjust();
8868# ifdef FEAT_EVAL
8869 scriptnames_slash_adjust();
8870# endif
8871 }
8872#endif
8873
8874 /* If 'wrap' is set, set w_leftcol to zero. */
8875 else if ((int *)varp == &curwin->w_p_wrap)
8876 {
8877 if (curwin->w_p_wrap)
8878 curwin->w_leftcol = 0;
8879 }
8880
Bram Moolenaar071d4272004-06-13 20:20:40 +00008881 else if ((int *)varp == &p_ea)
8882 {
8883 if (p_ea && !old_value)
8884 win_equal(curwin, FALSE, 0);
8885 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008886
8887 else if ((int *)varp == &p_wiv)
8888 {
8889 /*
8890 * When 'weirdinvert' changed, set/reset 't_xs'.
8891 * Then set 'weirdinvert' according to value of 't_xs'.
8892 */
8893 if (p_wiv && !old_value)
8894 T_XS = (char_u *)"y";
8895 else if (!p_wiv && old_value)
8896 T_XS = empty_option;
8897 p_wiv = (*T_XS != NUL);
8898 }
8899
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008900#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008901 else if ((int *)varp == &p_beval)
8902 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008903 if (!balloonEvalForTerm)
8904 {
8905 if (p_beval && !old_value)
8906 gui_mch_enable_beval_area(balloonEval);
8907 else if (!p_beval && old_value)
8908 gui_mch_disable_beval_area(balloonEval);
8909 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008910 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008911#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008912#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008913 else if ((int *)varp == &p_bevalterm)
8914 {
8915 mch_bevalterm_changed();
8916 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008917#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008918
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008919#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008920 else if ((int *)varp == &p_acd)
8921 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008922 /* Change directories when the 'acd' option is set now. */
Bram Moolenaar6f470022018-04-10 18:47:20 +02008923 DO_AUTOCHDIR;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008924 }
8925#endif
8926
8927#ifdef FEAT_DIFF
8928 /* 'diff' */
8929 else if ((int *)varp == &curwin->w_p_diff)
8930 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008931 /* May add or remove the buffer from the list of diff buffers. */
8932 diff_buf_adjust(curwin);
8933# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008934 if (foldmethodIsDiff(curwin))
8935 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008936# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008937 }
8938#endif
8939
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008940#ifdef HAVE_INPUT_METHOD
Bram Moolenaar071d4272004-06-13 20:20:40 +00008941 /* 'imdisable' */
8942 else if ((int *)varp == &p_imdisable)
8943 {
8944 /* Only de-activate it here, it will be enabled when changing mode. */
8945 if (p_imdisable)
8946 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008947 else if (State & INSERT)
8948 /* When the option is set from an autocommand, it may need to take
8949 * effect right away. */
8950 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008951 }
8952#endif
8953
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008954#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008955 /* 'spell' */
8956 else if ((int *)varp == &curwin->w_p_spell)
8957 {
8958 if (curwin->w_p_spell)
8959 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008960 char *errmsg = did_set_spelllang(curwin);
8961
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008962 if (errmsg != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008963 emsg(_(errmsg));
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008964 }
8965 }
8966#endif
8967
Bram Moolenaar071d4272004-06-13 20:20:40 +00008968#ifdef FEAT_ARABIC
8969 if ((int *)varp == &curwin->w_p_arab)
8970 {
8971 if (curwin->w_p_arab)
8972 {
8973 /*
8974 * 'arabic' is set, handle various sub-settings.
8975 */
8976 if (!p_tbidi)
8977 {
8978 /* set rightleft mode */
8979 if (!curwin->w_p_rl)
8980 {
8981 curwin->w_p_rl = TRUE;
8982 changed_window_setting();
8983 }
8984
8985 /* Enable Arabic shaping (major part of what Arabic requires) */
8986 if (!p_arshape)
8987 {
8988 p_arshape = TRUE;
8989 redraw_later_clear();
8990 }
8991 }
8992
8993 /* Arabic requires a utf-8 encoding, inform the user if its not
8994 * set. */
8995 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008996 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008997 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8998
Bram Moolenaar8820b482017-03-16 17:23:31 +01008999 msg_source(HL_ATTR(HLF_W));
Bram Moolenaar32526b32019-01-19 17:43:09 +01009000 msg_attr(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00009001#ifdef FEAT_EVAL
9002 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
9003#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009004 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009005
Bram Moolenaar071d4272004-06-13 20:20:40 +00009006 /* set 'delcombine' */
9007 p_deco = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009008
9009# ifdef FEAT_KEYMAP
9010 /* Force-set the necessary keymap for arabic */
9011 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
9012 OPT_LOCAL);
9013# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009014 }
9015 else
9016 {
9017 /*
9018 * 'arabic' is reset, handle various sub-settings.
9019 */
9020 if (!p_tbidi)
9021 {
9022 /* reset rightleft mode */
9023 if (curwin->w_p_rl)
9024 {
9025 curwin->w_p_rl = FALSE;
9026 changed_window_setting();
9027 }
9028
9029 /* 'arabicshape' isn't reset, it is a global option and
9030 * another window may still need it "on". */
9031 }
9032
9033 /* 'delcombine' isn't reset, it is a global option and another
9034 * window may still want it "on". */
9035
9036# ifdef FEAT_KEYMAP
9037 /* Revert to the default keymap */
9038 curbuf->b_p_iminsert = B_IMODE_NONE;
9039 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
9040# endif
9041 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00009042 }
9043
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00009044#endif
9045
Bram Moolenaar61be73b2016-04-29 22:59:22 +02009046#ifdef FEAT_TERMGUICOLORS
9047 /* 'termguicolors' */
9048 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02009049 {
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009050# ifdef FEAT_VTP
9051 /* Do not turn on 'tgc' when 24-bit colors are not supported. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02009052 if (
9053# ifdef VIMDLL
9054 !gui.in_use && !gui.starting &&
9055# endif
9056 !has_vtp_working())
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009057 {
9058 p_tgc = 0;
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01009059 return N_("E954: 24-bit colors are not supported on this environment");
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009060 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02009061 if (is_term_win32())
9062 swap_tcap();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009063# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02009064# ifdef FEAT_GUI
9065 if (!gui.in_use && !gui.starting)
9066# endif
9067 highlight_gui_started();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009068# ifdef FEAT_VTP
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009069 /* reset t_Co */
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02009070 if (is_term_win32())
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02009071 {
9072 control_console_color_rgb();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009073 set_termname(T_NAME);
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02009074 init_highlight(TRUE, FALSE);
9075 }
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009076# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02009077 }
9078#endif
9079
Bram Moolenaar071d4272004-06-13 20:20:40 +00009080 /*
9081 * End of handling side effects for bool options.
9082 */
9083
Bram Moolenaar53744302015-07-17 17:38:22 +02009084 /* after handling side effects, call autocommand */
9085
Bram Moolenaar071d4272004-06-13 20:20:40 +00009086 options[opt_idx].flags |= P_WAS_SET;
9087
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009088#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009089 // Don't do this while starting up or recursively.
9090 if (!starting && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009091 {
Bram Moolenaard7c96872019-06-15 17:12:48 +02009092 char_u buf_old[2], buf_old_global[2], buf_new[2], buf_type[7];
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009093
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009094 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009095 vim_snprintf((char *)buf_old_global, 2, "%d",
9096 old_global_value ? TRUE: FALSE);
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009097 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009098 vim_snprintf((char *)buf_type, 7, "%s",
9099 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009100 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9101 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9102 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009103 if (opt_flags & OPT_LOCAL)
9104 {
9105 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
9106 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9107 }
9108 if (opt_flags & OPT_GLOBAL)
9109 {
9110 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
9111 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old, -1);
9112 }
9113 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9114 {
9115 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
9116 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9117 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old_global, -1);
9118 }
9119 if (opt_flags & OPT_MODELINE)
9120 {
9121 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
9122 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9123 }
9124 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname,
9125 NULL, FALSE, NULL);
Bram Moolenaar53744302015-07-17 17:38:22 +02009126 reset_v_option_vars();
9127 }
9128#endif
9129
Bram Moolenaar071d4272004-06-13 20:20:40 +00009130 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009131 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009132 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009133 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009134 check_redraw(options[opt_idx].flags);
9135
9136 return NULL;
9137}
9138
9139/*
9140 * Set the value of a number option, and take care of side effects.
9141 * Returns NULL for success, or an error message for an error.
9142 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009143 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009144set_num_option(
9145 int opt_idx, /* index in options[] table */
9146 char_u *varp, /* pointer to the option variable */
9147 long value, /* new value */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009148 char *errbuf, /* buffer for error messages */
Bram Moolenaar9b578142016-01-30 19:39:49 +01009149 size_t errbuflen, /* length of "errbuf" */
9150 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00009151 OPT_MODELINE */
9152{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009153 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009154 long old_value = *(long *)varp;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02009155#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02009156 long old_global_value = 0; // only used when setting a local and
9157 // global option
Bram Moolenaar983f2f12019-06-16 16:41:41 +02009158#endif
Bram Moolenaard7c96872019-06-15 17:12:48 +02009159 long old_Rows = Rows; // remember old Rows
9160 long old_Columns = Columns; // remember old Columns
Bram Moolenaar071d4272004-06-13 20:20:40 +00009161 long *pp = (long *)varp;
9162
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009163 /* Disallow changing some options from secure mode. */
9164 if ((secure
9165#ifdef HAVE_SANDBOX
9166 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00009167#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009168 ) && (options[opt_idx].flags & P_SECURE))
9169 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009170
Bram Moolenaar983f2f12019-06-16 16:41:41 +02009171#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02009172 // Save the global value before changing anything. This is needed as for
9173 // a global-only option setting the "local value" infact sets the global
9174 // value (since there is only one value).
9175 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
Bram Moolenaar983f2f12019-06-16 16:41:41 +02009176 old_global_value = *(long *)get_varp_scope(&(options[opt_idx]),
9177 OPT_GLOBAL);
9178#endif
Bram Moolenaard7c96872019-06-15 17:12:48 +02009179
Bram Moolenaar071d4272004-06-13 20:20:40 +00009180 *pp = value;
9181#ifdef FEAT_EVAL
9182 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02009183 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009184#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009185#ifdef FEAT_GUI
9186 need_mouse_correct = TRUE;
9187#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009188
Bram Moolenaar14f24742012-08-08 18:01:05 +02009189 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009190 {
9191 errmsg = e_positive;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02009192#ifdef FEAT_VARTABS
9193 // Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use.
9194 curbuf->b_p_sw = tabstop_count(curbuf->b_p_vts_array) > 0
9195 ? tabstop_first(curbuf->b_p_vts_array)
9196 : curbuf->b_p_ts;
9197#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00009198 curbuf->b_p_sw = curbuf->b_p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02009199#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009200 }
9201
9202 /*
9203 * Number options that need some action when changed
9204 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009205 if (pp == &p_wh || pp == &p_hh)
9206 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009207 // 'winheight' and 'helpheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009208 if (p_wh < 1)
9209 {
9210 errmsg = e_positive;
9211 p_wh = 1;
9212 }
9213 if (p_wmh > p_wh)
9214 {
9215 errmsg = e_winheight;
9216 p_wh = p_wmh;
9217 }
9218 if (p_hh < 0)
9219 {
9220 errmsg = e_positive;
9221 p_hh = 0;
9222 }
9223
9224 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01009225 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009226 {
9227 if (pp == &p_wh && curwin->w_height < p_wh)
9228 win_setheight((int)p_wh);
9229 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
9230 win_setheight((int)p_hh);
9231 }
9232 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009233 else if (pp == &p_wmh)
9234 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009235 // 'winminheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009236 if (p_wmh < 0)
9237 {
9238 errmsg = e_positive;
9239 p_wmh = 0;
9240 }
9241 if (p_wmh > p_wh)
9242 {
9243 errmsg = e_winheight;
9244 p_wmh = p_wh;
9245 }
9246 win_setminheight();
9247 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009248 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009249 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009250 // 'winwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009251 if (p_wiw < 1)
9252 {
9253 errmsg = e_positive;
9254 p_wiw = 1;
9255 }
9256 if (p_wmw > p_wiw)
9257 {
9258 errmsg = e_winwidth;
9259 p_wiw = p_wmw;
9260 }
9261
9262 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01009263 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009264 win_setwidth((int)p_wiw);
9265 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009266 else if (pp == &p_wmw)
9267 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009268 // 'winminwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009269 if (p_wmw < 0)
9270 {
9271 errmsg = e_positive;
9272 p_wmw = 0;
9273 }
9274 if (p_wmw > p_wiw)
9275 {
9276 errmsg = e_winwidth;
9277 p_wmw = p_wiw;
9278 }
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009279 win_setminwidth();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009280 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009281
Bram Moolenaar071d4272004-06-13 20:20:40 +00009282 /* (re)set last window status line */
9283 else if (pp == &p_ls)
9284 {
9285 last_status(FALSE);
9286 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009287
9288 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00009289 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009290 {
9291 shell_new_rows(); /* recompute window positions and heights */
9292 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009293
9294#ifdef FEAT_GUI
9295 else if (pp == &p_linespace)
9296 {
Bram Moolenaar02743632005-07-25 20:42:36 +00009297 /* Recompute gui.char_height and resize the Vim window to keep the
9298 * same number of lines. */
9299 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00009300 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009301 }
9302#endif
9303
9304#ifdef FEAT_FOLDING
9305 /* 'foldlevel' */
9306 else if (pp == &curwin->w_p_fdl)
9307 {
9308 if (curwin->w_p_fdl < 0)
9309 curwin->w_p_fdl = 0;
9310 newFoldLevel();
9311 }
9312
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00009313 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009314 else if (pp == &curwin->w_p_fml)
9315 {
9316 foldUpdateAll(curwin);
9317 }
9318
9319 /* 'foldnestmax' */
9320 else if (pp == &curwin->w_p_fdn)
9321 {
9322 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
9323 foldUpdateAll(curwin);
9324 }
9325
9326 /* 'foldcolumn' */
9327 else if (pp == &curwin->w_p_fdc)
9328 {
9329 if (curwin->w_p_fdc < 0)
9330 {
9331 errmsg = e_positive;
9332 curwin->w_p_fdc = 0;
9333 }
9334 else if (curwin->w_p_fdc > 12)
9335 {
9336 errmsg = e_invarg;
9337 curwin->w_p_fdc = 12;
9338 }
9339 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009340#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009341
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009342#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009343 /* 'shiftwidth' or 'tabstop' */
9344 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
9345 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009346# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00009347 if (foldmethodIsIndent(curwin))
9348 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009349# endif
9350# ifdef FEAT_CINDENT
9351 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
9352 * parse 'cinoptions'. */
9353 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
9354 parse_cino(curbuf);
9355# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009356 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009357#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009358
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009359 /* 'maxcombine' */
9360 else if (pp == &p_mco)
9361 {
9362 if (p_mco > MAX_MCO)
9363 p_mco = MAX_MCO;
9364 else if (p_mco < 0)
9365 p_mco = 0;
9366 screenclear(); /* will re-allocate the screen */
9367 }
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009368
Bram Moolenaar071d4272004-06-13 20:20:40 +00009369 else if (pp == &curbuf->b_p_iminsert)
9370 {
9371 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
9372 {
9373 errmsg = e_invarg;
9374 curbuf->b_p_iminsert = B_IMODE_NONE;
9375 }
9376 p_iminsert = curbuf->b_p_iminsert;
9377 if (termcap_active) /* don't do this in the alternate screen */
9378 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02009379#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009380 /* Show/unshow value of 'keymap' in status lines. */
9381 status_redraw_curbuf();
9382#endif
9383 }
9384
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02009385#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
9386 /* 'imstyle' */
9387 else if (pp == &p_imst)
9388 {
9389 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
9390 errmsg = e_invarg;
9391 }
9392#endif
9393
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009394 else if (pp == &p_window)
9395 {
9396 if (p_window < 1)
9397 p_window = 1;
9398 else if (p_window >= Rows)
9399 p_window = Rows - 1;
9400 }
9401
Bram Moolenaar071d4272004-06-13 20:20:40 +00009402 else if (pp == &curbuf->b_p_imsearch)
9403 {
9404 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
9405 {
9406 errmsg = e_invarg;
9407 curbuf->b_p_imsearch = B_IMODE_NONE;
9408 }
9409 p_imsearch = curbuf->b_p_imsearch;
9410 }
9411
9412#ifdef FEAT_TITLE
9413 /* if 'titlelen' has changed, redraw the title */
9414 else if (pp == &p_titlelen)
9415 {
9416 if (p_titlelen < 0)
9417 {
9418 errmsg = e_positive;
9419 p_titlelen = 85;
9420 }
9421 if (starting != NO_SCREEN && old_value != p_titlelen)
9422 need_maketitle = TRUE;
9423 }
9424#endif
9425
9426 /* if p_ch changed value, change the command line height */
9427 else if (pp == &p_ch)
9428 {
9429 if (p_ch < 1)
9430 {
9431 errmsg = e_positive;
9432 p_ch = 1;
9433 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009434 if (p_ch > Rows - min_rows() + 1)
9435 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009436
9437 /* Only compute the new window layout when startup has been
9438 * completed. Otherwise the frame sizes may be wrong. */
9439 if (p_ch != old_value && full_screen
9440#ifdef FEAT_GUI
9441 && !gui.starting
9442#endif
9443 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009444 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009445 }
9446
9447 /* when 'updatecount' changes from zero to non-zero, open swap files */
9448 else if (pp == &p_uc)
9449 {
9450 if (p_uc < 0)
9451 {
9452 errmsg = e_positive;
9453 p_uc = 100;
9454 }
9455 if (p_uc && !old_value)
9456 ml_open_files();
9457 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009458#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009459 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009460 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009461 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009462 {
9463 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009464 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009465 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009466 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009467 {
9468 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009469 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009470 }
9471 }
9472#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009473#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009474 else if (pp == &p_mzq)
9475 mzvim_reset_timer();
9476#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009477
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009478#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9479 /* 'pyxversion' */
9480 else if (pp == &p_pyx)
9481 {
9482 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9483 errmsg = e_invarg;
9484 }
9485#endif
9486
Bram Moolenaar071d4272004-06-13 20:20:40 +00009487 /* sync undo before 'undolevels' changes */
9488 else if (pp == &p_ul)
9489 {
9490 /* use the old value, otherwise u_sync() may not work properly */
9491 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009492 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009493 p_ul = value;
9494 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009495 else if (pp == &curbuf->b_p_ul)
9496 {
9497 /* use the old value, otherwise u_sync() may not work properly */
9498 curbuf->b_p_ul = old_value;
9499 u_sync(TRUE);
9500 curbuf->b_p_ul = value;
9501 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009502
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009503#ifdef FEAT_LINEBREAK
9504 /* 'numberwidth' must be positive */
9505 else if (pp == &curwin->w_p_nuw)
9506 {
9507 if (curwin->w_p_nuw < 1)
9508 {
9509 errmsg = e_positive;
9510 curwin->w_p_nuw = 1;
9511 }
Bram Moolenaarf8a07122019-07-01 22:06:07 +02009512 if (curwin->w_p_nuw > 20)
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009513 {
9514 errmsg = e_invarg;
Bram Moolenaarf8a07122019-07-01 22:06:07 +02009515 curwin->w_p_nuw = 20;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009516 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009517 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009518 }
9519#endif
9520
Bram Moolenaar1a384422010-07-14 19:53:30 +02009521 else if (pp == &curbuf->b_p_tw)
9522 {
9523 if (curbuf->b_p_tw < 0)
9524 {
9525 errmsg = e_positive;
9526 curbuf->b_p_tw = 0;
9527 }
9528#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009529 {
9530 win_T *wp;
9531 tabpage_T *tp;
9532
9533 FOR_ALL_TAB_WINDOWS(tp, wp)
9534 check_colorcolumn(wp);
9535 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009536#endif
9537 }
9538
Bram Moolenaar071d4272004-06-13 20:20:40 +00009539 /*
9540 * Check the bounds for numeric options here
9541 */
9542 if (Rows < min_rows() && full_screen)
9543 {
9544 if (errbuf != NULL)
9545 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009546 vim_snprintf((char *)errbuf, errbuflen,
9547 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009548 errmsg = errbuf;
9549 }
9550 Rows = min_rows();
9551 }
9552 if (Columns < MIN_COLUMNS && full_screen)
9553 {
9554 if (errbuf != NULL)
9555 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009556 vim_snprintf((char *)errbuf, errbuflen,
9557 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009558 errmsg = errbuf;
9559 }
9560 Columns = MIN_COLUMNS;
9561 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009562 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009563
Bram Moolenaar071d4272004-06-13 20:20:40 +00009564 /*
9565 * If the screen (shell) height has been changed, assume it is the
9566 * physical screenheight.
9567 */
9568 if (old_Rows != Rows || old_Columns != Columns)
9569 {
9570 /* Changing the screen size is not allowed while updating the screen. */
9571 if (updating_screen)
9572 *pp = old_value;
9573 else if (full_screen
9574#ifdef FEAT_GUI
9575 && !gui.starting
9576#endif
9577 )
9578 set_shellsize((int)Columns, (int)Rows, TRUE);
9579 else
9580 {
9581 /* Postpone the resizing; check the size and cmdline position for
9582 * messages. */
9583 check_shellsize();
9584 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9585 cmdline_row = Rows - p_ch;
9586 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009587 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009588 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009589 }
9590
Bram Moolenaar071d4272004-06-13 20:20:40 +00009591 if (curbuf->b_p_ts <= 0)
9592 {
9593 errmsg = e_positive;
9594 curbuf->b_p_ts = 8;
9595 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009596 if (p_tm < 0)
9597 {
9598 errmsg = e_positive;
9599 p_tm = 0;
9600 }
9601 if ((curwin->w_p_scr <= 0
9602 || (curwin->w_p_scr > curwin->w_height
9603 && curwin->w_height > 0))
9604 && full_screen)
9605 {
9606 if (pp == &(curwin->w_p_scr))
9607 {
9608 if (curwin->w_p_scr != 0)
9609 errmsg = e_scroll;
9610 win_comp_scroll(curwin);
9611 }
9612 /* If 'scroll' became invalid because of a side effect silently adjust
9613 * it. */
9614 else if (curwin->w_p_scr <= 0)
9615 curwin->w_p_scr = 1;
9616 else /* curwin->w_p_scr > curwin->w_height */
9617 curwin->w_p_scr = curwin->w_height;
9618 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009619 if (p_hi < 0)
9620 {
9621 errmsg = e_positive;
9622 p_hi = 0;
9623 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009624 else if (p_hi > 10000)
9625 {
9626 errmsg = e_invarg;
9627 p_hi = 10000;
9628 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009629 if (p_re < 0 || p_re > 2)
9630 {
9631 errmsg = e_invarg;
9632 p_re = 0;
9633 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009634 if (p_report < 0)
9635 {
9636 errmsg = e_positive;
9637 p_report = 1;
9638 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009639 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009640 {
9641 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9642 p_sj = Rows / 2;
9643 else
9644 {
9645 errmsg = e_scroll;
9646 p_sj = 1;
9647 }
9648 }
9649 if (p_so < 0 && full_screen)
9650 {
Bram Moolenaar375e3392019-01-31 18:26:10 +01009651 errmsg = e_positive;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009652 p_so = 0;
9653 }
9654 if (p_siso < 0 && full_screen)
9655 {
9656 errmsg = e_positive;
9657 p_siso = 0;
9658 }
9659#ifdef FEAT_CMDWIN
9660 if (p_cwh < 1)
9661 {
9662 errmsg = e_positive;
9663 p_cwh = 1;
9664 }
9665#endif
9666 if (p_ut < 0)
9667 {
9668 errmsg = e_positive;
9669 p_ut = 2000;
9670 }
9671 if (p_ss < 0)
9672 {
9673 errmsg = e_positive;
9674 p_ss = 0;
9675 }
9676
9677 /* May set global value for local option. */
9678 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9679 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9680
9681 options[opt_idx].flags |= P_WAS_SET;
9682
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009683#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009684 // Don't do this while starting up, failure or recursively.
9685 if (!starting && errmsg == NULL && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009686 {
Bram Moolenaard7c96872019-06-15 17:12:48 +02009687 char_u buf_old[11], buf_old_global[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009688 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009689 vim_snprintf((char *)buf_old_global, 10, "%ld", old_global_value);
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009690 vim_snprintf((char *)buf_new, 10, "%ld", value);
9691 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009692 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9693 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9694 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009695 if (opt_flags & OPT_LOCAL)
9696 {
9697 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
9698 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9699 }
9700 if (opt_flags & OPT_GLOBAL)
9701 {
9702 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
9703 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old, -1);
9704 }
9705 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9706 {
9707 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
9708 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9709 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old_global, -1);
9710 }
9711 if (opt_flags & OPT_MODELINE)
9712 {
9713 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
9714 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9715 }
9716 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname,
9717 NULL, FALSE, NULL);
Bram Moolenaar53744302015-07-17 17:38:22 +02009718 reset_v_option_vars();
9719 }
9720#endif
9721
Bram Moolenaar071d4272004-06-13 20:20:40 +00009722 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009723 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009724 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009725 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009726 check_redraw(options[opt_idx].flags);
9727
9728 return errmsg;
9729}
9730
9731/*
9732 * Called after an option changed: check if something needs to be redrawn.
9733 */
9734 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009735check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009736{
9737 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009738 int doclear = (flags & P_RCLR) == P_RCLR;
9739 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009740
Bram Moolenaar071d4272004-06-13 20:20:40 +00009741 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9742 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009743
9744 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9745 changed_window_setting();
9746 if (flags & P_RBUF)
9747 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009748 if (flags & P_RWINONLY)
9749 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009750 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009751 redraw_all_later(CLEAR);
9752 else if (all)
9753 redraw_all_later(NOT_VALID);
9754}
9755
9756/*
9757 * Find index for option 'arg'.
9758 * Return -1 if not found.
9759 */
9760 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009761findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009762{
9763 int opt_idx;
9764 char *s, *p;
9765 static short quick_tab[27] = {0, 0}; /* quick access table */
9766 int is_term_opt;
9767
9768 /*
9769 * For first call: Initialize the quick-access table.
9770 * It contains the index for the first option that starts with a certain
9771 * letter. There are 26 letters, plus the first "t_" option.
9772 */
9773 if (quick_tab[1] == 0)
9774 {
9775 p = options[0].fullname;
9776 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9777 {
9778 if (s[0] != p[0])
9779 {
9780 if (s[0] == 't' && s[1] == '_')
9781 quick_tab[26] = opt_idx;
9782 else
9783 quick_tab[CharOrdLow(s[0])] = opt_idx;
9784 }
9785 p = s;
9786 }
9787 }
9788
9789 /*
9790 * Check for name starting with an illegal character.
9791 */
9792#ifdef EBCDIC
9793 if (!islower(arg[0]))
9794#else
9795 if (arg[0] < 'a' || arg[0] > 'z')
9796#endif
9797 return -1;
9798
9799 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9800 if (is_term_opt)
9801 opt_idx = quick_tab[26];
9802 else
9803 opt_idx = quick_tab[CharOrdLow(arg[0])];
9804 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9805 {
9806 if (STRCMP(arg, s) == 0) /* match full name */
9807 break;
9808 }
9809 if (s == NULL && !is_term_opt)
9810 {
9811 opt_idx = quick_tab[CharOrdLow(arg[0])];
9812 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9813 {
9814 s = options[opt_idx].shortname;
9815 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9816 break;
9817 s = NULL;
9818 }
9819 }
9820 if (s == NULL)
9821 opt_idx = -1;
9822 return opt_idx;
9823}
9824
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009825#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009826/*
9827 * Get the value for an option.
9828 *
9829 * Returns:
9830 * Number or Toggle option: 1, *numval gets value.
9831 * String option: 0, *stringval gets allocated string.
9832 * Hidden Number or Toggle option: -1.
9833 * hidden String option: -2.
9834 * unknown option: -3.
9835 */
9836 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009837get_option_value(
9838 char_u *name,
9839 long *numval,
9840 char_u **stringval, /* NULL when only checking existence */
9841 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009842{
9843 int opt_idx;
9844 char_u *varp;
9845
9846 opt_idx = findoption(name);
9847 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009848 {
9849 int key;
9850
9851 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009852 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009853 {
9854 char_u key_name[2];
9855 char_u *p;
9856
9857 if (key < 0)
9858 {
9859 key_name[0] = KEY2TERMCAP0(key);
9860 key_name[1] = KEY2TERMCAP1(key);
9861 }
9862 else
9863 {
9864 key_name[0] = KS_KEY;
9865 key_name[1] = (key & 0xff);
9866 }
9867 p = find_termcode(key_name);
9868 if (p != NULL)
9869 {
9870 if (stringval != NULL)
9871 *stringval = vim_strsave(p);
9872 return 0;
9873 }
9874 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009875 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009876 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009877
9878 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9879
9880 if (options[opt_idx].flags & P_STRING)
9881 {
9882 if (varp == NULL) /* hidden option */
9883 return -2;
9884 if (stringval != NULL)
9885 {
9886#ifdef FEAT_CRYPT
9887 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009888 if ((char_u **)varp == &curbuf->b_p_key
9889 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009890 *stringval = vim_strsave((char_u *)"*****");
9891 else
9892#endif
9893 *stringval = vim_strsave(*(char_u **)(varp));
9894 }
9895 return 0;
9896 }
9897
9898 if (varp == NULL) /* hidden option */
9899 return -1;
9900 if (options[opt_idx].flags & P_NUM)
9901 *numval = *(long *)varp;
9902 else
9903 {
9904 /* Special case: 'modified' is b_changed, but we also want to consider
9905 * it set when 'ff' or 'fenc' changed. */
9906 if ((int *)varp == &curbuf->b_changed)
9907 *numval = curbufIsChanged();
9908 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009909 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009910 }
9911 return 1;
9912}
9913#endif
9914
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009915#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009916/*
9917 * Returns the option attributes and its value. Unlike the above function it
9918 * will return either global value or local value of the option depending on
9919 * what was requested, but it will never return global value if it was
9920 * requested to return local one and vice versa. Neither it will return
9921 * buffer-local value if it was requested to return window-local one.
9922 *
9923 * Pretends that option is absent if it is not present in the requested scope
9924 * (i.e. has no global, window-local or buffer-local value depending on
9925 * opt_type). Uses
9926 *
9927 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009928 * 0 hidden or unknown option, also option that does not have requested
9929 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009930 * see SOPT_* in vim.h for other flags
9931 *
9932 * Possible opt_type values: see SREQ_* in vim.h
9933 */
9934 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009935get_option_value_strict(
9936 char_u *name,
9937 long *numval,
9938 char_u **stringval, /* NULL when only obtaining attributes */
9939 int opt_type,
9940 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009941{
9942 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009943 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009944 struct vimoption *p;
9945 int r = 0;
9946
9947 opt_idx = findoption(name);
9948 if (opt_idx < 0)
9949 return 0;
9950
9951 p = &(options[opt_idx]);
9952
9953 /* Hidden option */
9954 if (p->var == NULL)
9955 return 0;
9956
9957 if (p->flags & P_BOOL)
9958 r |= SOPT_BOOL;
9959 else if (p->flags & P_NUM)
9960 r |= SOPT_NUM;
9961 else if (p->flags & P_STRING)
9962 r |= SOPT_STRING;
9963
9964 if (p->indir == PV_NONE)
9965 {
9966 if (opt_type == SREQ_GLOBAL)
9967 r |= SOPT_GLOBAL;
9968 else
9969 return 0; /* Did not request global-only option */
9970 }
9971 else
9972 {
9973 if (p->indir & PV_BOTH)
9974 r |= SOPT_GLOBAL;
9975 else if (opt_type == SREQ_GLOBAL)
9976 return 0; /* Requested global option */
9977
9978 if (p->indir & PV_WIN)
9979 {
9980 if (opt_type == SREQ_BUF)
9981 return 0; /* Did not request window-local option */
9982 else
9983 r |= SOPT_WIN;
9984 }
9985 else if (p->indir & PV_BUF)
9986 {
9987 if (opt_type == SREQ_WIN)
9988 return 0; /* Did not request buffer-local option */
9989 else
9990 r |= SOPT_BUF;
9991 }
9992 }
9993
9994 if (stringval == NULL)
9995 return r;
9996
9997 if (opt_type == SREQ_GLOBAL)
9998 varp = p->var;
9999 else
10000 {
10001 if (opt_type == SREQ_BUF)
10002 {
10003 /* Special case: 'modified' is b_changed, but we also want to
10004 * consider it set when 'ff' or 'fenc' changed. */
10005 if (p->indir == PV_MOD)
10006 {
Bram Moolenaardefe6422018-06-24 15:14:07 +020010007 *numval = bufIsChanged((buf_T *)from);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010008 varp = NULL;
10009 }
10010#ifdef FEAT_CRYPT
10011 else if (p->indir == PV_KEY)
10012 {
10013 /* never return the value of the crypt key */
10014 *stringval = NULL;
10015 varp = NULL;
10016 }
10017#endif
10018 else
10019 {
Bram Moolenaardefe6422018-06-24 15:14:07 +020010020 buf_T *save_curbuf = curbuf;
10021
10022 // only getting a pointer, no need to use aucmd_prepbuf()
10023 curbuf = (buf_T *)from;
10024 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010025 varp = get_varp(p);
Bram Moolenaardefe6422018-06-24 15:14:07 +020010026 curbuf = save_curbuf;
10027 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010028 }
10029 }
10030 else if (opt_type == SREQ_WIN)
10031 {
Bram Moolenaardefe6422018-06-24 15:14:07 +020010032 win_T *save_curwin = curwin;
10033
10034 curwin = (win_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010035 curbuf = curwin->w_buffer;
10036 varp = get_varp(p);
10037 curwin = save_curwin;
10038 curbuf = curwin->w_buffer;
10039 }
10040 if (varp == p->var)
10041 return (r | SOPT_UNSET);
10042 }
10043
10044 if (varp != NULL)
10045 {
10046 if (p->flags & P_STRING)
10047 *stringval = vim_strsave(*(char_u **)(varp));
10048 else if (p->flags & P_NUM)
10049 *numval = *(long *) varp;
10050 else
10051 *numval = *(int *)varp;
10052 }
10053
10054 return r;
10055}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010056
10057/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010058 * Iterate over options. First argument is a pointer to a pointer to a
10059 * structure inside options[] array, second is option type like in the above
10060 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010061 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010062 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010063 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010064 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010065 * first argument to NULL.
10066 *
10067 * Returns full option name for current option on each call.
10068 */
10069 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010070option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010071{
10072 struct vimoption *ret = NULL;
10073 do
10074 {
10075 if (*option == NULL)
10076 *option = (void *) options;
10077 else if (((struct vimoption *) (*option))->fullname == NULL)
10078 {
10079 *option = NULL;
10080 return NULL;
10081 }
10082 else
10083 *option = (void *) (((struct vimoption *) (*option)) + 1);
10084
10085 ret = ((struct vimoption *) (*option));
10086
10087 /* Hidden option */
10088 if (ret->var == NULL)
10089 {
10090 ret = NULL;
10091 continue;
10092 }
10093
10094 switch (opt_type)
10095 {
10096 case SREQ_GLOBAL:
10097 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
10098 ret = NULL;
10099 break;
10100 case SREQ_BUF:
10101 if (!(ret->indir & PV_BUF))
10102 ret = NULL;
10103 break;
10104 case SREQ_WIN:
10105 if (!(ret->indir & PV_WIN))
10106 ret = NULL;
10107 break;
10108 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +010010109 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010110 return NULL;
10111 }
10112 }
10113 while (ret == NULL);
10114
10115 return (char_u *)ret->fullname;
10116}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010117#endif
10118
Bram Moolenaar071d4272004-06-13 20:20:40 +000010119/*
10120 * Set the value of option "name".
10121 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010122 *
10123 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010124 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010125 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010126set_option_value(
10127 char_u *name,
10128 long number,
10129 char_u *string,
10130 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010131{
10132 int opt_idx;
10133 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +000010134 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010135
10136 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010137 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +010010138 {
10139 int key;
10140
10141 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010142 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +010010143 {
10144 char_u key_name[2];
10145
10146 if (key < 0)
10147 {
10148 key_name[0] = KEY2TERMCAP0(key);
10149 key_name[1] = KEY2TERMCAP1(key);
10150 }
10151 else
10152 {
10153 key_name[0] = KS_KEY;
10154 key_name[1] = (key & 0xff);
10155 }
10156 add_termcode(key_name, string, FALSE);
10157 if (full_screen)
10158 ttest(FALSE);
10159 redraw_all_later(CLEAR);
10160 return NULL;
10161 }
10162
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010163 semsg(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +010010164 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010165 else
10166 {
10167 flags = options[opt_idx].flags;
10168#ifdef HAVE_SANDBOX
10169 /* Disallow changing some options in the sandbox */
10170 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010171 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010172 emsg(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010173 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010174 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010175#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010176 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010177 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010178 else
10179 {
Bram Moolenaarb3163762008-07-08 15:15:08 +000010180 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010181 if (varp != NULL) /* hidden option is not changed */
10182 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010183 if (number == 0 && string != NULL)
10184 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +000010185 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010186
10187 /* Either we are given a string or we are setting option
10188 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +000010189 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010190 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +000010191 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010192 {
10193 /* There's another character after zeros or the string
10194 * is empty. In both cases, we are trying to set a
10195 * num option using a string. */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010196 semsg(_("E521: Number required: &%s = '%s'"),
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010197 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010198 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010199
10200 }
10201 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010202 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010203 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +000010204 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010205 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010206 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010207 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010208 }
10209 }
10210 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010211 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010212}
10213
10214/*
10215 * Get the terminal code for a terminal option.
10216 * Returns NULL when not found.
10217 */
10218 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010219get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010220{
10221 int opt_idx;
10222 char_u *varp;
10223
10224 if (tname[0] != 't' || tname[1] != '_' ||
10225 tname[2] == NUL || tname[3] == NUL)
10226 return NULL;
10227 if ((opt_idx = findoption(tname)) >= 0)
10228 {
10229 varp = get_varp(&(options[opt_idx]));
10230 if (varp != NULL)
10231 varp = *(char_u **)(varp);
10232 return varp;
10233 }
10234 return find_termcode(tname + 2);
10235}
10236
10237 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010238get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010239{
10240 int i;
10241
10242 i = findoption((char_u *)"hl");
10243 if (i >= 0)
10244 return options[i].def_val[VI_DEFAULT];
10245 return (char_u *)NULL;
10246}
10247
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010248 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010249get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010250{
10251 int i;
10252
10253 i = findoption((char_u *)"enc");
10254 if (i >= 0)
10255 return options[i].def_val[VI_DEFAULT];
10256 return (char_u *)NULL;
10257}
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010258
Bram Moolenaar071d4272004-06-13 20:20:40 +000010259/*
10260 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010261 * When "has_lt" is true there is a '<' before "*arg_arg".
10262 * Returns 0 when the key is not recognized.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010263 */
10264 static int
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010265find_key_option(char_u *arg_arg, int has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010266{
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010267 int key = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010268 int modifiers;
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010269 char_u *arg = arg_arg;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010270
10271 /*
10272 * Don't use get_special_key_code() for t_xx, we don't want it to call
10273 * add_termcap_entry().
10274 */
10275 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
10276 key = TERMCAP2KEY(arg[2], arg[3]);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010277 else if (has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010278 {
10279 --arg; /* put arg at the '<' */
10280 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +020010281 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010282 if (modifiers) /* can't handle modifiers here */
10283 key = 0;
10284 }
10285 return key;
10286}
10287
10288/*
10289 * if 'all' == 0: show changed options
10290 * if 'all' == 1: show all normal options
10291 * if 'all' == 2: show all terminal options
10292 */
10293 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010294showoptions(
10295 int all,
10296 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010297{
10298 struct vimoption *p;
10299 int col;
10300 int isterm;
10301 char_u *varp;
10302 struct vimoption **items;
10303 int item_count;
10304 int run;
10305 int row, rows;
10306 int cols;
10307 int i;
10308 int len;
10309
10310#define INC 20
10311#define GAP 3
10312
Bram Moolenaarc799fe22019-05-28 23:08:19 +020010313 items = ALLOC_MULT(struct vimoption *, PARAM_COUNT);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010314 if (items == NULL)
10315 return;
10316
10317 /* Highlight title */
10318 if (all == 2)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010319 msg_puts_title(_("\n--- Terminal codes ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010320 else if (opt_flags & OPT_GLOBAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010321 msg_puts_title(_("\n--- Global option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010322 else if (opt_flags & OPT_LOCAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010323 msg_puts_title(_("\n--- Local option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010324 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010325 msg_puts_title(_("\n--- Options ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010326
10327 /*
10328 * do the loop two times:
10329 * 1. display the short items
10330 * 2. display the long items (only strings and numbers)
10331 */
10332 for (run = 1; run <= 2 && !got_int; ++run)
10333 {
10334 /*
10335 * collect the items in items[]
10336 */
10337 item_count = 0;
10338 for (p = &options[0]; p->fullname != NULL; p++)
10339 {
Bram Moolenaarf86db782018-10-25 13:31:37 +020010340 // apply :filter /pat/
10341 if (message_filtered((char_u *) p->fullname))
10342 continue;
10343
Bram Moolenaar071d4272004-06-13 20:20:40 +000010344 varp = NULL;
10345 isterm = istermoption(p);
10346 if (opt_flags != 0)
10347 {
10348 if (p->indir != PV_NONE && !isterm)
10349 varp = get_varp_scope(p, opt_flags);
10350 }
10351 else
10352 varp = get_varp(p);
10353 if (varp != NULL
10354 && ((all == 2 && isterm)
10355 || (all == 1 && !isterm)
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010356 || (all == 0 && !optval_default(p, varp, p_cp))))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010357 {
10358 if (p->flags & P_BOOL)
10359 len = 1; /* a toggle option fits always */
10360 else
10361 {
10362 option_value2string(p, opt_flags);
10363 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
10364 }
10365 if ((len <= INC - GAP && run == 1) ||
10366 (len > INC - GAP && run == 2))
10367 items[item_count++] = p;
10368 }
10369 }
10370
10371 /*
10372 * display the items
10373 */
10374 if (run == 1)
10375 {
10376 cols = (Columns + GAP - 3) / INC;
10377 if (cols == 0)
10378 cols = 1;
10379 rows = (item_count + cols - 1) / cols;
10380 }
10381 else /* run == 2 */
10382 rows = item_count;
10383 for (row = 0; row < rows && !got_int; ++row)
10384 {
10385 msg_putchar('\n'); /* go to next line */
10386 if (got_int) /* 'q' typed in more */
10387 break;
10388 col = 0;
10389 for (i = row; i < item_count; i += rows)
10390 {
10391 msg_col = col; /* make columns */
10392 showoneopt(items[i], opt_flags);
10393 col += INC;
10394 }
10395 out_flush();
10396 ui_breakcheck();
10397 }
10398 }
10399 vim_free(items);
10400}
10401
10402/*
10403 * Return TRUE if option "p" has its default value.
10404 */
10405 static int
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010406optval_default(struct vimoption *p, char_u *varp, int compatible)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010407{
10408 int dvi;
10409
10410 if (varp == NULL)
10411 return TRUE; /* hidden option is always at default */
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010412 dvi = ((p->flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010413 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010414 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010415 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010416 /* the cast to long is required for Manx C, long_i is
10417 * needed for MSVC */
10418 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010419 /* P_STRING */
10420 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
10421}
10422
10423/*
10424 * showoneopt: show the value of one option
10425 * must not be called with a hidden option!
10426 */
10427 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010428showoneopt(
10429 struct vimoption *p,
10430 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010431{
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010432 char_u *varp;
10433 int save_silent = silent_mode;
10434
10435 silent_mode = FALSE;
10436 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010437
10438 varp = get_varp_scope(p, opt_flags);
10439
10440 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
10441 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
10442 ? !curbufIsChanged() : !*(int *)varp))
Bram Moolenaar32526b32019-01-19 17:43:09 +010010443 msg_puts("no");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010444 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010445 msg_puts("--");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010446 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010447 msg_puts(" ");
10448 msg_puts(p->fullname);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010449 if (!(p->flags & P_BOOL))
10450 {
10451 msg_putchar('=');
10452 /* put value string in NameBuff */
10453 option_value2string(p, opt_flags);
10454 msg_outtrans(NameBuff);
10455 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010456
10457 silent_mode = save_silent;
10458 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010459}
10460
10461/*
10462 * Write modified options as ":set" commands to a file.
10463 *
10464 * There are three values for "opt_flags":
10465 * OPT_GLOBAL: Write global option values and fresh values of
10466 * buffer-local options (used for start of a session
10467 * file).
10468 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10469 * curwin (used for a vimrc file).
10470 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10471 * and local values for window-local options of
10472 * curwin. Local values are also written when at the
10473 * default value, because a modeline or autocommand
10474 * may have set them when doing ":edit file" and the
10475 * user has set them back at the default or fresh
10476 * value.
10477 * When "local_only" is TRUE, don't write fresh
10478 * values, only local values (for ":mkview").
10479 * (fresh value = value used for a new buffer or window for a local option).
10480 *
10481 * Return FAIL on error, OK otherwise.
10482 */
10483 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010484makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010485{
10486 struct vimoption *p;
10487 char_u *varp; /* currently used value */
10488 char_u *varp_fresh; /* local value */
10489 char_u *varp_local = NULL; /* fresh value */
10490 char *cmd;
10491 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010492 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010493
10494 /*
10495 * The options that don't have a default (terminal name, columns, lines)
10496 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010497 * Do the loop over "options[]" twice: once for options with the
10498 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010499 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010500 for (pri = 1; pri >= 0; --pri)
10501 {
10502 for (p = &options[0]; !istermoption(p); p++)
10503 if (!(p->flags & P_NO_MKRC)
10504 && !istermoption(p)
10505 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010506 {
10507 /* skip global option when only doing locals */
10508 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10509 continue;
10510
10511 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10512 * file, they are always buffer-specific. */
10513 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10514 continue;
10515
10516 /* Global values are only written when not at the default value. */
10517 varp = get_varp_scope(p, opt_flags);
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010518 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp, p_cp))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010519 continue;
10520
10521 round = 2;
10522 if (p->indir != PV_NONE)
10523 {
10524 if (p->var == VAR_WIN)
10525 {
10526 /* skip window-local option when only doing globals */
10527 if (!(opt_flags & OPT_LOCAL))
10528 continue;
10529 /* When fresh value of window-local option is not at the
10530 * default, need to write it too. */
10531 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10532 {
10533 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010534 if (!optval_default(p, varp_fresh, p_cp))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010535 {
10536 round = 1;
10537 varp_local = varp;
10538 varp = varp_fresh;
10539 }
10540 }
10541 }
10542 }
10543
10544 /* Round 1: fresh value for window-local options.
10545 * Round 2: other values */
10546 for ( ; round <= 2; varp = varp_local, ++round)
10547 {
10548 if (round == 1 || (opt_flags & OPT_GLOBAL))
10549 cmd = "set";
10550 else
10551 cmd = "setlocal";
10552
10553 if (p->flags & P_BOOL)
10554 {
10555 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10556 return FAIL;
10557 }
10558 else if (p->flags & P_NUM)
10559 {
10560 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10561 return FAIL;
10562 }
10563 else /* P_STRING */
10564 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010565 int do_endif = FALSE;
10566
Bram Moolenaar071d4272004-06-13 20:20:40 +000010567 /* Don't set 'syntax' and 'filetype' again if the value is
10568 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010569 if (
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +010010570#if defined(FEAT_SYN_HL)
10571 p->indir == PV_SYN ||
10572#endif
10573 p->indir == PV_FT)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010574 {
10575 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10576 *(char_u **)(varp)) < 0
10577 || put_eol(fd) < 0)
10578 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010579 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010580 }
10581 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010582 p->flags) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010583 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010584 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010585 {
10586 if (put_line(fd, "endif") == FAIL)
10587 return FAIL;
10588 }
10589 }
10590 }
10591 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010592 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010593 return OK;
10594}
10595
10596#if defined(FEAT_FOLDING) || defined(PROTO)
10597/*
10598 * Generate set commands for the local fold options only. Used when
10599 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10600 */
10601 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010602makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010603{
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010604 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, 0) == FAIL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010605# ifdef FEAT_EVAL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010606 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010607 == FAIL
10608# endif
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010609 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010610 == FAIL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010611 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010612 == FAIL
10613 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10614 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10615 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10616 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10617 )
10618 return FAIL;
10619
10620 return OK;
10621}
10622#endif
10623
10624 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010625put_setstring(
10626 FILE *fd,
10627 char *cmd,
10628 char *name,
10629 char_u **valuep,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010630 long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010631{
10632 char_u *s;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010633 char_u *buf = NULL;
10634 char_u *part = NULL;
10635 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010636
10637 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10638 return FAIL;
10639 if (*valuep != NULL)
10640 {
10641 /* Output 'pastetoggle' as key names. For other
10642 * options some characters have to be escaped with
10643 * CTRL-V or backslash */
10644 if (valuep == &p_pt)
10645 {
10646 s = *valuep;
10647 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010648 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010649 return FAIL;
10650 }
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010651 // expand the option value, replace $HOME by ~
10652 else if ((flags & P_EXPAND) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010653 {
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010654 int size = (int)STRLEN(*valuep) + 1;
10655
10656 // replace home directory in the whole option value into "buf"
10657 buf = alloc(size);
Bram Moolenaarf8441472011-04-28 17:24:58 +020010658 if (buf == NULL)
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010659 goto fail;
10660 home_replace(NULL, *valuep, buf, size, FALSE);
10661
10662 // If the option value is longer than MAXPATHL, we need to append
10663 // earch comma separated part of the option separately, so that it
10664 // can be expanded when read back.
10665 if (size >= MAXPATHL && (flags & P_COMMA) != 0
10666 && vim_strchr(*valuep, ',') != NULL)
10667 {
10668 part = alloc(size);
10669 if (part == NULL)
10670 goto fail;
10671
10672 // write line break to clear the option, e.g. ':set rtp='
10673 if (put_eol(fd) == FAIL)
10674 goto fail;
10675
10676 p = buf;
10677 while (*p != NUL)
10678 {
10679 // for each comma separated option part, append value to
10680 // the option, :set rtp+=value
10681 if (fprintf(fd, "%s %s+=", cmd, name) < 0)
10682 goto fail;
10683 (void)copy_option_part(&p, part, size, ",");
10684 if (put_escstr(fd, part, 2) == FAIL || put_eol(fd) == FAIL)
10685 goto fail;
10686 }
10687 vim_free(buf);
10688 vim_free(part);
10689 return OK;
10690 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010691 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010692 {
10693 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010694 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010695 }
10696 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010697 }
10698 else if (put_escstr(fd, *valuep, 2) == FAIL)
10699 return FAIL;
10700 }
10701 if (put_eol(fd) < 0)
10702 return FAIL;
10703 return OK;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010704fail:
10705 vim_free(buf);
10706 vim_free(part);
10707 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010708}
10709
10710 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010711put_setnum(
10712 FILE *fd,
10713 char *cmd,
10714 char *name,
10715 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010716{
10717 long wc;
10718
10719 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10720 return FAIL;
10721 if (wc_use_keyname((char_u *)valuep, &wc))
10722 {
10723 /* print 'wildchar' and 'wildcharm' as a key name */
10724 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10725 return FAIL;
10726 }
10727 else if (fprintf(fd, "%ld", *valuep) < 0)
10728 return FAIL;
10729 if (put_eol(fd) < 0)
10730 return FAIL;
10731 return OK;
10732}
10733
10734 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010735put_setbool(
10736 FILE *fd,
10737 char *cmd,
10738 char *name,
10739 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010740{
Bram Moolenaar893de922007-10-02 18:40:57 +000010741 if (value < 0) /* global/local option using global value */
10742 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010743 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10744 || put_eol(fd) < 0)
10745 return FAIL;
10746 return OK;
10747}
10748
10749/*
10750 * Clear all the terminal options.
10751 * If the option has been allocated, free the memory.
10752 * Terminal options are never hidden or indirect.
10753 */
10754 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010755clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010756{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010757 /*
10758 * Reset a few things before clearing the old options. This may cause
10759 * outputting a few things that the terminal doesn't understand, but the
10760 * screen will be cleared later, so this is OK.
10761 */
10762#ifdef FEAT_MOUSE_TTY
10763 mch_setmouse(FALSE); /* switch mouse off */
10764#endif
10765#ifdef FEAT_TITLE
Bram Moolenaar40385db2018-08-07 22:31:44 +020010766 mch_restore_title(SAVE_RESTORE_BOTH); /* restore window titles */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010767#endif
10768#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10769 /* When starting the GUI close the display opened for the clipboard.
10770 * After restoring the title, because that will need the display. */
10771 if (gui.starting)
10772 clear_xterm_clip();
10773#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010774 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010775
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010776 free_termoptions();
10777}
10778
10779 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010780free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010781{
10782 struct vimoption *p;
10783
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010784 for (p = options; p->fullname != NULL; p++)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010785 if (istermoption(p))
10786 {
10787 if (p->flags & P_ALLOCED)
10788 free_string_option(*(char_u **)(p->var));
10789 if (p->flags & P_DEF_ALLOCED)
10790 free_string_option(p->def_val[VI_DEFAULT]);
10791 *(char_u **)(p->var) = empty_option;
10792 p->def_val[VI_DEFAULT] = empty_option;
10793 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010794#ifdef FEAT_EVAL
10795 // remember where the option was cleared
10796 set_option_sctx_idx((int)(p - options), OPT_GLOBAL, current_sctx);
10797#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010798 }
10799 clear_termcodes();
10800}
10801
10802/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010803 * Free the string for one term option, if it was allocated.
10804 * Set the string to empty_option and clear allocated flag.
10805 * "var" points to the option value.
10806 */
10807 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010808free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010809{
10810 struct vimoption *p;
10811
10812 for (p = &options[0]; p->fullname != NULL; p++)
10813 if (p->var == var)
10814 {
10815 if (p->flags & P_ALLOCED)
10816 free_string_option(*(char_u **)(p->var));
10817 *(char_u **)(p->var) = empty_option;
10818 p->flags &= ~P_ALLOCED;
10819 break;
10820 }
10821}
10822
10823/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010824 * Set the terminal option defaults to the current value.
10825 * Used after setting the terminal name.
10826 */
10827 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010828set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010829{
10830 struct vimoption *p;
10831
10832 for (p = &options[0]; p->fullname != NULL; p++)
10833 {
10834 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10835 {
10836 if (p->flags & P_DEF_ALLOCED)
10837 {
10838 free_string_option(p->def_val[VI_DEFAULT]);
10839 p->flags &= ~P_DEF_ALLOCED;
10840 }
10841 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10842 if (p->flags & P_ALLOCED)
10843 {
10844 p->flags |= P_DEF_ALLOCED;
10845 p->flags &= ~P_ALLOCED; /* don't free the value now */
10846 }
10847 }
10848 }
10849}
10850
10851/*
10852 * return TRUE if 'p' starts with 't_'
10853 */
10854 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010855istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010856{
10857 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10858}
10859
10860/*
10861 * Compute columns for ruler and shown command. 'sc_col' is also used to
10862 * decide what the maximum length of a message on the status line can be.
10863 * If there is a status line for the last window, 'sc_col' is independent
10864 * of 'ru_col'.
10865 */
10866
10867#define COL_RULER 17 /* columns needed by standard ruler */
10868
10869 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010870comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010871{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010872#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010873 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010874
10875 sc_col = 0;
10876 ru_col = 0;
10877 if (p_ru)
10878 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010879# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010880 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010881# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010882 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010883# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010884 /* no last status line, adjust sc_col */
10885 if (!last_has_status)
10886 sc_col = ru_col;
10887 }
10888 if (p_sc)
10889 {
10890 sc_col += SHOWCMD_COLS;
10891 if (!p_ru || last_has_status) /* no need for separating space */
10892 ++sc_col;
10893 }
10894 sc_col = Columns - sc_col;
10895 ru_col = Columns - ru_col;
10896 if (sc_col <= 0) /* screen too narrow, will become a mess */
10897 sc_col = 1;
10898 if (ru_col <= 0)
10899 ru_col = 1;
10900#else
10901 sc_col = Columns;
10902 ru_col = Columns;
10903#endif
10904}
10905
Bram Moolenaar113e1072019-01-20 15:30:40 +010010906#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010907/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010908 * Unset local option value, similar to ":set opt<".
10909 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010910 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010911unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010912{
10913 struct vimoption *p;
10914 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010915 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010916
10917 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010918 if (opt_idx < 0)
10919 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010920 p = &(options[opt_idx]);
10921
10922 switch ((int)p->indir)
10923 {
10924 /* global option with local value: use local value if it's been set */
10925 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010926 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010927 break;
10928 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010929 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010930 break;
10931 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010932 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010933 break;
10934 case PV_AR:
10935 buf->b_p_ar = -1;
10936 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010937 case PV_BKC:
10938 clear_string_option(&buf->b_p_bkc);
10939 buf->b_bkc_flags = 0;
10940 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010941 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010942 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010943 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010944 case PV_TC:
10945 clear_string_option(&buf->b_p_tc);
10946 buf->b_tc_flags = 0;
10947 break;
Bram Moolenaar375e3392019-01-31 18:26:10 +010010948 case PV_SISO:
10949 curwin->w_p_siso = -1;
10950 break;
10951 case PV_SO:
10952 curwin->w_p_so = -1;
10953 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010954#ifdef FEAT_FIND_ID
10955 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010956 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010957 break;
10958 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010959 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010960 break;
10961#endif
10962#ifdef FEAT_INS_EXPAND
10963 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010964 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010965 break;
10966 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010967 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010968 break;
10969#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010970 case PV_FP:
10971 clear_string_option(&buf->b_p_fp);
10972 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010973#ifdef FEAT_QUICKFIX
10974 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010975 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010976 break;
10977 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010978 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010979 break;
10980 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010981 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010982 break;
10983#endif
10984#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10985 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010986 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010987 break;
10988#endif
10989#if defined(FEAT_CRYPT)
10990 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010991 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010992 break;
10993#endif
10994#ifdef FEAT_STL_OPT
10995 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010996 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010997 break;
10998#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010999 case PV_UL:
11000 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
11001 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011002#ifdef FEAT_LISP
11003 case PV_LW:
11004 clear_string_option(&buf->b_p_lw);
11005 break;
11006#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011007 case PV_MENC:
11008 clear_string_option(&buf->b_p_menc);
11009 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020011010 }
11011}
Bram Moolenaar113e1072019-01-20 15:30:40 +010011012#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020011013
11014/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011015 * Get pointer to option variable, depending on local or global scope.
11016 */
11017 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011018get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011019{
11020 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
11021 {
11022 if (p->var == VAR_WIN)
11023 return (char_u *)GLOBAL_WO(get_varp(p));
11024 return p->var;
11025 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000011026 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011027 {
11028 switch ((int)p->indir)
11029 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011030 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011031#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011032 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
11033 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
11034 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011035#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011036 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
11037 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
11038 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000011039 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011040 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011041 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar375e3392019-01-31 18:26:10 +010011042 case PV_SISO: return (char_u *)&(curwin->w_p_siso);
11043 case PV_SO: return (char_u *)&(curwin->w_p_so);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011044#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011045 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
11046 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011047#endif
11048#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011049 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
11050 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011051#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011052#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11053 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
11054#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011055#if defined(FEAT_CRYPT)
11056 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
11057#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011058#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011059 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011060#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011061 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011062#ifdef FEAT_LISP
11063 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
11064#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011065 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011066 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011067 }
11068 return NULL; /* "cannot happen" */
11069 }
11070 return get_varp(p);
11071}
11072
11073/*
11074 * Get pointer to option variable.
11075 */
11076 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011077get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011078{
11079 /* hidden option, always return NULL */
11080 if (p->var == NULL)
11081 return NULL;
11082
11083 switch ((int)p->indir)
11084 {
11085 case PV_NONE: return p->var;
11086
11087 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011088 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011089 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011090 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011091 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011092 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011093 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000011094 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000011095 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011096 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011097 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011098 case PV_TC: return *curbuf->b_p_tc != NUL
11099 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011100 case PV_BKC: return *curbuf->b_p_bkc != NUL
11101 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar375e3392019-01-31 18:26:10 +010011102 case PV_SISO: return curwin->w_p_siso >= 0
11103 ? (char_u *)&(curwin->w_p_siso) : p->var;
11104 case PV_SO: return curwin->w_p_so >= 0
11105 ? (char_u *)&(curwin->w_p_so) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011106#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011107 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011108 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011109 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011110 ? (char_u *)&(curbuf->b_p_inc) : p->var;
11111#endif
11112#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011113 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011114 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011115 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011116 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
11117#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011118 case PV_FP: return *curbuf->b_p_fp != NUL
11119 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011120#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011121 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011122 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011123 case PV_GP: return *curbuf->b_p_gp != NUL
11124 ? (char_u *)&(curbuf->b_p_gp) : p->var;
11125 case PV_MP: return *curbuf->b_p_mp != NUL
11126 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011127#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011128#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11129 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
11130 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
11131#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011132#if defined(FEAT_CRYPT)
11133 case PV_CM: return *curbuf->b_p_cm != NUL
11134 ? (char_u *)&(curbuf->b_p_cm) : p->var;
11135#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011136#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011137 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011138 ? (char_u *)&(curwin->w_p_stl) : p->var;
11139#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011140 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
11141 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011142#ifdef FEAT_LISP
11143 case PV_LW: return *curbuf->b_p_lw != NUL
11144 ? (char_u *)&(curbuf->b_p_lw) : p->var;
11145#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011146 case PV_MENC: return *curbuf->b_p_menc != NUL
11147 ? (char_u *)&(curbuf->b_p_menc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011148#ifdef FEAT_ARABIC
11149 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
11150#endif
11151 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011152#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000011153 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
11154#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011155#ifdef FEAT_SYN_HL
11156 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
11157 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020011158 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011159#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011160#ifdef FEAT_DIFF
11161 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
11162#endif
11163#ifdef FEAT_FOLDING
11164 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
11165 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
11166 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
11167 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
11168 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
11169 case PV_FML: return (char_u *)&(curwin->w_p_fml);
11170 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
11171# ifdef FEAT_EVAL
11172 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
11173 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
11174# endif
11175 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
11176#endif
11177 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020011178 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011179#ifdef FEAT_LINEBREAK
11180 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
11181#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011182 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000011183 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020011184#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011185 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
11186#endif
11187#ifdef FEAT_RIGHTLEFT
11188 case PV_RL: return (char_u *)&(curwin->w_p_rl);
11189 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
11190#endif
11191 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
11192 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
11193#ifdef FEAT_LINEBREAK
11194 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020011195 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
11196 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011197#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011198 case PV_WCR: return (char_u *)&(curwin->w_p_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011199 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011200 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011201#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011202 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
11203 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
11204#endif
11205#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011206 case PV_TWK: return (char_u *)&(curwin->w_p_twk);
11207 case PV_TWS: return (char_u *)&(curwin->w_p_tws);
11208 case PV_TWSL: return (char_u *)&(curbuf->b_p_twsl);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011209#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011210
11211 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
11212 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011213 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011214 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
11215 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011216 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
11217 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
11218#ifdef FEAT_CINDENT
11219 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
11220 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
11221 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
11222#endif
11223#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11224 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
11225#endif
11226#ifdef FEAT_COMMENTS
11227 case PV_COM: return (char_u *)&(curbuf->b_p_com);
11228#endif
11229#ifdef FEAT_FOLDING
11230 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
11231#endif
11232#ifdef FEAT_INS_EXPAND
11233 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
Bram Moolenaarac3150d2019-07-28 16:36:39 +020011234# ifdef BACKSLASH_IN_FILENAME
11235 case PV_CSL: return (char_u *)&(curbuf->b_p_csl);
11236# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011237#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011238#ifdef FEAT_COMPL_FUNC
11239 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011240 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011241#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +020011242#ifdef FEAT_EVAL
11243 case PV_TFU: return (char_u *)&(curbuf->b_p_tfu);
11244#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011245 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020011246 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011247 case PV_ET: return (char_u *)&(curbuf->b_p_et);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011248 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011249 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011250 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011251 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011252 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011253 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
11254 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
11255 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
11256 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
11257#ifdef FEAT_FIND_ID
11258# ifdef FEAT_EVAL
11259 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
11260# endif
11261#endif
11262#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11263 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
11264 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
11265#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011266#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011267 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
11268#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011269#ifdef FEAT_CRYPT
11270 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
11271#endif
11272#ifdef FEAT_LISP
11273 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
11274#endif
11275 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
11276 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
11277 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
11278 case PV_MOD: return (char_u *)&(curbuf->b_changed);
11279 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011280 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011281#ifdef FEAT_TEXTOBJ
11282 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
11283#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011284 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
11285#ifdef FEAT_SMARTINDENT
11286 case PV_SI: return (char_u *)&(curbuf->b_p_si);
11287#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011288 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011289 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
11290#ifdef FEAT_SEARCHPATH
11291 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
11292#endif
11293 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
11294#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011295 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011296 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
11297#endif
11298#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020011299 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
11300 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
11301 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011302#endif
11303 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
11304 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
11305 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
11306 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011307#ifdef FEAT_PERSISTENT_UNDO
11308 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
11309#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011310 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
11311#ifdef FEAT_KEYMAP
11312 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
11313#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011314#ifdef FEAT_SIGNS
11315 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
11316#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011317#ifdef FEAT_VARTABS
11318 case PV_VSTS: return (char_u *)&(curbuf->b_p_vsts);
11319 case PV_VTS: return (char_u *)&(curbuf->b_p_vts);
11320#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010011321 default: iemsg(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011322 }
11323 /* always return a valid pointer to avoid a crash! */
11324 return (char_u *)&(curbuf->b_p_wm);
11325}
11326
11327/*
11328 * Get the value of 'equalprg', either the buffer-local one or the global one.
11329 */
11330 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011331get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011332{
11333 if (*curbuf->b_p_ep == NUL)
11334 return p_ep;
11335 return curbuf->b_p_ep;
11336}
11337
Bram Moolenaar071d4272004-06-13 20:20:40 +000011338/*
11339 * Copy options from one window to another.
11340 * Used when splitting a window.
11341 */
11342 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011343win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011344{
11345 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
11346 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020011347#if defined(FEAT_LINEBREAK)
11348 briopt_check(wp_to);
11349#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011350}
Bram Moolenaar071d4272004-06-13 20:20:40 +000011351
11352/*
11353 * Copy the options from one winopt_T to another.
11354 * Doesn't free the old option values in "to", use clear_winopt() for that.
11355 * The 'scroll' option is not copied, because it depends on the window height.
11356 * The 'previewwindow' option is reset, there can be only one preview window.
11357 */
11358 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011359copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011360{
11361#ifdef FEAT_ARABIC
11362 to->wo_arab = from->wo_arab;
11363#endif
11364 to->wo_list = from->wo_list;
11365 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020011366 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011367#ifdef FEAT_LINEBREAK
11368 to->wo_nuw = from->wo_nuw;
11369#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011370#ifdef FEAT_RIGHTLEFT
11371 to->wo_rl = from->wo_rl;
11372 to->wo_rlc = vim_strsave(from->wo_rlc);
11373#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011374#ifdef FEAT_STL_OPT
11375 to->wo_stl = vim_strsave(from->wo_stl);
11376#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011377 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011378#ifdef FEAT_DIFF
11379 to->wo_wrap_save = from->wo_wrap_save;
11380#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011381#ifdef FEAT_LINEBREAK
11382 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020011383 to->wo_bri = from->wo_bri;
11384 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011385#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011386 to->wo_wcr = vim_strsave(from->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011387 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011388 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010011389 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011390 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011391#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000011392 to->wo_spell = from->wo_spell;
11393#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011394#ifdef FEAT_SYN_HL
11395 to->wo_cuc = from->wo_cuc;
11396 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020011397 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011398#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011399#ifdef FEAT_DIFF
11400 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011401 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011402#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011403#ifdef FEAT_CONCEAL
11404 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020011405 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011406#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011407#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011408 to->wo_twk = vim_strsave(from->wo_twk);
11409 to->wo_tws = vim_strsave(from->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011410#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011411#ifdef FEAT_FOLDING
11412 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011413 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011414 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011415 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011416 to->wo_fdi = vim_strsave(from->wo_fdi);
11417 to->wo_fml = from->wo_fml;
11418 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011419 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011420 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011421 to->wo_fdm_save = from->wo_diff_saved
11422 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011423 to->wo_fdn = from->wo_fdn;
11424# ifdef FEAT_EVAL
11425 to->wo_fde = vim_strsave(from->wo_fde);
11426 to->wo_fdt = vim_strsave(from->wo_fdt);
11427# endif
11428 to->wo_fmr = vim_strsave(from->wo_fmr);
11429#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011430#ifdef FEAT_SIGNS
11431 to->wo_scl = vim_strsave(from->wo_scl);
11432#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011433 check_winopt(to); /* don't want NULL pointers */
11434}
11435
11436/*
11437 * Check string options in a window for a NULL value.
11438 */
Bram Moolenaar5843f5f2019-08-20 20:13:45 +020011439 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011440check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011441{
11442 check_winopt(&win->w_onebuf_opt);
11443 check_winopt(&win->w_allbuf_opt);
11444}
11445
11446/*
11447 * Check for NULL pointers in a winopt_T and replace them with empty_option.
11448 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020011449 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011450check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011451{
11452#ifdef FEAT_FOLDING
11453 check_string_option(&wop->wo_fdi);
11454 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011455 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011456# ifdef FEAT_EVAL
11457 check_string_option(&wop->wo_fde);
11458 check_string_option(&wop->wo_fdt);
11459# endif
11460 check_string_option(&wop->wo_fmr);
11461#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011462#ifdef FEAT_SIGNS
11463 check_string_option(&wop->wo_scl);
11464#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011465#ifdef FEAT_RIGHTLEFT
11466 check_string_option(&wop->wo_rlc);
11467#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011468#ifdef FEAT_STL_OPT
11469 check_string_option(&wop->wo_stl);
11470#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011471#ifdef FEAT_SYN_HL
11472 check_string_option(&wop->wo_cc);
11473#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011474#ifdef FEAT_CONCEAL
11475 check_string_option(&wop->wo_cocu);
11476#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011477#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011478 check_string_option(&wop->wo_twk);
11479 check_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011480#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011481#ifdef FEAT_LINEBREAK
11482 check_string_option(&wop->wo_briopt);
11483#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011484 check_string_option(&wop->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011485}
11486
11487/*
11488 * Free the allocated memory inside a winopt_T.
11489 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011490 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011491clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011492{
11493#ifdef FEAT_FOLDING
11494 clear_string_option(&wop->wo_fdi);
11495 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011496 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011497# ifdef FEAT_EVAL
11498 clear_string_option(&wop->wo_fde);
11499 clear_string_option(&wop->wo_fdt);
11500# endif
11501 clear_string_option(&wop->wo_fmr);
11502#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011503#ifdef FEAT_SIGNS
11504 clear_string_option(&wop->wo_scl);
11505#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011506#ifdef FEAT_LINEBREAK
11507 clear_string_option(&wop->wo_briopt);
11508#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011509 clear_string_option(&wop->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011510#ifdef FEAT_RIGHTLEFT
11511 clear_string_option(&wop->wo_rlc);
11512#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011513#ifdef FEAT_STL_OPT
11514 clear_string_option(&wop->wo_stl);
11515#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011516#ifdef FEAT_SYN_HL
11517 clear_string_option(&wop->wo_cc);
11518#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011519#ifdef FEAT_CONCEAL
11520 clear_string_option(&wop->wo_cocu);
11521#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011522#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011523 clear_string_option(&wop->wo_twk);
11524 clear_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011525#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011526}
11527
11528/*
11529 * Copy global option values to local options for one buffer.
11530 * Used when creating a new buffer and sometimes when entering a buffer.
11531 * flags:
11532 * BCO_ENTER We will enter the buf buffer.
11533 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11534 * appropriate.
11535 * BCO_NOHELP Don't copy the values to a help buffer.
11536 */
11537 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011538buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011539{
11540 int should_copy = TRUE;
11541 char_u *save_p_isk = NULL; /* init for GCC */
11542 int dont_do_help;
11543 int did_isk = FALSE;
11544
11545 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011546 * Skip this when the option defaults have not been set yet. Happens when
11547 * main() allocates the first buffer.
11548 */
11549 if (p_cpo != NULL)
11550 {
11551 /*
11552 * Always copy when entering and 'cpo' contains 'S'.
11553 * Don't copy when already initialized.
11554 * Don't copy when 'cpo' contains 's' and not entering.
11555 * 'S' BCO_ENTER initialized 's' should_copy
11556 * yes yes X X TRUE
11557 * yes no yes X FALSE
11558 * no X yes X FALSE
11559 * X no no yes FALSE
11560 * X no no no TRUE
11561 * no yes no X TRUE
11562 */
11563 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11564 && (buf->b_p_initialized
11565 || (!(flags & BCO_ENTER)
11566 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11567 should_copy = FALSE;
11568
11569 if (should_copy || (flags & BCO_ALWAYS))
11570 {
11571 /* Don't copy the options specific to a help buffer when
11572 * BCO_NOHELP is given or the options were initialized already
11573 * (jumping back to a help file with CTRL-T or CTRL-O) */
11574 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11575 || buf->b_p_initialized;
11576 if (dont_do_help) /* don't free b_p_isk */
11577 {
11578 save_p_isk = buf->b_p_isk;
11579 buf->b_p_isk = NULL;
11580 }
11581 /*
Bram Moolenaar40385db2018-08-07 22:31:44 +020011582 * Always free the allocated strings. If not already initialized,
11583 * reset 'readonly' and copy 'fileformat'.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011584 */
11585 if (!buf->b_p_initialized)
11586 {
11587 free_buf_options(buf, TRUE);
11588 buf->b_p_ro = FALSE; /* don't copy readonly */
11589 buf->b_p_tx = p_tx;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011590 buf->b_p_fenc = vim_strsave(p_fenc);
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011591 switch (*p_ffs)
11592 {
11593 case 'm':
11594 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11595 case 'd':
11596 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11597 case 'u':
11598 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11599 default:
11600 buf->b_p_ff = vim_strsave(p_ff);
11601 }
11602 if (buf->b_p_ff != NULL)
11603 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011604 buf->b_p_bh = empty_option;
11605 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011606 }
11607 else
11608 free_buf_options(buf, FALSE);
11609
11610 buf->b_p_ai = p_ai;
11611 buf->b_p_ai_nopaste = p_ai_nopaste;
11612 buf->b_p_sw = p_sw;
11613 buf->b_p_tw = p_tw;
11614 buf->b_p_tw_nopaste = p_tw_nopaste;
11615 buf->b_p_tw_nobin = p_tw_nobin;
11616 buf->b_p_wm = p_wm;
11617 buf->b_p_wm_nopaste = p_wm_nopaste;
11618 buf->b_p_wm_nobin = p_wm_nobin;
11619 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011620 buf->b_p_bomb = p_bomb;
Bram Moolenaarb388be02015-07-22 22:19:38 +020011621 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011622 buf->b_p_et = p_et;
11623 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011624 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011625 buf->b_p_ml = p_ml;
11626 buf->b_p_ml_nobin = p_ml_nobin;
11627 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011628 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011629#ifdef FEAT_INS_EXPAND
11630 buf->b_p_cpt = vim_strsave(p_cpt);
Bram Moolenaarac3150d2019-07-28 16:36:39 +020011631# ifdef BACKSLASH_IN_FILENAME
11632 buf->b_p_csl = vim_strsave(p_csl);
11633# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011634#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011635#ifdef FEAT_COMPL_FUNC
11636 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011637 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011638#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +020011639#ifdef FEAT_EVAL
11640 buf->b_p_tfu = vim_strsave(p_tfu);
11641#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011642 buf->b_p_sts = p_sts;
11643 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011644#ifdef FEAT_VARTABS
11645 buf->b_p_vsts = vim_strsave(p_vsts);
11646 if (p_vsts && p_vsts != empty_option)
11647 tabstop_set(p_vsts, &buf->b_p_vsts_array);
11648 else
11649 buf->b_p_vsts_array = 0;
11650 buf->b_p_vsts_nopaste = p_vsts_nopaste
11651 ? vim_strsave(p_vsts_nopaste) : NULL;
11652#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011653 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011654#ifdef FEAT_COMMENTS
11655 buf->b_p_com = vim_strsave(p_com);
11656#endif
11657#ifdef FEAT_FOLDING
11658 buf->b_p_cms = vim_strsave(p_cms);
11659#endif
11660 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011661 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011662 buf->b_p_nf = vim_strsave(p_nf);
11663 buf->b_p_mps = vim_strsave(p_mps);
11664#ifdef FEAT_SMARTINDENT
11665 buf->b_p_si = p_si;
11666#endif
11667 buf->b_p_ci = p_ci;
11668#ifdef FEAT_CINDENT
11669 buf->b_p_cin = p_cin;
11670 buf->b_p_cink = vim_strsave(p_cink);
11671 buf->b_p_cino = vim_strsave(p_cino);
11672#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011673 /* Don't copy 'filetype', it must be detected */
11674 buf->b_p_ft = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011675 buf->b_p_pi = p_pi;
11676#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11677 buf->b_p_cinw = vim_strsave(p_cinw);
11678#endif
11679#ifdef FEAT_LISP
11680 buf->b_p_lisp = p_lisp;
11681#endif
11682#ifdef FEAT_SYN_HL
11683 /* Don't copy 'syntax', it must be set */
11684 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011685 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011686 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011687#endif
11688#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011689 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011690 (void)compile_cap_prog(&buf->b_s);
11691 buf->b_s.b_p_spf = vim_strsave(p_spf);
11692 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011693#endif
11694#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11695 buf->b_p_inde = vim_strsave(p_inde);
11696 buf->b_p_indk = vim_strsave(p_indk);
11697#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011698 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011699#if defined(FEAT_EVAL)
11700 buf->b_p_fex = vim_strsave(p_fex);
11701#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011702#ifdef FEAT_CRYPT
11703 buf->b_p_key = vim_strsave(p_key);
11704#endif
11705#ifdef FEAT_SEARCHPATH
11706 buf->b_p_sua = vim_strsave(p_sua);
11707#endif
11708#ifdef FEAT_KEYMAP
11709 buf->b_p_keymap = vim_strsave(p_keymap);
11710 buf->b_kmap_state |= KEYMAP_INIT;
11711#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011712#ifdef FEAT_TERMINAL
11713 buf->b_p_twsl = p_twsl;
11714#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011715 /* This isn't really an option, but copying the langmap and IME
11716 * state from the current buffer is better than resetting it. */
11717 buf->b_p_iminsert = p_iminsert;
11718 buf->b_p_imsearch = p_imsearch;
11719
11720 /* options that are normally global but also have a local value
11721 * are not copied, start using the global value */
11722 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011723 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011724 buf->b_p_bkc = empty_option;
11725 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011726#ifdef FEAT_QUICKFIX
11727 buf->b_p_gp = empty_option;
11728 buf->b_p_mp = empty_option;
11729 buf->b_p_efm = empty_option;
11730#endif
11731 buf->b_p_ep = empty_option;
11732 buf->b_p_kp = empty_option;
11733 buf->b_p_path = empty_option;
11734 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011735 buf->b_p_tc = empty_option;
11736 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011737#ifdef FEAT_FIND_ID
11738 buf->b_p_def = empty_option;
11739 buf->b_p_inc = empty_option;
11740# ifdef FEAT_EVAL
11741 buf->b_p_inex = vim_strsave(p_inex);
11742# endif
11743#endif
11744#ifdef FEAT_INS_EXPAND
11745 buf->b_p_dict = empty_option;
11746 buf->b_p_tsr = empty_option;
11747#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011748#ifdef FEAT_TEXTOBJ
11749 buf->b_p_qe = vim_strsave(p_qe);
11750#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011751#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11752 buf->b_p_bexpr = empty_option;
11753#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011754#if defined(FEAT_CRYPT)
11755 buf->b_p_cm = empty_option;
11756#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011757#ifdef FEAT_PERSISTENT_UNDO
11758 buf->b_p_udf = p_udf;
11759#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011760#ifdef FEAT_LISP
11761 buf->b_p_lw = empty_option;
11762#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011763 buf->b_p_menc = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011764
11765 /*
11766 * Don't copy the options set by ex_help(), use the saved values,
11767 * when going from a help buffer to a non-help buffer.
11768 * Don't touch these at all when BCO_NOHELP is used and going from
11769 * or to a help buffer.
11770 */
11771 if (dont_do_help)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011772 {
Bram Moolenaar071d4272004-06-13 20:20:40 +000011773 buf->b_p_isk = save_p_isk;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011774#ifdef FEAT_VARTABS
11775 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11776 tabstop_set(p_vts, &buf->b_p_vts_array);
11777 else
11778 buf->b_p_vts_array = NULL;
11779#endif
11780 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011781 else
11782 {
11783 buf->b_p_isk = vim_strsave(p_isk);
11784 did_isk = TRUE;
11785 buf->b_p_ts = p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011786#ifdef FEAT_VARTABS
11787 buf->b_p_vts = vim_strsave(p_vts);
11788 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11789 tabstop_set(p_vts, &buf->b_p_vts_array);
11790 else
11791 buf->b_p_vts_array = NULL;
11792#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011793 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011794 if (buf->b_p_bt[0] == 'h')
11795 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011796 buf->b_p_ma = p_ma;
11797 }
11798 }
11799
11800 /*
11801 * When the options should be copied (ignoring BCO_ALWAYS), set the
11802 * flag that indicates that the options have been initialized.
11803 */
11804 if (should_copy)
11805 buf->b_p_initialized = TRUE;
11806 }
11807
11808 check_buf_options(buf); /* make sure we don't have NULLs */
11809 if (did_isk)
11810 (void)buf_init_chartab(buf, FALSE);
11811}
11812
11813/*
11814 * Reset the 'modifiable' option and its default value.
11815 */
11816 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011817reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011818{
11819 int opt_idx;
11820
11821 curbuf->b_p_ma = FALSE;
11822 p_ma = FALSE;
11823 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011824 if (opt_idx >= 0)
11825 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011826}
11827
11828/*
11829 * Set the global value for 'iminsert' to the local value.
11830 */
11831 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011832set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011833{
11834 p_iminsert = curbuf->b_p_iminsert;
11835}
11836
11837/*
11838 * Set the global value for 'imsearch' to the local value.
11839 */
11840 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011841set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011842{
11843 p_imsearch = curbuf->b_p_imsearch;
11844}
11845
Bram Moolenaar071d4272004-06-13 20:20:40 +000011846static int expand_option_idx = -1;
11847static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11848static int expand_option_flags = 0;
11849
11850 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011851set_context_in_set_cmd(
11852 expand_T *xp,
11853 char_u *arg,
11854 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011855{
11856 int nextchar;
11857 long_u flags = 0; /* init for GCC */
11858 int opt_idx = 0; /* init for GCC */
11859 char_u *p;
11860 char_u *s;
11861 int is_term_option = FALSE;
11862 int key;
11863
11864 expand_option_flags = opt_flags;
11865
11866 xp->xp_context = EXPAND_SETTINGS;
11867 if (*arg == NUL)
11868 {
11869 xp->xp_pattern = arg;
11870 return;
11871 }
11872 p = arg + STRLEN(arg) - 1;
11873 if (*p == ' ' && *(p - 1) != '\\')
11874 {
11875 xp->xp_pattern = p + 1;
11876 return;
11877 }
11878 while (p > arg)
11879 {
11880 s = p;
11881 /* count number of backslashes before ' ' or ',' */
11882 if (*p == ' ' || *p == ',')
11883 {
11884 while (s > arg && *(s - 1) == '\\')
11885 --s;
11886 }
11887 /* break at a space with an even number of backslashes */
11888 if (*p == ' ' && ((p - s) & 1) == 0)
11889 {
11890 ++p;
11891 break;
11892 }
11893 --p;
11894 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011895 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011896 {
11897 xp->xp_context = EXPAND_BOOL_SETTINGS;
11898 p += 2;
11899 }
11900 if (STRNCMP(p, "inv", 3) == 0)
11901 {
11902 xp->xp_context = EXPAND_BOOL_SETTINGS;
11903 p += 3;
11904 }
11905 xp->xp_pattern = arg = p;
11906 if (*arg == '<')
11907 {
11908 while (*p != '>')
11909 if (*p++ == NUL) /* expand terminal option name */
11910 return;
11911 key = get_special_key_code(arg + 1);
11912 if (key == 0) /* unknown name */
11913 {
11914 xp->xp_context = EXPAND_NOTHING;
11915 return;
11916 }
11917 nextchar = *++p;
11918 is_term_option = TRUE;
11919 expand_option_name[2] = KEY2TERMCAP0(key);
11920 expand_option_name[3] = KEY2TERMCAP1(key);
11921 }
11922 else
11923 {
11924 if (p[0] == 't' && p[1] == '_')
11925 {
11926 p += 2;
11927 if (*p != NUL)
11928 ++p;
11929 if (*p == NUL)
11930 return; /* expand option name */
11931 nextchar = *++p;
11932 is_term_option = TRUE;
11933 expand_option_name[2] = p[-2];
11934 expand_option_name[3] = p[-1];
11935 }
11936 else
11937 {
11938 /* Allow * wildcard */
11939 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11940 p++;
11941 if (*p == NUL)
11942 return;
11943 nextchar = *p;
11944 *p = NUL;
11945 opt_idx = findoption(arg);
11946 *p = nextchar;
11947 if (opt_idx == -1 || options[opt_idx].var == NULL)
11948 {
11949 xp->xp_context = EXPAND_NOTHING;
11950 return;
11951 }
11952 flags = options[opt_idx].flags;
11953 if (flags & P_BOOL)
11954 {
11955 xp->xp_context = EXPAND_NOTHING;
11956 return;
11957 }
11958 }
11959 }
11960 /* handle "-=" and "+=" */
11961 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11962 {
11963 ++p;
11964 nextchar = '=';
11965 }
11966 if ((nextchar != '=' && nextchar != ':')
11967 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11968 {
11969 xp->xp_context = EXPAND_UNSUCCESSFUL;
11970 return;
11971 }
11972 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11973 {
11974 xp->xp_context = EXPAND_OLD_SETTING;
11975 if (is_term_option)
11976 expand_option_idx = -1;
11977 else
11978 expand_option_idx = opt_idx;
11979 xp->xp_pattern = p + 1;
11980 return;
11981 }
11982 xp->xp_context = EXPAND_NOTHING;
11983 if (is_term_option || (flags & P_NUM))
11984 return;
11985
11986 xp->xp_pattern = p + 1;
11987
11988 if (flags & P_EXPAND)
11989 {
11990 p = options[opt_idx].var;
11991 if (p == (char_u *)&p_bdir
11992 || p == (char_u *)&p_dir
11993 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011994 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011995 || p == (char_u *)&p_rtp
11996#ifdef FEAT_SEARCHPATH
11997 || p == (char_u *)&p_cdpath
11998#endif
11999#ifdef FEAT_SESSION
12000 || p == (char_u *)&p_vdir
12001#endif
12002 )
12003 {
12004 xp->xp_context = EXPAND_DIRECTORIES;
12005 if (p == (char_u *)&p_path
12006#ifdef FEAT_SEARCHPATH
12007 || p == (char_u *)&p_cdpath
12008#endif
12009 )
12010 xp->xp_backslash = XP_BS_THREE;
12011 else
12012 xp->xp_backslash = XP_BS_ONE;
12013 }
12014 else
12015 {
12016 xp->xp_context = EXPAND_FILES;
12017 /* for 'tags' need three backslashes for a space */
12018 if (p == (char_u *)&p_tags)
12019 xp->xp_backslash = XP_BS_THREE;
12020 else
12021 xp->xp_backslash = XP_BS_ONE;
12022 }
12023 }
12024
12025 /* For an option that is a list of file names, find the start of the
12026 * last file name. */
12027 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
12028 {
12029 /* count number of backslashes before ' ' or ',' */
12030 if (*p == ' ' || *p == ',')
12031 {
12032 s = p;
12033 while (s > xp->xp_pattern && *(s - 1) == '\\')
12034 --s;
12035 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
12036 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
12037 {
12038 xp->xp_pattern = p + 1;
12039 break;
12040 }
12041 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000012042
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000012043#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000012044 /* for 'spellsuggest' start at "file:" */
12045 if (options[opt_idx].var == (char_u *)&p_sps
12046 && STRNCMP(p, "file:", 5) == 0)
12047 {
12048 xp->xp_pattern = p + 5;
12049 break;
12050 }
12051#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012052 }
12053
12054 return;
12055}
12056
12057 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012058ExpandSettings(
12059 expand_T *xp,
12060 regmatch_T *regmatch,
12061 int *num_file,
12062 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012063{
12064 int num_normal = 0; /* Nr of matching non-term-code settings */
12065 int num_term = 0; /* Nr of matching terminal code settings */
12066 int opt_idx;
12067 int match;
12068 int count = 0;
12069 char_u *str;
12070 int loop;
12071 int is_term_opt;
12072 char_u name_buf[MAX_KEY_NAME_LEN];
12073 static char *(names[]) = {"all", "termcap"};
12074 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
12075
12076 /* do this loop twice:
12077 * loop == 0: count the number of matching options
12078 * loop == 1: copy the matching options into allocated memory
12079 */
12080 for (loop = 0; loop <= 1; ++loop)
12081 {
12082 regmatch->rm_ic = ic;
12083 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
12084 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000012085 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
12086 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012087 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
12088 {
12089 if (loop == 0)
12090 num_normal++;
12091 else
12092 (*file)[count++] = vim_strsave((char_u *)names[match]);
12093 }
12094 }
12095 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
12096 opt_idx++)
12097 {
12098 if (options[opt_idx].var == NULL)
12099 continue;
12100 if (xp->xp_context == EXPAND_BOOL_SETTINGS
12101 && !(options[opt_idx].flags & P_BOOL))
12102 continue;
12103 is_term_opt = istermoption(&options[opt_idx]);
12104 if (is_term_opt && num_normal > 0)
12105 continue;
12106 match = FALSE;
12107 if (vim_regexec(regmatch, str, (colnr_T)0)
12108 || (options[opt_idx].shortname != NULL
12109 && vim_regexec(regmatch,
12110 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
12111 match = TRUE;
12112 else if (is_term_opt)
12113 {
12114 name_buf[0] = '<';
12115 name_buf[1] = 't';
12116 name_buf[2] = '_';
12117 name_buf[3] = str[2];
12118 name_buf[4] = str[3];
12119 name_buf[5] = '>';
12120 name_buf[6] = NUL;
12121 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12122 {
12123 match = TRUE;
12124 str = name_buf;
12125 }
12126 }
12127 if (match)
12128 {
12129 if (loop == 0)
12130 {
12131 if (is_term_opt)
12132 num_term++;
12133 else
12134 num_normal++;
12135 }
12136 else
12137 (*file)[count++] = vim_strsave(str);
12138 }
12139 }
12140 /*
12141 * Check terminal key codes, these are not in the option table
12142 */
12143 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
12144 {
12145 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
12146 {
12147 if (!isprint(str[0]) || !isprint(str[1]))
12148 continue;
12149
12150 name_buf[0] = 't';
12151 name_buf[1] = '_';
12152 name_buf[2] = str[0];
12153 name_buf[3] = str[1];
12154 name_buf[4] = NUL;
12155
12156 match = FALSE;
12157 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12158 match = TRUE;
12159 else
12160 {
12161 name_buf[0] = '<';
12162 name_buf[1] = 't';
12163 name_buf[2] = '_';
12164 name_buf[3] = str[0];
12165 name_buf[4] = str[1];
12166 name_buf[5] = '>';
12167 name_buf[6] = NUL;
12168
12169 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12170 match = TRUE;
12171 }
12172 if (match)
12173 {
12174 if (loop == 0)
12175 num_term++;
12176 else
12177 (*file)[count++] = vim_strsave(name_buf);
12178 }
12179 }
12180
12181 /*
12182 * Check special key names.
12183 */
12184 regmatch->rm_ic = TRUE; /* ignore case here */
12185 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
12186 {
12187 name_buf[0] = '<';
12188 STRCPY(name_buf + 1, str);
12189 STRCAT(name_buf, ">");
12190
12191 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12192 {
12193 if (loop == 0)
12194 num_term++;
12195 else
12196 (*file)[count++] = vim_strsave(name_buf);
12197 }
12198 }
12199 }
12200 if (loop == 0)
12201 {
12202 if (num_normal > 0)
12203 *num_file = num_normal;
12204 else if (num_term > 0)
12205 *num_file = num_term;
12206 else
12207 return OK;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020012208 *file = ALLOC_MULT(char_u *, *num_file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012209 if (*file == NULL)
12210 {
12211 *file = (char_u **)"";
12212 return FAIL;
12213 }
12214 }
12215 }
12216 return OK;
12217}
12218
12219 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012220ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012221{
12222 char_u *var = NULL; /* init for GCC */
12223 char_u *buf;
12224
12225 *num_file = 0;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020012226 *file = ALLOC_ONE(char_u *);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012227 if (*file == NULL)
12228 return FAIL;
12229
12230 /*
12231 * For a terminal key code expand_option_idx is < 0.
12232 */
12233 if (expand_option_idx < 0)
12234 {
12235 var = find_termcode(expand_option_name + 2);
12236 if (var == NULL)
12237 expand_option_idx = findoption(expand_option_name);
12238 }
12239
12240 if (expand_option_idx >= 0)
12241 {
12242 /* put string of option value in NameBuff */
12243 option_value2string(&options[expand_option_idx], expand_option_flags);
12244 var = NameBuff;
12245 }
12246 else if (var == NULL)
12247 var = (char_u *)"";
12248
12249 /* A backslash is required before some characters. This is the reverse of
12250 * what happens in do_set(). */
12251 buf = vim_strsave_escaped(var, escape_chars);
12252
12253 if (buf == NULL)
12254 {
Bram Moolenaard23a8232018-02-10 18:45:26 +010012255 VIM_CLEAR(*file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012256 return FAIL;
12257 }
12258
12259#ifdef BACKSLASH_IN_FILENAME
12260 /* For MS-Windows et al. we don't double backslashes at the start and
12261 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012262 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012263 if (var[0] == '\\' && var[1] == '\\'
12264 && expand_option_idx >= 0
12265 && (options[expand_option_idx].flags & P_EXPAND)
12266 && vim_isfilec(var[2])
12267 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000012268 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012269#endif
12270
12271 *file[0] = buf;
12272 *num_file = 1;
12273 return OK;
12274}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012275
12276/*
12277 * Get the value for the numeric or string option *opp in a nice format into
12278 * NameBuff[]. Must not be called with a hidden option!
12279 */
12280 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012281option_value2string(
12282 struct vimoption *opp,
12283 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012284{
12285 char_u *varp;
12286
12287 varp = get_varp_scope(opp, opt_flags);
12288
12289 if (opp->flags & P_NUM)
12290 {
12291 long wc = 0;
12292
12293 if (wc_use_keyname(varp, &wc))
12294 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
12295 else if (wc != 0)
12296 STRCPY(NameBuff, transchar((int)wc));
12297 else
12298 sprintf((char *)NameBuff, "%ld", *(long *)varp);
12299 }
12300 else /* P_STRING */
12301 {
12302 varp = *(char_u **)(varp);
12303 if (varp == NULL) /* just in case */
12304 NameBuff[0] = NUL;
12305#ifdef FEAT_CRYPT
12306 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000012307 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012308 STRCPY(NameBuff, "*****");
12309#endif
12310 else if (opp->flags & P_EXPAND)
12311 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
12312 /* Translate 'pastetoggle' into special key names */
12313 else if ((char_u **)opp->var == &p_pt)
12314 str2specialbuf(p_pt, NameBuff, MAXPATHL);
12315 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000012316 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012317 }
12318}
12319
12320/*
12321 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
12322 * printed as a keyname.
12323 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
12324 */
12325 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012326wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012327{
12328 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
12329 {
12330 *wcp = *(long *)varp;
12331 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
12332 return TRUE;
12333 }
12334 return FALSE;
12335}
12336
Bram Moolenaar01615492015-02-03 13:00:38 +010012337#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012338/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012339 * Any character has an equivalent 'langmap' character. This is used for
12340 * keyboards that have a special language mode that sends characters above
12341 * 128 (although other characters can be translated too). The "to" field is a
12342 * Vim command character. This avoids having to switch the keyboard back to
12343 * ASCII mode when leaving Insert mode.
12344 *
12345 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
12346 * commands.
Bram Moolenaarfc3abf42019-01-24 15:54:21 +010012347 * langmap_mapga.ga_data is a sorted table of langmap_entry_T. This does the
12348 * same as langmap_mapchar[] for characters >= 256.
12349 *
12350 * Use growarray for 'langmap' chars >= 256
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012351 */
12352typedef struct
12353{
12354 int from;
12355 int to;
12356} langmap_entry_T;
12357
12358static garray_T langmap_mapga;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012359
12360/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012361 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
12362 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012363 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012364 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012365langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012366{
12367 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020012368 int a = 0;
12369 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012370
12371 /* Do a binary search for an existing entry. */
12372 while (a != b)
12373 {
12374 int i = (a + b) / 2;
12375 int d = entries[i].from - from;
12376
12377 if (d == 0)
12378 {
12379 entries[i].to = to;
12380 return;
12381 }
12382 if (d < 0)
12383 a = i + 1;
12384 else
12385 b = i;
12386 }
12387
12388 if (ga_grow(&langmap_mapga, 1) != OK)
12389 return; /* out of memory */
12390
12391 /* insert new entry at position "a" */
12392 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
12393 mch_memmove(entries + 1, entries,
12394 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
12395 ++langmap_mapga.ga_len;
12396 entries[0].from = from;
12397 entries[0].to = to;
12398}
12399
12400/*
12401 * Apply 'langmap' to multi-byte character "c" and return the result.
12402 */
12403 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012404langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012405{
12406 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
12407 int a = 0;
12408 int b = langmap_mapga.ga_len;
12409
12410 while (a != b)
12411 {
12412 int i = (a + b) / 2;
12413 int d = entries[i].from - c;
12414
12415 if (d == 0)
12416 return entries[i].to; /* found matching entry */
12417 if (d < 0)
12418 a = i + 1;
12419 else
12420 b = i;
12421 }
12422 return c; /* no entry found, return "c" unmodified */
12423}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012424
12425 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012426langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012427{
12428 int i;
12429
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012430 for (i = 0; i < 256; i++)
12431 langmap_mapchar[i] = i; /* we init with a one-to-one map */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012432 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012433}
12434
12435/*
12436 * Called when langmap option is set; the language map can be
12437 * changed at any time!
12438 */
12439 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012440langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012441{
12442 char_u *p;
12443 char_u *p2;
12444 int from, to;
12445
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012446 ga_clear(&langmap_mapga); /* clear the previous map first */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012447 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012448
12449 for (p = p_langmap; p[0] != NUL; )
12450 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000012451 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012452 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012453 {
12454 if (p2[0] == '\\' && p2[1] != NUL)
12455 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012456 }
12457 if (p2[0] == ';')
12458 ++p2; /* abcd;ABCD form, p2 points to A */
12459 else
12460 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
12461 while (p[0])
12462 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012463 if (p[0] == ',')
12464 {
12465 ++p;
12466 break;
12467 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012468 if (p[0] == '\\' && p[1] != NUL)
12469 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012470 from = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012471 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012472 if (p2 == NULL)
12473 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012474 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012475 if (p[0] != ',')
12476 {
12477 if (p[0] == '\\')
12478 ++p;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012479 to = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012480 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012481 }
12482 else
12483 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012484 if (p2[0] != ',')
12485 {
12486 if (p2[0] == '\\')
12487 ++p2;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012488 to = (*mb_ptr2char)(p2);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012489 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012490 }
12491 if (to == NUL)
12492 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012493 semsg(_("E357: 'langmap': Matching character missing for %s"),
Bram Moolenaar071d4272004-06-13 20:20:40 +000012494 transchar(from));
12495 return;
12496 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012497
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012498 if (from >= 256)
12499 langmap_set_entry(from, to);
12500 else
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012501 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012502
12503 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012504 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012505 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012506 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012507 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012508 if (*p == ';')
12509 {
12510 p = p2;
12511 if (p[0] != NUL)
12512 {
12513 if (p[0] != ',')
12514 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012515 semsg(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012516 return;
12517 }
12518 ++p;
12519 }
12520 break;
12521 }
12522 }
12523 }
12524 }
12525}
12526#endif
12527
12528/*
12529 * Return TRUE if format option 'x' is in effect.
12530 * Take care of no formatting when 'paste' is set.
12531 */
12532 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012533has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012534{
12535 if (p_paste)
12536 return FALSE;
12537 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12538}
12539
12540/*
12541 * Return TRUE if "x" is present in 'shortmess' option, or
12542 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12543 */
12544 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012545shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012546{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012547 return p_shm != NULL &&
12548 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012549 || (vim_strchr(p_shm, 'a') != NULL
12550 && vim_strchr((char_u *)SHM_A, x) != NULL));
12551}
12552
12553/*
12554 * paste_option_changed() - Called after p_paste was set or reset.
12555 */
12556 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012557paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012558{
12559 static int old_p_paste = FALSE;
12560 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012561 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012562#ifdef FEAT_CMDL_INFO
12563 static int save_ru = 0;
12564#endif
12565#ifdef FEAT_RIGHTLEFT
12566 static int save_ri = 0;
12567 static int save_hkmap = 0;
12568#endif
12569 buf_T *buf;
12570
12571 if (p_paste)
12572 {
12573 /*
12574 * Paste switched from off to on.
12575 * Save the current values, so they can be restored later.
12576 */
12577 if (!old_p_paste)
12578 {
12579 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012580 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012581 {
12582 buf->b_p_tw_nopaste = buf->b_p_tw;
12583 buf->b_p_wm_nopaste = buf->b_p_wm;
12584 buf->b_p_sts_nopaste = buf->b_p_sts;
12585 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012586 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012587#ifdef FEAT_VARTABS
12588 if (buf->b_p_vsts_nopaste)
12589 vim_free(buf->b_p_vsts_nopaste);
12590 buf->b_p_vsts_nopaste = buf->b_p_vsts && buf->b_p_vsts != empty_option
12591 ? vim_strsave(buf->b_p_vsts) : NULL;
12592#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012593 }
12594
12595 /* save global options */
12596 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012597 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012598#ifdef FEAT_CMDL_INFO
12599 save_ru = p_ru;
12600#endif
12601#ifdef FEAT_RIGHTLEFT
12602 save_ri = p_ri;
12603 save_hkmap = p_hkmap;
12604#endif
12605 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012606 p_ai_nopaste = p_ai;
12607 p_et_nopaste = p_et;
12608 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012609 p_tw_nopaste = p_tw;
12610 p_wm_nopaste = p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012611#ifdef FEAT_VARTABS
12612 if (p_vsts_nopaste)
12613 vim_free(p_vsts_nopaste);
12614 p_vsts_nopaste = p_vsts && p_vsts != empty_option ? vim_strsave(p_vsts) : NULL;
12615#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012616 }
12617
12618 /*
12619 * Always set the option values, also when 'paste' is set when it is
12620 * already on.
12621 */
12622 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012623 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012624 {
12625 buf->b_p_tw = 0; /* textwidth is 0 */
12626 buf->b_p_wm = 0; /* wrapmargin is 0 */
12627 buf->b_p_sts = 0; /* softtabstop is 0 */
12628 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012629 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012630#ifdef FEAT_VARTABS
12631 if (buf->b_p_vsts)
12632 free_string_option(buf->b_p_vsts);
12633 buf->b_p_vsts = empty_option;
12634 if (buf->b_p_vsts_array)
12635 vim_free(buf->b_p_vsts_array);
12636 buf->b_p_vsts_array = 0;
12637#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012638 }
12639
12640 /* set global options */
12641 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012642 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012643#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012644 if (p_ru)
12645 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012646 p_ru = 0; /* no ruler */
12647#endif
12648#ifdef FEAT_RIGHTLEFT
12649 p_ri = 0; /* no reverse insert */
12650 p_hkmap = 0; /* no Hebrew keyboard */
12651#endif
12652 /* set global values for local buffer options */
12653 p_tw = 0;
12654 p_wm = 0;
12655 p_sts = 0;
12656 p_ai = 0;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012657#ifdef FEAT_VARTABS
12658 if (p_vsts)
12659 free_string_option(p_vsts);
12660 p_vsts = empty_option;
12661#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012662 }
12663
12664 /*
12665 * Paste switched from on to off: Restore saved values.
12666 */
12667 else if (old_p_paste)
12668 {
12669 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012670 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012671 {
12672 buf->b_p_tw = buf->b_p_tw_nopaste;
12673 buf->b_p_wm = buf->b_p_wm_nopaste;
12674 buf->b_p_sts = buf->b_p_sts_nopaste;
12675 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012676 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012677#ifdef FEAT_VARTABS
12678 if (buf->b_p_vsts)
12679 free_string_option(buf->b_p_vsts);
12680 buf->b_p_vsts = buf->b_p_vsts_nopaste
12681 ? vim_strsave(buf->b_p_vsts_nopaste) : empty_option;
12682 if (buf->b_p_vsts_array)
12683 vim_free(buf->b_p_vsts_array);
12684 if (buf->b_p_vsts && buf->b_p_vsts != empty_option)
12685 tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array);
12686 else
12687 buf->b_p_vsts_array = 0;
12688#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012689 }
12690
12691 /* restore global options */
12692 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012693 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012694#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012695 if (p_ru != save_ru)
12696 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012697 p_ru = save_ru;
12698#endif
12699#ifdef FEAT_RIGHTLEFT
12700 p_ri = save_ri;
12701 p_hkmap = save_hkmap;
12702#endif
12703 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012704 p_ai = p_ai_nopaste;
12705 p_et = p_et_nopaste;
12706 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012707 p_tw = p_tw_nopaste;
12708 p_wm = p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012709#ifdef FEAT_VARTABS
12710 if (p_vsts)
12711 free_string_option(p_vsts);
12712 p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option;
12713#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012714 }
12715
12716 old_p_paste = p_paste;
12717}
12718
12719/*
12720 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12721 *
12722 * Reset 'compatible' and set the values for options that didn't get set yet
12723 * to the Vim defaults.
12724 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012725 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012726 */
12727 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012728vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012729{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012730 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012731 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012732 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012733
12734 if (!option_was_set((char_u *)"cp"))
12735 {
12736 p_cp = FALSE;
12737 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12738 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12739 set_option_default(opt_idx, OPT_FREE, FALSE);
12740 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012741 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012742 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012743
12744 if (fname != NULL)
12745 {
12746 p = vim_getenv(envname, &dofree);
12747 if (p == NULL)
12748 {
12749 /* Set $MYVIMRC to the first vimrc file found. */
12750 p = FullName_save(fname, FALSE);
12751 if (p != NULL)
12752 {
12753 vim_setenv(envname, p);
12754 vim_free(p);
12755 }
12756 }
12757 else if (dofree)
12758 vim_free(p);
12759 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012760}
12761
12762/*
12763 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12764 */
12765 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012766change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012767{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012768 int opt_idx;
12769
Bram Moolenaar071d4272004-06-13 20:20:40 +000012770 if (p_cp != on)
12771 {
12772 p_cp = on;
12773 compatible_set();
12774 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012775 opt_idx = findoption((char_u *)"cp");
12776 if (opt_idx >= 0)
12777 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012778}
12779
12780/*
12781 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012782 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012783 */
12784 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012785option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012786{
12787 int idx;
12788
12789 idx = findoption(name);
12790 if (idx < 0) /* unknown option */
12791 return FALSE;
12792 if (options[idx].flags & P_WAS_SET)
12793 return TRUE;
12794 return FALSE;
12795}
12796
12797/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012798 * Reset the flag indicating option "name" was set.
12799 */
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012800 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012801reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012802{
12803 int idx = findoption(name);
12804
12805 if (idx >= 0)
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012806 {
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012807 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012808 return OK;
12809 }
12810 return FAIL;
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012811}
12812
12813/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012814 * compatible_set() - Called when 'compatible' has been set or unset.
12815 *
12816 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12817 * flag) to a Vi compatible value.
12818 * When 'compatible' is unset: Set all options that have a different default
12819 * for Vim (without the P_VI_DEF flag) to that default.
12820 */
12821 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012822compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012823{
12824 int opt_idx;
12825
12826 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12827 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12828 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12829 set_option_default(opt_idx, OPT_FREE, p_cp);
12830 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012831 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012832}
12833
12834#ifdef FEAT_LINEBREAK
12835
Bram Moolenaar071d4272004-06-13 20:20:40 +000012836/*
12837 * fill_breakat_flags() -- called when 'breakat' changes value.
12838 */
12839 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012840fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012841{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012842 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012843 int i;
12844
12845 for (i = 0; i < 256; i++)
12846 breakat_flags[i] = FALSE;
12847
12848 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012849 for (p = p_breakat; *p; p++)
12850 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012851}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012852#endif
12853
12854/*
12855 * Check an option that can be a range of string values.
12856 *
12857 * Return OK for correct value, FAIL otherwise.
12858 * Empty is always OK.
12859 */
12860 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012861check_opt_strings(
12862 char_u *val,
12863 char **values,
12864 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012865{
12866 return opt_strings_flags(val, values, NULL, list);
12867}
12868
12869/*
12870 * Handle an option that can be a range of string values.
12871 * Set a flag in "*flagp" for each string present.
12872 *
12873 * Return OK for correct value, FAIL otherwise.
12874 * Empty is always OK.
12875 */
12876 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012877opt_strings_flags(
12878 char_u *val, /* new value */
12879 char **values, /* array of valid string values */
12880 unsigned *flagp,
12881 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012882{
12883 int i;
12884 int len;
12885 unsigned new_flags = 0;
12886
12887 while (*val)
12888 {
12889 for (i = 0; ; ++i)
12890 {
12891 if (values[i] == NULL) /* val not found in values[] */
12892 return FAIL;
12893
12894 len = (int)STRLEN(values[i]);
12895 if (STRNCMP(values[i], val, len) == 0
12896 && ((list && val[len] == ',') || val[len] == NUL))
12897 {
12898 val += len + (val[len] == ',');
12899 new_flags |= (1 << i);
12900 break; /* check next item in val list */
12901 }
12902 }
12903 }
12904 if (flagp != NULL)
12905 *flagp = new_flags;
12906
12907 return OK;
12908}
12909
12910/*
12911 * Read the 'wildmode' option, fill wim_flags[].
12912 */
12913 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012914check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012915{
12916 char_u new_wim_flags[4];
12917 char_u *p;
12918 int i;
12919 int idx = 0;
12920
12921 for (i = 0; i < 4; ++i)
12922 new_wim_flags[i] = 0;
12923
12924 for (p = p_wim; *p; ++p)
12925 {
12926 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12927 ;
12928 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12929 return FAIL;
12930 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12931 new_wim_flags[idx] |= WIM_LONGEST;
12932 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12933 new_wim_flags[idx] |= WIM_FULL;
12934 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12935 new_wim_flags[idx] |= WIM_LIST;
12936 else
12937 return FAIL;
12938 p += i;
12939 if (*p == NUL)
12940 break;
12941 if (*p == ',')
12942 {
12943 if (idx == 3)
12944 return FAIL;
12945 ++idx;
12946 }
12947 }
12948
12949 /* fill remaining entries with last flag */
12950 while (idx < 3)
12951 {
12952 new_wim_flags[idx + 1] = new_wim_flags[idx];
12953 ++idx;
12954 }
12955
12956 /* only when there are no errors, wim_flags[] is changed */
12957 for (i = 0; i < 4; ++i)
12958 wim_flags[i] = new_wim_flags[i];
12959 return OK;
12960}
12961
12962/*
12963 * Check if backspacing over something is allowed.
12964 */
12965 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012966can_bs(
12967 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012968{
Bram Moolenaar6b810d92018-06-04 17:28:44 +020012969#ifdef FEAT_JOB_CHANNEL
12970 if (what == BS_START && bt_prompt(curbuf))
12971 return FALSE;
12972#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012973 switch (*p_bs)
12974 {
12975 case '2': return TRUE;
12976 case '1': return (what != BS_START);
12977 case '0': return FALSE;
12978 }
12979 return vim_strchr(p_bs, what) != NULL;
12980}
12981
12982/*
12983 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12984 * the file must be considered changed when the value is different.
12985 */
12986 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012987save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012988{
12989 buf->b_start_ffc = *buf->b_p_ff;
12990 buf->b_start_eol = buf->b_p_eol;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012991 buf->b_start_bomb = buf->b_p_bomb;
12992
Bram Moolenaar071d4272004-06-13 20:20:40 +000012993 /* Only use free/alloc when necessary, they take time. */
12994 if (buf->b_start_fenc == NULL
12995 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12996 {
12997 vim_free(buf->b_start_fenc);
12998 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12999 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000013000}
13001
13002/*
13003 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
13004 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000013005 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
13006 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020013007 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010013008 * When "ignore_empty" is true don't consider a new, empty buffer to be
13009 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000013010 */
13011 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013012file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000013013{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000013014 /* In a buffer that was never loaded the options are not valid. */
13015 if (buf->b_flags & BF_NEVERLOADED)
13016 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010013017 if (ignore_empty
13018 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000013019 && buf->b_ml.ml_line_count == 1
13020 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
13021 return FALSE;
13022 if (buf->b_start_ffc != *buf->b_p_ff)
13023 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020013024 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000013025 return TRUE;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000013026 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
13027 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000013028 if (buf->b_start_fenc == NULL)
13029 return (*buf->b_p_fenc != NUL);
13030 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +000013031}
13032
13033/*
13034 * return OK if "p" is a valid fileformat name, FAIL otherwise.
13035 */
13036 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013037check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000013038{
13039 return check_opt_strings(p, p_ff_values, FALSE);
13040}
Bram Moolenaar14f24742012-08-08 18:01:05 +020013041
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010013042#if defined(FEAT_VARTABS) || defined(PROTO)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013043
13044/*
13045 * Set the integer values corresponding to the string setting of 'vartabstop'.
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010013046 * "array" will be set, caller must free it if needed.
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013047 */
13048 int
13049tabstop_set(char_u *var, int **array)
13050{
13051 int valcount = 1;
13052 int t;
13053 char_u *cp;
13054
Bram Moolenaar64f41072018-10-15 22:51:50 +020013055 if (var[0] == NUL || (var[0] == '0' && var[1] == NUL))
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013056 {
13057 *array = NULL;
13058 return TRUE;
13059 }
13060
Bram Moolenaar64f41072018-10-15 22:51:50 +020013061 for (cp = var; *cp != NUL; ++cp)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013062 {
Bram Moolenaar64f41072018-10-15 22:51:50 +020013063 if (cp == var || cp[-1] == ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013064 {
13065 char_u *end;
Bram Moolenaar64f41072018-10-15 22:51:50 +020013066
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013067 if (strtol((char *)cp, (char **)&end, 10) <= 0)
13068 {
13069 if (cp != end)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010013070 emsg(_(e_positive));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013071 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010013072 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013073 return FALSE;
13074 }
13075 }
13076
13077 if (VIM_ISDIGIT(*cp))
13078 continue;
Bram Moolenaar64f41072018-10-15 22:51:50 +020013079 if (cp[0] == ',' && cp > var && cp[-1] != ',' && cp[1] != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013080 {
13081 ++valcount;
13082 continue;
13083 }
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010013084 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013085 return FALSE;
13086 }
13087
Bram Moolenaarc799fe22019-05-28 23:08:19 +020013088 *array = ALLOC_MULT(int, valcount + 1);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010013089 if (*array == NULL)
13090 return FALSE;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013091 (*array)[0] = valcount;
13092
13093 t = 1;
Bram Moolenaar64f41072018-10-15 22:51:50 +020013094 for (cp = var; *cp != NUL;)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013095 {
13096 (*array)[t++] = atoi((char *)cp);
Bram Moolenaar64f41072018-10-15 22:51:50 +020013097 while (*cp != NUL && *cp != ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013098 ++cp;
Bram Moolenaar64f41072018-10-15 22:51:50 +020013099 if (*cp != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013100 ++cp;
13101 }
13102
13103 return TRUE;
13104}
13105
13106/*
13107 * Calculate the number of screen spaces a tab will occupy.
13108 * If "vts" is set then the tab widths are taken from that array,
13109 * otherwise the value of ts is used.
13110 */
13111 int
13112tabstop_padding(colnr_T col, int ts_arg, int *vts)
13113{
13114 int ts = ts_arg == 0 ? 8 : ts_arg;
13115 int tabcount;
13116 colnr_T tabcol = 0;
13117 int t;
13118 int padding = 0;
13119
13120 if (vts == NULL || vts[0] == 0)
13121 return ts - (col % ts);
13122
13123 tabcount = vts[0];
13124
13125 for (t = 1; t <= tabcount; ++t)
13126 {
13127 tabcol += vts[t];
13128 if (tabcol > col)
13129 {
13130 padding = (int)(tabcol - col);
13131 break;
13132 }
13133 }
13134 if (t > tabcount)
13135 padding = vts[tabcount] - (int)((col - tabcol) % vts[tabcount]);
13136
13137 return padding;
13138}
13139
13140/*
13141 * Find the size of the tab that covers a particular column.
13142 */
13143 int
13144tabstop_at(colnr_T col, int ts, int *vts)
13145{
13146 int tabcount;
13147 colnr_T tabcol = 0;
13148 int t;
13149 int tab_size = 0;
13150
13151 if (vts == 0 || vts[0] == 0)
13152 return ts;
13153
13154 tabcount = vts[0];
13155 for (t = 1; t <= tabcount; ++t)
13156 {
13157 tabcol += vts[t];
13158 if (tabcol > col)
13159 {
13160 tab_size = vts[t];
13161 break;
13162 }
13163 }
13164 if (t > tabcount)
13165 tab_size = vts[tabcount];
13166
13167 return tab_size;
13168}
13169
13170/*
13171 * Find the column on which a tab starts.
13172 */
13173 colnr_T
13174tabstop_start(colnr_T col, int ts, int *vts)
13175{
13176 int tabcount;
13177 colnr_T tabcol = 0;
13178 int t;
13179 int excess;
13180
Bram Moolenaar0119a592018-06-24 23:53:28 +020013181 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013182 return (col / ts) * ts;
13183
13184 tabcount = vts[0];
13185 for (t = 1; t <= tabcount; ++t)
13186 {
13187 tabcol += vts[t];
13188 if (tabcol > col)
13189 return tabcol - vts[t];
13190 }
13191
13192 excess = tabcol % vts[tabcount];
13193 return excess + ((col - excess) / vts[tabcount]) * vts[tabcount];
13194}
13195
13196/*
13197 * Find the number of tabs and spaces necessary to get from one column
13198 * to another.
13199 */
13200 void
13201tabstop_fromto(
13202 colnr_T start_col,
13203 colnr_T end_col,
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013204 int ts_arg,
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013205 int *vts,
13206 int *ntabs,
13207 int *nspcs)
13208{
13209 int spaces = end_col - start_col;
13210 colnr_T tabcol = 0;
13211 int padding = 0;
13212 int tabcount;
13213 int t;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013214 int ts = ts_arg == 0 ? curbuf->b_p_ts : ts_arg;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013215
Bram Moolenaar0119a592018-06-24 23:53:28 +020013216 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013217 {
13218 int tabs = 0;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013219 int initspc = 0;
Bram Moolenaar0119a592018-06-24 23:53:28 +020013220
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013221 initspc = ts - (start_col % ts);
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013222 if (spaces >= initspc)
13223 {
13224 spaces -= initspc;
13225 tabs++;
13226 }
13227 tabs += spaces / ts;
13228 spaces -= (spaces / ts) * ts;
13229
13230 *ntabs = tabs;
13231 *nspcs = spaces;
13232 return;
13233 }
13234
13235 /* Find the padding needed to reach the next tabstop. */
13236 tabcount = vts[0];
13237 for (t = 1; t <= tabcount; ++t)
13238 {
13239 tabcol += vts[t];
13240 if (tabcol > start_col)
13241 {
13242 padding = (int)(tabcol - start_col);
13243 break;
13244 }
13245 }
13246 if (t > tabcount)
13247 padding = vts[tabcount] - (int)((start_col - tabcol) % vts[tabcount]);
13248
13249 /* If the space needed is less than the padding no tabs can be used. */
13250 if (spaces < padding)
13251 {
13252 *ntabs = 0;
13253 *nspcs = spaces;
13254 return;
13255 }
13256
13257 *ntabs = 1;
13258 spaces -= padding;
13259
13260 /* At least one tab has been used. See if any more will fit. */
13261 while (spaces != 0 && ++t <= tabcount)
13262 {
13263 padding = vts[t];
13264 if (spaces < padding)
13265 {
13266 *nspcs = spaces;
13267 return;
13268 }
13269 ++*ntabs;
13270 spaces -= padding;
13271 }
13272
13273 *ntabs += spaces / vts[tabcount];
13274 *nspcs = spaces % vts[tabcount];
13275}
13276
13277/*
13278 * See if two tabstop arrays contain the same values.
13279 */
13280 int
13281tabstop_eq(int *ts1, int *ts2)
13282{
13283 int t;
13284
13285 if ((ts1 == 0 && ts2) || (ts1 && ts2 == 0))
13286 return FALSE;
13287 if (ts1 == ts2)
13288 return TRUE;
13289 if (ts1[0] != ts2[0])
13290 return FALSE;
13291
13292 for (t = 1; t <= ts1[0]; ++t)
13293 if (ts1[t] != ts2[t])
13294 return FALSE;
13295
13296 return TRUE;
13297}
13298
Bram Moolenaar113e1072019-01-20 15:30:40 +010013299#if defined(FEAT_BEVAL) || defined(PROTO)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013300/*
13301 * Copy a tabstop array, allocating space for the new array.
13302 */
13303 int *
13304tabstop_copy(int *oldts)
13305{
13306 int *newts;
13307 int t;
13308
Bram Moolenaar6ee96582019-04-27 22:06:37 +020013309 if (oldts == NULL)
13310 return NULL;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020013311 newts = ALLOC_MULT(int, oldts[0] + 1);
Bram Moolenaar6ee96582019-04-27 22:06:37 +020013312 if (newts != NULL)
13313 for (t = 0; t <= oldts[0]; ++t)
13314 newts[t] = oldts[t];
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013315 return newts;
13316}
Bram Moolenaar113e1072019-01-20 15:30:40 +010013317#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013318
13319/*
13320 * Return a count of the number of tabstops.
13321 */
13322 int
13323tabstop_count(int *ts)
13324{
13325 return ts != NULL ? ts[0] : 0;
13326}
13327
13328/*
13329 * Return the first tabstop, or 8 if there are no tabstops defined.
13330 */
13331 int
13332tabstop_first(int *ts)
13333{
13334 return ts != NULL ? ts[1] : 8;
13335}
13336
13337#endif
13338
Bram Moolenaar14f24742012-08-08 18:01:05 +020013339/*
13340 * Return the effective shiftwidth value for current buffer, using the
13341 * 'tabstop' value when 'shiftwidth' is zero.
13342 */
13343 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013344get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020013345{
Bram Moolenaarf9514162018-11-22 03:08:29 +010013346 return get_sw_value_col(buf, 0);
13347}
13348
13349/*
Bram Moolenaarf9514162018-11-22 03:08:29 +010013350 * Idem, using "pos".
13351 */
Bram Moolenaar5843f5f2019-08-20 20:13:45 +020013352 static long
Bram Moolenaarf9514162018-11-22 03:08:29 +010013353get_sw_value_pos(buf_T *buf, pos_T *pos)
13354{
13355 pos_T save_cursor = curwin->w_cursor;
13356 long sw_value;
13357
13358 curwin->w_cursor = *pos;
13359 sw_value = get_sw_value_col(buf, get_nolist_virtcol());
13360 curwin->w_cursor = save_cursor;
13361 return sw_value;
13362}
13363
13364/*
Bram Moolenaar5843f5f2019-08-20 20:13:45 +020013365 * Idem, using the first non-black in the current line.
13366 */
13367 long
13368get_sw_value_indent(buf_T *buf)
13369{
13370 pos_T pos = curwin->w_cursor;
13371
13372 pos.col = getwhitecols_curline();
13373 return get_sw_value_pos(buf, &pos);
13374}
13375
13376/*
Bram Moolenaarf9514162018-11-22 03:08:29 +010013377 * Idem, using virtual column "col".
13378 */
13379 long
13380get_sw_value_col(buf_T *buf, colnr_T col UNUSED)
13381{
13382 return buf->b_p_sw ? buf->b_p_sw :
13383 #ifdef FEAT_VARTABS
13384 tabstop_at(col, buf->b_p_ts, buf->b_p_vts_array);
13385 #else
13386 buf->b_p_ts;
13387 #endif
Bram Moolenaar14f24742012-08-08 18:01:05 +020013388}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013389
13390/*
13391 * Return the effective softtabstop value for the current buffer, using the
Bram Moolenaar33d5ab32018-07-02 20:51:24 +020013392 * 'shiftwidth' value when 'softtabstop' is negative.
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013393 */
13394 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013395get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013396{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010013397 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013398}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013399
13400/*
Bram Moolenaar375e3392019-01-31 18:26:10 +010013401 * Return the effective 'scrolloff' value for the current window, using the
13402 * global value when appropriate.
13403 */
13404 long
13405get_scrolloff_value(void)
13406{
13407 return curwin->w_p_so < 0 ? p_so : curwin->w_p_so;
13408}
13409
13410/*
13411 * Return the effective 'sidescrolloff' value for the current window, using the
13412 * global value when appropriate.
13413 */
13414 long
13415get_sidescrolloff_value(void)
13416{
13417 return curwin->w_p_siso < 0 ? p_siso : curwin->w_p_siso;
13418}
13419
13420/*
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013421 * Check matchpairs option for "*initc".
13422 * If there is a match set "*initc" to the matching character and "*findc" to
13423 * the opposite character. Set "*backwards" to the direction.
13424 * When "switchit" is TRUE swap the direction.
13425 */
13426 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010013427find_mps_values(
13428 int *initc,
13429 int *findc,
13430 int *backwards,
13431 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013432{
13433 char_u *ptr;
13434
13435 ptr = curbuf->b_p_mps;
13436 while (*ptr != NUL)
13437 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013438 if (has_mbyte)
13439 {
13440 char_u *prev;
13441
13442 if (mb_ptr2char(ptr) == *initc)
13443 {
13444 if (switchit)
13445 {
13446 *findc = *initc;
13447 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13448 *backwards = TRUE;
13449 }
13450 else
13451 {
13452 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13453 *backwards = FALSE;
13454 }
13455 return;
13456 }
13457 prev = ptr;
13458 ptr += mb_ptr2len(ptr) + 1;
13459 if (mb_ptr2char(ptr) == *initc)
13460 {
13461 if (switchit)
13462 {
13463 *findc = *initc;
13464 *initc = mb_ptr2char(prev);
13465 *backwards = FALSE;
13466 }
13467 else
13468 {
13469 *findc = mb_ptr2char(prev);
13470 *backwards = TRUE;
13471 }
13472 return;
13473 }
13474 ptr += mb_ptr2len(ptr);
13475 }
13476 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013477 {
13478 if (*ptr == *initc)
13479 {
13480 if (switchit)
13481 {
13482 *backwards = TRUE;
13483 *findc = *initc;
13484 *initc = ptr[2];
13485 }
13486 else
13487 {
13488 *backwards = FALSE;
13489 *findc = ptr[2];
13490 }
13491 return;
13492 }
13493 ptr += 2;
13494 if (*ptr == *initc)
13495 {
13496 if (switchit)
13497 {
13498 *backwards = FALSE;
13499 *findc = *initc;
13500 *initc = ptr[-2];
13501 }
13502 else
13503 {
13504 *backwards = TRUE;
13505 *findc = ptr[-2];
13506 }
13507 return;
13508 }
13509 ++ptr;
13510 }
13511 if (*ptr == ',')
13512 ++ptr;
13513 }
13514}
Bram Moolenaar597a4222014-06-25 14:39:50 +020013515
13516#if defined(FEAT_LINEBREAK) || defined(PROTO)
13517/*
13518 * This is called when 'breakindentopt' is changed and when a window is
13519 * initialized.
13520 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013521 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013522briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020013523{
13524 char_u *p;
13525 int bri_shift = 0;
13526 long bri_min = 20;
13527 int bri_sbr = FALSE;
13528
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013529 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013530 while (*p != NUL)
13531 {
13532 if (STRNCMP(p, "shift:", 6) == 0
13533 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
13534 {
13535 p += 6;
13536 bri_shift = getdigits(&p);
13537 }
13538 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
13539 {
13540 p += 4;
13541 bri_min = getdigits(&p);
13542 }
13543 else if (STRNCMP(p, "sbr", 3) == 0)
13544 {
13545 p += 3;
13546 bri_sbr = TRUE;
13547 }
13548 if (*p != ',' && *p != NUL)
13549 return FAIL;
13550 if (*p == ',')
13551 ++p;
13552 }
13553
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013554 wp->w_p_brishift = bri_shift;
13555 wp->w_p_brimin = bri_min;
13556 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013557
13558 return OK;
13559}
13560#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013561
13562/*
13563 * Get the local or global value of 'backupcopy'.
13564 */
13565 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013566get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013567{
13568 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
13569}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020013570
13571#if defined(FEAT_SIGNS) || defined(PROTO)
13572/*
13573 * Return TRUE when window "wp" has a column to draw signs in.
13574 */
13575 int
13576signcolumn_on(win_T *wp)
13577{
Bram Moolenaar394c5d82019-06-17 21:48:05 +020013578 // If 'signcolumn' is set to 'number', signs are displayed in the 'number'
13579 // column (if present). Otherwise signs are to be displayed in the sign
13580 // column.
13581 if (*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
13582 return wp->w_buffer->b_signlist != NULL && !wp->w_p_nu && !wp->w_p_rnu;
13583
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020013584 if (*wp->w_p_scl == 'n')
13585 return FALSE;
13586 if (*wp->w_p_scl == 'y')
13587 return TRUE;
13588 return (wp->w_buffer->b_signlist != NULL
13589# ifdef FEAT_NETBEANS_INTG
13590 || wp->w_buffer->b_has_sign_column
13591# endif
13592 );
13593}
13594#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013595
13596#if defined(FEAT_EVAL) || defined(PROTO)
13597/*
13598 * Get window or buffer local options.
13599 */
13600 dict_T *
13601get_winbuf_options(int bufopt)
13602{
13603 dict_T *d;
13604 int opt_idx;
13605
13606 d = dict_alloc();
13607 if (d == NULL)
13608 return NULL;
13609
13610 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
13611 {
13612 struct vimoption *opt = &options[opt_idx];
13613
13614 if ((bufopt && (opt->indir & PV_BUF))
13615 || (!bufopt && (opt->indir & PV_WIN)))
13616 {
13617 char_u *varp = get_varp(opt);
13618
13619 if (varp != NULL)
13620 {
13621 if (opt->flags & P_STRING)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013622 dict_add_string(d, opt->fullname, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020013623 else if (opt->flags & P_NUM)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013624 dict_add_number(d, opt->fullname, *(long *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013625 else
Bram Moolenaare0be1672018-07-08 16:50:37 +020013626 dict_add_number(d, opt->fullname, *(int *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013627 }
13628 }
13629 }
13630
13631 return d;
13632}
13633#endif