blob: fdad20551816d4bede020f0870fd2cd944cd78e8 [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 Moolenaarac3150d2019-07-28 16:36:39 +0200896 {"completeslash", "csl", P_STRING|P_VI_DEF|P_VIM,
897#if defined(FEAT_INS_EXPAND) && defined(BACKSLASH_IN_FILENAME)
898 (char_u *)&p_csl, PV_CSL,
899 {(char_u *)"", (char_u *)0L}
900#else
901 (char_u *)NULL, PV_NONE,
902 {(char_u *)0L, (char_u *)0L}
903#endif
904 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000905 {"confirm", "cf", P_BOOL|P_VI_DEF,
906#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
907 (char_u *)&p_confirm, PV_NONE,
908#else
909 (char_u *)NULL, PV_NONE,
910#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200911 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000912 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000913 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200914 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000915 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
916 (char_u *)&p_ci, PV_CI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200917 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000918 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
919 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000920 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200921 SCTX_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200922 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200923#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200924 (char_u *)&p_cm, PV_CM,
Bram Moolenaara86187b2018-12-16 18:20:00 +0100925 {(char_u *)"blowfish2", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200926#else
927 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200928 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200929#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200930 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000931 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
932#ifdef FEAT_CSCOPE
933 (char_u *)&p_cspc, PV_NONE,
934#else
935 (char_u *)NULL, PV_NONE,
936#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200937 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000938 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
939#ifdef FEAT_CSCOPE
940 (char_u *)&p_csprg, PV_NONE,
941 {(char_u *)"cscope", (char_u *)0L}
942#else
943 (char_u *)NULL, PV_NONE,
944 {(char_u *)0L, (char_u *)0L}
945#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200946 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200947 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000948#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
949 (char_u *)&p_csqf, PV_NONE,
950 {(char_u *)"", (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 Moolenaarf7befa92011-06-12 22:13:40 +0200956 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
957#ifdef FEAT_CSCOPE
958 (char_u *)&p_csre, PV_NONE,
959#else
960 (char_u *)NULL, PV_NONE,
961#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200962 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000963 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
964#ifdef FEAT_CSCOPE
965 (char_u *)&p_cst, PV_NONE,
966#else
967 (char_u *)NULL, PV_NONE,
968#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200969 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000970 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
971#ifdef FEAT_CSCOPE
972 (char_u *)&p_csto, PV_NONE,
973#else
974 (char_u *)NULL, PV_NONE,
975#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200976 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000977 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
978#ifdef FEAT_CSCOPE
979 (char_u *)&p_csverbose, PV_NONE,
980#else
981 (char_u *)NULL, PV_NONE,
982#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200983 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200984 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200985 (char_u *)VAR_WIN, PV_CRBIND,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200986 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar177ab9e2019-01-15 21:12:57 +0100987 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000988#ifdef FEAT_SYN_HL
989 (char_u *)VAR_WIN, PV_CUC,
990#else
991 (char_u *)NULL, PV_NONE,
992#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200993 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100994 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000995#ifdef FEAT_SYN_HL
996 (char_u *)VAR_WIN, PV_CUL,
997#else
998 (char_u *)NULL, PV_NONE,
999#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001000 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001001 {"debug", NULL, P_STRING|P_VI_DEF,
1002 (char_u *)&p_debug, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001003 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001004 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001005#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001006 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001007 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001008#else
1009 (char_u *)NULL, PV_NONE,
1010 {(char_u *)NULL, (char_u *)0L}
1011#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001012 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001013 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001014 (char_u *)&p_deco, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001015 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001016 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001017#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001018 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001019#else
1020 (char_u *)NULL, PV_NONE,
1021#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001022 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001023 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1024#ifdef FEAT_DIFF
1025 (char_u *)VAR_WIN, PV_DIFF,
1026#else
1027 (char_u *)NULL, PV_NONE,
1028#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001029 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001030 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001031#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1032 (char_u *)&p_dex, PV_NONE,
1033 {(char_u *)"", (char_u *)0L}
1034#else
1035 (char_u *)NULL, PV_NONE,
1036 {(char_u *)0L, (char_u *)0L}
1037#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001038 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001039 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1040 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001041#ifdef FEAT_DIFF
1042 (char_u *)&p_dip, PV_NONE,
Bram Moolenaarc93262b2018-09-10 21:15:40 +02001043 {(char_u *)"internal,filler", (char_u *)NULL}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001044#else
1045 (char_u *)NULL, PV_NONE,
1046 {(char_u *)"", (char_u *)NULL}
1047#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001048 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001049 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1050#ifdef FEAT_DIGRAPHS
1051 (char_u *)&p_dg, PV_NONE,
1052#else
1053 (char_u *)NULL, PV_NONE,
1054#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001055 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001056 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1057 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001058 (char_u *)&p_dir, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001059 {(char_u *)DFLT_DIR, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001060 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001061 (char_u *)&p_dy, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001062 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001063 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001064 (char_u *)&p_ead, PV_NONE,
1065 {(char_u *)"both", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001066 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001067 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1068 (char_u *)&p_ed, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001069 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001070 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaar3848e002016-03-19 18:42:29 +01001071 (char_u *)&p_emoji, PV_NONE,
1072 {(char_u *)TRUE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001073 SCTX_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001074 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001075 (char_u *)&p_enc, PV_NONE,
1076 {(char_u *)ENC_DFLT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001077 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001078 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1079 (char_u *)&p_eol, PV_EOL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001080 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001081 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1082 (char_u *)&p_ea, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001083 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001084 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001085 (char_u *)&p_ep, PV_EP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001086 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001087 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1088 (char_u *)&p_eb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001089 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001090 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1091#ifdef FEAT_QUICKFIX
1092 (char_u *)&p_ef, PV_NONE,
1093 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1094#else
1095 (char_u *)NULL, PV_NONE,
1096 {(char_u *)NULL, (char_u *)0L}
1097#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001098 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001099 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001100#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001101 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001102 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001103#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 Moolenaar071d4272004-06-13 20:20:40 +00001108 {"esckeys", "ek", P_BOOL|P_VIM,
1109 (char_u *)&p_ek, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001110 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001111 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001112 (char_u *)&p_ei, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001113 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001114 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1115 (char_u *)&p_et, PV_ET,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001116 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001117 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1118 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001119 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001120 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1121 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001122 (char_u *)&p_fenc, PV_FENC,
1123 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001124 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001125 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001126 (char_u *)&p_fencs, PV_NONE,
1127 {(char_u *)"ucs-bom", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001128 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001129 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1130 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001131 (char_u *)&p_ff, PV_FF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001132 {(char_u *)DFLT_FF, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001133 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001134 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001135 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001136 SCTX_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001137 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1138 (char_u *)&p_fic, PV_NONE,
1139 {
1140#ifdef CASE_INSENSITIVE_FILENAME
1141 (char_u *)TRUE,
1142#else
1143 (char_u *)FALSE,
1144#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001145 (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001146 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001147 (char_u *)&p_ft, PV_FT,
1148 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001149 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001150 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001151 (char_u *)&p_fcs, PV_NONE,
1152 {(char_u *)"vert:|,fold:-", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001153 SCTX_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001154 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1155 (char_u *)&p_fixeol, PV_FIXEOL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001156 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001157 {"fkmap", "fk", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001158 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001159 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001160 {"flash", "fl", P_BOOL|P_VI_DEF,
1161 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001162 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001163 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001164#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001165 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001166 {(char_u *)"", (char_u *)0L}
1167#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001168 (char_u *)NULL, PV_NONE,
1169 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001170#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001171 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001172 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1173#ifdef FEAT_FOLDING
1174 (char_u *)VAR_WIN, PV_FDC,
1175 {(char_u *)FALSE, (char_u *)0L}
1176#else
1177 (char_u *)NULL, PV_NONE,
1178 {(char_u *)NULL, (char_u *)0L}
1179#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001180 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001181 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1182#ifdef FEAT_FOLDING
1183 (char_u *)VAR_WIN, PV_FEN,
1184 {(char_u *)TRUE, (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 Moolenaar110289e2019-05-23 15:38:06 +02001190 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN|P_MLE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001191#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1192 (char_u *)VAR_WIN, PV_FDE,
1193 {(char_u *)"0", (char_u *)NULL}
1194#else
1195 (char_u *)NULL, PV_NONE,
1196 {(char_u *)NULL, (char_u *)0L}
1197#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001198 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001199 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001200#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001201 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001202 {(char_u *)"#", (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 {"foldlevel", "fdl", P_NUM|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_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001211 {(char_u *)0L, (char_u *)0L}
1212#else
1213 (char_u *)NULL, PV_NONE,
1214 {(char_u *)NULL, (char_u *)0L}
1215#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001216 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001217 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001218#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001219 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001220 {(char_u *)-1L, (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 Moolenaar071d4272004-06-13 20:20:40 +00001226 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001227 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001228#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001229 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001230 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001231#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001232 (char_u *)NULL, PV_NONE,
1233 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001234#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001235 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001236 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1237#ifdef FEAT_FOLDING
1238 (char_u *)VAR_WIN, PV_FDM,
1239 {(char_u *)"manual", (char_u *)NULL}
1240#else
1241 (char_u *)NULL, PV_NONE,
1242 {(char_u *)NULL, (char_u *)0L}
1243#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001244 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001245 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1246#ifdef FEAT_FOLDING
1247 (char_u *)VAR_WIN, PV_FML,
1248 {(char_u *)1L, (char_u *)0L}
1249#else
1250 (char_u *)NULL, PV_NONE,
1251 {(char_u *)NULL, (char_u *)0L}
1252#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001253 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001254 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1255#ifdef FEAT_FOLDING
1256 (char_u *)VAR_WIN, PV_FDN,
1257 {(char_u *)20L, (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 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1264#ifdef FEAT_FOLDING
1265 (char_u *)&p_fdo, PV_NONE,
1266 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1267 (char_u *)0L}
1268#else
1269 (char_u *)NULL, PV_NONE,
1270 {(char_u *)NULL, (char_u *)0L}
1271#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001272 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001273 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN|P_MLE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001274#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1275 (char_u *)VAR_WIN, PV_FDT,
1276 {(char_u *)"foldtext()", (char_u *)NULL}
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 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM|P_MLE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001283#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001284 (char_u *)&p_fex, PV_FEX,
1285 {(char_u *)"", (char_u *)0L}
1286#else
1287 (char_u *)NULL, PV_NONE,
1288 {(char_u *)0L, (char_u *)0L}
1289#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001290 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001291 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1292 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001293 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001294 SCTX_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001295 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1296 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001297 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001298 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001299 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001300 (char_u *)&p_fp, PV_FP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001301 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001302 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1303#ifdef HAVE_FSYNC
1304 (char_u *)&p_fs, PV_NONE,
1305 {(char_u *)TRUE, (char_u *)0L}
1306#else
1307 (char_u *)NULL, PV_NONE,
1308 {(char_u *)FALSE, (char_u *)0L}
1309#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001310 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001311 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1312 (char_u *)&p_gd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001313 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001314 {"graphic", "gr", P_BOOL|P_VI_DEF,
1315 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001316 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001317 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001318#ifdef FEAT_QUICKFIX
1319 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001320 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001321#else
1322 (char_u *)NULL, PV_NONE,
1323 {(char_u *)NULL, (char_u *)0L}
1324#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001325 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001326 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1327#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001328 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001329 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01001330# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001331 /* may be changed to "grep -n" in os_win32.c */
1332 (char_u *)"findstr /n",
1333# else
1334# ifdef UNIX
1335 /* Add an extra file name so that grep will always
1336 * insert a file name in the match line. */
1337 (char_u *)"grep -n $* /dev/null",
1338# else
1339# ifdef VMS
1340 (char_u *)"SEARCH/NUMBERS ",
1341# else
1342 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001343# endif
1344# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001345# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001346 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001347#else
1348 (char_u *)NULL, PV_NONE,
1349 {(char_u *)NULL, (char_u *)0L}
1350#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001351 SCTX_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001352 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001353#ifdef CURSOR_SHAPE
1354 (char_u *)&p_guicursor, PV_NONE,
1355 {
1356# ifdef FEAT_GUI
1357 (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 +01001358# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001359 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1360# endif
1361 (char_u *)0L}
1362#else
1363 (char_u *)NULL, PV_NONE,
1364 {(char_u *)NULL, (char_u *)0L}
1365#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001366 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001367 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001368#ifdef FEAT_GUI
1369 (char_u *)&p_guifont, PV_NONE,
1370 {(char_u *)"", (char_u *)0L}
1371#else
1372 (char_u *)NULL, PV_NONE,
1373 {(char_u *)NULL, (char_u *)0L}
1374#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001375 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001376 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001377#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1378 (char_u *)&p_guifontset, 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 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001386#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001387 (char_u *)&p_guifontwide, 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 Moolenaar071d4272004-06-13 20:20:40 +00001394 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001395#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001396 (char_u *)&p_ghr, PV_NONE,
1397#else
1398 (char_u *)NULL, PV_NONE,
1399#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001400 {(char_u *)50L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001401 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001402#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001403 (char_u *)&p_go, PV_NONE,
Bram Moolenaard0573012017-10-28 21:11:06 +02001404# if defined(UNIX) && !defined(FEAT_GUI_MAC)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001405 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001406# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001407 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001408# endif
1409#else
1410 (char_u *)NULL, PV_NONE,
1411 {(char_u *)NULL, (char_u *)0L}
1412#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001413 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001414 {"guipty", NULL, P_BOOL|P_VI_DEF,
1415#if defined(FEAT_GUI)
1416 (char_u *)&p_guipty, PV_NONE,
1417#else
1418 (char_u *)NULL, PV_NONE,
1419#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001420 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001421 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN|P_MLE,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001422#if defined(FEAT_GUI_TABLINE)
1423 (char_u *)&p_gtl, PV_NONE,
1424 {(char_u *)"", (char_u *)0L}
1425#else
1426 (char_u *)NULL, PV_NONE,
1427 {(char_u *)NULL, (char_u *)0L}
1428#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001429 SCTX_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001430 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001431#if defined(FEAT_GUI_TABLINE)
1432 (char_u *)&p_gtt, 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 Moolenaar071d4272004-06-13 20:20:40 +00001439 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1440 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001441 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001442 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1443 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001444 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001445 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001446 {"helpheight", "hh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001447 (char_u *)&p_hh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001448 {(char_u *)20L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001449 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001450#ifdef FEAT_MULTI_LANG
1451 (char_u *)&p_hlg, PV_NONE,
1452 {(char_u *)"", (char_u *)0L}
1453#else
1454 (char_u *)NULL, PV_NONE,
1455 {(char_u *)0L, (char_u *)0L}
1456#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001457 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001458 {"hidden", "hid", P_BOOL|P_VI_DEF,
1459 (char_u *)&p_hid, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001460 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001461 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001462 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001463 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001464 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001465 {"history", "hi", P_NUM|P_VIM,
1466 (char_u *)&p_hi, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001467 {(char_u *)0L, (char_u *)50L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001468 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1469#ifdef FEAT_RIGHTLEFT
1470 (char_u *)&p_hkmap, PV_NONE,
1471#else
1472 (char_u *)NULL, PV_NONE,
1473#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001474 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001475 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1476#ifdef FEAT_RIGHTLEFT
1477 (char_u *)&p_hkmapp, PV_NONE,
1478#else
1479 (char_u *)NULL, PV_NONE,
1480#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001481 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001482 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1483 (char_u *)&p_hls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001484 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001485 {"icon", NULL, P_BOOL|P_VI_DEF,
1486#ifdef FEAT_TITLE
1487 (char_u *)&p_icon, PV_NONE,
1488#else
1489 (char_u *)NULL, PV_NONE,
1490#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001491 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001492 {"iconstring", NULL, P_STRING|P_VI_DEF|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001493#ifdef FEAT_TITLE
1494 (char_u *)&p_iconstring, PV_NONE,
1495#else
1496 (char_u *)NULL, PV_NONE,
1497#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001498 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001499 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1500 (char_u *)&p_ic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001501 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001502 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001503#if defined(FEAT_EVAL)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001504 (char_u *)&p_imaf, PV_NONE,
1505 {(char_u *)"", (char_u *)NULL}
1506# else
1507 (char_u *)NULL, PV_NONE,
1508 {(char_u *)NULL, (char_u *)0L}
1509# endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001510 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001511 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001512#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001513 (char_u *)&p_imak, PV_NONE,
1514#else
1515 (char_u *)NULL, PV_NONE,
1516#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001517 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001518 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001519 (char_u *)&p_imcmdline, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001520 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001521 {"imdisable", "imd", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001522 (char_u *)&p_imdisable, PV_NONE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001523#ifdef __sgi
1524 {(char_u *)TRUE, (char_u *)0L}
1525#else
1526 {(char_u *)FALSE, (char_u *)0L}
1527#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001528 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001529 {"iminsert", "imi", P_NUM|P_VI_DEF,
1530 (char_u *)&p_iminsert, PV_IMI,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001531 {(char_u *)B_IMODE_NONE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001532 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001533 {"imsearch", "ims", P_NUM|P_VI_DEF,
1534 (char_u *)&p_imsearch, PV_IMS,
Bram Moolenaar4cf56bb2017-09-16 15:50:32 +02001535 {(char_u *)B_IMODE_USE_INSERT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001536 SCTX_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001537 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001538#if defined(FEAT_EVAL)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001539 (char_u *)&p_imsf, PV_NONE,
1540 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001541#else
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001542 (char_u *)NULL, PV_NONE,
1543 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001544#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001545 SCTX_INIT},
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001546 {"imstyle", "imst", P_NUM|P_VI_DEF|P_SECURE,
1547#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1548 (char_u *)&p_imst, PV_NONE,
1549 {(char_u *)IM_OVER_THE_SPOT, (char_u *)0L}
1550#else
1551 (char_u *)NULL, PV_NONE,
1552 {(char_u *)0L, (char_u *)0L}
1553#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001554 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001555 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1556#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001557 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001558 {(char_u *)"^\\s*#\\s*include", (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 Moolenaar110289e2019-05-23 15:38:06 +02001564 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001565#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1566 (char_u *)&p_inex, PV_INEX,
1567 {(char_u *)"", (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 Moolenaar071d4272004-06-13 20:20:40 +00001573 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1574 (char_u *)&p_is, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001575 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001576 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001577#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1578 (char_u *)&p_inde, PV_INDE,
1579 {(char_u *)"", (char_u *)0L}
1580#else
1581 (char_u *)NULL, PV_NONE,
1582 {(char_u *)0L, (char_u *)0L}
1583#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001584 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001585 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001586#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1587 (char_u *)&p_indk, PV_INDK,
Bram Moolenaarce655742019-01-31 14:12:57 +01001588 {INDENTKEYS_DEFAULT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001589#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 Moolenaar071d4272004-06-13 20:20:40 +00001594 {"infercase", "inf", P_BOOL|P_VI_DEF,
1595 (char_u *)&p_inf, PV_INF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001596 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001597 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1598 (char_u *)&p_im, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001599 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001600 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1601 (char_u *)&p_isf, PV_NONE,
1602 {
1603#ifdef BACKSLASH_IN_FILENAME
1604 /* Excluded are: & and ^ are special in cmd.exe
1605 * ( and ) are used in text separating fnames */
1606 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1607#else
1608# ifdef AMIGA
1609 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1610# else
1611# ifdef VMS
1612 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1613# else /* UNIX et al. */
1614# ifdef EBCDIC
1615 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1616# else
1617 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1618# endif
1619# endif
1620# endif
1621#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001622 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001623 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1624 (char_u *)&p_isi, PV_NONE,
1625 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001626#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001627 (char_u *)"@,48-57,_,128-167,224-235",
1628#else
1629# ifdef EBCDIC
1630 /* TODO: EBCDIC Check this! @ == isalpha()*/
1631 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1632 "112-120,128,140-142,156,158,172,"
1633 "174,186,191,203-207,219-225,235-239,"
1634 "251-254",
1635# else
1636 (char_u *)"@,48-57,_,192-255",
1637# endif
1638#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001639 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001640 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1641 (char_u *)&p_isk, PV_ISK,
1642 {
1643#ifdef EBCDIC
1644 (char_u *)"@,240-249,_",
1645 /* TODO: EBCDIC Check this! @ == isalpha()*/
1646 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1647 "112-120,128,140-142,156,158,172,"
1648 "174,186,191,203-207,219-225,235-239,"
1649 "251-254",
1650#else
1651 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001652# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001653 (char_u *)"@,48-57,_,128-167,224-235"
1654# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001655 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001656# endif
1657#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001658 } SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001659 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1660 (char_u *)&p_isp, PV_NONE,
1661 {
Bram Moolenaard0573012017-10-28 21:11:06 +02001662#if defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001663 (char_u *)"@,~-255",
1664#else
1665# ifdef EBCDIC
1666 /* all chars above 63 are printable */
1667 (char_u *)"63-255",
1668# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001669 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001670# endif
1671#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001672 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001673 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1674 (char_u *)&p_js, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001675 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001676 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1677#ifdef FEAT_CRYPT
1678 (char_u *)&p_key, PV_KEY,
1679 {(char_u *)"", (char_u *)0L}
1680#else
1681 (char_u *)NULL, PV_NONE,
1682 {(char_u *)0L, (char_u *)0L}
1683#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001684 SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001685 {"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 +00001686#ifdef FEAT_KEYMAP
1687 (char_u *)&p_keymap, PV_KMAP,
1688 {(char_u *)"", (char_u *)0L}
1689#else
1690 (char_u *)NULL, PV_NONE,
1691 {(char_u *)"", (char_u *)0L}
1692#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001693 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001694 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001695 (char_u *)&p_km, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001696 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001697 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001698 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001699 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001700#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001701 (char_u *)":help",
1702#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001703# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001704 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001705# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001706# ifdef USEMAN_S
1707 (char_u *)"man -s",
1708# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001709 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001710# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001711# endif
1712#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001713 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001714 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001715#ifdef FEAT_LANGMAP
1716 (char_u *)&p_langmap, PV_NONE,
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001717 {(char_u *)"", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001718#else
1719 (char_u *)NULL, PV_NONE,
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001720 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001721#endif
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001722 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001723 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001724#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1725 (char_u *)&p_lm, PV_NONE,
1726#else
1727 (char_u *)NULL, PV_NONE,
1728#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001729 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001730 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1731#ifdef FEAT_LANGMAP
1732 (char_u *)&p_lnr, PV_NONE,
1733#else
1734 (char_u *)NULL, PV_NONE,
1735#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001736 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001737 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1738#ifdef FEAT_LANGMAP
1739 (char_u *)&p_lrm, PV_NONE,
1740#else
1741 (char_u *)NULL, PV_NONE,
1742#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001743 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001744 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001745 (char_u *)&p_ls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001746 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001747 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1748 (char_u *)&p_lz, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001749 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001750 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1751#ifdef FEAT_LINEBREAK
1752 (char_u *)VAR_WIN, PV_LBR,
1753#else
1754 (char_u *)NULL, PV_NONE,
1755#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001756 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001757 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1758 (char_u *)&Rows, PV_NONE,
1759 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01001760#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001761 (char_u *)25L,
1762#else
1763 (char_u *)24L,
1764#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001765 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001766 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1767#ifdef FEAT_GUI
1768 (char_u *)&p_linespace, PV_NONE,
1769#else
1770 (char_u *)NULL, PV_NONE,
1771#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01001772#ifdef FEAT_GUI_MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001773 {(char_u *)1L, (char_u *)0L}
1774#else
1775 {(char_u *)0L, (char_u *)0L}
1776#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001777 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001778 {"lisp", NULL, P_BOOL|P_VI_DEF,
1779#ifdef FEAT_LISP
1780 (char_u *)&p_lisp, PV_LISP,
1781#else
1782 (char_u *)NULL, PV_NONE,
1783#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001784 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001785 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001786#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001787 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001788 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1789#else
1790 (char_u *)NULL, PV_NONE,
1791 {(char_u *)"", (char_u *)0L}
1792#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001793 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001794 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1795 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001796 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001797 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001798 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001799 {(char_u *)"eol:$", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001800 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1801 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001802 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001803 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001804#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001805 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001806 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001807#else
1808 (char_u *)NULL, PV_NONE,
1809 {(char_u *)"", (char_u *)0L}
1810#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001811 SCTX_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001812 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001813#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001814 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001815 {(char_u *)TRUE, (char_u *)0L}
1816#else
1817 (char_u *)NULL, PV_NONE,
1818 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001819#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001820 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001821 {"magic", NULL, P_BOOL|P_VI_DEF,
1822 (char_u *)&p_magic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001823 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001824 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001825#ifdef FEAT_QUICKFIX
1826 (char_u *)&p_mef, PV_NONE,
1827 {(char_u *)"", (char_u *)0L}
1828#else
1829 (char_u *)NULL, PV_NONE,
1830 {(char_u *)NULL, (char_u *)0L}
1831#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001832 SCTX_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001833 {"makeencoding","menc", P_STRING|P_VI_DEF,
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001834 (char_u *)&p_menc, PV_MENC,
1835 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001836 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001837 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1838#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001839 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001840# ifdef VMS
1841 {(char_u *)"MMS", (char_u *)0L}
1842# else
1843 {(char_u *)"make", (char_u *)0L}
1844# endif
1845#else
1846 (char_u *)NULL, PV_NONE,
1847 {(char_u *)NULL, (char_u *)0L}
1848#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001849 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001850 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001851 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001852 {(char_u *)"(:),{:},[:]", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001853 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001854 {"matchtime", "mat", P_NUM|P_VI_DEF,
1855 (char_u *)&p_mat, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001856 {(char_u *)5L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001857 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001858 (char_u *)&p_mco, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001859 {(char_u *)2, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001860 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1861#ifdef FEAT_EVAL
1862 (char_u *)&p_mfd, PV_NONE,
1863#else
1864 (char_u *)NULL, PV_NONE,
1865#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001866 {(char_u *)100L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001867 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1868 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001869 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001870 {"maxmem", "mm", P_NUM|P_VI_DEF,
1871 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001872 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001873 SCTX_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001874 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1875 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001876 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001877 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1878 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001879 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001880 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001881 {"menuitems", "mis", P_NUM|P_VI_DEF,
1882#ifdef FEAT_MENU
1883 (char_u *)&p_mis, PV_NONE,
1884#else
1885 (char_u *)NULL, PV_NONE,
1886#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001887 {(char_u *)25L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001888 {"mesg", NULL, P_BOOL|P_VI_DEF,
1889 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001890 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001891 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001892#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001893 (char_u *)&p_msm, PV_NONE,
1894 {(char_u *)"460000,2000,500", (char_u *)0L}
1895#else
1896 (char_u *)NULL, PV_NONE,
1897 {(char_u *)0L, (char_u *)0L}
1898#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001899 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001900 {"modeline", "ml", P_BOOL|P_VIM,
1901 (char_u *)&p_ml, PV_ML,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001902 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar7e800c62019-05-23 17:08:49 +02001903 {"modelineexpr", "mle", P_BOOL|P_VI_DEF|P_SECURE,
Bram Moolenaar110289e2019-05-23 15:38:06 +02001904 (char_u *)&p_mle, PV_NONE,
1905 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001906 {"modelines", "mls", P_NUM|P_VI_DEF,
1907 (char_u *)&p_mls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001908 {(char_u *)5L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001909 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1910 (char_u *)&p_ma, PV_MA,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001911 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001912 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1913 (char_u *)&p_mod, PV_MOD,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001914 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001915 {"more", NULL, P_BOOL|P_VIM,
1916 (char_u *)&p_more, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001917 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001918 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1919 (char_u *)&p_mouse, PV_NONE,
1920 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01001921#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001922 (char_u *)"a",
1923#else
1924 (char_u *)"",
1925#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001926 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001927 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1928#ifdef FEAT_GUI
1929 (char_u *)&p_mousef, PV_NONE,
1930#else
1931 (char_u *)NULL, PV_NONE,
1932#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001933 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001934 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1935#ifdef FEAT_GUI
1936 (char_u *)&p_mh, PV_NONE,
1937#else
1938 (char_u *)NULL, PV_NONE,
1939#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001940 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001941 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1942 (char_u *)&p_mousem, PV_NONE,
1943 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001944#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001945 (char_u *)"popup",
1946#else
Bram Moolenaard0573012017-10-28 21:11:06 +02001947# if defined(MACOS_X)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001948 (char_u *)"popup_setpos",
1949# else
1950 (char_u *)"extend",
1951# endif
1952#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001953 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001954 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001955#ifdef FEAT_MOUSESHAPE
1956 (char_u *)&p_mouseshape, PV_NONE,
1957 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1958#else
1959 (char_u *)NULL, PV_NONE,
1960 {(char_u *)NULL, (char_u *)0L}
1961#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001962 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001963 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1964 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001965 {(char_u *)500L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02001966 {"mzschemedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1967#if defined(DYNAMIC_MZSCHEME)
1968 (char_u *)&p_mzschemedll, PV_NONE,
1969 {(char_u *)DYNAMIC_MZSCH_DLL, (char_u *)0L}
1970#else
1971 (char_u *)NULL, PV_NONE,
1972 {(char_u *)"", (char_u *)0L}
1973#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001974 SCTX_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02001975 {"mzschemegcdll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1976#if defined(DYNAMIC_MZSCHEME)
1977 (char_u *)&p_mzschemegcdll, PV_NONE,
1978 {(char_u *)DYNAMIC_MZGC_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 Moolenaar325b7a22004-07-05 15:58:32 +00001984 {"mzquantum", "mzq", P_NUM,
1985#ifdef FEAT_MZSCHEME
1986 (char_u *)&p_mzq, PV_NONE,
1987#else
1988 (char_u *)NULL, PV_NONE,
1989#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001990 {(char_u *)100L, (char_u *)100L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001991 {"novice", NULL, P_BOOL|P_VI_DEF,
1992 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001993 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001994 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001995 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01001996 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001997 SCTX_INIT},
Bram Moolenaar2b044ff2019-06-24 05:45:14 +02001998 {"number", "nu", P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001999 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002000 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002001 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
2002#ifdef FEAT_LINEBREAK
2003 (char_u *)VAR_WIN, PV_NUW,
2004#else
2005 (char_u *)NULL, PV_NONE,
2006#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002007 {(char_u *)8L, (char_u *)4L} SCTX_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00002008 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00002009#ifdef FEAT_COMPL_FUNC
2010 (char_u *)&p_ofu, PV_OFU,
2011 {(char_u *)"", (char_u *)0L}
2012#else
2013 (char_u *)NULL, PV_NONE,
2014 {(char_u *)0L, (char_u *)0L}
2015#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002016 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002017 {"open", NULL, P_BOOL|P_VI_DEF,
2018 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002019 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002020 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002021#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002022 (char_u *)&p_odev, PV_NONE,
2023#else
2024 (char_u *)NULL, PV_NONE,
2025#endif
2026 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002027 SCTX_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002028 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2029 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002030 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002031 {"optimize", "opt", P_BOOL|P_VI_DEF,
2032 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002033 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002034 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002035 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002036 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002037 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2038 |P_SECURE,
2039 (char_u *)&p_pp, PV_NONE,
2040 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002041 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002042 {"paragraphs", "para", P_STRING|P_VI_DEF,
2043 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002044 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002045 (char_u *)0L} SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002046 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002047 (char_u *)&p_paste, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002048 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002049 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2050 (char_u *)&p_pt, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002051 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002052 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2053#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2054 (char_u *)&p_pex, PV_NONE,
2055 {(char_u *)"", (char_u *)0L}
2056#else
2057 (char_u *)NULL, PV_NONE,
2058 {(char_u *)0L, (char_u *)0L}
2059#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002060 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002061 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002062 (char_u *)&p_pm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002063 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002064 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002065 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002066 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002067#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002068 (char_u *)".,,",
2069#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002070 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002071#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002072 (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002073 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002074#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002075 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002076 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002077#else
2078 (char_u *)NULL, PV_NONE,
2079 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002080#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002081 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002082 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2083 (char_u *)&p_pi, PV_PI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002084 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002085 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002086#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002087 (char_u *)&p_pvh, PV_NONE,
2088#else
2089 (char_u *)NULL, PV_NONE,
2090#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002091 {(char_u *)12L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar79648732019-07-18 21:43:07 +02002092 {"previewpopup", "pvp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2093#ifdef FEAT_TEXT_PROP
2094 (char_u *)&p_pvp, PV_NONE,
2095 {(char_u *)"", (char_u *)0L}
2096#else
2097 (char_u *)NULL, PV_NONE,
2098 {(char_u *)NULL, (char_u *)0L}
2099#endif
2100 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002101 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002102#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002103 (char_u *)VAR_WIN, PV_PVW,
2104#else
2105 (char_u *)NULL, PV_NONE,
2106#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002107 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002108 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002109#ifdef FEAT_PRINTER
2110 (char_u *)&p_pdev, PV_NONE,
2111 {(char_u *)"", (char_u *)0L}
2112#else
2113 (char_u *)NULL, PV_NONE,
2114 {(char_u *)NULL, (char_u *)0L}
2115#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002116 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002117 {"printencoding", "penc", P_STRING|P_VI_DEF,
2118#ifdef FEAT_POSTSCRIPT
2119 (char_u *)&p_penc, 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 Moolenaar031cb742016-11-24 21:46:19 +01002126 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002127#ifdef FEAT_POSTSCRIPT
2128 (char_u *)&p_pexpr, 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 Moolenaar071d4272004-06-13 20:20:40 +00002135 {"printfont", "pfn", P_STRING|P_VI_DEF,
2136#ifdef FEAT_PRINTER
2137 (char_u *)&p_pfn, PV_NONE,
2138 {
2139# ifdef MSWIN
2140 (char_u *)"Courier_New:h10",
2141# else
2142 (char_u *)"courier",
2143# endif
2144 (char_u *)0L}
2145#else
2146 (char_u *)NULL, PV_NONE,
2147 {(char_u *)NULL, (char_u *)0L}
2148#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002149 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002150 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2151#ifdef FEAT_PRINTER
2152 (char_u *)&p_header, PV_NONE,
Bram Moolenaar0903d562017-08-26 22:30:15 +02002153 /* untranslated to avoid problems when 'encoding'
2154 * is changed */
2155 {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002156#else
2157 (char_u *)NULL, PV_NONE,
2158 {(char_u *)NULL, (char_u *)0L}
2159#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002160 SCTX_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002161 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01002162#if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002163 (char_u *)&p_pmcs, PV_NONE,
2164 {(char_u *)"", (char_u *)0L}
2165#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 {"printmbfont", "pmbfn", 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_pmfn, 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 Moolenaar0e7c4b92015-06-20 15:30:03 +02002179 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002180#ifdef FEAT_PRINTER
2181 (char_u *)&p_popt, 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 Moolenaar071d4272004-06-13 20:20:40 +00002188 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002189 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002190 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002191 {"pumheight", "ph", P_NUM|P_VI_DEF,
2192#ifdef FEAT_INS_EXPAND
2193 (char_u *)&p_ph, PV_NONE,
2194#else
2195 (char_u *)NULL, PV_NONE,
2196#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002197 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaara8f04aa2018-02-10 15:36:55 +01002198 {"pumwidth", "pw", P_NUM|P_VI_DEF,
2199#ifdef FEAT_INS_EXPAND
2200 (char_u *)&p_pw, PV_NONE,
2201#else
2202 (char_u *)NULL, PV_NONE,
2203#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002204 {(char_u *)15L, (char_u *)15L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002205 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002206#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002207 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002208 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002209#else
2210 (char_u *)NULL, PV_NONE,
2211 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002212#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002213 SCTX_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002214 {"pythonthreehome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2215#if defined(FEAT_PYTHON3)
2216 (char_u *)&p_py3home, PV_NONE,
2217 {(char_u *)"", (char_u *)0L}
2218#else
2219 (char_u *)NULL, PV_NONE,
2220 {(char_u *)NULL, (char_u *)0L}
2221#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002222 SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002223 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002224#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002225 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002226 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002227#else
2228 (char_u *)NULL, PV_NONE,
2229 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002230#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002231 SCTX_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002232 {"pythonhome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2233#if defined(FEAT_PYTHON)
2234 (char_u *)&p_pyhome, PV_NONE,
2235 {(char_u *)"", (char_u *)0L}
2236#else
2237 (char_u *)NULL, PV_NONE,
2238 {(char_u *)NULL, (char_u *)0L}
2239#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002240 SCTX_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002241 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2242#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2243 (char_u *)&p_pyx, PV_NONE,
2244#else
2245 (char_u *)NULL, PV_NONE,
2246#endif
2247 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002248 SCTX_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002249 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2250#ifdef FEAT_TEXTOBJ
2251 (char_u *)&p_qe, PV_QE,
2252 {(char_u *)"\\", (char_u *)0L}
2253#else
2254 (char_u *)NULL, PV_NONE,
2255 {(char_u *)NULL, (char_u *)0L}
2256#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002257 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002258 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2259 (char_u *)&p_ro, PV_RO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002260 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002261 {"redraw", NULL, P_BOOL|P_VI_DEF,
2262 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002263 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002264 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2265#ifdef FEAT_RELTIME
2266 (char_u *)&p_rdt, PV_NONE,
2267#else
2268 (char_u *)NULL, PV_NONE,
2269#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002270 {(char_u *)2000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002271 {"regexpengine", "re", P_NUM|P_VI_DEF,
2272 (char_u *)&p_re, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002273 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar2b044ff2019-06-24 05:45:14 +02002274 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaar64486672010-05-16 15:46:46 +02002275 (char_u *)VAR_WIN, PV_RNU,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002276 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002277 {"remap", NULL, P_BOOL|P_VI_DEF,
2278 (char_u *)&p_remap, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002279 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002280 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002281#ifdef FEAT_RENDER_OPTIONS
2282 (char_u *)&p_rop, PV_NONE,
2283 {(char_u *)"", (char_u *)0L}
2284#else
2285 (char_u *)NULL, PV_NONE,
2286 {(char_u *)NULL, (char_u *)0L}
2287#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002288 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002289 {"report", NULL, P_NUM|P_VI_DEF,
2290 (char_u *)&p_report, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002291 {(char_u *)2L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002292 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
Bram Moolenaar4f974752019-02-17 17:44:42 +01002293#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00002294 (char_u *)&p_rs, PV_NONE,
2295#else
2296 (char_u *)NULL, PV_NONE,
2297#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002298 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002299 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2300#ifdef FEAT_RIGHTLEFT
2301 (char_u *)&p_ri, PV_NONE,
2302#else
2303 (char_u *)NULL, PV_NONE,
2304#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002305 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002306 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2307#ifdef FEAT_RIGHTLEFT
2308 (char_u *)VAR_WIN, PV_RL,
2309#else
2310 (char_u *)NULL, PV_NONE,
2311#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002312 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002313 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2314#ifdef FEAT_RIGHTLEFT
2315 (char_u *)VAR_WIN, PV_RLC,
2316 {(char_u *)"search", (char_u *)NULL}
2317#else
2318 (char_u *)NULL, PV_NONE,
2319 {(char_u *)NULL, (char_u *)0L}
2320#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002321 SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002322 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002323#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002324 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002325 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002326#else
2327 (char_u *)NULL, PV_NONE,
2328 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002329#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002330 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002331 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2332#ifdef FEAT_CMDL_INFO
2333 (char_u *)&p_ru, PV_NONE,
2334#else
2335 (char_u *)NULL, PV_NONE,
2336#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002337 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02002338 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002339#ifdef FEAT_STL_OPT
2340 (char_u *)&p_ruf, PV_NONE,
2341#else
2342 (char_u *)NULL, PV_NONE,
2343#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002344 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002345 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2346 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002347 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002348 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002349 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002350 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2351 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002352 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002353 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002354 (char_u *)VAR_WIN, PV_SCBIND,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002355 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002356 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2357 (char_u *)&p_sj, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002358 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002359 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
Bram Moolenaar375e3392019-01-31 18:26:10 +01002360 (char_u *)&p_so, PV_SO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002361 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002362 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002363 (char_u *)&p_sbo, PV_NONE,
2364 {(char_u *)"ver,jump", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002365 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002366 {"sections", "sect", P_STRING|P_VI_DEF,
2367 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002368 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002369 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002370 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2371 (char_u *)&p_secure, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002372 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002373 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002374 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002375 {(char_u *)"inclusive", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002376 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002377 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002378 (char_u *)&p_slm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002379 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002380 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002381#ifdef FEAT_SESSION
2382 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar4d8bac82018-03-09 21:33:34 +01002383 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize,terminal",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002384 (char_u *)0L}
2385#else
2386 (char_u *)NULL, PV_NONE,
2387 {(char_u *)0L, (char_u *)0L}
2388#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002389 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002390 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2391 (char_u *)&p_sh, PV_NONE,
2392 {
2393#ifdef VMS
2394 (char_u *)"-",
2395#else
Bram Moolenaar4f974752019-02-17 17:44:42 +01002396# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002397 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002398# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002399 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002400# endif
2401#endif /* VMS */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002402 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002403 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2404 (char_u *)&p_shcf, PV_NONE,
2405 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002406#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002407 (char_u *)"/c",
2408#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002409 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002410#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002411 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002412 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2413#ifdef FEAT_QUICKFIX
2414 (char_u *)&p_sp, PV_NONE,
2415 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002416#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002417 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002418#else
2419 (char_u *)">",
2420#endif
2421 (char_u *)0L}
2422#else
2423 (char_u *)NULL, PV_NONE,
2424 {(char_u *)0L, (char_u *)0L}
2425#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002426 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002427 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2428 (char_u *)&p_shq, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002429 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002430 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2431 (char_u *)&p_srr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002432 {(char_u *)">", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002433 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2434#ifdef BACKSLASH_IN_FILENAME
2435 (char_u *)&p_ssl, PV_NONE,
2436#else
2437 (char_u *)NULL, PV_NONE,
2438#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002439 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002440 {"shelltemp", "stmp", P_BOOL,
2441 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002442 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002443 {"shelltype", "st", P_NUM|P_VI_DEF,
2444#ifdef AMIGA
2445 (char_u *)&p_st, PV_NONE,
2446#else
2447 (char_u *)NULL, PV_NONE,
2448#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002449 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002450 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2451 (char_u *)&p_sxq, PV_NONE,
2452 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002453#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002454 (char_u *)"\"",
2455#else
2456 (char_u *)"",
2457#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002458 (char_u *)0L} SCTX_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002459 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2460 (char_u *)&p_sxe, PV_NONE,
2461 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01002462#if defined(MSWIN)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002463 (char_u *)"\"&|<>()@^",
2464#else
2465 (char_u *)"",
2466#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002467 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002468 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2469 (char_u *)&p_sr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002470 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002471 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2472 (char_u *)&p_sw, PV_SW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002473 {(char_u *)8L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002474 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2475 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar9dfa3132019-05-04 21:08:40 +02002476 {(char_u *)"S", (char_u *)"filnxtToOS"}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002477 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002478 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002479 (char_u *)&p_sn, PV_SN,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002480 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002481 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2482#ifdef FEAT_LINEBREAK
2483 (char_u *)&p_sbr, PV_NONE,
2484#else
2485 (char_u *)NULL, PV_NONE,
2486#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002487 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002488 {"showcmd", "sc", P_BOOL|P_VIM,
2489#ifdef FEAT_CMDL_INFO
2490 (char_u *)&p_sc, PV_NONE,
2491#else
2492 (char_u *)NULL, PV_NONE,
2493#endif
2494 {(char_u *)FALSE,
2495#ifdef UNIX
2496 (char_u *)FALSE
2497#else
2498 (char_u *)TRUE
2499#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002500 } SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002501 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2502 (char_u *)&p_sft, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002503 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002504 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2505 (char_u *)&p_sm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002506 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002507 {"showmode", "smd", P_BOOL|P_VIM,
2508 (char_u *)&p_smd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002509 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002510 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002511 (char_u *)&p_stal, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002512 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002513 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2514 (char_u *)&p_ss, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002515 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002516 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar375e3392019-01-31 18:26:10 +01002517 (char_u *)&p_siso, PV_SISO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002518 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar2b044ff2019-06-24 05:45:14 +02002519 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RCLR,
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002520#ifdef FEAT_SIGNS
2521 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002522 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002523#else
2524 (char_u *)NULL, PV_NONE,
2525 {(char_u *)NULL, (char_u *)0L}
2526#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002527 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002528 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2529 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002530 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002531 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2532 (char_u *)&p_scs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002533 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002534 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2535#ifdef FEAT_SMARTINDENT
2536 (char_u *)&p_si, PV_SI,
2537#else
2538 (char_u *)NULL, PV_NONE,
2539#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002540 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002541 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2542 (char_u *)&p_sta, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002543 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002544 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2545 (char_u *)&p_sts, PV_STS,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002546 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002547 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2548 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002549 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002550 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002551#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002552 (char_u *)VAR_WIN, PV_SPELL,
2553#else
2554 (char_u *)NULL, PV_NONE,
2555#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002556 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002557 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002558#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002559 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002560 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002561#else
2562 (char_u *)NULL, PV_NONE,
2563 {(char_u *)0L, (char_u *)0L}
2564#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002565 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002566 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2567 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002568#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002569 (char_u *)&p_spf, PV_SPF,
2570 {(char_u *)"", (char_u *)0L}
2571#else
2572 (char_u *)NULL, PV_NONE,
2573 {(char_u *)0L, (char_u *)0L}
2574#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002575 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002576 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2577 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002578#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002579 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002580 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002581#else
2582 (char_u *)NULL, PV_NONE,
2583 {(char_u *)0L, (char_u *)0L}
2584#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002585 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002586 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002587#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002588 (char_u *)&p_sps, PV_NONE,
2589 {(char_u *)"best", (char_u *)0L}
2590#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 Moolenaar071d4272004-06-13 20:20:40 +00002595 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002596 (char_u *)&p_sb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002597 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002598 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002599 (char_u *)&p_spr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002600 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002601 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2602 (char_u *)&p_sol, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002603 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02002604 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002605#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002606 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002607#else
2608 (char_u *)NULL, PV_NONE,
2609#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002610 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002611 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002612 (char_u *)&p_su, PV_NONE,
2613 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002614 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002615 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002616#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002617 (char_u *)&p_sua, PV_SUA,
2618 {(char_u *)"", (char_u *)0L}
2619#else
2620 (char_u *)NULL, PV_NONE,
2621 {(char_u *)0L, (char_u *)0L}
2622#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002623 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002624 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2625 (char_u *)&p_swf, PV_SWF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002626 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002627 {"swapsync", "sws", P_STRING|P_VI_DEF,
2628 (char_u *)&p_sws, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002629 {(char_u *)"fsync", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002630 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002631 (char_u *)&p_swb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002632 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002633 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2634#ifdef FEAT_SYN_HL
2635 (char_u *)&p_smc, PV_SMC,
2636 {(char_u *)3000L, (char_u *)0L}
2637#else
2638 (char_u *)NULL, PV_NONE,
2639 {(char_u *)0L, (char_u *)0L}
2640#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002641 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002642 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002643#ifdef FEAT_SYN_HL
2644 (char_u *)&p_syn, PV_SYN,
2645 {(char_u *)"", (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 Moolenaar110289e2019-05-23 15:38:06 +02002651 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL|P_MLE,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002652#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002653 (char_u *)&p_tal, PV_NONE,
2654#else
2655 (char_u *)NULL, PV_NONE,
2656#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002657 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002658 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002659 (char_u *)&p_tpm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002660 {(char_u *)10L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002661 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2662 (char_u *)&p_ts, PV_TS,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002663 {(char_u *)8L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002664 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2665 (char_u *)&p_tbs, PV_NONE,
2666#ifdef VMS /* binary searching doesn't appear to work on VMS */
2667 {(char_u *)0L, (char_u *)0L}
2668#else
2669 {(char_u *)TRUE, (char_u *)0L}
2670#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002671 SCTX_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002672 {"tagcase", "tc", P_STRING|P_VIM,
2673 (char_u *)&p_tc, PV_TC,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002674 {(char_u *)"followic", (char_u *)"followic"} SCTX_INIT},
Bram Moolenaar45e18cb2019-04-28 18:05:35 +02002675 {"tagfunc", "tfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
2676#ifdef FEAT_EVAL
2677 (char_u *)&p_tfu, PV_TFU,
2678 {(char_u *)"", (char_u *)0L}
2679#else
2680 (char_u *)NULL, PV_NONE,
2681 {(char_u *)0L, (char_u *)0L}
2682#endif
2683 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002684 {"taglength", "tl", P_NUM|P_VI_DEF,
2685 (char_u *)&p_tl, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002686 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002687 {"tagrelative", "tr", P_BOOL|P_VIM,
2688 (char_u *)&p_tr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002689 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002690 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002691 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002692 {
2693#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2694 (char_u *)"./tags,./TAGS,tags,TAGS",
2695#else
2696 (char_u *)"./tags,tags",
2697#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002698 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002699 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2700 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002701 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002702 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002703#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002704 (char_u *)&p_tcldll, PV_NONE,
2705 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002706#else
2707 (char_u *)NULL, PV_NONE,
2708 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002709#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002710 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002711 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2712 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002713 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002714 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2715#ifdef FEAT_ARABIC
2716 (char_u *)&p_tbidi, PV_NONE,
2717#else
2718 (char_u *)NULL, PV_NONE,
2719#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002720 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002721 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002722 (char_u *)&p_tenc, PV_NONE,
2723 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002724 SCTX_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002725 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2726#ifdef FEAT_TERMGUICOLORS
2727 (char_u *)&p_tgc, PV_NONE,
2728 {(char_u *)FALSE, (char_u *)FALSE}
2729#else
2730 (char_u*)NULL, PV_NONE,
2731 {(char_u *)FALSE, (char_u *)FALSE}
2732#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002733 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002734 {"termwinkey", "twk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2735#ifdef FEAT_TERMINAL
2736 (char_u *)VAR_WIN, PV_TWK,
2737 {(char_u *)"", (char_u *)NULL}
2738#else
2739 (char_u *)NULL, PV_NONE,
2740 {(char_u *)NULL, (char_u *)0L}
2741#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002742 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002743 {"termwinscroll", "twsl", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2744#ifdef FEAT_TERMINAL
2745 (char_u *)&p_twsl, PV_TWSL,
2746 {(char_u *)10000L, (char_u *)10000L}
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 {"termwinsize", "tws", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2753#ifdef FEAT_TERMINAL
2754 (char_u *)VAR_WIN, PV_TWS,
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002755 {(char_u *)"", (char_u *)NULL}
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 Moolenaarc6ddce32019-02-08 12:47:03 +01002761 {"termwintype", "twt", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar4f974752019-02-17 17:44:42 +01002762#if defined(MSWIN) && defined(FEAT_TERMINAL)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01002763 (char_u *)&p_twt, PV_NONE,
2764 {(char_u *)"", (char_u *)NULL}
2765#else
2766 (char_u *)NULL, PV_NONE,
2767 {(char_u *)NULL, (char_u *)0L}
2768#endif
2769 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002770 {"terse", NULL, P_BOOL|P_VI_DEF,
2771 (char_u *)&p_terse, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002772 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002773 {"textauto", "ta", P_BOOL|P_VIM,
2774 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002775 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002776 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002777 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2778 (char_u *)&p_tx, PV_TX,
2779 {
2780#ifdef USE_CRNL
2781 (char_u *)TRUE,
2782#else
2783 (char_u *)FALSE,
2784#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002785 (char_u *)0L} SCTX_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002786 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002787 (char_u *)&p_tw, PV_TW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002788 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002789 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002790#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002791 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002792#else
2793 (char_u *)NULL, PV_NONE,
2794#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002795 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002796 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2797 (char_u *)&p_to, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002798 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002799 {"timeout", "to", P_BOOL|P_VI_DEF,
2800 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002801 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002802 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2803 (char_u *)&p_tm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002804 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002805 {"title", NULL, P_BOOL|P_VI_DEF,
2806#ifdef FEAT_TITLE
2807 (char_u *)&p_title, PV_NONE,
2808#else
2809 (char_u *)NULL, PV_NONE,
2810#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002811 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002812 {"titlelen", NULL, P_NUM|P_VI_DEF,
2813#ifdef FEAT_TITLE
2814 (char_u *)&p_titlelen, PV_NONE,
2815#else
2816 (char_u *)NULL, PV_NONE,
2817#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002818 {(char_u *)85L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002819 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002820#ifdef FEAT_TITLE
2821 (char_u *)&p_titleold, PV_NONE,
2822 {(char_u *)N_("Thanks for flying Vim"),
2823 (char_u *)0L}
2824#else
2825 (char_u *)NULL, PV_NONE,
2826 {(char_u *)0L, (char_u *)0L}
2827#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002828 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02002829 {"titlestring", NULL, P_STRING|P_VI_DEF|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002830#ifdef FEAT_TITLE
2831 (char_u *)&p_titlestring, PV_NONE,
2832#else
2833 (char_u *)NULL, PV_NONE,
2834#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002835 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002836 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar4f974752019-02-17 17:44:42 +01002837#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002838 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002839 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002840#else
2841 (char_u *)NULL, PV_NONE,
2842 {(char_u *)0L, (char_u *)0L}
2843#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002844 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002845 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002846#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002847 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002848 {(char_u *)"small", (char_u *)0L}
2849#else
2850 (char_u *)NULL, PV_NONE,
2851 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002852#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002853 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002854 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2855 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002856 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002857 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2858 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002859 {(char_u *)-1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002860 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2861 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002862 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002863 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2864 (char_u *)&p_tf, 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 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2867#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2868 (char_u *)&p_ttym, PV_NONE,
2869#else
2870 (char_u *)NULL, PV_NONE,
2871#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002872 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002873 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2874 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002875 {(char_u *)999L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002876 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2877 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002878 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002879 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2880 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002881#ifdef FEAT_PERSISTENT_UNDO
2882 (char_u *)&p_udir, PV_NONE,
2883 {(char_u *)".", (char_u *)0L}
2884#else
2885 (char_u *)NULL, PV_NONE,
2886 {(char_u *)0L, (char_u *)0L}
2887#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002888 SCTX_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002889 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2890#ifdef FEAT_PERSISTENT_UNDO
2891 (char_u *)&p_udf, PV_UDF,
2892#else
2893 (char_u *)NULL, PV_NONE,
2894#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002895 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002896 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002897 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002898 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01002899#if defined(UNIX) || defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002900 (char_u *)1000L,
2901#else
2902 (char_u *)100L,
2903#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002904 (char_u *)0L} SCTX_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002905 {"undoreload", "ur", P_NUM|P_VI_DEF,
2906 (char_u *)&p_ur, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002907 { (char_u *)10000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002908 {"updatecount", "uc", P_NUM|P_VI_DEF,
2909 (char_u *)&p_uc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002910 {(char_u *)200L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002911 {"updatetime", "ut", P_NUM|P_VI_DEF,
2912 (char_u *)&p_ut, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002913 {(char_u *)4000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar04958cb2018-06-23 19:23:02 +02002914 {"varsofttabstop", "vsts", P_STRING|P_VI_DEF|P_VIM|P_COMMA,
2915#ifdef FEAT_VARTABS
2916 (char_u *)&p_vsts, PV_VSTS,
2917 {(char_u *)"", (char_u *)0L}
2918#else
2919 (char_u *)NULL, PV_NONE,
2920 {(char_u *)"", (char_u *)NULL}
2921#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002922 SCTX_INIT},
Bram Moolenaar04958cb2018-06-23 19:23:02 +02002923 {"vartabstop", "vts", P_STRING|P_VI_DEF|P_VIM|P_RBUF|P_COMMA,
2924#ifdef FEAT_VARTABS
2925 (char_u *)&p_vts, PV_VTS,
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 Moolenaar071d4272004-06-13 20:20:40 +00002932 {"verbose", "vbs", P_NUM|P_VI_DEF,
2933 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002934 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002935 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2936 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002937 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002938 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2939#ifdef FEAT_SESSION
2940 (char_u *)&p_vdir, PV_NONE,
2941 {(char_u *)DFLT_VDIR, (char_u *)0L}
2942#else
2943 (char_u *)NULL, PV_NONE,
2944 {(char_u *)0L, (char_u *)0L}
2945#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002946 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002947 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002948#ifdef FEAT_SESSION
2949 (char_u *)&p_vop, PV_NONE,
Bram Moolenaar13e90412017-11-11 18:16:48 +01002950 {(char_u *)"folds,options,cursor,curdir",
2951 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002952#else
2953 (char_u *)NULL, PV_NONE,
2954 {(char_u *)0L, (char_u *)0L}
2955#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002956 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002957 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002958#ifdef FEAT_VIMINFO
2959 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002960#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002961 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002962#else
2963# ifdef AMIGA
2964 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002965 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002966# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002967 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002968# endif
2969#endif
2970#else
2971 (char_u *)NULL, PV_NONE,
2972 {(char_u *)0L, (char_u *)0L}
2973#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002974 SCTX_INIT},
Bram Moolenaarc229e542018-07-08 21:46:56 +02002975 {"viminfofile", "vif", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP
2976 |P_SECURE|P_VI_DEF,
Bram Moolenaarc4da1132017-07-15 19:39:43 +02002977#ifdef FEAT_VIMINFO
2978 (char_u *)&p_viminfofile, PV_NONE,
2979 {(char_u *)"", (char_u *)0L}
2980#else
2981 (char_u *)NULL, PV_NONE,
2982 {(char_u *)0L, (char_u *)0L}
2983#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002984 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002985 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2986 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002987 (char_u *)&p_ve, PV_NONE,
2988 {(char_u *)"", (char_u *)""}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002989 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002990 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2991 (char_u *)&p_vb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002992 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002993 {"w300", NULL, P_NUM|P_VI_DEF,
2994 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002995 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002996 {"w1200", NULL, P_NUM|P_VI_DEF,
2997 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002998 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002999 {"w9600", NULL, P_NUM|P_VI_DEF,
3000 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003001 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003002 {"warn", NULL, P_BOOL|P_VI_DEF,
3003 (char_u *)&p_warn, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003004 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003005 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
3006 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003007 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003008 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003009 (char_u *)&p_ww, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003010 {(char_u *)"", (char_u *)"b,s"} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003011 {"wildchar", "wc", P_NUM|P_VIM,
3012 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003013 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003014 SCTX_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003015 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003016 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003017 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003018 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003019#ifdef FEAT_WILDIGN
3020 (char_u *)&p_wig, PV_NONE,
3021#else
3022 (char_u *)NULL, PV_NONE,
3023#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003024 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003025 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3026 (char_u *)&p_wic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003027 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003028 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
3029#ifdef FEAT_WILDMENU
3030 (char_u *)&p_wmnu, PV_NONE,
3031#else
3032 (char_u *)NULL, PV_NONE,
3033#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003034 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003035 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003036 (char_u *)&p_wim, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003037 {(char_u *)"full", (char_u *)0L} SCTX_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003038 {"wildoptions", "wop", P_STRING|P_VI_DEF,
3039#ifdef FEAT_CMDL_COMPL
3040 (char_u *)&p_wop, PV_NONE,
3041 {(char_u *)"", (char_u *)0L}
3042#else
3043 (char_u *)NULL, PV_NONE,
3044 {(char_u *)NULL, (char_u *)0L}
3045#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003046 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003047 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3048#ifdef FEAT_WAK
3049 (char_u *)&p_wak, PV_NONE,
3050 {(char_u *)"menu", (char_u *)0L}
3051#else
3052 (char_u *)NULL, PV_NONE,
3053 {(char_u *)NULL, (char_u *)0L}
3054#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003055 SCTX_INIT},
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003056 {"wincolor", "wcr", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
3057 (char_u *)VAR_WIN, PV_WCR,
3058 {(char_u *)"", (char_u *)NULL}
3059 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003060 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003061 (char_u *)&p_window, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003062 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003063 {"winheight", "wh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003064 (char_u *)&p_wh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003065 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003066 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003067 (char_u *)VAR_WIN, PV_WFH,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003068 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003069 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003070 (char_u *)VAR_WIN, PV_WFW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003071 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003072 {"winminheight", "wmh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003073 (char_u *)&p_wmh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003074 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003075 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003076 (char_u *)&p_wmw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003077 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003078 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar4f974752019-02-17 17:44:42 +01003079#if defined(MSWIN) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003080 (char_u *)&p_winptydll, PV_NONE, {
3081# ifdef _WIN64
3082 (char_u *)"winpty64.dll",
3083# else
3084 (char_u *)"winpty32.dll",
3085# endif
3086 (char_u *)0L}
3087#else
3088 (char_u *)NULL, PV_NONE,
3089 {(char_u *)0L, (char_u *)0L}
3090#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003091 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003092 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003093 (char_u *)&p_wiw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003094 {(char_u *)20L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003095 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3096 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003097 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003098 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3099 (char_u *)&p_wm, PV_WM,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003100 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003101 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3102 (char_u *)&p_ws, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003103 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003104 {"write", NULL, P_BOOL|P_VI_DEF,
3105 (char_u *)&p_write, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003106 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003107 {"writeany", "wa", P_BOOL|P_VI_DEF,
3108 (char_u *)&p_wa, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003109 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003110 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3111 (char_u *)&p_wb, PV_NONE,
3112 {
3113#ifdef FEAT_WRITEBACKUP
3114 (char_u *)TRUE,
3115#else
3116 (char_u *)FALSE,
3117#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003118 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003119 {"writedelay", "wd", P_NUM|P_VI_DEF,
3120 (char_u *)&p_wd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003121 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003122
3123/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003124#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003125 (char_u *)&vvv, PV_NONE, \
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003126 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003127
3128 p_term("t_AB", T_CAB)
3129 p_term("t_AF", T_CAF)
3130 p_term("t_AL", T_CAL)
3131 p_term("t_al", T_AL)
3132 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003133 p_term("t_BE", T_BE)
3134 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003135 p_term("t_cd", T_CD)
3136 p_term("t_ce", T_CE)
3137 p_term("t_cl", T_CL)
3138 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003139 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003140 p_term("t_Co", T_CCO)
3141 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003142 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003143 p_term("t_cs", T_CS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003144 p_term("t_CV", T_CSV)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003145 p_term("t_da", T_DA)
3146 p_term("t_db", T_DB)
3147 p_term("t_DL", T_CDL)
3148 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003149 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003150 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003151 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003152 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003153 p_term("t_IE", T_CIE)
3154 p_term("t_IS", T_CIS)
3155 p_term("t_ke", T_KE)
3156 p_term("t_ks", T_KS)
3157 p_term("t_le", T_LE)
3158 p_term("t_mb", T_MB)
3159 p_term("t_md", T_MD)
3160 p_term("t_me", T_ME)
3161 p_term("t_mr", T_MR)
3162 p_term("t_ms", T_MS)
3163 p_term("t_nd", T_ND)
3164 p_term("t_op", T_OP)
Bram Moolenaara20f83d2017-10-15 13:35:01 +02003165 p_term("t_RF", T_RFG)
Bram Moolenaare5401222015-06-25 19:16:56 +02003166 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003167 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003168 p_term("t_RI", T_CRI)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003169 p_term("t_Ri", T_SRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003170 p_term("t_RS", T_CRS)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003171 p_term("t_RT", T_CRT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003172 p_term("t_RV", T_CRV)
3173 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003174 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003175 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003176 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003177 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003178 p_term("t_SI", T_CSI)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003179 p_term("t_Si", T_SSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003180 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003181 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003182 p_term("t_sr", T_SR)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003183 p_term("t_ST", T_CST)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003184 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003185 p_term("t_te", T_TE)
3186 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003187 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003188 p_term("t_ts", T_TS)
3189 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003190 p_term("t_ue", T_UE)
3191 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003192 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003193 p_term("t_vb", T_VB)
3194 p_term("t_ve", T_VE)
3195 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003196 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003197 p_term("t_vs", T_VS)
3198 p_term("t_WP", T_CWP)
3199 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003200 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003201 p_term("t_xs", T_XS)
3202 p_term("t_ZH", T_CZH)
3203 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003204 p_term("t_8f", T_8F)
3205 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003206
3207/* terminal key codes are not in here */
3208
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003209 /* end marker */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003210 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCTX_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003211};
3212
3213#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3214
Bram Moolenaar071d4272004-06-13 20:20:40 +00003215static char *(p_ambw_values[]) = {"single", "double", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003216static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003217static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003218static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003219#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003220static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003221#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003222#ifdef FEAT_CMDL_COMPL
3223static char *(p_wop_values[]) = {"tagfile", NULL};
3224#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003225#ifdef FEAT_WAK
3226static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3227#endif
3228static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003229static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3230static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003231static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003232#ifdef FEAT_BROWSE
3233static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3234#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003235static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
Bram Moolenaar57657d82006-04-21 22:12:41 +00003236static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003237static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003238static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", "prompt", "popup", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003239static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003240static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3241#ifdef FEAT_FOLDING
3242static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003243# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003244 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003245# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003246 NULL};
3247static char *(p_fcl_values[]) = {"all", NULL};
3248#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003249#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003250static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaarac3150d2019-07-28 16:36:39 +02003251# ifdef BACKSLASH_IN_FILENAME
3252static char *(p_csl_values[]) = {"slash", "backslash", NULL};
3253# endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003254#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003255#ifdef FEAT_SIGNS
Bram Moolenaar394c5d82019-06-17 21:48:05 +02003256static char *(p_scl_values[]) = {"yes", "no", "auto", "number", NULL};
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003257#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01003258#if defined(MSWIN) && defined(FEAT_TERMINAL)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01003259static char *(p_twt_values[]) = {"winpty", "conpty", "", NULL};
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01003260#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003261
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003262static void set_options_default(int opt_flags);
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003263static void set_string_default_esc(char *name, char_u *val, int escape);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003264static char_u *term_bg_default(void);
Bram Moolenaar916a8182018-11-25 02:18:29 +01003265static void did_set_option(int opt_idx, int opt_flags, int new_value, int value_checked);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003266static char_u *option_expand(int opt_idx, char_u *val);
3267static void didset_options(void);
3268static void didset_options2(void);
3269static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003270#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003271static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003272#else
3273# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3274#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003275static void set_string_option_global(int opt_idx, char_u **varp);
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003276static 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);
3277static char *set_chars_option(char_u **varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003278#ifdef FEAT_CLIPBOARD
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003279static char *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003280#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003281#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003282static char *did_set_spell_option(int is_spellfile);
3283static char *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003284#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003285#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003286static void set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003287#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003288static char *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3289static 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 +01003290static void check_redraw(long_u flags);
3291static int findoption(char_u *);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02003292static int find_key_option(char_u *arg_arg, int has_lt);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003293static void showoptions(int all, int opt_flags);
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02003294static int optval_default(struct vimoption *, char_u *varp, int compatible);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003295static void showoneopt(struct vimoption *, int opt_flags);
Bram Moolenaared18f2c2019-01-24 20:30:52 +01003296static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, long_u flags);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003297static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3298static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3299static int istermoption(struct vimoption *);
3300static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3301static char_u *get_varp(struct vimoption *);
3302static void option_value2string(struct vimoption *, int opt_flags);
3303static void check_winopt(winopt_T *wop);
3304static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003305#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003306static void langmap_init(void);
3307static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003308#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003309static void paste_option_changed(void);
3310static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003311#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003312static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003313#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003314static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3315static int check_opt_strings(char_u *val, char **values, int);
3316static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003317#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003318static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003319#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003320
3321/*
3322 * Initialize the options, first part.
3323 *
3324 * Called only once from main(), just after creating the first buffer.
Bram Moolenaar07268702018-03-01 21:57:32 +01003325 * If "clean_arg" is TRUE Vim was started with --clean.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003326 */
3327 void
Bram Moolenaar07268702018-03-01 21:57:32 +01003328set_init_1(int clean_arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003329{
3330 char_u *p;
3331 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003332 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003333
3334#ifdef FEAT_LANGMAP
3335 langmap_init();
3336#endif
3337
3338 /* Be Vi compatible by default */
3339 p_cp = TRUE;
3340
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003341 /* Use POSIX compatibility when $VIM_POSIX is set. */
3342 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003343 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003344 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar9dfa3132019-05-04 21:08:40 +02003345 set_string_default("shm", (char_u *)SHM_POSIX);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003346 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003347
Bram Moolenaar071d4272004-06-13 20:20:40 +00003348 /*
3349 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003350 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003351 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003352 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003353#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003354 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003355 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003356#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003357 )
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003358 set_string_default_esc("sh", p, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003359
3360#ifdef FEAT_WILDIGN
3361 /*
3362 * Set the default for 'backupskip' to include environment variables for
3363 * temp files.
3364 */
3365 {
3366# ifdef UNIX
3367 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3368# else
3369 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3370# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003371 int len;
3372 garray_T ga;
3373 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003374
3375 ga_init2(&ga, 1, 100);
3376 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3377 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003378 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003379# ifdef UNIX
3380 if (*names[n] == NUL)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003381# ifdef MACOS_X
3382 p = (char_u *)"/private/tmp";
3383# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003384 p = (char_u *)"/tmp";
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003385# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003386 else
3387# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003388 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003389 if (p != NULL && *p != NUL)
3390 {
3391 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003392 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003393 if (ga_grow(&ga, len) == OK)
3394 {
3395 if (ga.ga_len > 0)
3396 STRCAT(ga.ga_data, ",");
3397 STRCAT(ga.ga_data, p);
3398 add_pathsep(ga.ga_data);
3399 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003400 ga.ga_len += len;
3401 }
3402 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003403 if (mustfree)
3404 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003405 }
3406 if (ga.ga_data != NULL)
3407 {
3408 set_string_default("bsk", ga.ga_data);
3409 vim_free(ga.ga_data);
3410 }
3411 }
3412#endif
3413
3414 /*
3415 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3416 */
3417 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003418 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003419 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003420#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3421 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3422#endif
3423 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003424#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003425 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003426 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003427#else
3428# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003429 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003430 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003431# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003432 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003433# endif
3434#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003435 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003436 opt_idx = findoption((char_u *)"maxmem");
3437 if (opt_idx >= 0)
3438 {
3439#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003440 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3441 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003442#endif
3443 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3444 }
3445 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003446 }
3447
Bram Moolenaar071d4272004-06-13 20:20:40 +00003448#ifdef FEAT_SEARCHPATH
3449 {
3450 char_u *cdpath;
3451 char_u *buf;
3452 int i;
3453 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003454 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003455
3456 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003457 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003458 if (cdpath != NULL)
3459 {
Bram Moolenaar964b3742019-05-24 18:54:09 +02003460 buf = alloc((STRLEN(cdpath) << 1) + 2);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003461 if (buf != NULL)
3462 {
3463 buf[0] = ','; /* start with ",", current dir first */
3464 j = 1;
3465 for (i = 0; cdpath[i] != NUL; ++i)
3466 {
3467 if (vim_ispathlistsep(cdpath[i]))
3468 buf[j++] = ',';
3469 else
3470 {
3471 if (cdpath[i] == ' ' || cdpath[i] == ',')
3472 buf[j++] = '\\';
3473 buf[j++] = cdpath[i];
3474 }
3475 }
3476 buf[j] = NUL;
3477 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003478 if (opt_idx >= 0)
3479 {
3480 options[opt_idx].def_val[VI_DEFAULT] = buf;
3481 options[opt_idx].flags |= P_DEF_ALLOCED;
3482 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003483 else
3484 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003485 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003486 if (mustfree)
3487 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003488 }
3489 }
3490#endif
3491
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003492#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003493 /* Set print encoding on platforms that don't default to latin1 */
3494 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003495# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003496 (char_u *)"cp1252"
3497# else
3498# ifdef VMS
3499 (char_u *)"dec-mcs"
3500# else
3501# ifdef EBCDIC
3502 (char_u *)"ebcdic-uk"
3503# else
3504# ifdef MAC
3505 (char_u *)"mac-roman"
3506# else /* HPUX */
3507 (char_u *)"hp-roman8"
3508# endif
3509# endif
3510# endif
3511# endif
3512 );
3513#endif
3514
3515#ifdef FEAT_POSTSCRIPT
3516 /* 'printexpr' must be allocated to be able to evaluate it. */
3517 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003518# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003519 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003520# else
3521# ifdef VMS
3522 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3523
3524# else
3525 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3526# endif
3527# endif
3528 );
3529#endif
3530
3531 /*
3532 * Set all the options (except the terminal options) to their default
3533 * value. Also set the global value for local options.
3534 */
3535 set_options_default(0);
3536
Bram Moolenaar07268702018-03-01 21:57:32 +01003537#ifdef CLEAN_RUNTIMEPATH
3538 if (clean_arg)
3539 {
3540 opt_idx = findoption((char_u *)"runtimepath");
3541 if (opt_idx >= 0)
3542 {
3543 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3544 p_rtp = (char_u *)CLEAN_RUNTIMEPATH;
3545 }
3546 opt_idx = findoption((char_u *)"packpath");
3547 if (opt_idx >= 0)
3548 {
3549 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3550 p_pp = (char_u *)CLEAN_RUNTIMEPATH;
3551 }
3552 }
3553#endif
3554
Bram Moolenaar071d4272004-06-13 20:20:40 +00003555#ifdef FEAT_GUI
3556 if (found_reverse_arg)
3557 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3558#endif
3559
3560 curbuf->b_p_initialized = TRUE;
3561 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003562 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003563 check_buf_options(curbuf);
3564 check_win_options(curwin);
3565 check_options();
3566
3567 /* Must be before option_expand(), because that one needs vim_isIDc() */
3568 didset_options();
3569
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003570#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003571 /* Use the current chartab for the generic chartab. This is not in
3572 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003573 init_spell_chartab();
3574#endif
3575
Bram Moolenaar071d4272004-06-13 20:20:40 +00003576 /*
3577 * Expand environment variables and things like "~" for the defaults.
3578 * If option_expand() returns non-NULL the variable is expanded. This can
3579 * only happen for non-indirect options.
3580 * Also set the default to the expanded value, so ":set" does not list
3581 * them.
3582 * Don't set the P_ALLOCED flag, because we don't want to free the
3583 * default.
3584 */
3585 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3586 {
3587 if ((options[opt_idx].flags & P_GETTEXT)
3588 && options[opt_idx].var != NULL)
3589 p = (char_u *)_(*(char **)options[opt_idx].var);
3590 else
3591 p = option_expand(opt_idx, NULL);
3592 if (p != NULL && (p = vim_strsave(p)) != NULL)
3593 {
3594 *(char_u **)options[opt_idx].var = p;
3595 /* VIMEXP
3596 * Defaults for all expanded options are currently the same for Vi
3597 * and Vim. When this changes, add some code here! Also need to
3598 * split P_DEF_ALLOCED in two.
3599 */
3600 if (options[opt_idx].flags & P_DEF_ALLOCED)
3601 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3602 options[opt_idx].def_val[VI_DEFAULT] = p;
3603 options[opt_idx].flags |= P_DEF_ALLOCED;
3604 }
3605 }
3606
Bram Moolenaar071d4272004-06-13 20:20:40 +00003607 save_file_ff(curbuf); /* Buffer is unchanged */
3608
Bram Moolenaar071d4272004-06-13 20:20:40 +00003609#if defined(FEAT_ARABIC)
3610 /* Detect use of mlterm.
3611 * Mlterm is a terminal emulator akin to xterm that has some special
3612 * abilities (bidi namely).
3613 * NOTE: mlterm's author is being asked to 'set' a variable
3614 * instead of an environment variable due to inheritance.
3615 */
3616 if (mch_getenv((char_u *)"MLTERM") != NULL)
3617 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3618#endif
3619
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003620 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003621
Bram Moolenaar4f974752019-02-17 17:44:42 +01003622# if defined(MSWIN) && defined(FEAT_GETTEXT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003623 /*
3624 * If $LANG isn't set, try to get a good value for it. This makes the
3625 * right language be used automatically. Don't do this for English.
3626 */
3627 if (mch_getenv((char_u *)"LANG") == NULL)
3628 {
3629 char buf[20];
3630
3631 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3632 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3633 * only the first two. */
3634 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3635 (LPTSTR)buf, 20);
3636 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3637 {
3638 /* There are a few exceptions (probably more) */
3639 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3640 STRCPY(buf, "zh_TW");
3641 else if (STRNICMP(buf, "chs", 3) == 0
3642 || STRNICMP(buf, "zhc", 3) == 0)
3643 STRCPY(buf, "zh_CN");
3644 else if (STRNICMP(buf, "jp", 2) == 0)
3645 STRCPY(buf, "ja");
3646 else
3647 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003648 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003649 }
3650 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003651# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003652# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003653 /* Moved to os_mac_conv.c to avoid dependency problems. */
3654 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003655# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003656# endif
3657
3658 /* enc_locale() will try to find the encoding of the current locale. */
3659 p = enc_locale();
3660 if (p != NULL)
3661 {
3662 char_u *save_enc;
3663
3664 /* Try setting 'encoding' and check if the value is valid.
3665 * If not, go back to the default "latin1". */
3666 save_enc = p_enc;
3667 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003668 if (STRCMP(p_enc, "gb18030") == 0)
3669 {
3670 /* We don't support "gb18030", but "cp936" is a good substitute
3671 * for practical purposes, thus use that. It's not an alias to
3672 * still support conversion between gb18030 and utf-8. */
3673 p_enc = vim_strsave((char_u *)"cp936");
3674 vim_free(p);
3675 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003676 if (mb_init() == NULL)
3677 {
3678 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003679 if (opt_idx >= 0)
3680 {
3681 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3682 options[opt_idx].flags |= P_DEF_ALLOCED;
3683 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003684
Bram Moolenaard0573012017-10-28 21:11:06 +02003685#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003686 if (STRCMP(p_enc, "latin1") == 0 || enc_utf8)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003687 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003688 /* Adjust the default for 'isprint' and 'iskeyword' to match
3689 * latin1. Also set the defaults for when 'nocompatible' is
3690 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003691 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003692 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003693 set_string_option_direct((char_u *)"isk", -1,
3694 ISK_LATIN1, OPT_FREE, SID_NONE);
3695 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003696 if (opt_idx >= 0)
3697 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003698 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003699 if (opt_idx >= 0)
3700 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003701 (void)init_chartab();
3702 }
3703#endif
3704
Bram Moolenaarafde13b2019-04-28 19:46:49 +02003705#if defined(MSWIN) && (!defined(FEAT_GUI) || defined(VIMDLL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003706 /* Win32 console: When GetACP() returns a different value from
3707 * GetConsoleCP() set 'termencoding'. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02003708 if (
3709# ifdef VIMDLL
3710 (!gui.in_use && !gui.starting) &&
3711# endif
3712 GetACP() != GetConsoleCP())
Bram Moolenaar071d4272004-06-13 20:20:40 +00003713 {
3714 char buf[50];
3715
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01003716 /* Win32 console: In ConPTY, GetConsoleCP() returns zero.
3717 * Use an alternative value. */
3718 if (GetConsoleCP() == 0)
3719 sprintf(buf, "cp%ld", (long)GetACP());
3720 else
3721 sprintf(buf, "cp%ld", (long)GetConsoleCP());
Bram Moolenaar071d4272004-06-13 20:20:40 +00003722 p_tenc = vim_strsave((char_u *)buf);
3723 if (p_tenc != NULL)
3724 {
3725 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003726 if (opt_idx >= 0)
3727 {
3728 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3729 options[opt_idx].flags |= P_DEF_ALLOCED;
3730 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003731 convert_setup(&input_conv, p_tenc, p_enc);
3732 convert_setup(&output_conv, p_enc, p_tenc);
3733 }
3734 else
3735 p_tenc = empty_option;
3736 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003737#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01003738#if defined(MSWIN)
Bram Moolenaar05159a02005-02-26 23:04:13 +00003739 /* $HOME may have characters in active code page. */
3740 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003741#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003742 }
3743 else
3744 {
3745 vim_free(p_enc);
3746 p_enc = save_enc;
3747 }
3748 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003749
3750#ifdef FEAT_MULTI_LANG
3751 /* Set the default for 'helplang'. */
3752 set_helplang_default(get_mess_lang());
3753#endif
3754}
3755
3756/*
3757 * Set an option to its default value.
3758 * This does not take care of side effects!
3759 */
3760 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003761set_option_default(
3762 int opt_idx,
3763 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3764 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003765{
3766 char_u *varp; /* pointer to variable for current option */
3767 int dvi; /* index in def_val[] */
3768 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003769 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003770 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3771
3772 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3773 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003774 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003775 {
3776 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3777 if (flags & P_STRING)
3778 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003779 /* Use set_string_option_direct() for local options to handle
3780 * freeing and allocating the value. */
3781 if (options[opt_idx].indir != PV_NONE)
3782 set_string_option_direct(NULL, opt_idx,
3783 options[opt_idx].def_val[dvi], opt_flags, 0);
3784 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003785 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003786 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3787 free_string_option(*(char_u **)(varp));
3788 *(char_u **)varp = options[opt_idx].def_val[dvi];
3789 options[opt_idx].flags &= ~P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003790 }
3791 }
3792 else if (flags & P_NUM)
3793 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003794 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003795 win_comp_scroll(curwin);
3796 else
3797 {
Bram Moolenaar375e3392019-01-31 18:26:10 +01003798 long def_val = (long)(long_i)options[opt_idx].def_val[dvi];
3799
3800 if ((long *)varp == &curwin->w_p_so
3801 || (long *)varp == &curwin->w_p_siso)
3802 // 'scrolloff' and 'sidescrolloff' local values have a
3803 // different default value than the global default.
3804 *(long *)varp = -1;
3805 else
3806 *(long *)varp = def_val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003807 /* May also set global value for local option. */
3808 if (both)
3809 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
Bram Moolenaar375e3392019-01-31 18:26:10 +01003810 def_val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003811 }
3812 }
3813 else /* P_BOOL */
3814 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003815 /* the cast to long is required for Manx C, long_i is needed for
3816 * MSVC */
3817 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003818#ifdef UNIX
3819 /* 'modeline' defaults to off for root */
3820 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3821 *(int *)varp = FALSE;
3822#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003823 /* May also set global value for local option. */
3824 if (both)
3825 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3826 *(int *)varp;
3827 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003828
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003829 /* The default value is not insecure. */
3830 flagsp = insecure_flag(opt_idx, opt_flags);
3831 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003832 }
3833
3834#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003835 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003836#endif
3837}
3838
3839/*
3840 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003841 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003842 */
3843 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003844set_options_default(
3845 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003846{
3847 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003848 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003849 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003850
3851 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003852 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003853 && (opt_flags == 0
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003854 || (options[i].var != (char_u *)&p_enc
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003855# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003856 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003857 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003858# endif
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003859 )))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003860 set_option_default(i, opt_flags, p_cp);
3861
Bram Moolenaar071d4272004-06-13 20:20:40 +00003862 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003863 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003864 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003865#ifdef FEAT_CINDENT
3866 parse_cino(curbuf);
3867#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003868}
3869
3870/*
3871 * Set the Vi-default value of a string option.
3872 * Used for 'sh', 'backupskip' and 'term'.
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003873 * When "escape" is TRUE escape spaces with a backslash.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003874 */
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003875 static void
3876set_string_default_esc(char *name, char_u *val, int escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003877{
3878 char_u *p;
3879 int opt_idx;
3880
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003881 if (escape && vim_strchr(val, ' ') != NULL)
3882 p = vim_strsave_escaped(val, (char_u *)" ");
3883 else
3884 p = vim_strsave(val);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003885 if (p != NULL) /* we don't want a NULL */
3886 {
3887 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003888 if (opt_idx >= 0)
3889 {
3890 if (options[opt_idx].flags & P_DEF_ALLOCED)
3891 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3892 options[opt_idx].def_val[VI_DEFAULT] = p;
3893 options[opt_idx].flags |= P_DEF_ALLOCED;
3894 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003895 }
3896}
3897
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003898 void
3899set_string_default(char *name, char_u *val)
3900{
3901 set_string_default_esc(name, val, FALSE);
3902}
3903
Bram Moolenaar071d4272004-06-13 20:20:40 +00003904/*
3905 * Set the Vi-default value of a number option.
3906 * Used for 'lines' and 'columns'.
3907 */
3908 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003909set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003910{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003911 int opt_idx;
3912
3913 opt_idx = findoption((char_u *)name);
3914 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003915 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003916}
3917
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02003918/*
3919 * Set all window-local and buffer-local options to the Vim default.
3920 * local-global options will use the global value.
3921 */
3922 void
3923set_local_options_default(win_T *wp)
3924{
3925 win_T *save_curwin = curwin;
3926 int i;
3927
3928 curwin = wp;
3929 curbuf = curwin->w_buffer;
3930 block_autocmds();
3931
3932 for (i = 0; !istermoption(&options[i]); i++)
3933 {
3934 struct vimoption *p = &(options[i]);
3935 char_u *varp = get_varp_scope(p, OPT_LOCAL);
3936
3937 if (p->indir != PV_NONE
3938 && !(options[i].flags & P_NODEFAULT)
3939 && !optval_default(p, varp, FALSE))
3940 set_option_default(i, OPT_LOCAL, FALSE);
3941 }
3942
3943 unblock_autocmds();
3944 curwin = save_curwin;
3945 curbuf = curwin->w_buffer;
3946}
3947
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003948#if defined(EXITFREE) || defined(PROTO)
3949/*
3950 * Free all options.
3951 */
3952 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003953free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003954{
3955 int i;
3956
3957 for (i = 0; !istermoption(&options[i]); i++)
3958 {
3959 if (options[i].indir == PV_NONE)
3960 {
3961 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003962 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003963 free_string_option(*(char_u **)options[i].var);
3964 if (options[i].flags & P_DEF_ALLOCED)
3965 free_string_option(options[i].def_val[VI_DEFAULT]);
3966 }
3967 else if (options[i].var != VAR_WIN
3968 && (options[i].flags & P_STRING))
3969 /* buffer-local option: free global value */
3970 free_string_option(*(char_u **)options[i].var);
3971 }
3972}
3973#endif
3974
3975
Bram Moolenaar071d4272004-06-13 20:20:40 +00003976/*
3977 * Initialize the options, part two: After getting Rows and Columns and
3978 * setting 'term'.
3979 */
3980 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003981set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003982{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003983 int idx;
3984
Bram Moolenaar071d4272004-06-13 20:20:40 +00003985 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003986 * 'scroll' defaults to half the window height. The stored default is zero,
3987 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003988 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003989 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003990 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003991 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003992 comp_col();
3993
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003994 /*
3995 * 'window' is only for backwards compatibility with Vi.
3996 * Default is Rows - 1.
3997 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003998 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003999 p_window = Rows - 1;
4000 set_number_default("window", Rows - 1);
4001
Bram Moolenaarf740b292006-02-16 22:11:02 +00004002 /* For DOS console the default is always black. */
Bram Moolenaar4f974752019-02-17 17:44:42 +01004003#if !((defined(MSWIN)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00004004 /*
4005 * If 'background' wasn't set by the user, try guessing the value,
4006 * depending on the terminal name. Only need to check for terminals
4007 * with a dark background, that can handle color.
4008 */
4009 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004010 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
4011 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00004012 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004013 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00004014 /* don't mark it as set, when starting the GUI it may be
4015 * changed again */
4016 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004017 }
4018#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00004019
4020#ifdef CURSOR_SHAPE
4021 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
4022#endif
4023#ifdef FEAT_MOUSESHAPE
4024 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
4025#endif
4026#ifdef FEAT_PRINTER
4027 (void)parse_printoptions(); /* parse 'printoptions' default value */
4028#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004029}
4030
4031/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00004032 * Return "dark" or "light" depending on the kind of terminal.
4033 * This is just guessing! Recognized are:
4034 * "linux" Linux console
4035 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004036 * "cygwin.*" Cygwin shell
4037 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00004038 * We also check the COLORFGBG environment variable, which is set by
4039 * rxvt and derivatives. This variable contains either two or three
4040 * values separated by semicolons; we want the last value in either
4041 * case. If this value is 0-6 or 8, our background is dark.
4042 */
4043 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004044term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00004045{
Bram Moolenaar4f974752019-02-17 17:44:42 +01004046#if defined(MSWIN)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004047 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00004048 return (char_u *)"dark";
4049#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00004050 char_u *p;
4051
Bram Moolenaarf740b292006-02-16 22:11:02 +00004052 if (STRCMP(T_NAME, "linux") == 0
4053 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004054 || STRNCMP(T_NAME, "cygwin", 6) == 0
4055 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00004056 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
4057 && (p = vim_strrchr(p, ';')) != NULL
4058 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
4059 && p[2] == NUL))
4060 return (char_u *)"dark";
4061 return (char_u *)"light";
4062#endif
4063}
4064
4065/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004066 * Initialize the options, part three: After reading the .vimrc
4067 */
4068 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004069set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004070{
Bram Moolenaar4f974752019-02-17 17:44:42 +01004071#if defined(UNIX) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004072/*
4073 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4074 * This is done after other initializations, where 'shell' might have been
4075 * set, but only if they have not been set before.
4076 */
4077 char_u *p;
4078 int idx_srr;
4079 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004080# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004081 int idx_sp;
4082 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004083# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004084
4085 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004086 if (idx_srr < 0)
4087 do_srr = FALSE;
4088 else
4089 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004090# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004091 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004092 if (idx_sp < 0)
4093 do_sp = FALSE;
4094 else
4095 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004096# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004097 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004098 if (p != NULL)
4099 {
4100 /*
4101 * Default for p_sp is "| tee", for p_srr is ">".
4102 * For known shells it is changed here to include stderr.
4103 */
4104 if ( fnamecmp(p, "csh") == 0
4105 || fnamecmp(p, "tcsh") == 0
Bram Moolenaar4f974752019-02-17 17:44:42 +01004106# if defined(MSWIN) // also check with .exe extension
Bram Moolenaar071d4272004-06-13 20:20:40 +00004107 || fnamecmp(p, "csh.exe") == 0
4108 || fnamecmp(p, "tcsh.exe") == 0
4109# endif
4110 )
4111 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004112# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004113 if (do_sp)
4114 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01004115# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004116 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004117# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004118 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004119# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004120 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4121 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004122# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004123 if (do_srr)
4124 {
4125 p_srr = (char_u *)">&";
4126 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4127 }
4128 }
4129 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004130 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004131 if ( fnamecmp(p, "sh") == 0
4132 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004133 || fnamecmp(p, "mksh") == 0
4134 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004135 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004136 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004137 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004138 || fnamecmp(p, "fish") == 0
Bram Moolenaar4f974752019-02-17 17:44:42 +01004139# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004140 || fnamecmp(p, "cmd") == 0
4141 || fnamecmp(p, "sh.exe") == 0
4142 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004143 || fnamecmp(p, "mksh.exe") == 0
4144 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004145 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004146 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004147 || fnamecmp(p, "bash.exe") == 0
4148 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004149# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004150 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004151 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004152# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004153 if (do_sp)
4154 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01004155# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004156 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004157# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004158 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004159# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004160 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4161 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004162# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004163 if (do_srr)
4164 {
4165 p_srr = (char_u *)">%s 2>&1";
4166 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4167 }
4168 }
4169 vim_free(p);
4170 }
4171#endif
4172
Bram Moolenaar4f974752019-02-17 17:44:42 +01004173#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004174 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004175 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4176 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004177 * This is done after other initializations, where 'shell' might have been
4178 * set, but only if they have not been set before. Default for p_shcf is
4179 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004180 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004181 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004182 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004183 {
4184 int idx3;
4185
4186 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004187 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004188 {
4189 p_shcf = (char_u *)"-c";
4190 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4191 }
4192
Bram Moolenaar071d4272004-06-13 20:20:40 +00004193 /* Somehow Win32 requires the quotes around the redirection too */
4194 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004195 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004196 {
4197 p_sxq = (char_u *)"\"";
4198 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4199 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004200 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004201 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4202 {
4203 int idx3;
4204
4205 /*
4206 * cmd.exe on Windows will strip the first and last double quote given
4207 * on the command line, e.g. most of the time things like:
4208 * cmd /c "my path/to/echo" "my args to echo"
4209 * become:
4210 * my path/to/echo" "my args to echo
4211 * when executed.
4212 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004213 * To avoid this, set shellxquote to surround the command in
4214 * parenthesis. This appears to make most commands work, without
4215 * breaking commands that worked previously, such as
4216 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004217 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004218 idx3 = findoption((char_u *)"sxq");
4219 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4220 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004221 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004222 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4223 }
4224
Bram Moolenaara64ba222012-02-12 23:23:31 +01004225 idx3 = findoption((char_u *)"shcf");
4226 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4227 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004228 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004229 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4230 }
4231 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004232#endif
4233
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004234 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004235 {
4236 int idx_ffs = findoption((char_u *)"ffs");
4237
4238 /* Apply the first entry of 'fileformats' to the initial buffer. */
4239 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4240 set_fileformat(default_fileformat(), OPT_LOCAL);
4241 }
4242
Bram Moolenaar071d4272004-06-13 20:20:40 +00004243#ifdef FEAT_TITLE
4244 set_title_defaults();
4245#endif
4246}
4247
4248#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4249/*
4250 * When 'helplang' is still at its default value, set it to "lang".
4251 * Only the first two characters of "lang" are used.
4252 */
4253 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004254set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004255{
4256 int idx;
4257
4258 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4259 return;
4260 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004261 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004262 {
4263 if (options[idx].flags & P_ALLOCED)
4264 free_string_option(p_hlg);
4265 p_hlg = vim_strsave(lang);
4266 if (p_hlg == NULL)
4267 p_hlg = empty_option;
4268 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004269 {
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004270 // zh_CN becomes "cn", zh_TW becomes "tw"
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004271 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4272 {
4273 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4274 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4275 }
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004276 // any C like setting, such as C.UTF-8, becomes "en"
4277 else if (STRLEN(p_hlg) >= 1 && *p_hlg == 'C')
4278 {
4279 p_hlg[0] = 'e';
4280 p_hlg[1] = 'n';
4281 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004282 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004283 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004284 options[idx].flags |= P_ALLOCED;
4285 }
4286}
4287#endif
4288
4289#ifdef FEAT_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00004290 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004291gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004292{
4293 if (gui_get_lightness(gui.back_pixel) < 127)
4294 return (char_u *)"dark";
4295 return (char_u *)"light";
4296}
4297
4298/*
4299 * Option initializations that can only be done after opening the GUI window.
4300 */
4301 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004302init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004303{
4304 /* Set the 'background' option according to the lightness of the
4305 * background color, unless the user has set it already. */
4306 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4307 {
4308 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4309 highlight_changed();
4310 }
4311}
4312#endif
4313
4314#ifdef FEAT_TITLE
4315/*
4316 * 'title' and 'icon' only default to true if they have not been set or reset
4317 * in .vimrc and we can read the old value.
4318 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4319 * they can be reset. This reduces startup time when using X on a remote
4320 * machine.
4321 */
4322 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004323set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004324{
4325 int idx1;
4326 long val;
4327
4328 /*
4329 * If GUI is (going to be) used, we can always set the window title and
4330 * icon name. Saves a bit of time, because the X11 display server does
4331 * not need to be contacted.
4332 */
4333 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004334 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004335 {
4336#ifdef FEAT_GUI
4337 if (gui.starting || gui.in_use)
4338 val = TRUE;
4339 else
4340#endif
4341 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004342 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004343 p_title = val;
4344 }
4345 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004346 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004347 {
4348#ifdef FEAT_GUI
4349 if (gui.starting || gui.in_use)
4350 val = TRUE;
4351 else
4352#endif
4353 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004354 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004355 p_icon = val;
4356 }
4357}
4358#endif
4359
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004360#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02004361/*
4362 * Trigger the OptionSet autocommand.
4363 * "opt_idx" is the index of the option being set.
4364 * "opt_flags" can be OPT_LOCAL etc.
4365 * "oldval" the old value
4366 * "oldval_l" the old local value (only non-NULL if global and local value
4367 * are set)
4368 * "oldval_g" the old global value (only non-NULL if global and local value
4369 * are set)
4370 * "newval" the new value
4371 */
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004372 static void
4373trigger_optionsset_string(
4374 int opt_idx,
4375 int opt_flags,
Bram Moolenaard7c96872019-06-15 17:12:48 +02004376 char_u *oldval,
4377 char_u *oldval_l,
4378 char_u *oldval_g,
4379 char_u *newval)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004380{
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02004381 // Don't do this recursively.
4382 if (oldval != NULL && newval != NULL
4383 && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004384 {
4385 char_u buf_type[7];
4386
4387 sprintf((char *)buf_type, "%s",
4388 (opt_flags & OPT_LOCAL) ? "local" : "global");
4389 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4390 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4391 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
Bram Moolenaard7c96872019-06-15 17:12:48 +02004392 if (opt_flags & OPT_LOCAL)
4393 {
4394 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
4395 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1);
4396 }
4397 if (opt_flags & OPT_GLOBAL)
4398 {
4399 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
4400 set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval, -1);
4401 }
4402 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
4403 {
4404 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
4405 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval_l, -1);
4406 set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval_g, -1);
4407 }
4408 if (opt_flags & OPT_MODELINE)
4409 {
4410 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
4411 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1);
4412 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004413 apply_autocmds(EVENT_OPTIONSET,
4414 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4415 reset_v_option_vars();
4416 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004417}
4418#endif
4419
Bram Moolenaar071d4272004-06-13 20:20:40 +00004420/*
4421 * Parse 'arg' for option settings.
4422 *
4423 * 'arg' may be IObuff, but only when no errors can be present and option
4424 * does not need to be expanded with option_expand().
4425 * "opt_flags":
4426 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004427 * OPT_GLOBAL for ":setglobal"
4428 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004429 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004430 * OPT_WINONLY to only set window-local options
4431 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004432 *
4433 * returns FAIL if an error is detected, OK otherwise
4434 */
4435 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004436do_set(
4437 char_u *arg, /* option string (may be written to!) */
4438 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004439{
4440 int opt_idx;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004441 char *errmsg;
4442 char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00004443 char_u *startarg;
4444 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4445 int nextchar; /* next non-white char after option name */
4446 int afterchar; /* character just after option name */
4447 int len;
4448 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004449 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004450 int key;
4451 long_u flags; /* flags for current option */
4452 char_u *varp = NULL; /* pointer to variable for current option */
4453 int did_show = FALSE; /* already showed one value */
4454 int adding; /* "opt+=arg" */
4455 int prepending; /* "opt^=arg" */
4456 int removing; /* "opt-=arg" */
4457 int cp_val = 0;
4458 char_u key_name[2];
4459
4460 if (*arg == NUL)
4461 {
4462 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004463 did_show = TRUE;
4464 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004465 }
4466
4467 while (*arg != NUL) /* loop to process all options */
4468 {
4469 errmsg = NULL;
4470 startarg = arg; /* remember for error message */
4471
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004472 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4473 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004474 {
4475 /*
4476 * ":set all" show all options.
4477 * ":set all&" set all options to their default value.
4478 */
4479 arg += 3;
4480 if (*arg == '&')
4481 {
4482 ++arg;
4483 /* Only for :set command set global value of local options. */
4484 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004485 didset_options();
4486 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004487 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004488 }
4489 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004490 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004491 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004492 did_show = TRUE;
4493 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004494 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004495 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004496 {
4497 showoptions(2, opt_flags);
4498 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004499 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004500 arg += 7;
4501 }
4502 else
4503 {
4504 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004505 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004506 {
4507 prefix = 0;
4508 arg += 2;
4509 }
4510 else if (STRNCMP(arg, "inv", 3) == 0)
4511 {
4512 prefix = 2;
4513 arg += 3;
4514 }
4515
4516 /* find end of name */
4517 key = 0;
4518 if (*arg == '<')
4519 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004520 opt_idx = -1;
4521 /* look out for <t_>;> */
4522 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4523 len = 5;
4524 else
4525 {
4526 len = 1;
4527 while (arg[len] != NUL && arg[len] != '>')
4528 ++len;
4529 }
4530 if (arg[len] != '>')
4531 {
4532 errmsg = e_invarg;
4533 goto skip;
4534 }
4535 arg[len] = NUL; /* put NUL after name */
4536 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4537 opt_idx = findoption(arg + 1);
4538 arg[len++] = '>'; /* restore '>' */
4539 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004540 key = find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004541 }
4542 else
4543 {
4544 len = 0;
4545 /*
4546 * The two characters after "t_" may not be alphanumeric.
4547 */
4548 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4549 len = 4;
4550 else
4551 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4552 ++len;
4553 nextchar = arg[len];
4554 arg[len] = NUL; /* put NUL after name */
4555 opt_idx = findoption(arg);
4556 arg[len] = nextchar; /* restore nextchar */
4557 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004558 key = find_key_option(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004559 }
4560
4561 /* remember character after option name */
4562 afterchar = arg[len];
4563
4564 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004565 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004566 ++len;
4567
4568 adding = FALSE;
4569 prepending = FALSE;
4570 removing = FALSE;
4571 if (arg[len] != NUL && arg[len + 1] == '=')
4572 {
4573 if (arg[len] == '+')
4574 {
4575 adding = TRUE; /* "+=" */
4576 ++len;
4577 }
4578 else if (arg[len] == '^')
4579 {
4580 prepending = TRUE; /* "^=" */
4581 ++len;
4582 }
4583 else if (arg[len] == '-')
4584 {
4585 removing = TRUE; /* "-=" */
4586 ++len;
4587 }
4588 }
4589 nextchar = arg[len];
4590
4591 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4592 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004593 errmsg = N_("E518: Unknown option");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004594 goto skip;
4595 }
4596
4597 if (opt_idx >= 0)
4598 {
4599 if (options[opt_idx].var == NULL) /* hidden option: skip */
4600 {
4601 /* Only give an error message when requesting the value of
4602 * a hidden option, ignore setting it. */
4603 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4604 && (!(options[opt_idx].flags & P_BOOL)
4605 || nextchar == '?'))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004606 errmsg = N_("E519: Option not supported");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004607 goto skip;
4608 }
4609
4610 flags = options[opt_idx].flags;
4611 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4612 }
4613 else
4614 {
4615 flags = P_STRING;
4616 if (key < 0)
4617 {
4618 key_name[0] = KEY2TERMCAP0(key);
4619 key_name[1] = KEY2TERMCAP1(key);
4620 }
4621 else
4622 {
4623 key_name[0] = KS_KEY;
4624 key_name[1] = (key & 0xff);
4625 }
4626 }
4627
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004628 /* Skip all options that are not window-local (used when showing
4629 * an already loaded buffer in a window). */
4630 if ((opt_flags & OPT_WINONLY)
4631 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4632 goto skip;
4633
Bram Moolenaara3227e22006-03-08 21:32:40 +00004634 /* Skip all options that are window-local (used for :vimgrep). */
4635 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4636 && options[opt_idx].var == VAR_WIN)
4637 goto skip;
4638
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004639 /* Disallow changing some options from modelines. */
4640 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004641 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004642 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004643 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004644 errmsg = _("E520: Not allowed in a modeline");
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004645 goto skip;
4646 }
Bram Moolenaar110289e2019-05-23 15:38:06 +02004647 if ((flags & P_MLE) && !p_mle)
4648 {
4649 errmsg = _("E992: Not allowed in a modeline when 'modelineexpr' is off");
4650 goto skip;
4651 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004652#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004653 /* In diff mode some options are overruled. This avoids that
4654 * 'foldmethod' becomes "marker" instead of "diff" and that
4655 * "wrap" gets set. */
4656 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004657 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004658 && (
4659#ifdef FEAT_FOLDING
4660 options[opt_idx].indir == PV_FDM ||
4661#endif
4662 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004663 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004664#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004665 }
4666
4667#ifdef HAVE_SANDBOX
4668 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004669 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004670 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004671 errmsg = _(e_sandbox);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004672 goto skip;
4673 }
4674#endif
4675
4676 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4677 {
4678 arg += len;
4679 cp_val = p_cp;
4680 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4681 {
4682 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4683 {
4684 cp_val = FALSE;
4685 arg += 3;
4686 }
4687 else /* "opt&vi": set to Vi default */
4688 {
4689 cp_val = TRUE;
4690 arg += 2;
4691 }
4692 }
4693 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004694 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004695 {
4696 errmsg = e_trailing;
4697 goto skip;
4698 }
4699 }
4700
4701 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004702 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4703 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004704 */
4705 if (nextchar == '?'
4706 || (prefix == 1
4707 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4708 && !(flags & P_BOOL)))
4709 {
4710 /*
4711 * print value
4712 */
4713 if (did_show)
4714 msg_putchar('\n'); /* cursor below last one */
4715 else
4716 {
4717 gotocmdline(TRUE); /* cursor at status line */
4718 did_show = TRUE; /* remember that we did a line */
4719 }
4720 if (opt_idx >= 0)
4721 {
4722 showoneopt(&options[opt_idx], opt_flags);
4723#ifdef FEAT_EVAL
4724 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004725 {
4726 /* Mention where the option was last set. */
4727 if (varp == options[opt_idx].var)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004728 last_set_msg(options[opt_idx].script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004729 else if ((int)options[opt_idx].indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004730 last_set_msg(curwin->w_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004731 (int)options[opt_idx].indir & PV_MASK]);
4732 else if ((int)options[opt_idx].indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004733 last_set_msg(curbuf->b_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004734 (int)options[opt_idx].indir & PV_MASK]);
4735 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004736#endif
4737 }
4738 else
4739 {
4740 char_u *p;
4741
4742 p = find_termcode(key_name);
4743 if (p == NULL)
4744 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004745 errmsg = N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004746 goto skip;
4747 }
4748 else
4749 (void)show_one_termcode(key_name, p, TRUE);
4750 }
4751 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004752 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004753 errmsg = e_trailing;
4754 }
4755 else
4756 {
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004757 int value_is_replaced = !prepending && !adding && !removing;
Bram Moolenaar916a8182018-11-25 02:18:29 +01004758 int value_checked = FALSE;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004759
Bram Moolenaar071d4272004-06-13 20:20:40 +00004760 if (flags & P_BOOL) /* boolean */
4761 {
4762 if (nextchar == '=' || nextchar == ':')
4763 {
4764 errmsg = e_invarg;
4765 goto skip;
4766 }
4767
4768 /*
4769 * ":set opt!": invert
4770 * ":set opt&": reset to default value
4771 * ":set opt<": reset to global value
4772 */
4773 if (nextchar == '!')
4774 value = *(int *)(varp) ^ 1;
4775 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004776 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004777 ((flags & P_VI_DEF) || cp_val)
4778 ? VI_DEFAULT : VIM_DEFAULT];
4779 else if (nextchar == '<')
4780 {
4781 /* For 'autoread' -1 means to use global value. */
4782 if ((int *)varp == &curbuf->b_p_ar
4783 && opt_flags == OPT_LOCAL)
4784 value = -1;
4785 else
4786 value = *(int *)get_varp_scope(&(options[opt_idx]),
4787 OPT_GLOBAL);
4788 }
4789 else
4790 {
4791 /*
4792 * ":set invopt": invert
4793 * ":set opt" or ":set noopt": set or reset
4794 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004795 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004796 {
4797 errmsg = e_trailing;
4798 goto skip;
4799 }
4800 if (prefix == 2) /* inv */
4801 value = *(int *)(varp) ^ 1;
4802 else
4803 value = prefix;
4804 }
4805
4806 errmsg = set_bool_option(opt_idx, varp, (int)value,
4807 opt_flags);
4808 }
4809 else /* numeric or string */
4810 {
4811 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4812 || prefix != 1)
4813 {
4814 errmsg = e_invarg;
4815 goto skip;
4816 }
4817
4818 if (flags & P_NUM) /* numeric */
4819 {
4820 /*
4821 * Different ways to set a number option:
4822 * & set to default value
4823 * < set to global value
4824 * <xx> accept special key codes for 'wildchar'
4825 * c accept any non-digit for 'wildchar'
4826 * [-]0-9 set number
4827 * other error
4828 */
4829 ++arg;
4830 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004831 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004832 ((flags & P_VI_DEF) || cp_val)
4833 ? VI_DEFAULT : VIM_DEFAULT];
4834 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004835 {
4836 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4837 * use the global value. */
4838 if ((long *)varp == &curbuf->b_p_ul
4839 && opt_flags == OPT_LOCAL)
4840 value = NO_LOCAL_UNDOLEVEL;
4841 else
4842 value = *(long *)get_varp_scope(
4843 &(options[opt_idx]), OPT_GLOBAL);
4844 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004845 else if (((long *)varp == &p_wc
4846 || (long *)varp == &p_wcm)
4847 && (*arg == '<'
4848 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004849 || (*arg != NUL
4850 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004851 && !VIM_ISDIGIT(*arg))))
4852 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004853 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004854 if (value == 0 && (long *)varp != &p_wcm)
4855 {
4856 errmsg = e_invarg;
4857 goto skip;
4858 }
4859 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004860 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4861 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004862 /* Allow negative (for 'undolevels'), octal and
4863 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004864 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
Bram Moolenaar16e9b852019-05-19 19:59:35 +02004865 &value, NULL, 0, TRUE);
Bram Moolenaar06e2c812019-06-12 19:05:48 +02004866 if (i == 0 || (arg[i] != NUL
4867 && !VIM_ISWHITE(arg[i])))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004868 {
Bram Moolenaar16e9b852019-05-19 19:59:35 +02004869 errmsg = N_("E521: Number required after =");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004870 goto skip;
4871 }
4872 }
4873 else
4874 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004875 errmsg = N_("E521: Number required after =");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004876 goto skip;
4877 }
4878
4879 if (adding)
4880 value = *(long *)varp + value;
4881 if (prepending)
4882 value = *(long *)varp * value;
4883 if (removing)
4884 value = *(long *)varp - value;
4885 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004886 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004887 }
4888 else if (opt_idx >= 0) /* string */
4889 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004890 char_u *save_arg = NULL;
4891 char_u *s = NULL;
4892 char_u *oldval = NULL; /* previous value if *varp */
4893 char_u *newval;
4894 char_u *origval = NULL;
Bram Moolenaard7c96872019-06-15 17:12:48 +02004895 char_u *origval_l = NULL;
4896 char_u *origval_g = NULL;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004897#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004898 char_u *saved_origval = NULL;
Bram Moolenaard7c96872019-06-15 17:12:48 +02004899 char_u *saved_origval_l = NULL;
4900 char_u *saved_origval_g = NULL;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004901 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004902#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004903 unsigned newlen;
4904 int comma;
4905 int bs;
4906 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004907 was allocated */
4908
4909 /* When using ":set opt=val" for a global option
4910 * with a local value the local value will be
4911 * reset, use the global value here. */
4912 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004913 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004914 varp = options[opt_idx].var;
4915
4916 /* The old value is kept until we are sure that the
4917 * new value is valid. */
4918 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004919
Bram Moolenaard7c96872019-06-15 17:12:48 +02004920 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
4921 {
4922 origval_l = *(char_u **)get_varp_scope(
4923 &(options[opt_idx]), OPT_LOCAL);
4924 origval_g = *(char_u **)get_varp_scope(
4925 &(options[opt_idx]), OPT_GLOBAL);
4926
4927 // A global-local string option might have an empty
4928 // option as value to indicate that the global
4929 // value should be used.
4930 if (((int)options[opt_idx].indir & PV_BOTH)
4931 && origval_l == empty_option)
4932 origval_l = origval_g;
4933 }
4934
4935 // When setting the local value of a global
4936 // option, the old value may be the global value.
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004937 if (((int)options[opt_idx].indir & PV_BOTH)
4938 && (opt_flags & OPT_LOCAL))
4939 origval = *(char_u **)get_varp(
4940 &options[opt_idx]);
4941 else
4942 origval = oldval;
4943
Bram Moolenaar071d4272004-06-13 20:20:40 +00004944 if (nextchar == '&') /* set to default val */
4945 {
4946 newval = options[opt_idx].def_val[
4947 ((flags & P_VI_DEF) || cp_val)
4948 ? VI_DEFAULT : VIM_DEFAULT];
4949 if ((char_u **)varp == &p_bg)
4950 {
4951 /* guess the value of 'background' */
4952#ifdef FEAT_GUI
4953 if (gui.in_use)
4954 newval = gui_bg_default();
4955 else
4956#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004957 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004958 }
4959
4960 /* expand environment variables and ~ (since the
4961 * default value was already expanded, only
4962 * required when an environment variable was set
4963 * later */
4964 if (newval == NULL)
4965 newval = empty_option;
4966 else
4967 {
4968 s = option_expand(opt_idx, newval);
4969 if (s == NULL)
4970 s = newval;
4971 newval = vim_strsave(s);
4972 }
4973 new_value_alloced = TRUE;
4974 }
4975 else if (nextchar == '<') /* set to global val */
4976 {
4977 newval = vim_strsave(*(char_u **)get_varp_scope(
4978 &(options[opt_idx]), OPT_GLOBAL));
4979 new_value_alloced = TRUE;
4980 }
4981 else
4982 {
4983 ++arg; /* jump to after the '=' or ':' */
4984
4985 /*
4986 * Set 'keywordprg' to ":help" if an empty
4987 * value was passed to :set by the user.
4988 * Misuse errbuf[] for the resulting string.
4989 */
4990 if (varp == (char_u *)&p_kp
4991 && (*arg == NUL || *arg == ' '))
4992 {
4993 STRCPY(errbuf, ":help");
4994 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004995 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004996 }
4997 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004998 * Convert 'backspace' number to string, for
4999 * adding, prepending and removing string.
5000 */
5001 else if (varp == (char_u *)&p_bs
5002 && VIM_ISDIGIT(**(char_u **)varp))
5003 {
5004 i = getdigits((char_u **)varp);
5005 switch (i)
5006 {
5007 case 0:
5008 *(char_u **)varp = empty_option;
5009 break;
5010 case 1:
5011 *(char_u **)varp = vim_strsave(
5012 (char_u *)"indent,eol");
5013 break;
5014 case 2:
5015 *(char_u **)varp = vim_strsave(
5016 (char_u *)"indent,eol,start");
5017 break;
5018 }
5019 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02005020 if (origval == oldval)
5021 origval = *(char_u **)varp;
Bram Moolenaard7c96872019-06-15 17:12:48 +02005022 if (origval_l == oldval)
5023 origval_l = *(char_u **)varp;
5024 if (origval_g == oldval)
5025 origval_g = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01005026 oldval = *(char_u **)varp;
5027 }
5028 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00005029 * Convert 'whichwrap' number to string, for
5030 * backwards compatibility with Vim 3.0.
5031 * Misuse errbuf[] for the resulting string.
5032 */
5033 else if (varp == (char_u *)&p_ww
5034 && VIM_ISDIGIT(*arg))
5035 {
5036 *errbuf = NUL;
5037 i = getdigits(&arg);
5038 if (i & 1)
5039 STRCAT(errbuf, "b,");
5040 if (i & 2)
5041 STRCAT(errbuf, "s,");
5042 if (i & 4)
5043 STRCAT(errbuf, "h,l,");
5044 if (i & 8)
5045 STRCAT(errbuf, "<,>,");
5046 if (i & 16)
5047 STRCAT(errbuf, "[,],");
5048 if (*errbuf != NUL) /* remove trailing , */
5049 errbuf[STRLEN(errbuf) - 1] = NUL;
5050 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005051 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005052 }
5053 /*
5054 * Remove '>' before 'dir' and 'bdir', for
5055 * backwards compatibility with version 3.0
5056 */
5057 else if ( *arg == '>'
5058 && (varp == (char_u *)&p_dir
5059 || varp == (char_u *)&p_bdir))
5060 {
5061 ++arg;
5062 }
5063
Bram Moolenaar071d4272004-06-13 20:20:40 +00005064 /*
5065 * Copy the new string into allocated memory.
5066 * Can't use set_string_option_direct(), because
5067 * we need to remove the backslashes.
5068 */
5069 /* get a bit too much */
5070 newlen = (unsigned)STRLEN(arg) + 1;
5071 if (adding || prepending || removing)
5072 newlen += (unsigned)STRLEN(origval) + 1;
5073 newval = alloc(newlen);
5074 if (newval == NULL) /* out of mem, don't change */
5075 break;
5076 s = newval;
5077
5078 /*
5079 * Copy the string, skip over escaped chars.
5080 * For MS-DOS and WIN32 backslashes before normal
5081 * file name characters are not removed, and keep
5082 * backslash at start, for "\\machine\path", but
5083 * do remove it for "\\\\machine\\path".
5084 * The reverse is found in ExpandOldSetting().
5085 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005086 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005087 {
5088 if (*arg == '\\' && arg[1] != NUL
5089#ifdef BACKSLASH_IN_FILENAME
5090 && !((flags & P_EXPAND)
5091 && vim_isfilec(arg[1])
5092 && (arg[1] != '\\'
5093 || (s == newval
5094 && arg[2] != '\\')))
5095#endif
5096 )
5097 ++arg; /* remove backslash */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005098 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00005099 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005100 {
5101 /* copy multibyte char */
5102 mch_memmove(s, arg, (size_t)i);
5103 arg += i;
5104 s += i;
5105 }
5106 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005107 *s++ = *arg++;
5108 }
5109 *s = NUL;
5110
5111 /*
5112 * Expand environment variables and ~.
5113 * Don't do it when adding without inserting a
5114 * comma.
5115 */
5116 if (!(adding || prepending || removing)
5117 || (flags & P_COMMA))
5118 {
5119 s = option_expand(opt_idx, newval);
5120 if (s != NULL)
5121 {
5122 vim_free(newval);
5123 newlen = (unsigned)STRLEN(s) + 1;
5124 if (adding || prepending || removing)
5125 newlen += (unsigned)STRLEN(origval) + 1;
5126 newval = alloc(newlen);
5127 if (newval == NULL)
5128 break;
5129 STRCPY(newval, s);
5130 }
5131 }
5132
5133 /* locate newval[] in origval[] when removing it
5134 * and when adding to avoid duplicates */
5135 i = 0; /* init for GCC */
5136 if (removing || (flags & P_NODUP))
5137 {
5138 i = (int)STRLEN(newval);
5139 bs = 0;
5140 for (s = origval; *s; ++s)
5141 {
5142 if ((!(flags & P_COMMA)
5143 || s == origval
5144 || (s[-1] == ',' && !(bs & 1)))
5145 && STRNCMP(s, newval, i) == 0
5146 && (!(flags & P_COMMA)
5147 || s[i] == ','
5148 || s[i] == NUL))
5149 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005150 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005151 * even number of backslashes or a single
5152 * backslash preceded by a comma before it
5153 * is recognized as a separator */
5154 if ((s > origval + 1
5155 && s[-1] == '\\'
5156 && s[-2] != ',')
5157 || (s == origval + 1
5158 && s[-1] == '\\'))
5159
Bram Moolenaar071d4272004-06-13 20:20:40 +00005160 ++bs;
5161 else
5162 bs = 0;
5163 }
5164
5165 /* do not add if already there */
5166 if ((adding || prepending) && *s)
5167 {
5168 prepending = FALSE;
5169 adding = FALSE;
5170 STRCPY(newval, origval);
5171 }
5172 }
5173
5174 /* concatenate the two strings; add a ',' if
5175 * needed */
5176 if (adding || prepending)
5177 {
5178 comma = ((flags & P_COMMA) && *origval != NUL
5179 && *newval != NUL);
5180 if (adding)
5181 {
5182 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005183 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005184 if (comma && i > 1
5185 && (flags & P_ONECOMMA) == P_ONECOMMA
5186 && origval[i - 1] == ','
5187 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005188 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005189 mch_memmove(newval + i + comma, newval,
5190 STRLEN(newval) + 1);
5191 mch_memmove(newval, origval, (size_t)i);
5192 }
5193 else
5194 {
5195 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005196 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005197 }
5198 if (comma)
5199 newval[i] = ',';
5200 }
5201
5202 /* Remove newval[] from origval[]. (Note: "i" has
5203 * been set above and is used here). */
5204 if (removing)
5205 {
5206 STRCPY(newval, origval);
5207 if (*s)
5208 {
5209 /* may need to remove a comma */
5210 if (flags & P_COMMA)
5211 {
5212 if (s == origval)
5213 {
5214 /* include comma after string */
5215 if (s[i] == ',')
5216 ++i;
5217 }
5218 else
5219 {
5220 /* include comma before string */
5221 --s;
5222 ++i;
5223 }
5224 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005225 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005226 }
5227 }
5228
5229 if (flags & P_FLAGLIST)
5230 {
5231 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005232 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005233 {
5234 /* if options have P_FLAGLIST and
5235 * P_ONECOMMA such as 'whichwrap' */
5236 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005237 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005238 if (*s != ',' && *(s + 1) == ','
5239 && vim_strchr(s + 2, *s) != NULL)
5240 {
5241 /* Remove the duplicated value and
5242 * the next comma. */
5243 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005244 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005245 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005246 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005247 else
5248 {
5249 if ((!(flags & P_COMMA) || *s != ',')
5250 && vim_strchr(s + 1, *s) != NULL)
5251 {
5252 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005253 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005254 }
5255 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005256 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005257 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005258 }
5259
5260 if (save_arg != NULL) /* number for 'whichwrap' */
5261 arg = save_arg;
5262 new_value_alloced = TRUE;
5263 }
5264
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005265 /*
5266 * Set the new value.
5267 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005268 *(char_u **)(varp) = newval;
5269
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005270#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005271 if (!starting
5272# ifdef FEAT_CRYPT
5273 && options[opt_idx].indir != PV_KEY
5274# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005275 && origval != NULL && newval != NULL)
5276 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005277 /* origval may be freed by
5278 * did_set_string_option(), make a copy. */
5279 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005280 /* newval (and varp) may become invalid if the
5281 * buffer is closed by autocommands. */
5282 saved_newval = vim_strsave(newval);
Bram Moolenaard7c96872019-06-15 17:12:48 +02005283 if (origval_l != NULL)
5284 saved_origval_l = vim_strsave(origval_l);
5285 if (origval_g != NULL)
5286 saved_origval_g = vim_strsave(origval_g);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005287 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005288#endif
5289
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005290 {
5291 long_u *p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005292 int secure_saved = secure;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005293
5294 // When an option is set in the sandbox, from a
5295 // modeline or in secure mode, then deal with side
5296 // effects in secure mode. Also when the value was
5297 // set with the P_INSECURE flag and is not
5298 // completely replaced.
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005299 if ((opt_flags & OPT_MODELINE)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005300#ifdef HAVE_SANDBOX
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005301 || sandbox != 0
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005302#endif
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005303 || (!value_is_replaced && (*p & P_INSECURE)))
5304 secure = 1;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005305
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005306 // Handle side effects, and set the global value
5307 // for ":set" on local options. Note: when setting
5308 // 'syntax' or 'filetype' autocommands may be
5309 // triggered that can cause havoc.
5310 errmsg = did_set_string_option(
5311 opt_idx, (char_u **)varp,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005312 new_value_alloced, oldval, errbuf,
5313 opt_flags, &value_checked);
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005314
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005315 secure = secure_saved;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005316 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005317
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005318#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005319 if (errmsg == NULL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02005320 trigger_optionsset_string(
5321 opt_idx, opt_flags, saved_origval,
5322 saved_origval_l, saved_origval_g,
5323 saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005324 vim_free(saved_origval);
Bram Moolenaard7c96872019-06-15 17:12:48 +02005325 vim_free(saved_origval_l);
5326 vim_free(saved_origval_g);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005327 vim_free(saved_newval);
5328#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005329 /* If error detected, print the error message. */
5330 if (errmsg != NULL)
5331 goto skip;
5332 }
5333 else /* key code option */
5334 {
5335 char_u *p;
5336
5337 if (nextchar == '&')
5338 {
5339 if (add_termcap_entry(key_name, TRUE) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005340 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005341 }
5342 else
5343 {
5344 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005345 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005346 if (*p == '\\' && p[1] != NUL)
5347 ++p;
5348 nextchar = *p;
5349 *p = NUL;
5350 add_termcode(key_name, arg, FALSE);
5351 *p = nextchar;
5352 }
5353 if (full_screen)
5354 ttest(FALSE);
5355 redraw_all_later(CLEAR);
5356 }
5357 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005358
Bram Moolenaar071d4272004-06-13 20:20:40 +00005359 if (opt_idx >= 0)
Bram Moolenaar916a8182018-11-25 02:18:29 +01005360 did_set_option(
5361 opt_idx, opt_flags, value_is_replaced, value_checked);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005362 }
5363
5364skip:
5365 /*
5366 * Advance to next argument.
5367 * - skip until a blank found, taking care of backslashes
5368 * - skip blanks
5369 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5370 */
5371 for (i = 0; i < 2 ; ++i)
5372 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005373 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005374 if (*arg++ == '\\' && *arg != NUL)
5375 ++arg;
5376 arg = skipwhite(arg);
5377 if (*arg != '=')
5378 break;
5379 }
5380 }
5381
5382 if (errmsg != NULL)
5383 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005384 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005385 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005386 if (i + (arg - startarg) < IOSIZE)
5387 {
5388 /* append the argument with the error */
5389 STRCAT(IObuff, ": ");
5390 mch_memmove(IObuff + i, startarg, (arg - startarg));
5391 IObuff[i + (arg - startarg)] = NUL;
5392 }
5393 /* make sure all characters are printable */
5394 trans_characters(IObuff, IOSIZE);
5395
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005396 ++no_wait_return; // wait_return done later
5397 emsg((char *)IObuff); // show error highlighted
Bram Moolenaar071d4272004-06-13 20:20:40 +00005398 --no_wait_return;
5399
5400 return FAIL;
5401 }
5402
5403 arg = skipwhite(arg);
5404 }
5405
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005406theend:
5407 if (silent_mode && did_show)
5408 {
5409 /* After displaying option values in silent mode. */
5410 silent_mode = FALSE;
5411 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5412 msg_putchar('\n');
5413 cursor_on(); /* msg_start() switches it off */
5414 out_flush();
5415 silent_mode = TRUE;
5416 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5417 }
5418
Bram Moolenaar071d4272004-06-13 20:20:40 +00005419 return OK;
5420}
5421
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005422/*
5423 * Call this when an option has been given a new value through a user command.
5424 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5425 */
5426 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005427did_set_option(
5428 int opt_idx,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005429 int opt_flags, // possibly with OPT_MODELINE
5430 int new_value, // value was replaced completely
5431 int value_checked) // value was checked to be safe, no need to set the
5432 // P_INSECURE flag.
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005433{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005434 long_u *p;
5435
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005436 options[opt_idx].flags |= P_WAS_SET;
5437
5438 /* When an option is set in the sandbox, from a modeline or in secure mode
5439 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005440 * flag. */
5441 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar916a8182018-11-25 02:18:29 +01005442 if (!value_checked && (secure
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005443#ifdef HAVE_SANDBOX
5444 || sandbox != 0
5445#endif
Bram Moolenaar916a8182018-11-25 02:18:29 +01005446 || (opt_flags & OPT_MODELINE)))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005447 *p = *p | P_INSECURE;
5448 else if (new_value)
5449 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005450}
5451
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005452 static char *
5453illegal_char(char *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005454{
5455 if (errbuf == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005456 return "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00005457 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005458 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005459 return errbuf;
5460}
5461
5462/*
5463 * Convert a key name or string into a key value.
5464 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005465 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005466 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005467 int
5468string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005469{
5470 if (*arg == '<')
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02005471 return find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005472 if (*arg == '^')
5473 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005474 if (multi_byte)
5475 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005476 return *arg;
5477}
5478
5479#ifdef FEAT_CMDWIN
5480/*
5481 * Check value of 'cedit' and set cedit_key.
5482 * Returns NULL if value is OK, error message otherwise.
5483 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005484 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005485check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005486{
5487 int n;
5488
5489 if (*p_cedit == NUL)
5490 cedit_key = -1;
5491 else
5492 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005493 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005494 if (vim_isprintc(n))
5495 return e_invarg;
5496 cedit_key = n;
5497 }
5498 return NULL;
5499}
5500#endif
5501
5502#ifdef FEAT_TITLE
5503/*
5504 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5505 * maketitle() to create and display it.
5506 * When switching the title or icon off, call mch_restore_title() to get
5507 * the old value back.
5508 */
5509 static void
Bram Moolenaar84a93082018-06-16 22:58:15 +02005510did_set_title(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005511{
5512 if (starting != NO_SCREEN
5513#ifdef FEAT_GUI
5514 && !gui.starting
5515#endif
5516 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00005517 maketitle();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005518}
5519#endif
5520
5521/*
5522 * set_options_bin - called when 'bin' changes value.
5523 */
5524 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005525set_options_bin(
5526 int oldval,
5527 int newval,
5528 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005529{
5530 /*
5531 * The option values that are changed when 'bin' changes are
5532 * copied when 'bin is set and restored when 'bin' is reset.
5533 */
5534 if (newval)
5535 {
5536 if (!oldval) /* switched on */
5537 {
5538 if (!(opt_flags & OPT_GLOBAL))
5539 {
5540 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5541 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5542 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5543 curbuf->b_p_et_nobin = curbuf->b_p_et;
5544 }
5545 if (!(opt_flags & OPT_LOCAL))
5546 {
5547 p_tw_nobin = p_tw;
5548 p_wm_nobin = p_wm;
5549 p_ml_nobin = p_ml;
5550 p_et_nobin = p_et;
5551 }
5552 }
5553
5554 if (!(opt_flags & OPT_GLOBAL))
5555 {
5556 curbuf->b_p_tw = 0; /* no automatic line wrap */
5557 curbuf->b_p_wm = 0; /* no automatic line wrap */
5558 curbuf->b_p_ml = 0; /* no modelines */
5559 curbuf->b_p_et = 0; /* no expandtab */
5560 }
5561 if (!(opt_flags & OPT_LOCAL))
5562 {
5563 p_tw = 0;
5564 p_wm = 0;
5565 p_ml = FALSE;
5566 p_et = FALSE;
5567 p_bin = TRUE; /* needed when called for the "-b" argument */
5568 }
5569 }
5570 else if (oldval) /* switched off */
5571 {
5572 if (!(opt_flags & OPT_GLOBAL))
5573 {
5574 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5575 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5576 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5577 curbuf->b_p_et = curbuf->b_p_et_nobin;
5578 }
5579 if (!(opt_flags & OPT_LOCAL))
5580 {
5581 p_tw = p_tw_nobin;
5582 p_wm = p_wm_nobin;
5583 p_ml = p_ml_nobin;
5584 p_et = p_et_nobin;
5585 }
5586 }
5587}
5588
Bram Moolenaar071d4272004-06-13 20:20:40 +00005589/*
5590 * Expand environment variables for some string options.
5591 * These string options cannot be indirect!
5592 * If "val" is NULL expand the current value of the option.
5593 * Return pointer to NameBuff, or NULL when not expanded.
5594 */
5595 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005596option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005597{
5598 /* if option doesn't need expansion nothing to do */
5599 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5600 return NULL;
5601
5602 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5603 * expand_env() would truncate the string. */
5604 if (val != NULL && STRLEN(val) > MAXPATHL)
5605 return NULL;
5606
5607 if (val == NULL)
5608 val = *(char_u **)options[opt_idx].var;
5609
5610 /*
5611 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5612 * Escape spaces when expanding 'tags', they are used to separate file
5613 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005614 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005615 */
5616 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005617 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005618#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005619 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5620#endif
5621 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005622 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5623 return NULL;
5624
5625 return NameBuff;
5626}
5627
5628/*
5629 * After setting various option values: recompute variables that depend on
5630 * option values.
5631 */
5632 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005633didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005634{
5635 /* initialize the table for 'iskeyword' et.al. */
5636 (void)init_chartab();
5637
5638 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
5639 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005640 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005641#ifdef FEAT_SESSION
5642 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5643 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5644#endif
5645#ifdef FEAT_FOLDING
5646 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5647#endif
5648 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005649 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005650 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005651#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5652 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5653#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005654#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005655 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005656 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005657 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005658 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005659#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01005660#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005661 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5662#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005663#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005664 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5665#endif
5666#ifdef FEAT_CMDWIN
5667 /* set cedit_key */
5668 (void)check_cedit();
5669#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005670#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005671 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005672#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005673#ifdef FEAT_LINEBREAK
5674 /* initialize the table for 'breakat'. */
5675 fill_breakat_flags();
5676#endif
5677
5678}
5679
5680/*
5681 * More side effects of setting options.
5682 */
5683 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005684didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005685{
5686 /* Initialize the highlight_attr[] table. */
5687 (void)highlight_changed();
5688
5689 /* Parse default for 'wildmode' */
5690 check_opt_wim();
5691
5692 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005693 /* Parse default for 'fillchars'. */
5694 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005695
5696#ifdef FEAT_CLIPBOARD
5697 /* Parse default for 'clipboard' */
5698 (void)check_clipboard_option();
5699#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005700#ifdef FEAT_VARTABS
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01005701 vim_free(curbuf->b_p_vsts_array);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005702 tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_array);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01005703 vim_free(curbuf->b_p_vts_array);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005704 tabstop_set(curbuf->b_p_vts, &curbuf->b_p_vts_array);
5705#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005706}
5707
5708/*
5709 * Check for string options that are NULL (normally only termcap options).
5710 */
5711 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005712check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005713{
5714 int opt_idx;
5715
5716 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5717 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5718 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5719}
5720
5721/*
5722 * Check string options in a buffer for NULL value.
5723 */
5724 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005725check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005726{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005727 check_string_option(&buf->b_p_bh);
5728 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005729 check_string_option(&buf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005730 check_string_option(&buf->b_p_ff);
5731#ifdef FEAT_FIND_ID
5732 check_string_option(&buf->b_p_def);
5733 check_string_option(&buf->b_p_inc);
5734# ifdef FEAT_EVAL
5735 check_string_option(&buf->b_p_inex);
5736# endif
5737#endif
5738#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5739 check_string_option(&buf->b_p_inde);
5740 check_string_option(&buf->b_p_indk);
5741#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005742#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5743 check_string_option(&buf->b_p_bexpr);
5744#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005745#if defined(FEAT_CRYPT)
5746 check_string_option(&buf->b_p_cm);
5747#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005748 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005749#if defined(FEAT_EVAL)
5750 check_string_option(&buf->b_p_fex);
5751#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005752#ifdef FEAT_CRYPT
5753 check_string_option(&buf->b_p_key);
5754#endif
5755 check_string_option(&buf->b_p_kp);
5756 check_string_option(&buf->b_p_mps);
5757 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005758 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005759 check_string_option(&buf->b_p_isk);
5760#ifdef FEAT_COMMENTS
5761 check_string_option(&buf->b_p_com);
5762#endif
5763#ifdef FEAT_FOLDING
5764 check_string_option(&buf->b_p_cms);
5765#endif
5766 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005767#ifdef FEAT_TEXTOBJ
5768 check_string_option(&buf->b_p_qe);
5769#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005770#ifdef FEAT_SYN_HL
5771 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005772 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005773#endif
5774#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005775 check_string_option(&buf->b_s.b_p_spc);
5776 check_string_option(&buf->b_s.b_p_spf);
5777 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005778#endif
5779#ifdef FEAT_SEARCHPATH
5780 check_string_option(&buf->b_p_sua);
5781#endif
5782#ifdef FEAT_CINDENT
5783 check_string_option(&buf->b_p_cink);
5784 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005785 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005786#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005787 check_string_option(&buf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005788#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5789 check_string_option(&buf->b_p_cinw);
5790#endif
5791#ifdef FEAT_INS_EXPAND
5792 check_string_option(&buf->b_p_cpt);
5793#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005794#ifdef FEAT_COMPL_FUNC
5795 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005796 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005797#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +02005798#ifdef FEAT_EVAL
5799 check_string_option(&buf->b_p_tfu);
5800#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005801#ifdef FEAT_KEYMAP
5802 check_string_option(&buf->b_p_keymap);
5803#endif
5804#ifdef FEAT_QUICKFIX
5805 check_string_option(&buf->b_p_gp);
5806 check_string_option(&buf->b_p_mp);
5807 check_string_option(&buf->b_p_efm);
5808#endif
5809 check_string_option(&buf->b_p_ep);
5810 check_string_option(&buf->b_p_path);
5811 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005812 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005813#ifdef FEAT_INS_EXPAND
5814 check_string_option(&buf->b_p_dict);
5815 check_string_option(&buf->b_p_tsr);
5816#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005817#ifdef FEAT_LISP
5818 check_string_option(&buf->b_p_lw);
5819#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005820 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005821 check_string_option(&buf->b_p_menc);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005822#ifdef FEAT_VARTABS
5823 check_string_option(&buf->b_p_vsts);
5824 check_string_option(&buf->b_p_vts);
5825#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005826}
5827
5828/*
5829 * Free the string allocated for an option.
5830 * Checks for the string being empty_option. This may happen if we're out of
5831 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5832 * check_options().
5833 * Does NOT check for P_ALLOCED flag!
5834 */
5835 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005836free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005837{
5838 if (p != empty_option)
5839 vim_free(p);
5840}
5841
5842 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005843clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005844{
5845 if (*pp != empty_option)
5846 vim_free(*pp);
5847 *pp = empty_option;
5848}
5849
5850 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005851check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005852{
5853 if (*pp == NULL)
5854 *pp = empty_option;
5855}
5856
5857/*
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005858 * Return the option index found by a pointer into term_strings[].
5859 * Return -1 if not found.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005860 */
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005861 int
5862get_term_opt_idx(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005863{
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005864 int opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005865
5866 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5867 if (options[opt_idx].var == (char_u *)p)
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005868 return opt_idx;
5869 return -1; // cannot happen: didn't find it!
5870}
5871
5872/*
5873 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5874 * Return the option index or -1 if not found.
5875 */
5876 int
5877set_term_option_alloced(char_u **p)
5878{
5879 int opt_idx = get_term_opt_idx(p);
5880
5881 if (opt_idx >= 0)
5882 options[opt_idx].flags |= P_ALLOCED;
5883 return opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005884}
5885
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005886#if defined(FEAT_EVAL) || defined(PROTO)
5887/*
5888 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5889 * Return FALSE when it wasn't.
5890 * Return -1 for an unknown option.
5891 */
5892 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005893was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005894{
5895 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005896 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005897
5898 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005899 {
5900 flagp = insecure_flag(idx, opt_flags);
5901 return (*flagp & P_INSECURE) != 0;
5902 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005903 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005904 return -1;
5905}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005906
5907/*
5908 * Get a pointer to the flags used for the P_INSECURE flag of option
5909 * "opt_idx". For some local options a local flags field is used.
5910 */
5911 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005912insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005913{
5914 if (opt_flags & OPT_LOCAL)
5915 switch ((int)options[opt_idx].indir)
5916 {
5917#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005918 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005919#endif
5920#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005921# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005922 case PV_FDE: return &curwin->w_p_fde_flags;
5923 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005924# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005925# ifdef FEAT_BEVAL
5926 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5927# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005928# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005929 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005930# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005931 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005932# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005933 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005934# endif
5935#endif
5936 }
5937
5938 /* Nothing special, return global flags field. */
5939 return &options[opt_idx].flags;
5940}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005941#endif
5942
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005943#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005944/*
5945 * Redraw the window title and/or tab page text later.
5946 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005947static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005948{
5949 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005950 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005951}
5952#endif
5953
Bram Moolenaar071d4272004-06-13 20:20:40 +00005954/*
5955 * Set a string option to a new value (without checking the effect).
5956 * The string is copied into allocated memory.
5957 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005958 * When "set_sid" is zero set the scriptID to current_sctx.sc_sid. When
5959 * "set_sid" is SID_NONE don't set the scriptID. Otherwise set the scriptID to
5960 * "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005961 */
5962 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005963set_string_option_direct(
5964 char_u *name,
5965 int opt_idx,
5966 char_u *val,
5967 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5968 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005969{
5970 char_u *s;
5971 char_u **varp;
5972 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005973 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005974
Bram Moolenaar89d40322006-08-29 15:30:07 +00005975 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005976 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005977 idx = findoption(name);
5978 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005979 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005980 semsg(_(e_intern2), "set_string_option_direct()");
5981 siemsg(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005982 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005983 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005984 }
5985
Bram Moolenaar89d40322006-08-29 15:30:07 +00005986 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005987 return;
5988
5989 s = vim_strsave(val);
5990 if (s != NULL)
5991 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005992 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005993 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005994 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005995 free_string_option(*varp);
5996 *varp = s;
5997
5998 /* For buffer/window local option may also set the global value. */
5999 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00006000 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006001
Bram Moolenaar89d40322006-08-29 15:30:07 +00006002 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006003
6004 /* When setting both values of a global option with a local value,
6005 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00006006 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006007 {
6008 free_string_option(*varp);
6009 *varp = empty_option;
6010 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006011# ifdef FEAT_EVAL
6012 if (set_sid != SID_NONE)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02006013 {
6014 sctx_T script_ctx;
6015
6016 if (set_sid == 0)
6017 script_ctx = current_sctx;
6018 else
6019 {
6020 script_ctx.sc_sid = set_sid;
Bram Moolenaarded5f1b2018-11-10 17:33:29 +01006021 script_ctx.sc_seq = 0;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02006022 script_ctx.sc_lnum = 0;
Bram Moolenaar558ca4a2019-04-04 18:15:38 +02006023 script_ctx.sc_version = 1;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02006024 }
6025 set_option_sctx_idx(idx, opt_flags, script_ctx);
6026 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006027# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006028 }
6029}
6030
6031/*
Bram Moolenaar20c023a2019-05-26 21:03:24 +02006032 * Like set_string_option_direct(), but for a window-local option in "wp".
6033 * Blocks autocommands to avoid the old curwin becoming invalid.
6034 */
6035 void
6036set_string_option_direct_in_win(
6037 win_T *wp,
6038 char_u *name,
6039 int opt_idx,
6040 char_u *val,
6041 int opt_flags,
6042 int set_sid)
6043{
6044 win_T *save_curwin = curwin;
6045
6046 block_autocmds();
6047 curwin = wp;
6048 curbuf = curwin->w_buffer;
6049 set_string_option_direct(name, opt_idx, val, opt_flags, set_sid);
6050 curwin = save_curwin;
6051 curbuf = curwin->w_buffer;
6052 unblock_autocmds();
6053}
6054
6055/*
6056 * Like set_string_option_direct(), but for a buffer-local option in "buf".
6057 * Blocks autocommands to avoid the old curbuf becoming invalid.
6058 */
6059 void
6060set_string_option_direct_in_buf(
6061 buf_T *buf,
6062 char_u *name,
6063 int opt_idx,
6064 char_u *val,
6065 int opt_flags,
6066 int set_sid)
6067{
6068 buf_T *save_curbuf = curbuf;
6069
6070 block_autocmds();
6071 curbuf = buf;
6072 curwin->w_buffer = curbuf;
6073 set_string_option_direct(name, opt_idx, val, opt_flags, set_sid);
6074 curbuf = save_curbuf;
6075 curwin->w_buffer = curbuf;
6076 unblock_autocmds();
6077}
6078
6079/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006080 * Set global value for string option when it's a local option.
6081 */
6082 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01006083set_string_option_global(
6084 int opt_idx, /* option index */
6085 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006086{
6087 char_u **p, *s;
6088
6089 /* the global value is always allocated */
6090 if (options[opt_idx].var == VAR_WIN)
6091 p = (char_u **)GLOBAL_WO(varp);
6092 else
6093 p = (char_u **)options[opt_idx].var;
6094 if (options[opt_idx].indir != PV_NONE
6095 && p != varp
6096 && (s = vim_strsave(*varp)) != NULL)
6097 {
6098 free_string_option(*p);
6099 *p = s;
6100 }
6101}
6102
6103/*
6104 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006105 *
6106 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006107 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006108 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006109set_string_option(
6110 int opt_idx,
6111 char_u *value,
6112 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006113{
6114 char_u *s;
6115 char_u **varp;
6116 char_u *oldval;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02006117#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02006118 char_u *oldval_l = NULL;
6119 char_u *oldval_g = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02006120 char_u *saved_oldval = NULL;
Bram Moolenaard7c96872019-06-15 17:12:48 +02006121 char_u *saved_oldval_l = NULL;
6122 char_u *saved_oldval_g = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006123 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02006124#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006125 char *r = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01006126 int value_checked = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006127
6128 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006129 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006130
6131 s = vim_strsave(value);
6132 if (s != NULL)
6133 {
6134 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
6135 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006136 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006137 ? OPT_GLOBAL : OPT_LOCAL)
6138 : opt_flags);
6139 oldval = *varp;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02006140#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02006141 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6142 {
6143 oldval_l = *(char_u **)get_varp_scope(&(options[opt_idx]),
6144 OPT_LOCAL);
6145 oldval_g = *(char_u **)get_varp_scope(&(options[opt_idx]),
6146 OPT_GLOBAL);
6147 }
Bram Moolenaar983f2f12019-06-16 16:41:41 +02006148#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006149 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02006150
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006151#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02006152 if (!starting
6153# ifdef FEAT_CRYPT
6154 && options[opt_idx].indir != PV_KEY
6155# endif
6156 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006157 {
Bram Moolenaard7c96872019-06-15 17:12:48 +02006158 if (oldval_l != NULL)
6159 saved_oldval_l = vim_strsave(oldval_l);
6160 if (oldval_g != NULL)
6161 saved_oldval_g = vim_strsave(oldval_g);
Bram Moolenaar53744302015-07-17 17:38:22 +02006162 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006163 saved_newval = vim_strsave(s);
6164 }
Bram Moolenaar53744302015-07-17 17:38:22 +02006165#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006166 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
Bram Moolenaar916a8182018-11-25 02:18:29 +01006167 opt_flags, &value_checked)) == NULL)
6168 did_set_option(opt_idx, opt_flags, TRUE, value_checked);
Bram Moolenaar53744302015-07-17 17:38:22 +02006169
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006170#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006171 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006172 if (r == NULL)
6173 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaard7c96872019-06-15 17:12:48 +02006174 saved_oldval, saved_oldval_l,
6175 saved_oldval_g, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006176 vim_free(saved_oldval);
Bram Moolenaard7c96872019-06-15 17:12:48 +02006177 vim_free(saved_oldval_l);
6178 vim_free(saved_oldval_g);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006179 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02006180#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006181 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006182 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006183}
6184
6185/*
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006186 * Return TRUE if "val" is a valid name: only consists of alphanumeric ASCII
6187 * characters or characters in "allowed".
6188 */
6189 static int
6190valid_name(char_u *val, char *allowed)
6191{
6192 char_u *s;
6193
6194 for (s = val; *s != NUL; ++s)
6195 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)allowed, *s) == NULL)
6196 return FALSE;
6197 return TRUE;
6198}
6199
6200/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01006201 * Return TRUE if "val" is a valid 'filetype' name.
6202 * Also used for 'syntax' and 'keymap'.
6203 */
6204 static int
6205valid_filetype(char_u *val)
6206{
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006207 return valid_name(val, ".-_");
6208}
Bram Moolenaard0b51382016-11-04 15:23:45 +01006209
Bram Moolenaara7be0f22019-04-11 11:19:32 +02006210#if defined(FEAT_SPELL) || defined(PROTO)
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006211/*
6212 * Return TRUE if "val" is a valid 'spellang' value.
6213 */
6214 int
6215valid_spellang(char_u *val)
6216{
Bram Moolenaar9a061cb2019-05-05 16:55:03 +02006217 return valid_name(val, ".-_,@");
Bram Moolenaard0b51382016-11-04 15:23:45 +01006218}
6219
6220/*
Bram Moolenaar862f1e12019-04-10 22:33:41 +02006221 * Return TRUE if "val" is a valid 'spellfile' value.
6222 */
6223 static int
6224valid_spellfile(char_u *val)
6225{
6226 char_u *s;
6227
6228 for (s = val; *s != NUL; ++s)
6229 if (!vim_isfilec(*s) && *s != ',')
6230 return FALSE;
6231 return TRUE;
6232}
Bram Moolenaara7be0f22019-04-11 11:19:32 +02006233#endif
Bram Moolenaar862f1e12019-04-10 22:33:41 +02006234
6235/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006236 * Handle string options that need some action to perform when changed.
6237 * Returns NULL for success, or an error message for an error.
6238 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006239 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006240did_set_string_option(
Bram Moolenaar916a8182018-11-25 02:18:29 +01006241 int opt_idx, // index in options[] table
6242 char_u **varp, // pointer to the option variable
6243 int new_value_alloced, // new value was allocated
6244 char_u *oldval, // previous value of the option
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006245 char *errbuf, // buffer for errors, or NULL
Bram Moolenaar916a8182018-11-25 02:18:29 +01006246 int opt_flags, // OPT_LOCAL and/or OPT_GLOBAL
6247 int *value_checked) // value was checked to be save, no
6248 // need to set P_INSECURE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006249{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006250 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006251 char_u *s, *p;
6252 int did_chartab = FALSE;
6253 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006254 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006255#ifdef FEAT_GUI
6256 /* set when changing an option that only requires a redraw in the GUI */
6257 int redraw_gui_only = FALSE;
6258#endif
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02006259 int value_changed = FALSE;
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006260#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6261 int did_swaptcap = FALSE;
6262#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006263
6264 /* Get the global option to compare with, otherwise we would have to check
6265 * two values for all local options. */
6266 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6267
6268 /* Disallow changing some options from secure mode */
6269 if ((secure
6270#ifdef HAVE_SANDBOX
6271 || sandbox != 0
6272#endif
6273 ) && (options[opt_idx].flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006274 errmsg = e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006275
Bram Moolenaar916a8182018-11-25 02:18:29 +01006276 // Check for a "normal" directory or file name in some options. Disallow a
6277 // path separator (slash and/or backslash), wildcards and characters that
6278 // are often illegal in a file name. Be more permissive if "secure" is off.
Bram Moolenaar7554da42016-11-25 22:04:13 +01006279 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006280 && vim_strpbrk(*varp, (char_u *)(secure
6281 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006282 || ((options[opt_idx].flags & P_NDNAME)
6283 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006284 errmsg = e_invarg;
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006285
Bram Moolenaar071d4272004-06-13 20:20:40 +00006286 /* 'term' */
6287 else if (varp == &T_NAME)
6288 {
6289 if (T_NAME[0] == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006290 errmsg = N_("E529: Cannot set 'term' to empty string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006291#ifdef FEAT_GUI
6292 if (gui.in_use)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006293 errmsg = N_("E530: Cannot change term in GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006294 else if (term_is_gui(T_NAME))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006295 errmsg = N_("E531: Use \":gui\" to start the GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006296#endif
6297 else if (set_termname(T_NAME) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006298 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006299 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006300 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006301 /* Screen colors may have changed. */
6302 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006303
6304 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6305 * P_ALLOCED flag on 'term'. */
6306 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006307 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006308 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006309 }
6310
6311 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006312 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006313 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006314 char_u *bkc = p_bkc;
6315 unsigned int *flags = &bkc_flags;
6316
6317 if (opt_flags & OPT_LOCAL)
6318 {
6319 bkc = curbuf->b_p_bkc;
6320 flags = &curbuf->b_bkc_flags;
6321 }
6322
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006323 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6324 /* make the local value empty: use the global value */
6325 *flags = 0;
6326 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006327 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006328 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6329 errmsg = e_invarg;
6330 if ((((int)*flags & BKC_AUTO) != 0)
6331 + (((int)*flags & BKC_YES) != 0)
6332 + (((int)*flags & BKC_NO) != 0) != 1)
6333 {
6334 /* Must have exactly one of "auto", "yes" and "no". */
6335 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6336 errmsg = e_invarg;
6337 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006338 }
6339 }
6340
6341 /* 'backupext' and 'patchmode' */
6342 else if (varp == &p_bex || varp == &p_pm)
6343 {
6344 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6345 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006346 errmsg = N_("E589: 'backupext' and 'patchmode' are equal");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006347 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006348#ifdef FEAT_LINEBREAK
6349 /* 'breakindentopt' */
6350 else if (varp == &curwin->w_p_briopt)
6351 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006352 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006353 errmsg = e_invarg;
6354 }
6355#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006356
6357 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006358 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006359 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006360 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006361 */
6362 else if ( varp == &p_isi
6363 || varp == &(curbuf->b_p_isk)
6364 || varp == &p_isp
6365 || varp == &p_isf)
6366 {
6367 if (init_chartab() == FAIL)
6368 {
6369 did_chartab = TRUE; /* need to restore it below */
6370 errmsg = e_invarg; /* error in value */
6371 }
6372 }
6373
6374 /* 'helpfile' */
6375 else if (varp == &p_hf)
6376 {
6377 /* May compute new values for $VIM and $VIMRUNTIME */
6378 if (didset_vim)
6379 {
6380 vim_setenv((char_u *)"VIM", (char_u *)"");
6381 didset_vim = FALSE;
6382 }
6383 if (didset_vimruntime)
6384 {
6385 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6386 didset_vimruntime = FALSE;
6387 }
6388 }
6389
Bram Moolenaar1a384422010-07-14 19:53:30 +02006390#ifdef FEAT_SYN_HL
6391 /* 'colorcolumn' */
6392 else if (varp == &curwin->w_p_cc)
6393 errmsg = check_colorcolumn(curwin);
6394#endif
6395
Bram Moolenaar071d4272004-06-13 20:20:40 +00006396#ifdef FEAT_MULTI_LANG
6397 /* 'helplang' */
6398 else if (varp == &p_hlg)
6399 {
6400 /* Check for "", "ab", "ab,cd", etc. */
6401 for (s = p_hlg; *s != NUL; s += 3)
6402 {
6403 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6404 {
6405 errmsg = e_invarg;
6406 break;
6407 }
6408 if (s[2] == NUL)
6409 break;
6410 }
6411 }
6412#endif
6413
6414 /* 'highlight' */
6415 else if (varp == &p_hl)
6416 {
6417 if (highlight_changed() == FAIL)
6418 errmsg = e_invarg; /* invalid flags */
6419 }
6420
6421 /* 'nrformats' */
6422 else if (gvarp == &p_nf)
6423 {
6424 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6425 errmsg = e_invarg;
6426 }
6427
6428#ifdef FEAT_SESSION
6429 /* 'sessionoptions' */
6430 else if (varp == &p_ssop)
6431 {
6432 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6433 errmsg = e_invarg;
6434 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6435 {
6436 /* Don't allow both "sesdir" and "curdir". */
6437 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6438 errmsg = e_invarg;
6439 }
6440 }
6441 /* 'viewoptions' */
6442 else if (varp == &p_vop)
6443 {
6444 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6445 errmsg = e_invarg;
6446 }
6447#endif
6448
6449 /* 'scrollopt' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006450 else if (varp == &p_sbo)
6451 {
6452 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6453 errmsg = e_invarg;
6454 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006455
6456 /* 'ambiwidth' */
Bram Moolenaar3848e002016-03-19 18:42:29 +01006457 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006458 {
6459 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6460 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006461 else if (set_chars_option(&p_lcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006462 errmsg = _("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006463 else if (set_chars_option(&p_fcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006464 errmsg = _("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006465 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006466
6467 /* 'background' */
6468 else if (varp == &p_bg)
6469 {
6470 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6471 {
6472#ifdef FEAT_EVAL
6473 int dark = (*p_bg == 'd');
6474#endif
6475
6476 init_highlight(FALSE, FALSE);
6477
6478#ifdef FEAT_EVAL
6479 if (dark != (*p_bg == 'd')
6480 && get_var_value((char_u *)"g:colors_name") != NULL)
6481 {
6482 /* The color scheme must have set 'background' back to another
6483 * value, that's not what we want here. Disable the color
6484 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006485 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006486 free_string_option(p_bg);
6487 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6488 check_string_option(&p_bg);
6489 init_highlight(FALSE, FALSE);
6490 }
6491#endif
6492 }
6493 else
6494 errmsg = e_invarg;
6495 }
6496
6497 /* 'wildmode' */
6498 else if (varp == &p_wim)
6499 {
6500 if (check_opt_wim() == FAIL)
6501 errmsg = e_invarg;
6502 }
6503
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006504#ifdef FEAT_CMDL_COMPL
6505 /* 'wildoptions' */
6506 else if (varp == &p_wop)
6507 {
6508 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6509 errmsg = e_invarg;
6510 }
6511#endif
6512
Bram Moolenaar071d4272004-06-13 20:20:40 +00006513#ifdef FEAT_WAK
6514 /* 'winaltkeys' */
6515 else if (varp == &p_wak)
6516 {
6517 if (*p_wak == NUL
6518 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6519 errmsg = e_invarg;
6520# ifdef FEAT_MENU
6521# ifdef FEAT_GUI_MOTIF
6522 else if (gui.in_use)
6523 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6524# else
6525# ifdef FEAT_GUI_GTK
6526 else if (gui.in_use)
6527 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6528# endif
6529# endif
6530# endif
6531 }
6532#endif
6533
Bram Moolenaar071d4272004-06-13 20:20:40 +00006534 /* 'eventignore' */
6535 else if (varp == &p_ei)
6536 {
6537 if (check_ei() == FAIL)
6538 errmsg = e_invarg;
6539 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006540
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006541 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6542 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6543 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006544 {
6545 if (gvarp == &p_fenc)
6546 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006547 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006548 errmsg = e_modifiable;
6549 else if (vim_strchr(*varp, ',') != NULL)
6550 /* No comma allowed in 'fileencoding'; catches confusing it
6551 * with 'fileencodings'. */
6552 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006553 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006554 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006555#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006556 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006557 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006558#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006559 /* Add 'fileencoding' to the swap file. */
6560 ml_setflags(curbuf);
6561 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006562 }
6563 if (errmsg == NULL)
6564 {
6565 /* canonize the value, so that STRCMP() can be used on it */
6566 p = enc_canonize(*varp);
6567 if (p != NULL)
6568 {
6569 vim_free(*varp);
6570 *varp = p;
6571 }
6572 if (varp == &p_enc)
6573 {
6574 errmsg = mb_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006575#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006576 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006577#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006578 }
6579 }
6580
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006581#if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006582 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6583 {
6584 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6585 if (STRCMP(p_tenc, "utf-8") != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006586 errmsg = N_("E617: Cannot be changed in the GTK+ 2 GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006587 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006588#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006589
6590 if (errmsg == NULL)
6591 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006592#ifdef FEAT_KEYMAP
Bram Moolenaar071d4272004-06-13 20:20:40 +00006593 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6594 * (with another encoding). */
6595 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6596 (void)keymap_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006597#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006598
6599 /* When 'termencoding' is not empty and 'encoding' changes or when
6600 * 'termencoding' changes, need to setup for keyboard input and
6601 * display output conversion. */
6602 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6603 {
Bram Moolenaar17471e82017-11-26 23:47:18 +01006604 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6605 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6606 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006607 semsg(_("E950: Cannot convert between %s and %s"),
Bram Moolenaar17471e82017-11-26 23:47:18 +01006608 p_tenc, p_enc);
6609 errmsg = e_invarg;
6610 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006611 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006612
Bram Moolenaar4f974752019-02-17 17:44:42 +01006613#if defined(MSWIN)
Bram Moolenaar05159a02005-02-26 23:04:13 +00006614 /* $HOME may have characters in active code page. */
6615 if (varp == &p_enc)
6616 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006617#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006618 }
6619 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006620
6621#if defined(FEAT_POSTSCRIPT)
6622 else if (varp == &p_penc)
6623 {
6624 /* Canonize printencoding if VIM standard one */
6625 p = enc_canonize(p_penc);
6626 if (p != NULL)
6627 {
6628 vim_free(p_penc);
6629 p_penc = p;
6630 }
6631 else
6632 {
6633 /* Ensure lower case and '-' for '_' */
6634 for (s = p_penc; *s != NUL; s++)
6635 {
6636 if (*s == '_')
6637 *s = '-';
6638 else
6639 *s = TOLOWER_ASC(*s);
6640 }
6641 }
6642 }
6643#endif
6644
Bram Moolenaar9372a112005-12-06 19:59:18 +00006645#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006646 else if (varp == &p_imak)
6647 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006648 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006649 errmsg = e_invarg;
6650 }
6651#endif
6652
6653#ifdef FEAT_KEYMAP
6654 else if (varp == &curbuf->b_p_keymap)
6655 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006656 if (!valid_filetype(*varp))
6657 errmsg = e_invarg;
6658 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01006659 {
6660 int secure_save = secure;
6661
6662 // Reset the secure flag, since the value of 'keymap' has
6663 // been checked to be safe.
6664 secure = 0;
6665
6666 // load or unload key mapping tables
Bram Moolenaard0b51382016-11-04 15:23:45 +01006667 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006668
Bram Moolenaar916a8182018-11-25 02:18:29 +01006669 secure = secure_save;
6670
6671 // Since we check the value, there is no need to set P_INSECURE,
6672 // even when the value comes from a modeline.
6673 *value_checked = TRUE;
6674 }
6675
Bram Moolenaarfab06232009-03-04 03:13:35 +00006676 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006677 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006678 if (*curbuf->b_p_keymap != NUL)
6679 {
6680 /* Installed a new keymap, switch on using it. */
6681 curbuf->b_p_iminsert = B_IMODE_LMAP;
6682 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6683 curbuf->b_p_imsearch = B_IMODE_LMAP;
6684 }
6685 else
6686 {
6687 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6688 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6689 curbuf->b_p_iminsert = B_IMODE_NONE;
6690 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6691 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6692 }
6693 if ((opt_flags & OPT_LOCAL) == 0)
6694 {
6695 set_iminsert_global();
6696 set_imsearch_global();
6697 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006698 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006699 }
6700 }
6701#endif
6702
6703 /* 'fileformat' */
6704 else if (gvarp == &p_ff)
6705 {
6706 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6707 errmsg = e_modifiable;
6708 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6709 errmsg = e_invarg;
6710 else
6711 {
6712 /* may also change 'textmode' */
6713 if (get_fileformat(curbuf) == EOL_DOS)
6714 curbuf->b_p_tx = TRUE;
6715 else
6716 curbuf->b_p_tx = FALSE;
6717#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006718 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006719#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006720 /* update flag in swap file */
6721 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006722 /* Redraw needed when switching to/from "mac": a CR in the text
6723 * will be displayed differently. */
6724 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6725 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006726 }
6727 }
6728
6729 /* 'fileformats' */
6730 else if (varp == &p_ffs)
6731 {
6732 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6733 errmsg = e_invarg;
6734 else
6735 {
6736 /* also change 'textauto' */
6737 if (*p_ffs == NUL)
6738 p_ta = FALSE;
6739 else
6740 p_ta = TRUE;
6741 }
6742 }
6743
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006744#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006745 /* 'cryptkey' */
6746 else if (gvarp == &p_key)
6747 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006748# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006749 /* Make sure the ":set" command doesn't show the new value in the
6750 * history. */
6751 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006752# endif
6753 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6754 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006755 ml_set_crypt_key(curbuf, oldval,
6756 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006757 }
6758
6759 else if (gvarp == &p_cm)
6760 {
6761 if (opt_flags & OPT_LOCAL)
6762 p = curbuf->b_p_cm;
6763 else
6764 p = p_cm;
6765 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6766 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006767 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006768 errmsg = e_invarg;
6769 else
6770 {
6771 /* When setting the global value to empty, make it "zip". */
6772 if (*p_cm == NUL)
6773 {
6774 if (new_value_alloced)
6775 free_string_option(p_cm);
6776 p_cm = vim_strsave((char_u *)"zip");
6777 new_value_alloced = TRUE;
6778 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006779 /* When using ":set cm=name" the local value is going to be empty.
6780 * Do that here, otherwise the crypt functions will still use the
6781 * local value. */
6782 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6783 {
6784 free_string_option(curbuf->b_p_cm);
6785 curbuf->b_p_cm = empty_option;
6786 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006787
6788 /* Need to update the swapfile when the effective method changed.
6789 * Set "s" to the effective old value, "p" to the effective new
6790 * method and compare. */
6791 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6792 s = p_cm; /* was previously using the global value */
6793 else
6794 s = oldval;
6795 if (*curbuf->b_p_cm == NUL)
6796 p = p_cm; /* is now using the global value */
6797 else
6798 p = curbuf->b_p_cm;
6799 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006800 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006801
6802 /* If the global value changes need to update the swapfile for all
6803 * buffers using that value. */
6804 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6805 {
6806 buf_T *buf;
6807
Bram Moolenaar29323592016-07-24 22:04:11 +02006808 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006809 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006810 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006811 }
6812 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006813 }
6814#endif
6815
6816 /* 'matchpairs' */
6817 else if (gvarp == &p_mps)
6818 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006819 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006820 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006821 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006822 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006823 int x2 = -1;
6824 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006825
6826 if (*p != NUL)
6827 p += mb_ptr2len(p);
6828 if (*p != NUL)
6829 x2 = *p++;
6830 if (*p != NUL)
6831 {
6832 x3 = mb_ptr2char(p);
6833 p += mb_ptr2len(p);
6834 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006835 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006836 {
6837 errmsg = e_invarg;
6838 break;
6839 }
6840 if (*p == NUL)
6841 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006842 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006843 }
6844 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006845 {
6846 /* Check for "x:y,x:y" */
6847 for (p = *varp; *p != NUL; p += 4)
6848 {
6849 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6850 {
6851 errmsg = e_invarg;
6852 break;
6853 }
6854 if (p[3] == NUL)
6855 break;
6856 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006857 }
6858 }
6859
6860#ifdef FEAT_COMMENTS
6861 /* 'comments' */
6862 else if (gvarp == &p_com)
6863 {
6864 for (s = *varp; *s; )
6865 {
6866 while (*s && *s != ':')
6867 {
6868 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6869 && !VIM_ISDIGIT(*s) && *s != '-')
6870 {
6871 errmsg = illegal_char(errbuf, *s);
6872 break;
6873 }
6874 ++s;
6875 }
6876 if (*s++ == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006877 errmsg = N_("E524: Missing colon");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006878 else if (*s == ',' || *s == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006879 errmsg = N_("E525: Zero length string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006880 if (errmsg != NULL)
6881 break;
6882 while (*s && *s != ',')
6883 {
6884 if (*s == '\\' && s[1] != NUL)
6885 ++s;
6886 ++s;
6887 }
6888 s = skip_to_option_part(s);
6889 }
6890 }
6891#endif
6892
6893 /* 'listchars' */
6894 else if (varp == &p_lcs)
6895 {
6896 errmsg = set_chars_option(varp);
6897 }
6898
Bram Moolenaar071d4272004-06-13 20:20:40 +00006899 /* 'fillchars' */
6900 else if (varp == &p_fcs)
6901 {
6902 errmsg = set_chars_option(varp);
6903 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006904
6905#ifdef FEAT_CMDWIN
6906 /* 'cedit' */
6907 else if (varp == &p_cedit)
6908 {
6909 errmsg = check_cedit();
6910 }
6911#endif
6912
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006913 /* 'verbosefile' */
6914 else if (varp == &p_vfile)
6915 {
6916 verbose_stop();
6917 if (*p_vfile != NUL && verbose_open() == FAIL)
6918 errmsg = e_invarg;
6919 }
6920
Bram Moolenaar071d4272004-06-13 20:20:40 +00006921#ifdef FEAT_VIMINFO
6922 /* 'viminfo' */
6923 else if (varp == &p_viminfo)
6924 {
6925 for (s = p_viminfo; *s;)
6926 {
6927 /* Check it's a valid character */
6928 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6929 {
6930 errmsg = illegal_char(errbuf, *s);
6931 break;
6932 }
6933 if (*s == 'n') /* name is always last one */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006934 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006935 else if (*s == 'r') /* skip until next ',' */
6936 {
6937 while (*++s && *s != ',')
6938 ;
6939 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006940 else if (*s == '%')
6941 {
6942 /* optional number */
6943 while (vim_isdigit(*++s))
6944 ;
6945 }
6946 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006947 ++s; /* no extra chars */
6948 else /* must have a number */
6949 {
6950 while (vim_isdigit(*++s))
6951 ;
6952
6953 if (!VIM_ISDIGIT(*(s - 1)))
6954 {
6955 if (errbuf != NULL)
6956 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006957 sprintf(errbuf, _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006958 transchar_byte(*(s - 1)));
6959 errmsg = errbuf;
6960 }
6961 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006962 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006963 break;
6964 }
6965 }
6966 if (*s == ',')
6967 ++s;
6968 else if (*s)
6969 {
6970 if (errbuf != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006971 errmsg = N_("E527: Missing comma");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006972 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006973 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006974 break;
6975 }
6976 }
6977 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006978 errmsg = N_("E528: Must specify a ' value");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006979 }
6980#endif /* FEAT_VIMINFO */
6981
6982 /* terminal options */
6983 else if (istermoption(&options[opt_idx]) && full_screen)
6984 {
6985 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6986 if (varp == &T_CCO)
6987 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006988 int colors = atoi((char *)T_CCO);
6989
6990 /* Only reinitialize colors if t_Co value has really changed to
6991 * avoid expensive reload of colorscheme if t_Co is set to the
6992 * same value multiple times. */
6993 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006994 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006995 t_colors = colors;
6996 if (t_colors <= 1)
6997 {
6998 if (new_value_alloced)
6999 vim_free(T_CCO);
7000 T_CCO = empty_option;
7001 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007002#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
7003 if (is_term_win32())
7004 {
7005 swap_tcap();
7006 did_swaptcap = TRUE;
7007 }
7008#endif
Bram Moolenaarc84e8952009-03-18 13:21:18 +00007009 /* We now have a different color setup, initialize it again. */
7010 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007011 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007012 }
7013 ttest(FALSE);
7014 if (varp == &T_ME)
7015 {
7016 out_str(T_ME);
7017 redraw_later(CLEAR);
Bram Moolenaarafde13b2019-04-28 19:46:49 +02007018#if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007019 /* Since t_me has been set, this probably means that the user
7020 * wants to use this as default colors. Need to reset default
7021 * background/foreground colors. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02007022# ifdef VIMDLL
7023 if (!gui.in_use && !gui.starting)
7024# endif
7025 mch_set_normal_colors();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007026#endif
7027 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01007028 if (varp == &T_BE && termcap_active)
7029 {
7030 if (*T_BE == NUL)
7031 /* When clearing t_BE we assume the user no longer wants
7032 * bracketed paste, thus disable it by writing t_BD. */
7033 out_str(T_BD);
7034 else
7035 out_str(T_BE);
7036 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007037 }
7038
7039#ifdef FEAT_LINEBREAK
7040 /* 'showbreak' */
7041 else if (varp == &p_sbr)
7042 {
7043 for (s = p_sbr; *s; )
7044 {
7045 if (ptr2cells(s) != 1)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007046 errmsg = N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01007047 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007048 }
7049 }
7050#endif
7051
7052#ifdef FEAT_GUI
7053 /* 'guifont' */
7054 else if (varp == &p_guifont)
7055 {
7056 if (gui.in_use)
7057 {
7058 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00007059# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007060 /*
7061 * Put up a font dialog and let the user select a new value.
7062 * If this is cancelled go back to the old value but don't
7063 * give an error message.
7064 */
7065 if (STRCMP(p, "*") == 0)
7066 {
7067 p = gui_mch_font_dialog(oldval);
7068
7069 if (new_value_alloced)
7070 free_string_option(p_guifont);
7071
7072 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
7073 new_value_alloced = TRUE;
7074 }
7075# endif
7076 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
7077 {
7078# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
7079 if (STRCMP(p_guifont, "*") == 0)
7080 {
7081 /* Dialog was cancelled: Keep the old value without giving
7082 * an error message. */
7083 if (new_value_alloced)
7084 free_string_option(p_guifont);
7085 p_guifont = vim_strsave(oldval);
7086 new_value_alloced = TRUE;
7087 }
7088 else
7089# endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007090 errmsg = N_("E596: Invalid font(s)");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007091 }
7092 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007093 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007094 }
7095# ifdef FEAT_XFONTSET
7096 else if (varp == &p_guifontset)
7097 {
7098 if (STRCMP(p_guifontset, "*") == 0)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007099 errmsg = N_("E597: can't select fontset");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007100 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007101 errmsg = N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007102 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007103 }
7104# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007105 else if (varp == &p_guifontwide)
7106 {
7107 if (STRCMP(p_guifontwide, "*") == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007108 errmsg = N_("E533: can't select wide font");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007109 else if (gui_get_wide_font() == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007110 errmsg = N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007111 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007112 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007113#endif
7114
7115#ifdef CURSOR_SHAPE
7116 /* 'guicursor' */
7117 else if (varp == &p_guicursor)
7118 errmsg = parse_shape_opt(SHAPE_CURSOR);
7119#endif
7120
7121#ifdef FEAT_MOUSESHAPE
7122 /* 'mouseshape' */
7123 else if (varp == &p_mouseshape)
7124 {
7125 errmsg = parse_shape_opt(SHAPE_MOUSE);
7126 update_mouseshape(-1);
7127 }
7128#endif
7129
7130#ifdef FEAT_PRINTER
7131 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00007132 errmsg = parse_printoptions();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01007133# if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00007134 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00007135 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00007136# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007137#endif
7138
7139#ifdef FEAT_LANGMAP
7140 /* 'langmap' */
7141 else if (varp == &p_langmap)
7142 langmap_set();
7143#endif
7144
7145#ifdef FEAT_LINEBREAK
7146 /* 'breakat' */
7147 else if (varp == &p_breakat)
7148 fill_breakat_flags();
7149#endif
7150
7151#ifdef FEAT_TITLE
7152 /* 'titlestring' and 'iconstring' */
7153 else if (varp == &p_titlestring || varp == &p_iconstring)
7154 {
7155# ifdef FEAT_STL_OPT
7156 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
7157
7158 /* NULL => statusline syntax */
7159 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
7160 stl_syntax |= flagval;
7161 else
7162 stl_syntax &= ~flagval;
7163# endif
Bram Moolenaar84a93082018-06-16 22:58:15 +02007164 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007165 }
7166#endif
7167
7168#ifdef FEAT_GUI
7169 /* 'guioptions' */
7170 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007171 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007172 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007173 redraw_gui_only = TRUE;
7174 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007175#endif
7176
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00007177#if defined(FEAT_GUI_TABLINE)
7178 /* 'guitablabel' */
7179 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007180 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00007181 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007182 redraw_gui_only = TRUE;
7183 }
7184 /* 'guitabtooltip' */
7185 else if (varp == &p_gtt)
7186 {
7187 redraw_gui_only = TRUE;
7188 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00007189#endif
7190
Bram Moolenaar071d4272004-06-13 20:20:40 +00007191#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
7192 /* 'ttymouse' */
7193 else if (varp == &p_ttym)
7194 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007195 /* Switch the mouse off before changing the escape sequences used for
7196 * that. */
7197 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007198 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
7199 errmsg = e_invarg;
7200 else
7201 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00007202 if (termcap_active)
7203 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007204 }
7205#endif
7206
Bram Moolenaar071d4272004-06-13 20:20:40 +00007207 /* 'selection' */
7208 else if (varp == &p_sel)
7209 {
7210 if (*p_sel == NUL
7211 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
7212 errmsg = e_invarg;
7213 }
7214
7215 /* 'selectmode' */
7216 else if (varp == &p_slm)
7217 {
7218 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
7219 errmsg = e_invarg;
7220 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007221
7222#ifdef FEAT_BROWSE
7223 /* 'browsedir' */
7224 else if (varp == &p_bsdir)
7225 {
7226 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7227 && !mch_isdir(p_bsdir))
7228 errmsg = e_invarg;
7229 }
7230#endif
7231
Bram Moolenaar071d4272004-06-13 20:20:40 +00007232 /* 'keymodel' */
7233 else if (varp == &p_km)
7234 {
7235 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7236 errmsg = e_invarg;
7237 else
7238 {
7239 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7240 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7241 }
7242 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007243
7244 /* 'mousemodel' */
7245 else if (varp == &p_mousem)
7246 {
7247 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7248 errmsg = e_invarg;
7249#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7250 else if (*p_mousem != *oldval)
7251 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7252 * to create or delete the popup menus. */
7253 gui_motif_update_mousemodel(root_menu);
7254#endif
7255 }
7256
7257 /* 'switchbuf' */
7258 else if (varp == &p_swb)
7259 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007260 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007261 errmsg = e_invarg;
7262 }
7263
7264 /* 'debug' */
7265 else if (varp == &p_debug)
7266 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007267 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007268 errmsg = e_invarg;
7269 }
7270
7271 /* 'display' */
7272 else if (varp == &p_dy)
7273 {
7274 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7275 errmsg = e_invarg;
7276 else
7277 (void)init_chartab();
7278
7279 }
7280
Bram Moolenaar071d4272004-06-13 20:20:40 +00007281 /* 'eadirection' */
7282 else if (varp == &p_ead)
7283 {
7284 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7285 errmsg = e_invarg;
7286 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007287
7288#ifdef FEAT_CLIPBOARD
7289 /* 'clipboard' */
7290 else if (varp == &p_cb)
7291 errmsg = check_clipboard_option();
7292#endif
7293
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007294#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007295 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7296 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007297 else if (varp == &(curwin->w_s->b_p_spl)
7298 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007299 {
Bram Moolenaar862f1e12019-04-10 22:33:41 +02007300 int is_spellfile = varp == &(curwin->w_s->b_p_spf);
7301
7302 if ((is_spellfile && !valid_spellfile(*varp))
7303 || (!is_spellfile && !valid_spellang(*varp)))
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02007304 errmsg = e_invarg;
7305 else
Bram Moolenaar862f1e12019-04-10 22:33:41 +02007306 errmsg = did_set_spell_option(is_spellfile);
Bram Moolenaar217ad922005-03-20 22:37:15 +00007307 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007308 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007309 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007310 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007311 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007312 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007313 /* 'spellsuggest' */
7314 else if (varp == &p_sps)
7315 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007316 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007317 errmsg = e_invarg;
7318 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007319 /* 'mkspellmem' */
7320 else if (varp == &p_msm)
7321 {
7322 if (spell_check_msm() != OK)
7323 errmsg = e_invarg;
7324 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007325#endif
7326
Bram Moolenaar071d4272004-06-13 20:20:40 +00007327 /* When 'bufhidden' is set, check for valid value. */
7328 else if (gvarp == &p_bh)
7329 {
7330 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7331 errmsg = e_invarg;
7332 }
7333
7334 /* When 'buftype' is set, check for valid value. */
7335 else if (gvarp == &p_bt)
7336 {
7337 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7338 errmsg = e_invarg;
7339 else
7340 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007341 if (curwin->w_status_height)
7342 {
7343 curwin->w_redr_status = TRUE;
7344 redraw_later(VALID);
7345 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007346 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007347#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007348 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007349#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007350 }
7351 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007352
7353#ifdef FEAT_STL_OPT
7354 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007355 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007356 {
7357 int wid;
7358
7359 if (varp == &p_ruf) /* reset ru_wid first */
7360 ru_wid = 0;
7361 s = *varp;
7362 if (varp == &p_ruf && *s == '%')
7363 {
7364 /* set ru_wid if 'ruf' starts with "%99(" */
7365 if (*++s == '-') /* ignore a '-' */
7366 s++;
7367 wid = getdigits(&s);
7368 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7369 ru_wid = wid;
7370 else
7371 errmsg = check_stl_option(p_ruf);
7372 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007373 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007374 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007375 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007376 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007377 comp_col();
7378 }
7379#endif
7380
7381#ifdef FEAT_INS_EXPAND
7382 /* check if it is a valid value for 'complete' -- Acevedo */
7383 else if (gvarp == &p_cpt)
7384 {
7385 for (s = *varp; *s;)
7386 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007387 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007388 s++;
7389 if (!*s)
7390 break;
7391 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7392 {
7393 errmsg = illegal_char(errbuf, *s);
7394 break;
7395 }
7396 if (*++s != NUL && *s != ',' && *s != ' ')
7397 {
7398 if (s[-1] == 'k' || s[-1] == 's')
7399 {
7400 /* skip optional filename after 'k' and 's' */
7401 while (*s && *s != ',' && *s != ' ')
7402 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007403 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007404 ++s;
7405 ++s;
7406 }
7407 }
7408 else
7409 {
7410 if (errbuf != NULL)
7411 {
7412 sprintf((char *)errbuf,
7413 _("E535: Illegal character after <%c>"),
7414 *--s);
7415 errmsg = errbuf;
7416 }
7417 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007418 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00007419 break;
7420 }
7421 }
7422 }
7423 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007424
Bram Moolenaarac3150d2019-07-28 16:36:39 +02007425 // 'completeopt'
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007426 else if (varp == &p_cot)
7427 {
7428 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7429 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007430 else
7431 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007432 }
Bram Moolenaarac3150d2019-07-28 16:36:39 +02007433
7434# ifdef BACKSLASH_IN_FILENAME
7435 // 'completeslash'
7436 else if (varp == &curbuf->b_p_csl)
7437 {
7438 if (check_opt_strings(p_csl, p_csl_values, FALSE) != OK)
7439 errmsg = e_invarg;
7440 }
7441# endif
7442#endif // FEAT_INS_EXPAND
Bram Moolenaar071d4272004-06-13 20:20:40 +00007443
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007444#ifdef FEAT_SIGNS
Bram Moolenaare4b407f2019-07-04 11:59:28 +02007445 // 'signcolumn'
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007446 else if (varp == &curwin->w_p_scl)
7447 {
7448 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7449 errmsg = e_invarg;
Bram Moolenaare4b407f2019-07-04 11:59:28 +02007450 // When changing the 'signcolumn' to or from 'number', recompute the
7451 // width of the number column if 'number' or 'relativenumber' is set.
7452 if (((*oldval == 'n' && *(oldval + 1) == 'u')
7453 || (*curwin->w_p_scl == 'n' && *(curwin->w_p_scl + 1) =='u'))
7454 && (curwin->w_p_nu || curwin->w_p_rnu))
7455 curwin->w_nrwidth_line_count = 0;
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007456 }
7457#endif
7458
Bram Moolenaar071d4272004-06-13 20:20:40 +00007459
Bram Moolenaar4f974752019-02-17 17:44:42 +01007460#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007461 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007462 else if (varp == &p_toolbar)
7463 {
7464 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7465 &toolbar_flags, TRUE) != OK)
7466 errmsg = e_invarg;
7467 else
7468 {
7469 out_flush();
7470 gui_mch_show_toolbar((toolbar_flags &
7471 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7472 }
7473 }
7474#endif
7475
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007476#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007477 /* 'toolbariconsize': GTK+ 2 only */
7478 else if (varp == &p_tbis)
7479 {
7480 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7481 errmsg = e_invarg;
7482 else
7483 {
7484 out_flush();
7485 gui_mch_show_toolbar((toolbar_flags &
7486 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7487 }
7488 }
7489#endif
7490
7491 /* 'pastetoggle': translate key codes like in a mapping */
7492 else if (varp == &p_pt)
7493 {
7494 if (*p_pt)
7495 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007496 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007497 if (p != NULL)
7498 {
7499 if (new_value_alloced)
7500 free_string_option(p_pt);
7501 p_pt = p;
7502 new_value_alloced = TRUE;
7503 }
7504 }
7505 }
7506
7507 /* 'backspace' */
7508 else if (varp == &p_bs)
7509 {
7510 if (VIM_ISDIGIT(*p_bs))
7511 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007512 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007513 errmsg = e_invarg;
7514 }
7515 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7516 errmsg = e_invarg;
7517 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007518 else if (varp == &p_bo)
7519 {
7520 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7521 errmsg = e_invarg;
7522 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007523
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007524 /* 'tagcase' */
7525 else if (gvarp == &p_tc)
7526 {
7527 unsigned int *flags;
7528
7529 if (opt_flags & OPT_LOCAL)
7530 {
7531 p = curbuf->b_p_tc;
7532 flags = &curbuf->b_tc_flags;
7533 }
7534 else
7535 {
7536 p = p_tc;
7537 flags = &tc_flags;
7538 }
7539
7540 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7541 /* make the local value empty: use the global value */
7542 *flags = 0;
7543 else if (*p == NUL
7544 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7545 errmsg = e_invarg;
7546 }
7547
Bram Moolenaar071d4272004-06-13 20:20:40 +00007548 /* 'casemap' */
7549 else if (varp == &p_cmp)
7550 {
7551 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7552 errmsg = e_invarg;
7553 }
7554
7555#ifdef FEAT_DIFF
7556 /* 'diffopt' */
7557 else if (varp == &p_dip)
7558 {
7559 if (diffopt_changed() == FAIL)
7560 errmsg = e_invarg;
7561 }
7562#endif
7563
7564#ifdef FEAT_FOLDING
7565 /* 'foldmethod' */
7566 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7567 {
7568 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7569 || *curwin->w_p_fdm == NUL)
7570 errmsg = e_invarg;
7571 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007572 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007573 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007574 if (foldmethodIsDiff(curwin))
7575 newFoldLevel();
7576 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007577 }
7578# ifdef FEAT_EVAL
7579 /* 'foldexpr' */
7580 else if (varp == &curwin->w_p_fde)
7581 {
7582 if (foldmethodIsExpr(curwin))
7583 foldUpdateAll(curwin);
7584 }
7585# endif
7586 /* 'foldmarker' */
7587 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7588 {
7589 p = vim_strchr(*varp, ',');
7590 if (p == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007591 errmsg = N_("E536: comma required");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007592 else if (p == *varp || p[1] == NUL)
7593 errmsg = e_invarg;
7594 else if (foldmethodIsMarker(curwin))
7595 foldUpdateAll(curwin);
7596 }
7597 /* 'commentstring' */
7598 else if (gvarp == &p_cms)
7599 {
7600 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007601 errmsg = N_("E537: 'commentstring' must be empty or contain %s");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007602 }
7603 /* 'foldopen' */
7604 else if (varp == &p_fdo)
7605 {
7606 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7607 errmsg = e_invarg;
7608 }
7609 /* 'foldclose' */
7610 else if (varp == &p_fcl)
7611 {
7612 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7613 errmsg = e_invarg;
7614 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007615 /* 'foldignore' */
7616 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7617 {
7618 if (foldmethodIsIndent(curwin))
7619 foldUpdateAll(curwin);
7620 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007621#endif
7622
Bram Moolenaar071d4272004-06-13 20:20:40 +00007623 /* 'virtualedit' */
7624 else if (varp == &p_ve)
7625 {
7626 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7627 errmsg = e_invarg;
7628 else if (STRCMP(p_ve, oldval) != 0)
7629 {
7630 /* Recompute cursor position in case the new 've' setting
7631 * changes something. */
7632 validate_virtcol();
7633 coladvance(curwin->w_virtcol);
7634 }
7635 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007636
7637#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7638 else if (varp == &p_csqf)
7639 {
7640 if (p_csqf != NULL)
7641 {
7642 p = p_csqf;
7643 while (*p != NUL)
7644 {
7645 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7646 || p[1] == NUL
7647 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7648 || (p[2] != NUL && p[2] != ','))
7649 {
7650 errmsg = e_invarg;
7651 break;
7652 }
7653 else if (p[2] == NUL)
7654 break;
7655 else
7656 p += 3;
7657 }
7658 }
7659 }
7660#endif
7661
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007662#ifdef FEAT_CINDENT
7663 /* 'cinoptions' */
7664 else if (gvarp == &p_cino)
7665 {
7666 /* TODO: recognize errors */
7667 parse_cino(curbuf);
7668 }
7669#endif
7670
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007671#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007672 /* 'renderoptions' */
Bram Moolenaar3767c6e2017-12-05 16:57:56 +01007673 else if (varp == &p_rop)
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007674 {
7675 if (!gui_mch_set_rendering_options(p_rop))
7676 errmsg = e_invarg;
7677 }
7678#endif
7679
Bram Moolenaard0b51382016-11-04 15:23:45 +01007680 else if (gvarp == &p_ft)
7681 {
7682 if (!valid_filetype(*varp))
7683 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007684 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007685 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007686 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007687
7688 // Since we check the value, there is no need to set P_INSECURE,
7689 // even when the value comes from a modeline.
7690 *value_checked = TRUE;
7691 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007692 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007693
7694#ifdef FEAT_SYN_HL
7695 else if (gvarp == &p_syn)
7696 {
7697 if (!valid_filetype(*varp))
7698 errmsg = e_invarg;
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007699 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007700 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007701 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007702
7703 // Since we check the value, there is no need to set P_INSECURE,
7704 // even when the value comes from a modeline.
7705 *value_checked = TRUE;
7706 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007707 }
7708#endif
7709
Bram Moolenaar825680f2017-07-22 17:04:02 +02007710#ifdef FEAT_TERMINAL
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007711 // 'termwinkey'
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007712 else if (varp == &curwin->w_p_twk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007713 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007714 if (*curwin->w_p_twk != NUL
7715 && string_to_key(curwin->w_p_twk, TRUE) == 0)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007716 errmsg = e_invarg;
7717 }
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007718 // 'termwinsize'
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007719 else if (varp == &curwin->w_p_tws)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007720 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007721 if (*curwin->w_p_tws != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007722 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007723 p = skipdigits(curwin->w_p_tws);
7724 if (p == curwin->w_p_tws
Bram Moolenaar498c2562018-04-15 23:45:15 +02007725 || (*p != 'x' && *p != '*')
7726 || *skipdigits(p + 1) != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007727 errmsg = e_invarg;
7728 }
7729 }
Bram Moolenaar4f974752019-02-17 17:44:42 +01007730# if defined(MSWIN)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007731 // 'termwintype'
7732 else if (varp == &p_twt)
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007733 {
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007734 if (check_opt_strings(*varp, p_twt_values, FALSE) != OK)
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007735 errmsg = e_invarg;
7736 }
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007737# endif
Bram Moolenaar825680f2017-07-22 17:04:02 +02007738#endif
7739
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007740#ifdef FEAT_VARTABS
7741 /* 'varsofttabstop' */
7742 else if (varp == &(curbuf->b_p_vsts))
7743 {
7744 char_u *cp;
7745
7746 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7747 {
7748 if (curbuf->b_p_vsts_array)
7749 {
7750 vim_free(curbuf->b_p_vsts_array);
7751 curbuf->b_p_vsts_array = 0;
7752 }
7753 }
7754 else
7755 {
7756 for (cp = *varp; *cp; ++cp)
7757 {
7758 if (vim_isdigit(*cp))
7759 continue;
7760 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7761 continue;
7762 errmsg = e_invarg;
7763 break;
7764 }
7765 if (errmsg == NULL)
7766 {
7767 int *oldarray = curbuf->b_p_vsts_array;
7768 if (tabstop_set(*varp, &(curbuf->b_p_vsts_array)))
7769 {
7770 if (oldarray)
7771 vim_free(oldarray);
7772 }
7773 else
7774 errmsg = e_invarg;
7775 }
7776 }
7777 }
7778
7779 /* 'vartabstop' */
7780 else if (varp == &(curbuf->b_p_vts))
7781 {
7782 char_u *cp;
7783
7784 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7785 {
7786 if (curbuf->b_p_vts_array)
7787 {
7788 vim_free(curbuf->b_p_vts_array);
7789 curbuf->b_p_vts_array = NULL;
7790 }
7791 }
7792 else
7793 {
7794 for (cp = *varp; *cp; ++cp)
7795 {
7796 if (vim_isdigit(*cp))
7797 continue;
7798 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7799 continue;
7800 errmsg = e_invarg;
7801 break;
7802 }
7803 if (errmsg == NULL)
7804 {
7805 int *oldarray = curbuf->b_p_vts_array;
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007806
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007807 if (tabstop_set(*varp, &(curbuf->b_p_vts_array)))
7808 {
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007809 vim_free(oldarray);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007810#ifdef FEAT_FOLDING
7811 if (foldmethodIsIndent(curwin))
7812 foldUpdateAll(curwin);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007813#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007814 }
7815 else
7816 errmsg = e_invarg;
7817 }
7818 }
7819 }
7820#endif
7821
Bram Moolenaar79648732019-07-18 21:43:07 +02007822#ifdef FEAT_TEXT_PROP
7823 // 'previewpopup'
7824 else if (varp == &p_pvp)
7825 {
7826 if (parse_previewpopup(NULL) == FAIL)
7827 errmsg = e_invarg;
7828 }
7829#endif
7830
Bram Moolenaar071d4272004-06-13 20:20:40 +00007831 /* Options that are a list of flags. */
7832 else
7833 {
7834 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007835 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007836 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007837 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007838 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007839 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007840 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007841 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007842 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007843#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007844 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007845 p = (char_u *)COCU_ALL;
7846#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007847 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007848 {
7849#ifdef FEAT_MOUSE
7850 p = (char_u *)MOUSE_ALL;
7851#else
7852 if (*p_mouse != NUL)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007853 errmsg = N_("E538: No mouse support");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007854#endif
7855 }
7856#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007857 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007858 p = (char_u *)GO_ALL;
7859#endif
7860 if (p != NULL)
7861 {
7862 for (s = *varp; *s; ++s)
7863 if (vim_strchr(p, *s) == NULL)
7864 {
7865 errmsg = illegal_char(errbuf, *s);
7866 break;
7867 }
7868 }
7869 }
7870
7871 /*
7872 * If error detected, restore the previous value.
7873 */
7874 if (errmsg != NULL)
7875 {
7876 if (new_value_alloced)
7877 free_string_option(*varp);
7878 *varp = oldval;
7879 /*
7880 * When resetting some values, need to act on it.
7881 */
7882 if (did_chartab)
7883 (void)init_chartab();
7884 if (varp == &p_hl)
7885 (void)highlight_changed();
7886 }
7887 else
7888 {
7889#ifdef FEAT_EVAL
7890 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02007891 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007892#endif
7893 /*
7894 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007895 * Use "free_oldval", because recursiveness may change the flags under
7896 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007897 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007898 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007899 free_string_option(oldval);
7900 if (new_value_alloced)
7901 options[opt_idx].flags |= P_ALLOCED;
7902 else
7903 options[opt_idx].flags &= ~P_ALLOCED;
7904
7905 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007906 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007907 {
7908 /* global option with local value set to use global value; free
7909 * the local value and make it empty */
7910 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7911 free_string_option(*(char_u **)p);
7912 *(char_u **)p = empty_option;
7913 }
7914
7915 /* May set global value for local option. */
7916 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7917 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007918
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007919 /*
7920 * Trigger the autocommand only after setting the flags.
7921 */
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007922#ifdef FEAT_SYN_HL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007923 /* When 'syntax' is set, load the syntax of that name */
7924 if (varp == &(curbuf->b_p_syn))
7925 {
Bram Moolenaara5616b02018-06-17 19:08:30 +02007926 static int syn_recursive = 0;
7927
7928 ++syn_recursive;
7929 // Only pass TRUE for "force" when the value changed or not used
7930 // recursively, to avoid endless recurrence.
7931 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname,
7932 value_changed || syn_recursive == 1, curbuf);
7933 --syn_recursive;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007934 }
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007935#endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007936 else if (varp == &(curbuf->b_p_ft))
7937 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007938 /* 'filetype' is set, trigger the FileType autocommand.
7939 * Skip this when called from a modeline and the filetype was
Bram Moolenaara5616b02018-06-17 19:08:30 +02007940 * already set to this value. */
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007941 if (!(opt_flags & OPT_MODELINE) || value_changed)
Bram Moolenaar90492982017-06-22 14:16:31 +02007942 {
Bram Moolenaar916a8182018-11-25 02:18:29 +01007943 static int ft_recursive = 0;
7944 int secure_save = secure;
7945
7946 // Reset the secure flag, since the value of 'filetype' has
7947 // been checked to be safe.
7948 secure = 0;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007949
7950 ++ft_recursive;
Bram Moolenaar90492982017-06-22 14:16:31 +02007951 did_filetype = TRUE;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007952 // Only pass TRUE for "force" when the value changed or not
7953 // used recursively, to avoid endless recurrence.
7954 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname,
7955 value_changed || ft_recursive == 1, curbuf);
7956 --ft_recursive;
Bram Moolenaar163095f2017-07-09 15:41:53 +02007957 /* Just in case the old "curbuf" is now invalid. */
7958 if (varp != &(curbuf->b_p_ft))
7959 varp = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007960
7961 secure = secure_save;
Bram Moolenaar90492982017-06-22 14:16:31 +02007962 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007963 }
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007964#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007965 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007966 {
7967 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007968 char_u *q = curwin->w_s->b_p_spl;
7969
7970 /* Skip the first name if it is "cjk". */
7971 if (STRNCMP(q, "cjk,", 4) == 0)
7972 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007973
7974 /*
7975 * Source the spell/LANG.vim in 'runtimepath'.
7976 * They could set 'spellcapcheck' depending on the language.
7977 * Use the first name in 'spelllang' up to '_region' or
7978 * '.encoding'.
7979 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007980 for (p = q; *p != NUL; ++p)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01007981 if (!ASCII_ISALNUM(*p) && *p != '-')
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007982 break;
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007983 if (p > q)
7984 {
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02007985 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
7986 (int)(p - q), q);
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007987 source_runtime(fname, DIP_ALL);
7988 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007989 }
7990#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007991 }
7992
7993#ifdef FEAT_MOUSE
7994 if (varp == &p_mouse)
7995 {
7996# ifdef FEAT_MOUSE_TTY
7997 if (*p_mouse == NUL)
7998 mch_setmouse(FALSE); /* switch mouse off */
7999 else
8000# endif
8001 setmouse(); /* in case 'mouse' changed */
8002 }
8003#endif
8004
Bram Moolenaar913077c2012-03-28 19:59:04 +02008005 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008006 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008007 curwin->w_set_curswant = TRUE;
8008
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00008009#ifdef FEAT_GUI
8010 /* check redraw when it's not a GUI option or the GUI is active. */
8011 if (!redraw_gui_only || gui.in_use)
8012#endif
8013 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008014
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008015#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
8016 if (did_swaptcap)
8017 {
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008018 set_termname((char_u *)"win32");
8019 init_highlight(TRUE, FALSE);
8020 }
8021#endif
8022
Bram Moolenaar071d4272004-06-13 20:20:40 +00008023 return errmsg;
8024}
8025
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01008026#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02008027/*
8028 * Simple int comparison function for use with qsort()
8029 */
8030 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01008031int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02008032{
8033 return *(const int *)a - *(const int *)b;
8034}
8035
8036/*
8037 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
8038 * Returns error message, NULL if it's OK.
8039 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008040 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008041check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02008042{
8043 char_u *s;
8044 int col;
8045 int count = 0;
8046 int color_cols[256];
8047 int i;
8048 int j = 0;
8049
Bram Moolenaar50f834d2011-09-21 13:40:17 +02008050 if (wp->w_buffer == NULL)
8051 return NULL; /* buffer was closed */
8052
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008053 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02008054 {
8055 if (*s == '-' || *s == '+')
8056 {
8057 /* -N and +N: add to 'textwidth' */
8058 col = (*s == '-') ? -1 : 1;
8059 ++s;
8060 if (!VIM_ISDIGIT(*s))
8061 return e_invarg;
8062 col = col * getdigits(&s);
8063 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008064 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02008065 col += wp->w_buffer->b_p_tw;
8066 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008067 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02008068 }
8069 else if (VIM_ISDIGIT(*s))
8070 col = getdigits(&s);
8071 else
8072 return e_invarg;
8073 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008074skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02008075 if (*s == NUL)
8076 break;
8077 if (*s != ',')
8078 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008079 if (*++s == NUL)
8080 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02008081 }
8082
8083 vim_free(wp->w_p_cc_cols);
8084 if (count == 0)
8085 wp->w_p_cc_cols = NULL;
8086 else
8087 {
Bram Moolenaarc799fe22019-05-28 23:08:19 +02008088 wp->w_p_cc_cols = ALLOC_MULT(int, count + 1);
Bram Moolenaar1a384422010-07-14 19:53:30 +02008089 if (wp->w_p_cc_cols != NULL)
8090 {
8091 /* sort the columns for faster usage on screen redraw inside
8092 * win_line() */
8093 qsort(color_cols, count, sizeof(int), int_cmp);
8094
8095 for (i = 0; i < count; ++i)
8096 /* skip duplicates */
8097 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
8098 wp->w_p_cc_cols[j++] = color_cols[i];
8099 wp->w_p_cc_cols[j] = -1; /* end marker */
8100 }
8101 }
8102
8103 return NULL; /* no error */
8104}
8105#endif
8106
Bram Moolenaar071d4272004-06-13 20:20:40 +00008107/*
8108 * Handle setting 'listchars' or 'fillchars'.
8109 * Returns error message, NULL if it's OK.
8110 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008111 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008112set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008113{
8114 int round, i, len, entries;
8115 char_u *p, *s;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008116 int c1 = 0, c2 = 0, c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008117 struct charstab
8118 {
8119 int *cp;
8120 char *name;
8121 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00008122 static struct charstab filltab[] =
8123 {
8124 {&fill_stl, "stl"},
8125 {&fill_stlnc, "stlnc"},
8126 {&fill_vert, "vert"},
8127 {&fill_fold, "fold"},
8128 {&fill_diff, "diff"},
8129 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00008130 static struct charstab lcstab[] =
8131 {
8132 {&lcs_eol, "eol"},
8133 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008134 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00008135 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02008136 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00008137 {&lcs_tab2, "tab"},
8138 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02008139#ifdef FEAT_CONCEAL
8140 {&lcs_conceal, "conceal"},
8141#else
8142 {NULL, "conceal"},
8143#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008144 };
8145 struct charstab *tab;
8146
Bram Moolenaar071d4272004-06-13 20:20:40 +00008147 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008148 {
8149 tab = lcstab;
8150 entries = sizeof(lcstab) / sizeof(struct charstab);
8151 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008152 else
8153 {
8154 tab = filltab;
8155 entries = sizeof(filltab) / sizeof(struct charstab);
8156 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008157
8158 /* first round: check for valid value, second round: assign values */
8159 for (round = 0; round <= 1; ++round)
8160 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008161 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008162 {
8163 /* After checking that the value is valid: set defaults: space for
8164 * 'fillchars', NUL for 'listchars' */
8165 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008166 if (tab[i].cp != NULL)
8167 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar83a52172019-01-16 22:41:54 +01008168
Bram Moolenaar071d4272004-06-13 20:20:40 +00008169 if (varp == &p_lcs)
Bram Moolenaar83a52172019-01-16 22:41:54 +01008170 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008171 lcs_tab1 = NUL;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008172 lcs_tab3 = NUL;
8173 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008174 else
8175 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008176 }
8177 p = *varp;
8178 while (*p)
8179 {
8180 for (i = 0; i < entries; ++i)
8181 {
8182 len = (int)STRLEN(tab[i].name);
8183 if (STRNCMP(p, tab[i].name, len) == 0
8184 && p[len] == ':'
8185 && p[len + 1] != NUL)
8186 {
Bram Moolenaar2c519cf2019-03-21 21:45:34 +01008187 c2 = c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008188 s = p + len + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008189 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00008190 if (mb_char2cells(c1) > 1)
8191 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008192 if (tab[i].cp == &lcs_tab2)
8193 {
8194 if (*s == NUL)
8195 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008196 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00008197 if (mb_char2cells(c2) > 1)
8198 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008199 if (!(*s == ',' || *s == NUL))
8200 {
Bram Moolenaar83a52172019-01-16 22:41:54 +01008201 c3 = mb_ptr2char_adv(&s);
8202 if (mb_char2cells(c3) > 1)
8203 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008204 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008205 }
Bram Moolenaar83a52172019-01-16 22:41:54 +01008206
Bram Moolenaar071d4272004-06-13 20:20:40 +00008207 if (*s == ',' || *s == NUL)
8208 {
8209 if (round)
8210 {
8211 if (tab[i].cp == &lcs_tab2)
8212 {
8213 lcs_tab1 = c1;
8214 lcs_tab2 = c2;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008215 lcs_tab3 = c3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008216 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008217 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008218 *(tab[i].cp) = c1;
8219
8220 }
8221 p = s;
8222 break;
8223 }
8224 }
8225 }
8226
8227 if (i == entries)
8228 return e_invarg;
8229 if (*p == ',')
8230 ++p;
8231 }
8232 }
8233
8234 return NULL; /* no error */
8235}
8236
8237#ifdef FEAT_STL_OPT
8238/*
8239 * Check validity of options with the 'statusline' format.
8240 * Return error message or NULL.
8241 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008242 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008243check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008244{
8245 int itemcnt = 0;
8246 int groupdepth = 0;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008247 static char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00008248
8249 while (*s && itemcnt < STL_MAX_ITEM)
8250 {
8251 /* Check for valid keys after % sequences */
8252 while (*s && *s != '%')
8253 s++;
8254 if (!*s)
8255 break;
8256 s++;
8257 if (*s != '%' && *s != ')')
8258 ++itemcnt;
8259 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
8260 {
8261 s++;
8262 continue;
8263 }
8264 if (*s == ')')
8265 {
8266 s++;
8267 if (--groupdepth < 0)
8268 break;
8269 continue;
8270 }
8271 if (*s == '-')
8272 s++;
8273 while (VIM_ISDIGIT(*s))
8274 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00008275 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008276 continue;
8277 if (*s == '.')
8278 {
8279 s++;
8280 while (*s && VIM_ISDIGIT(*s))
8281 s++;
8282 }
8283 if (*s == '(')
8284 {
8285 groupdepth++;
8286 continue;
8287 }
8288 if (vim_strchr(STL_ALL, *s) == NULL)
8289 {
8290 return illegal_char(errbuf, *s);
8291 }
8292 if (*s == '{')
8293 {
8294 s++;
8295 while (*s != '}' && *s)
8296 s++;
8297 if (*s != '}')
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008298 return N_("E540: Unclosed expression sequence");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008299 }
8300 }
8301 if (itemcnt >= STL_MAX_ITEM)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008302 return N_("E541: too many items");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008303 if (groupdepth != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008304 return N_("E542: unbalanced groups");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008305 return NULL;
8306}
8307#endif
8308
8309#ifdef FEAT_CLIPBOARD
8310/*
8311 * Extract the items in the 'clipboard' option and set global values.
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008312 * Return an error message or NULL for success.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008313 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008314 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008315check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008316{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008317 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008318 int new_autoselect_star = FALSE;
8319 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008320 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008321 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008322 regprog_T *new_exclude_prog = NULL;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008323 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008324 char_u *p;
8325
8326 for (p = p_cb; *p != NUL; )
8327 {
8328 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
8329 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008330 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008331 p += 7;
8332 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02008333 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008334 && (p[11] == ',' || p[11] == NUL))
8335 {
8336 new_unnamed |= CLIP_UNNAMED_PLUS;
8337 p += 11;
8338 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008339 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008340 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008341 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02008342 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008343 p += 10;
8344 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02008345 else if (STRNCMP(p, "autoselectplus", 14) == 0
8346 && (p[14] == ',' || p[14] == NUL))
8347 {
8348 new_autoselect_plus = TRUE;
8349 p += 14;
8350 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008351 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008352 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008353 {
8354 new_autoselectml = TRUE;
8355 p += 12;
8356 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008357 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
8358 {
8359 new_html = TRUE;
8360 p += 4;
8361 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008362 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
8363 {
8364 p += 8;
8365 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
8366 if (new_exclude_prog == NULL)
8367 errmsg = e_invarg;
8368 break;
8369 }
8370 else
8371 {
8372 errmsg = e_invarg;
8373 break;
8374 }
8375 if (*p == ',')
8376 ++p;
8377 }
8378 if (errmsg == NULL)
8379 {
8380 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008381 clip_autoselect_star = new_autoselect_star;
8382 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008383 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008384 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008385 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008386 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008387#ifdef FEAT_GUI_GTK
8388 if (gui.in_use)
8389 {
8390 gui_gtk_set_selection_targets();
8391 gui_gtk_set_dnd_targets();
8392 }
8393#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008394 }
8395 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008396 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008397
8398 return errmsg;
8399}
8400#endif
8401
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008402#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008403/*
8404 * Handle side effects of setting 'spell'.
8405 * Return an error message or NULL for success.
8406 */
8407 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008408did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008409{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008410 char *errmsg = NULL;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008411 win_T *wp;
8412 int l;
8413
8414 if (is_spellfile)
8415 {
8416 l = (int)STRLEN(curwin->w_s->b_p_spf);
8417 if (l > 0 && (l < 4
8418 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8419 errmsg = e_invarg;
8420 }
8421
8422 if (errmsg == NULL)
8423 {
8424 FOR_ALL_WINDOWS(wp)
8425 if (wp->w_buffer == curbuf && wp->w_p_spell)
8426 {
8427 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008428 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008429 }
8430 }
8431 return errmsg;
8432}
8433
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008434/*
8435 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8436 * Return error message when failed, NULL when OK.
8437 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008438 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008439compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008440{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008441 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008442 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008443
Bram Moolenaar860cae12010-06-05 23:22:07 +02008444 if (*synblock->b_p_spc == NUL)
8445 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008446 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008447 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008448 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008449 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008450 if (re != NULL)
8451 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008452 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008453 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008454 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008455 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008456 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008457 return e_invarg;
8458 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008459 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008460 }
8461
Bram Moolenaar473de612013-06-08 18:19:48 +02008462 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008463 return NULL;
8464}
8465#endif
8466
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008467#if defined(FEAT_EVAL) || defined(PROTO)
8468/*
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008469 * Set the script_ctx for an option, taking care of setting the buffer- or
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008470 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008471 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008472 static void
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008473set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008474{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008475 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8476 int indir = (int)options[opt_idx].indir;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008477 sctx_T new_script_ctx = script_ctx;
8478
8479 new_script_ctx.sc_lnum += sourcing_lnum;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008480
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008481 /* Remember where the option was set. For local options need to do that
8482 * in the buffer or window structure. */
8483 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008484 options[opt_idx].script_ctx = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008485 if (both || (opt_flags & OPT_LOCAL))
8486 {
8487 if (indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008488 curbuf->b_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008489 else if (indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008490 curwin->w_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008491 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008492}
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02008493
8494/*
8495 * Set the script_ctx for a termcap option.
8496 * "name" must be the two character code, e.g. "RV".
8497 * When "name" is NULL use "opt_idx".
8498 */
8499 void
8500set_term_option_sctx_idx(char *name, int opt_idx)
8501{
8502 char_u buf[5];
8503 int idx;
8504
8505 if (name == NULL)
8506 idx = opt_idx;
8507 else
8508 {
8509 buf[0] = 't';
8510 buf[1] = '_';
8511 buf[2] = name[0];
8512 buf[3] = name[1];
8513 buf[4] = 0;
8514 idx = findoption(buf);
8515 }
8516 if (idx >= 0)
8517 set_option_sctx_idx(idx, OPT_GLOBAL, current_sctx);
8518}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008519#endif
8520
Bram Moolenaar071d4272004-06-13 20:20:40 +00008521/*
8522 * Set the value of a boolean option, and take care of side effects.
8523 * Returns NULL for success, or an error message for an error.
8524 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008525 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008526set_bool_option(
8527 int opt_idx, /* index in options[] table */
8528 char_u *varp, /* pointer to the option variable */
8529 int value, /* new value */
8530 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008531{
8532 int old_value = *(int *)varp;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008533#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02008534 int old_global_value = 0;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008535#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008536
Bram Moolenaar071d4272004-06-13 20:20:40 +00008537 /* Disallow changing some options from secure mode */
8538 if ((secure
8539#ifdef HAVE_SANDBOX
8540 || sandbox != 0
8541#endif
8542 ) && (options[opt_idx].flags & P_SECURE))
8543 return e_secure;
8544
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008545#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02008546 // Save the global value before changing anything. This is needed as for
8547 // a global-only option setting the "local value" in fact sets the global
8548 // value (since there is only one value).
8549 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8550 old_global_value = *(int *)get_varp_scope(&(options[opt_idx]),
8551 OPT_GLOBAL);
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008552#endif
Bram Moolenaard7c96872019-06-15 17:12:48 +02008553
Bram Moolenaar071d4272004-06-13 20:20:40 +00008554 *(int *)varp = value; /* set the new value */
8555#ifdef FEAT_EVAL
8556 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008557 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008558#endif
8559
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008560#ifdef FEAT_GUI
8561 need_mouse_correct = TRUE;
8562#endif
8563
Bram Moolenaar071d4272004-06-13 20:20:40 +00008564 /* May set global value for local option. */
8565 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8566 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8567
8568 /*
8569 * Handle side effects of changing a bool option.
8570 */
8571
8572 /* 'compatible' */
8573 if ((int *)varp == &p_cp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008574 compatible_set();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008575
Bram Moolenaar920694c2016-08-21 17:45:02 +02008576#ifdef FEAT_LANGMAP
8577 if ((int *)varp == &p_lrm)
8578 /* 'langremap' -> !'langnoremap' */
8579 p_lnr = !p_lrm;
8580 else if ((int *)varp == &p_lnr)
8581 /* 'langnoremap' -> !'langremap' */
8582 p_lrm = !p_lnr;
8583#endif
8584
Bram Moolenaar8c63e0e2018-09-25 22:17:54 +02008585#ifdef FEAT_SYN_HL
8586 else if ((int *)varp == &curwin->w_p_cul && !value && old_value)
8587 reset_cursorline();
8588#endif
8589
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008590#ifdef FEAT_PERSISTENT_UNDO
8591 /* 'undofile' */
8592 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8593 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008594 /* Only take action when the option was set. When reset we do not
8595 * delete the undo file, the option may be set again without making
8596 * any changes in between. */
8597 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008598 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008599 char_u hash[UNDO_HASH_SIZE];
8600 buf_T *save_curbuf = curbuf;
8601
Bram Moolenaar29323592016-07-24 22:04:11 +02008602 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008603 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008604 /* When 'undofile' is set globally: for every buffer, otherwise
8605 * only for the current buffer: Try to read in the undofile,
8606 * if one exists, the buffer wasn't changed and the buffer was
8607 * loaded */
8608 if ((curbuf == save_curbuf
8609 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8610 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8611 {
8612 u_compute_hash(hash);
8613 u_read_undo(NULL, hash, curbuf->b_fname);
8614 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008615 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008616 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008617 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008618 }
8619#endif
8620
Bram Moolenaar071d4272004-06-13 20:20:40 +00008621 else if ((int *)varp == &curbuf->b_p_ro)
8622 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008623 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008624 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8625 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008626
8627 /* when 'readonly' is set may give W10 again */
8628 if (curbuf->b_p_ro)
8629 curbuf->b_did_warn = FALSE;
8630
Bram Moolenaar071d4272004-06-13 20:20:40 +00008631#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008632 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008633#endif
8634 }
8635
Bram Moolenaar9c449722010-07-20 18:44:27 +02008636#ifdef FEAT_GUI
8637 else if ((int *)varp == &p_mh)
8638 {
8639 if (!p_mh)
8640 gui_mch_mousehide(FALSE);
8641 }
8642#endif
8643
Bram Moolenaara539df02010-08-01 14:35:05 +02008644 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008645 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008646 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008647# ifdef FEAT_TERMINAL
8648 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaard7db27b2018-03-07 23:02:33 +01008649 if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf)
8650 && curbuf->b_term != NULL && !term_is_finished(curbuf))))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008651 {
8652 curbuf->b_p_ma = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008653 return N_("E946: Cannot make a terminal with running job modifiable");
Bram Moolenaar423802d2017-07-30 16:52:24 +02008654 }
8655# endif
8656# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008657 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008658# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008659 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008660#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008661 /* when 'endofline' is changed, redraw the window title */
8662 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008663 {
8664 redraw_titles();
8665 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008666 /* when 'fixeol' is changed, redraw the window title */
8667 else if ((int *)varp == &curbuf->b_p_fixeol)
8668 {
8669 redraw_titles();
8670 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008671 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008672 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008673 {
8674 redraw_titles();
8675 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008676#endif
8677
8678 /* when 'bin' is set also set some other options */
8679 else if ((int *)varp == &curbuf->b_p_bin)
8680 {
8681 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8682#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008683 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008684#endif
8685 }
8686
Bram Moolenaar071d4272004-06-13 20:20:40 +00008687 /* when 'buflisted' changes, trigger autocommands */
8688 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8689 {
8690 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8691 NULL, NULL, TRUE, curbuf);
8692 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008693
8694 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8695 else if ((int *)varp == &curbuf->b_p_swf)
8696 {
8697 if (curbuf->b_p_swf && p_uc)
8698 ml_open_file(curbuf); /* create the swap file */
8699 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008700 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8701 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008702 mf_close_file(curbuf, TRUE); /* remove the swap file */
8703 }
8704
8705 /* when 'terse' is set change 'shortmess' */
8706 else if ((int *)varp == &p_terse)
8707 {
8708 char_u *p;
8709
8710 p = vim_strchr(p_shm, SHM_SEARCH);
8711
8712 /* insert 's' in p_shm */
8713 if (p_terse && p == NULL)
8714 {
8715 STRCPY(IObuff, p_shm);
8716 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008717 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008718 }
8719 /* remove 's' from p_shm */
8720 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008721 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008722 }
8723
8724 /* when 'paste' is set or reset also change other options */
8725 else if ((int *)varp == &p_paste)
8726 {
8727 paste_option_changed();
8728 }
8729
8730 /* when 'insertmode' is set from an autocommand need to do work here */
8731 else if ((int *)varp == &p_im)
8732 {
8733 if (p_im)
8734 {
8735 if ((State & INSERT) == 0)
8736 need_start_insertmode = TRUE;
8737 stop_insert_mode = FALSE;
8738 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008739 /* only reset if it was set previously */
8740 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008741 {
8742 need_start_insertmode = FALSE;
8743 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008744 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008745 clear_cmdline = TRUE; /* remove "(insert)" */
8746 restart_edit = 0;
8747 }
8748 }
8749
8750 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8751 else if ((int *)varp == &p_ic && p_hls)
8752 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008753 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008754 }
8755
8756#ifdef FEAT_SEARCH_EXTRA
8757 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8758 else if ((int *)varp == &p_hls)
8759 {
Bram Moolenaar451fc7b2018-04-27 22:53:07 +02008760 set_no_hlsearch(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008761 }
8762#endif
8763
Bram Moolenaar071d4272004-06-13 20:20:40 +00008764 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8765 * at the end of normal_cmd() */
8766 else if ((int *)varp == &curwin->w_p_scb)
8767 {
8768 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008769 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008770 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008771 curwin->w_scbind_pos = curwin->w_topline;
8772 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008773 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008774
Bram Moolenaar4033c552017-09-16 20:54:51 +02008775#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008776 /* There can be only one window with 'previewwindow' set. */
8777 else if ((int *)varp == &curwin->w_p_pvw)
8778 {
8779 if (curwin->w_p_pvw)
8780 {
8781 win_T *win;
8782
Bram Moolenaar29323592016-07-24 22:04:11 +02008783 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008784 if (win->w_p_pvw && win != curwin)
8785 {
8786 curwin->w_p_pvw = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008787 return N_("E590: A preview window already exists");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008788 }
8789 }
8790 }
8791#endif
8792
8793 /* when 'textmode' is set or reset also change 'fileformat' */
8794 else if ((int *)varp == &curbuf->b_p_tx)
8795 {
8796 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8797 }
8798
8799 /* when 'textauto' is set or reset also change 'fileformats' */
8800 else if ((int *)varp == &p_ta)
Bram Moolenaarabab0b02019-03-30 18:47:01 +01008801 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008802 set_string_option_direct((char_u *)"ffs", -1,
8803 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008804 OPT_FREE | opt_flags, 0);
Bram Moolenaarabab0b02019-03-30 18:47:01 +01008805 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008806
8807 /*
8808 * When 'lisp' option changes include/exclude '-' in
8809 * keyword characters.
8810 */
8811#ifdef FEAT_LISP
8812 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8813 {
8814 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8815 }
8816#endif
8817
8818#ifdef FEAT_TITLE
8819 /* when 'title' changed, may need to change the title; same for 'icon' */
Bram Moolenaar84a93082018-06-16 22:58:15 +02008820 else if ((int *)varp == &p_title || (int *)varp == &p_icon)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008821 {
Bram Moolenaar84a93082018-06-16 22:58:15 +02008822 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008823 }
8824#endif
8825
8826 else if ((int *)varp == &curbuf->b_changed)
8827 {
8828 if (!value)
8829 save_file_ff(curbuf); /* Buffer is unchanged */
8830#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008831 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008832#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008833 modified_was_set = value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008834 }
8835
8836#ifdef BACKSLASH_IN_FILENAME
8837 else if ((int *)varp == &p_ssl)
8838 {
8839 if (p_ssl)
8840 {
8841 psepc = '/';
8842 psepcN = '\\';
8843 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008844 }
8845 else
8846 {
8847 psepc = '\\';
8848 psepcN = '/';
8849 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008850 }
8851
8852 /* need to adjust the file name arguments and buffer names. */
8853 buflist_slash_adjust();
8854 alist_slash_adjust();
8855# ifdef FEAT_EVAL
8856 scriptnames_slash_adjust();
8857# endif
8858 }
8859#endif
8860
8861 /* If 'wrap' is set, set w_leftcol to zero. */
8862 else if ((int *)varp == &curwin->w_p_wrap)
8863 {
8864 if (curwin->w_p_wrap)
8865 curwin->w_leftcol = 0;
8866 }
8867
Bram Moolenaar071d4272004-06-13 20:20:40 +00008868 else if ((int *)varp == &p_ea)
8869 {
8870 if (p_ea && !old_value)
8871 win_equal(curwin, FALSE, 0);
8872 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008873
8874 else if ((int *)varp == &p_wiv)
8875 {
8876 /*
8877 * When 'weirdinvert' changed, set/reset 't_xs'.
8878 * Then set 'weirdinvert' according to value of 't_xs'.
8879 */
8880 if (p_wiv && !old_value)
8881 T_XS = (char_u *)"y";
8882 else if (!p_wiv && old_value)
8883 T_XS = empty_option;
8884 p_wiv = (*T_XS != NUL);
8885 }
8886
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008887#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008888 else if ((int *)varp == &p_beval)
8889 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008890 if (!balloonEvalForTerm)
8891 {
8892 if (p_beval && !old_value)
8893 gui_mch_enable_beval_area(balloonEval);
8894 else if (!p_beval && old_value)
8895 gui_mch_disable_beval_area(balloonEval);
8896 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008897 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008898#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008899#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008900 else if ((int *)varp == &p_bevalterm)
8901 {
8902 mch_bevalterm_changed();
8903 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008904#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008905
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008906#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008907 else if ((int *)varp == &p_acd)
8908 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008909 /* Change directories when the 'acd' option is set now. */
Bram Moolenaar6f470022018-04-10 18:47:20 +02008910 DO_AUTOCHDIR;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008911 }
8912#endif
8913
8914#ifdef FEAT_DIFF
8915 /* 'diff' */
8916 else if ((int *)varp == &curwin->w_p_diff)
8917 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008918 /* May add or remove the buffer from the list of diff buffers. */
8919 diff_buf_adjust(curwin);
8920# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008921 if (foldmethodIsDiff(curwin))
8922 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008923# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008924 }
8925#endif
8926
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008927#ifdef HAVE_INPUT_METHOD
Bram Moolenaar071d4272004-06-13 20:20:40 +00008928 /* 'imdisable' */
8929 else if ((int *)varp == &p_imdisable)
8930 {
8931 /* Only de-activate it here, it will be enabled when changing mode. */
8932 if (p_imdisable)
8933 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008934 else if (State & INSERT)
8935 /* When the option is set from an autocommand, it may need to take
8936 * effect right away. */
8937 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008938 }
8939#endif
8940
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008941#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008942 /* 'spell' */
8943 else if ((int *)varp == &curwin->w_p_spell)
8944 {
8945 if (curwin->w_p_spell)
8946 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008947 char *errmsg = did_set_spelllang(curwin);
8948
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008949 if (errmsg != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008950 emsg(_(errmsg));
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008951 }
8952 }
8953#endif
8954
Bram Moolenaar071d4272004-06-13 20:20:40 +00008955#ifdef FEAT_ARABIC
8956 if ((int *)varp == &curwin->w_p_arab)
8957 {
8958 if (curwin->w_p_arab)
8959 {
8960 /*
8961 * 'arabic' is set, handle various sub-settings.
8962 */
8963 if (!p_tbidi)
8964 {
8965 /* set rightleft mode */
8966 if (!curwin->w_p_rl)
8967 {
8968 curwin->w_p_rl = TRUE;
8969 changed_window_setting();
8970 }
8971
8972 /* Enable Arabic shaping (major part of what Arabic requires) */
8973 if (!p_arshape)
8974 {
8975 p_arshape = TRUE;
8976 redraw_later_clear();
8977 }
8978 }
8979
8980 /* Arabic requires a utf-8 encoding, inform the user if its not
8981 * set. */
8982 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008983 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008984 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8985
Bram Moolenaar8820b482017-03-16 17:23:31 +01008986 msg_source(HL_ATTR(HLF_W));
Bram Moolenaar32526b32019-01-19 17:43:09 +01008987 msg_attr(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008988#ifdef FEAT_EVAL
8989 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8990#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008991 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008992
Bram Moolenaar071d4272004-06-13 20:20:40 +00008993 /* set 'delcombine' */
8994 p_deco = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008995
8996# ifdef FEAT_KEYMAP
8997 /* Force-set the necessary keymap for arabic */
8998 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8999 OPT_LOCAL);
9000# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009001 }
9002 else
9003 {
9004 /*
9005 * 'arabic' is reset, handle various sub-settings.
9006 */
9007 if (!p_tbidi)
9008 {
9009 /* reset rightleft mode */
9010 if (curwin->w_p_rl)
9011 {
9012 curwin->w_p_rl = FALSE;
9013 changed_window_setting();
9014 }
9015
9016 /* 'arabicshape' isn't reset, it is a global option and
9017 * another window may still need it "on". */
9018 }
9019
9020 /* 'delcombine' isn't reset, it is a global option and another
9021 * window may still want it "on". */
9022
9023# ifdef FEAT_KEYMAP
9024 /* Revert to the default keymap */
9025 curbuf->b_p_iminsert = B_IMODE_NONE;
9026 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
9027# endif
9028 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00009029 }
9030
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00009031#endif
9032
Bram Moolenaar61be73b2016-04-29 22:59:22 +02009033#ifdef FEAT_TERMGUICOLORS
9034 /* 'termguicolors' */
9035 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02009036 {
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009037# ifdef FEAT_VTP
9038 /* Do not turn on 'tgc' when 24-bit colors are not supported. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02009039 if (
9040# ifdef VIMDLL
9041 !gui.in_use && !gui.starting &&
9042# endif
9043 !has_vtp_working())
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009044 {
9045 p_tgc = 0;
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01009046 return N_("E954: 24-bit colors are not supported on this environment");
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009047 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02009048 if (is_term_win32())
9049 swap_tcap();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009050# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02009051# ifdef FEAT_GUI
9052 if (!gui.in_use && !gui.starting)
9053# endif
9054 highlight_gui_started();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009055# ifdef FEAT_VTP
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009056 /* reset t_Co */
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02009057 if (is_term_win32())
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02009058 {
9059 control_console_color_rgb();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009060 set_termname(T_NAME);
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02009061 init_highlight(TRUE, FALSE);
9062 }
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009063# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02009064 }
9065#endif
9066
Bram Moolenaar071d4272004-06-13 20:20:40 +00009067 /*
9068 * End of handling side effects for bool options.
9069 */
9070
Bram Moolenaar53744302015-07-17 17:38:22 +02009071 /* after handling side effects, call autocommand */
9072
Bram Moolenaar071d4272004-06-13 20:20:40 +00009073 options[opt_idx].flags |= P_WAS_SET;
9074
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009075#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009076 // Don't do this while starting up or recursively.
9077 if (!starting && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009078 {
Bram Moolenaard7c96872019-06-15 17:12:48 +02009079 char_u buf_old[2], buf_old_global[2], buf_new[2], buf_type[7];
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009080
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009081 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009082 vim_snprintf((char *)buf_old_global, 2, "%d",
9083 old_global_value ? TRUE: FALSE);
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009084 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009085 vim_snprintf((char *)buf_type, 7, "%s",
9086 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009087 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9088 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9089 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009090 if (opt_flags & OPT_LOCAL)
9091 {
9092 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
9093 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9094 }
9095 if (opt_flags & OPT_GLOBAL)
9096 {
9097 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
9098 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old, -1);
9099 }
9100 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9101 {
9102 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
9103 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9104 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old_global, -1);
9105 }
9106 if (opt_flags & OPT_MODELINE)
9107 {
9108 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
9109 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9110 }
9111 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname,
9112 NULL, FALSE, NULL);
Bram Moolenaar53744302015-07-17 17:38:22 +02009113 reset_v_option_vars();
9114 }
9115#endif
9116
Bram Moolenaar071d4272004-06-13 20:20:40 +00009117 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009118 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009119 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009120 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009121 check_redraw(options[opt_idx].flags);
9122
9123 return NULL;
9124}
9125
9126/*
9127 * Set the value of a number option, and take care of side effects.
9128 * Returns NULL for success, or an error message for an error.
9129 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009130 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009131set_num_option(
9132 int opt_idx, /* index in options[] table */
9133 char_u *varp, /* pointer to the option variable */
9134 long value, /* new value */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009135 char *errbuf, /* buffer for error messages */
Bram Moolenaar9b578142016-01-30 19:39:49 +01009136 size_t errbuflen, /* length of "errbuf" */
9137 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00009138 OPT_MODELINE */
9139{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009140 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009141 long old_value = *(long *)varp;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02009142#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02009143 long old_global_value = 0; // only used when setting a local and
9144 // global option
Bram Moolenaar983f2f12019-06-16 16:41:41 +02009145#endif
Bram Moolenaard7c96872019-06-15 17:12:48 +02009146 long old_Rows = Rows; // remember old Rows
9147 long old_Columns = Columns; // remember old Columns
Bram Moolenaar071d4272004-06-13 20:20:40 +00009148 long *pp = (long *)varp;
9149
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009150 /* Disallow changing some options from secure mode. */
9151 if ((secure
9152#ifdef HAVE_SANDBOX
9153 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00009154#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009155 ) && (options[opt_idx].flags & P_SECURE))
9156 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009157
Bram Moolenaar983f2f12019-06-16 16:41:41 +02009158#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02009159 // Save the global value before changing anything. This is needed as for
9160 // a global-only option setting the "local value" infact sets the global
9161 // value (since there is only one value).
9162 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
Bram Moolenaar983f2f12019-06-16 16:41:41 +02009163 old_global_value = *(long *)get_varp_scope(&(options[opt_idx]),
9164 OPT_GLOBAL);
9165#endif
Bram Moolenaard7c96872019-06-15 17:12:48 +02009166
Bram Moolenaar071d4272004-06-13 20:20:40 +00009167 *pp = value;
9168#ifdef FEAT_EVAL
9169 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02009170 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009171#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009172#ifdef FEAT_GUI
9173 need_mouse_correct = TRUE;
9174#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009175
Bram Moolenaar14f24742012-08-08 18:01:05 +02009176 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009177 {
9178 errmsg = e_positive;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02009179#ifdef FEAT_VARTABS
9180 // Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use.
9181 curbuf->b_p_sw = tabstop_count(curbuf->b_p_vts_array) > 0
9182 ? tabstop_first(curbuf->b_p_vts_array)
9183 : curbuf->b_p_ts;
9184#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00009185 curbuf->b_p_sw = curbuf->b_p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02009186#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009187 }
9188
9189 /*
9190 * Number options that need some action when changed
9191 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009192 if (pp == &p_wh || pp == &p_hh)
9193 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009194 // 'winheight' and 'helpheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009195 if (p_wh < 1)
9196 {
9197 errmsg = e_positive;
9198 p_wh = 1;
9199 }
9200 if (p_wmh > p_wh)
9201 {
9202 errmsg = e_winheight;
9203 p_wh = p_wmh;
9204 }
9205 if (p_hh < 0)
9206 {
9207 errmsg = e_positive;
9208 p_hh = 0;
9209 }
9210
9211 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01009212 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009213 {
9214 if (pp == &p_wh && curwin->w_height < p_wh)
9215 win_setheight((int)p_wh);
9216 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
9217 win_setheight((int)p_hh);
9218 }
9219 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009220 else if (pp == &p_wmh)
9221 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009222 // 'winminheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009223 if (p_wmh < 0)
9224 {
9225 errmsg = e_positive;
9226 p_wmh = 0;
9227 }
9228 if (p_wmh > p_wh)
9229 {
9230 errmsg = e_winheight;
9231 p_wmh = p_wh;
9232 }
9233 win_setminheight();
9234 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009235 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009236 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009237 // 'winwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009238 if (p_wiw < 1)
9239 {
9240 errmsg = e_positive;
9241 p_wiw = 1;
9242 }
9243 if (p_wmw > p_wiw)
9244 {
9245 errmsg = e_winwidth;
9246 p_wiw = p_wmw;
9247 }
9248
9249 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01009250 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009251 win_setwidth((int)p_wiw);
9252 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009253 else if (pp == &p_wmw)
9254 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009255 // 'winminwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009256 if (p_wmw < 0)
9257 {
9258 errmsg = e_positive;
9259 p_wmw = 0;
9260 }
9261 if (p_wmw > p_wiw)
9262 {
9263 errmsg = e_winwidth;
9264 p_wmw = p_wiw;
9265 }
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009266 win_setminwidth();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009267 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009268
Bram Moolenaar071d4272004-06-13 20:20:40 +00009269 /* (re)set last window status line */
9270 else if (pp == &p_ls)
9271 {
9272 last_status(FALSE);
9273 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009274
9275 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00009276 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009277 {
9278 shell_new_rows(); /* recompute window positions and heights */
9279 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009280
9281#ifdef FEAT_GUI
9282 else if (pp == &p_linespace)
9283 {
Bram Moolenaar02743632005-07-25 20:42:36 +00009284 /* Recompute gui.char_height and resize the Vim window to keep the
9285 * same number of lines. */
9286 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00009287 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009288 }
9289#endif
9290
9291#ifdef FEAT_FOLDING
9292 /* 'foldlevel' */
9293 else if (pp == &curwin->w_p_fdl)
9294 {
9295 if (curwin->w_p_fdl < 0)
9296 curwin->w_p_fdl = 0;
9297 newFoldLevel();
9298 }
9299
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00009300 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009301 else if (pp == &curwin->w_p_fml)
9302 {
9303 foldUpdateAll(curwin);
9304 }
9305
9306 /* 'foldnestmax' */
9307 else if (pp == &curwin->w_p_fdn)
9308 {
9309 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
9310 foldUpdateAll(curwin);
9311 }
9312
9313 /* 'foldcolumn' */
9314 else if (pp == &curwin->w_p_fdc)
9315 {
9316 if (curwin->w_p_fdc < 0)
9317 {
9318 errmsg = e_positive;
9319 curwin->w_p_fdc = 0;
9320 }
9321 else if (curwin->w_p_fdc > 12)
9322 {
9323 errmsg = e_invarg;
9324 curwin->w_p_fdc = 12;
9325 }
9326 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009327#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009328
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009329#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009330 /* 'shiftwidth' or 'tabstop' */
9331 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
9332 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009333# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00009334 if (foldmethodIsIndent(curwin))
9335 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009336# endif
9337# ifdef FEAT_CINDENT
9338 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
9339 * parse 'cinoptions'. */
9340 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
9341 parse_cino(curbuf);
9342# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009343 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009344#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009345
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009346 /* 'maxcombine' */
9347 else if (pp == &p_mco)
9348 {
9349 if (p_mco > MAX_MCO)
9350 p_mco = MAX_MCO;
9351 else if (p_mco < 0)
9352 p_mco = 0;
9353 screenclear(); /* will re-allocate the screen */
9354 }
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009355
Bram Moolenaar071d4272004-06-13 20:20:40 +00009356 else if (pp == &curbuf->b_p_iminsert)
9357 {
9358 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
9359 {
9360 errmsg = e_invarg;
9361 curbuf->b_p_iminsert = B_IMODE_NONE;
9362 }
9363 p_iminsert = curbuf->b_p_iminsert;
9364 if (termcap_active) /* don't do this in the alternate screen */
9365 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02009366#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009367 /* Show/unshow value of 'keymap' in status lines. */
9368 status_redraw_curbuf();
9369#endif
9370 }
9371
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02009372#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
9373 /* 'imstyle' */
9374 else if (pp == &p_imst)
9375 {
9376 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
9377 errmsg = e_invarg;
9378 }
9379#endif
9380
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009381 else if (pp == &p_window)
9382 {
9383 if (p_window < 1)
9384 p_window = 1;
9385 else if (p_window >= Rows)
9386 p_window = Rows - 1;
9387 }
9388
Bram Moolenaar071d4272004-06-13 20:20:40 +00009389 else if (pp == &curbuf->b_p_imsearch)
9390 {
9391 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
9392 {
9393 errmsg = e_invarg;
9394 curbuf->b_p_imsearch = B_IMODE_NONE;
9395 }
9396 p_imsearch = curbuf->b_p_imsearch;
9397 }
9398
9399#ifdef FEAT_TITLE
9400 /* if 'titlelen' has changed, redraw the title */
9401 else if (pp == &p_titlelen)
9402 {
9403 if (p_titlelen < 0)
9404 {
9405 errmsg = e_positive;
9406 p_titlelen = 85;
9407 }
9408 if (starting != NO_SCREEN && old_value != p_titlelen)
9409 need_maketitle = TRUE;
9410 }
9411#endif
9412
9413 /* if p_ch changed value, change the command line height */
9414 else if (pp == &p_ch)
9415 {
9416 if (p_ch < 1)
9417 {
9418 errmsg = e_positive;
9419 p_ch = 1;
9420 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009421 if (p_ch > Rows - min_rows() + 1)
9422 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009423
9424 /* Only compute the new window layout when startup has been
9425 * completed. Otherwise the frame sizes may be wrong. */
9426 if (p_ch != old_value && full_screen
9427#ifdef FEAT_GUI
9428 && !gui.starting
9429#endif
9430 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009431 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009432 }
9433
9434 /* when 'updatecount' changes from zero to non-zero, open swap files */
9435 else if (pp == &p_uc)
9436 {
9437 if (p_uc < 0)
9438 {
9439 errmsg = e_positive;
9440 p_uc = 100;
9441 }
9442 if (p_uc && !old_value)
9443 ml_open_files();
9444 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009445#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009446 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009447 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009448 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009449 {
9450 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009451 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009452 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009453 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009454 {
9455 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009456 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009457 }
9458 }
9459#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009460#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009461 else if (pp == &p_mzq)
9462 mzvim_reset_timer();
9463#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009464
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009465#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9466 /* 'pyxversion' */
9467 else if (pp == &p_pyx)
9468 {
9469 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9470 errmsg = e_invarg;
9471 }
9472#endif
9473
Bram Moolenaar071d4272004-06-13 20:20:40 +00009474 /* sync undo before 'undolevels' changes */
9475 else if (pp == &p_ul)
9476 {
9477 /* use the old value, otherwise u_sync() may not work properly */
9478 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009479 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009480 p_ul = value;
9481 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009482 else if (pp == &curbuf->b_p_ul)
9483 {
9484 /* use the old value, otherwise u_sync() may not work properly */
9485 curbuf->b_p_ul = old_value;
9486 u_sync(TRUE);
9487 curbuf->b_p_ul = value;
9488 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009489
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009490#ifdef FEAT_LINEBREAK
9491 /* 'numberwidth' must be positive */
9492 else if (pp == &curwin->w_p_nuw)
9493 {
9494 if (curwin->w_p_nuw < 1)
9495 {
9496 errmsg = e_positive;
9497 curwin->w_p_nuw = 1;
9498 }
Bram Moolenaarf8a07122019-07-01 22:06:07 +02009499 if (curwin->w_p_nuw > 20)
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009500 {
9501 errmsg = e_invarg;
Bram Moolenaarf8a07122019-07-01 22:06:07 +02009502 curwin->w_p_nuw = 20;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009503 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009504 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009505 }
9506#endif
9507
Bram Moolenaar1a384422010-07-14 19:53:30 +02009508 else if (pp == &curbuf->b_p_tw)
9509 {
9510 if (curbuf->b_p_tw < 0)
9511 {
9512 errmsg = e_positive;
9513 curbuf->b_p_tw = 0;
9514 }
9515#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009516 {
9517 win_T *wp;
9518 tabpage_T *tp;
9519
9520 FOR_ALL_TAB_WINDOWS(tp, wp)
9521 check_colorcolumn(wp);
9522 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009523#endif
9524 }
9525
Bram Moolenaar071d4272004-06-13 20:20:40 +00009526 /*
9527 * Check the bounds for numeric options here
9528 */
9529 if (Rows < min_rows() && full_screen)
9530 {
9531 if (errbuf != NULL)
9532 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009533 vim_snprintf((char *)errbuf, errbuflen,
9534 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009535 errmsg = errbuf;
9536 }
9537 Rows = min_rows();
9538 }
9539 if (Columns < MIN_COLUMNS && full_screen)
9540 {
9541 if (errbuf != NULL)
9542 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009543 vim_snprintf((char *)errbuf, errbuflen,
9544 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009545 errmsg = errbuf;
9546 }
9547 Columns = MIN_COLUMNS;
9548 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009549 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009550
Bram Moolenaar071d4272004-06-13 20:20:40 +00009551 /*
9552 * If the screen (shell) height has been changed, assume it is the
9553 * physical screenheight.
9554 */
9555 if (old_Rows != Rows || old_Columns != Columns)
9556 {
9557 /* Changing the screen size is not allowed while updating the screen. */
9558 if (updating_screen)
9559 *pp = old_value;
9560 else if (full_screen
9561#ifdef FEAT_GUI
9562 && !gui.starting
9563#endif
9564 )
9565 set_shellsize((int)Columns, (int)Rows, TRUE);
9566 else
9567 {
9568 /* Postpone the resizing; check the size and cmdline position for
9569 * messages. */
9570 check_shellsize();
9571 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9572 cmdline_row = Rows - p_ch;
9573 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009574 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009575 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009576 }
9577
Bram Moolenaar071d4272004-06-13 20:20:40 +00009578 if (curbuf->b_p_ts <= 0)
9579 {
9580 errmsg = e_positive;
9581 curbuf->b_p_ts = 8;
9582 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009583 if (p_tm < 0)
9584 {
9585 errmsg = e_positive;
9586 p_tm = 0;
9587 }
9588 if ((curwin->w_p_scr <= 0
9589 || (curwin->w_p_scr > curwin->w_height
9590 && curwin->w_height > 0))
9591 && full_screen)
9592 {
9593 if (pp == &(curwin->w_p_scr))
9594 {
9595 if (curwin->w_p_scr != 0)
9596 errmsg = e_scroll;
9597 win_comp_scroll(curwin);
9598 }
9599 /* If 'scroll' became invalid because of a side effect silently adjust
9600 * it. */
9601 else if (curwin->w_p_scr <= 0)
9602 curwin->w_p_scr = 1;
9603 else /* curwin->w_p_scr > curwin->w_height */
9604 curwin->w_p_scr = curwin->w_height;
9605 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009606 if (p_hi < 0)
9607 {
9608 errmsg = e_positive;
9609 p_hi = 0;
9610 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009611 else if (p_hi > 10000)
9612 {
9613 errmsg = e_invarg;
9614 p_hi = 10000;
9615 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009616 if (p_re < 0 || p_re > 2)
9617 {
9618 errmsg = e_invarg;
9619 p_re = 0;
9620 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009621 if (p_report < 0)
9622 {
9623 errmsg = e_positive;
9624 p_report = 1;
9625 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009626 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009627 {
9628 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9629 p_sj = Rows / 2;
9630 else
9631 {
9632 errmsg = e_scroll;
9633 p_sj = 1;
9634 }
9635 }
9636 if (p_so < 0 && full_screen)
9637 {
Bram Moolenaar375e3392019-01-31 18:26:10 +01009638 errmsg = e_positive;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009639 p_so = 0;
9640 }
9641 if (p_siso < 0 && full_screen)
9642 {
9643 errmsg = e_positive;
9644 p_siso = 0;
9645 }
9646#ifdef FEAT_CMDWIN
9647 if (p_cwh < 1)
9648 {
9649 errmsg = e_positive;
9650 p_cwh = 1;
9651 }
9652#endif
9653 if (p_ut < 0)
9654 {
9655 errmsg = e_positive;
9656 p_ut = 2000;
9657 }
9658 if (p_ss < 0)
9659 {
9660 errmsg = e_positive;
9661 p_ss = 0;
9662 }
9663
9664 /* May set global value for local option. */
9665 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9666 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9667
9668 options[opt_idx].flags |= P_WAS_SET;
9669
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009670#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009671 // Don't do this while starting up, failure or recursively.
9672 if (!starting && errmsg == NULL && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009673 {
Bram Moolenaard7c96872019-06-15 17:12:48 +02009674 char_u buf_old[11], buf_old_global[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009675 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009676 vim_snprintf((char *)buf_old_global, 10, "%ld", old_global_value);
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009677 vim_snprintf((char *)buf_new, 10, "%ld", value);
9678 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009679 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9680 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9681 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009682 if (opt_flags & OPT_LOCAL)
9683 {
9684 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
9685 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9686 }
9687 if (opt_flags & OPT_GLOBAL)
9688 {
9689 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
9690 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old, -1);
9691 }
9692 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9693 {
9694 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
9695 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9696 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old_global, -1);
9697 }
9698 if (opt_flags & OPT_MODELINE)
9699 {
9700 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
9701 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9702 }
9703 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname,
9704 NULL, FALSE, NULL);
Bram Moolenaar53744302015-07-17 17:38:22 +02009705 reset_v_option_vars();
9706 }
9707#endif
9708
Bram Moolenaar071d4272004-06-13 20:20:40 +00009709 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009710 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009711 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009712 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009713 check_redraw(options[opt_idx].flags);
9714
9715 return errmsg;
9716}
9717
9718/*
9719 * Called after an option changed: check if something needs to be redrawn.
9720 */
9721 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009722check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009723{
9724 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009725 int doclear = (flags & P_RCLR) == P_RCLR;
9726 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009727
Bram Moolenaar071d4272004-06-13 20:20:40 +00009728 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9729 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009730
9731 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9732 changed_window_setting();
9733 if (flags & P_RBUF)
9734 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009735 if (flags & P_RWINONLY)
9736 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009737 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009738 redraw_all_later(CLEAR);
9739 else if (all)
9740 redraw_all_later(NOT_VALID);
9741}
9742
9743/*
9744 * Find index for option 'arg'.
9745 * Return -1 if not found.
9746 */
9747 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009748findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009749{
9750 int opt_idx;
9751 char *s, *p;
9752 static short quick_tab[27] = {0, 0}; /* quick access table */
9753 int is_term_opt;
9754
9755 /*
9756 * For first call: Initialize the quick-access table.
9757 * It contains the index for the first option that starts with a certain
9758 * letter. There are 26 letters, plus the first "t_" option.
9759 */
9760 if (quick_tab[1] == 0)
9761 {
9762 p = options[0].fullname;
9763 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9764 {
9765 if (s[0] != p[0])
9766 {
9767 if (s[0] == 't' && s[1] == '_')
9768 quick_tab[26] = opt_idx;
9769 else
9770 quick_tab[CharOrdLow(s[0])] = opt_idx;
9771 }
9772 p = s;
9773 }
9774 }
9775
9776 /*
9777 * Check for name starting with an illegal character.
9778 */
9779#ifdef EBCDIC
9780 if (!islower(arg[0]))
9781#else
9782 if (arg[0] < 'a' || arg[0] > 'z')
9783#endif
9784 return -1;
9785
9786 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9787 if (is_term_opt)
9788 opt_idx = quick_tab[26];
9789 else
9790 opt_idx = quick_tab[CharOrdLow(arg[0])];
9791 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9792 {
9793 if (STRCMP(arg, s) == 0) /* match full name */
9794 break;
9795 }
9796 if (s == NULL && !is_term_opt)
9797 {
9798 opt_idx = quick_tab[CharOrdLow(arg[0])];
9799 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9800 {
9801 s = options[opt_idx].shortname;
9802 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9803 break;
9804 s = NULL;
9805 }
9806 }
9807 if (s == NULL)
9808 opt_idx = -1;
9809 return opt_idx;
9810}
9811
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009812#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009813/*
9814 * Get the value for an option.
9815 *
9816 * Returns:
9817 * Number or Toggle option: 1, *numval gets value.
9818 * String option: 0, *stringval gets allocated string.
9819 * Hidden Number or Toggle option: -1.
9820 * hidden String option: -2.
9821 * unknown option: -3.
9822 */
9823 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009824get_option_value(
9825 char_u *name,
9826 long *numval,
9827 char_u **stringval, /* NULL when only checking existence */
9828 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009829{
9830 int opt_idx;
9831 char_u *varp;
9832
9833 opt_idx = findoption(name);
9834 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009835 {
9836 int key;
9837
9838 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009839 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009840 {
9841 char_u key_name[2];
9842 char_u *p;
9843
9844 if (key < 0)
9845 {
9846 key_name[0] = KEY2TERMCAP0(key);
9847 key_name[1] = KEY2TERMCAP1(key);
9848 }
9849 else
9850 {
9851 key_name[0] = KS_KEY;
9852 key_name[1] = (key & 0xff);
9853 }
9854 p = find_termcode(key_name);
9855 if (p != NULL)
9856 {
9857 if (stringval != NULL)
9858 *stringval = vim_strsave(p);
9859 return 0;
9860 }
9861 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009862 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009863 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009864
9865 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9866
9867 if (options[opt_idx].flags & P_STRING)
9868 {
9869 if (varp == NULL) /* hidden option */
9870 return -2;
9871 if (stringval != NULL)
9872 {
9873#ifdef FEAT_CRYPT
9874 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009875 if ((char_u **)varp == &curbuf->b_p_key
9876 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009877 *stringval = vim_strsave((char_u *)"*****");
9878 else
9879#endif
9880 *stringval = vim_strsave(*(char_u **)(varp));
9881 }
9882 return 0;
9883 }
9884
9885 if (varp == NULL) /* hidden option */
9886 return -1;
9887 if (options[opt_idx].flags & P_NUM)
9888 *numval = *(long *)varp;
9889 else
9890 {
9891 /* Special case: 'modified' is b_changed, but we also want to consider
9892 * it set when 'ff' or 'fenc' changed. */
9893 if ((int *)varp == &curbuf->b_changed)
9894 *numval = curbufIsChanged();
9895 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009896 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009897 }
9898 return 1;
9899}
9900#endif
9901
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009902#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009903/*
9904 * Returns the option attributes and its value. Unlike the above function it
9905 * will return either global value or local value of the option depending on
9906 * what was requested, but it will never return global value if it was
9907 * requested to return local one and vice versa. Neither it will return
9908 * buffer-local value if it was requested to return window-local one.
9909 *
9910 * Pretends that option is absent if it is not present in the requested scope
9911 * (i.e. has no global, window-local or buffer-local value depending on
9912 * opt_type). Uses
9913 *
9914 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009915 * 0 hidden or unknown option, also option that does not have requested
9916 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009917 * see SOPT_* in vim.h for other flags
9918 *
9919 * Possible opt_type values: see SREQ_* in vim.h
9920 */
9921 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009922get_option_value_strict(
9923 char_u *name,
9924 long *numval,
9925 char_u **stringval, /* NULL when only obtaining attributes */
9926 int opt_type,
9927 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009928{
9929 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009930 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009931 struct vimoption *p;
9932 int r = 0;
9933
9934 opt_idx = findoption(name);
9935 if (opt_idx < 0)
9936 return 0;
9937
9938 p = &(options[opt_idx]);
9939
9940 /* Hidden option */
9941 if (p->var == NULL)
9942 return 0;
9943
9944 if (p->flags & P_BOOL)
9945 r |= SOPT_BOOL;
9946 else if (p->flags & P_NUM)
9947 r |= SOPT_NUM;
9948 else if (p->flags & P_STRING)
9949 r |= SOPT_STRING;
9950
9951 if (p->indir == PV_NONE)
9952 {
9953 if (opt_type == SREQ_GLOBAL)
9954 r |= SOPT_GLOBAL;
9955 else
9956 return 0; /* Did not request global-only option */
9957 }
9958 else
9959 {
9960 if (p->indir & PV_BOTH)
9961 r |= SOPT_GLOBAL;
9962 else if (opt_type == SREQ_GLOBAL)
9963 return 0; /* Requested global option */
9964
9965 if (p->indir & PV_WIN)
9966 {
9967 if (opt_type == SREQ_BUF)
9968 return 0; /* Did not request window-local option */
9969 else
9970 r |= SOPT_WIN;
9971 }
9972 else if (p->indir & PV_BUF)
9973 {
9974 if (opt_type == SREQ_WIN)
9975 return 0; /* Did not request buffer-local option */
9976 else
9977 r |= SOPT_BUF;
9978 }
9979 }
9980
9981 if (stringval == NULL)
9982 return r;
9983
9984 if (opt_type == SREQ_GLOBAL)
9985 varp = p->var;
9986 else
9987 {
9988 if (opt_type == SREQ_BUF)
9989 {
9990 /* Special case: 'modified' is b_changed, but we also want to
9991 * consider it set when 'ff' or 'fenc' changed. */
9992 if (p->indir == PV_MOD)
9993 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009994 *numval = bufIsChanged((buf_T *)from);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009995 varp = NULL;
9996 }
9997#ifdef FEAT_CRYPT
9998 else if (p->indir == PV_KEY)
9999 {
10000 /* never return the value of the crypt key */
10001 *stringval = NULL;
10002 varp = NULL;
10003 }
10004#endif
10005 else
10006 {
Bram Moolenaardefe6422018-06-24 15:14:07 +020010007 buf_T *save_curbuf = curbuf;
10008
10009 // only getting a pointer, no need to use aucmd_prepbuf()
10010 curbuf = (buf_T *)from;
10011 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010012 varp = get_varp(p);
Bram Moolenaardefe6422018-06-24 15:14:07 +020010013 curbuf = save_curbuf;
10014 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010015 }
10016 }
10017 else if (opt_type == SREQ_WIN)
10018 {
Bram Moolenaardefe6422018-06-24 15:14:07 +020010019 win_T *save_curwin = curwin;
10020
10021 curwin = (win_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010022 curbuf = curwin->w_buffer;
10023 varp = get_varp(p);
10024 curwin = save_curwin;
10025 curbuf = curwin->w_buffer;
10026 }
10027 if (varp == p->var)
10028 return (r | SOPT_UNSET);
10029 }
10030
10031 if (varp != NULL)
10032 {
10033 if (p->flags & P_STRING)
10034 *stringval = vim_strsave(*(char_u **)(varp));
10035 else if (p->flags & P_NUM)
10036 *numval = *(long *) varp;
10037 else
10038 *numval = *(int *)varp;
10039 }
10040
10041 return r;
10042}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010043
10044/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010045 * Iterate over options. First argument is a pointer to a pointer to a
10046 * structure inside options[] array, second is option type like in the above
10047 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010048 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010049 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010050 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010051 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010052 * first argument to NULL.
10053 *
10054 * Returns full option name for current option on each call.
10055 */
10056 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010057option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010058{
10059 struct vimoption *ret = NULL;
10060 do
10061 {
10062 if (*option == NULL)
10063 *option = (void *) options;
10064 else if (((struct vimoption *) (*option))->fullname == NULL)
10065 {
10066 *option = NULL;
10067 return NULL;
10068 }
10069 else
10070 *option = (void *) (((struct vimoption *) (*option)) + 1);
10071
10072 ret = ((struct vimoption *) (*option));
10073
10074 /* Hidden option */
10075 if (ret->var == NULL)
10076 {
10077 ret = NULL;
10078 continue;
10079 }
10080
10081 switch (opt_type)
10082 {
10083 case SREQ_GLOBAL:
10084 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
10085 ret = NULL;
10086 break;
10087 case SREQ_BUF:
10088 if (!(ret->indir & PV_BUF))
10089 ret = NULL;
10090 break;
10091 case SREQ_WIN:
10092 if (!(ret->indir & PV_WIN))
10093 ret = NULL;
10094 break;
10095 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +010010096 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010097 return NULL;
10098 }
10099 }
10100 while (ret == NULL);
10101
10102 return (char_u *)ret->fullname;
10103}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010104#endif
10105
Bram Moolenaar071d4272004-06-13 20:20:40 +000010106/*
10107 * Set the value of option "name".
10108 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010109 *
10110 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010111 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010112 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010113set_option_value(
10114 char_u *name,
10115 long number,
10116 char_u *string,
10117 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010118{
10119 int opt_idx;
10120 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +000010121 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010122
10123 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010124 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +010010125 {
10126 int key;
10127
10128 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010129 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +010010130 {
10131 char_u key_name[2];
10132
10133 if (key < 0)
10134 {
10135 key_name[0] = KEY2TERMCAP0(key);
10136 key_name[1] = KEY2TERMCAP1(key);
10137 }
10138 else
10139 {
10140 key_name[0] = KS_KEY;
10141 key_name[1] = (key & 0xff);
10142 }
10143 add_termcode(key_name, string, FALSE);
10144 if (full_screen)
10145 ttest(FALSE);
10146 redraw_all_later(CLEAR);
10147 return NULL;
10148 }
10149
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010150 semsg(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +010010151 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010152 else
10153 {
10154 flags = options[opt_idx].flags;
10155#ifdef HAVE_SANDBOX
10156 /* Disallow changing some options in the sandbox */
10157 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010158 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010159 emsg(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010160 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010161 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010162#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010163 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010164 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010165 else
10166 {
Bram Moolenaarb3163762008-07-08 15:15:08 +000010167 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010168 if (varp != NULL) /* hidden option is not changed */
10169 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010170 if (number == 0 && string != NULL)
10171 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +000010172 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010173
10174 /* Either we are given a string or we are setting option
10175 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +000010176 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010177 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +000010178 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010179 {
10180 /* There's another character after zeros or the string
10181 * is empty. In both cases, we are trying to set a
10182 * num option using a string. */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010183 semsg(_("E521: Number required: &%s = '%s'"),
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010184 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010185 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010186
10187 }
10188 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010189 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010190 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +000010191 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010192 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010193 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010194 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010195 }
10196 }
10197 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010198 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010199}
10200
10201/*
10202 * Get the terminal code for a terminal option.
10203 * Returns NULL when not found.
10204 */
10205 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010206get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010207{
10208 int opt_idx;
10209 char_u *varp;
10210
10211 if (tname[0] != 't' || tname[1] != '_' ||
10212 tname[2] == NUL || tname[3] == NUL)
10213 return NULL;
10214 if ((opt_idx = findoption(tname)) >= 0)
10215 {
10216 varp = get_varp(&(options[opt_idx]));
10217 if (varp != NULL)
10218 varp = *(char_u **)(varp);
10219 return varp;
10220 }
10221 return find_termcode(tname + 2);
10222}
10223
10224 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010225get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010226{
10227 int i;
10228
10229 i = findoption((char_u *)"hl");
10230 if (i >= 0)
10231 return options[i].def_val[VI_DEFAULT];
10232 return (char_u *)NULL;
10233}
10234
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010235 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010236get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010237{
10238 int i;
10239
10240 i = findoption((char_u *)"enc");
10241 if (i >= 0)
10242 return options[i].def_val[VI_DEFAULT];
10243 return (char_u *)NULL;
10244}
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010245
Bram Moolenaar071d4272004-06-13 20:20:40 +000010246/*
10247 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010248 * When "has_lt" is true there is a '<' before "*arg_arg".
10249 * Returns 0 when the key is not recognized.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010250 */
10251 static int
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010252find_key_option(char_u *arg_arg, int has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010253{
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010254 int key = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010255 int modifiers;
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010256 char_u *arg = arg_arg;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010257
10258 /*
10259 * Don't use get_special_key_code() for t_xx, we don't want it to call
10260 * add_termcap_entry().
10261 */
10262 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
10263 key = TERMCAP2KEY(arg[2], arg[3]);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010264 else if (has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010265 {
10266 --arg; /* put arg at the '<' */
10267 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +020010268 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010269 if (modifiers) /* can't handle modifiers here */
10270 key = 0;
10271 }
10272 return key;
10273}
10274
10275/*
10276 * if 'all' == 0: show changed options
10277 * if 'all' == 1: show all normal options
10278 * if 'all' == 2: show all terminal options
10279 */
10280 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010281showoptions(
10282 int all,
10283 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010284{
10285 struct vimoption *p;
10286 int col;
10287 int isterm;
10288 char_u *varp;
10289 struct vimoption **items;
10290 int item_count;
10291 int run;
10292 int row, rows;
10293 int cols;
10294 int i;
10295 int len;
10296
10297#define INC 20
10298#define GAP 3
10299
Bram Moolenaarc799fe22019-05-28 23:08:19 +020010300 items = ALLOC_MULT(struct vimoption *, PARAM_COUNT);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010301 if (items == NULL)
10302 return;
10303
10304 /* Highlight title */
10305 if (all == 2)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010306 msg_puts_title(_("\n--- Terminal codes ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010307 else if (opt_flags & OPT_GLOBAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010308 msg_puts_title(_("\n--- Global option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010309 else if (opt_flags & OPT_LOCAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010310 msg_puts_title(_("\n--- Local option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010311 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010312 msg_puts_title(_("\n--- Options ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010313
10314 /*
10315 * do the loop two times:
10316 * 1. display the short items
10317 * 2. display the long items (only strings and numbers)
10318 */
10319 for (run = 1; run <= 2 && !got_int; ++run)
10320 {
10321 /*
10322 * collect the items in items[]
10323 */
10324 item_count = 0;
10325 for (p = &options[0]; p->fullname != NULL; p++)
10326 {
Bram Moolenaarf86db782018-10-25 13:31:37 +020010327 // apply :filter /pat/
10328 if (message_filtered((char_u *) p->fullname))
10329 continue;
10330
Bram Moolenaar071d4272004-06-13 20:20:40 +000010331 varp = NULL;
10332 isterm = istermoption(p);
10333 if (opt_flags != 0)
10334 {
10335 if (p->indir != PV_NONE && !isterm)
10336 varp = get_varp_scope(p, opt_flags);
10337 }
10338 else
10339 varp = get_varp(p);
10340 if (varp != NULL
10341 && ((all == 2 && isterm)
10342 || (all == 1 && !isterm)
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010343 || (all == 0 && !optval_default(p, varp, p_cp))))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010344 {
10345 if (p->flags & P_BOOL)
10346 len = 1; /* a toggle option fits always */
10347 else
10348 {
10349 option_value2string(p, opt_flags);
10350 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
10351 }
10352 if ((len <= INC - GAP && run == 1) ||
10353 (len > INC - GAP && run == 2))
10354 items[item_count++] = p;
10355 }
10356 }
10357
10358 /*
10359 * display the items
10360 */
10361 if (run == 1)
10362 {
10363 cols = (Columns + GAP - 3) / INC;
10364 if (cols == 0)
10365 cols = 1;
10366 rows = (item_count + cols - 1) / cols;
10367 }
10368 else /* run == 2 */
10369 rows = item_count;
10370 for (row = 0; row < rows && !got_int; ++row)
10371 {
10372 msg_putchar('\n'); /* go to next line */
10373 if (got_int) /* 'q' typed in more */
10374 break;
10375 col = 0;
10376 for (i = row; i < item_count; i += rows)
10377 {
10378 msg_col = col; /* make columns */
10379 showoneopt(items[i], opt_flags);
10380 col += INC;
10381 }
10382 out_flush();
10383 ui_breakcheck();
10384 }
10385 }
10386 vim_free(items);
10387}
10388
10389/*
10390 * Return TRUE if option "p" has its default value.
10391 */
10392 static int
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010393optval_default(struct vimoption *p, char_u *varp, int compatible)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010394{
10395 int dvi;
10396
10397 if (varp == NULL)
10398 return TRUE; /* hidden option is always at default */
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010399 dvi = ((p->flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010400 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010401 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010402 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010403 /* the cast to long is required for Manx C, long_i is
10404 * needed for MSVC */
10405 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010406 /* P_STRING */
10407 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
10408}
10409
10410/*
10411 * showoneopt: show the value of one option
10412 * must not be called with a hidden option!
10413 */
10414 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010415showoneopt(
10416 struct vimoption *p,
10417 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010418{
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010419 char_u *varp;
10420 int save_silent = silent_mode;
10421
10422 silent_mode = FALSE;
10423 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010424
10425 varp = get_varp_scope(p, opt_flags);
10426
10427 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
10428 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
10429 ? !curbufIsChanged() : !*(int *)varp))
Bram Moolenaar32526b32019-01-19 17:43:09 +010010430 msg_puts("no");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010431 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010432 msg_puts("--");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010433 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010434 msg_puts(" ");
10435 msg_puts(p->fullname);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010436 if (!(p->flags & P_BOOL))
10437 {
10438 msg_putchar('=');
10439 /* put value string in NameBuff */
10440 option_value2string(p, opt_flags);
10441 msg_outtrans(NameBuff);
10442 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010443
10444 silent_mode = save_silent;
10445 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010446}
10447
10448/*
10449 * Write modified options as ":set" commands to a file.
10450 *
10451 * There are three values for "opt_flags":
10452 * OPT_GLOBAL: Write global option values and fresh values of
10453 * buffer-local options (used for start of a session
10454 * file).
10455 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10456 * curwin (used for a vimrc file).
10457 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10458 * and local values for window-local options of
10459 * curwin. Local values are also written when at the
10460 * default value, because a modeline or autocommand
10461 * may have set them when doing ":edit file" and the
10462 * user has set them back at the default or fresh
10463 * value.
10464 * When "local_only" is TRUE, don't write fresh
10465 * values, only local values (for ":mkview").
10466 * (fresh value = value used for a new buffer or window for a local option).
10467 *
10468 * Return FAIL on error, OK otherwise.
10469 */
10470 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010471makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010472{
10473 struct vimoption *p;
10474 char_u *varp; /* currently used value */
10475 char_u *varp_fresh; /* local value */
10476 char_u *varp_local = NULL; /* fresh value */
10477 char *cmd;
10478 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010479 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010480
10481 /*
10482 * The options that don't have a default (terminal name, columns, lines)
10483 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010484 * Do the loop over "options[]" twice: once for options with the
10485 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010486 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010487 for (pri = 1; pri >= 0; --pri)
10488 {
10489 for (p = &options[0]; !istermoption(p); p++)
10490 if (!(p->flags & P_NO_MKRC)
10491 && !istermoption(p)
10492 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010493 {
10494 /* skip global option when only doing locals */
10495 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10496 continue;
10497
10498 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10499 * file, they are always buffer-specific. */
10500 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10501 continue;
10502
10503 /* Global values are only written when not at the default value. */
10504 varp = get_varp_scope(p, opt_flags);
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010505 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp, p_cp))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010506 continue;
10507
10508 round = 2;
10509 if (p->indir != PV_NONE)
10510 {
10511 if (p->var == VAR_WIN)
10512 {
10513 /* skip window-local option when only doing globals */
10514 if (!(opt_flags & OPT_LOCAL))
10515 continue;
10516 /* When fresh value of window-local option is not at the
10517 * default, need to write it too. */
10518 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10519 {
10520 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010521 if (!optval_default(p, varp_fresh, p_cp))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010522 {
10523 round = 1;
10524 varp_local = varp;
10525 varp = varp_fresh;
10526 }
10527 }
10528 }
10529 }
10530
10531 /* Round 1: fresh value for window-local options.
10532 * Round 2: other values */
10533 for ( ; round <= 2; varp = varp_local, ++round)
10534 {
10535 if (round == 1 || (opt_flags & OPT_GLOBAL))
10536 cmd = "set";
10537 else
10538 cmd = "setlocal";
10539
10540 if (p->flags & P_BOOL)
10541 {
10542 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10543 return FAIL;
10544 }
10545 else if (p->flags & P_NUM)
10546 {
10547 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10548 return FAIL;
10549 }
10550 else /* P_STRING */
10551 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010552 int do_endif = FALSE;
10553
Bram Moolenaar071d4272004-06-13 20:20:40 +000010554 /* Don't set 'syntax' and 'filetype' again if the value is
10555 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010556 if (
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +010010557#if defined(FEAT_SYN_HL)
10558 p->indir == PV_SYN ||
10559#endif
10560 p->indir == PV_FT)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010561 {
10562 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10563 *(char_u **)(varp)) < 0
10564 || put_eol(fd) < 0)
10565 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010566 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010567 }
10568 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010569 p->flags) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010570 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010571 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010572 {
10573 if (put_line(fd, "endif") == FAIL)
10574 return FAIL;
10575 }
10576 }
10577 }
10578 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010579 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010580 return OK;
10581}
10582
10583#if defined(FEAT_FOLDING) || defined(PROTO)
10584/*
10585 * Generate set commands for the local fold options only. Used when
10586 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10587 */
10588 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010589makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010590{
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010591 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, 0) == FAIL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010592# ifdef FEAT_EVAL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010593 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010594 == FAIL
10595# endif
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010596 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010597 == FAIL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010598 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010599 == FAIL
10600 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10601 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10602 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10603 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10604 )
10605 return FAIL;
10606
10607 return OK;
10608}
10609#endif
10610
10611 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010612put_setstring(
10613 FILE *fd,
10614 char *cmd,
10615 char *name,
10616 char_u **valuep,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010617 long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010618{
10619 char_u *s;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010620 char_u *buf = NULL;
10621 char_u *part = NULL;
10622 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010623
10624 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10625 return FAIL;
10626 if (*valuep != NULL)
10627 {
10628 /* Output 'pastetoggle' as key names. For other
10629 * options some characters have to be escaped with
10630 * CTRL-V or backslash */
10631 if (valuep == &p_pt)
10632 {
10633 s = *valuep;
10634 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010635 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010636 return FAIL;
10637 }
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010638 // expand the option value, replace $HOME by ~
10639 else if ((flags & P_EXPAND) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010640 {
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010641 int size = (int)STRLEN(*valuep) + 1;
10642
10643 // replace home directory in the whole option value into "buf"
10644 buf = alloc(size);
Bram Moolenaarf8441472011-04-28 17:24:58 +020010645 if (buf == NULL)
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010646 goto fail;
10647 home_replace(NULL, *valuep, buf, size, FALSE);
10648
10649 // If the option value is longer than MAXPATHL, we need to append
10650 // earch comma separated part of the option separately, so that it
10651 // can be expanded when read back.
10652 if (size >= MAXPATHL && (flags & P_COMMA) != 0
10653 && vim_strchr(*valuep, ',') != NULL)
10654 {
10655 part = alloc(size);
10656 if (part == NULL)
10657 goto fail;
10658
10659 // write line break to clear the option, e.g. ':set rtp='
10660 if (put_eol(fd) == FAIL)
10661 goto fail;
10662
10663 p = buf;
10664 while (*p != NUL)
10665 {
10666 // for each comma separated option part, append value to
10667 // the option, :set rtp+=value
10668 if (fprintf(fd, "%s %s+=", cmd, name) < 0)
10669 goto fail;
10670 (void)copy_option_part(&p, part, size, ",");
10671 if (put_escstr(fd, part, 2) == FAIL || put_eol(fd) == FAIL)
10672 goto fail;
10673 }
10674 vim_free(buf);
10675 vim_free(part);
10676 return OK;
10677 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010678 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010679 {
10680 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010681 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010682 }
10683 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010684 }
10685 else if (put_escstr(fd, *valuep, 2) == FAIL)
10686 return FAIL;
10687 }
10688 if (put_eol(fd) < 0)
10689 return FAIL;
10690 return OK;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010691fail:
10692 vim_free(buf);
10693 vim_free(part);
10694 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010695}
10696
10697 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010698put_setnum(
10699 FILE *fd,
10700 char *cmd,
10701 char *name,
10702 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010703{
10704 long wc;
10705
10706 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10707 return FAIL;
10708 if (wc_use_keyname((char_u *)valuep, &wc))
10709 {
10710 /* print 'wildchar' and 'wildcharm' as a key name */
10711 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10712 return FAIL;
10713 }
10714 else if (fprintf(fd, "%ld", *valuep) < 0)
10715 return FAIL;
10716 if (put_eol(fd) < 0)
10717 return FAIL;
10718 return OK;
10719}
10720
10721 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010722put_setbool(
10723 FILE *fd,
10724 char *cmd,
10725 char *name,
10726 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010727{
Bram Moolenaar893de922007-10-02 18:40:57 +000010728 if (value < 0) /* global/local option using global value */
10729 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010730 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10731 || put_eol(fd) < 0)
10732 return FAIL;
10733 return OK;
10734}
10735
10736/*
10737 * Clear all the terminal options.
10738 * If the option has been allocated, free the memory.
10739 * Terminal options are never hidden or indirect.
10740 */
10741 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010742clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010743{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010744 /*
10745 * Reset a few things before clearing the old options. This may cause
10746 * outputting a few things that the terminal doesn't understand, but the
10747 * screen will be cleared later, so this is OK.
10748 */
10749#ifdef FEAT_MOUSE_TTY
10750 mch_setmouse(FALSE); /* switch mouse off */
10751#endif
10752#ifdef FEAT_TITLE
Bram Moolenaar40385db2018-08-07 22:31:44 +020010753 mch_restore_title(SAVE_RESTORE_BOTH); /* restore window titles */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010754#endif
10755#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10756 /* When starting the GUI close the display opened for the clipboard.
10757 * After restoring the title, because that will need the display. */
10758 if (gui.starting)
10759 clear_xterm_clip();
10760#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010761 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010762
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010763 free_termoptions();
10764}
10765
10766 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010767free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010768{
10769 struct vimoption *p;
10770
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010771 for (p = options; p->fullname != NULL; p++)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010772 if (istermoption(p))
10773 {
10774 if (p->flags & P_ALLOCED)
10775 free_string_option(*(char_u **)(p->var));
10776 if (p->flags & P_DEF_ALLOCED)
10777 free_string_option(p->def_val[VI_DEFAULT]);
10778 *(char_u **)(p->var) = empty_option;
10779 p->def_val[VI_DEFAULT] = empty_option;
10780 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010781#ifdef FEAT_EVAL
10782 // remember where the option was cleared
10783 set_option_sctx_idx((int)(p - options), OPT_GLOBAL, current_sctx);
10784#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010785 }
10786 clear_termcodes();
10787}
10788
10789/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010790 * Free the string for one term option, if it was allocated.
10791 * Set the string to empty_option and clear allocated flag.
10792 * "var" points to the option value.
10793 */
10794 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010795free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010796{
10797 struct vimoption *p;
10798
10799 for (p = &options[0]; p->fullname != NULL; p++)
10800 if (p->var == var)
10801 {
10802 if (p->flags & P_ALLOCED)
10803 free_string_option(*(char_u **)(p->var));
10804 *(char_u **)(p->var) = empty_option;
10805 p->flags &= ~P_ALLOCED;
10806 break;
10807 }
10808}
10809
10810/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010811 * Set the terminal option defaults to the current value.
10812 * Used after setting the terminal name.
10813 */
10814 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010815set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010816{
10817 struct vimoption *p;
10818
10819 for (p = &options[0]; p->fullname != NULL; p++)
10820 {
10821 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10822 {
10823 if (p->flags & P_DEF_ALLOCED)
10824 {
10825 free_string_option(p->def_val[VI_DEFAULT]);
10826 p->flags &= ~P_DEF_ALLOCED;
10827 }
10828 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10829 if (p->flags & P_ALLOCED)
10830 {
10831 p->flags |= P_DEF_ALLOCED;
10832 p->flags &= ~P_ALLOCED; /* don't free the value now */
10833 }
10834 }
10835 }
10836}
10837
10838/*
10839 * return TRUE if 'p' starts with 't_'
10840 */
10841 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010842istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010843{
10844 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10845}
10846
10847/*
10848 * Compute columns for ruler and shown command. 'sc_col' is also used to
10849 * decide what the maximum length of a message on the status line can be.
10850 * If there is a status line for the last window, 'sc_col' is independent
10851 * of 'ru_col'.
10852 */
10853
10854#define COL_RULER 17 /* columns needed by standard ruler */
10855
10856 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010857comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010858{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010859#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010860 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010861
10862 sc_col = 0;
10863 ru_col = 0;
10864 if (p_ru)
10865 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010866# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010867 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010868# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010869 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010870# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010871 /* no last status line, adjust sc_col */
10872 if (!last_has_status)
10873 sc_col = ru_col;
10874 }
10875 if (p_sc)
10876 {
10877 sc_col += SHOWCMD_COLS;
10878 if (!p_ru || last_has_status) /* no need for separating space */
10879 ++sc_col;
10880 }
10881 sc_col = Columns - sc_col;
10882 ru_col = Columns - ru_col;
10883 if (sc_col <= 0) /* screen too narrow, will become a mess */
10884 sc_col = 1;
10885 if (ru_col <= 0)
10886 ru_col = 1;
10887#else
10888 sc_col = Columns;
10889 ru_col = Columns;
10890#endif
10891}
10892
Bram Moolenaar113e1072019-01-20 15:30:40 +010010893#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010894/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010895 * Unset local option value, similar to ":set opt<".
10896 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010897 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010898unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010899{
10900 struct vimoption *p;
10901 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010902 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010903
10904 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010905 if (opt_idx < 0)
10906 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010907 p = &(options[opt_idx]);
10908
10909 switch ((int)p->indir)
10910 {
10911 /* global option with local value: use local value if it's been set */
10912 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010913 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010914 break;
10915 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010916 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010917 break;
10918 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010919 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010920 break;
10921 case PV_AR:
10922 buf->b_p_ar = -1;
10923 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010924 case PV_BKC:
10925 clear_string_option(&buf->b_p_bkc);
10926 buf->b_bkc_flags = 0;
10927 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010928 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010929 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010930 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010931 case PV_TC:
10932 clear_string_option(&buf->b_p_tc);
10933 buf->b_tc_flags = 0;
10934 break;
Bram Moolenaar375e3392019-01-31 18:26:10 +010010935 case PV_SISO:
10936 curwin->w_p_siso = -1;
10937 break;
10938 case PV_SO:
10939 curwin->w_p_so = -1;
10940 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010941#ifdef FEAT_FIND_ID
10942 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010943 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010944 break;
10945 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010946 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010947 break;
10948#endif
10949#ifdef FEAT_INS_EXPAND
10950 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010951 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010952 break;
10953 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010954 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010955 break;
10956#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010957 case PV_FP:
10958 clear_string_option(&buf->b_p_fp);
10959 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010960#ifdef FEAT_QUICKFIX
10961 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010962 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010963 break;
10964 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010965 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010966 break;
10967 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010968 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010969 break;
10970#endif
10971#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10972 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010973 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010974 break;
10975#endif
10976#if defined(FEAT_CRYPT)
10977 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010978 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010979 break;
10980#endif
10981#ifdef FEAT_STL_OPT
10982 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010983 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010984 break;
10985#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010986 case PV_UL:
10987 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10988 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010989#ifdef FEAT_LISP
10990 case PV_LW:
10991 clear_string_option(&buf->b_p_lw);
10992 break;
10993#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010994 case PV_MENC:
10995 clear_string_option(&buf->b_p_menc);
10996 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010997 }
10998}
Bram Moolenaar113e1072019-01-20 15:30:40 +010010999#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020011000
11001/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011002 * Get pointer to option variable, depending on local or global scope.
11003 */
11004 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011005get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011006{
11007 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
11008 {
11009 if (p->var == VAR_WIN)
11010 return (char_u *)GLOBAL_WO(get_varp(p));
11011 return p->var;
11012 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000011013 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011014 {
11015 switch ((int)p->indir)
11016 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011017 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011018#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011019 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
11020 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
11021 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011022#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011023 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
11024 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
11025 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000011026 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011027 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011028 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar375e3392019-01-31 18:26:10 +010011029 case PV_SISO: return (char_u *)&(curwin->w_p_siso);
11030 case PV_SO: return (char_u *)&(curwin->w_p_so);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011031#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011032 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
11033 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011034#endif
11035#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011036 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
11037 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011038#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011039#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11040 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
11041#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011042#if defined(FEAT_CRYPT)
11043 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
11044#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011045#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011046 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011047#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011048 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011049#ifdef FEAT_LISP
11050 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
11051#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011052 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011053 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011054 }
11055 return NULL; /* "cannot happen" */
11056 }
11057 return get_varp(p);
11058}
11059
11060/*
11061 * Get pointer to option variable.
11062 */
11063 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011064get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011065{
11066 /* hidden option, always return NULL */
11067 if (p->var == NULL)
11068 return NULL;
11069
11070 switch ((int)p->indir)
11071 {
11072 case PV_NONE: return p->var;
11073
11074 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011075 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011076 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011077 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011078 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011079 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011080 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000011081 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000011082 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011083 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011084 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011085 case PV_TC: return *curbuf->b_p_tc != NUL
11086 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011087 case PV_BKC: return *curbuf->b_p_bkc != NUL
11088 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar375e3392019-01-31 18:26:10 +010011089 case PV_SISO: return curwin->w_p_siso >= 0
11090 ? (char_u *)&(curwin->w_p_siso) : p->var;
11091 case PV_SO: return curwin->w_p_so >= 0
11092 ? (char_u *)&(curwin->w_p_so) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011093#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011094 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011095 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011096 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011097 ? (char_u *)&(curbuf->b_p_inc) : p->var;
11098#endif
11099#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011100 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011101 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011102 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011103 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
11104#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011105 case PV_FP: return *curbuf->b_p_fp != NUL
11106 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011107#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011108 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011109 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011110 case PV_GP: return *curbuf->b_p_gp != NUL
11111 ? (char_u *)&(curbuf->b_p_gp) : p->var;
11112 case PV_MP: return *curbuf->b_p_mp != NUL
11113 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011114#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011115#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11116 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
11117 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
11118#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011119#if defined(FEAT_CRYPT)
11120 case PV_CM: return *curbuf->b_p_cm != NUL
11121 ? (char_u *)&(curbuf->b_p_cm) : p->var;
11122#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011123#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011124 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011125 ? (char_u *)&(curwin->w_p_stl) : p->var;
11126#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011127 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
11128 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011129#ifdef FEAT_LISP
11130 case PV_LW: return *curbuf->b_p_lw != NUL
11131 ? (char_u *)&(curbuf->b_p_lw) : p->var;
11132#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011133 case PV_MENC: return *curbuf->b_p_menc != NUL
11134 ? (char_u *)&(curbuf->b_p_menc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011135#ifdef FEAT_ARABIC
11136 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
11137#endif
11138 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011139#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000011140 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
11141#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011142#ifdef FEAT_SYN_HL
11143 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
11144 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020011145 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011146#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011147#ifdef FEAT_DIFF
11148 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
11149#endif
11150#ifdef FEAT_FOLDING
11151 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
11152 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
11153 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
11154 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
11155 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
11156 case PV_FML: return (char_u *)&(curwin->w_p_fml);
11157 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
11158# ifdef FEAT_EVAL
11159 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
11160 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
11161# endif
11162 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
11163#endif
11164 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020011165 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011166#ifdef FEAT_LINEBREAK
11167 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
11168#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011169 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000011170 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020011171#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011172 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
11173#endif
11174#ifdef FEAT_RIGHTLEFT
11175 case PV_RL: return (char_u *)&(curwin->w_p_rl);
11176 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
11177#endif
11178 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
11179 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
11180#ifdef FEAT_LINEBREAK
11181 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020011182 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
11183 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011184#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011185 case PV_WCR: return (char_u *)&(curwin->w_p_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011186 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011187 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011188#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011189 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
11190 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
11191#endif
11192#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011193 case PV_TWK: return (char_u *)&(curwin->w_p_twk);
11194 case PV_TWS: return (char_u *)&(curwin->w_p_tws);
11195 case PV_TWSL: return (char_u *)&(curbuf->b_p_twsl);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011196#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011197
11198 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
11199 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011200 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011201 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
11202 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011203 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
11204 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
11205#ifdef FEAT_CINDENT
11206 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
11207 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
11208 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
11209#endif
11210#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11211 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
11212#endif
11213#ifdef FEAT_COMMENTS
11214 case PV_COM: return (char_u *)&(curbuf->b_p_com);
11215#endif
11216#ifdef FEAT_FOLDING
11217 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
11218#endif
11219#ifdef FEAT_INS_EXPAND
11220 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
Bram Moolenaarac3150d2019-07-28 16:36:39 +020011221# ifdef BACKSLASH_IN_FILENAME
11222 case PV_CSL: return (char_u *)&(curbuf->b_p_csl);
11223# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011224#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011225#ifdef FEAT_COMPL_FUNC
11226 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011227 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011228#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +020011229#ifdef FEAT_EVAL
11230 case PV_TFU: return (char_u *)&(curbuf->b_p_tfu);
11231#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011232 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020011233 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011234 case PV_ET: return (char_u *)&(curbuf->b_p_et);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011235 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011236 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011237 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011238 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011239 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011240 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
11241 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
11242 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
11243 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
11244#ifdef FEAT_FIND_ID
11245# ifdef FEAT_EVAL
11246 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
11247# endif
11248#endif
11249#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11250 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
11251 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
11252#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011253#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011254 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
11255#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011256#ifdef FEAT_CRYPT
11257 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
11258#endif
11259#ifdef FEAT_LISP
11260 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
11261#endif
11262 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
11263 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
11264 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
11265 case PV_MOD: return (char_u *)&(curbuf->b_changed);
11266 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011267 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011268#ifdef FEAT_TEXTOBJ
11269 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
11270#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011271 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
11272#ifdef FEAT_SMARTINDENT
11273 case PV_SI: return (char_u *)&(curbuf->b_p_si);
11274#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011275 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011276 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
11277#ifdef FEAT_SEARCHPATH
11278 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
11279#endif
11280 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
11281#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011282 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011283 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
11284#endif
11285#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020011286 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
11287 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
11288 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011289#endif
11290 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
11291 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
11292 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
11293 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011294#ifdef FEAT_PERSISTENT_UNDO
11295 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
11296#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011297 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
11298#ifdef FEAT_KEYMAP
11299 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
11300#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011301#ifdef FEAT_SIGNS
11302 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
11303#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011304#ifdef FEAT_VARTABS
11305 case PV_VSTS: return (char_u *)&(curbuf->b_p_vsts);
11306 case PV_VTS: return (char_u *)&(curbuf->b_p_vts);
11307#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010011308 default: iemsg(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011309 }
11310 /* always return a valid pointer to avoid a crash! */
11311 return (char_u *)&(curbuf->b_p_wm);
11312}
11313
11314/*
11315 * Get the value of 'equalprg', either the buffer-local one or the global one.
11316 */
11317 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011318get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011319{
11320 if (*curbuf->b_p_ep == NUL)
11321 return p_ep;
11322 return curbuf->b_p_ep;
11323}
11324
Bram Moolenaar071d4272004-06-13 20:20:40 +000011325/*
11326 * Copy options from one window to another.
11327 * Used when splitting a window.
11328 */
11329 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011330win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011331{
11332 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
11333 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020011334#if defined(FEAT_LINEBREAK)
11335 briopt_check(wp_to);
11336#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011337}
Bram Moolenaar071d4272004-06-13 20:20:40 +000011338
11339/*
11340 * Copy the options from one winopt_T to another.
11341 * Doesn't free the old option values in "to", use clear_winopt() for that.
11342 * The 'scroll' option is not copied, because it depends on the window height.
11343 * The 'previewwindow' option is reset, there can be only one preview window.
11344 */
11345 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011346copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011347{
11348#ifdef FEAT_ARABIC
11349 to->wo_arab = from->wo_arab;
11350#endif
11351 to->wo_list = from->wo_list;
11352 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020011353 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011354#ifdef FEAT_LINEBREAK
11355 to->wo_nuw = from->wo_nuw;
11356#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011357#ifdef FEAT_RIGHTLEFT
11358 to->wo_rl = from->wo_rl;
11359 to->wo_rlc = vim_strsave(from->wo_rlc);
11360#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011361#ifdef FEAT_STL_OPT
11362 to->wo_stl = vim_strsave(from->wo_stl);
11363#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011364 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011365#ifdef FEAT_DIFF
11366 to->wo_wrap_save = from->wo_wrap_save;
11367#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011368#ifdef FEAT_LINEBREAK
11369 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020011370 to->wo_bri = from->wo_bri;
11371 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011372#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011373 to->wo_wcr = vim_strsave(from->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011374 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011375 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010011376 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011377 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011378#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000011379 to->wo_spell = from->wo_spell;
11380#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011381#ifdef FEAT_SYN_HL
11382 to->wo_cuc = from->wo_cuc;
11383 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020011384 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011385#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011386#ifdef FEAT_DIFF
11387 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011388 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011389#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011390#ifdef FEAT_CONCEAL
11391 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020011392 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011393#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011394#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011395 to->wo_twk = vim_strsave(from->wo_twk);
11396 to->wo_tws = vim_strsave(from->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011397#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011398#ifdef FEAT_FOLDING
11399 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011400 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011401 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011402 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011403 to->wo_fdi = vim_strsave(from->wo_fdi);
11404 to->wo_fml = from->wo_fml;
11405 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011406 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011407 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011408 to->wo_fdm_save = from->wo_diff_saved
11409 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011410 to->wo_fdn = from->wo_fdn;
11411# ifdef FEAT_EVAL
11412 to->wo_fde = vim_strsave(from->wo_fde);
11413 to->wo_fdt = vim_strsave(from->wo_fdt);
11414# endif
11415 to->wo_fmr = vim_strsave(from->wo_fmr);
11416#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011417#ifdef FEAT_SIGNS
11418 to->wo_scl = vim_strsave(from->wo_scl);
11419#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011420 check_winopt(to); /* don't want NULL pointers */
11421}
11422
11423/*
11424 * Check string options in a window for a NULL value.
11425 */
11426 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011427check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011428{
11429 check_winopt(&win->w_onebuf_opt);
11430 check_winopt(&win->w_allbuf_opt);
11431}
11432
11433/*
11434 * Check for NULL pointers in a winopt_T and replace them with empty_option.
11435 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020011436 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011437check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011438{
11439#ifdef FEAT_FOLDING
11440 check_string_option(&wop->wo_fdi);
11441 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011442 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011443# ifdef FEAT_EVAL
11444 check_string_option(&wop->wo_fde);
11445 check_string_option(&wop->wo_fdt);
11446# endif
11447 check_string_option(&wop->wo_fmr);
11448#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011449#ifdef FEAT_SIGNS
11450 check_string_option(&wop->wo_scl);
11451#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011452#ifdef FEAT_RIGHTLEFT
11453 check_string_option(&wop->wo_rlc);
11454#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011455#ifdef FEAT_STL_OPT
11456 check_string_option(&wop->wo_stl);
11457#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011458#ifdef FEAT_SYN_HL
11459 check_string_option(&wop->wo_cc);
11460#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011461#ifdef FEAT_CONCEAL
11462 check_string_option(&wop->wo_cocu);
11463#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011464#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011465 check_string_option(&wop->wo_twk);
11466 check_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011467#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011468#ifdef FEAT_LINEBREAK
11469 check_string_option(&wop->wo_briopt);
11470#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011471 check_string_option(&wop->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011472}
11473
11474/*
11475 * Free the allocated memory inside a winopt_T.
11476 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011477 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011478clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011479{
11480#ifdef FEAT_FOLDING
11481 clear_string_option(&wop->wo_fdi);
11482 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011483 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011484# ifdef FEAT_EVAL
11485 clear_string_option(&wop->wo_fde);
11486 clear_string_option(&wop->wo_fdt);
11487# endif
11488 clear_string_option(&wop->wo_fmr);
11489#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011490#ifdef FEAT_SIGNS
11491 clear_string_option(&wop->wo_scl);
11492#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011493#ifdef FEAT_LINEBREAK
11494 clear_string_option(&wop->wo_briopt);
11495#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011496 clear_string_option(&wop->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011497#ifdef FEAT_RIGHTLEFT
11498 clear_string_option(&wop->wo_rlc);
11499#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011500#ifdef FEAT_STL_OPT
11501 clear_string_option(&wop->wo_stl);
11502#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011503#ifdef FEAT_SYN_HL
11504 clear_string_option(&wop->wo_cc);
11505#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011506#ifdef FEAT_CONCEAL
11507 clear_string_option(&wop->wo_cocu);
11508#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011509#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011510 clear_string_option(&wop->wo_twk);
11511 clear_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011512#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011513}
11514
11515/*
11516 * Copy global option values to local options for one buffer.
11517 * Used when creating a new buffer and sometimes when entering a buffer.
11518 * flags:
11519 * BCO_ENTER We will enter the buf buffer.
11520 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11521 * appropriate.
11522 * BCO_NOHELP Don't copy the values to a help buffer.
11523 */
11524 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011525buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011526{
11527 int should_copy = TRUE;
11528 char_u *save_p_isk = NULL; /* init for GCC */
11529 int dont_do_help;
11530 int did_isk = FALSE;
11531
11532 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011533 * Skip this when the option defaults have not been set yet. Happens when
11534 * main() allocates the first buffer.
11535 */
11536 if (p_cpo != NULL)
11537 {
11538 /*
11539 * Always copy when entering and 'cpo' contains 'S'.
11540 * Don't copy when already initialized.
11541 * Don't copy when 'cpo' contains 's' and not entering.
11542 * 'S' BCO_ENTER initialized 's' should_copy
11543 * yes yes X X TRUE
11544 * yes no yes X FALSE
11545 * no X yes X FALSE
11546 * X no no yes FALSE
11547 * X no no no TRUE
11548 * no yes no X TRUE
11549 */
11550 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11551 && (buf->b_p_initialized
11552 || (!(flags & BCO_ENTER)
11553 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11554 should_copy = FALSE;
11555
11556 if (should_copy || (flags & BCO_ALWAYS))
11557 {
11558 /* Don't copy the options specific to a help buffer when
11559 * BCO_NOHELP is given or the options were initialized already
11560 * (jumping back to a help file with CTRL-T or CTRL-O) */
11561 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11562 || buf->b_p_initialized;
11563 if (dont_do_help) /* don't free b_p_isk */
11564 {
11565 save_p_isk = buf->b_p_isk;
11566 buf->b_p_isk = NULL;
11567 }
11568 /*
Bram Moolenaar40385db2018-08-07 22:31:44 +020011569 * Always free the allocated strings. If not already initialized,
11570 * reset 'readonly' and copy 'fileformat'.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011571 */
11572 if (!buf->b_p_initialized)
11573 {
11574 free_buf_options(buf, TRUE);
11575 buf->b_p_ro = FALSE; /* don't copy readonly */
11576 buf->b_p_tx = p_tx;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011577 buf->b_p_fenc = vim_strsave(p_fenc);
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011578 switch (*p_ffs)
11579 {
11580 case 'm':
11581 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11582 case 'd':
11583 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11584 case 'u':
11585 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11586 default:
11587 buf->b_p_ff = vim_strsave(p_ff);
11588 }
11589 if (buf->b_p_ff != NULL)
11590 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011591 buf->b_p_bh = empty_option;
11592 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011593 }
11594 else
11595 free_buf_options(buf, FALSE);
11596
11597 buf->b_p_ai = p_ai;
11598 buf->b_p_ai_nopaste = p_ai_nopaste;
11599 buf->b_p_sw = p_sw;
11600 buf->b_p_tw = p_tw;
11601 buf->b_p_tw_nopaste = p_tw_nopaste;
11602 buf->b_p_tw_nobin = p_tw_nobin;
11603 buf->b_p_wm = p_wm;
11604 buf->b_p_wm_nopaste = p_wm_nopaste;
11605 buf->b_p_wm_nobin = p_wm_nobin;
11606 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011607 buf->b_p_bomb = p_bomb;
Bram Moolenaarb388be02015-07-22 22:19:38 +020011608 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011609 buf->b_p_et = p_et;
11610 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011611 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011612 buf->b_p_ml = p_ml;
11613 buf->b_p_ml_nobin = p_ml_nobin;
11614 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011615 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011616#ifdef FEAT_INS_EXPAND
11617 buf->b_p_cpt = vim_strsave(p_cpt);
Bram Moolenaarac3150d2019-07-28 16:36:39 +020011618# ifdef BACKSLASH_IN_FILENAME
11619 buf->b_p_csl = vim_strsave(p_csl);
11620# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011621#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011622#ifdef FEAT_COMPL_FUNC
11623 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011624 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011625#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +020011626#ifdef FEAT_EVAL
11627 buf->b_p_tfu = vim_strsave(p_tfu);
11628#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011629 buf->b_p_sts = p_sts;
11630 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011631#ifdef FEAT_VARTABS
11632 buf->b_p_vsts = vim_strsave(p_vsts);
11633 if (p_vsts && p_vsts != empty_option)
11634 tabstop_set(p_vsts, &buf->b_p_vsts_array);
11635 else
11636 buf->b_p_vsts_array = 0;
11637 buf->b_p_vsts_nopaste = p_vsts_nopaste
11638 ? vim_strsave(p_vsts_nopaste) : NULL;
11639#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011640 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011641#ifdef FEAT_COMMENTS
11642 buf->b_p_com = vim_strsave(p_com);
11643#endif
11644#ifdef FEAT_FOLDING
11645 buf->b_p_cms = vim_strsave(p_cms);
11646#endif
11647 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011648 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011649 buf->b_p_nf = vim_strsave(p_nf);
11650 buf->b_p_mps = vim_strsave(p_mps);
11651#ifdef FEAT_SMARTINDENT
11652 buf->b_p_si = p_si;
11653#endif
11654 buf->b_p_ci = p_ci;
11655#ifdef FEAT_CINDENT
11656 buf->b_p_cin = p_cin;
11657 buf->b_p_cink = vim_strsave(p_cink);
11658 buf->b_p_cino = vim_strsave(p_cino);
11659#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011660 /* Don't copy 'filetype', it must be detected */
11661 buf->b_p_ft = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011662 buf->b_p_pi = p_pi;
11663#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11664 buf->b_p_cinw = vim_strsave(p_cinw);
11665#endif
11666#ifdef FEAT_LISP
11667 buf->b_p_lisp = p_lisp;
11668#endif
11669#ifdef FEAT_SYN_HL
11670 /* Don't copy 'syntax', it must be set */
11671 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011672 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011673 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011674#endif
11675#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011676 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011677 (void)compile_cap_prog(&buf->b_s);
11678 buf->b_s.b_p_spf = vim_strsave(p_spf);
11679 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011680#endif
11681#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11682 buf->b_p_inde = vim_strsave(p_inde);
11683 buf->b_p_indk = vim_strsave(p_indk);
11684#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011685 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011686#if defined(FEAT_EVAL)
11687 buf->b_p_fex = vim_strsave(p_fex);
11688#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011689#ifdef FEAT_CRYPT
11690 buf->b_p_key = vim_strsave(p_key);
11691#endif
11692#ifdef FEAT_SEARCHPATH
11693 buf->b_p_sua = vim_strsave(p_sua);
11694#endif
11695#ifdef FEAT_KEYMAP
11696 buf->b_p_keymap = vim_strsave(p_keymap);
11697 buf->b_kmap_state |= KEYMAP_INIT;
11698#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011699#ifdef FEAT_TERMINAL
11700 buf->b_p_twsl = p_twsl;
11701#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011702 /* This isn't really an option, but copying the langmap and IME
11703 * state from the current buffer is better than resetting it. */
11704 buf->b_p_iminsert = p_iminsert;
11705 buf->b_p_imsearch = p_imsearch;
11706
11707 /* options that are normally global but also have a local value
11708 * are not copied, start using the global value */
11709 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011710 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011711 buf->b_p_bkc = empty_option;
11712 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011713#ifdef FEAT_QUICKFIX
11714 buf->b_p_gp = empty_option;
11715 buf->b_p_mp = empty_option;
11716 buf->b_p_efm = empty_option;
11717#endif
11718 buf->b_p_ep = empty_option;
11719 buf->b_p_kp = empty_option;
11720 buf->b_p_path = empty_option;
11721 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011722 buf->b_p_tc = empty_option;
11723 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011724#ifdef FEAT_FIND_ID
11725 buf->b_p_def = empty_option;
11726 buf->b_p_inc = empty_option;
11727# ifdef FEAT_EVAL
11728 buf->b_p_inex = vim_strsave(p_inex);
11729# endif
11730#endif
11731#ifdef FEAT_INS_EXPAND
11732 buf->b_p_dict = empty_option;
11733 buf->b_p_tsr = empty_option;
11734#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011735#ifdef FEAT_TEXTOBJ
11736 buf->b_p_qe = vim_strsave(p_qe);
11737#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011738#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11739 buf->b_p_bexpr = empty_option;
11740#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011741#if defined(FEAT_CRYPT)
11742 buf->b_p_cm = empty_option;
11743#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011744#ifdef FEAT_PERSISTENT_UNDO
11745 buf->b_p_udf = p_udf;
11746#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011747#ifdef FEAT_LISP
11748 buf->b_p_lw = empty_option;
11749#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011750 buf->b_p_menc = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011751
11752 /*
11753 * Don't copy the options set by ex_help(), use the saved values,
11754 * when going from a help buffer to a non-help buffer.
11755 * Don't touch these at all when BCO_NOHELP is used and going from
11756 * or to a help buffer.
11757 */
11758 if (dont_do_help)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011759 {
Bram Moolenaar071d4272004-06-13 20:20:40 +000011760 buf->b_p_isk = save_p_isk;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011761#ifdef FEAT_VARTABS
11762 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11763 tabstop_set(p_vts, &buf->b_p_vts_array);
11764 else
11765 buf->b_p_vts_array = NULL;
11766#endif
11767 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011768 else
11769 {
11770 buf->b_p_isk = vim_strsave(p_isk);
11771 did_isk = TRUE;
11772 buf->b_p_ts = p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011773#ifdef FEAT_VARTABS
11774 buf->b_p_vts = vim_strsave(p_vts);
11775 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11776 tabstop_set(p_vts, &buf->b_p_vts_array);
11777 else
11778 buf->b_p_vts_array = NULL;
11779#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011780 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011781 if (buf->b_p_bt[0] == 'h')
11782 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011783 buf->b_p_ma = p_ma;
11784 }
11785 }
11786
11787 /*
11788 * When the options should be copied (ignoring BCO_ALWAYS), set the
11789 * flag that indicates that the options have been initialized.
11790 */
11791 if (should_copy)
11792 buf->b_p_initialized = TRUE;
11793 }
11794
11795 check_buf_options(buf); /* make sure we don't have NULLs */
11796 if (did_isk)
11797 (void)buf_init_chartab(buf, FALSE);
11798}
11799
11800/*
11801 * Reset the 'modifiable' option and its default value.
11802 */
11803 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011804reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011805{
11806 int opt_idx;
11807
11808 curbuf->b_p_ma = FALSE;
11809 p_ma = FALSE;
11810 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011811 if (opt_idx >= 0)
11812 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011813}
11814
11815/*
11816 * Set the global value for 'iminsert' to the local value.
11817 */
11818 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011819set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011820{
11821 p_iminsert = curbuf->b_p_iminsert;
11822}
11823
11824/*
11825 * Set the global value for 'imsearch' to the local value.
11826 */
11827 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011828set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011829{
11830 p_imsearch = curbuf->b_p_imsearch;
11831}
11832
11833#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11834static int expand_option_idx = -1;
11835static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11836static int expand_option_flags = 0;
11837
11838 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011839set_context_in_set_cmd(
11840 expand_T *xp,
11841 char_u *arg,
11842 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011843{
11844 int nextchar;
11845 long_u flags = 0; /* init for GCC */
11846 int opt_idx = 0; /* init for GCC */
11847 char_u *p;
11848 char_u *s;
11849 int is_term_option = FALSE;
11850 int key;
11851
11852 expand_option_flags = opt_flags;
11853
11854 xp->xp_context = EXPAND_SETTINGS;
11855 if (*arg == NUL)
11856 {
11857 xp->xp_pattern = arg;
11858 return;
11859 }
11860 p = arg + STRLEN(arg) - 1;
11861 if (*p == ' ' && *(p - 1) != '\\')
11862 {
11863 xp->xp_pattern = p + 1;
11864 return;
11865 }
11866 while (p > arg)
11867 {
11868 s = p;
11869 /* count number of backslashes before ' ' or ',' */
11870 if (*p == ' ' || *p == ',')
11871 {
11872 while (s > arg && *(s - 1) == '\\')
11873 --s;
11874 }
11875 /* break at a space with an even number of backslashes */
11876 if (*p == ' ' && ((p - s) & 1) == 0)
11877 {
11878 ++p;
11879 break;
11880 }
11881 --p;
11882 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011883 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011884 {
11885 xp->xp_context = EXPAND_BOOL_SETTINGS;
11886 p += 2;
11887 }
11888 if (STRNCMP(p, "inv", 3) == 0)
11889 {
11890 xp->xp_context = EXPAND_BOOL_SETTINGS;
11891 p += 3;
11892 }
11893 xp->xp_pattern = arg = p;
11894 if (*arg == '<')
11895 {
11896 while (*p != '>')
11897 if (*p++ == NUL) /* expand terminal option name */
11898 return;
11899 key = get_special_key_code(arg + 1);
11900 if (key == 0) /* unknown name */
11901 {
11902 xp->xp_context = EXPAND_NOTHING;
11903 return;
11904 }
11905 nextchar = *++p;
11906 is_term_option = TRUE;
11907 expand_option_name[2] = KEY2TERMCAP0(key);
11908 expand_option_name[3] = KEY2TERMCAP1(key);
11909 }
11910 else
11911 {
11912 if (p[0] == 't' && p[1] == '_')
11913 {
11914 p += 2;
11915 if (*p != NUL)
11916 ++p;
11917 if (*p == NUL)
11918 return; /* expand option name */
11919 nextchar = *++p;
11920 is_term_option = TRUE;
11921 expand_option_name[2] = p[-2];
11922 expand_option_name[3] = p[-1];
11923 }
11924 else
11925 {
11926 /* Allow * wildcard */
11927 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11928 p++;
11929 if (*p == NUL)
11930 return;
11931 nextchar = *p;
11932 *p = NUL;
11933 opt_idx = findoption(arg);
11934 *p = nextchar;
11935 if (opt_idx == -1 || options[opt_idx].var == NULL)
11936 {
11937 xp->xp_context = EXPAND_NOTHING;
11938 return;
11939 }
11940 flags = options[opt_idx].flags;
11941 if (flags & P_BOOL)
11942 {
11943 xp->xp_context = EXPAND_NOTHING;
11944 return;
11945 }
11946 }
11947 }
11948 /* handle "-=" and "+=" */
11949 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11950 {
11951 ++p;
11952 nextchar = '=';
11953 }
11954 if ((nextchar != '=' && nextchar != ':')
11955 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11956 {
11957 xp->xp_context = EXPAND_UNSUCCESSFUL;
11958 return;
11959 }
11960 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11961 {
11962 xp->xp_context = EXPAND_OLD_SETTING;
11963 if (is_term_option)
11964 expand_option_idx = -1;
11965 else
11966 expand_option_idx = opt_idx;
11967 xp->xp_pattern = p + 1;
11968 return;
11969 }
11970 xp->xp_context = EXPAND_NOTHING;
11971 if (is_term_option || (flags & P_NUM))
11972 return;
11973
11974 xp->xp_pattern = p + 1;
11975
11976 if (flags & P_EXPAND)
11977 {
11978 p = options[opt_idx].var;
11979 if (p == (char_u *)&p_bdir
11980 || p == (char_u *)&p_dir
11981 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011982 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011983 || p == (char_u *)&p_rtp
11984#ifdef FEAT_SEARCHPATH
11985 || p == (char_u *)&p_cdpath
11986#endif
11987#ifdef FEAT_SESSION
11988 || p == (char_u *)&p_vdir
11989#endif
11990 )
11991 {
11992 xp->xp_context = EXPAND_DIRECTORIES;
11993 if (p == (char_u *)&p_path
11994#ifdef FEAT_SEARCHPATH
11995 || p == (char_u *)&p_cdpath
11996#endif
11997 )
11998 xp->xp_backslash = XP_BS_THREE;
11999 else
12000 xp->xp_backslash = XP_BS_ONE;
12001 }
12002 else
12003 {
12004 xp->xp_context = EXPAND_FILES;
12005 /* for 'tags' need three backslashes for a space */
12006 if (p == (char_u *)&p_tags)
12007 xp->xp_backslash = XP_BS_THREE;
12008 else
12009 xp->xp_backslash = XP_BS_ONE;
12010 }
12011 }
12012
12013 /* For an option that is a list of file names, find the start of the
12014 * last file name. */
12015 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
12016 {
12017 /* count number of backslashes before ' ' or ',' */
12018 if (*p == ' ' || *p == ',')
12019 {
12020 s = p;
12021 while (s > xp->xp_pattern && *(s - 1) == '\\')
12022 --s;
12023 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
12024 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
12025 {
12026 xp->xp_pattern = p + 1;
12027 break;
12028 }
12029 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000012030
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000012031#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000012032 /* for 'spellsuggest' start at "file:" */
12033 if (options[opt_idx].var == (char_u *)&p_sps
12034 && STRNCMP(p, "file:", 5) == 0)
12035 {
12036 xp->xp_pattern = p + 5;
12037 break;
12038 }
12039#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012040 }
12041
12042 return;
12043}
12044
12045 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012046ExpandSettings(
12047 expand_T *xp,
12048 regmatch_T *regmatch,
12049 int *num_file,
12050 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012051{
12052 int num_normal = 0; /* Nr of matching non-term-code settings */
12053 int num_term = 0; /* Nr of matching terminal code settings */
12054 int opt_idx;
12055 int match;
12056 int count = 0;
12057 char_u *str;
12058 int loop;
12059 int is_term_opt;
12060 char_u name_buf[MAX_KEY_NAME_LEN];
12061 static char *(names[]) = {"all", "termcap"};
12062 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
12063
12064 /* do this loop twice:
12065 * loop == 0: count the number of matching options
12066 * loop == 1: copy the matching options into allocated memory
12067 */
12068 for (loop = 0; loop <= 1; ++loop)
12069 {
12070 regmatch->rm_ic = ic;
12071 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
12072 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000012073 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
12074 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012075 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
12076 {
12077 if (loop == 0)
12078 num_normal++;
12079 else
12080 (*file)[count++] = vim_strsave((char_u *)names[match]);
12081 }
12082 }
12083 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
12084 opt_idx++)
12085 {
12086 if (options[opt_idx].var == NULL)
12087 continue;
12088 if (xp->xp_context == EXPAND_BOOL_SETTINGS
12089 && !(options[opt_idx].flags & P_BOOL))
12090 continue;
12091 is_term_opt = istermoption(&options[opt_idx]);
12092 if (is_term_opt && num_normal > 0)
12093 continue;
12094 match = FALSE;
12095 if (vim_regexec(regmatch, str, (colnr_T)0)
12096 || (options[opt_idx].shortname != NULL
12097 && vim_regexec(regmatch,
12098 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
12099 match = TRUE;
12100 else if (is_term_opt)
12101 {
12102 name_buf[0] = '<';
12103 name_buf[1] = 't';
12104 name_buf[2] = '_';
12105 name_buf[3] = str[2];
12106 name_buf[4] = str[3];
12107 name_buf[5] = '>';
12108 name_buf[6] = NUL;
12109 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12110 {
12111 match = TRUE;
12112 str = name_buf;
12113 }
12114 }
12115 if (match)
12116 {
12117 if (loop == 0)
12118 {
12119 if (is_term_opt)
12120 num_term++;
12121 else
12122 num_normal++;
12123 }
12124 else
12125 (*file)[count++] = vim_strsave(str);
12126 }
12127 }
12128 /*
12129 * Check terminal key codes, these are not in the option table
12130 */
12131 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
12132 {
12133 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
12134 {
12135 if (!isprint(str[0]) || !isprint(str[1]))
12136 continue;
12137
12138 name_buf[0] = 't';
12139 name_buf[1] = '_';
12140 name_buf[2] = str[0];
12141 name_buf[3] = str[1];
12142 name_buf[4] = NUL;
12143
12144 match = FALSE;
12145 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12146 match = TRUE;
12147 else
12148 {
12149 name_buf[0] = '<';
12150 name_buf[1] = 't';
12151 name_buf[2] = '_';
12152 name_buf[3] = str[0];
12153 name_buf[4] = str[1];
12154 name_buf[5] = '>';
12155 name_buf[6] = NUL;
12156
12157 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12158 match = TRUE;
12159 }
12160 if (match)
12161 {
12162 if (loop == 0)
12163 num_term++;
12164 else
12165 (*file)[count++] = vim_strsave(name_buf);
12166 }
12167 }
12168
12169 /*
12170 * Check special key names.
12171 */
12172 regmatch->rm_ic = TRUE; /* ignore case here */
12173 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
12174 {
12175 name_buf[0] = '<';
12176 STRCPY(name_buf + 1, str);
12177 STRCAT(name_buf, ">");
12178
12179 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12180 {
12181 if (loop == 0)
12182 num_term++;
12183 else
12184 (*file)[count++] = vim_strsave(name_buf);
12185 }
12186 }
12187 }
12188 if (loop == 0)
12189 {
12190 if (num_normal > 0)
12191 *num_file = num_normal;
12192 else if (num_term > 0)
12193 *num_file = num_term;
12194 else
12195 return OK;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020012196 *file = ALLOC_MULT(char_u *, *num_file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012197 if (*file == NULL)
12198 {
12199 *file = (char_u **)"";
12200 return FAIL;
12201 }
12202 }
12203 }
12204 return OK;
12205}
12206
12207 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012208ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012209{
12210 char_u *var = NULL; /* init for GCC */
12211 char_u *buf;
12212
12213 *num_file = 0;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020012214 *file = ALLOC_ONE(char_u *);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012215 if (*file == NULL)
12216 return FAIL;
12217
12218 /*
12219 * For a terminal key code expand_option_idx is < 0.
12220 */
12221 if (expand_option_idx < 0)
12222 {
12223 var = find_termcode(expand_option_name + 2);
12224 if (var == NULL)
12225 expand_option_idx = findoption(expand_option_name);
12226 }
12227
12228 if (expand_option_idx >= 0)
12229 {
12230 /* put string of option value in NameBuff */
12231 option_value2string(&options[expand_option_idx], expand_option_flags);
12232 var = NameBuff;
12233 }
12234 else if (var == NULL)
12235 var = (char_u *)"";
12236
12237 /* A backslash is required before some characters. This is the reverse of
12238 * what happens in do_set(). */
12239 buf = vim_strsave_escaped(var, escape_chars);
12240
12241 if (buf == NULL)
12242 {
Bram Moolenaard23a8232018-02-10 18:45:26 +010012243 VIM_CLEAR(*file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012244 return FAIL;
12245 }
12246
12247#ifdef BACKSLASH_IN_FILENAME
12248 /* For MS-Windows et al. we don't double backslashes at the start and
12249 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012250 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012251 if (var[0] == '\\' && var[1] == '\\'
12252 && expand_option_idx >= 0
12253 && (options[expand_option_idx].flags & P_EXPAND)
12254 && vim_isfilec(var[2])
12255 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000012256 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012257#endif
12258
12259 *file[0] = buf;
12260 *num_file = 1;
12261 return OK;
12262}
12263#endif
12264
12265/*
12266 * Get the value for the numeric or string option *opp in a nice format into
12267 * NameBuff[]. Must not be called with a hidden option!
12268 */
12269 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012270option_value2string(
12271 struct vimoption *opp,
12272 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012273{
12274 char_u *varp;
12275
12276 varp = get_varp_scope(opp, opt_flags);
12277
12278 if (opp->flags & P_NUM)
12279 {
12280 long wc = 0;
12281
12282 if (wc_use_keyname(varp, &wc))
12283 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
12284 else if (wc != 0)
12285 STRCPY(NameBuff, transchar((int)wc));
12286 else
12287 sprintf((char *)NameBuff, "%ld", *(long *)varp);
12288 }
12289 else /* P_STRING */
12290 {
12291 varp = *(char_u **)(varp);
12292 if (varp == NULL) /* just in case */
12293 NameBuff[0] = NUL;
12294#ifdef FEAT_CRYPT
12295 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000012296 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012297 STRCPY(NameBuff, "*****");
12298#endif
12299 else if (opp->flags & P_EXPAND)
12300 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
12301 /* Translate 'pastetoggle' into special key names */
12302 else if ((char_u **)opp->var == &p_pt)
12303 str2specialbuf(p_pt, NameBuff, MAXPATHL);
12304 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000012305 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012306 }
12307}
12308
12309/*
12310 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
12311 * printed as a keyname.
12312 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
12313 */
12314 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012315wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012316{
12317 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
12318 {
12319 *wcp = *(long *)varp;
12320 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
12321 return TRUE;
12322 }
12323 return FALSE;
12324}
12325
Bram Moolenaar01615492015-02-03 13:00:38 +010012326#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012327/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012328 * Any character has an equivalent 'langmap' character. This is used for
12329 * keyboards that have a special language mode that sends characters above
12330 * 128 (although other characters can be translated too). The "to" field is a
12331 * Vim command character. This avoids having to switch the keyboard back to
12332 * ASCII mode when leaving Insert mode.
12333 *
12334 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
12335 * commands.
Bram Moolenaarfc3abf42019-01-24 15:54:21 +010012336 * langmap_mapga.ga_data is a sorted table of langmap_entry_T. This does the
12337 * same as langmap_mapchar[] for characters >= 256.
12338 *
12339 * Use growarray for 'langmap' chars >= 256
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012340 */
12341typedef struct
12342{
12343 int from;
12344 int to;
12345} langmap_entry_T;
12346
12347static garray_T langmap_mapga;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012348
12349/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012350 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
12351 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012352 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012353 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012354langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012355{
12356 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020012357 int a = 0;
12358 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012359
12360 /* Do a binary search for an existing entry. */
12361 while (a != b)
12362 {
12363 int i = (a + b) / 2;
12364 int d = entries[i].from - from;
12365
12366 if (d == 0)
12367 {
12368 entries[i].to = to;
12369 return;
12370 }
12371 if (d < 0)
12372 a = i + 1;
12373 else
12374 b = i;
12375 }
12376
12377 if (ga_grow(&langmap_mapga, 1) != OK)
12378 return; /* out of memory */
12379
12380 /* insert new entry at position "a" */
12381 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
12382 mch_memmove(entries + 1, entries,
12383 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
12384 ++langmap_mapga.ga_len;
12385 entries[0].from = from;
12386 entries[0].to = to;
12387}
12388
12389/*
12390 * Apply 'langmap' to multi-byte character "c" and return the result.
12391 */
12392 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012393langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012394{
12395 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
12396 int a = 0;
12397 int b = langmap_mapga.ga_len;
12398
12399 while (a != b)
12400 {
12401 int i = (a + b) / 2;
12402 int d = entries[i].from - c;
12403
12404 if (d == 0)
12405 return entries[i].to; /* found matching entry */
12406 if (d < 0)
12407 a = i + 1;
12408 else
12409 b = i;
12410 }
12411 return c; /* no entry found, return "c" unmodified */
12412}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012413
12414 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012415langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012416{
12417 int i;
12418
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012419 for (i = 0; i < 256; i++)
12420 langmap_mapchar[i] = i; /* we init with a one-to-one map */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012421 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012422}
12423
12424/*
12425 * Called when langmap option is set; the language map can be
12426 * changed at any time!
12427 */
12428 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012429langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012430{
12431 char_u *p;
12432 char_u *p2;
12433 int from, to;
12434
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012435 ga_clear(&langmap_mapga); /* clear the previous map first */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012436 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012437
12438 for (p = p_langmap; p[0] != NUL; )
12439 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000012440 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012441 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012442 {
12443 if (p2[0] == '\\' && p2[1] != NUL)
12444 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012445 }
12446 if (p2[0] == ';')
12447 ++p2; /* abcd;ABCD form, p2 points to A */
12448 else
12449 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
12450 while (p[0])
12451 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012452 if (p[0] == ',')
12453 {
12454 ++p;
12455 break;
12456 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012457 if (p[0] == '\\' && p[1] != NUL)
12458 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012459 from = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012460 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012461 if (p2 == NULL)
12462 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012463 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012464 if (p[0] != ',')
12465 {
12466 if (p[0] == '\\')
12467 ++p;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012468 to = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012469 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012470 }
12471 else
12472 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012473 if (p2[0] != ',')
12474 {
12475 if (p2[0] == '\\')
12476 ++p2;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012477 to = (*mb_ptr2char)(p2);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012478 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012479 }
12480 if (to == NUL)
12481 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012482 semsg(_("E357: 'langmap': Matching character missing for %s"),
Bram Moolenaar071d4272004-06-13 20:20:40 +000012483 transchar(from));
12484 return;
12485 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012486
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012487 if (from >= 256)
12488 langmap_set_entry(from, to);
12489 else
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012490 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012491
12492 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012493 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012494 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012495 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012496 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012497 if (*p == ';')
12498 {
12499 p = p2;
12500 if (p[0] != NUL)
12501 {
12502 if (p[0] != ',')
12503 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012504 semsg(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012505 return;
12506 }
12507 ++p;
12508 }
12509 break;
12510 }
12511 }
12512 }
12513 }
12514}
12515#endif
12516
12517/*
12518 * Return TRUE if format option 'x' is in effect.
12519 * Take care of no formatting when 'paste' is set.
12520 */
12521 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012522has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012523{
12524 if (p_paste)
12525 return FALSE;
12526 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12527}
12528
12529/*
12530 * Return TRUE if "x" is present in 'shortmess' option, or
12531 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12532 */
12533 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012534shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012535{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012536 return p_shm != NULL &&
12537 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012538 || (vim_strchr(p_shm, 'a') != NULL
12539 && vim_strchr((char_u *)SHM_A, x) != NULL));
12540}
12541
12542/*
12543 * paste_option_changed() - Called after p_paste was set or reset.
12544 */
12545 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012546paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012547{
12548 static int old_p_paste = FALSE;
12549 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012550 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012551#ifdef FEAT_CMDL_INFO
12552 static int save_ru = 0;
12553#endif
12554#ifdef FEAT_RIGHTLEFT
12555 static int save_ri = 0;
12556 static int save_hkmap = 0;
12557#endif
12558 buf_T *buf;
12559
12560 if (p_paste)
12561 {
12562 /*
12563 * Paste switched from off to on.
12564 * Save the current values, so they can be restored later.
12565 */
12566 if (!old_p_paste)
12567 {
12568 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012569 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012570 {
12571 buf->b_p_tw_nopaste = buf->b_p_tw;
12572 buf->b_p_wm_nopaste = buf->b_p_wm;
12573 buf->b_p_sts_nopaste = buf->b_p_sts;
12574 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012575 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012576#ifdef FEAT_VARTABS
12577 if (buf->b_p_vsts_nopaste)
12578 vim_free(buf->b_p_vsts_nopaste);
12579 buf->b_p_vsts_nopaste = buf->b_p_vsts && buf->b_p_vsts != empty_option
12580 ? vim_strsave(buf->b_p_vsts) : NULL;
12581#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012582 }
12583
12584 /* save global options */
12585 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012586 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012587#ifdef FEAT_CMDL_INFO
12588 save_ru = p_ru;
12589#endif
12590#ifdef FEAT_RIGHTLEFT
12591 save_ri = p_ri;
12592 save_hkmap = p_hkmap;
12593#endif
12594 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012595 p_ai_nopaste = p_ai;
12596 p_et_nopaste = p_et;
12597 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012598 p_tw_nopaste = p_tw;
12599 p_wm_nopaste = p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012600#ifdef FEAT_VARTABS
12601 if (p_vsts_nopaste)
12602 vim_free(p_vsts_nopaste);
12603 p_vsts_nopaste = p_vsts && p_vsts != empty_option ? vim_strsave(p_vsts) : NULL;
12604#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012605 }
12606
12607 /*
12608 * Always set the option values, also when 'paste' is set when it is
12609 * already on.
12610 */
12611 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012612 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012613 {
12614 buf->b_p_tw = 0; /* textwidth is 0 */
12615 buf->b_p_wm = 0; /* wrapmargin is 0 */
12616 buf->b_p_sts = 0; /* softtabstop is 0 */
12617 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012618 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012619#ifdef FEAT_VARTABS
12620 if (buf->b_p_vsts)
12621 free_string_option(buf->b_p_vsts);
12622 buf->b_p_vsts = empty_option;
12623 if (buf->b_p_vsts_array)
12624 vim_free(buf->b_p_vsts_array);
12625 buf->b_p_vsts_array = 0;
12626#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012627 }
12628
12629 /* set global options */
12630 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012631 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012632#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012633 if (p_ru)
12634 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012635 p_ru = 0; /* no ruler */
12636#endif
12637#ifdef FEAT_RIGHTLEFT
12638 p_ri = 0; /* no reverse insert */
12639 p_hkmap = 0; /* no Hebrew keyboard */
12640#endif
12641 /* set global values for local buffer options */
12642 p_tw = 0;
12643 p_wm = 0;
12644 p_sts = 0;
12645 p_ai = 0;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012646#ifdef FEAT_VARTABS
12647 if (p_vsts)
12648 free_string_option(p_vsts);
12649 p_vsts = empty_option;
12650#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012651 }
12652
12653 /*
12654 * Paste switched from on to off: Restore saved values.
12655 */
12656 else if (old_p_paste)
12657 {
12658 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012659 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012660 {
12661 buf->b_p_tw = buf->b_p_tw_nopaste;
12662 buf->b_p_wm = buf->b_p_wm_nopaste;
12663 buf->b_p_sts = buf->b_p_sts_nopaste;
12664 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012665 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012666#ifdef FEAT_VARTABS
12667 if (buf->b_p_vsts)
12668 free_string_option(buf->b_p_vsts);
12669 buf->b_p_vsts = buf->b_p_vsts_nopaste
12670 ? vim_strsave(buf->b_p_vsts_nopaste) : empty_option;
12671 if (buf->b_p_vsts_array)
12672 vim_free(buf->b_p_vsts_array);
12673 if (buf->b_p_vsts && buf->b_p_vsts != empty_option)
12674 tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array);
12675 else
12676 buf->b_p_vsts_array = 0;
12677#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012678 }
12679
12680 /* restore global options */
12681 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012682 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012683#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012684 if (p_ru != save_ru)
12685 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012686 p_ru = save_ru;
12687#endif
12688#ifdef FEAT_RIGHTLEFT
12689 p_ri = save_ri;
12690 p_hkmap = save_hkmap;
12691#endif
12692 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012693 p_ai = p_ai_nopaste;
12694 p_et = p_et_nopaste;
12695 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012696 p_tw = p_tw_nopaste;
12697 p_wm = p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012698#ifdef FEAT_VARTABS
12699 if (p_vsts)
12700 free_string_option(p_vsts);
12701 p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option;
12702#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012703 }
12704
12705 old_p_paste = p_paste;
12706}
12707
12708/*
12709 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12710 *
12711 * Reset 'compatible' and set the values for options that didn't get set yet
12712 * to the Vim defaults.
12713 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012714 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012715 */
12716 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012717vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012718{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012719 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012720 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012721 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012722
12723 if (!option_was_set((char_u *)"cp"))
12724 {
12725 p_cp = FALSE;
12726 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12727 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12728 set_option_default(opt_idx, OPT_FREE, FALSE);
12729 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012730 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012731 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012732
12733 if (fname != NULL)
12734 {
12735 p = vim_getenv(envname, &dofree);
12736 if (p == NULL)
12737 {
12738 /* Set $MYVIMRC to the first vimrc file found. */
12739 p = FullName_save(fname, FALSE);
12740 if (p != NULL)
12741 {
12742 vim_setenv(envname, p);
12743 vim_free(p);
12744 }
12745 }
12746 else if (dofree)
12747 vim_free(p);
12748 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012749}
12750
12751/*
12752 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12753 */
12754 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012755change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012756{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012757 int opt_idx;
12758
Bram Moolenaar071d4272004-06-13 20:20:40 +000012759 if (p_cp != on)
12760 {
12761 p_cp = on;
12762 compatible_set();
12763 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012764 opt_idx = findoption((char_u *)"cp");
12765 if (opt_idx >= 0)
12766 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012767}
12768
12769/*
12770 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012771 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012772 */
12773 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012774option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012775{
12776 int idx;
12777
12778 idx = findoption(name);
12779 if (idx < 0) /* unknown option */
12780 return FALSE;
12781 if (options[idx].flags & P_WAS_SET)
12782 return TRUE;
12783 return FALSE;
12784}
12785
12786/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012787 * Reset the flag indicating option "name" was set.
12788 */
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012789 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012790reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012791{
12792 int idx = findoption(name);
12793
12794 if (idx >= 0)
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012795 {
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012796 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012797 return OK;
12798 }
12799 return FAIL;
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012800}
12801
12802/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012803 * compatible_set() - Called when 'compatible' has been set or unset.
12804 *
12805 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12806 * flag) to a Vi compatible value.
12807 * When 'compatible' is unset: Set all options that have a different default
12808 * for Vim (without the P_VI_DEF flag) to that default.
12809 */
12810 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012811compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012812{
12813 int opt_idx;
12814
12815 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12816 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12817 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12818 set_option_default(opt_idx, OPT_FREE, p_cp);
12819 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012820 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012821}
12822
12823#ifdef FEAT_LINEBREAK
12824
Bram Moolenaar071d4272004-06-13 20:20:40 +000012825/*
12826 * fill_breakat_flags() -- called when 'breakat' changes value.
12827 */
12828 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012829fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012830{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012831 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012832 int i;
12833
12834 for (i = 0; i < 256; i++)
12835 breakat_flags[i] = FALSE;
12836
12837 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012838 for (p = p_breakat; *p; p++)
12839 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012840}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012841#endif
12842
12843/*
12844 * Check an option that can be a range of string values.
12845 *
12846 * Return OK for correct value, FAIL otherwise.
12847 * Empty is always OK.
12848 */
12849 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012850check_opt_strings(
12851 char_u *val,
12852 char **values,
12853 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012854{
12855 return opt_strings_flags(val, values, NULL, list);
12856}
12857
12858/*
12859 * Handle an option that can be a range of string values.
12860 * Set a flag in "*flagp" for each string present.
12861 *
12862 * Return OK for correct value, FAIL otherwise.
12863 * Empty is always OK.
12864 */
12865 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012866opt_strings_flags(
12867 char_u *val, /* new value */
12868 char **values, /* array of valid string values */
12869 unsigned *flagp,
12870 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012871{
12872 int i;
12873 int len;
12874 unsigned new_flags = 0;
12875
12876 while (*val)
12877 {
12878 for (i = 0; ; ++i)
12879 {
12880 if (values[i] == NULL) /* val not found in values[] */
12881 return FAIL;
12882
12883 len = (int)STRLEN(values[i]);
12884 if (STRNCMP(values[i], val, len) == 0
12885 && ((list && val[len] == ',') || val[len] == NUL))
12886 {
12887 val += len + (val[len] == ',');
12888 new_flags |= (1 << i);
12889 break; /* check next item in val list */
12890 }
12891 }
12892 }
12893 if (flagp != NULL)
12894 *flagp = new_flags;
12895
12896 return OK;
12897}
12898
12899/*
12900 * Read the 'wildmode' option, fill wim_flags[].
12901 */
12902 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012903check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012904{
12905 char_u new_wim_flags[4];
12906 char_u *p;
12907 int i;
12908 int idx = 0;
12909
12910 for (i = 0; i < 4; ++i)
12911 new_wim_flags[i] = 0;
12912
12913 for (p = p_wim; *p; ++p)
12914 {
12915 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12916 ;
12917 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12918 return FAIL;
12919 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12920 new_wim_flags[idx] |= WIM_LONGEST;
12921 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12922 new_wim_flags[idx] |= WIM_FULL;
12923 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12924 new_wim_flags[idx] |= WIM_LIST;
12925 else
12926 return FAIL;
12927 p += i;
12928 if (*p == NUL)
12929 break;
12930 if (*p == ',')
12931 {
12932 if (idx == 3)
12933 return FAIL;
12934 ++idx;
12935 }
12936 }
12937
12938 /* fill remaining entries with last flag */
12939 while (idx < 3)
12940 {
12941 new_wim_flags[idx + 1] = new_wim_flags[idx];
12942 ++idx;
12943 }
12944
12945 /* only when there are no errors, wim_flags[] is changed */
12946 for (i = 0; i < 4; ++i)
12947 wim_flags[i] = new_wim_flags[i];
12948 return OK;
12949}
12950
12951/*
12952 * Check if backspacing over something is allowed.
12953 */
12954 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012955can_bs(
12956 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012957{
Bram Moolenaar6b810d92018-06-04 17:28:44 +020012958#ifdef FEAT_JOB_CHANNEL
12959 if (what == BS_START && bt_prompt(curbuf))
12960 return FALSE;
12961#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012962 switch (*p_bs)
12963 {
12964 case '2': return TRUE;
12965 case '1': return (what != BS_START);
12966 case '0': return FALSE;
12967 }
12968 return vim_strchr(p_bs, what) != NULL;
12969}
12970
12971/*
12972 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12973 * the file must be considered changed when the value is different.
12974 */
12975 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012976save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012977{
12978 buf->b_start_ffc = *buf->b_p_ff;
12979 buf->b_start_eol = buf->b_p_eol;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012980 buf->b_start_bomb = buf->b_p_bomb;
12981
Bram Moolenaar071d4272004-06-13 20:20:40 +000012982 /* Only use free/alloc when necessary, they take time. */
12983 if (buf->b_start_fenc == NULL
12984 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12985 {
12986 vim_free(buf->b_start_fenc);
12987 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12988 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012989}
12990
12991/*
12992 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12993 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012994 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12995 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012996 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012997 * When "ignore_empty" is true don't consider a new, empty buffer to be
12998 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012999 */
13000 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013001file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000013002{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000013003 /* In a buffer that was never loaded the options are not valid. */
13004 if (buf->b_flags & BF_NEVERLOADED)
13005 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010013006 if (ignore_empty
13007 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000013008 && buf->b_ml.ml_line_count == 1
13009 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
13010 return FALSE;
13011 if (buf->b_start_ffc != *buf->b_p_ff)
13012 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020013013 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000013014 return TRUE;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000013015 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
13016 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000013017 if (buf->b_start_fenc == NULL)
13018 return (*buf->b_p_fenc != NUL);
13019 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +000013020}
13021
13022/*
13023 * return OK if "p" is a valid fileformat name, FAIL otherwise.
13024 */
13025 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013026check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000013027{
13028 return check_opt_strings(p, p_ff_values, FALSE);
13029}
Bram Moolenaar14f24742012-08-08 18:01:05 +020013030
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010013031#if defined(FEAT_VARTABS) || defined(PROTO)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013032
13033/*
13034 * Set the integer values corresponding to the string setting of 'vartabstop'.
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010013035 * "array" will be set, caller must free it if needed.
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013036 */
13037 int
13038tabstop_set(char_u *var, int **array)
13039{
13040 int valcount = 1;
13041 int t;
13042 char_u *cp;
13043
Bram Moolenaar64f41072018-10-15 22:51:50 +020013044 if (var[0] == NUL || (var[0] == '0' && var[1] == NUL))
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013045 {
13046 *array = NULL;
13047 return TRUE;
13048 }
13049
Bram Moolenaar64f41072018-10-15 22:51:50 +020013050 for (cp = var; *cp != NUL; ++cp)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013051 {
Bram Moolenaar64f41072018-10-15 22:51:50 +020013052 if (cp == var || cp[-1] == ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013053 {
13054 char_u *end;
Bram Moolenaar64f41072018-10-15 22:51:50 +020013055
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013056 if (strtol((char *)cp, (char **)&end, 10) <= 0)
13057 {
13058 if (cp != end)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010013059 emsg(_(e_positive));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013060 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010013061 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013062 return FALSE;
13063 }
13064 }
13065
13066 if (VIM_ISDIGIT(*cp))
13067 continue;
Bram Moolenaar64f41072018-10-15 22:51:50 +020013068 if (cp[0] == ',' && cp > var && cp[-1] != ',' && cp[1] != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013069 {
13070 ++valcount;
13071 continue;
13072 }
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010013073 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013074 return FALSE;
13075 }
13076
Bram Moolenaarc799fe22019-05-28 23:08:19 +020013077 *array = ALLOC_MULT(int, valcount + 1);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010013078 if (*array == NULL)
13079 return FALSE;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013080 (*array)[0] = valcount;
13081
13082 t = 1;
Bram Moolenaar64f41072018-10-15 22:51:50 +020013083 for (cp = var; *cp != NUL;)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013084 {
13085 (*array)[t++] = atoi((char *)cp);
Bram Moolenaar64f41072018-10-15 22:51:50 +020013086 while (*cp != NUL && *cp != ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013087 ++cp;
Bram Moolenaar64f41072018-10-15 22:51:50 +020013088 if (*cp != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013089 ++cp;
13090 }
13091
13092 return TRUE;
13093}
13094
13095/*
13096 * Calculate the number of screen spaces a tab will occupy.
13097 * If "vts" is set then the tab widths are taken from that array,
13098 * otherwise the value of ts is used.
13099 */
13100 int
13101tabstop_padding(colnr_T col, int ts_arg, int *vts)
13102{
13103 int ts = ts_arg == 0 ? 8 : ts_arg;
13104 int tabcount;
13105 colnr_T tabcol = 0;
13106 int t;
13107 int padding = 0;
13108
13109 if (vts == NULL || vts[0] == 0)
13110 return ts - (col % ts);
13111
13112 tabcount = vts[0];
13113
13114 for (t = 1; t <= tabcount; ++t)
13115 {
13116 tabcol += vts[t];
13117 if (tabcol > col)
13118 {
13119 padding = (int)(tabcol - col);
13120 break;
13121 }
13122 }
13123 if (t > tabcount)
13124 padding = vts[tabcount] - (int)((col - tabcol) % vts[tabcount]);
13125
13126 return padding;
13127}
13128
13129/*
13130 * Find the size of the tab that covers a particular column.
13131 */
13132 int
13133tabstop_at(colnr_T col, int ts, int *vts)
13134{
13135 int tabcount;
13136 colnr_T tabcol = 0;
13137 int t;
13138 int tab_size = 0;
13139
13140 if (vts == 0 || vts[0] == 0)
13141 return ts;
13142
13143 tabcount = vts[0];
13144 for (t = 1; t <= tabcount; ++t)
13145 {
13146 tabcol += vts[t];
13147 if (tabcol > col)
13148 {
13149 tab_size = vts[t];
13150 break;
13151 }
13152 }
13153 if (t > tabcount)
13154 tab_size = vts[tabcount];
13155
13156 return tab_size;
13157}
13158
13159/*
13160 * Find the column on which a tab starts.
13161 */
13162 colnr_T
13163tabstop_start(colnr_T col, int ts, int *vts)
13164{
13165 int tabcount;
13166 colnr_T tabcol = 0;
13167 int t;
13168 int excess;
13169
Bram Moolenaar0119a592018-06-24 23:53:28 +020013170 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013171 return (col / ts) * ts;
13172
13173 tabcount = vts[0];
13174 for (t = 1; t <= tabcount; ++t)
13175 {
13176 tabcol += vts[t];
13177 if (tabcol > col)
13178 return tabcol - vts[t];
13179 }
13180
13181 excess = tabcol % vts[tabcount];
13182 return excess + ((col - excess) / vts[tabcount]) * vts[tabcount];
13183}
13184
13185/*
13186 * Find the number of tabs and spaces necessary to get from one column
13187 * to another.
13188 */
13189 void
13190tabstop_fromto(
13191 colnr_T start_col,
13192 colnr_T end_col,
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013193 int ts_arg,
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013194 int *vts,
13195 int *ntabs,
13196 int *nspcs)
13197{
13198 int spaces = end_col - start_col;
13199 colnr_T tabcol = 0;
13200 int padding = 0;
13201 int tabcount;
13202 int t;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013203 int ts = ts_arg == 0 ? curbuf->b_p_ts : ts_arg;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013204
Bram Moolenaar0119a592018-06-24 23:53:28 +020013205 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013206 {
13207 int tabs = 0;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013208 int initspc = 0;
Bram Moolenaar0119a592018-06-24 23:53:28 +020013209
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013210 initspc = ts - (start_col % ts);
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013211 if (spaces >= initspc)
13212 {
13213 spaces -= initspc;
13214 tabs++;
13215 }
13216 tabs += spaces / ts;
13217 spaces -= (spaces / ts) * ts;
13218
13219 *ntabs = tabs;
13220 *nspcs = spaces;
13221 return;
13222 }
13223
13224 /* Find the padding needed to reach the next tabstop. */
13225 tabcount = vts[0];
13226 for (t = 1; t <= tabcount; ++t)
13227 {
13228 tabcol += vts[t];
13229 if (tabcol > start_col)
13230 {
13231 padding = (int)(tabcol - start_col);
13232 break;
13233 }
13234 }
13235 if (t > tabcount)
13236 padding = vts[tabcount] - (int)((start_col - tabcol) % vts[tabcount]);
13237
13238 /* If the space needed is less than the padding no tabs can be used. */
13239 if (spaces < padding)
13240 {
13241 *ntabs = 0;
13242 *nspcs = spaces;
13243 return;
13244 }
13245
13246 *ntabs = 1;
13247 spaces -= padding;
13248
13249 /* At least one tab has been used. See if any more will fit. */
13250 while (spaces != 0 && ++t <= tabcount)
13251 {
13252 padding = vts[t];
13253 if (spaces < padding)
13254 {
13255 *nspcs = spaces;
13256 return;
13257 }
13258 ++*ntabs;
13259 spaces -= padding;
13260 }
13261
13262 *ntabs += spaces / vts[tabcount];
13263 *nspcs = spaces % vts[tabcount];
13264}
13265
13266/*
13267 * See if two tabstop arrays contain the same values.
13268 */
13269 int
13270tabstop_eq(int *ts1, int *ts2)
13271{
13272 int t;
13273
13274 if ((ts1 == 0 && ts2) || (ts1 && ts2 == 0))
13275 return FALSE;
13276 if (ts1 == ts2)
13277 return TRUE;
13278 if (ts1[0] != ts2[0])
13279 return FALSE;
13280
13281 for (t = 1; t <= ts1[0]; ++t)
13282 if (ts1[t] != ts2[t])
13283 return FALSE;
13284
13285 return TRUE;
13286}
13287
Bram Moolenaar113e1072019-01-20 15:30:40 +010013288#if defined(FEAT_BEVAL) || defined(PROTO)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013289/*
13290 * Copy a tabstop array, allocating space for the new array.
13291 */
13292 int *
13293tabstop_copy(int *oldts)
13294{
13295 int *newts;
13296 int t;
13297
Bram Moolenaar6ee96582019-04-27 22:06:37 +020013298 if (oldts == NULL)
13299 return NULL;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020013300 newts = ALLOC_MULT(int, oldts[0] + 1);
Bram Moolenaar6ee96582019-04-27 22:06:37 +020013301 if (newts != NULL)
13302 for (t = 0; t <= oldts[0]; ++t)
13303 newts[t] = oldts[t];
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013304 return newts;
13305}
Bram Moolenaar113e1072019-01-20 15:30:40 +010013306#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013307
13308/*
13309 * Return a count of the number of tabstops.
13310 */
13311 int
13312tabstop_count(int *ts)
13313{
13314 return ts != NULL ? ts[0] : 0;
13315}
13316
13317/*
13318 * Return the first tabstop, or 8 if there are no tabstops defined.
13319 */
13320 int
13321tabstop_first(int *ts)
13322{
13323 return ts != NULL ? ts[1] : 8;
13324}
13325
13326#endif
13327
Bram Moolenaar14f24742012-08-08 18:01:05 +020013328/*
13329 * Return the effective shiftwidth value for current buffer, using the
13330 * 'tabstop' value when 'shiftwidth' is zero.
13331 */
13332 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013333get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020013334{
Bram Moolenaarf9514162018-11-22 03:08:29 +010013335 return get_sw_value_col(buf, 0);
13336}
13337
13338/*
13339 * Idem, using the first non-black in the current line.
13340 */
13341 long
13342get_sw_value_indent(buf_T *buf)
13343{
13344 pos_T pos = curwin->w_cursor;
13345
13346 pos.col = getwhitecols_curline();
13347 return get_sw_value_pos(buf, &pos);
13348}
13349
13350/*
13351 * Idem, using "pos".
13352 */
13353 long
13354get_sw_value_pos(buf_T *buf, pos_T *pos)
13355{
13356 pos_T save_cursor = curwin->w_cursor;
13357 long sw_value;
13358
13359 curwin->w_cursor = *pos;
13360 sw_value = get_sw_value_col(buf, get_nolist_virtcol());
13361 curwin->w_cursor = save_cursor;
13362 return sw_value;
13363}
13364
13365/*
13366 * Idem, using virtual column "col".
13367 */
13368 long
13369get_sw_value_col(buf_T *buf, colnr_T col UNUSED)
13370{
13371 return buf->b_p_sw ? buf->b_p_sw :
13372 #ifdef FEAT_VARTABS
13373 tabstop_at(col, buf->b_p_ts, buf->b_p_vts_array);
13374 #else
13375 buf->b_p_ts;
13376 #endif
Bram Moolenaar14f24742012-08-08 18:01:05 +020013377}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013378
13379/*
13380 * Return the effective softtabstop value for the current buffer, using the
Bram Moolenaar33d5ab32018-07-02 20:51:24 +020013381 * 'shiftwidth' value when 'softtabstop' is negative.
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013382 */
13383 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013384get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013385{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010013386 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013387}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013388
13389/*
Bram Moolenaar375e3392019-01-31 18:26:10 +010013390 * Return the effective 'scrolloff' value for the current window, using the
13391 * global value when appropriate.
13392 */
13393 long
13394get_scrolloff_value(void)
13395{
13396 return curwin->w_p_so < 0 ? p_so : curwin->w_p_so;
13397}
13398
13399/*
13400 * Return the effective 'sidescrolloff' value for the current window, using the
13401 * global value when appropriate.
13402 */
13403 long
13404get_sidescrolloff_value(void)
13405{
13406 return curwin->w_p_siso < 0 ? p_siso : curwin->w_p_siso;
13407}
13408
13409/*
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013410 * Check matchpairs option for "*initc".
13411 * If there is a match set "*initc" to the matching character and "*findc" to
13412 * the opposite character. Set "*backwards" to the direction.
13413 * When "switchit" is TRUE swap the direction.
13414 */
13415 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010013416find_mps_values(
13417 int *initc,
13418 int *findc,
13419 int *backwards,
13420 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013421{
13422 char_u *ptr;
13423
13424 ptr = curbuf->b_p_mps;
13425 while (*ptr != NUL)
13426 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013427 if (has_mbyte)
13428 {
13429 char_u *prev;
13430
13431 if (mb_ptr2char(ptr) == *initc)
13432 {
13433 if (switchit)
13434 {
13435 *findc = *initc;
13436 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13437 *backwards = TRUE;
13438 }
13439 else
13440 {
13441 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13442 *backwards = FALSE;
13443 }
13444 return;
13445 }
13446 prev = ptr;
13447 ptr += mb_ptr2len(ptr) + 1;
13448 if (mb_ptr2char(ptr) == *initc)
13449 {
13450 if (switchit)
13451 {
13452 *findc = *initc;
13453 *initc = mb_ptr2char(prev);
13454 *backwards = FALSE;
13455 }
13456 else
13457 {
13458 *findc = mb_ptr2char(prev);
13459 *backwards = TRUE;
13460 }
13461 return;
13462 }
13463 ptr += mb_ptr2len(ptr);
13464 }
13465 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013466 {
13467 if (*ptr == *initc)
13468 {
13469 if (switchit)
13470 {
13471 *backwards = TRUE;
13472 *findc = *initc;
13473 *initc = ptr[2];
13474 }
13475 else
13476 {
13477 *backwards = FALSE;
13478 *findc = ptr[2];
13479 }
13480 return;
13481 }
13482 ptr += 2;
13483 if (*ptr == *initc)
13484 {
13485 if (switchit)
13486 {
13487 *backwards = FALSE;
13488 *findc = *initc;
13489 *initc = ptr[-2];
13490 }
13491 else
13492 {
13493 *backwards = TRUE;
13494 *findc = ptr[-2];
13495 }
13496 return;
13497 }
13498 ++ptr;
13499 }
13500 if (*ptr == ',')
13501 ++ptr;
13502 }
13503}
Bram Moolenaar597a4222014-06-25 14:39:50 +020013504
13505#if defined(FEAT_LINEBREAK) || defined(PROTO)
13506/*
13507 * This is called when 'breakindentopt' is changed and when a window is
13508 * initialized.
13509 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013510 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013511briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020013512{
13513 char_u *p;
13514 int bri_shift = 0;
13515 long bri_min = 20;
13516 int bri_sbr = FALSE;
13517
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013518 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013519 while (*p != NUL)
13520 {
13521 if (STRNCMP(p, "shift:", 6) == 0
13522 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
13523 {
13524 p += 6;
13525 bri_shift = getdigits(&p);
13526 }
13527 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
13528 {
13529 p += 4;
13530 bri_min = getdigits(&p);
13531 }
13532 else if (STRNCMP(p, "sbr", 3) == 0)
13533 {
13534 p += 3;
13535 bri_sbr = TRUE;
13536 }
13537 if (*p != ',' && *p != NUL)
13538 return FAIL;
13539 if (*p == ',')
13540 ++p;
13541 }
13542
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013543 wp->w_p_brishift = bri_shift;
13544 wp->w_p_brimin = bri_min;
13545 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013546
13547 return OK;
13548}
13549#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013550
13551/*
13552 * Get the local or global value of 'backupcopy'.
13553 */
13554 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013555get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013556{
13557 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
13558}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020013559
13560#if defined(FEAT_SIGNS) || defined(PROTO)
13561/*
13562 * Return TRUE when window "wp" has a column to draw signs in.
13563 */
13564 int
13565signcolumn_on(win_T *wp)
13566{
Bram Moolenaar394c5d82019-06-17 21:48:05 +020013567 // If 'signcolumn' is set to 'number', signs are displayed in the 'number'
13568 // column (if present). Otherwise signs are to be displayed in the sign
13569 // column.
13570 if (*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
13571 return wp->w_buffer->b_signlist != NULL && !wp->w_p_nu && !wp->w_p_rnu;
13572
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020013573 if (*wp->w_p_scl == 'n')
13574 return FALSE;
13575 if (*wp->w_p_scl == 'y')
13576 return TRUE;
13577 return (wp->w_buffer->b_signlist != NULL
13578# ifdef FEAT_NETBEANS_INTG
13579 || wp->w_buffer->b_has_sign_column
13580# endif
13581 );
13582}
13583#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013584
13585#if defined(FEAT_EVAL) || defined(PROTO)
13586/*
13587 * Get window or buffer local options.
13588 */
13589 dict_T *
13590get_winbuf_options(int bufopt)
13591{
13592 dict_T *d;
13593 int opt_idx;
13594
13595 d = dict_alloc();
13596 if (d == NULL)
13597 return NULL;
13598
13599 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
13600 {
13601 struct vimoption *opt = &options[opt_idx];
13602
13603 if ((bufopt && (opt->indir & PV_BUF))
13604 || (!bufopt && (opt->indir & PV_WIN)))
13605 {
13606 char_u *varp = get_varp(opt);
13607
13608 if (varp != NULL)
13609 {
13610 if (opt->flags & P_STRING)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013611 dict_add_string(d, opt->fullname, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020013612 else if (opt->flags & P_NUM)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013613 dict_add_number(d, opt->fullname, *(long *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013614 else
Bram Moolenaare0be1672018-07-08 16:50:37 +020013615 dict_add_number(d, opt->fullname, *(int *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013616 }
13617 }
13618 }
13619
13620 return d;
13621}
13622#endif