blob: 69d272768676d7c53b9f29106ae58f0dd3bc3882 [file] [log] [blame]
Bram Moolenaaredf3f972016-08-29 22:49:24 +02001/* vi:set ts=8 sts=4 sw=4 noet:
Bram Moolenaar071d4272004-06-13 20:20:40 +00002 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * Code to handle user-settable options. This is all pretty much table-
12 * driven. Checklist for adding a new option:
13 * - Put it in the options array below (copy an existing entry).
14 * - For a global option: Add a variable for it in option.h.
15 * - For a buffer or window local option:
16 * - Add a PV_XX entry to the enum below.
17 * - Add a variable to the window or buffer struct in structs.h.
18 * - For a window option, add some code to copy_winopt().
19 * - For a buffer option, add some code to buf_copy_options().
20 * - For a buffer string option, add code to check_buf_options().
21 * - If it's a numeric option, add any necessary bounds checks to do_set().
22 * - If it's a list of flags, add some code in do_set(), search for WW_ALL.
23 * - When adding an option with expansion (P_EXPAND), but with a different
24 * default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP.
Bram Moolenaarcea912a2016-10-12 14:20:24 +020025 * - Add documentation! One line in doc/quickref.txt, full description in
Bram Moolenaar071d4272004-06-13 20:20:40 +000026 * options.txt, and any other related places.
27 * - Add an entry in runtime/optwin.vim.
28 * When making changes:
29 * - Adjust the help for the option in doc/option.txt.
30 * - When an entry has the P_VIM flag, or is lacking the P_VI_DEF flag, add a
31 * comment at the help for the 'compatible' option.
32 */
33
34#define IN_OPTION_C
35#include "vim.h"
36
37/*
38 * The options that are local to a window or buffer have "indir" set to one of
39 * these values. Special values:
40 * PV_NONE: global option.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000041 * PV_WIN is added: window-local option
42 * PV_BUF is added: buffer-local option
Bram Moolenaar071d4272004-06-13 20:20:40 +000043 * PV_BOTH is added: global option which also has a local value.
44 */
45#define PV_BOTH 0x1000
Bram Moolenaara23ccb82006-02-27 00:08:02 +000046#define PV_WIN 0x2000
47#define PV_BUF 0x4000
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000048#define PV_MASK 0x0fff
Bram Moolenaara23ccb82006-02-27 00:08:02 +000049#define OPT_WIN(x) (idopt_T)(PV_WIN + (int)(x))
50#define OPT_BUF(x) (idopt_T)(PV_BUF + (int)(x))
Bram Moolenaar071d4272004-06-13 20:20:40 +000051#define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
52
Bram Moolenaara23ccb82006-02-27 00:08:02 +000053/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000054 * Definition of the PV_ values for buffer-local options.
55 * The BV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000056 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +000057#define PV_AI OPT_BUF(BV_AI)
58#define PV_AR OPT_BOTH(OPT_BUF(BV_AR))
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020059#define PV_BKC OPT_BOTH(OPT_BUF(BV_BKC))
Bram Moolenaar81bdd6a2017-07-23 22:57:00 +020060#define PV_BH OPT_BUF(BV_BH)
61#define PV_BT OPT_BUF(BV_BT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000062#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000063# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
64# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
65# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000066#endif
67#define PV_BIN OPT_BUF(BV_BIN)
68#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaarfc3abf42019-01-24 15:54:21 +010069#define PV_BOMB OPT_BUF(BV_BOMB)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000070#define PV_CI OPT_BUF(BV_CI)
71#ifdef FEAT_CINDENT
72# define PV_CIN OPT_BUF(BV_CIN)
73# define PV_CINK OPT_BUF(BV_CINK)
74# define PV_CINO OPT_BUF(BV_CINO)
75#endif
76#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
77# define PV_CINW OPT_BUF(BV_CINW)
78#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020079#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000080#ifdef FEAT_FOLDING
81# define PV_CMS OPT_BUF(BV_CMS)
82#endif
83#ifdef FEAT_COMMENTS
84# define PV_COM OPT_BUF(BV_COM)
85#endif
86#ifdef FEAT_INS_EXPAND
87# define PV_CPT OPT_BUF(BV_CPT)
88# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
89# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
90#endif
Bram Moolenaarac3150d2019-07-28 16:36:39 +020091#define PV_CSL OPT_BUF(BV_CSL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000092#ifdef FEAT_COMPL_FUNC
93# define PV_CFU OPT_BUF(BV_CFU)
94#endif
95#ifdef FEAT_FIND_ID
96# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
97# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
98#endif
99#define PV_EOL OPT_BUF(BV_EOL)
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200100#define PV_FIXEOL OPT_BUF(BV_FIXEOL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000101#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
102#define PV_ET OPT_BUF(BV_ET)
Bram Moolenaarfc3abf42019-01-24 15:54:21 +0100103#define PV_FENC OPT_BUF(BV_FENC)
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000104#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
105# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
106#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100107#define PV_FP OPT_BOTH(OPT_BUF(BV_FP))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000108#ifdef FEAT_EVAL
109# define PV_FEX OPT_BUF(BV_FEX)
110#endif
111#define PV_FF OPT_BUF(BV_FF)
112#define PV_FLP OPT_BUF(BV_FLP)
113#define PV_FO OPT_BUF(BV_FO)
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +0100114#define PV_FT OPT_BUF(BV_FT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000115#define PV_IMI OPT_BUF(BV_IMI)
116#define PV_IMS OPT_BUF(BV_IMS)
117#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
118# define PV_INDE OPT_BUF(BV_INDE)
119# define PV_INDK OPT_BUF(BV_INDK)
120#endif
121#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
122# define PV_INEX OPT_BUF(BV_INEX)
123#endif
124#define PV_INF OPT_BUF(BV_INF)
125#define PV_ISK OPT_BUF(BV_ISK)
126#ifdef FEAT_CRYPT
127# define PV_KEY OPT_BUF(BV_KEY)
128#endif
129#ifdef FEAT_KEYMAP
130# define PV_KMAP OPT_BUF(BV_KMAP)
131#endif
132#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
133#ifdef FEAT_LISP
134# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100135# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000136#endif
Bram Moolenaarfc3abf42019-01-24 15:54:21 +0100137#define PV_MENC OPT_BOTH(OPT_BUF(BV_MENC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000138#define PV_MA OPT_BUF(BV_MA)
139#define PV_ML OPT_BUF(BV_ML)
140#define PV_MOD OPT_BUF(BV_MOD)
141#define PV_MPS OPT_BUF(BV_MPS)
142#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000143#ifdef FEAT_COMPL_FUNC
144# define PV_OFU OPT_BUF(BV_OFU)
145#endif
146#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
147#define PV_PI OPT_BUF(BV_PI)
148#ifdef FEAT_TEXTOBJ
149# define PV_QE OPT_BUF(BV_QE)
150#endif
151#define PV_RO OPT_BUF(BV_RO)
152#ifdef FEAT_SMARTINDENT
153# define PV_SI OPT_BUF(BV_SI)
154#endif
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100155#define PV_SN OPT_BUF(BV_SN)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000156#ifdef FEAT_SYN_HL
157# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000158# define PV_SYN OPT_BUF(BV_SYN)
159#endif
160#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000161# define PV_SPC OPT_BUF(BV_SPC)
162# define PV_SPF OPT_BUF(BV_SPF)
163# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000164#endif
165#define PV_STS OPT_BUF(BV_STS)
166#ifdef FEAT_SEARCHPATH
167# define PV_SUA OPT_BUF(BV_SUA)
168#endif
169#define PV_SW OPT_BUF(BV_SW)
170#define PV_SWF OPT_BUF(BV_SWF)
Bram Moolenaar45e18cb2019-04-28 18:05:35 +0200171#ifdef FEAT_EVAL
172# define PV_TFU OPT_BUF(BV_TFU)
173#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000174#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
Bram Moolenaar0f6562e2015-11-24 18:48:14 +0100175#define PV_TC OPT_BOTH(OPT_BUF(BV_TC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000176#define PV_TS OPT_BUF(BV_TS)
177#define PV_TW OPT_BUF(BV_TW)
178#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200179#ifdef FEAT_PERSISTENT_UNDO
180# define PV_UDF OPT_BUF(BV_UDF)
181#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000182#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200183#ifdef FEAT_VARTABS
184# define PV_VSTS OPT_BUF(BV_VSTS)
185# define PV_VTS OPT_BUF(BV_VTS)
186#endif
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000187
188/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000189 * Definition of the PV_ values for window-local options.
190 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000191 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000192#define PV_LIST OPT_WIN(WV_LIST)
193#ifdef FEAT_ARABIC
194# define PV_ARAB OPT_WIN(WV_ARAB)
195#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200196#ifdef FEAT_LINEBREAK
197# define PV_BRI OPT_WIN(WV_BRI)
198# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
199#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200200# define PV_WCR OPT_WIN(WV_WCR)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000201#ifdef FEAT_DIFF
202# define PV_DIFF OPT_WIN(WV_DIFF)
203#endif
204#ifdef FEAT_FOLDING
205# define PV_FDC OPT_WIN(WV_FDC)
206# define PV_FEN OPT_WIN(WV_FEN)
207# define PV_FDI OPT_WIN(WV_FDI)
208# define PV_FDL OPT_WIN(WV_FDL)
209# define PV_FDM OPT_WIN(WV_FDM)
210# define PV_FML OPT_WIN(WV_FML)
211# define PV_FDN OPT_WIN(WV_FDN)
212# ifdef FEAT_EVAL
213# define PV_FDE OPT_WIN(WV_FDE)
214# define PV_FDT OPT_WIN(WV_FDT)
215# endif
216# define PV_FMR OPT_WIN(WV_FMR)
217#endif
218#ifdef FEAT_LINEBREAK
219# define PV_LBR OPT_WIN(WV_LBR)
220#endif
221#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200222#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000223#ifdef FEAT_LINEBREAK
224# define PV_NUW OPT_WIN(WV_NUW)
225#endif
Bram Moolenaar4033c552017-09-16 20:54:51 +0200226#if defined(FEAT_QUICKFIX)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000227# define PV_PVW OPT_WIN(WV_PVW)
228#endif
229#ifdef FEAT_RIGHTLEFT
230# define PV_RL OPT_WIN(WV_RL)
231# define PV_RLC OPT_WIN(WV_RLC)
232#endif
Bram Moolenaar8a3bb562018-03-04 20:14:14 +0100233#define PV_SCBIND OPT_WIN(WV_SCBIND)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000234#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaar375e3392019-01-31 18:26:10 +0100235#define PV_SISO OPT_BOTH(OPT_WIN(WV_SISO))
236#define PV_SO OPT_BOTH(OPT_WIN(WV_SO))
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000237#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000238# define PV_SPELL OPT_WIN(WV_SPELL)
239#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000240#ifdef FEAT_SYN_HL
241# define PV_CUC OPT_WIN(WV_CUC)
242# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200243# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000244#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000245#ifdef FEAT_STL_OPT
246# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
247#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100248#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000249# define PV_WFH OPT_WIN(WV_WFH)
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000250# define PV_WFW OPT_WIN(WV_WFW)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000251#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar8a3bb562018-03-04 20:14:14 +0100252#define PV_CRBIND OPT_WIN(WV_CRBIND)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200253#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200254# define PV_COCU OPT_WIN(WV_COCU)
255# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200256#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200257#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200258# define PV_TWK OPT_WIN(WV_TWK)
259# define PV_TWS OPT_WIN(WV_TWS)
260# define PV_TWSL OPT_BUF(BV_TWSL)
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200261#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200262#ifdef FEAT_SIGNS
263# define PV_SCL OPT_WIN(WV_SCL)
264#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000265
266/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000267typedef enum
268{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000269 PV_NONE = 0,
270 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000271} idopt_T;
272
273/*
274 * Options local to a window have a value local to a buffer and global to all
275 * buffers. Indicate this by setting "var" to VAR_WIN.
276 */
277#define VAR_WIN ((char_u *)-1)
278
279/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000280 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000281 * Only to be used in option.c!
282 */
283static int p_ai;
284static int p_bin;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000285static int p_bomb;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000286static char_u *p_bh;
287static char_u *p_bt;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000288static int p_bl;
289static int p_ci;
290#ifdef FEAT_CINDENT
291static int p_cin;
292static char_u *p_cink;
293static char_u *p_cino;
294#endif
295#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
296static char_u *p_cinw;
297#endif
298#ifdef FEAT_COMMENTS
299static char_u *p_com;
300#endif
301#ifdef FEAT_FOLDING
302static char_u *p_cms;
303#endif
304#ifdef FEAT_INS_EXPAND
305static char_u *p_cpt;
306#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000307#ifdef FEAT_COMPL_FUNC
308static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000309static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000310#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +0200311#ifdef FEAT_EVAL
312static char_u *p_tfu;
313#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000314static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200315static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000316static int p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000317static char_u *p_fenc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000318static char_u *p_ff;
319static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000320static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000321static char_u *p_ft;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000322static long p_iminsert;
323static long p_imsearch;
324#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
325static char_u *p_inex;
326#endif
327#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
328static char_u *p_inde;
329static char_u *p_indk;
330#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000331#if defined(FEAT_EVAL)
332static char_u *p_fex;
333#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000334static int p_inf;
335static char_u *p_isk;
336#ifdef FEAT_CRYPT
337static char_u *p_key;
338#endif
339#ifdef FEAT_LISP
340static int p_lisp;
341#endif
342static int p_ml;
343static int p_ma;
344static int p_mod;
345static char_u *p_mps;
346static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000347static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000348#ifdef FEAT_TEXTOBJ
349static char_u *p_qe;
350#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000351static int p_ro;
352#ifdef FEAT_SMARTINDENT
353static int p_si;
354#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000355static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000356static long p_sts;
357#if defined(FEAT_SEARCHPATH)
358static char_u *p_sua;
359#endif
360static long p_sw;
361static int p_swf;
362#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000363static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000364static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000365#endif
366#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000367static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000368static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000369static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000370#endif
371static long p_ts;
372static long p_tw;
373static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200374#ifdef FEAT_PERSISTENT_UNDO
375static int p_udf;
376#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000377static long p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200378#ifdef FEAT_VARTABS
379static char_u *p_vsts;
380static char_u *p_vts;
381#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000382#ifdef FEAT_KEYMAP
383static char_u *p_keymap;
384#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200385#ifdef FEAT_TERMINAL
Bram Moolenaarb833c1e2018-05-05 16:36:06 +0200386static long p_twsl; /* 'termwinscroll' */
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200387#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000388
389/* Saved values for when 'bin' is set. */
390static int p_et_nobin;
391static int p_ml_nobin;
392static long p_tw_nobin;
393static long p_wm_nobin;
394
395/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200396static int p_ai_nopaste;
397static int p_et_nopaste;
398static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000399static long p_tw_nopaste;
400static long p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200401#ifdef FEAT_VARTABS
402static char_u *p_vsts_nopaste;
403#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000404
405struct vimoption
406{
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200407 char *fullname; // full option name
408 char *shortname; // permissible abbreviation
409 long_u flags; // see below
410 char_u *var; // global option: pointer to variable;
411 // window-local option: VAR_WIN;
412 // buffer-local option: global value
413 idopt_T indir; // global option: PV_NONE;
414 // local option: indirect option index
415 char_u *def_val[2]; // default values for variable (vi and vim)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000416#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200417 sctx_T script_ctx; // script context where the option was last set
Bram Moolenaar558ca4a2019-04-04 18:15:38 +0200418# define SCTX_INIT , {0, 0, 0, 1}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000419#else
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200420# define SCTX_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000421#endif
422};
423
424#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
425#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
426
427/*
428 * Flags
429 */
430#define P_BOOL 0x01 /* the option is boolean */
431#define P_NUM 0x02 /* the option is numeric */
432#define P_STRING 0x04 /* the option is a string */
433#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000434 must use free_string_option() when
435 assigning new value. Not set if default is
436 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000437#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
438 never be used for local or hidden options! */
439#define P_NODEFAULT 0x40 /* don't set to default value */
440#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
441 use vim_free() when assigning new value */
442#define P_WAS_SET 0x100 /* option has been set/reset */
443#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
444#define P_VI_DEF 0x400 /* Use Vi default for Vim */
445#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
446
447 /* when option changed, what to display: */
448#define P_RSTAT 0x1000 /* redraw status lines */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100449#define P_RWIN 0x2000 /* redraw current window and recompute text */
450#define P_RBUF 0x4000 /* redraw current buffer and recompute text */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000451#define P_RALL 0x6000 /* redraw all windows */
452#define P_RCLR 0x7000 /* clear and redraw all */
453
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200454#define P_COMMA 0x8000 /* comma separated list */
455#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
456 * commas */
457#define P_NODUP 0x20000L /* don't allow duplicate strings */
458#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000459
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200460#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
461#define P_GETTEXT 0x100000L /* expand default value with _() */
462#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
463#define P_NFNAME 0x400000L /* only normal file name chars allowed */
464#define P_INSECURE 0x800000L /* option was set from a modeline */
465#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7554da42016-11-25 22:04:13 +0100466 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200467#define P_NO_ML 0x2000000L /* not allowed in modeline */
468#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200469 * there is a redraw flag */
Bram Moolenaar7554da42016-11-25 22:04:13 +0100470#define P_NDNAME 0x8000000L /* only normal dir name chars allowed */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100471#define P_RWINONLY 0x10000000L /* only redraw current window */
Bram Moolenaar110289e2019-05-23 15:38:06 +0200472#define P_MLE 0x20000000L /* under control of 'modelineexpr' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000473
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000474#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
475
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000476/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
477 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100478#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000479# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000480#else
481# define ISP_LATIN1 (char_u *)"@,161-255"
482#endif
483
Bram Moolenaar05fbfdc2017-08-14 22:35:08 +0200484# define HIGHLIGHT_INIT "8:SpecialKey,~:EndOfBuffer,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn,q:QuickFixLine,z:StatusLineTerm,Z:StatusLineTermNC"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000485
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +0100486/* Default python version for pyx* commands */
487#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
488# define DEFAULT_PYTHON_VER 0
489#elif defined(FEAT_PYTHON3)
490# define DEFAULT_PYTHON_VER 3
491#elif defined(FEAT_PYTHON)
492# define DEFAULT_PYTHON_VER 2
493#else
494# define DEFAULT_PYTHON_VER 0
495#endif
496
Bram Moolenaarce655742019-01-31 14:12:57 +0100497// used for 'cinkeys' and 'indentkeys'
498#define INDENTKEYS_DEFAULT (char_u *)"0{,0},0),0],:,0#,!^F,o,O,e"
499
Bram Moolenaar071d4272004-06-13 20:20:40 +0000500/*
501 * options[] is initialized here.
502 * The order of the options MUST be alphabetic for ":set all" and findoption().
503 * All option names MUST start with a lowercase letter (for findoption()).
504 * Exception: "t_" options are at the end.
505 * The options with a NULL variable are 'hidden': a set command for them is
506 * ignored and they are not printed.
507 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100508static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000509{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200510 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000511#ifdef FEAT_RIGHTLEFT
512 (char_u *)&p_aleph, PV_NONE,
513#else
514 (char_u *)NULL, PV_NONE,
515#endif
516 {
Bram Moolenaar4f974752019-02-17 17:44:42 +0100517#if defined(MSWIN) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000518 (char_u *)128L,
519#else
520 (char_u *)224L,
521#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200522 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000523 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
Bram Moolenaard0573012017-10-28 21:11:06 +0200524#if defined(FEAT_GUI_MAC)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000525 (char_u *)&p_antialias, PV_NONE,
526 {(char_u *)FALSE, (char_u *)FALSE}
527#else
528 (char_u *)NULL, PV_NONE,
529 {(char_u *)FALSE, (char_u *)FALSE}
530#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200531 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200532 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000533#ifdef FEAT_ARABIC
534 (char_u *)VAR_WIN, PV_ARAB,
535#else
536 (char_u *)NULL, PV_NONE,
537#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200538 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000539 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
540#ifdef FEAT_ARABIC
541 (char_u *)&p_arshape, PV_NONE,
542#else
543 (char_u *)NULL, PV_NONE,
544#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200545 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000546 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
547#ifdef FEAT_RIGHTLEFT
548 (char_u *)&p_ari, PV_NONE,
549#else
550 (char_u *)NULL, PV_NONE,
551#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200552 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000553 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000554 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200555 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000556 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000557 (char_u *)&p_ambw, PV_NONE,
558 {(char_u *)"single", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200559 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000560 {"autochdir", "acd", P_BOOL|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100561#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000562 (char_u *)&p_acd, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100563 {(char_u *)FALSE, (char_u *)0L}
564#else
565 (char_u *)NULL, PV_NONE,
566 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000567#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200568 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000569 {"autoindent", "ai", P_BOOL|P_VI_DEF,
570 (char_u *)&p_ai, PV_AI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200571 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000572 {"autoprint", "ap", P_BOOL|P_VI_DEF,
573 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200574 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000575 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000576 (char_u *)&p_ar, PV_AR,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200577 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000578 {"autowrite", "aw", P_BOOL|P_VI_DEF,
579 (char_u *)&p_aw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200580 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000581 {"autowriteall","awa", P_BOOL|P_VI_DEF,
582 (char_u *)&p_awa, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200583 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000584 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
585 (char_u *)&p_bg, PV_NONE,
586 {
Bram Moolenaar4f974752019-02-17 17:44:42 +0100587#if (defined(MSWIN)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000588 (char_u *)"dark",
589#else
590 (char_u *)"light",
591#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200592 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200593 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000594 (char_u *)&p_bs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200595 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000596 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
597 (char_u *)&p_bk, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200598 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200599 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200600 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000601#ifdef UNIX
602 {(char_u *)"yes", (char_u *)"auto"}
603#else
604 {(char_u *)"auto", (char_u *)"auto"}
605#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200606 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200607 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
608 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000609 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200610 {(char_u *)DFLT_BDIR, (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000611 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000612 (char_u *)&p_bex, PV_NONE,
613 {
614#ifdef VMS
615 (char_u *)"_",
616#else
617 (char_u *)"~",
618#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200619 (char_u *)0L} SCTX_INIT},
Bram Moolenaar06e2c812019-06-12 19:05:48 +0200620 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000621#ifdef FEAT_WILDIGN
622 (char_u *)&p_bsk, PV_NONE,
623 {(char_u *)"", (char_u *)0L}
624#else
625 (char_u *)NULL, PV_NONE,
626 {(char_u *)0L, (char_u *)0L}
627#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200628 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000629 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100630#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000631 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100632 {(char_u *)600L, (char_u *)0L}
633#else
634 (char_u *)NULL, PV_NONE,
635 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000636#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200637 SCTX_INIT},
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100638 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100639#ifdef FEAT_BEVAL_GUI
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100640 (char_u *)&p_beval, PV_NONE,
641 {(char_u *)FALSE, (char_u *)0L}
642#else
643 (char_u *)NULL, PV_NONE,
644 {(char_u *)0L, (char_u *)0L}
645#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200646 SCTX_INIT},
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100647 {"balloonevalterm", "bevalterm",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100648#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100649 (char_u *)&p_bevalterm, PV_NONE,
650 {(char_u *)FALSE, (char_u *)0L}
651#else
652 (char_u *)NULL, PV_NONE,
653 {(char_u *)0L, (char_u *)0L}
654#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200655 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +0200656 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM|P_MLE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100657#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
658 (char_u *)&p_bexpr, PV_BEXPR,
659 {(char_u *)"", (char_u *)0L}
660#else
661 (char_u *)NULL, PV_NONE,
662 {(char_u *)0L, (char_u *)0L}
663#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200664 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000665 {"beautify", "bf", P_BOOL|P_VI_DEF,
666 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200667 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200668 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
669 (char_u *)&p_bo, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200670 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000671 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
672 (char_u *)&p_bin, PV_BIN,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200673 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000674 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000675 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200676 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000677 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000678 (char_u *)&p_bomb, PV_BOMB,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200679 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000680 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
681#ifdef FEAT_LINEBREAK
682 (char_u *)&p_breakat, PV_NONE,
683 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
684#else
685 (char_u *)NULL, PV_NONE,
686 {(char_u *)0L, (char_u *)0L}
687#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200688 SCTX_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200689 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
690#ifdef FEAT_LINEBREAK
691 (char_u *)VAR_WIN, PV_BRI,
692 {(char_u *)FALSE, (char_u *)0L}
693#else
694 (char_u *)NULL, PV_NONE,
695 {(char_u *)0L, (char_u *)0L}
696#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200697 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200698 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
699 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200700#ifdef FEAT_LINEBREAK
701 (char_u *)VAR_WIN, PV_BRIOPT,
702 {(char_u *)"", (char_u *)NULL}
703#else
704 (char_u *)NULL, PV_NONE,
705 {(char_u *)"", (char_u *)NULL}
706#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200707 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000708 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
709#ifdef FEAT_BROWSE
710 (char_u *)&p_bsdir, PV_NONE,
711 {(char_u *)"last", (char_u *)0L}
712#else
713 (char_u *)NULL, PV_NONE,
714 {(char_u *)0L, (char_u *)0L}
715#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200716 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000717 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000718 (char_u *)&p_bh, PV_BH,
719 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200720 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000721 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
722 (char_u *)&p_bl, PV_BL,
723 {(char_u *)1L, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200724 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000725 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000726 (char_u *)&p_bt, PV_BT,
727 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200728 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200729 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000730 (char_u *)&p_cmp, PV_NONE,
731 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200732 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +0200733 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE|P_COMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000734#ifdef FEAT_SEARCHPATH
735 (char_u *)&p_cdpath, PV_NONE,
736 {(char_u *)",,", (char_u *)0L}
737#else
738 (char_u *)NULL, PV_NONE,
739 {(char_u *)0L, (char_u *)0L}
740#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200741 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000742 {"cedit", NULL, P_STRING,
743#ifdef FEAT_CMDWIN
744 (char_u *)&p_cedit, PV_NONE,
745 {(char_u *)"", (char_u *)CTRL_F_STR}
746#else
747 (char_u *)NULL, PV_NONE,
748 {(char_u *)0L, (char_u *)0L}
749#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200750 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000751 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +0100752#if defined(FEAT_EVAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000753 (char_u *)&p_ccv, PV_NONE,
754 {(char_u *)"", (char_u *)0L}
755#else
756 (char_u *)NULL, PV_NONE,
757 {(char_u *)0L, (char_u *)0L}
758#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200759 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000760 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
761#ifdef FEAT_CINDENT
762 (char_u *)&p_cin, PV_CIN,
763#else
764 (char_u *)NULL, PV_NONE,
765#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200766 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200767 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000768#ifdef FEAT_CINDENT
769 (char_u *)&p_cink, PV_CINK,
Bram Moolenaarce655742019-01-31 14:12:57 +0100770 {INDENTKEYS_DEFAULT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000771#else
772 (char_u *)NULL, PV_NONE,
773 {(char_u *)0L, (char_u *)0L}
774#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200775 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200776 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000777#ifdef FEAT_CINDENT
778 (char_u *)&p_cino, PV_CINO,
779#else
780 (char_u *)NULL, PV_NONE,
781#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200782 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200783 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000784#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
785 (char_u *)&p_cinw, PV_CINW,
786 {(char_u *)"if,else,while,do,for,switch",
787 (char_u *)0L}
788#else
789 (char_u *)NULL, PV_NONE,
790 {(char_u *)0L, (char_u *)0L}
791#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200792 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200793 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000794#ifdef FEAT_CLIPBOARD
795 (char_u *)&p_cb, PV_NONE,
796# ifdef FEAT_XCLIPBOARD
797 {(char_u *)"autoselect,exclude:cons\\|linux",
798 (char_u *)0L}
799# else
800 {(char_u *)"", (char_u *)0L}
801# endif
802#else
803 (char_u *)NULL, PV_NONE,
804 {(char_u *)"", (char_u *)0L}
805#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200806 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000807 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
808 (char_u *)&p_ch, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200809 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000810 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
811#ifdef FEAT_CMDWIN
812 (char_u *)&p_cwh, PV_NONE,
813#else
814 (char_u *)NULL, PV_NONE,
815#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200816 {(char_u *)7L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200817 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200818#ifdef FEAT_SYN_HL
819 (char_u *)VAR_WIN, PV_CC,
820#else
821 (char_u *)NULL, PV_NONE,
822#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200823 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000824 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
825 (char_u *)&Columns, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200826 {(char_u *)80L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200827 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
828 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000829#ifdef FEAT_COMMENTS
830 (char_u *)&p_com, PV_COM,
831 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
832 (char_u *)0L}
833#else
834 (char_u *)NULL, PV_NONE,
835 {(char_u *)0L, (char_u *)0L}
836#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200837 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200838 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000839#ifdef FEAT_FOLDING
840 (char_u *)&p_cms, PV_CMS,
841 {(char_u *)"/*%s*/", (char_u *)0L}
842#else
843 (char_u *)NULL, PV_NONE,
844 {(char_u *)0L, (char_u *)0L}
845#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200846 SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000847 /* P_PRI_MKRC isn't needed here, optval_default()
848 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000849 {"compatible", "cp", P_BOOL|P_RALL,
850 (char_u *)&p_cp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200851 {(char_u *)TRUE, (char_u *)FALSE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200852 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000853#ifdef FEAT_INS_EXPAND
854 (char_u *)&p_cpt, PV_CPT,
855 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
856#else
857 (char_u *)NULL, PV_NONE,
858 {(char_u *)0L, (char_u *)0L}
859#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200860 SCTX_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200861 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200862#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200863 (char_u *)VAR_WIN, PV_COCU,
864 {(char_u *)"", (char_u *)NULL}
865#else
866 (char_u *)NULL, PV_NONE,
867 {(char_u *)NULL, (char_u *)0L}
868#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200869 SCTX_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200870 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
871#ifdef FEAT_CONCEAL
872 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200873#else
874 (char_u *)NULL, PV_NONE,
875#endif
876 {(char_u *)0L, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200877 SCTX_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000878 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
879#ifdef FEAT_COMPL_FUNC
880 (char_u *)&p_cfu, PV_CFU,
881 {(char_u *)"", (char_u *)0L}
882#else
883 (char_u *)NULL, PV_NONE,
884 {(char_u *)0L, (char_u *)0L}
885#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200886 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200887 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000888#ifdef FEAT_INS_EXPAND
889 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000890 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000891#else
892 (char_u *)NULL, PV_NONE,
893 {(char_u *)0L, (char_u *)0L}
894#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200895 SCTX_INIT},
Bram Moolenaar62a0cb42019-08-18 16:35:23 +0200896 {"completepopup", "cpp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
897#ifdef FEAT_TEXT_PROP
898 (char_u *)&p_cpp, PV_NONE,
899 {(char_u *)"", (char_u *)0L}
900#else
901 (char_u *)NULL, PV_NONE,
902 {(char_u *)NULL, (char_u *)0L}
903#endif
904 SCTX_INIT},
Bram Moolenaarac3150d2019-07-28 16:36:39 +0200905 {"completeslash", "csl", P_STRING|P_VI_DEF|P_VIM,
906#if defined(FEAT_INS_EXPAND) && defined(BACKSLASH_IN_FILENAME)
907 (char_u *)&p_csl, PV_CSL,
908 {(char_u *)"", (char_u *)0L}
909#else
910 (char_u *)NULL, PV_NONE,
911 {(char_u *)0L, (char_u *)0L}
912#endif
913 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000914 {"confirm", "cf", P_BOOL|P_VI_DEF,
915#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
916 (char_u *)&p_confirm, PV_NONE,
917#else
918 (char_u *)NULL, PV_NONE,
919#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200920 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000921 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000922 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200923 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000924 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
925 (char_u *)&p_ci, PV_CI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200926 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000927 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
928 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000929 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200930 SCTX_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200931 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200932#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200933 (char_u *)&p_cm, PV_CM,
Bram Moolenaara86187b2018-12-16 18:20:00 +0100934 {(char_u *)"blowfish2", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200935#else
936 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200937 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200938#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200939 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000940 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
941#ifdef FEAT_CSCOPE
942 (char_u *)&p_cspc, PV_NONE,
943#else
944 (char_u *)NULL, PV_NONE,
945#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200946 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000947 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
948#ifdef FEAT_CSCOPE
949 (char_u *)&p_csprg, PV_NONE,
950 {(char_u *)"cscope", (char_u *)0L}
951#else
952 (char_u *)NULL, PV_NONE,
953 {(char_u *)0L, (char_u *)0L}
954#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200955 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200956 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000957#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
958 (char_u *)&p_csqf, PV_NONE,
959 {(char_u *)"", (char_u *)0L}
960#else
961 (char_u *)NULL, PV_NONE,
962 {(char_u *)0L, (char_u *)0L}
963#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200964 SCTX_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200965 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
966#ifdef FEAT_CSCOPE
967 (char_u *)&p_csre, PV_NONE,
968#else
969 (char_u *)NULL, PV_NONE,
970#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200971 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000972 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
973#ifdef FEAT_CSCOPE
974 (char_u *)&p_cst, PV_NONE,
975#else
976 (char_u *)NULL, PV_NONE,
977#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200978 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000979 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
980#ifdef FEAT_CSCOPE
981 (char_u *)&p_csto, PV_NONE,
982#else
983 (char_u *)NULL, PV_NONE,
984#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200985 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000986 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
987#ifdef FEAT_CSCOPE
988 (char_u *)&p_csverbose, PV_NONE,
989#else
990 (char_u *)NULL, PV_NONE,
991#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200992 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200993 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200994 (char_u *)VAR_WIN, PV_CRBIND,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200995 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar177ab9e2019-01-15 21:12:57 +0100996 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000997#ifdef FEAT_SYN_HL
998 (char_u *)VAR_WIN, PV_CUC,
999#else
1000 (char_u *)NULL, PV_NONE,
1001#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001002 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +01001003 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001004#ifdef FEAT_SYN_HL
1005 (char_u *)VAR_WIN, PV_CUL,
1006#else
1007 (char_u *)NULL, PV_NONE,
1008#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001009 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001010 {"debug", NULL, P_STRING|P_VI_DEF,
1011 (char_u *)&p_debug, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001012 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001013 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001014#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001015 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001016 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001017#else
1018 (char_u *)NULL, PV_NONE,
1019 {(char_u *)NULL, (char_u *)0L}
1020#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001021 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001022 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001023 (char_u *)&p_deco, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001024 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001025 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001026#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001027 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001028#else
1029 (char_u *)NULL, PV_NONE,
1030#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001031 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001032 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1033#ifdef FEAT_DIFF
1034 (char_u *)VAR_WIN, PV_DIFF,
1035#else
1036 (char_u *)NULL, PV_NONE,
1037#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001038 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001039 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001040#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1041 (char_u *)&p_dex, PV_NONE,
1042 {(char_u *)"", (char_u *)0L}
1043#else
1044 (char_u *)NULL, PV_NONE,
1045 {(char_u *)0L, (char_u *)0L}
1046#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001047 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001048 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1049 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001050#ifdef FEAT_DIFF
1051 (char_u *)&p_dip, PV_NONE,
Bram Moolenaarc93262b2018-09-10 21:15:40 +02001052 {(char_u *)"internal,filler", (char_u *)NULL}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001053#else
1054 (char_u *)NULL, PV_NONE,
1055 {(char_u *)"", (char_u *)NULL}
1056#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001057 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001058 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1059#ifdef FEAT_DIGRAPHS
1060 (char_u *)&p_dg, PV_NONE,
1061#else
1062 (char_u *)NULL, PV_NONE,
1063#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001064 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001065 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1066 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001067 (char_u *)&p_dir, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001068 {(char_u *)DFLT_DIR, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001069 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001070 (char_u *)&p_dy, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001071 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001072 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001073 (char_u *)&p_ead, PV_NONE,
1074 {(char_u *)"both", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001075 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001076 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1077 (char_u *)&p_ed, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001078 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001079 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaar3848e002016-03-19 18:42:29 +01001080 (char_u *)&p_emoji, PV_NONE,
1081 {(char_u *)TRUE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001082 SCTX_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001083 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001084 (char_u *)&p_enc, PV_NONE,
1085 {(char_u *)ENC_DFLT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001086 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001087 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1088 (char_u *)&p_eol, PV_EOL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001089 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001090 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1091 (char_u *)&p_ea, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001092 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001093 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001094 (char_u *)&p_ep, PV_EP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001095 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001096 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1097 (char_u *)&p_eb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001098 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001099 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1100#ifdef FEAT_QUICKFIX
1101 (char_u *)&p_ef, PV_NONE,
1102 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1103#else
1104 (char_u *)NULL, PV_NONE,
1105 {(char_u *)NULL, (char_u *)0L}
1106#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001107 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001108 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001109#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001110 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001111 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001112#else
1113 (char_u *)NULL, PV_NONE,
1114 {(char_u *)NULL, (char_u *)0L}
1115#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001116 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001117 {"esckeys", "ek", P_BOOL|P_VIM,
1118 (char_u *)&p_ek, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001119 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001120 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001121 (char_u *)&p_ei, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001122 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001123 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1124 (char_u *)&p_et, PV_ET,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001125 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001126 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1127 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001128 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001129 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1130 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001131 (char_u *)&p_fenc, PV_FENC,
1132 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001133 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001134 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001135 (char_u *)&p_fencs, PV_NONE,
1136 {(char_u *)"ucs-bom", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001137 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001138 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1139 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001140 (char_u *)&p_ff, PV_FF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001141 {(char_u *)DFLT_FF, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001142 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001143 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001144 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001145 SCTX_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001146 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1147 (char_u *)&p_fic, PV_NONE,
1148 {
1149#ifdef CASE_INSENSITIVE_FILENAME
1150 (char_u *)TRUE,
1151#else
1152 (char_u *)FALSE,
1153#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001154 (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001155 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001156 (char_u *)&p_ft, PV_FT,
1157 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001158 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001159 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001160 (char_u *)&p_fcs, PV_NONE,
1161 {(char_u *)"vert:|,fold:-", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001162 SCTX_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001163 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1164 (char_u *)&p_fixeol, PV_FIXEOL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001165 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001166 {"fkmap", "fk", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001167 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001168 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001169 {"flash", "fl", P_BOOL|P_VI_DEF,
1170 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001171 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001172 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001173#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001174 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001175 {(char_u *)"", (char_u *)0L}
1176#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001177 (char_u *)NULL, PV_NONE,
1178 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001179#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001180 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001181 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1182#ifdef FEAT_FOLDING
1183 (char_u *)VAR_WIN, PV_FDC,
1184 {(char_u *)FALSE, (char_u *)0L}
1185#else
1186 (char_u *)NULL, PV_NONE,
1187 {(char_u *)NULL, (char_u *)0L}
1188#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001189 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001190 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1191#ifdef FEAT_FOLDING
1192 (char_u *)VAR_WIN, PV_FEN,
1193 {(char_u *)TRUE, (char_u *)0L}
1194#else
1195 (char_u *)NULL, PV_NONE,
1196 {(char_u *)NULL, (char_u *)0L}
1197#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001198 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001199 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN|P_MLE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001200#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1201 (char_u *)VAR_WIN, PV_FDE,
1202 {(char_u *)"0", (char_u *)NULL}
1203#else
1204 (char_u *)NULL, PV_NONE,
1205 {(char_u *)NULL, (char_u *)0L}
1206#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001207 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001208 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001209#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001210 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001211 {(char_u *)"#", (char_u *)NULL}
1212#else
1213 (char_u *)NULL, PV_NONE,
1214 {(char_u *)NULL, (char_u *)0L}
1215#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001216 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001217 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001218#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001219 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001220 {(char_u *)0L, (char_u *)0L}
1221#else
1222 (char_u *)NULL, PV_NONE,
1223 {(char_u *)NULL, (char_u *)0L}
1224#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001225 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001226 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001227#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001228 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001229 {(char_u *)-1L, (char_u *)0L}
1230#else
1231 (char_u *)NULL, PV_NONE,
1232 {(char_u *)NULL, (char_u *)0L}
1233#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001234 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001235 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001236 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001237#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001238 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001239 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001240#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001241 (char_u *)NULL, PV_NONE,
1242 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001243#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001244 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001245 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1246#ifdef FEAT_FOLDING
1247 (char_u *)VAR_WIN, PV_FDM,
1248 {(char_u *)"manual", (char_u *)NULL}
1249#else
1250 (char_u *)NULL, PV_NONE,
1251 {(char_u *)NULL, (char_u *)0L}
1252#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001253 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001254 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1255#ifdef FEAT_FOLDING
1256 (char_u *)VAR_WIN, PV_FML,
1257 {(char_u *)1L, (char_u *)0L}
1258#else
1259 (char_u *)NULL, PV_NONE,
1260 {(char_u *)NULL, (char_u *)0L}
1261#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001262 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001263 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1264#ifdef FEAT_FOLDING
1265 (char_u *)VAR_WIN, PV_FDN,
1266 {(char_u *)20L, (char_u *)0L}
1267#else
1268 (char_u *)NULL, PV_NONE,
1269 {(char_u *)NULL, (char_u *)0L}
1270#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001271 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001272 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1273#ifdef FEAT_FOLDING
1274 (char_u *)&p_fdo, PV_NONE,
1275 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1276 (char_u *)0L}
1277#else
1278 (char_u *)NULL, PV_NONE,
1279 {(char_u *)NULL, (char_u *)0L}
1280#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001281 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001282 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN|P_MLE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001283#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1284 (char_u *)VAR_WIN, PV_FDT,
1285 {(char_u *)"foldtext()", (char_u *)NULL}
1286#else
1287 (char_u *)NULL, PV_NONE,
1288 {(char_u *)NULL, (char_u *)0L}
1289#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001290 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001291 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM|P_MLE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001292#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001293 (char_u *)&p_fex, PV_FEX,
1294 {(char_u *)"", (char_u *)0L}
1295#else
1296 (char_u *)NULL, PV_NONE,
1297 {(char_u *)0L, (char_u *)0L}
1298#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001299 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001300 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1301 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001302 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001303 SCTX_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001304 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1305 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001306 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001307 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001308 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001309 (char_u *)&p_fp, PV_FP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001310 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001311 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1312#ifdef HAVE_FSYNC
1313 (char_u *)&p_fs, PV_NONE,
1314 {(char_u *)TRUE, (char_u *)0L}
1315#else
1316 (char_u *)NULL, PV_NONE,
1317 {(char_u *)FALSE, (char_u *)0L}
1318#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001319 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001320 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1321 (char_u *)&p_gd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001322 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001323 {"graphic", "gr", P_BOOL|P_VI_DEF,
1324 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001325 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001326 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001327#ifdef FEAT_QUICKFIX
1328 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001329 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001330#else
1331 (char_u *)NULL, PV_NONE,
1332 {(char_u *)NULL, (char_u *)0L}
1333#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001334 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001335 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1336#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001337 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001338 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01001339# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001340 /* may be changed to "grep -n" in os_win32.c */
1341 (char_u *)"findstr /n",
1342# else
1343# ifdef UNIX
1344 /* Add an extra file name so that grep will always
1345 * insert a file name in the match line. */
1346 (char_u *)"grep -n $* /dev/null",
1347# else
1348# ifdef VMS
1349 (char_u *)"SEARCH/NUMBERS ",
1350# else
1351 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001352# endif
1353# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001354# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001355 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001356#else
1357 (char_u *)NULL, PV_NONE,
1358 {(char_u *)NULL, (char_u *)0L}
1359#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001360 SCTX_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001361 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001362#ifdef CURSOR_SHAPE
1363 (char_u *)&p_guicursor, PV_NONE,
1364 {
1365# ifdef FEAT_GUI
1366 (char_u *)"n-v-c:block-Cursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001367# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001368 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1369# endif
1370 (char_u *)0L}
1371#else
1372 (char_u *)NULL, PV_NONE,
1373 {(char_u *)NULL, (char_u *)0L}
1374#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001375 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001376 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001377#ifdef FEAT_GUI
1378 (char_u *)&p_guifont, PV_NONE,
1379 {(char_u *)"", (char_u *)0L}
1380#else
1381 (char_u *)NULL, PV_NONE,
1382 {(char_u *)NULL, (char_u *)0L}
1383#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001384 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001385 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001386#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1387 (char_u *)&p_guifontset, PV_NONE,
1388 {(char_u *)"", (char_u *)0L}
1389#else
1390 (char_u *)NULL, PV_NONE,
1391 {(char_u *)NULL, (char_u *)0L}
1392#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001393 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001394 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001395#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001396 (char_u *)&p_guifontwide, PV_NONE,
1397 {(char_u *)"", (char_u *)0L}
1398#else
1399 (char_u *)NULL, PV_NONE,
1400 {(char_u *)NULL, (char_u *)0L}
1401#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001402 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001403 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001404#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001405 (char_u *)&p_ghr, PV_NONE,
1406#else
1407 (char_u *)NULL, PV_NONE,
1408#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001409 {(char_u *)50L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001410 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001411#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001412 (char_u *)&p_go, PV_NONE,
Bram Moolenaard0573012017-10-28 21:11:06 +02001413# if defined(UNIX) && !defined(FEAT_GUI_MAC)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001414 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001415# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001416 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001417# endif
1418#else
1419 (char_u *)NULL, PV_NONE,
1420 {(char_u *)NULL, (char_u *)0L}
1421#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001422 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001423 {"guipty", NULL, P_BOOL|P_VI_DEF,
1424#if defined(FEAT_GUI)
1425 (char_u *)&p_guipty, PV_NONE,
1426#else
1427 (char_u *)NULL, PV_NONE,
1428#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001429 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001430 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN|P_MLE,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001431#if defined(FEAT_GUI_TABLINE)
1432 (char_u *)&p_gtl, PV_NONE,
1433 {(char_u *)"", (char_u *)0L}
1434#else
1435 (char_u *)NULL, PV_NONE,
1436 {(char_u *)NULL, (char_u *)0L}
1437#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001438 SCTX_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001439 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001440#if defined(FEAT_GUI_TABLINE)
1441 (char_u *)&p_gtt, PV_NONE,
1442 {(char_u *)"", (char_u *)0L}
1443#else
1444 (char_u *)NULL, PV_NONE,
1445 {(char_u *)NULL, (char_u *)0L}
1446#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001447 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001448 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1449 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001450 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001451 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1452 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001453 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001454 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001455 {"helpheight", "hh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001456 (char_u *)&p_hh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001457 {(char_u *)20L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001458 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001459#ifdef FEAT_MULTI_LANG
1460 (char_u *)&p_hlg, PV_NONE,
1461 {(char_u *)"", (char_u *)0L}
1462#else
1463 (char_u *)NULL, PV_NONE,
1464 {(char_u *)0L, (char_u *)0L}
1465#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001466 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001467 {"hidden", "hid", P_BOOL|P_VI_DEF,
1468 (char_u *)&p_hid, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001469 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001470 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001471 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001472 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001473 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001474 {"history", "hi", P_NUM|P_VIM,
1475 (char_u *)&p_hi, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001476 {(char_u *)0L, (char_u *)50L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001477 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1478#ifdef FEAT_RIGHTLEFT
1479 (char_u *)&p_hkmap, PV_NONE,
1480#else
1481 (char_u *)NULL, PV_NONE,
1482#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001483 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001484 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1485#ifdef FEAT_RIGHTLEFT
1486 (char_u *)&p_hkmapp, PV_NONE,
1487#else
1488 (char_u *)NULL, PV_NONE,
1489#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001490 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001491 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1492 (char_u *)&p_hls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001493 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001494 {"icon", NULL, P_BOOL|P_VI_DEF,
1495#ifdef FEAT_TITLE
1496 (char_u *)&p_icon, PV_NONE,
1497#else
1498 (char_u *)NULL, PV_NONE,
1499#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001500 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001501 {"iconstring", NULL, P_STRING|P_VI_DEF|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001502#ifdef FEAT_TITLE
1503 (char_u *)&p_iconstring, PV_NONE,
1504#else
1505 (char_u *)NULL, PV_NONE,
1506#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001507 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001508 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1509 (char_u *)&p_ic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001510 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001511 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001512#if defined(FEAT_EVAL)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001513 (char_u *)&p_imaf, PV_NONE,
1514 {(char_u *)"", (char_u *)NULL}
1515# else
1516 (char_u *)NULL, PV_NONE,
1517 {(char_u *)NULL, (char_u *)0L}
1518# endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001519 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001520 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001521#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001522 (char_u *)&p_imak, PV_NONE,
1523#else
1524 (char_u *)NULL, PV_NONE,
1525#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001526 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001527 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001528 (char_u *)&p_imcmdline, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001529 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001530 {"imdisable", "imd", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001531 (char_u *)&p_imdisable, PV_NONE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001532#ifdef __sgi
1533 {(char_u *)TRUE, (char_u *)0L}
1534#else
1535 {(char_u *)FALSE, (char_u *)0L}
1536#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001537 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001538 {"iminsert", "imi", P_NUM|P_VI_DEF,
1539 (char_u *)&p_iminsert, PV_IMI,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001540 {(char_u *)B_IMODE_NONE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001541 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001542 {"imsearch", "ims", P_NUM|P_VI_DEF,
1543 (char_u *)&p_imsearch, PV_IMS,
Bram Moolenaar4cf56bb2017-09-16 15:50:32 +02001544 {(char_u *)B_IMODE_USE_INSERT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001545 SCTX_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001546 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001547#if defined(FEAT_EVAL)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001548 (char_u *)&p_imsf, PV_NONE,
1549 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001550#else
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001551 (char_u *)NULL, PV_NONE,
1552 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001553#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001554 SCTX_INIT},
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001555 {"imstyle", "imst", P_NUM|P_VI_DEF|P_SECURE,
1556#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1557 (char_u *)&p_imst, PV_NONE,
1558 {(char_u *)IM_OVER_THE_SPOT, (char_u *)0L}
1559#else
1560 (char_u *)NULL, PV_NONE,
1561 {(char_u *)0L, (char_u *)0L}
1562#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001563 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001564 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1565#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001566 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001567 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1568#else
1569 (char_u *)NULL, PV_NONE,
1570 {(char_u *)0L, (char_u *)0L}
1571#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001572 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001573 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001574#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1575 (char_u *)&p_inex, PV_INEX,
1576 {(char_u *)"", (char_u *)0L}
1577#else
1578 (char_u *)NULL, PV_NONE,
1579 {(char_u *)0L, (char_u *)0L}
1580#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001581 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001582 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1583 (char_u *)&p_is, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001584 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001585 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001586#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1587 (char_u *)&p_inde, PV_INDE,
1588 {(char_u *)"", (char_u *)0L}
1589#else
1590 (char_u *)NULL, PV_NONE,
1591 {(char_u *)0L, (char_u *)0L}
1592#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001593 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001594 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001595#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1596 (char_u *)&p_indk, PV_INDK,
Bram Moolenaarce655742019-01-31 14:12:57 +01001597 {INDENTKEYS_DEFAULT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001598#else
1599 (char_u *)NULL, PV_NONE,
1600 {(char_u *)0L, (char_u *)0L}
1601#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001602 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001603 {"infercase", "inf", P_BOOL|P_VI_DEF,
1604 (char_u *)&p_inf, PV_INF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001605 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001606 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1607 (char_u *)&p_im, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001608 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001609 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1610 (char_u *)&p_isf, PV_NONE,
1611 {
1612#ifdef BACKSLASH_IN_FILENAME
1613 /* Excluded are: & and ^ are special in cmd.exe
1614 * ( and ) are used in text separating fnames */
1615 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1616#else
1617# ifdef AMIGA
1618 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1619# else
1620# ifdef VMS
1621 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1622# else /* UNIX et al. */
1623# ifdef EBCDIC
1624 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1625# else
1626 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1627# endif
1628# endif
1629# endif
1630#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001631 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001632 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1633 (char_u *)&p_isi, PV_NONE,
1634 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001635#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001636 (char_u *)"@,48-57,_,128-167,224-235",
1637#else
1638# ifdef EBCDIC
1639 /* TODO: EBCDIC Check this! @ == isalpha()*/
1640 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1641 "112-120,128,140-142,156,158,172,"
1642 "174,186,191,203-207,219-225,235-239,"
1643 "251-254",
1644# else
1645 (char_u *)"@,48-57,_,192-255",
1646# endif
1647#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001648 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001649 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1650 (char_u *)&p_isk, PV_ISK,
1651 {
1652#ifdef EBCDIC
1653 (char_u *)"@,240-249,_",
1654 /* TODO: EBCDIC Check this! @ == isalpha()*/
1655 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1656 "112-120,128,140-142,156,158,172,"
1657 "174,186,191,203-207,219-225,235-239,"
1658 "251-254",
1659#else
1660 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001661# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001662 (char_u *)"@,48-57,_,128-167,224-235"
1663# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001664 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001665# endif
1666#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001667 } SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001668 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1669 (char_u *)&p_isp, PV_NONE,
1670 {
Bram Moolenaard0573012017-10-28 21:11:06 +02001671#if defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001672 (char_u *)"@,~-255",
1673#else
1674# ifdef EBCDIC
1675 /* all chars above 63 are printable */
1676 (char_u *)"63-255",
1677# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001678 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001679# endif
1680#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001681 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001682 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1683 (char_u *)&p_js, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001684 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001685 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1686#ifdef FEAT_CRYPT
1687 (char_u *)&p_key, PV_KEY,
1688 {(char_u *)"", (char_u *)0L}
1689#else
1690 (char_u *)NULL, PV_NONE,
1691 {(char_u *)0L, (char_u *)0L}
1692#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001693 SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001694 {"keymap", "kmp", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_RSTAT|P_NFNAME|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001695#ifdef FEAT_KEYMAP
1696 (char_u *)&p_keymap, PV_KMAP,
1697 {(char_u *)"", (char_u *)0L}
1698#else
1699 (char_u *)NULL, PV_NONE,
1700 {(char_u *)"", (char_u *)0L}
1701#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001702 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001703 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001704 (char_u *)&p_km, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001705 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001706 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001707 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001708 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001709#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001710 (char_u *)":help",
1711#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001712# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001713 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001714# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001715# ifdef USEMAN_S
1716 (char_u *)"man -s",
1717# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001718 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001719# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001720# endif
1721#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001722 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001723 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001724#ifdef FEAT_LANGMAP
1725 (char_u *)&p_langmap, PV_NONE,
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001726 {(char_u *)"", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001727#else
1728 (char_u *)NULL, PV_NONE,
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001729 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001730#endif
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001731 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001732 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001733#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1734 (char_u *)&p_lm, PV_NONE,
1735#else
1736 (char_u *)NULL, PV_NONE,
1737#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001738 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001739 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1740#ifdef FEAT_LANGMAP
1741 (char_u *)&p_lnr, PV_NONE,
1742#else
1743 (char_u *)NULL, PV_NONE,
1744#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001745 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001746 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1747#ifdef FEAT_LANGMAP
1748 (char_u *)&p_lrm, PV_NONE,
1749#else
1750 (char_u *)NULL, PV_NONE,
1751#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001752 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001753 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001754 (char_u *)&p_ls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001755 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001756 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1757 (char_u *)&p_lz, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001758 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001759 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1760#ifdef FEAT_LINEBREAK
1761 (char_u *)VAR_WIN, PV_LBR,
1762#else
1763 (char_u *)NULL, PV_NONE,
1764#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001765 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001766 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1767 (char_u *)&Rows, PV_NONE,
1768 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01001769#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001770 (char_u *)25L,
1771#else
1772 (char_u *)24L,
1773#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001774 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001775 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1776#ifdef FEAT_GUI
1777 (char_u *)&p_linespace, PV_NONE,
1778#else
1779 (char_u *)NULL, PV_NONE,
1780#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01001781#ifdef FEAT_GUI_MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001782 {(char_u *)1L, (char_u *)0L}
1783#else
1784 {(char_u *)0L, (char_u *)0L}
1785#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001786 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001787 {"lisp", NULL, P_BOOL|P_VI_DEF,
1788#ifdef FEAT_LISP
1789 (char_u *)&p_lisp, PV_LISP,
1790#else
1791 (char_u *)NULL, PV_NONE,
1792#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001793 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001794 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001795#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001796 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001797 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1798#else
1799 (char_u *)NULL, PV_NONE,
1800 {(char_u *)"", (char_u *)0L}
1801#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001802 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001803 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1804 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001805 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001806 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001807 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001808 {(char_u *)"eol:$", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001809 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1810 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001811 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001812 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001813#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001814 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001815 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001816#else
1817 (char_u *)NULL, PV_NONE,
1818 {(char_u *)"", (char_u *)0L}
1819#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001820 SCTX_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001821 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001822#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001823 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001824 {(char_u *)TRUE, (char_u *)0L}
1825#else
1826 (char_u *)NULL, PV_NONE,
1827 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001828#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001829 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001830 {"magic", NULL, P_BOOL|P_VI_DEF,
1831 (char_u *)&p_magic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001832 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001833 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001834#ifdef FEAT_QUICKFIX
1835 (char_u *)&p_mef, PV_NONE,
1836 {(char_u *)"", (char_u *)0L}
1837#else
1838 (char_u *)NULL, PV_NONE,
1839 {(char_u *)NULL, (char_u *)0L}
1840#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001841 SCTX_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001842 {"makeencoding","menc", P_STRING|P_VI_DEF,
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001843 (char_u *)&p_menc, PV_MENC,
1844 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001845 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001846 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1847#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001848 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001849# ifdef VMS
1850 {(char_u *)"MMS", (char_u *)0L}
1851# else
1852 {(char_u *)"make", (char_u *)0L}
1853# endif
1854#else
1855 (char_u *)NULL, PV_NONE,
1856 {(char_u *)NULL, (char_u *)0L}
1857#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001858 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001859 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001860 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001861 {(char_u *)"(:),{:},[:]", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001862 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001863 {"matchtime", "mat", P_NUM|P_VI_DEF,
1864 (char_u *)&p_mat, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001865 {(char_u *)5L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001866 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001867 (char_u *)&p_mco, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001868 {(char_u *)2, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001869 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1870#ifdef FEAT_EVAL
1871 (char_u *)&p_mfd, PV_NONE,
1872#else
1873 (char_u *)NULL, PV_NONE,
1874#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001875 {(char_u *)100L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001876 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1877 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001878 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001879 {"maxmem", "mm", P_NUM|P_VI_DEF,
1880 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001881 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001882 SCTX_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001883 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1884 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001885 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001886 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1887 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001888 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001889 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001890 {"menuitems", "mis", P_NUM|P_VI_DEF,
1891#ifdef FEAT_MENU
1892 (char_u *)&p_mis, PV_NONE,
1893#else
1894 (char_u *)NULL, PV_NONE,
1895#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001896 {(char_u *)25L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001897 {"mesg", NULL, P_BOOL|P_VI_DEF,
1898 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001899 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001900 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001901#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001902 (char_u *)&p_msm, PV_NONE,
1903 {(char_u *)"460000,2000,500", (char_u *)0L}
1904#else
1905 (char_u *)NULL, PV_NONE,
1906 {(char_u *)0L, (char_u *)0L}
1907#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001908 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001909 {"modeline", "ml", P_BOOL|P_VIM,
1910 (char_u *)&p_ml, PV_ML,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001911 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar7e800c62019-05-23 17:08:49 +02001912 {"modelineexpr", "mle", P_BOOL|P_VI_DEF|P_SECURE,
Bram Moolenaar110289e2019-05-23 15:38:06 +02001913 (char_u *)&p_mle, PV_NONE,
1914 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001915 {"modelines", "mls", P_NUM|P_VI_DEF,
1916 (char_u *)&p_mls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001917 {(char_u *)5L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001918 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1919 (char_u *)&p_ma, PV_MA,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001920 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001921 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1922 (char_u *)&p_mod, PV_MOD,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001923 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001924 {"more", NULL, P_BOOL|P_VIM,
1925 (char_u *)&p_more, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001926 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001927 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1928 (char_u *)&p_mouse, PV_NONE,
1929 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01001930#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001931 (char_u *)"a",
1932#else
1933 (char_u *)"",
1934#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001935 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001936 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1937#ifdef FEAT_GUI
1938 (char_u *)&p_mousef, PV_NONE,
1939#else
1940 (char_u *)NULL, PV_NONE,
1941#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001942 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001943 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1944#ifdef FEAT_GUI
1945 (char_u *)&p_mh, PV_NONE,
1946#else
1947 (char_u *)NULL, PV_NONE,
1948#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001949 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001950 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1951 (char_u *)&p_mousem, PV_NONE,
1952 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001953#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001954 (char_u *)"popup",
1955#else
Bram Moolenaard0573012017-10-28 21:11:06 +02001956# if defined(MACOS_X)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001957 (char_u *)"popup_setpos",
1958# else
1959 (char_u *)"extend",
1960# endif
1961#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001962 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001963 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001964#ifdef FEAT_MOUSESHAPE
1965 (char_u *)&p_mouseshape, PV_NONE,
1966 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1967#else
1968 (char_u *)NULL, PV_NONE,
1969 {(char_u *)NULL, (char_u *)0L}
1970#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001971 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001972 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1973 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001974 {(char_u *)500L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02001975 {"mzschemedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1976#if defined(DYNAMIC_MZSCHEME)
1977 (char_u *)&p_mzschemedll, PV_NONE,
1978 {(char_u *)DYNAMIC_MZSCH_DLL, (char_u *)0L}
1979#else
1980 (char_u *)NULL, PV_NONE,
1981 {(char_u *)"", (char_u *)0L}
1982#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001983 SCTX_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02001984 {"mzschemegcdll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1985#if defined(DYNAMIC_MZSCHEME)
1986 (char_u *)&p_mzschemegcdll, PV_NONE,
1987 {(char_u *)DYNAMIC_MZGC_DLL, (char_u *)0L}
1988#else
1989 (char_u *)NULL, PV_NONE,
1990 {(char_u *)"", (char_u *)0L}
1991#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001992 SCTX_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001993 {"mzquantum", "mzq", P_NUM,
1994#ifdef FEAT_MZSCHEME
1995 (char_u *)&p_mzq, PV_NONE,
1996#else
1997 (char_u *)NULL, PV_NONE,
1998#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001999 {(char_u *)100L, (char_u *)100L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002000 {"novice", NULL, P_BOOL|P_VI_DEF,
2001 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002002 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002003 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002004 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01002005 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002006 SCTX_INIT},
Bram Moolenaar2b044ff2019-06-24 05:45:14 +02002007 {"number", "nu", P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002008 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002009 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002010 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
2011#ifdef FEAT_LINEBREAK
2012 (char_u *)VAR_WIN, PV_NUW,
2013#else
2014 (char_u *)NULL, PV_NONE,
2015#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002016 {(char_u *)8L, (char_u *)4L} SCTX_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00002017 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00002018#ifdef FEAT_COMPL_FUNC
2019 (char_u *)&p_ofu, PV_OFU,
2020 {(char_u *)"", (char_u *)0L}
2021#else
2022 (char_u *)NULL, PV_NONE,
2023 {(char_u *)0L, (char_u *)0L}
2024#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002025 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002026 {"open", NULL, P_BOOL|P_VI_DEF,
2027 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002028 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002029 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002030#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002031 (char_u *)&p_odev, PV_NONE,
2032#else
2033 (char_u *)NULL, PV_NONE,
2034#endif
2035 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002036 SCTX_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002037 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2038 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002039 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002040 {"optimize", "opt", P_BOOL|P_VI_DEF,
2041 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002042 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002043 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002044 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002045 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002046 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2047 |P_SECURE,
2048 (char_u *)&p_pp, PV_NONE,
2049 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002050 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002051 {"paragraphs", "para", P_STRING|P_VI_DEF,
2052 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002053 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002054 (char_u *)0L} SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002055 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002056 (char_u *)&p_paste, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002057 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002058 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2059 (char_u *)&p_pt, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002060 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002061 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2062#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2063 (char_u *)&p_pex, PV_NONE,
2064 {(char_u *)"", (char_u *)0L}
2065#else
2066 (char_u *)NULL, PV_NONE,
2067 {(char_u *)0L, (char_u *)0L}
2068#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002069 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002070 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002071 (char_u *)&p_pm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002072 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002073 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002074 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002075 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002076#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002077 (char_u *)".,,",
2078#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002079 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002080#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002081 (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002082 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002083#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002084 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002085 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002086#else
2087 (char_u *)NULL, PV_NONE,
2088 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002089#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002090 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002091 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2092 (char_u *)&p_pi, PV_PI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002093 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002094 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002095#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002096 (char_u *)&p_pvh, PV_NONE,
2097#else
2098 (char_u *)NULL, PV_NONE,
2099#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002100 {(char_u *)12L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar79648732019-07-18 21:43:07 +02002101 {"previewpopup", "pvp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2102#ifdef FEAT_TEXT_PROP
2103 (char_u *)&p_pvp, PV_NONE,
2104 {(char_u *)"", (char_u *)0L}
2105#else
2106 (char_u *)NULL, PV_NONE,
2107 {(char_u *)NULL, (char_u *)0L}
2108#endif
2109 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002110 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002111#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002112 (char_u *)VAR_WIN, PV_PVW,
2113#else
2114 (char_u *)NULL, PV_NONE,
2115#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002116 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002117 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002118#ifdef FEAT_PRINTER
2119 (char_u *)&p_pdev, PV_NONE,
2120 {(char_u *)"", (char_u *)0L}
2121#else
2122 (char_u *)NULL, PV_NONE,
2123 {(char_u *)NULL, (char_u *)0L}
2124#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002125 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002126 {"printencoding", "penc", P_STRING|P_VI_DEF,
2127#ifdef FEAT_POSTSCRIPT
2128 (char_u *)&p_penc, PV_NONE,
2129 {(char_u *)"", (char_u *)0L}
2130#else
2131 (char_u *)NULL, PV_NONE,
2132 {(char_u *)NULL, (char_u *)0L}
2133#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002134 SCTX_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002135 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002136#ifdef FEAT_POSTSCRIPT
2137 (char_u *)&p_pexpr, PV_NONE,
2138 {(char_u *)"", (char_u *)0L}
2139#else
2140 (char_u *)NULL, PV_NONE,
2141 {(char_u *)NULL, (char_u *)0L}
2142#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002143 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002144 {"printfont", "pfn", P_STRING|P_VI_DEF,
2145#ifdef FEAT_PRINTER
2146 (char_u *)&p_pfn, PV_NONE,
2147 {
2148# ifdef MSWIN
2149 (char_u *)"Courier_New:h10",
2150# else
2151 (char_u *)"courier",
2152# endif
2153 (char_u *)0L}
2154#else
2155 (char_u *)NULL, PV_NONE,
2156 {(char_u *)NULL, (char_u *)0L}
2157#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002158 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002159 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2160#ifdef FEAT_PRINTER
2161 (char_u *)&p_header, PV_NONE,
Bram Moolenaar0903d562017-08-26 22:30:15 +02002162 /* untranslated to avoid problems when 'encoding'
2163 * is changed */
2164 {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002165#else
2166 (char_u *)NULL, PV_NONE,
2167 {(char_u *)NULL, (char_u *)0L}
2168#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002169 SCTX_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002170 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01002171#if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002172 (char_u *)&p_pmcs, PV_NONE,
2173 {(char_u *)"", (char_u *)0L}
2174#else
2175 (char_u *)NULL, PV_NONE,
2176 {(char_u *)NULL, (char_u *)0L}
2177#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002178 SCTX_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002179 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01002180#if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002181 (char_u *)&p_pmfn, PV_NONE,
2182 {(char_u *)"", (char_u *)0L}
2183#else
2184 (char_u *)NULL, PV_NONE,
2185 {(char_u *)NULL, (char_u *)0L}
2186#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002187 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002188 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002189#ifdef FEAT_PRINTER
2190 (char_u *)&p_popt, PV_NONE,
2191 {(char_u *)"", (char_u *)0L}
2192#else
2193 (char_u *)NULL, PV_NONE,
2194 {(char_u *)NULL, (char_u *)0L}
2195#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002196 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002197 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002198 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002199 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002200 {"pumheight", "ph", P_NUM|P_VI_DEF,
2201#ifdef FEAT_INS_EXPAND
2202 (char_u *)&p_ph, PV_NONE,
2203#else
2204 (char_u *)NULL, PV_NONE,
2205#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002206 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaara8f04aa2018-02-10 15:36:55 +01002207 {"pumwidth", "pw", P_NUM|P_VI_DEF,
2208#ifdef FEAT_INS_EXPAND
2209 (char_u *)&p_pw, PV_NONE,
2210#else
2211 (char_u *)NULL, PV_NONE,
2212#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002213 {(char_u *)15L, (char_u *)15L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002214 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002215#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002216 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002217 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002218#else
2219 (char_u *)NULL, PV_NONE,
2220 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002221#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002222 SCTX_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002223 {"pythonthreehome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2224#if defined(FEAT_PYTHON3)
2225 (char_u *)&p_py3home, PV_NONE,
2226 {(char_u *)"", (char_u *)0L}
2227#else
2228 (char_u *)NULL, PV_NONE,
2229 {(char_u *)NULL, (char_u *)0L}
2230#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002231 SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002232 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002233#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002234 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002235 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002236#else
2237 (char_u *)NULL, PV_NONE,
2238 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002239#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002240 SCTX_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002241 {"pythonhome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2242#if defined(FEAT_PYTHON)
2243 (char_u *)&p_pyhome, PV_NONE,
2244 {(char_u *)"", (char_u *)0L}
2245#else
2246 (char_u *)NULL, PV_NONE,
2247 {(char_u *)NULL, (char_u *)0L}
2248#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002249 SCTX_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002250 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2251#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2252 (char_u *)&p_pyx, PV_NONE,
2253#else
2254 (char_u *)NULL, PV_NONE,
2255#endif
2256 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002257 SCTX_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002258 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2259#ifdef FEAT_TEXTOBJ
2260 (char_u *)&p_qe, PV_QE,
2261 {(char_u *)"\\", (char_u *)0L}
2262#else
2263 (char_u *)NULL, PV_NONE,
2264 {(char_u *)NULL, (char_u *)0L}
2265#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002266 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002267 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2268 (char_u *)&p_ro, PV_RO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002269 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002270 {"redraw", NULL, P_BOOL|P_VI_DEF,
2271 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002272 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002273 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2274#ifdef FEAT_RELTIME
2275 (char_u *)&p_rdt, PV_NONE,
2276#else
2277 (char_u *)NULL, PV_NONE,
2278#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002279 {(char_u *)2000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002280 {"regexpengine", "re", P_NUM|P_VI_DEF,
2281 (char_u *)&p_re, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002282 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar2b044ff2019-06-24 05:45:14 +02002283 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaar64486672010-05-16 15:46:46 +02002284 (char_u *)VAR_WIN, PV_RNU,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002285 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002286 {"remap", NULL, P_BOOL|P_VI_DEF,
2287 (char_u *)&p_remap, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002288 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002289 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002290#ifdef FEAT_RENDER_OPTIONS
2291 (char_u *)&p_rop, PV_NONE,
2292 {(char_u *)"", (char_u *)0L}
2293#else
2294 (char_u *)NULL, PV_NONE,
2295 {(char_u *)NULL, (char_u *)0L}
2296#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002297 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002298 {"report", NULL, P_NUM|P_VI_DEF,
2299 (char_u *)&p_report, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002300 {(char_u *)2L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002301 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
Bram Moolenaar4f974752019-02-17 17:44:42 +01002302#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00002303 (char_u *)&p_rs, PV_NONE,
2304#else
2305 (char_u *)NULL, PV_NONE,
2306#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002307 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002308 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2309#ifdef FEAT_RIGHTLEFT
2310 (char_u *)&p_ri, PV_NONE,
2311#else
2312 (char_u *)NULL, PV_NONE,
2313#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002314 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002315 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2316#ifdef FEAT_RIGHTLEFT
2317 (char_u *)VAR_WIN, PV_RL,
2318#else
2319 (char_u *)NULL, PV_NONE,
2320#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002321 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002322 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2323#ifdef FEAT_RIGHTLEFT
2324 (char_u *)VAR_WIN, PV_RLC,
2325 {(char_u *)"search", (char_u *)NULL}
2326#else
2327 (char_u *)NULL, PV_NONE,
2328 {(char_u *)NULL, (char_u *)0L}
2329#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002330 SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002331 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002332#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002333 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002334 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002335#else
2336 (char_u *)NULL, PV_NONE,
2337 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002338#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002339 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002340 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2341#ifdef FEAT_CMDL_INFO
2342 (char_u *)&p_ru, PV_NONE,
2343#else
2344 (char_u *)NULL, PV_NONE,
2345#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002346 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02002347 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002348#ifdef FEAT_STL_OPT
2349 (char_u *)&p_ruf, PV_NONE,
2350#else
2351 (char_u *)NULL, PV_NONE,
2352#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002353 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002354 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2355 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002356 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002357 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002358 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002359 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2360 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002361 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002362 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002363 (char_u *)VAR_WIN, PV_SCBIND,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002364 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002365 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2366 (char_u *)&p_sj, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002367 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002368 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
Bram Moolenaar375e3392019-01-31 18:26:10 +01002369 (char_u *)&p_so, PV_SO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002370 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002371 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002372 (char_u *)&p_sbo, PV_NONE,
2373 {(char_u *)"ver,jump", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002374 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002375 {"sections", "sect", P_STRING|P_VI_DEF,
2376 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002377 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002378 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002379 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2380 (char_u *)&p_secure, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002381 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002382 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002383 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002384 {(char_u *)"inclusive", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002385 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002386 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002387 (char_u *)&p_slm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002388 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002389 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002390#ifdef FEAT_SESSION
2391 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar4d8bac82018-03-09 21:33:34 +01002392 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize,terminal",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002393 (char_u *)0L}
2394#else
2395 (char_u *)NULL, PV_NONE,
2396 {(char_u *)0L, (char_u *)0L}
2397#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002398 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002399 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2400 (char_u *)&p_sh, PV_NONE,
2401 {
2402#ifdef VMS
2403 (char_u *)"-",
2404#else
Bram Moolenaar4f974752019-02-17 17:44:42 +01002405# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002406 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002407# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002408 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002409# endif
2410#endif /* VMS */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002411 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002412 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2413 (char_u *)&p_shcf, PV_NONE,
2414 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002415#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002416 (char_u *)"/c",
2417#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002418 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002419#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002420 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002421 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2422#ifdef FEAT_QUICKFIX
2423 (char_u *)&p_sp, PV_NONE,
2424 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002425#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002426 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002427#else
2428 (char_u *)">",
2429#endif
2430 (char_u *)0L}
2431#else
2432 (char_u *)NULL, PV_NONE,
2433 {(char_u *)0L, (char_u *)0L}
2434#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002435 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002436 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2437 (char_u *)&p_shq, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002438 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002439 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2440 (char_u *)&p_srr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002441 {(char_u *)">", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002442 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2443#ifdef BACKSLASH_IN_FILENAME
2444 (char_u *)&p_ssl, PV_NONE,
2445#else
2446 (char_u *)NULL, PV_NONE,
2447#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002448 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002449 {"shelltemp", "stmp", P_BOOL,
2450 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002451 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002452 {"shelltype", "st", P_NUM|P_VI_DEF,
2453#ifdef AMIGA
2454 (char_u *)&p_st, PV_NONE,
2455#else
2456 (char_u *)NULL, PV_NONE,
2457#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002458 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002459 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2460 (char_u *)&p_sxq, PV_NONE,
2461 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002462#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002463 (char_u *)"\"",
2464#else
2465 (char_u *)"",
2466#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002467 (char_u *)0L} SCTX_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002468 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2469 (char_u *)&p_sxe, PV_NONE,
2470 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01002471#if defined(MSWIN)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002472 (char_u *)"\"&|<>()@^",
2473#else
2474 (char_u *)"",
2475#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002476 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002477 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2478 (char_u *)&p_sr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002479 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002480 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2481 (char_u *)&p_sw, PV_SW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002482 {(char_u *)8L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002483 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2484 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar9dfa3132019-05-04 21:08:40 +02002485 {(char_u *)"S", (char_u *)"filnxtToOS"}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002486 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002487 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002488 (char_u *)&p_sn, PV_SN,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002489 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002490 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2491#ifdef FEAT_LINEBREAK
2492 (char_u *)&p_sbr, PV_NONE,
2493#else
2494 (char_u *)NULL, PV_NONE,
2495#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002496 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002497 {"showcmd", "sc", P_BOOL|P_VIM,
2498#ifdef FEAT_CMDL_INFO
2499 (char_u *)&p_sc, PV_NONE,
2500#else
2501 (char_u *)NULL, PV_NONE,
2502#endif
2503 {(char_u *)FALSE,
2504#ifdef UNIX
2505 (char_u *)FALSE
2506#else
2507 (char_u *)TRUE
2508#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002509 } SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002510 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2511 (char_u *)&p_sft, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002512 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002513 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2514 (char_u *)&p_sm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002515 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002516 {"showmode", "smd", P_BOOL|P_VIM,
2517 (char_u *)&p_smd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002518 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002519 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002520 (char_u *)&p_stal, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002521 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002522 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2523 (char_u *)&p_ss, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002524 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002525 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar375e3392019-01-31 18:26:10 +01002526 (char_u *)&p_siso, PV_SISO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002527 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar2b044ff2019-06-24 05:45:14 +02002528 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RCLR,
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002529#ifdef FEAT_SIGNS
2530 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002531 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002532#else
2533 (char_u *)NULL, PV_NONE,
2534 {(char_u *)NULL, (char_u *)0L}
2535#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002536 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002537 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2538 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002539 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002540 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2541 (char_u *)&p_scs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002542 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002543 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2544#ifdef FEAT_SMARTINDENT
2545 (char_u *)&p_si, PV_SI,
2546#else
2547 (char_u *)NULL, PV_NONE,
2548#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002549 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002550 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2551 (char_u *)&p_sta, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002552 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002553 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2554 (char_u *)&p_sts, PV_STS,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002555 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002556 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2557 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002558 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002559 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002560#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002561 (char_u *)VAR_WIN, PV_SPELL,
2562#else
2563 (char_u *)NULL, PV_NONE,
2564#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002565 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002566 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002567#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002568 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002569 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002570#else
2571 (char_u *)NULL, PV_NONE,
2572 {(char_u *)0L, (char_u *)0L}
2573#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002574 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002575 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2576 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002577#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002578 (char_u *)&p_spf, PV_SPF,
2579 {(char_u *)"", (char_u *)0L}
2580#else
2581 (char_u *)NULL, PV_NONE,
2582 {(char_u *)0L, (char_u *)0L}
2583#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002584 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002585 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2586 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002587#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002588 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002589 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002590#else
2591 (char_u *)NULL, PV_NONE,
2592 {(char_u *)0L, (char_u *)0L}
2593#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002594 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002595 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002596#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002597 (char_u *)&p_sps, PV_NONE,
2598 {(char_u *)"best", (char_u *)0L}
2599#else
2600 (char_u *)NULL, PV_NONE,
2601 {(char_u *)0L, (char_u *)0L}
2602#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002603 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002604 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002605 (char_u *)&p_sb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002606 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002607 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002608 (char_u *)&p_spr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002609 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002610 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2611 (char_u *)&p_sol, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002612 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02002613 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002614#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002615 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002616#else
2617 (char_u *)NULL, PV_NONE,
2618#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002619 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002620 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002621 (char_u *)&p_su, PV_NONE,
2622 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002623 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002624 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002625#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002626 (char_u *)&p_sua, PV_SUA,
2627 {(char_u *)"", (char_u *)0L}
2628#else
2629 (char_u *)NULL, PV_NONE,
2630 {(char_u *)0L, (char_u *)0L}
2631#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002632 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002633 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2634 (char_u *)&p_swf, PV_SWF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002635 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002636 {"swapsync", "sws", P_STRING|P_VI_DEF,
2637 (char_u *)&p_sws, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002638 {(char_u *)"fsync", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002639 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002640 (char_u *)&p_swb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002641 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002642 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2643#ifdef FEAT_SYN_HL
2644 (char_u *)&p_smc, PV_SMC,
2645 {(char_u *)3000L, (char_u *)0L}
2646#else
2647 (char_u *)NULL, PV_NONE,
2648 {(char_u *)0L, (char_u *)0L}
2649#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002650 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002651 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002652#ifdef FEAT_SYN_HL
2653 (char_u *)&p_syn, PV_SYN,
2654 {(char_u *)"", (char_u *)0L}
2655#else
2656 (char_u *)NULL, PV_NONE,
2657 {(char_u *)0L, (char_u *)0L}
2658#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002659 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02002660 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL|P_MLE,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002661#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002662 (char_u *)&p_tal, PV_NONE,
2663#else
2664 (char_u *)NULL, PV_NONE,
2665#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002666 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002667 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002668 (char_u *)&p_tpm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002669 {(char_u *)10L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002670 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2671 (char_u *)&p_ts, PV_TS,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002672 {(char_u *)8L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002673 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2674 (char_u *)&p_tbs, PV_NONE,
2675#ifdef VMS /* binary searching doesn't appear to work on VMS */
2676 {(char_u *)0L, (char_u *)0L}
2677#else
2678 {(char_u *)TRUE, (char_u *)0L}
2679#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002680 SCTX_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002681 {"tagcase", "tc", P_STRING|P_VIM,
2682 (char_u *)&p_tc, PV_TC,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002683 {(char_u *)"followic", (char_u *)"followic"} SCTX_INIT},
Bram Moolenaar45e18cb2019-04-28 18:05:35 +02002684 {"tagfunc", "tfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
2685#ifdef FEAT_EVAL
2686 (char_u *)&p_tfu, PV_TFU,
2687 {(char_u *)"", (char_u *)0L}
2688#else
2689 (char_u *)NULL, PV_NONE,
2690 {(char_u *)0L, (char_u *)0L}
2691#endif
2692 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002693 {"taglength", "tl", P_NUM|P_VI_DEF,
2694 (char_u *)&p_tl, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002695 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002696 {"tagrelative", "tr", P_BOOL|P_VIM,
2697 (char_u *)&p_tr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002698 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002699 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002700 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002701 {
2702#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2703 (char_u *)"./tags,./TAGS,tags,TAGS",
2704#else
2705 (char_u *)"./tags,tags",
2706#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002707 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002708 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2709 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002710 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002711 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002712#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002713 (char_u *)&p_tcldll, PV_NONE,
2714 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002715#else
2716 (char_u *)NULL, PV_NONE,
2717 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002718#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002719 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002720 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2721 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002722 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002723 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2724#ifdef FEAT_ARABIC
2725 (char_u *)&p_tbidi, PV_NONE,
2726#else
2727 (char_u *)NULL, PV_NONE,
2728#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002729 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002730 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002731 (char_u *)&p_tenc, PV_NONE,
2732 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002733 SCTX_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002734 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2735#ifdef FEAT_TERMGUICOLORS
2736 (char_u *)&p_tgc, PV_NONE,
2737 {(char_u *)FALSE, (char_u *)FALSE}
2738#else
2739 (char_u*)NULL, PV_NONE,
2740 {(char_u *)FALSE, (char_u *)FALSE}
2741#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002742 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002743 {"termwinkey", "twk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2744#ifdef FEAT_TERMINAL
2745 (char_u *)VAR_WIN, PV_TWK,
2746 {(char_u *)"", (char_u *)NULL}
2747#else
2748 (char_u *)NULL, PV_NONE,
2749 {(char_u *)NULL, (char_u *)0L}
2750#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002751 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002752 {"termwinscroll", "twsl", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2753#ifdef FEAT_TERMINAL
2754 (char_u *)&p_twsl, PV_TWSL,
2755 {(char_u *)10000L, (char_u *)10000L}
2756#else
2757 (char_u *)NULL, PV_NONE,
2758 {(char_u *)NULL, (char_u *)0L}
2759#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002760 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002761 {"termwinsize", "tws", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2762#ifdef FEAT_TERMINAL
2763 (char_u *)VAR_WIN, PV_TWS,
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002764 {(char_u *)"", (char_u *)NULL}
2765#else
2766 (char_u *)NULL, PV_NONE,
2767 {(char_u *)NULL, (char_u *)0L}
2768#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002769 SCTX_INIT},
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01002770 {"termwintype", "twt", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar4f974752019-02-17 17:44:42 +01002771#if defined(MSWIN) && defined(FEAT_TERMINAL)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01002772 (char_u *)&p_twt, PV_NONE,
2773 {(char_u *)"", (char_u *)NULL}
2774#else
2775 (char_u *)NULL, PV_NONE,
2776 {(char_u *)NULL, (char_u *)0L}
2777#endif
2778 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002779 {"terse", NULL, P_BOOL|P_VI_DEF,
2780 (char_u *)&p_terse, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002781 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002782 {"textauto", "ta", P_BOOL|P_VIM,
2783 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002784 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002785 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002786 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2787 (char_u *)&p_tx, PV_TX,
2788 {
2789#ifdef USE_CRNL
2790 (char_u *)TRUE,
2791#else
2792 (char_u *)FALSE,
2793#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002794 (char_u *)0L} SCTX_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002795 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002796 (char_u *)&p_tw, PV_TW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002797 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002798 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002799#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002800 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002801#else
2802 (char_u *)NULL, PV_NONE,
2803#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002804 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002805 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2806 (char_u *)&p_to, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002807 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002808 {"timeout", "to", P_BOOL|P_VI_DEF,
2809 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002810 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002811 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2812 (char_u *)&p_tm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002813 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002814 {"title", NULL, P_BOOL|P_VI_DEF,
2815#ifdef FEAT_TITLE
2816 (char_u *)&p_title, PV_NONE,
2817#else
2818 (char_u *)NULL, PV_NONE,
2819#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002820 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002821 {"titlelen", NULL, P_NUM|P_VI_DEF,
2822#ifdef FEAT_TITLE
2823 (char_u *)&p_titlelen, PV_NONE,
2824#else
2825 (char_u *)NULL, PV_NONE,
2826#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002827 {(char_u *)85L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002828 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002829#ifdef FEAT_TITLE
2830 (char_u *)&p_titleold, PV_NONE,
2831 {(char_u *)N_("Thanks for flying Vim"),
2832 (char_u *)0L}
2833#else
2834 (char_u *)NULL, PV_NONE,
2835 {(char_u *)0L, (char_u *)0L}
2836#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002837 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02002838 {"titlestring", NULL, P_STRING|P_VI_DEF|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002839#ifdef FEAT_TITLE
2840 (char_u *)&p_titlestring, PV_NONE,
2841#else
2842 (char_u *)NULL, PV_NONE,
2843#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002844 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002845 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar4f974752019-02-17 17:44:42 +01002846#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002847 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002848 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002849#else
2850 (char_u *)NULL, PV_NONE,
2851 {(char_u *)0L, (char_u *)0L}
2852#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002853 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002854 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002855#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002856 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002857 {(char_u *)"small", (char_u *)0L}
2858#else
2859 (char_u *)NULL, PV_NONE,
2860 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002861#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002862 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002863 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2864 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002865 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002866 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2867 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002868 {(char_u *)-1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002869 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2870 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002871 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002872 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2873 (char_u *)&p_tf, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002874 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002875 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2876#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2877 (char_u *)&p_ttym, PV_NONE,
2878#else
2879 (char_u *)NULL, PV_NONE,
2880#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002881 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002882 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2883 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002884 {(char_u *)999L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002885 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2886 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002887 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002888 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2889 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002890#ifdef FEAT_PERSISTENT_UNDO
2891 (char_u *)&p_udir, PV_NONE,
2892 {(char_u *)".", (char_u *)0L}
2893#else
2894 (char_u *)NULL, PV_NONE,
2895 {(char_u *)0L, (char_u *)0L}
2896#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002897 SCTX_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002898 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2899#ifdef FEAT_PERSISTENT_UNDO
2900 (char_u *)&p_udf, PV_UDF,
2901#else
2902 (char_u *)NULL, PV_NONE,
2903#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002904 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002905 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002906 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002907 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01002908#if defined(UNIX) || defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002909 (char_u *)1000L,
2910#else
2911 (char_u *)100L,
2912#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002913 (char_u *)0L} SCTX_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002914 {"undoreload", "ur", P_NUM|P_VI_DEF,
2915 (char_u *)&p_ur, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002916 { (char_u *)10000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002917 {"updatecount", "uc", P_NUM|P_VI_DEF,
2918 (char_u *)&p_uc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002919 {(char_u *)200L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002920 {"updatetime", "ut", P_NUM|P_VI_DEF,
2921 (char_u *)&p_ut, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002922 {(char_u *)4000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar04958cb2018-06-23 19:23:02 +02002923 {"varsofttabstop", "vsts", P_STRING|P_VI_DEF|P_VIM|P_COMMA,
2924#ifdef FEAT_VARTABS
2925 (char_u *)&p_vsts, PV_VSTS,
2926 {(char_u *)"", (char_u *)0L}
2927#else
2928 (char_u *)NULL, PV_NONE,
2929 {(char_u *)"", (char_u *)NULL}
2930#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002931 SCTX_INIT},
Bram Moolenaar04958cb2018-06-23 19:23:02 +02002932 {"vartabstop", "vts", P_STRING|P_VI_DEF|P_VIM|P_RBUF|P_COMMA,
2933#ifdef FEAT_VARTABS
2934 (char_u *)&p_vts, PV_VTS,
2935 {(char_u *)"", (char_u *)0L}
2936#else
2937 (char_u *)NULL, PV_NONE,
2938 {(char_u *)"", (char_u *)NULL}
2939#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002940 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002941 {"verbose", "vbs", P_NUM|P_VI_DEF,
2942 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002943 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002944 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2945 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002946 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002947 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2948#ifdef FEAT_SESSION
2949 (char_u *)&p_vdir, PV_NONE,
2950 {(char_u *)DFLT_VDIR, (char_u *)0L}
2951#else
2952 (char_u *)NULL, PV_NONE,
2953 {(char_u *)0L, (char_u *)0L}
2954#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002955 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002956 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002957#ifdef FEAT_SESSION
2958 (char_u *)&p_vop, PV_NONE,
Bram Moolenaar13e90412017-11-11 18:16:48 +01002959 {(char_u *)"folds,options,cursor,curdir",
2960 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002961#else
2962 (char_u *)NULL, PV_NONE,
2963 {(char_u *)0L, (char_u *)0L}
2964#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002965 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002966 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002967#ifdef FEAT_VIMINFO
2968 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002969#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002970 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002971#else
2972# ifdef AMIGA
2973 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002974 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002975# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002976 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002977# endif
2978#endif
2979#else
2980 (char_u *)NULL, PV_NONE,
2981 {(char_u *)0L, (char_u *)0L}
2982#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002983 SCTX_INIT},
Bram Moolenaarc229e542018-07-08 21:46:56 +02002984 {"viminfofile", "vif", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP
2985 |P_SECURE|P_VI_DEF,
Bram Moolenaarc4da1132017-07-15 19:39:43 +02002986#ifdef FEAT_VIMINFO
2987 (char_u *)&p_viminfofile, PV_NONE,
2988 {(char_u *)"", (char_u *)0L}
2989#else
2990 (char_u *)NULL, PV_NONE,
2991 {(char_u *)0L, (char_u *)0L}
2992#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002993 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002994 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2995 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002996 (char_u *)&p_ve, PV_NONE,
2997 {(char_u *)"", (char_u *)""}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002998 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002999 {"visualbell", "vb", P_BOOL|P_VI_DEF,
3000 (char_u *)&p_vb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003001 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003002 {"w300", NULL, P_NUM|P_VI_DEF,
3003 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003004 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003005 {"w1200", NULL, P_NUM|P_VI_DEF,
3006 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003007 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003008 {"w9600", NULL, P_NUM|P_VI_DEF,
3009 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003010 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003011 {"warn", NULL, P_BOOL|P_VI_DEF,
3012 (char_u *)&p_warn, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003013 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003014 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
3015 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003016 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003017 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003018 (char_u *)&p_ww, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003019 {(char_u *)"", (char_u *)"b,s"} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003020 {"wildchar", "wc", P_NUM|P_VIM,
3021 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003022 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003023 SCTX_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003024 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003025 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003026 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003027 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003028#ifdef FEAT_WILDIGN
3029 (char_u *)&p_wig, PV_NONE,
3030#else
3031 (char_u *)NULL, PV_NONE,
3032#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003033 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003034 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3035 (char_u *)&p_wic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003036 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003037 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
3038#ifdef FEAT_WILDMENU
3039 (char_u *)&p_wmnu, PV_NONE,
3040#else
3041 (char_u *)NULL, PV_NONE,
3042#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003043 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003044 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003045 (char_u *)&p_wim, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003046 {(char_u *)"full", (char_u *)0L} SCTX_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003047 {"wildoptions", "wop", P_STRING|P_VI_DEF,
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003048 (char_u *)&p_wop, PV_NONE,
3049 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003050 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003051 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3052#ifdef FEAT_WAK
3053 (char_u *)&p_wak, PV_NONE,
3054 {(char_u *)"menu", (char_u *)0L}
3055#else
3056 (char_u *)NULL, PV_NONE,
3057 {(char_u *)NULL, (char_u *)0L}
3058#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003059 SCTX_INIT},
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003060 {"wincolor", "wcr", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
3061 (char_u *)VAR_WIN, PV_WCR,
3062 {(char_u *)"", (char_u *)NULL}
3063 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003064 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003065 (char_u *)&p_window, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003066 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003067 {"winheight", "wh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003068 (char_u *)&p_wh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003069 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003070 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003071 (char_u *)VAR_WIN, PV_WFH,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003072 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003073 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003074 (char_u *)VAR_WIN, PV_WFW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003075 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003076 {"winminheight", "wmh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003077 (char_u *)&p_wmh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003078 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003079 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003080 (char_u *)&p_wmw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003081 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003082 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar4f974752019-02-17 17:44:42 +01003083#if defined(MSWIN) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003084 (char_u *)&p_winptydll, PV_NONE, {
3085# ifdef _WIN64
3086 (char_u *)"winpty64.dll",
3087# else
3088 (char_u *)"winpty32.dll",
3089# endif
3090 (char_u *)0L}
3091#else
3092 (char_u *)NULL, PV_NONE,
3093 {(char_u *)0L, (char_u *)0L}
3094#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003095 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003096 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003097 (char_u *)&p_wiw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003098 {(char_u *)20L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003099 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3100 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003101 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003102 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3103 (char_u *)&p_wm, PV_WM,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003104 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003105 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3106 (char_u *)&p_ws, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003107 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003108 {"write", NULL, P_BOOL|P_VI_DEF,
3109 (char_u *)&p_write, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003110 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003111 {"writeany", "wa", P_BOOL|P_VI_DEF,
3112 (char_u *)&p_wa, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003113 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003114 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3115 (char_u *)&p_wb, PV_NONE,
3116 {
3117#ifdef FEAT_WRITEBACKUP
3118 (char_u *)TRUE,
3119#else
3120 (char_u *)FALSE,
3121#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003122 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003123 {"writedelay", "wd", P_NUM|P_VI_DEF,
3124 (char_u *)&p_wd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003125 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003126
3127/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003128#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003129 (char_u *)&vvv, PV_NONE, \
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003130 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003131
3132 p_term("t_AB", T_CAB)
3133 p_term("t_AF", T_CAF)
3134 p_term("t_AL", T_CAL)
3135 p_term("t_al", T_AL)
3136 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003137 p_term("t_BE", T_BE)
3138 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003139 p_term("t_cd", T_CD)
3140 p_term("t_ce", T_CE)
3141 p_term("t_cl", T_CL)
3142 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003143 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003144 p_term("t_Co", T_CCO)
3145 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003146 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003147 p_term("t_cs", T_CS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003148 p_term("t_CV", T_CSV)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003149 p_term("t_da", T_DA)
3150 p_term("t_db", T_DB)
3151 p_term("t_DL", T_CDL)
3152 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003153 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003154 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003155 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003156 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003157 p_term("t_IE", T_CIE)
3158 p_term("t_IS", T_CIS)
3159 p_term("t_ke", T_KE)
3160 p_term("t_ks", T_KS)
3161 p_term("t_le", T_LE)
3162 p_term("t_mb", T_MB)
3163 p_term("t_md", T_MD)
3164 p_term("t_me", T_ME)
3165 p_term("t_mr", T_MR)
3166 p_term("t_ms", T_MS)
3167 p_term("t_nd", T_ND)
3168 p_term("t_op", T_OP)
Bram Moolenaara20f83d2017-10-15 13:35:01 +02003169 p_term("t_RF", T_RFG)
Bram Moolenaare5401222015-06-25 19:16:56 +02003170 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003171 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003172 p_term("t_RI", T_CRI)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003173 p_term("t_Ri", T_SRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003174 p_term("t_RS", T_CRS)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003175 p_term("t_RT", T_CRT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003176 p_term("t_RV", T_CRV)
3177 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003178 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003179 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003180 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003181 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003182 p_term("t_SI", T_CSI)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003183 p_term("t_Si", T_SSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003184 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003185 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003186 p_term("t_sr", T_SR)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003187 p_term("t_ST", T_CST)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003188 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003189 p_term("t_te", T_TE)
3190 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003191 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003192 p_term("t_ts", T_TS)
3193 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003194 p_term("t_ue", T_UE)
3195 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003196 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003197 p_term("t_vb", T_VB)
3198 p_term("t_ve", T_VE)
3199 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003200 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003201 p_term("t_vs", T_VS)
3202 p_term("t_WP", T_CWP)
3203 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003204 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003205 p_term("t_xs", T_XS)
3206 p_term("t_ZH", T_CZH)
3207 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003208 p_term("t_8f", T_8F)
3209 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003210
3211/* terminal key codes are not in here */
3212
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003213 /* end marker */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003214 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCTX_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003215};
3216
3217#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3218
Bram Moolenaar071d4272004-06-13 20:20:40 +00003219static char *(p_ambw_values[]) = {"single", "double", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003220static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003221static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003222static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003223#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003224static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003225#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003226static char *(p_wop_values[]) = {"tagfile", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003227#ifdef FEAT_WAK
3228static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3229#endif
3230static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003231static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3232static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003233static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003234#ifdef FEAT_BROWSE
3235static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3236#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003237static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
Bram Moolenaar57657d82006-04-21 22:12:41 +00003238static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003239static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003240static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", "prompt", "popup", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003241static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003242static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3243#ifdef FEAT_FOLDING
3244static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003245# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003246 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003247# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003248 NULL};
3249static char *(p_fcl_values[]) = {"all", NULL};
3250#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003251#ifdef FEAT_INS_EXPAND
Bram Moolenaar576a4a62019-08-18 15:25:17 +02003252static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "popup", "noinsert", "noselect", NULL};
Bram Moolenaarac3150d2019-07-28 16:36:39 +02003253# ifdef BACKSLASH_IN_FILENAME
3254static char *(p_csl_values[]) = {"slash", "backslash", NULL};
3255# endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003256#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003257#ifdef FEAT_SIGNS
Bram Moolenaar394c5d82019-06-17 21:48:05 +02003258static char *(p_scl_values[]) = {"yes", "no", "auto", "number", NULL};
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003259#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01003260#if defined(MSWIN) && defined(FEAT_TERMINAL)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01003261static char *(p_twt_values[]) = {"winpty", "conpty", "", NULL};
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01003262#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003263
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003264static void set_options_default(int opt_flags);
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003265static void set_string_default_esc(char *name, char_u *val, int escape);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003266static char_u *term_bg_default(void);
Bram Moolenaar916a8182018-11-25 02:18:29 +01003267static void did_set_option(int opt_idx, int opt_flags, int new_value, int value_checked);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003268static char_u *option_expand(int opt_idx, char_u *val);
3269static void didset_options(void);
3270static void didset_options2(void);
3271static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003272#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003273static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003274#else
3275# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3276#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003277static void set_string_option_global(int opt_idx, char_u **varp);
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003278static char *did_set_string_option(int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char *errbuf, int opt_flags, int *value_checked);
3279static char *set_chars_option(char_u **varp);
Bram 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 Moolenaar62a0cb42019-08-18 16:35:23 +02007833 // 'completepopup'
7834 else if (varp == &p_cpp)
7835 {
7836 if (parse_completepopup(NULL) == FAIL)
7837 errmsg = e_invarg;
7838 }
Bram Moolenaar79648732019-07-18 21:43:07 +02007839#endif
7840
Bram Moolenaar071d4272004-06-13 20:20:40 +00007841 /* Options that are a list of flags. */
7842 else
7843 {
7844 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007845 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007846 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007847 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007848 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007849 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007850 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007851 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007852 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007853#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007854 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007855 p = (char_u *)COCU_ALL;
7856#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007857 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007858 {
7859#ifdef FEAT_MOUSE
7860 p = (char_u *)MOUSE_ALL;
7861#else
7862 if (*p_mouse != NUL)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007863 errmsg = N_("E538: No mouse support");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007864#endif
7865 }
7866#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007867 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007868 p = (char_u *)GO_ALL;
7869#endif
7870 if (p != NULL)
7871 {
7872 for (s = *varp; *s; ++s)
7873 if (vim_strchr(p, *s) == NULL)
7874 {
7875 errmsg = illegal_char(errbuf, *s);
7876 break;
7877 }
7878 }
7879 }
7880
7881 /*
7882 * If error detected, restore the previous value.
7883 */
7884 if (errmsg != NULL)
7885 {
7886 if (new_value_alloced)
7887 free_string_option(*varp);
7888 *varp = oldval;
7889 /*
7890 * When resetting some values, need to act on it.
7891 */
7892 if (did_chartab)
7893 (void)init_chartab();
7894 if (varp == &p_hl)
7895 (void)highlight_changed();
7896 }
7897 else
7898 {
7899#ifdef FEAT_EVAL
7900 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02007901 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007902#endif
7903 /*
7904 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007905 * Use "free_oldval", because recursiveness may change the flags under
7906 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007907 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007908 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007909 free_string_option(oldval);
7910 if (new_value_alloced)
7911 options[opt_idx].flags |= P_ALLOCED;
7912 else
7913 options[opt_idx].flags &= ~P_ALLOCED;
7914
7915 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007916 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007917 {
7918 /* global option with local value set to use global value; free
7919 * the local value and make it empty */
7920 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7921 free_string_option(*(char_u **)p);
7922 *(char_u **)p = empty_option;
7923 }
7924
7925 /* May set global value for local option. */
7926 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7927 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007928
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007929 /*
7930 * Trigger the autocommand only after setting the flags.
7931 */
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007932#ifdef FEAT_SYN_HL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007933 /* When 'syntax' is set, load the syntax of that name */
7934 if (varp == &(curbuf->b_p_syn))
7935 {
Bram Moolenaara5616b02018-06-17 19:08:30 +02007936 static int syn_recursive = 0;
7937
7938 ++syn_recursive;
7939 // Only pass TRUE for "force" when the value changed or not used
7940 // recursively, to avoid endless recurrence.
7941 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname,
7942 value_changed || syn_recursive == 1, curbuf);
Bram Moolenaarc7f1e402019-08-03 13:29:46 +02007943 curbuf->b_flags |= BF_SYN_SET;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007944 --syn_recursive;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007945 }
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007946#endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007947 else if (varp == &(curbuf->b_p_ft))
7948 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007949 /* 'filetype' is set, trigger the FileType autocommand.
7950 * Skip this when called from a modeline and the filetype was
Bram Moolenaara5616b02018-06-17 19:08:30 +02007951 * already set to this value. */
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007952 if (!(opt_flags & OPT_MODELINE) || value_changed)
Bram Moolenaar90492982017-06-22 14:16:31 +02007953 {
Bram Moolenaar916a8182018-11-25 02:18:29 +01007954 static int ft_recursive = 0;
7955 int secure_save = secure;
7956
7957 // Reset the secure flag, since the value of 'filetype' has
7958 // been checked to be safe.
7959 secure = 0;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007960
7961 ++ft_recursive;
Bram Moolenaar90492982017-06-22 14:16:31 +02007962 did_filetype = TRUE;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007963 // Only pass TRUE for "force" when the value changed or not
7964 // used recursively, to avoid endless recurrence.
7965 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname,
7966 value_changed || ft_recursive == 1, curbuf);
7967 --ft_recursive;
Bram Moolenaar163095f2017-07-09 15:41:53 +02007968 /* Just in case the old "curbuf" is now invalid. */
7969 if (varp != &(curbuf->b_p_ft))
7970 varp = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007971
7972 secure = secure_save;
Bram Moolenaar90492982017-06-22 14:16:31 +02007973 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007974 }
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007975#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007976 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007977 {
7978 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007979 char_u *q = curwin->w_s->b_p_spl;
7980
7981 /* Skip the first name if it is "cjk". */
7982 if (STRNCMP(q, "cjk,", 4) == 0)
7983 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007984
7985 /*
7986 * Source the spell/LANG.vim in 'runtimepath'.
7987 * They could set 'spellcapcheck' depending on the language.
7988 * Use the first name in 'spelllang' up to '_region' or
7989 * '.encoding'.
7990 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007991 for (p = q; *p != NUL; ++p)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01007992 if (!ASCII_ISALNUM(*p) && *p != '-')
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007993 break;
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007994 if (p > q)
7995 {
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02007996 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
7997 (int)(p - q), q);
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007998 source_runtime(fname, DIP_ALL);
7999 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00008000 }
8001#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008002 }
8003
8004#ifdef FEAT_MOUSE
8005 if (varp == &p_mouse)
8006 {
8007# ifdef FEAT_MOUSE_TTY
8008 if (*p_mouse == NUL)
8009 mch_setmouse(FALSE); /* switch mouse off */
8010 else
8011# endif
8012 setmouse(); /* in case 'mouse' changed */
8013 }
8014#endif
8015
Bram Moolenaar913077c2012-03-28 19:59:04 +02008016 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008017 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008018 curwin->w_set_curswant = TRUE;
8019
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00008020#ifdef FEAT_GUI
8021 /* check redraw when it's not a GUI option or the GUI is active. */
8022 if (!redraw_gui_only || gui.in_use)
8023#endif
8024 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008025
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008026#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
8027 if (did_swaptcap)
8028 {
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008029 set_termname((char_u *)"win32");
8030 init_highlight(TRUE, FALSE);
8031 }
8032#endif
8033
Bram Moolenaar071d4272004-06-13 20:20:40 +00008034 return errmsg;
8035}
8036
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01008037#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02008038/*
8039 * Simple int comparison function for use with qsort()
8040 */
8041 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01008042int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02008043{
8044 return *(const int *)a - *(const int *)b;
8045}
8046
8047/*
8048 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
8049 * Returns error message, NULL if it's OK.
8050 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008051 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008052check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02008053{
8054 char_u *s;
8055 int col;
8056 int count = 0;
8057 int color_cols[256];
8058 int i;
8059 int j = 0;
8060
Bram Moolenaar50f834d2011-09-21 13:40:17 +02008061 if (wp->w_buffer == NULL)
8062 return NULL; /* buffer was closed */
8063
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008064 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02008065 {
8066 if (*s == '-' || *s == '+')
8067 {
8068 /* -N and +N: add to 'textwidth' */
8069 col = (*s == '-') ? -1 : 1;
8070 ++s;
8071 if (!VIM_ISDIGIT(*s))
8072 return e_invarg;
8073 col = col * getdigits(&s);
8074 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008075 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02008076 col += wp->w_buffer->b_p_tw;
8077 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008078 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02008079 }
8080 else if (VIM_ISDIGIT(*s))
8081 col = getdigits(&s);
8082 else
8083 return e_invarg;
8084 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008085skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02008086 if (*s == NUL)
8087 break;
8088 if (*s != ',')
8089 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008090 if (*++s == NUL)
8091 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02008092 }
8093
8094 vim_free(wp->w_p_cc_cols);
8095 if (count == 0)
8096 wp->w_p_cc_cols = NULL;
8097 else
8098 {
Bram Moolenaarc799fe22019-05-28 23:08:19 +02008099 wp->w_p_cc_cols = ALLOC_MULT(int, count + 1);
Bram Moolenaar1a384422010-07-14 19:53:30 +02008100 if (wp->w_p_cc_cols != NULL)
8101 {
8102 /* sort the columns for faster usage on screen redraw inside
8103 * win_line() */
8104 qsort(color_cols, count, sizeof(int), int_cmp);
8105
8106 for (i = 0; i < count; ++i)
8107 /* skip duplicates */
8108 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
8109 wp->w_p_cc_cols[j++] = color_cols[i];
8110 wp->w_p_cc_cols[j] = -1; /* end marker */
8111 }
8112 }
8113
8114 return NULL; /* no error */
8115}
8116#endif
8117
Bram Moolenaar071d4272004-06-13 20:20:40 +00008118/*
8119 * Handle setting 'listchars' or 'fillchars'.
8120 * Returns error message, NULL if it's OK.
8121 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008122 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008123set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008124{
8125 int round, i, len, entries;
8126 char_u *p, *s;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008127 int c1 = 0, c2 = 0, c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008128 struct charstab
8129 {
8130 int *cp;
8131 char *name;
8132 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00008133 static struct charstab filltab[] =
8134 {
8135 {&fill_stl, "stl"},
8136 {&fill_stlnc, "stlnc"},
8137 {&fill_vert, "vert"},
8138 {&fill_fold, "fold"},
8139 {&fill_diff, "diff"},
8140 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00008141 static struct charstab lcstab[] =
8142 {
8143 {&lcs_eol, "eol"},
8144 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008145 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00008146 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02008147 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00008148 {&lcs_tab2, "tab"},
8149 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02008150#ifdef FEAT_CONCEAL
8151 {&lcs_conceal, "conceal"},
8152#else
8153 {NULL, "conceal"},
8154#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008155 };
8156 struct charstab *tab;
8157
Bram Moolenaar071d4272004-06-13 20:20:40 +00008158 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008159 {
8160 tab = lcstab;
8161 entries = sizeof(lcstab) / sizeof(struct charstab);
8162 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008163 else
8164 {
8165 tab = filltab;
8166 entries = sizeof(filltab) / sizeof(struct charstab);
8167 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008168
8169 /* first round: check for valid value, second round: assign values */
8170 for (round = 0; round <= 1; ++round)
8171 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008172 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008173 {
8174 /* After checking that the value is valid: set defaults: space for
8175 * 'fillchars', NUL for 'listchars' */
8176 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008177 if (tab[i].cp != NULL)
8178 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar83a52172019-01-16 22:41:54 +01008179
Bram Moolenaar071d4272004-06-13 20:20:40 +00008180 if (varp == &p_lcs)
Bram Moolenaar83a52172019-01-16 22:41:54 +01008181 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008182 lcs_tab1 = NUL;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008183 lcs_tab3 = NUL;
8184 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008185 else
8186 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008187 }
8188 p = *varp;
8189 while (*p)
8190 {
8191 for (i = 0; i < entries; ++i)
8192 {
8193 len = (int)STRLEN(tab[i].name);
8194 if (STRNCMP(p, tab[i].name, len) == 0
8195 && p[len] == ':'
8196 && p[len + 1] != NUL)
8197 {
Bram Moolenaar2c519cf2019-03-21 21:45:34 +01008198 c2 = c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008199 s = p + len + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008200 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00008201 if (mb_char2cells(c1) > 1)
8202 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008203 if (tab[i].cp == &lcs_tab2)
8204 {
8205 if (*s == NUL)
8206 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008207 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00008208 if (mb_char2cells(c2) > 1)
8209 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008210 if (!(*s == ',' || *s == NUL))
8211 {
Bram Moolenaar83a52172019-01-16 22:41:54 +01008212 c3 = mb_ptr2char_adv(&s);
8213 if (mb_char2cells(c3) > 1)
8214 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008215 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008216 }
Bram Moolenaar83a52172019-01-16 22:41:54 +01008217
Bram Moolenaar071d4272004-06-13 20:20:40 +00008218 if (*s == ',' || *s == NUL)
8219 {
8220 if (round)
8221 {
8222 if (tab[i].cp == &lcs_tab2)
8223 {
8224 lcs_tab1 = c1;
8225 lcs_tab2 = c2;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008226 lcs_tab3 = c3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008227 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008228 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008229 *(tab[i].cp) = c1;
8230
8231 }
8232 p = s;
8233 break;
8234 }
8235 }
8236 }
8237
8238 if (i == entries)
8239 return e_invarg;
8240 if (*p == ',')
8241 ++p;
8242 }
8243 }
8244
8245 return NULL; /* no error */
8246}
8247
8248#ifdef FEAT_STL_OPT
8249/*
8250 * Check validity of options with the 'statusline' format.
8251 * Return error message or NULL.
8252 */
Bram Moolenaar5843f5f2019-08-20 20:13:45 +02008253 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008254check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008255{
8256 int itemcnt = 0;
8257 int groupdepth = 0;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008258 static char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00008259
8260 while (*s && itemcnt < STL_MAX_ITEM)
8261 {
8262 /* Check for valid keys after % sequences */
8263 while (*s && *s != '%')
8264 s++;
8265 if (!*s)
8266 break;
8267 s++;
8268 if (*s != '%' && *s != ')')
8269 ++itemcnt;
8270 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
8271 {
8272 s++;
8273 continue;
8274 }
8275 if (*s == ')')
8276 {
8277 s++;
8278 if (--groupdepth < 0)
8279 break;
8280 continue;
8281 }
8282 if (*s == '-')
8283 s++;
8284 while (VIM_ISDIGIT(*s))
8285 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00008286 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008287 continue;
8288 if (*s == '.')
8289 {
8290 s++;
8291 while (*s && VIM_ISDIGIT(*s))
8292 s++;
8293 }
8294 if (*s == '(')
8295 {
8296 groupdepth++;
8297 continue;
8298 }
8299 if (vim_strchr(STL_ALL, *s) == NULL)
8300 {
8301 return illegal_char(errbuf, *s);
8302 }
8303 if (*s == '{')
8304 {
8305 s++;
8306 while (*s != '}' && *s)
8307 s++;
8308 if (*s != '}')
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008309 return N_("E540: Unclosed expression sequence");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008310 }
8311 }
8312 if (itemcnt >= STL_MAX_ITEM)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008313 return N_("E541: too many items");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008314 if (groupdepth != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008315 return N_("E542: unbalanced groups");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008316 return NULL;
8317}
8318#endif
8319
8320#ifdef FEAT_CLIPBOARD
8321/*
8322 * Extract the items in the 'clipboard' option and set global values.
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008323 * Return an error message or NULL for success.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008324 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008325 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008326check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008327{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008328 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008329 int new_autoselect_star = FALSE;
8330 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008331 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008332 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008333 regprog_T *new_exclude_prog = NULL;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008334 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008335 char_u *p;
8336
8337 for (p = p_cb; *p != NUL; )
8338 {
8339 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
8340 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008341 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008342 p += 7;
8343 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02008344 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008345 && (p[11] == ',' || p[11] == NUL))
8346 {
8347 new_unnamed |= CLIP_UNNAMED_PLUS;
8348 p += 11;
8349 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008350 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008351 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008352 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02008353 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008354 p += 10;
8355 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02008356 else if (STRNCMP(p, "autoselectplus", 14) == 0
8357 && (p[14] == ',' || p[14] == NUL))
8358 {
8359 new_autoselect_plus = TRUE;
8360 p += 14;
8361 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008362 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008363 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008364 {
8365 new_autoselectml = TRUE;
8366 p += 12;
8367 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008368 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
8369 {
8370 new_html = TRUE;
8371 p += 4;
8372 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008373 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
8374 {
8375 p += 8;
8376 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
8377 if (new_exclude_prog == NULL)
8378 errmsg = e_invarg;
8379 break;
8380 }
8381 else
8382 {
8383 errmsg = e_invarg;
8384 break;
8385 }
8386 if (*p == ',')
8387 ++p;
8388 }
8389 if (errmsg == NULL)
8390 {
8391 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008392 clip_autoselect_star = new_autoselect_star;
8393 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008394 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008395 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008396 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008397 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008398#ifdef FEAT_GUI_GTK
8399 if (gui.in_use)
8400 {
8401 gui_gtk_set_selection_targets();
8402 gui_gtk_set_dnd_targets();
8403 }
8404#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008405 }
8406 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008407 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008408
8409 return errmsg;
8410}
8411#endif
8412
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008413#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008414/*
8415 * Handle side effects of setting 'spell'.
8416 * Return an error message or NULL for success.
8417 */
8418 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008419did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008420{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008421 char *errmsg = NULL;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008422 win_T *wp;
8423 int l;
8424
8425 if (is_spellfile)
8426 {
8427 l = (int)STRLEN(curwin->w_s->b_p_spf);
8428 if (l > 0 && (l < 4
8429 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8430 errmsg = e_invarg;
8431 }
8432
8433 if (errmsg == NULL)
8434 {
8435 FOR_ALL_WINDOWS(wp)
8436 if (wp->w_buffer == curbuf && wp->w_p_spell)
8437 {
8438 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008439 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008440 }
8441 }
8442 return errmsg;
8443}
8444
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008445/*
8446 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8447 * Return error message when failed, NULL when OK.
8448 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008449 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008450compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008451{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008452 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008453 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008454
Bram Moolenaar860cae12010-06-05 23:22:07 +02008455 if (*synblock->b_p_spc == NUL)
8456 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008457 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008458 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008459 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008460 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008461 if (re != NULL)
8462 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008463 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008464 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008465 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008466 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008467 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008468 return e_invarg;
8469 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008470 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008471 }
8472
Bram Moolenaar473de612013-06-08 18:19:48 +02008473 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008474 return NULL;
8475}
8476#endif
8477
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008478#if defined(FEAT_EVAL) || defined(PROTO)
8479/*
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008480 * Set the script_ctx for an option, taking care of setting the buffer- or
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008481 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008482 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008483 static void
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008484set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008485{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008486 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8487 int indir = (int)options[opt_idx].indir;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008488 sctx_T new_script_ctx = script_ctx;
8489
8490 new_script_ctx.sc_lnum += sourcing_lnum;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008491
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008492 /* Remember where the option was set. For local options need to do that
8493 * in the buffer or window structure. */
8494 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008495 options[opt_idx].script_ctx = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008496 if (both || (opt_flags & OPT_LOCAL))
8497 {
8498 if (indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008499 curbuf->b_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008500 else if (indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008501 curwin->w_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008502 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008503}
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02008504
8505/*
8506 * Set the script_ctx for a termcap option.
8507 * "name" must be the two character code, e.g. "RV".
8508 * When "name" is NULL use "opt_idx".
8509 */
8510 void
8511set_term_option_sctx_idx(char *name, int opt_idx)
8512{
8513 char_u buf[5];
8514 int idx;
8515
8516 if (name == NULL)
8517 idx = opt_idx;
8518 else
8519 {
8520 buf[0] = 't';
8521 buf[1] = '_';
8522 buf[2] = name[0];
8523 buf[3] = name[1];
8524 buf[4] = 0;
8525 idx = findoption(buf);
8526 }
8527 if (idx >= 0)
8528 set_option_sctx_idx(idx, OPT_GLOBAL, current_sctx);
8529}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008530#endif
8531
Bram Moolenaar071d4272004-06-13 20:20:40 +00008532/*
8533 * Set the value of a boolean option, and take care of side effects.
8534 * Returns NULL for success, or an error message for an error.
8535 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008536 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008537set_bool_option(
8538 int opt_idx, /* index in options[] table */
8539 char_u *varp, /* pointer to the option variable */
8540 int value, /* new value */
8541 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008542{
8543 int old_value = *(int *)varp;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008544#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02008545 int old_global_value = 0;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008546#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008547
Bram Moolenaar071d4272004-06-13 20:20:40 +00008548 /* Disallow changing some options from secure mode */
8549 if ((secure
8550#ifdef HAVE_SANDBOX
8551 || sandbox != 0
8552#endif
8553 ) && (options[opt_idx].flags & P_SECURE))
8554 return e_secure;
8555
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008556#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02008557 // Save the global value before changing anything. This is needed as for
8558 // a global-only option setting the "local value" in fact sets the global
8559 // value (since there is only one value).
8560 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8561 old_global_value = *(int *)get_varp_scope(&(options[opt_idx]),
8562 OPT_GLOBAL);
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008563#endif
Bram Moolenaard7c96872019-06-15 17:12:48 +02008564
Bram Moolenaar071d4272004-06-13 20:20:40 +00008565 *(int *)varp = value; /* set the new value */
8566#ifdef FEAT_EVAL
8567 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008568 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008569#endif
8570
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008571#ifdef FEAT_GUI
8572 need_mouse_correct = TRUE;
8573#endif
8574
Bram Moolenaar071d4272004-06-13 20:20:40 +00008575 /* May set global value for local option. */
8576 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8577 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8578
8579 /*
8580 * Handle side effects of changing a bool option.
8581 */
8582
8583 /* 'compatible' */
8584 if ((int *)varp == &p_cp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008585 compatible_set();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008586
Bram Moolenaar920694c2016-08-21 17:45:02 +02008587#ifdef FEAT_LANGMAP
8588 if ((int *)varp == &p_lrm)
8589 /* 'langremap' -> !'langnoremap' */
8590 p_lnr = !p_lrm;
8591 else if ((int *)varp == &p_lnr)
8592 /* 'langnoremap' -> !'langremap' */
8593 p_lrm = !p_lnr;
8594#endif
8595
Bram Moolenaar8c63e0e2018-09-25 22:17:54 +02008596#ifdef FEAT_SYN_HL
8597 else if ((int *)varp == &curwin->w_p_cul && !value && old_value)
8598 reset_cursorline();
8599#endif
8600
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008601#ifdef FEAT_PERSISTENT_UNDO
8602 /* 'undofile' */
8603 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8604 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008605 /* Only take action when the option was set. When reset we do not
8606 * delete the undo file, the option may be set again without making
8607 * any changes in between. */
8608 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008609 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008610 char_u hash[UNDO_HASH_SIZE];
8611 buf_T *save_curbuf = curbuf;
8612
Bram Moolenaar29323592016-07-24 22:04:11 +02008613 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008614 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008615 /* When 'undofile' is set globally: for every buffer, otherwise
8616 * only for the current buffer: Try to read in the undofile,
8617 * if one exists, the buffer wasn't changed and the buffer was
8618 * loaded */
8619 if ((curbuf == save_curbuf
8620 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8621 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8622 {
8623 u_compute_hash(hash);
8624 u_read_undo(NULL, hash, curbuf->b_fname);
8625 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008626 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008627 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008628 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008629 }
8630#endif
8631
Bram Moolenaar071d4272004-06-13 20:20:40 +00008632 else if ((int *)varp == &curbuf->b_p_ro)
8633 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008634 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008635 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8636 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008637
8638 /* when 'readonly' is set may give W10 again */
8639 if (curbuf->b_p_ro)
8640 curbuf->b_did_warn = FALSE;
8641
Bram Moolenaar071d4272004-06-13 20:20:40 +00008642#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008643 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008644#endif
8645 }
8646
Bram Moolenaar9c449722010-07-20 18:44:27 +02008647#ifdef FEAT_GUI
8648 else if ((int *)varp == &p_mh)
8649 {
8650 if (!p_mh)
8651 gui_mch_mousehide(FALSE);
8652 }
8653#endif
8654
Bram Moolenaara539df02010-08-01 14:35:05 +02008655 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008656 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008657 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008658# ifdef FEAT_TERMINAL
8659 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaard7db27b2018-03-07 23:02:33 +01008660 if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf)
8661 && curbuf->b_term != NULL && !term_is_finished(curbuf))))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008662 {
8663 curbuf->b_p_ma = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008664 return N_("E946: Cannot make a terminal with running job modifiable");
Bram Moolenaar423802d2017-07-30 16:52:24 +02008665 }
8666# endif
8667# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008668 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008669# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008670 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008671#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008672 /* when 'endofline' is changed, redraw the window title */
8673 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008674 {
8675 redraw_titles();
8676 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008677 /* when 'fixeol' is changed, redraw the window title */
8678 else if ((int *)varp == &curbuf->b_p_fixeol)
8679 {
8680 redraw_titles();
8681 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008682 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008683 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008684 {
8685 redraw_titles();
8686 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008687#endif
8688
8689 /* when 'bin' is set also set some other options */
8690 else if ((int *)varp == &curbuf->b_p_bin)
8691 {
8692 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8693#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008694 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008695#endif
8696 }
8697
Bram Moolenaar071d4272004-06-13 20:20:40 +00008698 /* when 'buflisted' changes, trigger autocommands */
8699 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8700 {
8701 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8702 NULL, NULL, TRUE, curbuf);
8703 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008704
8705 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8706 else if ((int *)varp == &curbuf->b_p_swf)
8707 {
8708 if (curbuf->b_p_swf && p_uc)
8709 ml_open_file(curbuf); /* create the swap file */
8710 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008711 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8712 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008713 mf_close_file(curbuf, TRUE); /* remove the swap file */
8714 }
8715
8716 /* when 'terse' is set change 'shortmess' */
8717 else if ((int *)varp == &p_terse)
8718 {
8719 char_u *p;
8720
8721 p = vim_strchr(p_shm, SHM_SEARCH);
8722
8723 /* insert 's' in p_shm */
8724 if (p_terse && p == NULL)
8725 {
8726 STRCPY(IObuff, p_shm);
8727 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008728 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008729 }
8730 /* remove 's' from p_shm */
8731 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008732 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008733 }
8734
8735 /* when 'paste' is set or reset also change other options */
8736 else if ((int *)varp == &p_paste)
8737 {
8738 paste_option_changed();
8739 }
8740
8741 /* when 'insertmode' is set from an autocommand need to do work here */
8742 else if ((int *)varp == &p_im)
8743 {
8744 if (p_im)
8745 {
8746 if ((State & INSERT) == 0)
8747 need_start_insertmode = TRUE;
8748 stop_insert_mode = FALSE;
8749 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008750 /* only reset if it was set previously */
8751 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008752 {
8753 need_start_insertmode = FALSE;
8754 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008755 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008756 clear_cmdline = TRUE; /* remove "(insert)" */
8757 restart_edit = 0;
8758 }
8759 }
8760
8761 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8762 else if ((int *)varp == &p_ic && p_hls)
8763 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008764 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008765 }
8766
8767#ifdef FEAT_SEARCH_EXTRA
8768 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8769 else if ((int *)varp == &p_hls)
8770 {
Bram Moolenaar451fc7b2018-04-27 22:53:07 +02008771 set_no_hlsearch(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008772 }
8773#endif
8774
Bram Moolenaar071d4272004-06-13 20:20:40 +00008775 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8776 * at the end of normal_cmd() */
8777 else if ((int *)varp == &curwin->w_p_scb)
8778 {
8779 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008780 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008781 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008782 curwin->w_scbind_pos = curwin->w_topline;
8783 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008784 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008785
Bram Moolenaar4033c552017-09-16 20:54:51 +02008786#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008787 /* There can be only one window with 'previewwindow' set. */
8788 else if ((int *)varp == &curwin->w_p_pvw)
8789 {
8790 if (curwin->w_p_pvw)
8791 {
8792 win_T *win;
8793
Bram Moolenaar29323592016-07-24 22:04:11 +02008794 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008795 if (win->w_p_pvw && win != curwin)
8796 {
8797 curwin->w_p_pvw = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008798 return N_("E590: A preview window already exists");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008799 }
8800 }
8801 }
8802#endif
8803
8804 /* when 'textmode' is set or reset also change 'fileformat' */
8805 else if ((int *)varp == &curbuf->b_p_tx)
8806 {
8807 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8808 }
8809
8810 /* when 'textauto' is set or reset also change 'fileformats' */
8811 else if ((int *)varp == &p_ta)
Bram Moolenaarabab0b02019-03-30 18:47:01 +01008812 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008813 set_string_option_direct((char_u *)"ffs", -1,
8814 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008815 OPT_FREE | opt_flags, 0);
Bram Moolenaarabab0b02019-03-30 18:47:01 +01008816 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008817
8818 /*
8819 * When 'lisp' option changes include/exclude '-' in
8820 * keyword characters.
8821 */
8822#ifdef FEAT_LISP
8823 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8824 {
8825 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8826 }
8827#endif
8828
8829#ifdef FEAT_TITLE
8830 /* when 'title' changed, may need to change the title; same for 'icon' */
Bram Moolenaar84a93082018-06-16 22:58:15 +02008831 else if ((int *)varp == &p_title || (int *)varp == &p_icon)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008832 {
Bram Moolenaar84a93082018-06-16 22:58:15 +02008833 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008834 }
8835#endif
8836
8837 else if ((int *)varp == &curbuf->b_changed)
8838 {
8839 if (!value)
8840 save_file_ff(curbuf); /* Buffer is unchanged */
8841#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008842 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008843#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008844 modified_was_set = value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008845 }
8846
8847#ifdef BACKSLASH_IN_FILENAME
8848 else if ((int *)varp == &p_ssl)
8849 {
8850 if (p_ssl)
8851 {
8852 psepc = '/';
8853 psepcN = '\\';
8854 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008855 }
8856 else
8857 {
8858 psepc = '\\';
8859 psepcN = '/';
8860 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008861 }
8862
8863 /* need to adjust the file name arguments and buffer names. */
8864 buflist_slash_adjust();
8865 alist_slash_adjust();
8866# ifdef FEAT_EVAL
8867 scriptnames_slash_adjust();
8868# endif
8869 }
8870#endif
8871
8872 /* If 'wrap' is set, set w_leftcol to zero. */
8873 else if ((int *)varp == &curwin->w_p_wrap)
8874 {
8875 if (curwin->w_p_wrap)
8876 curwin->w_leftcol = 0;
8877 }
8878
Bram Moolenaar071d4272004-06-13 20:20:40 +00008879 else if ((int *)varp == &p_ea)
8880 {
8881 if (p_ea && !old_value)
8882 win_equal(curwin, FALSE, 0);
8883 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008884
8885 else if ((int *)varp == &p_wiv)
8886 {
8887 /*
8888 * When 'weirdinvert' changed, set/reset 't_xs'.
8889 * Then set 'weirdinvert' according to value of 't_xs'.
8890 */
8891 if (p_wiv && !old_value)
8892 T_XS = (char_u *)"y";
8893 else if (!p_wiv && old_value)
8894 T_XS = empty_option;
8895 p_wiv = (*T_XS != NUL);
8896 }
8897
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008898#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008899 else if ((int *)varp == &p_beval)
8900 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008901 if (!balloonEvalForTerm)
8902 {
8903 if (p_beval && !old_value)
8904 gui_mch_enable_beval_area(balloonEval);
8905 else if (!p_beval && old_value)
8906 gui_mch_disable_beval_area(balloonEval);
8907 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008908 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008909#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008910#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008911 else if ((int *)varp == &p_bevalterm)
8912 {
8913 mch_bevalterm_changed();
8914 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008915#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008916
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008917#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008918 else if ((int *)varp == &p_acd)
8919 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008920 /* Change directories when the 'acd' option is set now. */
Bram Moolenaar6f470022018-04-10 18:47:20 +02008921 DO_AUTOCHDIR;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008922 }
8923#endif
8924
8925#ifdef FEAT_DIFF
8926 /* 'diff' */
8927 else if ((int *)varp == &curwin->w_p_diff)
8928 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008929 /* May add or remove the buffer from the list of diff buffers. */
8930 diff_buf_adjust(curwin);
8931# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008932 if (foldmethodIsDiff(curwin))
8933 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008934# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008935 }
8936#endif
8937
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008938#ifdef HAVE_INPUT_METHOD
Bram Moolenaar071d4272004-06-13 20:20:40 +00008939 /* 'imdisable' */
8940 else if ((int *)varp == &p_imdisable)
8941 {
8942 /* Only de-activate it here, it will be enabled when changing mode. */
8943 if (p_imdisable)
8944 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008945 else if (State & INSERT)
8946 /* When the option is set from an autocommand, it may need to take
8947 * effect right away. */
8948 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008949 }
8950#endif
8951
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008952#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008953 /* 'spell' */
8954 else if ((int *)varp == &curwin->w_p_spell)
8955 {
8956 if (curwin->w_p_spell)
8957 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008958 char *errmsg = did_set_spelllang(curwin);
8959
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008960 if (errmsg != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008961 emsg(_(errmsg));
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008962 }
8963 }
8964#endif
8965
Bram Moolenaar071d4272004-06-13 20:20:40 +00008966#ifdef FEAT_ARABIC
8967 if ((int *)varp == &curwin->w_p_arab)
8968 {
8969 if (curwin->w_p_arab)
8970 {
8971 /*
8972 * 'arabic' is set, handle various sub-settings.
8973 */
8974 if (!p_tbidi)
8975 {
8976 /* set rightleft mode */
8977 if (!curwin->w_p_rl)
8978 {
8979 curwin->w_p_rl = TRUE;
8980 changed_window_setting();
8981 }
8982
8983 /* Enable Arabic shaping (major part of what Arabic requires) */
8984 if (!p_arshape)
8985 {
8986 p_arshape = TRUE;
8987 redraw_later_clear();
8988 }
8989 }
8990
8991 /* Arabic requires a utf-8 encoding, inform the user if its not
8992 * set. */
8993 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008994 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008995 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8996
Bram Moolenaar8820b482017-03-16 17:23:31 +01008997 msg_source(HL_ATTR(HLF_W));
Bram Moolenaar32526b32019-01-19 17:43:09 +01008998 msg_attr(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008999#ifdef FEAT_EVAL
9000 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
9001#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009002 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009003
Bram Moolenaar071d4272004-06-13 20:20:40 +00009004 /* set 'delcombine' */
9005 p_deco = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009006
9007# ifdef FEAT_KEYMAP
9008 /* Force-set the necessary keymap for arabic */
9009 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
9010 OPT_LOCAL);
9011# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009012 }
9013 else
9014 {
9015 /*
9016 * 'arabic' is reset, handle various sub-settings.
9017 */
9018 if (!p_tbidi)
9019 {
9020 /* reset rightleft mode */
9021 if (curwin->w_p_rl)
9022 {
9023 curwin->w_p_rl = FALSE;
9024 changed_window_setting();
9025 }
9026
9027 /* 'arabicshape' isn't reset, it is a global option and
9028 * another window may still need it "on". */
9029 }
9030
9031 /* 'delcombine' isn't reset, it is a global option and another
9032 * window may still want it "on". */
9033
9034# ifdef FEAT_KEYMAP
9035 /* Revert to the default keymap */
9036 curbuf->b_p_iminsert = B_IMODE_NONE;
9037 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
9038# endif
9039 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00009040 }
9041
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00009042#endif
9043
Bram Moolenaar61be73b2016-04-29 22:59:22 +02009044#ifdef FEAT_TERMGUICOLORS
9045 /* 'termguicolors' */
9046 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02009047 {
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009048# ifdef FEAT_VTP
9049 /* Do not turn on 'tgc' when 24-bit colors are not supported. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02009050 if (
9051# ifdef VIMDLL
9052 !gui.in_use && !gui.starting &&
9053# endif
9054 !has_vtp_working())
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009055 {
9056 p_tgc = 0;
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01009057 return N_("E954: 24-bit colors are not supported on this environment");
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009058 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02009059 if (is_term_win32())
9060 swap_tcap();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009061# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02009062# ifdef FEAT_GUI
9063 if (!gui.in_use && !gui.starting)
9064# endif
9065 highlight_gui_started();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009066# ifdef FEAT_VTP
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009067 /* reset t_Co */
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02009068 if (is_term_win32())
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02009069 {
9070 control_console_color_rgb();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009071 set_termname(T_NAME);
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02009072 init_highlight(TRUE, FALSE);
9073 }
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009074# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02009075 }
9076#endif
9077
Bram Moolenaar071d4272004-06-13 20:20:40 +00009078 /*
9079 * End of handling side effects for bool options.
9080 */
9081
Bram Moolenaar53744302015-07-17 17:38:22 +02009082 /* after handling side effects, call autocommand */
9083
Bram Moolenaar071d4272004-06-13 20:20:40 +00009084 options[opt_idx].flags |= P_WAS_SET;
9085
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009086#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009087 // Don't do this while starting up or recursively.
9088 if (!starting && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009089 {
Bram Moolenaard7c96872019-06-15 17:12:48 +02009090 char_u buf_old[2], buf_old_global[2], buf_new[2], buf_type[7];
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009091
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009092 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009093 vim_snprintf((char *)buf_old_global, 2, "%d",
9094 old_global_value ? TRUE: FALSE);
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009095 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009096 vim_snprintf((char *)buf_type, 7, "%s",
9097 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009098 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9099 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9100 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009101 if (opt_flags & OPT_LOCAL)
9102 {
9103 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
9104 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9105 }
9106 if (opt_flags & OPT_GLOBAL)
9107 {
9108 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
9109 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old, -1);
9110 }
9111 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9112 {
9113 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
9114 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9115 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old_global, -1);
9116 }
9117 if (opt_flags & OPT_MODELINE)
9118 {
9119 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
9120 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9121 }
9122 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname,
9123 NULL, FALSE, NULL);
Bram Moolenaar53744302015-07-17 17:38:22 +02009124 reset_v_option_vars();
9125 }
9126#endif
9127
Bram Moolenaar071d4272004-06-13 20:20:40 +00009128 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009129 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009130 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009131 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009132 check_redraw(options[opt_idx].flags);
9133
9134 return NULL;
9135}
9136
9137/*
9138 * Set the value of a number option, and take care of side effects.
9139 * Returns NULL for success, or an error message for an error.
9140 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009141 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009142set_num_option(
9143 int opt_idx, /* index in options[] table */
9144 char_u *varp, /* pointer to the option variable */
9145 long value, /* new value */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009146 char *errbuf, /* buffer for error messages */
Bram Moolenaar9b578142016-01-30 19:39:49 +01009147 size_t errbuflen, /* length of "errbuf" */
9148 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00009149 OPT_MODELINE */
9150{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009151 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009152 long old_value = *(long *)varp;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02009153#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02009154 long old_global_value = 0; // only used when setting a local and
9155 // global option
Bram Moolenaar983f2f12019-06-16 16:41:41 +02009156#endif
Bram Moolenaard7c96872019-06-15 17:12:48 +02009157 long old_Rows = Rows; // remember old Rows
9158 long old_Columns = Columns; // remember old Columns
Bram Moolenaar071d4272004-06-13 20:20:40 +00009159 long *pp = (long *)varp;
9160
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009161 /* Disallow changing some options from secure mode. */
9162 if ((secure
9163#ifdef HAVE_SANDBOX
9164 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00009165#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009166 ) && (options[opt_idx].flags & P_SECURE))
9167 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009168
Bram Moolenaar983f2f12019-06-16 16:41:41 +02009169#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02009170 // Save the global value before changing anything. This is needed as for
9171 // a global-only option setting the "local value" infact sets the global
9172 // value (since there is only one value).
9173 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
Bram Moolenaar983f2f12019-06-16 16:41:41 +02009174 old_global_value = *(long *)get_varp_scope(&(options[opt_idx]),
9175 OPT_GLOBAL);
9176#endif
Bram Moolenaard7c96872019-06-15 17:12:48 +02009177
Bram Moolenaar071d4272004-06-13 20:20:40 +00009178 *pp = value;
9179#ifdef FEAT_EVAL
9180 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02009181 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009182#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009183#ifdef FEAT_GUI
9184 need_mouse_correct = TRUE;
9185#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009186
Bram Moolenaar14f24742012-08-08 18:01:05 +02009187 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009188 {
9189 errmsg = e_positive;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02009190#ifdef FEAT_VARTABS
9191 // Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use.
9192 curbuf->b_p_sw = tabstop_count(curbuf->b_p_vts_array) > 0
9193 ? tabstop_first(curbuf->b_p_vts_array)
9194 : curbuf->b_p_ts;
9195#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00009196 curbuf->b_p_sw = curbuf->b_p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02009197#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009198 }
9199
9200 /*
9201 * Number options that need some action when changed
9202 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009203 if (pp == &p_wh || pp == &p_hh)
9204 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009205 // 'winheight' and 'helpheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009206 if (p_wh < 1)
9207 {
9208 errmsg = e_positive;
9209 p_wh = 1;
9210 }
9211 if (p_wmh > p_wh)
9212 {
9213 errmsg = e_winheight;
9214 p_wh = p_wmh;
9215 }
9216 if (p_hh < 0)
9217 {
9218 errmsg = e_positive;
9219 p_hh = 0;
9220 }
9221
9222 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01009223 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009224 {
9225 if (pp == &p_wh && curwin->w_height < p_wh)
9226 win_setheight((int)p_wh);
9227 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
9228 win_setheight((int)p_hh);
9229 }
9230 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009231 else if (pp == &p_wmh)
9232 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009233 // 'winminheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009234 if (p_wmh < 0)
9235 {
9236 errmsg = e_positive;
9237 p_wmh = 0;
9238 }
9239 if (p_wmh > p_wh)
9240 {
9241 errmsg = e_winheight;
9242 p_wmh = p_wh;
9243 }
9244 win_setminheight();
9245 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009246 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009247 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009248 // 'winwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009249 if (p_wiw < 1)
9250 {
9251 errmsg = e_positive;
9252 p_wiw = 1;
9253 }
9254 if (p_wmw > p_wiw)
9255 {
9256 errmsg = e_winwidth;
9257 p_wiw = p_wmw;
9258 }
9259
9260 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01009261 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009262 win_setwidth((int)p_wiw);
9263 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009264 else if (pp == &p_wmw)
9265 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009266 // 'winminwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009267 if (p_wmw < 0)
9268 {
9269 errmsg = e_positive;
9270 p_wmw = 0;
9271 }
9272 if (p_wmw > p_wiw)
9273 {
9274 errmsg = e_winwidth;
9275 p_wmw = p_wiw;
9276 }
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009277 win_setminwidth();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009278 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009279
Bram Moolenaar071d4272004-06-13 20:20:40 +00009280 /* (re)set last window status line */
9281 else if (pp == &p_ls)
9282 {
9283 last_status(FALSE);
9284 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009285
9286 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00009287 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009288 {
9289 shell_new_rows(); /* recompute window positions and heights */
9290 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009291
9292#ifdef FEAT_GUI
9293 else if (pp == &p_linespace)
9294 {
Bram Moolenaar02743632005-07-25 20:42:36 +00009295 /* Recompute gui.char_height and resize the Vim window to keep the
9296 * same number of lines. */
9297 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00009298 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009299 }
9300#endif
9301
9302#ifdef FEAT_FOLDING
9303 /* 'foldlevel' */
9304 else if (pp == &curwin->w_p_fdl)
9305 {
9306 if (curwin->w_p_fdl < 0)
9307 curwin->w_p_fdl = 0;
9308 newFoldLevel();
9309 }
9310
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00009311 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009312 else if (pp == &curwin->w_p_fml)
9313 {
9314 foldUpdateAll(curwin);
9315 }
9316
9317 /* 'foldnestmax' */
9318 else if (pp == &curwin->w_p_fdn)
9319 {
9320 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
9321 foldUpdateAll(curwin);
9322 }
9323
9324 /* 'foldcolumn' */
9325 else if (pp == &curwin->w_p_fdc)
9326 {
9327 if (curwin->w_p_fdc < 0)
9328 {
9329 errmsg = e_positive;
9330 curwin->w_p_fdc = 0;
9331 }
9332 else if (curwin->w_p_fdc > 12)
9333 {
9334 errmsg = e_invarg;
9335 curwin->w_p_fdc = 12;
9336 }
9337 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009338#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009339
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009340#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009341 /* 'shiftwidth' or 'tabstop' */
9342 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
9343 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009344# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00009345 if (foldmethodIsIndent(curwin))
9346 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009347# endif
9348# ifdef FEAT_CINDENT
9349 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
9350 * parse 'cinoptions'. */
9351 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
9352 parse_cino(curbuf);
9353# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009354 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009355#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009356
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009357 /* 'maxcombine' */
9358 else if (pp == &p_mco)
9359 {
9360 if (p_mco > MAX_MCO)
9361 p_mco = MAX_MCO;
9362 else if (p_mco < 0)
9363 p_mco = 0;
9364 screenclear(); /* will re-allocate the screen */
9365 }
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009366
Bram Moolenaar071d4272004-06-13 20:20:40 +00009367 else if (pp == &curbuf->b_p_iminsert)
9368 {
9369 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
9370 {
9371 errmsg = e_invarg;
9372 curbuf->b_p_iminsert = B_IMODE_NONE;
9373 }
9374 p_iminsert = curbuf->b_p_iminsert;
9375 if (termcap_active) /* don't do this in the alternate screen */
9376 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02009377#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009378 /* Show/unshow value of 'keymap' in status lines. */
9379 status_redraw_curbuf();
9380#endif
9381 }
9382
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02009383#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
9384 /* 'imstyle' */
9385 else if (pp == &p_imst)
9386 {
9387 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
9388 errmsg = e_invarg;
9389 }
9390#endif
9391
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009392 else if (pp == &p_window)
9393 {
9394 if (p_window < 1)
9395 p_window = 1;
9396 else if (p_window >= Rows)
9397 p_window = Rows - 1;
9398 }
9399
Bram Moolenaar071d4272004-06-13 20:20:40 +00009400 else if (pp == &curbuf->b_p_imsearch)
9401 {
9402 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
9403 {
9404 errmsg = e_invarg;
9405 curbuf->b_p_imsearch = B_IMODE_NONE;
9406 }
9407 p_imsearch = curbuf->b_p_imsearch;
9408 }
9409
9410#ifdef FEAT_TITLE
9411 /* if 'titlelen' has changed, redraw the title */
9412 else if (pp == &p_titlelen)
9413 {
9414 if (p_titlelen < 0)
9415 {
9416 errmsg = e_positive;
9417 p_titlelen = 85;
9418 }
9419 if (starting != NO_SCREEN && old_value != p_titlelen)
9420 need_maketitle = TRUE;
9421 }
9422#endif
9423
9424 /* if p_ch changed value, change the command line height */
9425 else if (pp == &p_ch)
9426 {
9427 if (p_ch < 1)
9428 {
9429 errmsg = e_positive;
9430 p_ch = 1;
9431 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009432 if (p_ch > Rows - min_rows() + 1)
9433 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009434
9435 /* Only compute the new window layout when startup has been
9436 * completed. Otherwise the frame sizes may be wrong. */
9437 if (p_ch != old_value && full_screen
9438#ifdef FEAT_GUI
9439 && !gui.starting
9440#endif
9441 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009442 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009443 }
9444
9445 /* when 'updatecount' changes from zero to non-zero, open swap files */
9446 else if (pp == &p_uc)
9447 {
9448 if (p_uc < 0)
9449 {
9450 errmsg = e_positive;
9451 p_uc = 100;
9452 }
9453 if (p_uc && !old_value)
9454 ml_open_files();
9455 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009456#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009457 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009458 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009459 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009460 {
9461 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009462 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009463 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009464 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009465 {
9466 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009467 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009468 }
9469 }
9470#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009471#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009472 else if (pp == &p_mzq)
9473 mzvim_reset_timer();
9474#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009475
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009476#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9477 /* 'pyxversion' */
9478 else if (pp == &p_pyx)
9479 {
9480 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9481 errmsg = e_invarg;
9482 }
9483#endif
9484
Bram Moolenaar071d4272004-06-13 20:20:40 +00009485 /* sync undo before 'undolevels' changes */
9486 else if (pp == &p_ul)
9487 {
9488 /* use the old value, otherwise u_sync() may not work properly */
9489 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009490 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009491 p_ul = value;
9492 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009493 else if (pp == &curbuf->b_p_ul)
9494 {
9495 /* use the old value, otherwise u_sync() may not work properly */
9496 curbuf->b_p_ul = old_value;
9497 u_sync(TRUE);
9498 curbuf->b_p_ul = value;
9499 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009500
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009501#ifdef FEAT_LINEBREAK
9502 /* 'numberwidth' must be positive */
9503 else if (pp == &curwin->w_p_nuw)
9504 {
9505 if (curwin->w_p_nuw < 1)
9506 {
9507 errmsg = e_positive;
9508 curwin->w_p_nuw = 1;
9509 }
Bram Moolenaarf8a07122019-07-01 22:06:07 +02009510 if (curwin->w_p_nuw > 20)
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009511 {
9512 errmsg = e_invarg;
Bram Moolenaarf8a07122019-07-01 22:06:07 +02009513 curwin->w_p_nuw = 20;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009514 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009515 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009516 }
9517#endif
9518
Bram Moolenaar1a384422010-07-14 19:53:30 +02009519 else if (pp == &curbuf->b_p_tw)
9520 {
9521 if (curbuf->b_p_tw < 0)
9522 {
9523 errmsg = e_positive;
9524 curbuf->b_p_tw = 0;
9525 }
9526#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009527 {
9528 win_T *wp;
9529 tabpage_T *tp;
9530
9531 FOR_ALL_TAB_WINDOWS(tp, wp)
9532 check_colorcolumn(wp);
9533 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009534#endif
9535 }
9536
Bram Moolenaar071d4272004-06-13 20:20:40 +00009537 /*
9538 * Check the bounds for numeric options here
9539 */
9540 if (Rows < min_rows() && full_screen)
9541 {
9542 if (errbuf != NULL)
9543 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009544 vim_snprintf((char *)errbuf, errbuflen,
9545 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009546 errmsg = errbuf;
9547 }
9548 Rows = min_rows();
9549 }
9550 if (Columns < MIN_COLUMNS && full_screen)
9551 {
9552 if (errbuf != NULL)
9553 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009554 vim_snprintf((char *)errbuf, errbuflen,
9555 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009556 errmsg = errbuf;
9557 }
9558 Columns = MIN_COLUMNS;
9559 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009560 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009561
Bram Moolenaar071d4272004-06-13 20:20:40 +00009562 /*
9563 * If the screen (shell) height has been changed, assume it is the
9564 * physical screenheight.
9565 */
9566 if (old_Rows != Rows || old_Columns != Columns)
9567 {
9568 /* Changing the screen size is not allowed while updating the screen. */
9569 if (updating_screen)
9570 *pp = old_value;
9571 else if (full_screen
9572#ifdef FEAT_GUI
9573 && !gui.starting
9574#endif
9575 )
9576 set_shellsize((int)Columns, (int)Rows, TRUE);
9577 else
9578 {
9579 /* Postpone the resizing; check the size and cmdline position for
9580 * messages. */
9581 check_shellsize();
9582 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9583 cmdline_row = Rows - p_ch;
9584 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009585 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009586 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009587 }
9588
Bram Moolenaar071d4272004-06-13 20:20:40 +00009589 if (curbuf->b_p_ts <= 0)
9590 {
9591 errmsg = e_positive;
9592 curbuf->b_p_ts = 8;
9593 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009594 if (p_tm < 0)
9595 {
9596 errmsg = e_positive;
9597 p_tm = 0;
9598 }
9599 if ((curwin->w_p_scr <= 0
9600 || (curwin->w_p_scr > curwin->w_height
9601 && curwin->w_height > 0))
9602 && full_screen)
9603 {
9604 if (pp == &(curwin->w_p_scr))
9605 {
9606 if (curwin->w_p_scr != 0)
9607 errmsg = e_scroll;
9608 win_comp_scroll(curwin);
9609 }
9610 /* If 'scroll' became invalid because of a side effect silently adjust
9611 * it. */
9612 else if (curwin->w_p_scr <= 0)
9613 curwin->w_p_scr = 1;
9614 else /* curwin->w_p_scr > curwin->w_height */
9615 curwin->w_p_scr = curwin->w_height;
9616 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009617 if (p_hi < 0)
9618 {
9619 errmsg = e_positive;
9620 p_hi = 0;
9621 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009622 else if (p_hi > 10000)
9623 {
9624 errmsg = e_invarg;
9625 p_hi = 10000;
9626 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009627 if (p_re < 0 || p_re > 2)
9628 {
9629 errmsg = e_invarg;
9630 p_re = 0;
9631 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009632 if (p_report < 0)
9633 {
9634 errmsg = e_positive;
9635 p_report = 1;
9636 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009637 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009638 {
9639 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9640 p_sj = Rows / 2;
9641 else
9642 {
9643 errmsg = e_scroll;
9644 p_sj = 1;
9645 }
9646 }
9647 if (p_so < 0 && full_screen)
9648 {
Bram Moolenaar375e3392019-01-31 18:26:10 +01009649 errmsg = e_positive;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009650 p_so = 0;
9651 }
9652 if (p_siso < 0 && full_screen)
9653 {
9654 errmsg = e_positive;
9655 p_siso = 0;
9656 }
9657#ifdef FEAT_CMDWIN
9658 if (p_cwh < 1)
9659 {
9660 errmsg = e_positive;
9661 p_cwh = 1;
9662 }
9663#endif
9664 if (p_ut < 0)
9665 {
9666 errmsg = e_positive;
9667 p_ut = 2000;
9668 }
9669 if (p_ss < 0)
9670 {
9671 errmsg = e_positive;
9672 p_ss = 0;
9673 }
9674
9675 /* May set global value for local option. */
9676 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9677 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9678
9679 options[opt_idx].flags |= P_WAS_SET;
9680
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009681#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009682 // Don't do this while starting up, failure or recursively.
9683 if (!starting && errmsg == NULL && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009684 {
Bram Moolenaard7c96872019-06-15 17:12:48 +02009685 char_u buf_old[11], buf_old_global[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009686 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009687 vim_snprintf((char *)buf_old_global, 10, "%ld", old_global_value);
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009688 vim_snprintf((char *)buf_new, 10, "%ld", value);
9689 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009690 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9691 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9692 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009693 if (opt_flags & OPT_LOCAL)
9694 {
9695 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
9696 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9697 }
9698 if (opt_flags & OPT_GLOBAL)
9699 {
9700 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
9701 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old, -1);
9702 }
9703 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9704 {
9705 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
9706 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9707 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old_global, -1);
9708 }
9709 if (opt_flags & OPT_MODELINE)
9710 {
9711 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
9712 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9713 }
9714 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname,
9715 NULL, FALSE, NULL);
Bram Moolenaar53744302015-07-17 17:38:22 +02009716 reset_v_option_vars();
9717 }
9718#endif
9719
Bram Moolenaar071d4272004-06-13 20:20:40 +00009720 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009721 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009722 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009723 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009724 check_redraw(options[opt_idx].flags);
9725
9726 return errmsg;
9727}
9728
9729/*
9730 * Called after an option changed: check if something needs to be redrawn.
9731 */
9732 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009733check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009734{
9735 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009736 int doclear = (flags & P_RCLR) == P_RCLR;
9737 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009738
Bram Moolenaar071d4272004-06-13 20:20:40 +00009739 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9740 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009741
9742 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9743 changed_window_setting();
9744 if (flags & P_RBUF)
9745 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009746 if (flags & P_RWINONLY)
9747 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009748 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009749 redraw_all_later(CLEAR);
9750 else if (all)
9751 redraw_all_later(NOT_VALID);
9752}
9753
9754/*
9755 * Find index for option 'arg'.
9756 * Return -1 if not found.
9757 */
9758 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009759findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009760{
9761 int opt_idx;
9762 char *s, *p;
9763 static short quick_tab[27] = {0, 0}; /* quick access table */
9764 int is_term_opt;
9765
9766 /*
9767 * For first call: Initialize the quick-access table.
9768 * It contains the index for the first option that starts with a certain
9769 * letter. There are 26 letters, plus the first "t_" option.
9770 */
9771 if (quick_tab[1] == 0)
9772 {
9773 p = options[0].fullname;
9774 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9775 {
9776 if (s[0] != p[0])
9777 {
9778 if (s[0] == 't' && s[1] == '_')
9779 quick_tab[26] = opt_idx;
9780 else
9781 quick_tab[CharOrdLow(s[0])] = opt_idx;
9782 }
9783 p = s;
9784 }
9785 }
9786
9787 /*
9788 * Check for name starting with an illegal character.
9789 */
9790#ifdef EBCDIC
9791 if (!islower(arg[0]))
9792#else
9793 if (arg[0] < 'a' || arg[0] > 'z')
9794#endif
9795 return -1;
9796
9797 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9798 if (is_term_opt)
9799 opt_idx = quick_tab[26];
9800 else
9801 opt_idx = quick_tab[CharOrdLow(arg[0])];
9802 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9803 {
9804 if (STRCMP(arg, s) == 0) /* match full name */
9805 break;
9806 }
9807 if (s == NULL && !is_term_opt)
9808 {
9809 opt_idx = quick_tab[CharOrdLow(arg[0])];
9810 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9811 {
9812 s = options[opt_idx].shortname;
9813 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9814 break;
9815 s = NULL;
9816 }
9817 }
9818 if (s == NULL)
9819 opt_idx = -1;
9820 return opt_idx;
9821}
9822
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009823#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009824/*
9825 * Get the value for an option.
9826 *
9827 * Returns:
9828 * Number or Toggle option: 1, *numval gets value.
9829 * String option: 0, *stringval gets allocated string.
9830 * Hidden Number or Toggle option: -1.
9831 * hidden String option: -2.
9832 * unknown option: -3.
9833 */
9834 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009835get_option_value(
9836 char_u *name,
9837 long *numval,
9838 char_u **stringval, /* NULL when only checking existence */
9839 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009840{
9841 int opt_idx;
9842 char_u *varp;
9843
9844 opt_idx = findoption(name);
9845 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009846 {
9847 int key;
9848
9849 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009850 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009851 {
9852 char_u key_name[2];
9853 char_u *p;
9854
9855 if (key < 0)
9856 {
9857 key_name[0] = KEY2TERMCAP0(key);
9858 key_name[1] = KEY2TERMCAP1(key);
9859 }
9860 else
9861 {
9862 key_name[0] = KS_KEY;
9863 key_name[1] = (key & 0xff);
9864 }
9865 p = find_termcode(key_name);
9866 if (p != NULL)
9867 {
9868 if (stringval != NULL)
9869 *stringval = vim_strsave(p);
9870 return 0;
9871 }
9872 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009873 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009874 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009875
9876 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9877
9878 if (options[opt_idx].flags & P_STRING)
9879 {
9880 if (varp == NULL) /* hidden option */
9881 return -2;
9882 if (stringval != NULL)
9883 {
9884#ifdef FEAT_CRYPT
9885 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009886 if ((char_u **)varp == &curbuf->b_p_key
9887 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009888 *stringval = vim_strsave((char_u *)"*****");
9889 else
9890#endif
9891 *stringval = vim_strsave(*(char_u **)(varp));
9892 }
9893 return 0;
9894 }
9895
9896 if (varp == NULL) /* hidden option */
9897 return -1;
9898 if (options[opt_idx].flags & P_NUM)
9899 *numval = *(long *)varp;
9900 else
9901 {
9902 /* Special case: 'modified' is b_changed, but we also want to consider
9903 * it set when 'ff' or 'fenc' changed. */
9904 if ((int *)varp == &curbuf->b_changed)
9905 *numval = curbufIsChanged();
9906 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009907 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009908 }
9909 return 1;
9910}
9911#endif
9912
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009913#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009914/*
9915 * Returns the option attributes and its value. Unlike the above function it
9916 * will return either global value or local value of the option depending on
9917 * what was requested, but it will never return global value if it was
9918 * requested to return local one and vice versa. Neither it will return
9919 * buffer-local value if it was requested to return window-local one.
9920 *
9921 * Pretends that option is absent if it is not present in the requested scope
9922 * (i.e. has no global, window-local or buffer-local value depending on
9923 * opt_type). Uses
9924 *
9925 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009926 * 0 hidden or unknown option, also option that does not have requested
9927 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009928 * see SOPT_* in vim.h for other flags
9929 *
9930 * Possible opt_type values: see SREQ_* in vim.h
9931 */
9932 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009933get_option_value_strict(
9934 char_u *name,
9935 long *numval,
9936 char_u **stringval, /* NULL when only obtaining attributes */
9937 int opt_type,
9938 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009939{
9940 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009941 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009942 struct vimoption *p;
9943 int r = 0;
9944
9945 opt_idx = findoption(name);
9946 if (opt_idx < 0)
9947 return 0;
9948
9949 p = &(options[opt_idx]);
9950
9951 /* Hidden option */
9952 if (p->var == NULL)
9953 return 0;
9954
9955 if (p->flags & P_BOOL)
9956 r |= SOPT_BOOL;
9957 else if (p->flags & P_NUM)
9958 r |= SOPT_NUM;
9959 else if (p->flags & P_STRING)
9960 r |= SOPT_STRING;
9961
9962 if (p->indir == PV_NONE)
9963 {
9964 if (opt_type == SREQ_GLOBAL)
9965 r |= SOPT_GLOBAL;
9966 else
9967 return 0; /* Did not request global-only option */
9968 }
9969 else
9970 {
9971 if (p->indir & PV_BOTH)
9972 r |= SOPT_GLOBAL;
9973 else if (opt_type == SREQ_GLOBAL)
9974 return 0; /* Requested global option */
9975
9976 if (p->indir & PV_WIN)
9977 {
9978 if (opt_type == SREQ_BUF)
9979 return 0; /* Did not request window-local option */
9980 else
9981 r |= SOPT_WIN;
9982 }
9983 else if (p->indir & PV_BUF)
9984 {
9985 if (opt_type == SREQ_WIN)
9986 return 0; /* Did not request buffer-local option */
9987 else
9988 r |= SOPT_BUF;
9989 }
9990 }
9991
9992 if (stringval == NULL)
9993 return r;
9994
9995 if (opt_type == SREQ_GLOBAL)
9996 varp = p->var;
9997 else
9998 {
9999 if (opt_type == SREQ_BUF)
10000 {
10001 /* Special case: 'modified' is b_changed, but we also want to
10002 * consider it set when 'ff' or 'fenc' changed. */
10003 if (p->indir == PV_MOD)
10004 {
Bram Moolenaardefe6422018-06-24 15:14:07 +020010005 *numval = bufIsChanged((buf_T *)from);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010006 varp = NULL;
10007 }
10008#ifdef FEAT_CRYPT
10009 else if (p->indir == PV_KEY)
10010 {
10011 /* never return the value of the crypt key */
10012 *stringval = NULL;
10013 varp = NULL;
10014 }
10015#endif
10016 else
10017 {
Bram Moolenaardefe6422018-06-24 15:14:07 +020010018 buf_T *save_curbuf = curbuf;
10019
10020 // only getting a pointer, no need to use aucmd_prepbuf()
10021 curbuf = (buf_T *)from;
10022 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010023 varp = get_varp(p);
Bram Moolenaardefe6422018-06-24 15:14:07 +020010024 curbuf = save_curbuf;
10025 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010026 }
10027 }
10028 else if (opt_type == SREQ_WIN)
10029 {
Bram Moolenaardefe6422018-06-24 15:14:07 +020010030 win_T *save_curwin = curwin;
10031
10032 curwin = (win_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010033 curbuf = curwin->w_buffer;
10034 varp = get_varp(p);
10035 curwin = save_curwin;
10036 curbuf = curwin->w_buffer;
10037 }
10038 if (varp == p->var)
10039 return (r | SOPT_UNSET);
10040 }
10041
10042 if (varp != NULL)
10043 {
10044 if (p->flags & P_STRING)
10045 *stringval = vim_strsave(*(char_u **)(varp));
10046 else if (p->flags & P_NUM)
10047 *numval = *(long *) varp;
10048 else
10049 *numval = *(int *)varp;
10050 }
10051
10052 return r;
10053}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010054
10055/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010056 * Iterate over options. First argument is a pointer to a pointer to a
10057 * structure inside options[] array, second is option type like in the above
10058 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010059 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010060 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010061 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010062 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010063 * first argument to NULL.
10064 *
10065 * Returns full option name for current option on each call.
10066 */
10067 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010068option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010069{
10070 struct vimoption *ret = NULL;
10071 do
10072 {
10073 if (*option == NULL)
10074 *option = (void *) options;
10075 else if (((struct vimoption *) (*option))->fullname == NULL)
10076 {
10077 *option = NULL;
10078 return NULL;
10079 }
10080 else
10081 *option = (void *) (((struct vimoption *) (*option)) + 1);
10082
10083 ret = ((struct vimoption *) (*option));
10084
10085 /* Hidden option */
10086 if (ret->var == NULL)
10087 {
10088 ret = NULL;
10089 continue;
10090 }
10091
10092 switch (opt_type)
10093 {
10094 case SREQ_GLOBAL:
10095 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
10096 ret = NULL;
10097 break;
10098 case SREQ_BUF:
10099 if (!(ret->indir & PV_BUF))
10100 ret = NULL;
10101 break;
10102 case SREQ_WIN:
10103 if (!(ret->indir & PV_WIN))
10104 ret = NULL;
10105 break;
10106 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +010010107 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010108 return NULL;
10109 }
10110 }
10111 while (ret == NULL);
10112
10113 return (char_u *)ret->fullname;
10114}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010115#endif
10116
Bram Moolenaar071d4272004-06-13 20:20:40 +000010117/*
10118 * Set the value of option "name".
10119 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010120 *
10121 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010122 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010123 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010124set_option_value(
10125 char_u *name,
10126 long number,
10127 char_u *string,
10128 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010129{
10130 int opt_idx;
10131 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +000010132 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010133
10134 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010135 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +010010136 {
10137 int key;
10138
10139 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010140 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +010010141 {
10142 char_u key_name[2];
10143
10144 if (key < 0)
10145 {
10146 key_name[0] = KEY2TERMCAP0(key);
10147 key_name[1] = KEY2TERMCAP1(key);
10148 }
10149 else
10150 {
10151 key_name[0] = KS_KEY;
10152 key_name[1] = (key & 0xff);
10153 }
10154 add_termcode(key_name, string, FALSE);
10155 if (full_screen)
10156 ttest(FALSE);
10157 redraw_all_later(CLEAR);
10158 return NULL;
10159 }
10160
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010161 semsg(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +010010162 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010163 else
10164 {
10165 flags = options[opt_idx].flags;
10166#ifdef HAVE_SANDBOX
10167 /* Disallow changing some options in the sandbox */
10168 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010169 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010170 emsg(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010171 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010172 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010173#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010174 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010175 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010176 else
10177 {
Bram Moolenaarb3163762008-07-08 15:15:08 +000010178 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010179 if (varp != NULL) /* hidden option is not changed */
10180 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010181 if (number == 0 && string != NULL)
10182 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +000010183 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010184
10185 /* Either we are given a string or we are setting option
10186 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +000010187 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010188 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +000010189 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010190 {
10191 /* There's another character after zeros or the string
10192 * is empty. In both cases, we are trying to set a
10193 * num option using a string. */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010194 semsg(_("E521: Number required: &%s = '%s'"),
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010195 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010196 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010197
10198 }
10199 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010200 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010201 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +000010202 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010203 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010204 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010205 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010206 }
10207 }
10208 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010209 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010210}
10211
10212/*
10213 * Get the terminal code for a terminal option.
10214 * Returns NULL when not found.
10215 */
10216 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010217get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010218{
10219 int opt_idx;
10220 char_u *varp;
10221
10222 if (tname[0] != 't' || tname[1] != '_' ||
10223 tname[2] == NUL || tname[3] == NUL)
10224 return NULL;
10225 if ((opt_idx = findoption(tname)) >= 0)
10226 {
10227 varp = get_varp(&(options[opt_idx]));
10228 if (varp != NULL)
10229 varp = *(char_u **)(varp);
10230 return varp;
10231 }
10232 return find_termcode(tname + 2);
10233}
10234
10235 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010236get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010237{
10238 int i;
10239
10240 i = findoption((char_u *)"hl");
10241 if (i >= 0)
10242 return options[i].def_val[VI_DEFAULT];
10243 return (char_u *)NULL;
10244}
10245
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010246 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010247get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010248{
10249 int i;
10250
10251 i = findoption((char_u *)"enc");
10252 if (i >= 0)
10253 return options[i].def_val[VI_DEFAULT];
10254 return (char_u *)NULL;
10255}
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010256
Bram Moolenaar071d4272004-06-13 20:20:40 +000010257/*
10258 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010259 * When "has_lt" is true there is a '<' before "*arg_arg".
10260 * Returns 0 when the key is not recognized.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010261 */
10262 static int
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010263find_key_option(char_u *arg_arg, int has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010264{
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010265 int key = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010266 int modifiers;
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010267 char_u *arg = arg_arg;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010268
10269 /*
10270 * Don't use get_special_key_code() for t_xx, we don't want it to call
10271 * add_termcap_entry().
10272 */
10273 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
10274 key = TERMCAP2KEY(arg[2], arg[3]);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010275 else if (has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010276 {
10277 --arg; /* put arg at the '<' */
10278 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +020010279 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010280 if (modifiers) /* can't handle modifiers here */
10281 key = 0;
10282 }
10283 return key;
10284}
10285
10286/*
10287 * if 'all' == 0: show changed options
10288 * if 'all' == 1: show all normal options
10289 * if 'all' == 2: show all terminal options
10290 */
10291 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010292showoptions(
10293 int all,
10294 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010295{
10296 struct vimoption *p;
10297 int col;
10298 int isterm;
10299 char_u *varp;
10300 struct vimoption **items;
10301 int item_count;
10302 int run;
10303 int row, rows;
10304 int cols;
10305 int i;
10306 int len;
10307
10308#define INC 20
10309#define GAP 3
10310
Bram Moolenaarc799fe22019-05-28 23:08:19 +020010311 items = ALLOC_MULT(struct vimoption *, PARAM_COUNT);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010312 if (items == NULL)
10313 return;
10314
10315 /* Highlight title */
10316 if (all == 2)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010317 msg_puts_title(_("\n--- Terminal codes ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010318 else if (opt_flags & OPT_GLOBAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010319 msg_puts_title(_("\n--- Global option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010320 else if (opt_flags & OPT_LOCAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010321 msg_puts_title(_("\n--- Local option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010322 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010323 msg_puts_title(_("\n--- Options ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010324
10325 /*
10326 * do the loop two times:
10327 * 1. display the short items
10328 * 2. display the long items (only strings and numbers)
10329 */
10330 for (run = 1; run <= 2 && !got_int; ++run)
10331 {
10332 /*
10333 * collect the items in items[]
10334 */
10335 item_count = 0;
10336 for (p = &options[0]; p->fullname != NULL; p++)
10337 {
Bram Moolenaarf86db782018-10-25 13:31:37 +020010338 // apply :filter /pat/
10339 if (message_filtered((char_u *) p->fullname))
10340 continue;
10341
Bram Moolenaar071d4272004-06-13 20:20:40 +000010342 varp = NULL;
10343 isterm = istermoption(p);
10344 if (opt_flags != 0)
10345 {
10346 if (p->indir != PV_NONE && !isterm)
10347 varp = get_varp_scope(p, opt_flags);
10348 }
10349 else
10350 varp = get_varp(p);
10351 if (varp != NULL
10352 && ((all == 2 && isterm)
10353 || (all == 1 && !isterm)
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010354 || (all == 0 && !optval_default(p, varp, p_cp))))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010355 {
10356 if (p->flags & P_BOOL)
10357 len = 1; /* a toggle option fits always */
10358 else
10359 {
10360 option_value2string(p, opt_flags);
10361 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
10362 }
10363 if ((len <= INC - GAP && run == 1) ||
10364 (len > INC - GAP && run == 2))
10365 items[item_count++] = p;
10366 }
10367 }
10368
10369 /*
10370 * display the items
10371 */
10372 if (run == 1)
10373 {
10374 cols = (Columns + GAP - 3) / INC;
10375 if (cols == 0)
10376 cols = 1;
10377 rows = (item_count + cols - 1) / cols;
10378 }
10379 else /* run == 2 */
10380 rows = item_count;
10381 for (row = 0; row < rows && !got_int; ++row)
10382 {
10383 msg_putchar('\n'); /* go to next line */
10384 if (got_int) /* 'q' typed in more */
10385 break;
10386 col = 0;
10387 for (i = row; i < item_count; i += rows)
10388 {
10389 msg_col = col; /* make columns */
10390 showoneopt(items[i], opt_flags);
10391 col += INC;
10392 }
10393 out_flush();
10394 ui_breakcheck();
10395 }
10396 }
10397 vim_free(items);
10398}
10399
10400/*
10401 * Return TRUE if option "p" has its default value.
10402 */
10403 static int
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010404optval_default(struct vimoption *p, char_u *varp, int compatible)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010405{
10406 int dvi;
10407
10408 if (varp == NULL)
10409 return TRUE; /* hidden option is always at default */
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010410 dvi = ((p->flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010411 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010412 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010413 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010414 /* the cast to long is required for Manx C, long_i is
10415 * needed for MSVC */
10416 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010417 /* P_STRING */
10418 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
10419}
10420
10421/*
10422 * showoneopt: show the value of one option
10423 * must not be called with a hidden option!
10424 */
10425 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010426showoneopt(
10427 struct vimoption *p,
10428 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010429{
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010430 char_u *varp;
10431 int save_silent = silent_mode;
10432
10433 silent_mode = FALSE;
10434 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010435
10436 varp = get_varp_scope(p, opt_flags);
10437
10438 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
10439 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
10440 ? !curbufIsChanged() : !*(int *)varp))
Bram Moolenaar32526b32019-01-19 17:43:09 +010010441 msg_puts("no");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010442 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010443 msg_puts("--");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010444 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010445 msg_puts(" ");
10446 msg_puts(p->fullname);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010447 if (!(p->flags & P_BOOL))
10448 {
10449 msg_putchar('=');
10450 /* put value string in NameBuff */
10451 option_value2string(p, opt_flags);
10452 msg_outtrans(NameBuff);
10453 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010454
10455 silent_mode = save_silent;
10456 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010457}
10458
10459/*
10460 * Write modified options as ":set" commands to a file.
10461 *
10462 * There are three values for "opt_flags":
10463 * OPT_GLOBAL: Write global option values and fresh values of
10464 * buffer-local options (used for start of a session
10465 * file).
10466 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10467 * curwin (used for a vimrc file).
10468 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10469 * and local values for window-local options of
10470 * curwin. Local values are also written when at the
10471 * default value, because a modeline or autocommand
10472 * may have set them when doing ":edit file" and the
10473 * user has set them back at the default or fresh
10474 * value.
10475 * When "local_only" is TRUE, don't write fresh
10476 * values, only local values (for ":mkview").
10477 * (fresh value = value used for a new buffer or window for a local option).
10478 *
10479 * Return FAIL on error, OK otherwise.
10480 */
10481 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010482makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010483{
10484 struct vimoption *p;
10485 char_u *varp; /* currently used value */
10486 char_u *varp_fresh; /* local value */
10487 char_u *varp_local = NULL; /* fresh value */
10488 char *cmd;
10489 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010490 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010491
10492 /*
10493 * The options that don't have a default (terminal name, columns, lines)
10494 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010495 * Do the loop over "options[]" twice: once for options with the
10496 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010497 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010498 for (pri = 1; pri >= 0; --pri)
10499 {
10500 for (p = &options[0]; !istermoption(p); p++)
10501 if (!(p->flags & P_NO_MKRC)
10502 && !istermoption(p)
10503 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010504 {
10505 /* skip global option when only doing locals */
10506 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10507 continue;
10508
10509 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10510 * file, they are always buffer-specific. */
10511 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10512 continue;
10513
10514 /* Global values are only written when not at the default value. */
10515 varp = get_varp_scope(p, opt_flags);
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010516 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp, p_cp))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010517 continue;
10518
10519 round = 2;
10520 if (p->indir != PV_NONE)
10521 {
10522 if (p->var == VAR_WIN)
10523 {
10524 /* skip window-local option when only doing globals */
10525 if (!(opt_flags & OPT_LOCAL))
10526 continue;
10527 /* When fresh value of window-local option is not at the
10528 * default, need to write it too. */
10529 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10530 {
10531 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010532 if (!optval_default(p, varp_fresh, p_cp))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010533 {
10534 round = 1;
10535 varp_local = varp;
10536 varp = varp_fresh;
10537 }
10538 }
10539 }
10540 }
10541
10542 /* Round 1: fresh value for window-local options.
10543 * Round 2: other values */
10544 for ( ; round <= 2; varp = varp_local, ++round)
10545 {
10546 if (round == 1 || (opt_flags & OPT_GLOBAL))
10547 cmd = "set";
10548 else
10549 cmd = "setlocal";
10550
10551 if (p->flags & P_BOOL)
10552 {
10553 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10554 return FAIL;
10555 }
10556 else if (p->flags & P_NUM)
10557 {
10558 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10559 return FAIL;
10560 }
10561 else /* P_STRING */
10562 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010563 int do_endif = FALSE;
10564
Bram Moolenaar071d4272004-06-13 20:20:40 +000010565 /* Don't set 'syntax' and 'filetype' again if the value is
10566 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010567 if (
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +010010568#if defined(FEAT_SYN_HL)
10569 p->indir == PV_SYN ||
10570#endif
10571 p->indir == PV_FT)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010572 {
10573 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10574 *(char_u **)(varp)) < 0
10575 || put_eol(fd) < 0)
10576 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010577 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010578 }
10579 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010580 p->flags) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010581 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010582 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010583 {
10584 if (put_line(fd, "endif") == FAIL)
10585 return FAIL;
10586 }
10587 }
10588 }
10589 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010590 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010591 return OK;
10592}
10593
10594#if defined(FEAT_FOLDING) || defined(PROTO)
10595/*
10596 * Generate set commands for the local fold options only. Used when
10597 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10598 */
10599 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010600makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010601{
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010602 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, 0) == FAIL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010603# ifdef FEAT_EVAL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010604 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010605 == FAIL
10606# endif
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010607 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010608 == FAIL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010609 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010610 == FAIL
10611 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10612 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10613 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10614 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10615 )
10616 return FAIL;
10617
10618 return OK;
10619}
10620#endif
10621
10622 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010623put_setstring(
10624 FILE *fd,
10625 char *cmd,
10626 char *name,
10627 char_u **valuep,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010628 long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010629{
10630 char_u *s;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010631 char_u *buf = NULL;
10632 char_u *part = NULL;
10633 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010634
10635 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10636 return FAIL;
10637 if (*valuep != NULL)
10638 {
10639 /* Output 'pastetoggle' as key names. For other
10640 * options some characters have to be escaped with
10641 * CTRL-V or backslash */
10642 if (valuep == &p_pt)
10643 {
10644 s = *valuep;
10645 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010646 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010647 return FAIL;
10648 }
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010649 // expand the option value, replace $HOME by ~
10650 else if ((flags & P_EXPAND) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010651 {
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010652 int size = (int)STRLEN(*valuep) + 1;
10653
10654 // replace home directory in the whole option value into "buf"
10655 buf = alloc(size);
Bram Moolenaarf8441472011-04-28 17:24:58 +020010656 if (buf == NULL)
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010657 goto fail;
10658 home_replace(NULL, *valuep, buf, size, FALSE);
10659
10660 // If the option value is longer than MAXPATHL, we need to append
10661 // earch comma separated part of the option separately, so that it
10662 // can be expanded when read back.
10663 if (size >= MAXPATHL && (flags & P_COMMA) != 0
10664 && vim_strchr(*valuep, ',') != NULL)
10665 {
10666 part = alloc(size);
10667 if (part == NULL)
10668 goto fail;
10669
10670 // write line break to clear the option, e.g. ':set rtp='
10671 if (put_eol(fd) == FAIL)
10672 goto fail;
10673
10674 p = buf;
10675 while (*p != NUL)
10676 {
10677 // for each comma separated option part, append value to
10678 // the option, :set rtp+=value
10679 if (fprintf(fd, "%s %s+=", cmd, name) < 0)
10680 goto fail;
10681 (void)copy_option_part(&p, part, size, ",");
10682 if (put_escstr(fd, part, 2) == FAIL || put_eol(fd) == FAIL)
10683 goto fail;
10684 }
10685 vim_free(buf);
10686 vim_free(part);
10687 return OK;
10688 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010689 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010690 {
10691 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010692 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010693 }
10694 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010695 }
10696 else if (put_escstr(fd, *valuep, 2) == FAIL)
10697 return FAIL;
10698 }
10699 if (put_eol(fd) < 0)
10700 return FAIL;
10701 return OK;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010702fail:
10703 vim_free(buf);
10704 vim_free(part);
10705 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010706}
10707
10708 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010709put_setnum(
10710 FILE *fd,
10711 char *cmd,
10712 char *name,
10713 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010714{
10715 long wc;
10716
10717 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10718 return FAIL;
10719 if (wc_use_keyname((char_u *)valuep, &wc))
10720 {
10721 /* print 'wildchar' and 'wildcharm' as a key name */
10722 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10723 return FAIL;
10724 }
10725 else if (fprintf(fd, "%ld", *valuep) < 0)
10726 return FAIL;
10727 if (put_eol(fd) < 0)
10728 return FAIL;
10729 return OK;
10730}
10731
10732 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010733put_setbool(
10734 FILE *fd,
10735 char *cmd,
10736 char *name,
10737 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010738{
Bram Moolenaar893de922007-10-02 18:40:57 +000010739 if (value < 0) /* global/local option using global value */
10740 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010741 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10742 || put_eol(fd) < 0)
10743 return FAIL;
10744 return OK;
10745}
10746
10747/*
10748 * Clear all the terminal options.
10749 * If the option has been allocated, free the memory.
10750 * Terminal options are never hidden or indirect.
10751 */
10752 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010753clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010754{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010755 /*
10756 * Reset a few things before clearing the old options. This may cause
10757 * outputting a few things that the terminal doesn't understand, but the
10758 * screen will be cleared later, so this is OK.
10759 */
10760#ifdef FEAT_MOUSE_TTY
10761 mch_setmouse(FALSE); /* switch mouse off */
10762#endif
10763#ifdef FEAT_TITLE
Bram Moolenaar40385db2018-08-07 22:31:44 +020010764 mch_restore_title(SAVE_RESTORE_BOTH); /* restore window titles */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010765#endif
10766#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10767 /* When starting the GUI close the display opened for the clipboard.
10768 * After restoring the title, because that will need the display. */
10769 if (gui.starting)
10770 clear_xterm_clip();
10771#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010772 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010773
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010774 free_termoptions();
10775}
10776
10777 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010778free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010779{
10780 struct vimoption *p;
10781
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010782 for (p = options; p->fullname != NULL; p++)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010783 if (istermoption(p))
10784 {
10785 if (p->flags & P_ALLOCED)
10786 free_string_option(*(char_u **)(p->var));
10787 if (p->flags & P_DEF_ALLOCED)
10788 free_string_option(p->def_val[VI_DEFAULT]);
10789 *(char_u **)(p->var) = empty_option;
10790 p->def_val[VI_DEFAULT] = empty_option;
10791 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010792#ifdef FEAT_EVAL
10793 // remember where the option was cleared
10794 set_option_sctx_idx((int)(p - options), OPT_GLOBAL, current_sctx);
10795#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010796 }
10797 clear_termcodes();
10798}
10799
10800/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010801 * Free the string for one term option, if it was allocated.
10802 * Set the string to empty_option and clear allocated flag.
10803 * "var" points to the option value.
10804 */
10805 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010806free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010807{
10808 struct vimoption *p;
10809
10810 for (p = &options[0]; p->fullname != NULL; p++)
10811 if (p->var == var)
10812 {
10813 if (p->flags & P_ALLOCED)
10814 free_string_option(*(char_u **)(p->var));
10815 *(char_u **)(p->var) = empty_option;
10816 p->flags &= ~P_ALLOCED;
10817 break;
10818 }
10819}
10820
10821/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010822 * Set the terminal option defaults to the current value.
10823 * Used after setting the terminal name.
10824 */
10825 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010826set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010827{
10828 struct vimoption *p;
10829
10830 for (p = &options[0]; p->fullname != NULL; p++)
10831 {
10832 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10833 {
10834 if (p->flags & P_DEF_ALLOCED)
10835 {
10836 free_string_option(p->def_val[VI_DEFAULT]);
10837 p->flags &= ~P_DEF_ALLOCED;
10838 }
10839 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10840 if (p->flags & P_ALLOCED)
10841 {
10842 p->flags |= P_DEF_ALLOCED;
10843 p->flags &= ~P_ALLOCED; /* don't free the value now */
10844 }
10845 }
10846 }
10847}
10848
10849/*
10850 * return TRUE if 'p' starts with 't_'
10851 */
10852 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010853istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010854{
10855 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10856}
10857
10858/*
10859 * Compute columns for ruler and shown command. 'sc_col' is also used to
10860 * decide what the maximum length of a message on the status line can be.
10861 * If there is a status line for the last window, 'sc_col' is independent
10862 * of 'ru_col'.
10863 */
10864
10865#define COL_RULER 17 /* columns needed by standard ruler */
10866
10867 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010868comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010869{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010870#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010871 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010872
10873 sc_col = 0;
10874 ru_col = 0;
10875 if (p_ru)
10876 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010877# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010878 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010879# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010880 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010881# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010882 /* no last status line, adjust sc_col */
10883 if (!last_has_status)
10884 sc_col = ru_col;
10885 }
10886 if (p_sc)
10887 {
10888 sc_col += SHOWCMD_COLS;
10889 if (!p_ru || last_has_status) /* no need for separating space */
10890 ++sc_col;
10891 }
10892 sc_col = Columns - sc_col;
10893 ru_col = Columns - ru_col;
10894 if (sc_col <= 0) /* screen too narrow, will become a mess */
10895 sc_col = 1;
10896 if (ru_col <= 0)
10897 ru_col = 1;
10898#else
10899 sc_col = Columns;
10900 ru_col = Columns;
10901#endif
10902}
10903
Bram Moolenaar113e1072019-01-20 15:30:40 +010010904#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010905/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010906 * Unset local option value, similar to ":set opt<".
10907 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010908 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010909unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010910{
10911 struct vimoption *p;
10912 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010913 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010914
10915 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010916 if (opt_idx < 0)
10917 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010918 p = &(options[opt_idx]);
10919
10920 switch ((int)p->indir)
10921 {
10922 /* global option with local value: use local value if it's been set */
10923 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010924 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010925 break;
10926 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010927 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010928 break;
10929 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010930 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010931 break;
10932 case PV_AR:
10933 buf->b_p_ar = -1;
10934 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010935 case PV_BKC:
10936 clear_string_option(&buf->b_p_bkc);
10937 buf->b_bkc_flags = 0;
10938 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010939 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010940 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010941 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010942 case PV_TC:
10943 clear_string_option(&buf->b_p_tc);
10944 buf->b_tc_flags = 0;
10945 break;
Bram Moolenaar375e3392019-01-31 18:26:10 +010010946 case PV_SISO:
10947 curwin->w_p_siso = -1;
10948 break;
10949 case PV_SO:
10950 curwin->w_p_so = -1;
10951 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010952#ifdef FEAT_FIND_ID
10953 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010954 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010955 break;
10956 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010957 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010958 break;
10959#endif
10960#ifdef FEAT_INS_EXPAND
10961 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010962 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010963 break;
10964 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010965 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010966 break;
10967#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010968 case PV_FP:
10969 clear_string_option(&buf->b_p_fp);
10970 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010971#ifdef FEAT_QUICKFIX
10972 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010973 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010974 break;
10975 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010976 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010977 break;
10978 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010979 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010980 break;
10981#endif
10982#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10983 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010984 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010985 break;
10986#endif
10987#if defined(FEAT_CRYPT)
10988 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010989 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010990 break;
10991#endif
10992#ifdef FEAT_STL_OPT
10993 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010994 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010995 break;
10996#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010997 case PV_UL:
10998 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10999 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011000#ifdef FEAT_LISP
11001 case PV_LW:
11002 clear_string_option(&buf->b_p_lw);
11003 break;
11004#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011005 case PV_MENC:
11006 clear_string_option(&buf->b_p_menc);
11007 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020011008 }
11009}
Bram Moolenaar113e1072019-01-20 15:30:40 +010011010#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020011011
11012/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011013 * Get pointer to option variable, depending on local or global scope.
11014 */
11015 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011016get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011017{
11018 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
11019 {
11020 if (p->var == VAR_WIN)
11021 return (char_u *)GLOBAL_WO(get_varp(p));
11022 return p->var;
11023 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000011024 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011025 {
11026 switch ((int)p->indir)
11027 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011028 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011029#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011030 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
11031 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
11032 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011033#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011034 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
11035 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
11036 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000011037 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011038 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011039 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar375e3392019-01-31 18:26:10 +010011040 case PV_SISO: return (char_u *)&(curwin->w_p_siso);
11041 case PV_SO: return (char_u *)&(curwin->w_p_so);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011042#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011043 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
11044 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011045#endif
11046#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011047 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
11048 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011049#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011050#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11051 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
11052#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011053#if defined(FEAT_CRYPT)
11054 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
11055#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011056#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011057 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011058#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011059 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011060#ifdef FEAT_LISP
11061 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
11062#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011063 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011064 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011065 }
11066 return NULL; /* "cannot happen" */
11067 }
11068 return get_varp(p);
11069}
11070
11071/*
11072 * Get pointer to option variable.
11073 */
11074 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011075get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011076{
11077 /* hidden option, always return NULL */
11078 if (p->var == NULL)
11079 return NULL;
11080
11081 switch ((int)p->indir)
11082 {
11083 case PV_NONE: return p->var;
11084
11085 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011086 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011087 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011088 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011089 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011090 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011091 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000011092 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000011093 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011094 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011095 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011096 case PV_TC: return *curbuf->b_p_tc != NUL
11097 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011098 case PV_BKC: return *curbuf->b_p_bkc != NUL
11099 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar375e3392019-01-31 18:26:10 +010011100 case PV_SISO: return curwin->w_p_siso >= 0
11101 ? (char_u *)&(curwin->w_p_siso) : p->var;
11102 case PV_SO: return curwin->w_p_so >= 0
11103 ? (char_u *)&(curwin->w_p_so) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011104#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011105 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011106 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011107 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011108 ? (char_u *)&(curbuf->b_p_inc) : p->var;
11109#endif
11110#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011111 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011112 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011113 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011114 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
11115#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011116 case PV_FP: return *curbuf->b_p_fp != NUL
11117 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011118#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011119 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011120 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011121 case PV_GP: return *curbuf->b_p_gp != NUL
11122 ? (char_u *)&(curbuf->b_p_gp) : p->var;
11123 case PV_MP: return *curbuf->b_p_mp != NUL
11124 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011125#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011126#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11127 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
11128 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
11129#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011130#if defined(FEAT_CRYPT)
11131 case PV_CM: return *curbuf->b_p_cm != NUL
11132 ? (char_u *)&(curbuf->b_p_cm) : p->var;
11133#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011134#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011135 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011136 ? (char_u *)&(curwin->w_p_stl) : p->var;
11137#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011138 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
11139 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011140#ifdef FEAT_LISP
11141 case PV_LW: return *curbuf->b_p_lw != NUL
11142 ? (char_u *)&(curbuf->b_p_lw) : p->var;
11143#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011144 case PV_MENC: return *curbuf->b_p_menc != NUL
11145 ? (char_u *)&(curbuf->b_p_menc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011146#ifdef FEAT_ARABIC
11147 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
11148#endif
11149 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011150#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000011151 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
11152#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011153#ifdef FEAT_SYN_HL
11154 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
11155 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020011156 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011157#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011158#ifdef FEAT_DIFF
11159 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
11160#endif
11161#ifdef FEAT_FOLDING
11162 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
11163 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
11164 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
11165 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
11166 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
11167 case PV_FML: return (char_u *)&(curwin->w_p_fml);
11168 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
11169# ifdef FEAT_EVAL
11170 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
11171 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
11172# endif
11173 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
11174#endif
11175 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020011176 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011177#ifdef FEAT_LINEBREAK
11178 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
11179#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011180 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000011181 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020011182#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011183 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
11184#endif
11185#ifdef FEAT_RIGHTLEFT
11186 case PV_RL: return (char_u *)&(curwin->w_p_rl);
11187 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
11188#endif
11189 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
11190 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
11191#ifdef FEAT_LINEBREAK
11192 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020011193 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
11194 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011195#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011196 case PV_WCR: return (char_u *)&(curwin->w_p_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011197 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011198 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011199#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011200 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
11201 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
11202#endif
11203#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011204 case PV_TWK: return (char_u *)&(curwin->w_p_twk);
11205 case PV_TWS: return (char_u *)&(curwin->w_p_tws);
11206 case PV_TWSL: return (char_u *)&(curbuf->b_p_twsl);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011207#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011208
11209 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
11210 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011211 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011212 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
11213 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011214 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
11215 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
11216#ifdef FEAT_CINDENT
11217 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
11218 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
11219 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
11220#endif
11221#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11222 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
11223#endif
11224#ifdef FEAT_COMMENTS
11225 case PV_COM: return (char_u *)&(curbuf->b_p_com);
11226#endif
11227#ifdef FEAT_FOLDING
11228 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
11229#endif
11230#ifdef FEAT_INS_EXPAND
11231 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
Bram Moolenaarac3150d2019-07-28 16:36:39 +020011232# ifdef BACKSLASH_IN_FILENAME
11233 case PV_CSL: return (char_u *)&(curbuf->b_p_csl);
11234# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011235#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011236#ifdef FEAT_COMPL_FUNC
11237 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011238 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011239#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +020011240#ifdef FEAT_EVAL
11241 case PV_TFU: return (char_u *)&(curbuf->b_p_tfu);
11242#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011243 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020011244 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011245 case PV_ET: return (char_u *)&(curbuf->b_p_et);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011246 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011247 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011248 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011249 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011250 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011251 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
11252 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
11253 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
11254 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
11255#ifdef FEAT_FIND_ID
11256# ifdef FEAT_EVAL
11257 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
11258# endif
11259#endif
11260#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11261 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
11262 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
11263#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011264#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011265 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
11266#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011267#ifdef FEAT_CRYPT
11268 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
11269#endif
11270#ifdef FEAT_LISP
11271 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
11272#endif
11273 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
11274 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
11275 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
11276 case PV_MOD: return (char_u *)&(curbuf->b_changed);
11277 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011278 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011279#ifdef FEAT_TEXTOBJ
11280 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
11281#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011282 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
11283#ifdef FEAT_SMARTINDENT
11284 case PV_SI: return (char_u *)&(curbuf->b_p_si);
11285#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011286 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011287 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
11288#ifdef FEAT_SEARCHPATH
11289 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
11290#endif
11291 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
11292#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011293 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011294 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
11295#endif
11296#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020011297 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
11298 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
11299 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011300#endif
11301 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
11302 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
11303 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
11304 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011305#ifdef FEAT_PERSISTENT_UNDO
11306 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
11307#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011308 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
11309#ifdef FEAT_KEYMAP
11310 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
11311#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011312#ifdef FEAT_SIGNS
11313 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
11314#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011315#ifdef FEAT_VARTABS
11316 case PV_VSTS: return (char_u *)&(curbuf->b_p_vsts);
11317 case PV_VTS: return (char_u *)&(curbuf->b_p_vts);
11318#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010011319 default: iemsg(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011320 }
11321 /* always return a valid pointer to avoid a crash! */
11322 return (char_u *)&(curbuf->b_p_wm);
11323}
11324
11325/*
11326 * Get the value of 'equalprg', either the buffer-local one or the global one.
11327 */
11328 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011329get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011330{
11331 if (*curbuf->b_p_ep == NUL)
11332 return p_ep;
11333 return curbuf->b_p_ep;
11334}
11335
Bram Moolenaar071d4272004-06-13 20:20:40 +000011336/*
11337 * Copy options from one window to another.
11338 * Used when splitting a window.
11339 */
11340 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011341win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011342{
11343 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
11344 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020011345#if defined(FEAT_LINEBREAK)
11346 briopt_check(wp_to);
11347#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011348}
Bram Moolenaar071d4272004-06-13 20:20:40 +000011349
11350/*
11351 * Copy the options from one winopt_T to another.
11352 * Doesn't free the old option values in "to", use clear_winopt() for that.
11353 * The 'scroll' option is not copied, because it depends on the window height.
11354 * The 'previewwindow' option is reset, there can be only one preview window.
11355 */
11356 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011357copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011358{
11359#ifdef FEAT_ARABIC
11360 to->wo_arab = from->wo_arab;
11361#endif
11362 to->wo_list = from->wo_list;
11363 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020011364 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011365#ifdef FEAT_LINEBREAK
11366 to->wo_nuw = from->wo_nuw;
11367#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011368#ifdef FEAT_RIGHTLEFT
11369 to->wo_rl = from->wo_rl;
11370 to->wo_rlc = vim_strsave(from->wo_rlc);
11371#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011372#ifdef FEAT_STL_OPT
11373 to->wo_stl = vim_strsave(from->wo_stl);
11374#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011375 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011376#ifdef FEAT_DIFF
11377 to->wo_wrap_save = from->wo_wrap_save;
11378#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011379#ifdef FEAT_LINEBREAK
11380 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020011381 to->wo_bri = from->wo_bri;
11382 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011383#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011384 to->wo_wcr = vim_strsave(from->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011385 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011386 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010011387 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011388 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011389#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000011390 to->wo_spell = from->wo_spell;
11391#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011392#ifdef FEAT_SYN_HL
11393 to->wo_cuc = from->wo_cuc;
11394 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020011395 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011396#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011397#ifdef FEAT_DIFF
11398 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011399 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011400#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011401#ifdef FEAT_CONCEAL
11402 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020011403 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011404#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011405#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011406 to->wo_twk = vim_strsave(from->wo_twk);
11407 to->wo_tws = vim_strsave(from->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011408#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011409#ifdef FEAT_FOLDING
11410 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011411 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011412 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011413 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011414 to->wo_fdi = vim_strsave(from->wo_fdi);
11415 to->wo_fml = from->wo_fml;
11416 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011417 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011418 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011419 to->wo_fdm_save = from->wo_diff_saved
11420 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011421 to->wo_fdn = from->wo_fdn;
11422# ifdef FEAT_EVAL
11423 to->wo_fde = vim_strsave(from->wo_fde);
11424 to->wo_fdt = vim_strsave(from->wo_fdt);
11425# endif
11426 to->wo_fmr = vim_strsave(from->wo_fmr);
11427#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011428#ifdef FEAT_SIGNS
11429 to->wo_scl = vim_strsave(from->wo_scl);
11430#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011431 check_winopt(to); /* don't want NULL pointers */
11432}
11433
11434/*
11435 * Check string options in a window for a NULL value.
11436 */
Bram Moolenaar5843f5f2019-08-20 20:13:45 +020011437 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011438check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011439{
11440 check_winopt(&win->w_onebuf_opt);
11441 check_winopt(&win->w_allbuf_opt);
11442}
11443
11444/*
11445 * Check for NULL pointers in a winopt_T and replace them with empty_option.
11446 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020011447 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011448check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011449{
11450#ifdef FEAT_FOLDING
11451 check_string_option(&wop->wo_fdi);
11452 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011453 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011454# ifdef FEAT_EVAL
11455 check_string_option(&wop->wo_fde);
11456 check_string_option(&wop->wo_fdt);
11457# endif
11458 check_string_option(&wop->wo_fmr);
11459#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011460#ifdef FEAT_SIGNS
11461 check_string_option(&wop->wo_scl);
11462#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011463#ifdef FEAT_RIGHTLEFT
11464 check_string_option(&wop->wo_rlc);
11465#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011466#ifdef FEAT_STL_OPT
11467 check_string_option(&wop->wo_stl);
11468#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011469#ifdef FEAT_SYN_HL
11470 check_string_option(&wop->wo_cc);
11471#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011472#ifdef FEAT_CONCEAL
11473 check_string_option(&wop->wo_cocu);
11474#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011475#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011476 check_string_option(&wop->wo_twk);
11477 check_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011478#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011479#ifdef FEAT_LINEBREAK
11480 check_string_option(&wop->wo_briopt);
11481#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011482 check_string_option(&wop->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011483}
11484
11485/*
11486 * Free the allocated memory inside a winopt_T.
11487 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011488 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011489clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011490{
11491#ifdef FEAT_FOLDING
11492 clear_string_option(&wop->wo_fdi);
11493 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011494 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011495# ifdef FEAT_EVAL
11496 clear_string_option(&wop->wo_fde);
11497 clear_string_option(&wop->wo_fdt);
11498# endif
11499 clear_string_option(&wop->wo_fmr);
11500#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011501#ifdef FEAT_SIGNS
11502 clear_string_option(&wop->wo_scl);
11503#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011504#ifdef FEAT_LINEBREAK
11505 clear_string_option(&wop->wo_briopt);
11506#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011507 clear_string_option(&wop->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011508#ifdef FEAT_RIGHTLEFT
11509 clear_string_option(&wop->wo_rlc);
11510#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011511#ifdef FEAT_STL_OPT
11512 clear_string_option(&wop->wo_stl);
11513#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011514#ifdef FEAT_SYN_HL
11515 clear_string_option(&wop->wo_cc);
11516#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011517#ifdef FEAT_CONCEAL
11518 clear_string_option(&wop->wo_cocu);
11519#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011520#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011521 clear_string_option(&wop->wo_twk);
11522 clear_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011523#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011524}
11525
11526/*
11527 * Copy global option values to local options for one buffer.
11528 * Used when creating a new buffer and sometimes when entering a buffer.
11529 * flags:
11530 * BCO_ENTER We will enter the buf buffer.
11531 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11532 * appropriate.
11533 * BCO_NOHELP Don't copy the values to a help buffer.
11534 */
11535 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011536buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011537{
11538 int should_copy = TRUE;
11539 char_u *save_p_isk = NULL; /* init for GCC */
11540 int dont_do_help;
11541 int did_isk = FALSE;
11542
11543 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011544 * Skip this when the option defaults have not been set yet. Happens when
11545 * main() allocates the first buffer.
11546 */
11547 if (p_cpo != NULL)
11548 {
11549 /*
11550 * Always copy when entering and 'cpo' contains 'S'.
11551 * Don't copy when already initialized.
11552 * Don't copy when 'cpo' contains 's' and not entering.
11553 * 'S' BCO_ENTER initialized 's' should_copy
11554 * yes yes X X TRUE
11555 * yes no yes X FALSE
11556 * no X yes X FALSE
11557 * X no no yes FALSE
11558 * X no no no TRUE
11559 * no yes no X TRUE
11560 */
11561 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11562 && (buf->b_p_initialized
11563 || (!(flags & BCO_ENTER)
11564 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11565 should_copy = FALSE;
11566
11567 if (should_copy || (flags & BCO_ALWAYS))
11568 {
11569 /* Don't copy the options specific to a help buffer when
11570 * BCO_NOHELP is given or the options were initialized already
11571 * (jumping back to a help file with CTRL-T or CTRL-O) */
11572 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11573 || buf->b_p_initialized;
11574 if (dont_do_help) /* don't free b_p_isk */
11575 {
11576 save_p_isk = buf->b_p_isk;
11577 buf->b_p_isk = NULL;
11578 }
11579 /*
Bram Moolenaar40385db2018-08-07 22:31:44 +020011580 * Always free the allocated strings. If not already initialized,
11581 * reset 'readonly' and copy 'fileformat'.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011582 */
11583 if (!buf->b_p_initialized)
11584 {
11585 free_buf_options(buf, TRUE);
11586 buf->b_p_ro = FALSE; /* don't copy readonly */
11587 buf->b_p_tx = p_tx;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011588 buf->b_p_fenc = vim_strsave(p_fenc);
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011589 switch (*p_ffs)
11590 {
11591 case 'm':
11592 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11593 case 'd':
11594 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11595 case 'u':
11596 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11597 default:
11598 buf->b_p_ff = vim_strsave(p_ff);
11599 }
11600 if (buf->b_p_ff != NULL)
11601 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011602 buf->b_p_bh = empty_option;
11603 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011604 }
11605 else
11606 free_buf_options(buf, FALSE);
11607
11608 buf->b_p_ai = p_ai;
11609 buf->b_p_ai_nopaste = p_ai_nopaste;
11610 buf->b_p_sw = p_sw;
11611 buf->b_p_tw = p_tw;
11612 buf->b_p_tw_nopaste = p_tw_nopaste;
11613 buf->b_p_tw_nobin = p_tw_nobin;
11614 buf->b_p_wm = p_wm;
11615 buf->b_p_wm_nopaste = p_wm_nopaste;
11616 buf->b_p_wm_nobin = p_wm_nobin;
11617 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011618 buf->b_p_bomb = p_bomb;
Bram Moolenaarb388be02015-07-22 22:19:38 +020011619 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011620 buf->b_p_et = p_et;
11621 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011622 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011623 buf->b_p_ml = p_ml;
11624 buf->b_p_ml_nobin = p_ml_nobin;
11625 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011626 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011627#ifdef FEAT_INS_EXPAND
11628 buf->b_p_cpt = vim_strsave(p_cpt);
Bram Moolenaarac3150d2019-07-28 16:36:39 +020011629# ifdef BACKSLASH_IN_FILENAME
11630 buf->b_p_csl = vim_strsave(p_csl);
11631# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011632#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011633#ifdef FEAT_COMPL_FUNC
11634 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011635 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011636#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +020011637#ifdef FEAT_EVAL
11638 buf->b_p_tfu = vim_strsave(p_tfu);
11639#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011640 buf->b_p_sts = p_sts;
11641 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011642#ifdef FEAT_VARTABS
11643 buf->b_p_vsts = vim_strsave(p_vsts);
11644 if (p_vsts && p_vsts != empty_option)
11645 tabstop_set(p_vsts, &buf->b_p_vsts_array);
11646 else
11647 buf->b_p_vsts_array = 0;
11648 buf->b_p_vsts_nopaste = p_vsts_nopaste
11649 ? vim_strsave(p_vsts_nopaste) : NULL;
11650#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011651 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011652#ifdef FEAT_COMMENTS
11653 buf->b_p_com = vim_strsave(p_com);
11654#endif
11655#ifdef FEAT_FOLDING
11656 buf->b_p_cms = vim_strsave(p_cms);
11657#endif
11658 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011659 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011660 buf->b_p_nf = vim_strsave(p_nf);
11661 buf->b_p_mps = vim_strsave(p_mps);
11662#ifdef FEAT_SMARTINDENT
11663 buf->b_p_si = p_si;
11664#endif
11665 buf->b_p_ci = p_ci;
11666#ifdef FEAT_CINDENT
11667 buf->b_p_cin = p_cin;
11668 buf->b_p_cink = vim_strsave(p_cink);
11669 buf->b_p_cino = vim_strsave(p_cino);
11670#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011671 /* Don't copy 'filetype', it must be detected */
11672 buf->b_p_ft = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011673 buf->b_p_pi = p_pi;
11674#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11675 buf->b_p_cinw = vim_strsave(p_cinw);
11676#endif
11677#ifdef FEAT_LISP
11678 buf->b_p_lisp = p_lisp;
11679#endif
11680#ifdef FEAT_SYN_HL
11681 /* Don't copy 'syntax', it must be set */
11682 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011683 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011684 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011685#endif
11686#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011687 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011688 (void)compile_cap_prog(&buf->b_s);
11689 buf->b_s.b_p_spf = vim_strsave(p_spf);
11690 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011691#endif
11692#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11693 buf->b_p_inde = vim_strsave(p_inde);
11694 buf->b_p_indk = vim_strsave(p_indk);
11695#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011696 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011697#if defined(FEAT_EVAL)
11698 buf->b_p_fex = vim_strsave(p_fex);
11699#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011700#ifdef FEAT_CRYPT
11701 buf->b_p_key = vim_strsave(p_key);
11702#endif
11703#ifdef FEAT_SEARCHPATH
11704 buf->b_p_sua = vim_strsave(p_sua);
11705#endif
11706#ifdef FEAT_KEYMAP
11707 buf->b_p_keymap = vim_strsave(p_keymap);
11708 buf->b_kmap_state |= KEYMAP_INIT;
11709#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011710#ifdef FEAT_TERMINAL
11711 buf->b_p_twsl = p_twsl;
11712#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011713 /* This isn't really an option, but copying the langmap and IME
11714 * state from the current buffer is better than resetting it. */
11715 buf->b_p_iminsert = p_iminsert;
11716 buf->b_p_imsearch = p_imsearch;
11717
11718 /* options that are normally global but also have a local value
11719 * are not copied, start using the global value */
11720 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011721 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011722 buf->b_p_bkc = empty_option;
11723 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011724#ifdef FEAT_QUICKFIX
11725 buf->b_p_gp = empty_option;
11726 buf->b_p_mp = empty_option;
11727 buf->b_p_efm = empty_option;
11728#endif
11729 buf->b_p_ep = empty_option;
11730 buf->b_p_kp = empty_option;
11731 buf->b_p_path = empty_option;
11732 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011733 buf->b_p_tc = empty_option;
11734 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011735#ifdef FEAT_FIND_ID
11736 buf->b_p_def = empty_option;
11737 buf->b_p_inc = empty_option;
11738# ifdef FEAT_EVAL
11739 buf->b_p_inex = vim_strsave(p_inex);
11740# endif
11741#endif
11742#ifdef FEAT_INS_EXPAND
11743 buf->b_p_dict = empty_option;
11744 buf->b_p_tsr = empty_option;
11745#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011746#ifdef FEAT_TEXTOBJ
11747 buf->b_p_qe = vim_strsave(p_qe);
11748#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011749#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11750 buf->b_p_bexpr = empty_option;
11751#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011752#if defined(FEAT_CRYPT)
11753 buf->b_p_cm = empty_option;
11754#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011755#ifdef FEAT_PERSISTENT_UNDO
11756 buf->b_p_udf = p_udf;
11757#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011758#ifdef FEAT_LISP
11759 buf->b_p_lw = empty_option;
11760#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011761 buf->b_p_menc = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011762
11763 /*
11764 * Don't copy the options set by ex_help(), use the saved values,
11765 * when going from a help buffer to a non-help buffer.
11766 * Don't touch these at all when BCO_NOHELP is used and going from
11767 * or to a help buffer.
11768 */
11769 if (dont_do_help)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011770 {
Bram Moolenaar071d4272004-06-13 20:20:40 +000011771 buf->b_p_isk = save_p_isk;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011772#ifdef FEAT_VARTABS
11773 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11774 tabstop_set(p_vts, &buf->b_p_vts_array);
11775 else
11776 buf->b_p_vts_array = NULL;
11777#endif
11778 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011779 else
11780 {
11781 buf->b_p_isk = vim_strsave(p_isk);
11782 did_isk = TRUE;
11783 buf->b_p_ts = p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011784#ifdef FEAT_VARTABS
11785 buf->b_p_vts = vim_strsave(p_vts);
11786 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11787 tabstop_set(p_vts, &buf->b_p_vts_array);
11788 else
11789 buf->b_p_vts_array = NULL;
11790#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011791 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011792 if (buf->b_p_bt[0] == 'h')
11793 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011794 buf->b_p_ma = p_ma;
11795 }
11796 }
11797
11798 /*
11799 * When the options should be copied (ignoring BCO_ALWAYS), set the
11800 * flag that indicates that the options have been initialized.
11801 */
11802 if (should_copy)
11803 buf->b_p_initialized = TRUE;
11804 }
11805
11806 check_buf_options(buf); /* make sure we don't have NULLs */
11807 if (did_isk)
11808 (void)buf_init_chartab(buf, FALSE);
11809}
11810
11811/*
11812 * Reset the 'modifiable' option and its default value.
11813 */
11814 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011815reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011816{
11817 int opt_idx;
11818
11819 curbuf->b_p_ma = FALSE;
11820 p_ma = FALSE;
11821 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011822 if (opt_idx >= 0)
11823 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011824}
11825
11826/*
11827 * Set the global value for 'iminsert' to the local value.
11828 */
11829 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011830set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011831{
11832 p_iminsert = curbuf->b_p_iminsert;
11833}
11834
11835/*
11836 * Set the global value for 'imsearch' to the local value.
11837 */
11838 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011839set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011840{
11841 p_imsearch = curbuf->b_p_imsearch;
11842}
11843
Bram Moolenaar071d4272004-06-13 20:20:40 +000011844static int expand_option_idx = -1;
11845static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11846static int expand_option_flags = 0;
11847
11848 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011849set_context_in_set_cmd(
11850 expand_T *xp,
11851 char_u *arg,
11852 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011853{
11854 int nextchar;
11855 long_u flags = 0; /* init for GCC */
11856 int opt_idx = 0; /* init for GCC */
11857 char_u *p;
11858 char_u *s;
11859 int is_term_option = FALSE;
11860 int key;
11861
11862 expand_option_flags = opt_flags;
11863
11864 xp->xp_context = EXPAND_SETTINGS;
11865 if (*arg == NUL)
11866 {
11867 xp->xp_pattern = arg;
11868 return;
11869 }
11870 p = arg + STRLEN(arg) - 1;
11871 if (*p == ' ' && *(p - 1) != '\\')
11872 {
11873 xp->xp_pattern = p + 1;
11874 return;
11875 }
11876 while (p > arg)
11877 {
11878 s = p;
11879 /* count number of backslashes before ' ' or ',' */
11880 if (*p == ' ' || *p == ',')
11881 {
11882 while (s > arg && *(s - 1) == '\\')
11883 --s;
11884 }
11885 /* break at a space with an even number of backslashes */
11886 if (*p == ' ' && ((p - s) & 1) == 0)
11887 {
11888 ++p;
11889 break;
11890 }
11891 --p;
11892 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011893 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011894 {
11895 xp->xp_context = EXPAND_BOOL_SETTINGS;
11896 p += 2;
11897 }
11898 if (STRNCMP(p, "inv", 3) == 0)
11899 {
11900 xp->xp_context = EXPAND_BOOL_SETTINGS;
11901 p += 3;
11902 }
11903 xp->xp_pattern = arg = p;
11904 if (*arg == '<')
11905 {
11906 while (*p != '>')
11907 if (*p++ == NUL) /* expand terminal option name */
11908 return;
11909 key = get_special_key_code(arg + 1);
11910 if (key == 0) /* unknown name */
11911 {
11912 xp->xp_context = EXPAND_NOTHING;
11913 return;
11914 }
11915 nextchar = *++p;
11916 is_term_option = TRUE;
11917 expand_option_name[2] = KEY2TERMCAP0(key);
11918 expand_option_name[3] = KEY2TERMCAP1(key);
11919 }
11920 else
11921 {
11922 if (p[0] == 't' && p[1] == '_')
11923 {
11924 p += 2;
11925 if (*p != NUL)
11926 ++p;
11927 if (*p == NUL)
11928 return; /* expand option name */
11929 nextchar = *++p;
11930 is_term_option = TRUE;
11931 expand_option_name[2] = p[-2];
11932 expand_option_name[3] = p[-1];
11933 }
11934 else
11935 {
11936 /* Allow * wildcard */
11937 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11938 p++;
11939 if (*p == NUL)
11940 return;
11941 nextchar = *p;
11942 *p = NUL;
11943 opt_idx = findoption(arg);
11944 *p = nextchar;
11945 if (opt_idx == -1 || options[opt_idx].var == NULL)
11946 {
11947 xp->xp_context = EXPAND_NOTHING;
11948 return;
11949 }
11950 flags = options[opt_idx].flags;
11951 if (flags & P_BOOL)
11952 {
11953 xp->xp_context = EXPAND_NOTHING;
11954 return;
11955 }
11956 }
11957 }
11958 /* handle "-=" and "+=" */
11959 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11960 {
11961 ++p;
11962 nextchar = '=';
11963 }
11964 if ((nextchar != '=' && nextchar != ':')
11965 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11966 {
11967 xp->xp_context = EXPAND_UNSUCCESSFUL;
11968 return;
11969 }
11970 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11971 {
11972 xp->xp_context = EXPAND_OLD_SETTING;
11973 if (is_term_option)
11974 expand_option_idx = -1;
11975 else
11976 expand_option_idx = opt_idx;
11977 xp->xp_pattern = p + 1;
11978 return;
11979 }
11980 xp->xp_context = EXPAND_NOTHING;
11981 if (is_term_option || (flags & P_NUM))
11982 return;
11983
11984 xp->xp_pattern = p + 1;
11985
11986 if (flags & P_EXPAND)
11987 {
11988 p = options[opt_idx].var;
11989 if (p == (char_u *)&p_bdir
11990 || p == (char_u *)&p_dir
11991 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011992 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011993 || p == (char_u *)&p_rtp
11994#ifdef FEAT_SEARCHPATH
11995 || p == (char_u *)&p_cdpath
11996#endif
11997#ifdef FEAT_SESSION
11998 || p == (char_u *)&p_vdir
11999#endif
12000 )
12001 {
12002 xp->xp_context = EXPAND_DIRECTORIES;
12003 if (p == (char_u *)&p_path
12004#ifdef FEAT_SEARCHPATH
12005 || p == (char_u *)&p_cdpath
12006#endif
12007 )
12008 xp->xp_backslash = XP_BS_THREE;
12009 else
12010 xp->xp_backslash = XP_BS_ONE;
12011 }
12012 else
12013 {
12014 xp->xp_context = EXPAND_FILES;
12015 /* for 'tags' need three backslashes for a space */
12016 if (p == (char_u *)&p_tags)
12017 xp->xp_backslash = XP_BS_THREE;
12018 else
12019 xp->xp_backslash = XP_BS_ONE;
12020 }
12021 }
12022
12023 /* For an option that is a list of file names, find the start of the
12024 * last file name. */
12025 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
12026 {
12027 /* count number of backslashes before ' ' or ',' */
12028 if (*p == ' ' || *p == ',')
12029 {
12030 s = p;
12031 while (s > xp->xp_pattern && *(s - 1) == '\\')
12032 --s;
12033 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
12034 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
12035 {
12036 xp->xp_pattern = p + 1;
12037 break;
12038 }
12039 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000012040
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000012041#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000012042 /* for 'spellsuggest' start at "file:" */
12043 if (options[opt_idx].var == (char_u *)&p_sps
12044 && STRNCMP(p, "file:", 5) == 0)
12045 {
12046 xp->xp_pattern = p + 5;
12047 break;
12048 }
12049#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012050 }
12051
12052 return;
12053}
12054
12055 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012056ExpandSettings(
12057 expand_T *xp,
12058 regmatch_T *regmatch,
12059 int *num_file,
12060 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012061{
12062 int num_normal = 0; /* Nr of matching non-term-code settings */
12063 int num_term = 0; /* Nr of matching terminal code settings */
12064 int opt_idx;
12065 int match;
12066 int count = 0;
12067 char_u *str;
12068 int loop;
12069 int is_term_opt;
12070 char_u name_buf[MAX_KEY_NAME_LEN];
12071 static char *(names[]) = {"all", "termcap"};
12072 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
12073
12074 /* do this loop twice:
12075 * loop == 0: count the number of matching options
12076 * loop == 1: copy the matching options into allocated memory
12077 */
12078 for (loop = 0; loop <= 1; ++loop)
12079 {
12080 regmatch->rm_ic = ic;
12081 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
12082 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000012083 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
12084 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012085 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
12086 {
12087 if (loop == 0)
12088 num_normal++;
12089 else
12090 (*file)[count++] = vim_strsave((char_u *)names[match]);
12091 }
12092 }
12093 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
12094 opt_idx++)
12095 {
12096 if (options[opt_idx].var == NULL)
12097 continue;
12098 if (xp->xp_context == EXPAND_BOOL_SETTINGS
12099 && !(options[opt_idx].flags & P_BOOL))
12100 continue;
12101 is_term_opt = istermoption(&options[opt_idx]);
12102 if (is_term_opt && num_normal > 0)
12103 continue;
12104 match = FALSE;
12105 if (vim_regexec(regmatch, str, (colnr_T)0)
12106 || (options[opt_idx].shortname != NULL
12107 && vim_regexec(regmatch,
12108 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
12109 match = TRUE;
12110 else if (is_term_opt)
12111 {
12112 name_buf[0] = '<';
12113 name_buf[1] = 't';
12114 name_buf[2] = '_';
12115 name_buf[3] = str[2];
12116 name_buf[4] = str[3];
12117 name_buf[5] = '>';
12118 name_buf[6] = NUL;
12119 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12120 {
12121 match = TRUE;
12122 str = name_buf;
12123 }
12124 }
12125 if (match)
12126 {
12127 if (loop == 0)
12128 {
12129 if (is_term_opt)
12130 num_term++;
12131 else
12132 num_normal++;
12133 }
12134 else
12135 (*file)[count++] = vim_strsave(str);
12136 }
12137 }
12138 /*
12139 * Check terminal key codes, these are not in the option table
12140 */
12141 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
12142 {
12143 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
12144 {
12145 if (!isprint(str[0]) || !isprint(str[1]))
12146 continue;
12147
12148 name_buf[0] = 't';
12149 name_buf[1] = '_';
12150 name_buf[2] = str[0];
12151 name_buf[3] = str[1];
12152 name_buf[4] = NUL;
12153
12154 match = FALSE;
12155 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12156 match = TRUE;
12157 else
12158 {
12159 name_buf[0] = '<';
12160 name_buf[1] = 't';
12161 name_buf[2] = '_';
12162 name_buf[3] = str[0];
12163 name_buf[4] = str[1];
12164 name_buf[5] = '>';
12165 name_buf[6] = NUL;
12166
12167 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12168 match = TRUE;
12169 }
12170 if (match)
12171 {
12172 if (loop == 0)
12173 num_term++;
12174 else
12175 (*file)[count++] = vim_strsave(name_buf);
12176 }
12177 }
12178
12179 /*
12180 * Check special key names.
12181 */
12182 regmatch->rm_ic = TRUE; /* ignore case here */
12183 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
12184 {
12185 name_buf[0] = '<';
12186 STRCPY(name_buf + 1, str);
12187 STRCAT(name_buf, ">");
12188
12189 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12190 {
12191 if (loop == 0)
12192 num_term++;
12193 else
12194 (*file)[count++] = vim_strsave(name_buf);
12195 }
12196 }
12197 }
12198 if (loop == 0)
12199 {
12200 if (num_normal > 0)
12201 *num_file = num_normal;
12202 else if (num_term > 0)
12203 *num_file = num_term;
12204 else
12205 return OK;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020012206 *file = ALLOC_MULT(char_u *, *num_file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012207 if (*file == NULL)
12208 {
12209 *file = (char_u **)"";
12210 return FAIL;
12211 }
12212 }
12213 }
12214 return OK;
12215}
12216
12217 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012218ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012219{
12220 char_u *var = NULL; /* init for GCC */
12221 char_u *buf;
12222
12223 *num_file = 0;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020012224 *file = ALLOC_ONE(char_u *);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012225 if (*file == NULL)
12226 return FAIL;
12227
12228 /*
12229 * For a terminal key code expand_option_idx is < 0.
12230 */
12231 if (expand_option_idx < 0)
12232 {
12233 var = find_termcode(expand_option_name + 2);
12234 if (var == NULL)
12235 expand_option_idx = findoption(expand_option_name);
12236 }
12237
12238 if (expand_option_idx >= 0)
12239 {
12240 /* put string of option value in NameBuff */
12241 option_value2string(&options[expand_option_idx], expand_option_flags);
12242 var = NameBuff;
12243 }
12244 else if (var == NULL)
12245 var = (char_u *)"";
12246
12247 /* A backslash is required before some characters. This is the reverse of
12248 * what happens in do_set(). */
12249 buf = vim_strsave_escaped(var, escape_chars);
12250
12251 if (buf == NULL)
12252 {
Bram Moolenaard23a8232018-02-10 18:45:26 +010012253 VIM_CLEAR(*file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012254 return FAIL;
12255 }
12256
12257#ifdef BACKSLASH_IN_FILENAME
12258 /* For MS-Windows et al. we don't double backslashes at the start and
12259 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012260 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012261 if (var[0] == '\\' && var[1] == '\\'
12262 && expand_option_idx >= 0
12263 && (options[expand_option_idx].flags & P_EXPAND)
12264 && vim_isfilec(var[2])
12265 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000012266 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012267#endif
12268
12269 *file[0] = buf;
12270 *num_file = 1;
12271 return OK;
12272}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012273
12274/*
12275 * Get the value for the numeric or string option *opp in a nice format into
12276 * NameBuff[]. Must not be called with a hidden option!
12277 */
12278 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012279option_value2string(
12280 struct vimoption *opp,
12281 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012282{
12283 char_u *varp;
12284
12285 varp = get_varp_scope(opp, opt_flags);
12286
12287 if (opp->flags & P_NUM)
12288 {
12289 long wc = 0;
12290
12291 if (wc_use_keyname(varp, &wc))
12292 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
12293 else if (wc != 0)
12294 STRCPY(NameBuff, transchar((int)wc));
12295 else
12296 sprintf((char *)NameBuff, "%ld", *(long *)varp);
12297 }
12298 else /* P_STRING */
12299 {
12300 varp = *(char_u **)(varp);
12301 if (varp == NULL) /* just in case */
12302 NameBuff[0] = NUL;
12303#ifdef FEAT_CRYPT
12304 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000012305 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012306 STRCPY(NameBuff, "*****");
12307#endif
12308 else if (opp->flags & P_EXPAND)
12309 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
12310 /* Translate 'pastetoggle' into special key names */
12311 else if ((char_u **)opp->var == &p_pt)
12312 str2specialbuf(p_pt, NameBuff, MAXPATHL);
12313 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000012314 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012315 }
12316}
12317
12318/*
12319 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
12320 * printed as a keyname.
12321 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
12322 */
12323 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012324wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012325{
12326 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
12327 {
12328 *wcp = *(long *)varp;
12329 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
12330 return TRUE;
12331 }
12332 return FALSE;
12333}
12334
Bram Moolenaar01615492015-02-03 13:00:38 +010012335#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012336/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012337 * Any character has an equivalent 'langmap' character. This is used for
12338 * keyboards that have a special language mode that sends characters above
12339 * 128 (although other characters can be translated too). The "to" field is a
12340 * Vim command character. This avoids having to switch the keyboard back to
12341 * ASCII mode when leaving Insert mode.
12342 *
12343 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
12344 * commands.
Bram Moolenaarfc3abf42019-01-24 15:54:21 +010012345 * langmap_mapga.ga_data is a sorted table of langmap_entry_T. This does the
12346 * same as langmap_mapchar[] for characters >= 256.
12347 *
12348 * Use growarray for 'langmap' chars >= 256
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012349 */
12350typedef struct
12351{
12352 int from;
12353 int to;
12354} langmap_entry_T;
12355
12356static garray_T langmap_mapga;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012357
12358/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012359 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
12360 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012361 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012362 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012363langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012364{
12365 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020012366 int a = 0;
12367 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012368
12369 /* Do a binary search for an existing entry. */
12370 while (a != b)
12371 {
12372 int i = (a + b) / 2;
12373 int d = entries[i].from - from;
12374
12375 if (d == 0)
12376 {
12377 entries[i].to = to;
12378 return;
12379 }
12380 if (d < 0)
12381 a = i + 1;
12382 else
12383 b = i;
12384 }
12385
12386 if (ga_grow(&langmap_mapga, 1) != OK)
12387 return; /* out of memory */
12388
12389 /* insert new entry at position "a" */
12390 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
12391 mch_memmove(entries + 1, entries,
12392 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
12393 ++langmap_mapga.ga_len;
12394 entries[0].from = from;
12395 entries[0].to = to;
12396}
12397
12398/*
12399 * Apply 'langmap' to multi-byte character "c" and return the result.
12400 */
12401 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012402langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012403{
12404 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
12405 int a = 0;
12406 int b = langmap_mapga.ga_len;
12407
12408 while (a != b)
12409 {
12410 int i = (a + b) / 2;
12411 int d = entries[i].from - c;
12412
12413 if (d == 0)
12414 return entries[i].to; /* found matching entry */
12415 if (d < 0)
12416 a = i + 1;
12417 else
12418 b = i;
12419 }
12420 return c; /* no entry found, return "c" unmodified */
12421}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012422
12423 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012424langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012425{
12426 int i;
12427
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012428 for (i = 0; i < 256; i++)
12429 langmap_mapchar[i] = i; /* we init with a one-to-one map */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012430 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012431}
12432
12433/*
12434 * Called when langmap option is set; the language map can be
12435 * changed at any time!
12436 */
12437 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012438langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012439{
12440 char_u *p;
12441 char_u *p2;
12442 int from, to;
12443
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012444 ga_clear(&langmap_mapga); /* clear the previous map first */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012445 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012446
12447 for (p = p_langmap; p[0] != NUL; )
12448 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000012449 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012450 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012451 {
12452 if (p2[0] == '\\' && p2[1] != NUL)
12453 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012454 }
12455 if (p2[0] == ';')
12456 ++p2; /* abcd;ABCD form, p2 points to A */
12457 else
12458 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
12459 while (p[0])
12460 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012461 if (p[0] == ',')
12462 {
12463 ++p;
12464 break;
12465 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012466 if (p[0] == '\\' && p[1] != NUL)
12467 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012468 from = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012469 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012470 if (p2 == NULL)
12471 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012472 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012473 if (p[0] != ',')
12474 {
12475 if (p[0] == '\\')
12476 ++p;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012477 to = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012478 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012479 }
12480 else
12481 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012482 if (p2[0] != ',')
12483 {
12484 if (p2[0] == '\\')
12485 ++p2;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012486 to = (*mb_ptr2char)(p2);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012487 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012488 }
12489 if (to == NUL)
12490 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012491 semsg(_("E357: 'langmap': Matching character missing for %s"),
Bram Moolenaar071d4272004-06-13 20:20:40 +000012492 transchar(from));
12493 return;
12494 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012495
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012496 if (from >= 256)
12497 langmap_set_entry(from, to);
12498 else
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012499 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012500
12501 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012502 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012503 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012504 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012505 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012506 if (*p == ';')
12507 {
12508 p = p2;
12509 if (p[0] != NUL)
12510 {
12511 if (p[0] != ',')
12512 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012513 semsg(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012514 return;
12515 }
12516 ++p;
12517 }
12518 break;
12519 }
12520 }
12521 }
12522 }
12523}
12524#endif
12525
12526/*
12527 * Return TRUE if format option 'x' is in effect.
12528 * Take care of no formatting when 'paste' is set.
12529 */
12530 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012531has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012532{
12533 if (p_paste)
12534 return FALSE;
12535 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12536}
12537
12538/*
12539 * Return TRUE if "x" is present in 'shortmess' option, or
12540 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12541 */
12542 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012543shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012544{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012545 return p_shm != NULL &&
12546 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012547 || (vim_strchr(p_shm, 'a') != NULL
12548 && vim_strchr((char_u *)SHM_A, x) != NULL));
12549}
12550
12551/*
12552 * paste_option_changed() - Called after p_paste was set or reset.
12553 */
12554 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012555paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012556{
12557 static int old_p_paste = FALSE;
12558 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012559 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012560#ifdef FEAT_CMDL_INFO
12561 static int save_ru = 0;
12562#endif
12563#ifdef FEAT_RIGHTLEFT
12564 static int save_ri = 0;
12565 static int save_hkmap = 0;
12566#endif
12567 buf_T *buf;
12568
12569 if (p_paste)
12570 {
12571 /*
12572 * Paste switched from off to on.
12573 * Save the current values, so they can be restored later.
12574 */
12575 if (!old_p_paste)
12576 {
12577 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012578 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012579 {
12580 buf->b_p_tw_nopaste = buf->b_p_tw;
12581 buf->b_p_wm_nopaste = buf->b_p_wm;
12582 buf->b_p_sts_nopaste = buf->b_p_sts;
12583 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012584 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012585#ifdef FEAT_VARTABS
12586 if (buf->b_p_vsts_nopaste)
12587 vim_free(buf->b_p_vsts_nopaste);
12588 buf->b_p_vsts_nopaste = buf->b_p_vsts && buf->b_p_vsts != empty_option
12589 ? vim_strsave(buf->b_p_vsts) : NULL;
12590#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012591 }
12592
12593 /* save global options */
12594 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012595 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012596#ifdef FEAT_CMDL_INFO
12597 save_ru = p_ru;
12598#endif
12599#ifdef FEAT_RIGHTLEFT
12600 save_ri = p_ri;
12601 save_hkmap = p_hkmap;
12602#endif
12603 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012604 p_ai_nopaste = p_ai;
12605 p_et_nopaste = p_et;
12606 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012607 p_tw_nopaste = p_tw;
12608 p_wm_nopaste = p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012609#ifdef FEAT_VARTABS
12610 if (p_vsts_nopaste)
12611 vim_free(p_vsts_nopaste);
12612 p_vsts_nopaste = p_vsts && p_vsts != empty_option ? vim_strsave(p_vsts) : NULL;
12613#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012614 }
12615
12616 /*
12617 * Always set the option values, also when 'paste' is set when it is
12618 * already on.
12619 */
12620 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012621 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012622 {
12623 buf->b_p_tw = 0; /* textwidth is 0 */
12624 buf->b_p_wm = 0; /* wrapmargin is 0 */
12625 buf->b_p_sts = 0; /* softtabstop is 0 */
12626 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012627 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012628#ifdef FEAT_VARTABS
12629 if (buf->b_p_vsts)
12630 free_string_option(buf->b_p_vsts);
12631 buf->b_p_vsts = empty_option;
12632 if (buf->b_p_vsts_array)
12633 vim_free(buf->b_p_vsts_array);
12634 buf->b_p_vsts_array = 0;
12635#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012636 }
12637
12638 /* set global options */
12639 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012640 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012641#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012642 if (p_ru)
12643 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012644 p_ru = 0; /* no ruler */
12645#endif
12646#ifdef FEAT_RIGHTLEFT
12647 p_ri = 0; /* no reverse insert */
12648 p_hkmap = 0; /* no Hebrew keyboard */
12649#endif
12650 /* set global values for local buffer options */
12651 p_tw = 0;
12652 p_wm = 0;
12653 p_sts = 0;
12654 p_ai = 0;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012655#ifdef FEAT_VARTABS
12656 if (p_vsts)
12657 free_string_option(p_vsts);
12658 p_vsts = empty_option;
12659#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012660 }
12661
12662 /*
12663 * Paste switched from on to off: Restore saved values.
12664 */
12665 else if (old_p_paste)
12666 {
12667 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012668 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012669 {
12670 buf->b_p_tw = buf->b_p_tw_nopaste;
12671 buf->b_p_wm = buf->b_p_wm_nopaste;
12672 buf->b_p_sts = buf->b_p_sts_nopaste;
12673 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012674 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012675#ifdef FEAT_VARTABS
12676 if (buf->b_p_vsts)
12677 free_string_option(buf->b_p_vsts);
12678 buf->b_p_vsts = buf->b_p_vsts_nopaste
12679 ? vim_strsave(buf->b_p_vsts_nopaste) : empty_option;
12680 if (buf->b_p_vsts_array)
12681 vim_free(buf->b_p_vsts_array);
12682 if (buf->b_p_vsts && buf->b_p_vsts != empty_option)
12683 tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array);
12684 else
12685 buf->b_p_vsts_array = 0;
12686#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012687 }
12688
12689 /* restore global options */
12690 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012691 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012692#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012693 if (p_ru != save_ru)
12694 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012695 p_ru = save_ru;
12696#endif
12697#ifdef FEAT_RIGHTLEFT
12698 p_ri = save_ri;
12699 p_hkmap = save_hkmap;
12700#endif
12701 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012702 p_ai = p_ai_nopaste;
12703 p_et = p_et_nopaste;
12704 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012705 p_tw = p_tw_nopaste;
12706 p_wm = p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012707#ifdef FEAT_VARTABS
12708 if (p_vsts)
12709 free_string_option(p_vsts);
12710 p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option;
12711#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012712 }
12713
12714 old_p_paste = p_paste;
12715}
12716
12717/*
12718 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12719 *
12720 * Reset 'compatible' and set the values for options that didn't get set yet
12721 * to the Vim defaults.
12722 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012723 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012724 */
12725 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012726vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012727{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012728 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012729 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012730 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012731
12732 if (!option_was_set((char_u *)"cp"))
12733 {
12734 p_cp = FALSE;
12735 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12736 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12737 set_option_default(opt_idx, OPT_FREE, FALSE);
12738 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012739 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012740 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012741
12742 if (fname != NULL)
12743 {
12744 p = vim_getenv(envname, &dofree);
12745 if (p == NULL)
12746 {
12747 /* Set $MYVIMRC to the first vimrc file found. */
12748 p = FullName_save(fname, FALSE);
12749 if (p != NULL)
12750 {
12751 vim_setenv(envname, p);
12752 vim_free(p);
12753 }
12754 }
12755 else if (dofree)
12756 vim_free(p);
12757 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012758}
12759
12760/*
12761 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12762 */
12763 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012764change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012765{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012766 int opt_idx;
12767
Bram Moolenaar071d4272004-06-13 20:20:40 +000012768 if (p_cp != on)
12769 {
12770 p_cp = on;
12771 compatible_set();
12772 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012773 opt_idx = findoption((char_u *)"cp");
12774 if (opt_idx >= 0)
12775 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012776}
12777
12778/*
12779 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012780 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012781 */
12782 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012783option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012784{
12785 int idx;
12786
12787 idx = findoption(name);
12788 if (idx < 0) /* unknown option */
12789 return FALSE;
12790 if (options[idx].flags & P_WAS_SET)
12791 return TRUE;
12792 return FALSE;
12793}
12794
12795/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012796 * Reset the flag indicating option "name" was set.
12797 */
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012798 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012799reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012800{
12801 int idx = findoption(name);
12802
12803 if (idx >= 0)
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012804 {
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012805 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012806 return OK;
12807 }
12808 return FAIL;
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012809}
12810
12811/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012812 * compatible_set() - Called when 'compatible' has been set or unset.
12813 *
12814 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12815 * flag) to a Vi compatible value.
12816 * When 'compatible' is unset: Set all options that have a different default
12817 * for Vim (without the P_VI_DEF flag) to that default.
12818 */
12819 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012820compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012821{
12822 int opt_idx;
12823
12824 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12825 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12826 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12827 set_option_default(opt_idx, OPT_FREE, p_cp);
12828 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012829 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012830}
12831
12832#ifdef FEAT_LINEBREAK
12833
Bram Moolenaar071d4272004-06-13 20:20:40 +000012834/*
12835 * fill_breakat_flags() -- called when 'breakat' changes value.
12836 */
12837 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012838fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012839{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012840 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012841 int i;
12842
12843 for (i = 0; i < 256; i++)
12844 breakat_flags[i] = FALSE;
12845
12846 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012847 for (p = p_breakat; *p; p++)
12848 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012849}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012850#endif
12851
12852/*
12853 * Check an option that can be a range of string values.
12854 *
12855 * Return OK for correct value, FAIL otherwise.
12856 * Empty is always OK.
12857 */
12858 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012859check_opt_strings(
12860 char_u *val,
12861 char **values,
12862 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012863{
12864 return opt_strings_flags(val, values, NULL, list);
12865}
12866
12867/*
12868 * Handle an option that can be a range of string values.
12869 * Set a flag in "*flagp" for each string present.
12870 *
12871 * Return OK for correct value, FAIL otherwise.
12872 * Empty is always OK.
12873 */
12874 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012875opt_strings_flags(
12876 char_u *val, /* new value */
12877 char **values, /* array of valid string values */
12878 unsigned *flagp,
12879 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012880{
12881 int i;
12882 int len;
12883 unsigned new_flags = 0;
12884
12885 while (*val)
12886 {
12887 for (i = 0; ; ++i)
12888 {
12889 if (values[i] == NULL) /* val not found in values[] */
12890 return FAIL;
12891
12892 len = (int)STRLEN(values[i]);
12893 if (STRNCMP(values[i], val, len) == 0
12894 && ((list && val[len] == ',') || val[len] == NUL))
12895 {
12896 val += len + (val[len] == ',');
12897 new_flags |= (1 << i);
12898 break; /* check next item in val list */
12899 }
12900 }
12901 }
12902 if (flagp != NULL)
12903 *flagp = new_flags;
12904
12905 return OK;
12906}
12907
12908/*
12909 * Read the 'wildmode' option, fill wim_flags[].
12910 */
12911 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012912check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012913{
12914 char_u new_wim_flags[4];
12915 char_u *p;
12916 int i;
12917 int idx = 0;
12918
12919 for (i = 0; i < 4; ++i)
12920 new_wim_flags[i] = 0;
12921
12922 for (p = p_wim; *p; ++p)
12923 {
12924 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12925 ;
12926 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12927 return FAIL;
12928 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12929 new_wim_flags[idx] |= WIM_LONGEST;
12930 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12931 new_wim_flags[idx] |= WIM_FULL;
12932 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12933 new_wim_flags[idx] |= WIM_LIST;
12934 else
12935 return FAIL;
12936 p += i;
12937 if (*p == NUL)
12938 break;
12939 if (*p == ',')
12940 {
12941 if (idx == 3)
12942 return FAIL;
12943 ++idx;
12944 }
12945 }
12946
12947 /* fill remaining entries with last flag */
12948 while (idx < 3)
12949 {
12950 new_wim_flags[idx + 1] = new_wim_flags[idx];
12951 ++idx;
12952 }
12953
12954 /* only when there are no errors, wim_flags[] is changed */
12955 for (i = 0; i < 4; ++i)
12956 wim_flags[i] = new_wim_flags[i];
12957 return OK;
12958}
12959
12960/*
12961 * Check if backspacing over something is allowed.
12962 */
12963 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012964can_bs(
12965 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012966{
Bram Moolenaar6b810d92018-06-04 17:28:44 +020012967#ifdef FEAT_JOB_CHANNEL
12968 if (what == BS_START && bt_prompt(curbuf))
12969 return FALSE;
12970#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012971 switch (*p_bs)
12972 {
12973 case '2': return TRUE;
12974 case '1': return (what != BS_START);
12975 case '0': return FALSE;
12976 }
12977 return vim_strchr(p_bs, what) != NULL;
12978}
12979
12980/*
12981 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12982 * the file must be considered changed when the value is different.
12983 */
12984 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012985save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012986{
12987 buf->b_start_ffc = *buf->b_p_ff;
12988 buf->b_start_eol = buf->b_p_eol;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012989 buf->b_start_bomb = buf->b_p_bomb;
12990
Bram Moolenaar071d4272004-06-13 20:20:40 +000012991 /* Only use free/alloc when necessary, they take time. */
12992 if (buf->b_start_fenc == NULL
12993 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12994 {
12995 vim_free(buf->b_start_fenc);
12996 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12997 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012998}
12999
13000/*
13001 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
13002 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000013003 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
13004 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020013005 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010013006 * When "ignore_empty" is true don't consider a new, empty buffer to be
13007 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000013008 */
13009 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013010file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000013011{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000013012 /* In a buffer that was never loaded the options are not valid. */
13013 if (buf->b_flags & BF_NEVERLOADED)
13014 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010013015 if (ignore_empty
13016 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000013017 && buf->b_ml.ml_line_count == 1
13018 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
13019 return FALSE;
13020 if (buf->b_start_ffc != *buf->b_p_ff)
13021 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020013022 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000013023 return TRUE;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000013024 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
13025 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000013026 if (buf->b_start_fenc == NULL)
13027 return (*buf->b_p_fenc != NUL);
13028 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +000013029}
13030
13031/*
13032 * return OK if "p" is a valid fileformat name, FAIL otherwise.
13033 */
13034 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013035check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000013036{
13037 return check_opt_strings(p, p_ff_values, FALSE);
13038}
Bram Moolenaar14f24742012-08-08 18:01:05 +020013039
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010013040#if defined(FEAT_VARTABS) || defined(PROTO)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013041
13042/*
13043 * Set the integer values corresponding to the string setting of 'vartabstop'.
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010013044 * "array" will be set, caller must free it if needed.
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013045 */
13046 int
13047tabstop_set(char_u *var, int **array)
13048{
13049 int valcount = 1;
13050 int t;
13051 char_u *cp;
13052
Bram Moolenaar64f41072018-10-15 22:51:50 +020013053 if (var[0] == NUL || (var[0] == '0' && var[1] == NUL))
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013054 {
13055 *array = NULL;
13056 return TRUE;
13057 }
13058
Bram Moolenaar64f41072018-10-15 22:51:50 +020013059 for (cp = var; *cp != NUL; ++cp)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013060 {
Bram Moolenaar64f41072018-10-15 22:51:50 +020013061 if (cp == var || cp[-1] == ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013062 {
13063 char_u *end;
Bram Moolenaar64f41072018-10-15 22:51:50 +020013064
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013065 if (strtol((char *)cp, (char **)&end, 10) <= 0)
13066 {
13067 if (cp != end)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010013068 emsg(_(e_positive));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013069 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010013070 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013071 return FALSE;
13072 }
13073 }
13074
13075 if (VIM_ISDIGIT(*cp))
13076 continue;
Bram Moolenaar64f41072018-10-15 22:51:50 +020013077 if (cp[0] == ',' && cp > var && cp[-1] != ',' && cp[1] != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013078 {
13079 ++valcount;
13080 continue;
13081 }
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010013082 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013083 return FALSE;
13084 }
13085
Bram Moolenaarc799fe22019-05-28 23:08:19 +020013086 *array = ALLOC_MULT(int, valcount + 1);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010013087 if (*array == NULL)
13088 return FALSE;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013089 (*array)[0] = valcount;
13090
13091 t = 1;
Bram Moolenaar64f41072018-10-15 22:51:50 +020013092 for (cp = var; *cp != NUL;)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013093 {
13094 (*array)[t++] = atoi((char *)cp);
Bram Moolenaar64f41072018-10-15 22:51:50 +020013095 while (*cp != NUL && *cp != ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013096 ++cp;
Bram Moolenaar64f41072018-10-15 22:51:50 +020013097 if (*cp != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013098 ++cp;
13099 }
13100
13101 return TRUE;
13102}
13103
13104/*
13105 * Calculate the number of screen spaces a tab will occupy.
13106 * If "vts" is set then the tab widths are taken from that array,
13107 * otherwise the value of ts is used.
13108 */
13109 int
13110tabstop_padding(colnr_T col, int ts_arg, int *vts)
13111{
13112 int ts = ts_arg == 0 ? 8 : ts_arg;
13113 int tabcount;
13114 colnr_T tabcol = 0;
13115 int t;
13116 int padding = 0;
13117
13118 if (vts == NULL || vts[0] == 0)
13119 return ts - (col % ts);
13120
13121 tabcount = vts[0];
13122
13123 for (t = 1; t <= tabcount; ++t)
13124 {
13125 tabcol += vts[t];
13126 if (tabcol > col)
13127 {
13128 padding = (int)(tabcol - col);
13129 break;
13130 }
13131 }
13132 if (t > tabcount)
13133 padding = vts[tabcount] - (int)((col - tabcol) % vts[tabcount]);
13134
13135 return padding;
13136}
13137
13138/*
13139 * Find the size of the tab that covers a particular column.
13140 */
13141 int
13142tabstop_at(colnr_T col, int ts, int *vts)
13143{
13144 int tabcount;
13145 colnr_T tabcol = 0;
13146 int t;
13147 int tab_size = 0;
13148
13149 if (vts == 0 || vts[0] == 0)
13150 return ts;
13151
13152 tabcount = vts[0];
13153 for (t = 1; t <= tabcount; ++t)
13154 {
13155 tabcol += vts[t];
13156 if (tabcol > col)
13157 {
13158 tab_size = vts[t];
13159 break;
13160 }
13161 }
13162 if (t > tabcount)
13163 tab_size = vts[tabcount];
13164
13165 return tab_size;
13166}
13167
13168/*
13169 * Find the column on which a tab starts.
13170 */
13171 colnr_T
13172tabstop_start(colnr_T col, int ts, int *vts)
13173{
13174 int tabcount;
13175 colnr_T tabcol = 0;
13176 int t;
13177 int excess;
13178
Bram Moolenaar0119a592018-06-24 23:53:28 +020013179 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013180 return (col / ts) * ts;
13181
13182 tabcount = vts[0];
13183 for (t = 1; t <= tabcount; ++t)
13184 {
13185 tabcol += vts[t];
13186 if (tabcol > col)
13187 return tabcol - vts[t];
13188 }
13189
13190 excess = tabcol % vts[tabcount];
13191 return excess + ((col - excess) / vts[tabcount]) * vts[tabcount];
13192}
13193
13194/*
13195 * Find the number of tabs and spaces necessary to get from one column
13196 * to another.
13197 */
13198 void
13199tabstop_fromto(
13200 colnr_T start_col,
13201 colnr_T end_col,
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013202 int ts_arg,
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013203 int *vts,
13204 int *ntabs,
13205 int *nspcs)
13206{
13207 int spaces = end_col - start_col;
13208 colnr_T tabcol = 0;
13209 int padding = 0;
13210 int tabcount;
13211 int t;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013212 int ts = ts_arg == 0 ? curbuf->b_p_ts : ts_arg;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013213
Bram Moolenaar0119a592018-06-24 23:53:28 +020013214 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013215 {
13216 int tabs = 0;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013217 int initspc = 0;
Bram Moolenaar0119a592018-06-24 23:53:28 +020013218
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013219 initspc = ts - (start_col % ts);
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013220 if (spaces >= initspc)
13221 {
13222 spaces -= initspc;
13223 tabs++;
13224 }
13225 tabs += spaces / ts;
13226 spaces -= (spaces / ts) * ts;
13227
13228 *ntabs = tabs;
13229 *nspcs = spaces;
13230 return;
13231 }
13232
13233 /* Find the padding needed to reach the next tabstop. */
13234 tabcount = vts[0];
13235 for (t = 1; t <= tabcount; ++t)
13236 {
13237 tabcol += vts[t];
13238 if (tabcol > start_col)
13239 {
13240 padding = (int)(tabcol - start_col);
13241 break;
13242 }
13243 }
13244 if (t > tabcount)
13245 padding = vts[tabcount] - (int)((start_col - tabcol) % vts[tabcount]);
13246
13247 /* If the space needed is less than the padding no tabs can be used. */
13248 if (spaces < padding)
13249 {
13250 *ntabs = 0;
13251 *nspcs = spaces;
13252 return;
13253 }
13254
13255 *ntabs = 1;
13256 spaces -= padding;
13257
13258 /* At least one tab has been used. See if any more will fit. */
13259 while (spaces != 0 && ++t <= tabcount)
13260 {
13261 padding = vts[t];
13262 if (spaces < padding)
13263 {
13264 *nspcs = spaces;
13265 return;
13266 }
13267 ++*ntabs;
13268 spaces -= padding;
13269 }
13270
13271 *ntabs += spaces / vts[tabcount];
13272 *nspcs = spaces % vts[tabcount];
13273}
13274
13275/*
13276 * See if two tabstop arrays contain the same values.
13277 */
13278 int
13279tabstop_eq(int *ts1, int *ts2)
13280{
13281 int t;
13282
13283 if ((ts1 == 0 && ts2) || (ts1 && ts2 == 0))
13284 return FALSE;
13285 if (ts1 == ts2)
13286 return TRUE;
13287 if (ts1[0] != ts2[0])
13288 return FALSE;
13289
13290 for (t = 1; t <= ts1[0]; ++t)
13291 if (ts1[t] != ts2[t])
13292 return FALSE;
13293
13294 return TRUE;
13295}
13296
Bram Moolenaar113e1072019-01-20 15:30:40 +010013297#if defined(FEAT_BEVAL) || defined(PROTO)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013298/*
13299 * Copy a tabstop array, allocating space for the new array.
13300 */
13301 int *
13302tabstop_copy(int *oldts)
13303{
13304 int *newts;
13305 int t;
13306
Bram Moolenaar6ee96582019-04-27 22:06:37 +020013307 if (oldts == NULL)
13308 return NULL;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020013309 newts = ALLOC_MULT(int, oldts[0] + 1);
Bram Moolenaar6ee96582019-04-27 22:06:37 +020013310 if (newts != NULL)
13311 for (t = 0; t <= oldts[0]; ++t)
13312 newts[t] = oldts[t];
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013313 return newts;
13314}
Bram Moolenaar113e1072019-01-20 15:30:40 +010013315#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013316
13317/*
13318 * Return a count of the number of tabstops.
13319 */
13320 int
13321tabstop_count(int *ts)
13322{
13323 return ts != NULL ? ts[0] : 0;
13324}
13325
13326/*
13327 * Return the first tabstop, or 8 if there are no tabstops defined.
13328 */
13329 int
13330tabstop_first(int *ts)
13331{
13332 return ts != NULL ? ts[1] : 8;
13333}
13334
13335#endif
13336
Bram Moolenaar14f24742012-08-08 18:01:05 +020013337/*
13338 * Return the effective shiftwidth value for current buffer, using the
13339 * 'tabstop' value when 'shiftwidth' is zero.
13340 */
13341 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013342get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020013343{
Bram Moolenaarf9514162018-11-22 03:08:29 +010013344 return get_sw_value_col(buf, 0);
13345}
13346
13347/*
Bram Moolenaarf9514162018-11-22 03:08:29 +010013348 * Idem, using "pos".
13349 */
Bram Moolenaar5843f5f2019-08-20 20:13:45 +020013350 static long
Bram Moolenaarf9514162018-11-22 03:08:29 +010013351get_sw_value_pos(buf_T *buf, pos_T *pos)
13352{
13353 pos_T save_cursor = curwin->w_cursor;
13354 long sw_value;
13355
13356 curwin->w_cursor = *pos;
13357 sw_value = get_sw_value_col(buf, get_nolist_virtcol());
13358 curwin->w_cursor = save_cursor;
13359 return sw_value;
13360}
13361
13362/*
Bram Moolenaar5843f5f2019-08-20 20:13:45 +020013363 * Idem, using the first non-black in the current line.
13364 */
13365 long
13366get_sw_value_indent(buf_T *buf)
13367{
13368 pos_T pos = curwin->w_cursor;
13369
13370 pos.col = getwhitecols_curline();
13371 return get_sw_value_pos(buf, &pos);
13372}
13373
13374/*
Bram Moolenaarf9514162018-11-22 03:08:29 +010013375 * Idem, using virtual column "col".
13376 */
13377 long
13378get_sw_value_col(buf_T *buf, colnr_T col UNUSED)
13379{
13380 return buf->b_p_sw ? buf->b_p_sw :
13381 #ifdef FEAT_VARTABS
13382 tabstop_at(col, buf->b_p_ts, buf->b_p_vts_array);
13383 #else
13384 buf->b_p_ts;
13385 #endif
Bram Moolenaar14f24742012-08-08 18:01:05 +020013386}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013387
13388/*
13389 * Return the effective softtabstop value for the current buffer, using the
Bram Moolenaar33d5ab32018-07-02 20:51:24 +020013390 * 'shiftwidth' value when 'softtabstop' is negative.
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013391 */
13392 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013393get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013394{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010013395 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013396}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013397
13398/*
Bram Moolenaar375e3392019-01-31 18:26:10 +010013399 * Return the effective 'scrolloff' value for the current window, using the
13400 * global value when appropriate.
13401 */
13402 long
13403get_scrolloff_value(void)
13404{
13405 return curwin->w_p_so < 0 ? p_so : curwin->w_p_so;
13406}
13407
13408/*
13409 * Return the effective 'sidescrolloff' value for the current window, using the
13410 * global value when appropriate.
13411 */
13412 long
13413get_sidescrolloff_value(void)
13414{
13415 return curwin->w_p_siso < 0 ? p_siso : curwin->w_p_siso;
13416}
13417
13418/*
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013419 * Check matchpairs option for "*initc".
13420 * If there is a match set "*initc" to the matching character and "*findc" to
13421 * the opposite character. Set "*backwards" to the direction.
13422 * When "switchit" is TRUE swap the direction.
13423 */
13424 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010013425find_mps_values(
13426 int *initc,
13427 int *findc,
13428 int *backwards,
13429 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013430{
13431 char_u *ptr;
13432
13433 ptr = curbuf->b_p_mps;
13434 while (*ptr != NUL)
13435 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013436 if (has_mbyte)
13437 {
13438 char_u *prev;
13439
13440 if (mb_ptr2char(ptr) == *initc)
13441 {
13442 if (switchit)
13443 {
13444 *findc = *initc;
13445 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13446 *backwards = TRUE;
13447 }
13448 else
13449 {
13450 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13451 *backwards = FALSE;
13452 }
13453 return;
13454 }
13455 prev = ptr;
13456 ptr += mb_ptr2len(ptr) + 1;
13457 if (mb_ptr2char(ptr) == *initc)
13458 {
13459 if (switchit)
13460 {
13461 *findc = *initc;
13462 *initc = mb_ptr2char(prev);
13463 *backwards = FALSE;
13464 }
13465 else
13466 {
13467 *findc = mb_ptr2char(prev);
13468 *backwards = TRUE;
13469 }
13470 return;
13471 }
13472 ptr += mb_ptr2len(ptr);
13473 }
13474 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013475 {
13476 if (*ptr == *initc)
13477 {
13478 if (switchit)
13479 {
13480 *backwards = TRUE;
13481 *findc = *initc;
13482 *initc = ptr[2];
13483 }
13484 else
13485 {
13486 *backwards = FALSE;
13487 *findc = ptr[2];
13488 }
13489 return;
13490 }
13491 ptr += 2;
13492 if (*ptr == *initc)
13493 {
13494 if (switchit)
13495 {
13496 *backwards = FALSE;
13497 *findc = *initc;
13498 *initc = ptr[-2];
13499 }
13500 else
13501 {
13502 *backwards = TRUE;
13503 *findc = ptr[-2];
13504 }
13505 return;
13506 }
13507 ++ptr;
13508 }
13509 if (*ptr == ',')
13510 ++ptr;
13511 }
13512}
Bram Moolenaar597a4222014-06-25 14:39:50 +020013513
13514#if defined(FEAT_LINEBREAK) || defined(PROTO)
13515/*
13516 * This is called when 'breakindentopt' is changed and when a window is
13517 * initialized.
13518 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013519 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013520briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020013521{
13522 char_u *p;
13523 int bri_shift = 0;
13524 long bri_min = 20;
13525 int bri_sbr = FALSE;
13526
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013527 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013528 while (*p != NUL)
13529 {
13530 if (STRNCMP(p, "shift:", 6) == 0
13531 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
13532 {
13533 p += 6;
13534 bri_shift = getdigits(&p);
13535 }
13536 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
13537 {
13538 p += 4;
13539 bri_min = getdigits(&p);
13540 }
13541 else if (STRNCMP(p, "sbr", 3) == 0)
13542 {
13543 p += 3;
13544 bri_sbr = TRUE;
13545 }
13546 if (*p != ',' && *p != NUL)
13547 return FAIL;
13548 if (*p == ',')
13549 ++p;
13550 }
13551
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013552 wp->w_p_brishift = bri_shift;
13553 wp->w_p_brimin = bri_min;
13554 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013555
13556 return OK;
13557}
13558#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013559
13560/*
13561 * Get the local or global value of 'backupcopy'.
13562 */
13563 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013564get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013565{
13566 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
13567}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020013568
13569#if defined(FEAT_SIGNS) || defined(PROTO)
13570/*
13571 * Return TRUE when window "wp" has a column to draw signs in.
13572 */
13573 int
13574signcolumn_on(win_T *wp)
13575{
Bram Moolenaar394c5d82019-06-17 21:48:05 +020013576 // If 'signcolumn' is set to 'number', signs are displayed in the 'number'
13577 // column (if present). Otherwise signs are to be displayed in the sign
13578 // column.
13579 if (*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
13580 return wp->w_buffer->b_signlist != NULL && !wp->w_p_nu && !wp->w_p_rnu;
13581
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020013582 if (*wp->w_p_scl == 'n')
13583 return FALSE;
13584 if (*wp->w_p_scl == 'y')
13585 return TRUE;
13586 return (wp->w_buffer->b_signlist != NULL
13587# ifdef FEAT_NETBEANS_INTG
13588 || wp->w_buffer->b_has_sign_column
13589# endif
13590 );
13591}
13592#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013593
13594#if defined(FEAT_EVAL) || defined(PROTO)
13595/*
13596 * Get window or buffer local options.
13597 */
13598 dict_T *
13599get_winbuf_options(int bufopt)
13600{
13601 dict_T *d;
13602 int opt_idx;
13603
13604 d = dict_alloc();
13605 if (d == NULL)
13606 return NULL;
13607
13608 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
13609 {
13610 struct vimoption *opt = &options[opt_idx];
13611
13612 if ((bufopt && (opt->indir & PV_BUF))
13613 || (!bufopt && (opt->indir & PV_WIN)))
13614 {
13615 char_u *varp = get_varp(opt);
13616
13617 if (varp != NULL)
13618 {
13619 if (opt->flags & P_STRING)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013620 dict_add_string(d, opt->fullname, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020013621 else if (opt->flags & P_NUM)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013622 dict_add_number(d, opt->fullname, *(long *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013623 else
Bram Moolenaare0be1672018-07-08 16:50:37 +020013624 dict_add_number(d, opt->fullname, *(int *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013625 }
13626 }
13627 }
13628
13629 return d;
13630}
13631#endif