blob: a804dd870449f343a1a309530fd23d8f1123bb09 [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'
Bram Moolenaarb78564d2019-07-28 19:24:36 +02007436 else if (gvarp == &p_csl)
Bram Moolenaarac3150d2019-07-28 16:36:39 +02007437 {
Bram Moolenaarb78564d2019-07-28 19:24:36 +02007438 if (check_opt_strings(p_csl, p_csl_values, FALSE) != OK
7439 || check_opt_strings(curbuf->b_p_csl, p_csl_values, FALSE) != OK)
Bram Moolenaarac3150d2019-07-28 16:36:39 +02007440 errmsg = e_invarg;
7441 }
7442# endif
7443#endif // FEAT_INS_EXPAND
Bram Moolenaar071d4272004-06-13 20:20:40 +00007444
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007445#ifdef FEAT_SIGNS
Bram Moolenaare4b407f2019-07-04 11:59:28 +02007446 // 'signcolumn'
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007447 else if (varp == &curwin->w_p_scl)
7448 {
7449 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7450 errmsg = e_invarg;
Bram Moolenaare4b407f2019-07-04 11:59:28 +02007451 // When changing the 'signcolumn' to or from 'number', recompute the
7452 // width of the number column if 'number' or 'relativenumber' is set.
7453 if (((*oldval == 'n' && *(oldval + 1) == 'u')
7454 || (*curwin->w_p_scl == 'n' && *(curwin->w_p_scl + 1) =='u'))
7455 && (curwin->w_p_nu || curwin->w_p_rnu))
7456 curwin->w_nrwidth_line_count = 0;
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007457 }
7458#endif
7459
Bram Moolenaar071d4272004-06-13 20:20:40 +00007460
Bram Moolenaar4f974752019-02-17 17:44:42 +01007461#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007462 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007463 else if (varp == &p_toolbar)
7464 {
7465 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7466 &toolbar_flags, TRUE) != OK)
7467 errmsg = e_invarg;
7468 else
7469 {
7470 out_flush();
7471 gui_mch_show_toolbar((toolbar_flags &
7472 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7473 }
7474 }
7475#endif
7476
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007477#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007478 /* 'toolbariconsize': GTK+ 2 only */
7479 else if (varp == &p_tbis)
7480 {
7481 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7482 errmsg = e_invarg;
7483 else
7484 {
7485 out_flush();
7486 gui_mch_show_toolbar((toolbar_flags &
7487 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7488 }
7489 }
7490#endif
7491
7492 /* 'pastetoggle': translate key codes like in a mapping */
7493 else if (varp == &p_pt)
7494 {
7495 if (*p_pt)
7496 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007497 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007498 if (p != NULL)
7499 {
7500 if (new_value_alloced)
7501 free_string_option(p_pt);
7502 p_pt = p;
7503 new_value_alloced = TRUE;
7504 }
7505 }
7506 }
7507
7508 /* 'backspace' */
7509 else if (varp == &p_bs)
7510 {
7511 if (VIM_ISDIGIT(*p_bs))
7512 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007513 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007514 errmsg = e_invarg;
7515 }
7516 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7517 errmsg = e_invarg;
7518 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007519 else if (varp == &p_bo)
7520 {
7521 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7522 errmsg = e_invarg;
7523 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007524
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007525 /* 'tagcase' */
7526 else if (gvarp == &p_tc)
7527 {
7528 unsigned int *flags;
7529
7530 if (opt_flags & OPT_LOCAL)
7531 {
7532 p = curbuf->b_p_tc;
7533 flags = &curbuf->b_tc_flags;
7534 }
7535 else
7536 {
7537 p = p_tc;
7538 flags = &tc_flags;
7539 }
7540
7541 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7542 /* make the local value empty: use the global value */
7543 *flags = 0;
7544 else if (*p == NUL
7545 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7546 errmsg = e_invarg;
7547 }
7548
Bram Moolenaar071d4272004-06-13 20:20:40 +00007549 /* 'casemap' */
7550 else if (varp == &p_cmp)
7551 {
7552 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7553 errmsg = e_invarg;
7554 }
7555
7556#ifdef FEAT_DIFF
7557 /* 'diffopt' */
7558 else if (varp == &p_dip)
7559 {
7560 if (diffopt_changed() == FAIL)
7561 errmsg = e_invarg;
7562 }
7563#endif
7564
7565#ifdef FEAT_FOLDING
7566 /* 'foldmethod' */
7567 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7568 {
7569 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7570 || *curwin->w_p_fdm == NUL)
7571 errmsg = e_invarg;
7572 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007573 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007574 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007575 if (foldmethodIsDiff(curwin))
7576 newFoldLevel();
7577 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007578 }
7579# ifdef FEAT_EVAL
7580 /* 'foldexpr' */
7581 else if (varp == &curwin->w_p_fde)
7582 {
7583 if (foldmethodIsExpr(curwin))
7584 foldUpdateAll(curwin);
7585 }
7586# endif
7587 /* 'foldmarker' */
7588 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7589 {
7590 p = vim_strchr(*varp, ',');
7591 if (p == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007592 errmsg = N_("E536: comma required");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007593 else if (p == *varp || p[1] == NUL)
7594 errmsg = e_invarg;
7595 else if (foldmethodIsMarker(curwin))
7596 foldUpdateAll(curwin);
7597 }
7598 /* 'commentstring' */
7599 else if (gvarp == &p_cms)
7600 {
7601 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007602 errmsg = N_("E537: 'commentstring' must be empty or contain %s");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007603 }
7604 /* 'foldopen' */
7605 else if (varp == &p_fdo)
7606 {
7607 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7608 errmsg = e_invarg;
7609 }
7610 /* 'foldclose' */
7611 else if (varp == &p_fcl)
7612 {
7613 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7614 errmsg = e_invarg;
7615 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007616 /* 'foldignore' */
7617 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7618 {
7619 if (foldmethodIsIndent(curwin))
7620 foldUpdateAll(curwin);
7621 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007622#endif
7623
Bram Moolenaar071d4272004-06-13 20:20:40 +00007624 /* 'virtualedit' */
7625 else if (varp == &p_ve)
7626 {
7627 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7628 errmsg = e_invarg;
7629 else if (STRCMP(p_ve, oldval) != 0)
7630 {
7631 /* Recompute cursor position in case the new 've' setting
7632 * changes something. */
7633 validate_virtcol();
7634 coladvance(curwin->w_virtcol);
7635 }
7636 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007637
7638#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7639 else if (varp == &p_csqf)
7640 {
7641 if (p_csqf != NULL)
7642 {
7643 p = p_csqf;
7644 while (*p != NUL)
7645 {
7646 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7647 || p[1] == NUL
7648 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7649 || (p[2] != NUL && p[2] != ','))
7650 {
7651 errmsg = e_invarg;
7652 break;
7653 }
7654 else if (p[2] == NUL)
7655 break;
7656 else
7657 p += 3;
7658 }
7659 }
7660 }
7661#endif
7662
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007663#ifdef FEAT_CINDENT
7664 /* 'cinoptions' */
7665 else if (gvarp == &p_cino)
7666 {
7667 /* TODO: recognize errors */
7668 parse_cino(curbuf);
7669 }
7670#endif
7671
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007672#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007673 /* 'renderoptions' */
Bram Moolenaar3767c6e2017-12-05 16:57:56 +01007674 else if (varp == &p_rop)
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007675 {
7676 if (!gui_mch_set_rendering_options(p_rop))
7677 errmsg = e_invarg;
7678 }
7679#endif
7680
Bram Moolenaard0b51382016-11-04 15:23:45 +01007681 else if (gvarp == &p_ft)
7682 {
7683 if (!valid_filetype(*varp))
7684 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007685 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007686 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007687 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007688
7689 // Since we check the value, there is no need to set P_INSECURE,
7690 // even when the value comes from a modeline.
7691 *value_checked = TRUE;
7692 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007693 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007694
7695#ifdef FEAT_SYN_HL
7696 else if (gvarp == &p_syn)
7697 {
7698 if (!valid_filetype(*varp))
7699 errmsg = e_invarg;
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007700 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007701 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007702 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007703
7704 // Since we check the value, there is no need to set P_INSECURE,
7705 // even when the value comes from a modeline.
7706 *value_checked = TRUE;
7707 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007708 }
7709#endif
7710
Bram Moolenaar825680f2017-07-22 17:04:02 +02007711#ifdef FEAT_TERMINAL
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007712 // 'termwinkey'
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007713 else if (varp == &curwin->w_p_twk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007714 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007715 if (*curwin->w_p_twk != NUL
7716 && string_to_key(curwin->w_p_twk, TRUE) == 0)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007717 errmsg = e_invarg;
7718 }
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007719 // 'termwinsize'
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007720 else if (varp == &curwin->w_p_tws)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007721 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007722 if (*curwin->w_p_tws != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007723 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007724 p = skipdigits(curwin->w_p_tws);
7725 if (p == curwin->w_p_tws
Bram Moolenaar498c2562018-04-15 23:45:15 +02007726 || (*p != 'x' && *p != '*')
7727 || *skipdigits(p + 1) != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007728 errmsg = e_invarg;
7729 }
7730 }
Bram Moolenaar4f974752019-02-17 17:44:42 +01007731# if defined(MSWIN)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007732 // 'termwintype'
7733 else if (varp == &p_twt)
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007734 {
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007735 if (check_opt_strings(*varp, p_twt_values, FALSE) != OK)
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007736 errmsg = e_invarg;
7737 }
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007738# endif
Bram Moolenaar825680f2017-07-22 17:04:02 +02007739#endif
7740
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007741#ifdef FEAT_VARTABS
7742 /* 'varsofttabstop' */
7743 else if (varp == &(curbuf->b_p_vsts))
7744 {
7745 char_u *cp;
7746
7747 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7748 {
7749 if (curbuf->b_p_vsts_array)
7750 {
7751 vim_free(curbuf->b_p_vsts_array);
7752 curbuf->b_p_vsts_array = 0;
7753 }
7754 }
7755 else
7756 {
7757 for (cp = *varp; *cp; ++cp)
7758 {
7759 if (vim_isdigit(*cp))
7760 continue;
7761 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7762 continue;
7763 errmsg = e_invarg;
7764 break;
7765 }
7766 if (errmsg == NULL)
7767 {
7768 int *oldarray = curbuf->b_p_vsts_array;
7769 if (tabstop_set(*varp, &(curbuf->b_p_vsts_array)))
7770 {
7771 if (oldarray)
7772 vim_free(oldarray);
7773 }
7774 else
7775 errmsg = e_invarg;
7776 }
7777 }
7778 }
7779
7780 /* 'vartabstop' */
7781 else if (varp == &(curbuf->b_p_vts))
7782 {
7783 char_u *cp;
7784
7785 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7786 {
7787 if (curbuf->b_p_vts_array)
7788 {
7789 vim_free(curbuf->b_p_vts_array);
7790 curbuf->b_p_vts_array = NULL;
7791 }
7792 }
7793 else
7794 {
7795 for (cp = *varp; *cp; ++cp)
7796 {
7797 if (vim_isdigit(*cp))
7798 continue;
7799 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7800 continue;
7801 errmsg = e_invarg;
7802 break;
7803 }
7804 if (errmsg == NULL)
7805 {
7806 int *oldarray = curbuf->b_p_vts_array;
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007807
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007808 if (tabstop_set(*varp, &(curbuf->b_p_vts_array)))
7809 {
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007810 vim_free(oldarray);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007811#ifdef FEAT_FOLDING
7812 if (foldmethodIsIndent(curwin))
7813 foldUpdateAll(curwin);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007814#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007815 }
7816 else
7817 errmsg = e_invarg;
7818 }
7819 }
7820 }
7821#endif
7822
Bram Moolenaar79648732019-07-18 21:43:07 +02007823#ifdef FEAT_TEXT_PROP
7824 // 'previewpopup'
7825 else if (varp == &p_pvp)
7826 {
7827 if (parse_previewpopup(NULL) == FAIL)
7828 errmsg = e_invarg;
7829 }
7830#endif
7831
Bram Moolenaar071d4272004-06-13 20:20:40 +00007832 /* Options that are a list of flags. */
7833 else
7834 {
7835 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007836 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007837 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007838 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007839 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007840 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007841 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007842 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007843 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007844#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007845 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007846 p = (char_u *)COCU_ALL;
7847#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007848 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007849 {
7850#ifdef FEAT_MOUSE
7851 p = (char_u *)MOUSE_ALL;
7852#else
7853 if (*p_mouse != NUL)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007854 errmsg = N_("E538: No mouse support");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007855#endif
7856 }
7857#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007858 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007859 p = (char_u *)GO_ALL;
7860#endif
7861 if (p != NULL)
7862 {
7863 for (s = *varp; *s; ++s)
7864 if (vim_strchr(p, *s) == NULL)
7865 {
7866 errmsg = illegal_char(errbuf, *s);
7867 break;
7868 }
7869 }
7870 }
7871
7872 /*
7873 * If error detected, restore the previous value.
7874 */
7875 if (errmsg != NULL)
7876 {
7877 if (new_value_alloced)
7878 free_string_option(*varp);
7879 *varp = oldval;
7880 /*
7881 * When resetting some values, need to act on it.
7882 */
7883 if (did_chartab)
7884 (void)init_chartab();
7885 if (varp == &p_hl)
7886 (void)highlight_changed();
7887 }
7888 else
7889 {
7890#ifdef FEAT_EVAL
7891 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02007892 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007893#endif
7894 /*
7895 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007896 * Use "free_oldval", because recursiveness may change the flags under
7897 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007898 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007899 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007900 free_string_option(oldval);
7901 if (new_value_alloced)
7902 options[opt_idx].flags |= P_ALLOCED;
7903 else
7904 options[opt_idx].flags &= ~P_ALLOCED;
7905
7906 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007907 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007908 {
7909 /* global option with local value set to use global value; free
7910 * the local value and make it empty */
7911 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7912 free_string_option(*(char_u **)p);
7913 *(char_u **)p = empty_option;
7914 }
7915
7916 /* May set global value for local option. */
7917 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7918 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007919
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007920 /*
7921 * Trigger the autocommand only after setting the flags.
7922 */
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007923#ifdef FEAT_SYN_HL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007924 /* When 'syntax' is set, load the syntax of that name */
7925 if (varp == &(curbuf->b_p_syn))
7926 {
Bram Moolenaara5616b02018-06-17 19:08:30 +02007927 static int syn_recursive = 0;
7928
7929 ++syn_recursive;
7930 // Only pass TRUE for "force" when the value changed or not used
7931 // recursively, to avoid endless recurrence.
7932 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname,
7933 value_changed || syn_recursive == 1, curbuf);
7934 --syn_recursive;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007935 }
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007936#endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007937 else if (varp == &(curbuf->b_p_ft))
7938 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007939 /* 'filetype' is set, trigger the FileType autocommand.
7940 * Skip this when called from a modeline and the filetype was
Bram Moolenaara5616b02018-06-17 19:08:30 +02007941 * already set to this value. */
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007942 if (!(opt_flags & OPT_MODELINE) || value_changed)
Bram Moolenaar90492982017-06-22 14:16:31 +02007943 {
Bram Moolenaar916a8182018-11-25 02:18:29 +01007944 static int ft_recursive = 0;
7945 int secure_save = secure;
7946
7947 // Reset the secure flag, since the value of 'filetype' has
7948 // been checked to be safe.
7949 secure = 0;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007950
7951 ++ft_recursive;
Bram Moolenaar90492982017-06-22 14:16:31 +02007952 did_filetype = TRUE;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007953 // Only pass TRUE for "force" when the value changed or not
7954 // used recursively, to avoid endless recurrence.
7955 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname,
7956 value_changed || ft_recursive == 1, curbuf);
7957 --ft_recursive;
Bram Moolenaar163095f2017-07-09 15:41:53 +02007958 /* Just in case the old "curbuf" is now invalid. */
7959 if (varp != &(curbuf->b_p_ft))
7960 varp = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007961
7962 secure = secure_save;
Bram Moolenaar90492982017-06-22 14:16:31 +02007963 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007964 }
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007965#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007966 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007967 {
7968 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007969 char_u *q = curwin->w_s->b_p_spl;
7970
7971 /* Skip the first name if it is "cjk". */
7972 if (STRNCMP(q, "cjk,", 4) == 0)
7973 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007974
7975 /*
7976 * Source the spell/LANG.vim in 'runtimepath'.
7977 * They could set 'spellcapcheck' depending on the language.
7978 * Use the first name in 'spelllang' up to '_region' or
7979 * '.encoding'.
7980 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007981 for (p = q; *p != NUL; ++p)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01007982 if (!ASCII_ISALNUM(*p) && *p != '-')
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007983 break;
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007984 if (p > q)
7985 {
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02007986 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
7987 (int)(p - q), q);
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007988 source_runtime(fname, DIP_ALL);
7989 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007990 }
7991#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007992 }
7993
7994#ifdef FEAT_MOUSE
7995 if (varp == &p_mouse)
7996 {
7997# ifdef FEAT_MOUSE_TTY
7998 if (*p_mouse == NUL)
7999 mch_setmouse(FALSE); /* switch mouse off */
8000 else
8001# endif
8002 setmouse(); /* in case 'mouse' changed */
8003 }
8004#endif
8005
Bram Moolenaar913077c2012-03-28 19:59:04 +02008006 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008007 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008008 curwin->w_set_curswant = TRUE;
8009
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00008010#ifdef FEAT_GUI
8011 /* check redraw when it's not a GUI option or the GUI is active. */
8012 if (!redraw_gui_only || gui.in_use)
8013#endif
8014 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008015
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008016#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
8017 if (did_swaptcap)
8018 {
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008019 set_termname((char_u *)"win32");
8020 init_highlight(TRUE, FALSE);
8021 }
8022#endif
8023
Bram Moolenaar071d4272004-06-13 20:20:40 +00008024 return errmsg;
8025}
8026
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01008027#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02008028/*
8029 * Simple int comparison function for use with qsort()
8030 */
8031 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01008032int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02008033{
8034 return *(const int *)a - *(const int *)b;
8035}
8036
8037/*
8038 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
8039 * Returns error message, NULL if it's OK.
8040 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008041 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008042check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02008043{
8044 char_u *s;
8045 int col;
8046 int count = 0;
8047 int color_cols[256];
8048 int i;
8049 int j = 0;
8050
Bram Moolenaar50f834d2011-09-21 13:40:17 +02008051 if (wp->w_buffer == NULL)
8052 return NULL; /* buffer was closed */
8053
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008054 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02008055 {
8056 if (*s == '-' || *s == '+')
8057 {
8058 /* -N and +N: add to 'textwidth' */
8059 col = (*s == '-') ? -1 : 1;
8060 ++s;
8061 if (!VIM_ISDIGIT(*s))
8062 return e_invarg;
8063 col = col * getdigits(&s);
8064 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008065 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02008066 col += wp->w_buffer->b_p_tw;
8067 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008068 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02008069 }
8070 else if (VIM_ISDIGIT(*s))
8071 col = getdigits(&s);
8072 else
8073 return e_invarg;
8074 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008075skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02008076 if (*s == NUL)
8077 break;
8078 if (*s != ',')
8079 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008080 if (*++s == NUL)
8081 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02008082 }
8083
8084 vim_free(wp->w_p_cc_cols);
8085 if (count == 0)
8086 wp->w_p_cc_cols = NULL;
8087 else
8088 {
Bram Moolenaarc799fe22019-05-28 23:08:19 +02008089 wp->w_p_cc_cols = ALLOC_MULT(int, count + 1);
Bram Moolenaar1a384422010-07-14 19:53:30 +02008090 if (wp->w_p_cc_cols != NULL)
8091 {
8092 /* sort the columns for faster usage on screen redraw inside
8093 * win_line() */
8094 qsort(color_cols, count, sizeof(int), int_cmp);
8095
8096 for (i = 0; i < count; ++i)
8097 /* skip duplicates */
8098 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
8099 wp->w_p_cc_cols[j++] = color_cols[i];
8100 wp->w_p_cc_cols[j] = -1; /* end marker */
8101 }
8102 }
8103
8104 return NULL; /* no error */
8105}
8106#endif
8107
Bram Moolenaar071d4272004-06-13 20:20:40 +00008108/*
8109 * Handle setting 'listchars' or 'fillchars'.
8110 * Returns error message, NULL if it's OK.
8111 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008112 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008113set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008114{
8115 int round, i, len, entries;
8116 char_u *p, *s;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008117 int c1 = 0, c2 = 0, c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008118 struct charstab
8119 {
8120 int *cp;
8121 char *name;
8122 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00008123 static struct charstab filltab[] =
8124 {
8125 {&fill_stl, "stl"},
8126 {&fill_stlnc, "stlnc"},
8127 {&fill_vert, "vert"},
8128 {&fill_fold, "fold"},
8129 {&fill_diff, "diff"},
8130 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00008131 static struct charstab lcstab[] =
8132 {
8133 {&lcs_eol, "eol"},
8134 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008135 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00008136 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02008137 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00008138 {&lcs_tab2, "tab"},
8139 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02008140#ifdef FEAT_CONCEAL
8141 {&lcs_conceal, "conceal"},
8142#else
8143 {NULL, "conceal"},
8144#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008145 };
8146 struct charstab *tab;
8147
Bram Moolenaar071d4272004-06-13 20:20:40 +00008148 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008149 {
8150 tab = lcstab;
8151 entries = sizeof(lcstab) / sizeof(struct charstab);
8152 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008153 else
8154 {
8155 tab = filltab;
8156 entries = sizeof(filltab) / sizeof(struct charstab);
8157 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008158
8159 /* first round: check for valid value, second round: assign values */
8160 for (round = 0; round <= 1; ++round)
8161 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008162 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008163 {
8164 /* After checking that the value is valid: set defaults: space for
8165 * 'fillchars', NUL for 'listchars' */
8166 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008167 if (tab[i].cp != NULL)
8168 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar83a52172019-01-16 22:41:54 +01008169
Bram Moolenaar071d4272004-06-13 20:20:40 +00008170 if (varp == &p_lcs)
Bram Moolenaar83a52172019-01-16 22:41:54 +01008171 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008172 lcs_tab1 = NUL;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008173 lcs_tab3 = NUL;
8174 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008175 else
8176 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008177 }
8178 p = *varp;
8179 while (*p)
8180 {
8181 for (i = 0; i < entries; ++i)
8182 {
8183 len = (int)STRLEN(tab[i].name);
8184 if (STRNCMP(p, tab[i].name, len) == 0
8185 && p[len] == ':'
8186 && p[len + 1] != NUL)
8187 {
Bram Moolenaar2c519cf2019-03-21 21:45:34 +01008188 c2 = c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008189 s = p + len + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008190 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00008191 if (mb_char2cells(c1) > 1)
8192 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008193 if (tab[i].cp == &lcs_tab2)
8194 {
8195 if (*s == NUL)
8196 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008197 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00008198 if (mb_char2cells(c2) > 1)
8199 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008200 if (!(*s == ',' || *s == NUL))
8201 {
Bram Moolenaar83a52172019-01-16 22:41:54 +01008202 c3 = mb_ptr2char_adv(&s);
8203 if (mb_char2cells(c3) > 1)
8204 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008205 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008206 }
Bram Moolenaar83a52172019-01-16 22:41:54 +01008207
Bram Moolenaar071d4272004-06-13 20:20:40 +00008208 if (*s == ',' || *s == NUL)
8209 {
8210 if (round)
8211 {
8212 if (tab[i].cp == &lcs_tab2)
8213 {
8214 lcs_tab1 = c1;
8215 lcs_tab2 = c2;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008216 lcs_tab3 = c3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008217 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008218 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008219 *(tab[i].cp) = c1;
8220
8221 }
8222 p = s;
8223 break;
8224 }
8225 }
8226 }
8227
8228 if (i == entries)
8229 return e_invarg;
8230 if (*p == ',')
8231 ++p;
8232 }
8233 }
8234
8235 return NULL; /* no error */
8236}
8237
8238#ifdef FEAT_STL_OPT
8239/*
8240 * Check validity of options with the 'statusline' format.
8241 * Return error message or NULL.
8242 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008243 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008244check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008245{
8246 int itemcnt = 0;
8247 int groupdepth = 0;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008248 static char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00008249
8250 while (*s && itemcnt < STL_MAX_ITEM)
8251 {
8252 /* Check for valid keys after % sequences */
8253 while (*s && *s != '%')
8254 s++;
8255 if (!*s)
8256 break;
8257 s++;
8258 if (*s != '%' && *s != ')')
8259 ++itemcnt;
8260 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
8261 {
8262 s++;
8263 continue;
8264 }
8265 if (*s == ')')
8266 {
8267 s++;
8268 if (--groupdepth < 0)
8269 break;
8270 continue;
8271 }
8272 if (*s == '-')
8273 s++;
8274 while (VIM_ISDIGIT(*s))
8275 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00008276 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008277 continue;
8278 if (*s == '.')
8279 {
8280 s++;
8281 while (*s && VIM_ISDIGIT(*s))
8282 s++;
8283 }
8284 if (*s == '(')
8285 {
8286 groupdepth++;
8287 continue;
8288 }
8289 if (vim_strchr(STL_ALL, *s) == NULL)
8290 {
8291 return illegal_char(errbuf, *s);
8292 }
8293 if (*s == '{')
8294 {
8295 s++;
8296 while (*s != '}' && *s)
8297 s++;
8298 if (*s != '}')
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008299 return N_("E540: Unclosed expression sequence");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008300 }
8301 }
8302 if (itemcnt >= STL_MAX_ITEM)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008303 return N_("E541: too many items");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008304 if (groupdepth != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008305 return N_("E542: unbalanced groups");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008306 return NULL;
8307}
8308#endif
8309
8310#ifdef FEAT_CLIPBOARD
8311/*
8312 * Extract the items in the 'clipboard' option and set global values.
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008313 * Return an error message or NULL for success.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008314 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008315 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008316check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008317{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008318 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008319 int new_autoselect_star = FALSE;
8320 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008321 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008322 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008323 regprog_T *new_exclude_prog = NULL;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008324 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008325 char_u *p;
8326
8327 for (p = p_cb; *p != NUL; )
8328 {
8329 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
8330 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008331 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008332 p += 7;
8333 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02008334 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008335 && (p[11] == ',' || p[11] == NUL))
8336 {
8337 new_unnamed |= CLIP_UNNAMED_PLUS;
8338 p += 11;
8339 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008340 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008341 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008342 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02008343 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008344 p += 10;
8345 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02008346 else if (STRNCMP(p, "autoselectplus", 14) == 0
8347 && (p[14] == ',' || p[14] == NUL))
8348 {
8349 new_autoselect_plus = TRUE;
8350 p += 14;
8351 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008352 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008353 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008354 {
8355 new_autoselectml = TRUE;
8356 p += 12;
8357 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008358 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
8359 {
8360 new_html = TRUE;
8361 p += 4;
8362 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008363 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
8364 {
8365 p += 8;
8366 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
8367 if (new_exclude_prog == NULL)
8368 errmsg = e_invarg;
8369 break;
8370 }
8371 else
8372 {
8373 errmsg = e_invarg;
8374 break;
8375 }
8376 if (*p == ',')
8377 ++p;
8378 }
8379 if (errmsg == NULL)
8380 {
8381 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008382 clip_autoselect_star = new_autoselect_star;
8383 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008384 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008385 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008386 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008387 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008388#ifdef FEAT_GUI_GTK
8389 if (gui.in_use)
8390 {
8391 gui_gtk_set_selection_targets();
8392 gui_gtk_set_dnd_targets();
8393 }
8394#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008395 }
8396 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008397 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008398
8399 return errmsg;
8400}
8401#endif
8402
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008403#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008404/*
8405 * Handle side effects of setting 'spell'.
8406 * Return an error message or NULL for success.
8407 */
8408 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008409did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008410{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008411 char *errmsg = NULL;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008412 win_T *wp;
8413 int l;
8414
8415 if (is_spellfile)
8416 {
8417 l = (int)STRLEN(curwin->w_s->b_p_spf);
8418 if (l > 0 && (l < 4
8419 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8420 errmsg = e_invarg;
8421 }
8422
8423 if (errmsg == NULL)
8424 {
8425 FOR_ALL_WINDOWS(wp)
8426 if (wp->w_buffer == curbuf && wp->w_p_spell)
8427 {
8428 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008429 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008430 }
8431 }
8432 return errmsg;
8433}
8434
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008435/*
8436 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8437 * Return error message when failed, NULL when OK.
8438 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008439 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008440compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008441{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008442 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008443 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008444
Bram Moolenaar860cae12010-06-05 23:22:07 +02008445 if (*synblock->b_p_spc == NUL)
8446 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008447 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008448 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008449 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008450 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008451 if (re != NULL)
8452 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008453 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008454 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008455 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008456 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008457 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008458 return e_invarg;
8459 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008460 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008461 }
8462
Bram Moolenaar473de612013-06-08 18:19:48 +02008463 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008464 return NULL;
8465}
8466#endif
8467
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008468#if defined(FEAT_EVAL) || defined(PROTO)
8469/*
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008470 * Set the script_ctx for an option, taking care of setting the buffer- or
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008471 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008472 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008473 static void
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008474set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008475{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008476 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8477 int indir = (int)options[opt_idx].indir;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008478 sctx_T new_script_ctx = script_ctx;
8479
8480 new_script_ctx.sc_lnum += sourcing_lnum;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008481
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008482 /* Remember where the option was set. For local options need to do that
8483 * in the buffer or window structure. */
8484 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008485 options[opt_idx].script_ctx = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008486 if (both || (opt_flags & OPT_LOCAL))
8487 {
8488 if (indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008489 curbuf->b_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008490 else if (indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008491 curwin->w_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008492 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008493}
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02008494
8495/*
8496 * Set the script_ctx for a termcap option.
8497 * "name" must be the two character code, e.g. "RV".
8498 * When "name" is NULL use "opt_idx".
8499 */
8500 void
8501set_term_option_sctx_idx(char *name, int opt_idx)
8502{
8503 char_u buf[5];
8504 int idx;
8505
8506 if (name == NULL)
8507 idx = opt_idx;
8508 else
8509 {
8510 buf[0] = 't';
8511 buf[1] = '_';
8512 buf[2] = name[0];
8513 buf[3] = name[1];
8514 buf[4] = 0;
8515 idx = findoption(buf);
8516 }
8517 if (idx >= 0)
8518 set_option_sctx_idx(idx, OPT_GLOBAL, current_sctx);
8519}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008520#endif
8521
Bram Moolenaar071d4272004-06-13 20:20:40 +00008522/*
8523 * Set the value of a boolean option, and take care of side effects.
8524 * Returns NULL for success, or an error message for an error.
8525 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008526 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008527set_bool_option(
8528 int opt_idx, /* index in options[] table */
8529 char_u *varp, /* pointer to the option variable */
8530 int value, /* new value */
8531 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008532{
8533 int old_value = *(int *)varp;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008534#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02008535 int old_global_value = 0;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008536#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008537
Bram Moolenaar071d4272004-06-13 20:20:40 +00008538 /* Disallow changing some options from secure mode */
8539 if ((secure
8540#ifdef HAVE_SANDBOX
8541 || sandbox != 0
8542#endif
8543 ) && (options[opt_idx].flags & P_SECURE))
8544 return e_secure;
8545
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008546#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02008547 // Save the global value before changing anything. This is needed as for
8548 // a global-only option setting the "local value" in fact sets the global
8549 // value (since there is only one value).
8550 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8551 old_global_value = *(int *)get_varp_scope(&(options[opt_idx]),
8552 OPT_GLOBAL);
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008553#endif
Bram Moolenaard7c96872019-06-15 17:12:48 +02008554
Bram Moolenaar071d4272004-06-13 20:20:40 +00008555 *(int *)varp = value; /* set the new value */
8556#ifdef FEAT_EVAL
8557 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008558 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008559#endif
8560
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008561#ifdef FEAT_GUI
8562 need_mouse_correct = TRUE;
8563#endif
8564
Bram Moolenaar071d4272004-06-13 20:20:40 +00008565 /* May set global value for local option. */
8566 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8567 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8568
8569 /*
8570 * Handle side effects of changing a bool option.
8571 */
8572
8573 /* 'compatible' */
8574 if ((int *)varp == &p_cp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008575 compatible_set();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008576
Bram Moolenaar920694c2016-08-21 17:45:02 +02008577#ifdef FEAT_LANGMAP
8578 if ((int *)varp == &p_lrm)
8579 /* 'langremap' -> !'langnoremap' */
8580 p_lnr = !p_lrm;
8581 else if ((int *)varp == &p_lnr)
8582 /* 'langnoremap' -> !'langremap' */
8583 p_lrm = !p_lnr;
8584#endif
8585
Bram Moolenaar8c63e0e2018-09-25 22:17:54 +02008586#ifdef FEAT_SYN_HL
8587 else if ((int *)varp == &curwin->w_p_cul && !value && old_value)
8588 reset_cursorline();
8589#endif
8590
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008591#ifdef FEAT_PERSISTENT_UNDO
8592 /* 'undofile' */
8593 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8594 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008595 /* Only take action when the option was set. When reset we do not
8596 * delete the undo file, the option may be set again without making
8597 * any changes in between. */
8598 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008599 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008600 char_u hash[UNDO_HASH_SIZE];
8601 buf_T *save_curbuf = curbuf;
8602
Bram Moolenaar29323592016-07-24 22:04:11 +02008603 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008604 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008605 /* When 'undofile' is set globally: for every buffer, otherwise
8606 * only for the current buffer: Try to read in the undofile,
8607 * if one exists, the buffer wasn't changed and the buffer was
8608 * loaded */
8609 if ((curbuf == save_curbuf
8610 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8611 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8612 {
8613 u_compute_hash(hash);
8614 u_read_undo(NULL, hash, curbuf->b_fname);
8615 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008616 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008617 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008618 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008619 }
8620#endif
8621
Bram Moolenaar071d4272004-06-13 20:20:40 +00008622 else if ((int *)varp == &curbuf->b_p_ro)
8623 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008624 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008625 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8626 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008627
8628 /* when 'readonly' is set may give W10 again */
8629 if (curbuf->b_p_ro)
8630 curbuf->b_did_warn = FALSE;
8631
Bram Moolenaar071d4272004-06-13 20:20:40 +00008632#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008633 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008634#endif
8635 }
8636
Bram Moolenaar9c449722010-07-20 18:44:27 +02008637#ifdef FEAT_GUI
8638 else if ((int *)varp == &p_mh)
8639 {
8640 if (!p_mh)
8641 gui_mch_mousehide(FALSE);
8642 }
8643#endif
8644
Bram Moolenaara539df02010-08-01 14:35:05 +02008645 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008646 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008647 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008648# ifdef FEAT_TERMINAL
8649 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaard7db27b2018-03-07 23:02:33 +01008650 if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf)
8651 && curbuf->b_term != NULL && !term_is_finished(curbuf))))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008652 {
8653 curbuf->b_p_ma = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008654 return N_("E946: Cannot make a terminal with running job modifiable");
Bram Moolenaar423802d2017-07-30 16:52:24 +02008655 }
8656# endif
8657# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008658 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008659# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008660 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008661#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008662 /* when 'endofline' is changed, redraw the window title */
8663 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008664 {
8665 redraw_titles();
8666 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008667 /* when 'fixeol' is changed, redraw the window title */
8668 else if ((int *)varp == &curbuf->b_p_fixeol)
8669 {
8670 redraw_titles();
8671 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008672 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008673 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008674 {
8675 redraw_titles();
8676 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008677#endif
8678
8679 /* when 'bin' is set also set some other options */
8680 else if ((int *)varp == &curbuf->b_p_bin)
8681 {
8682 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8683#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008684 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008685#endif
8686 }
8687
Bram Moolenaar071d4272004-06-13 20:20:40 +00008688 /* when 'buflisted' changes, trigger autocommands */
8689 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8690 {
8691 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8692 NULL, NULL, TRUE, curbuf);
8693 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008694
8695 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8696 else if ((int *)varp == &curbuf->b_p_swf)
8697 {
8698 if (curbuf->b_p_swf && p_uc)
8699 ml_open_file(curbuf); /* create the swap file */
8700 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008701 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8702 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008703 mf_close_file(curbuf, TRUE); /* remove the swap file */
8704 }
8705
8706 /* when 'terse' is set change 'shortmess' */
8707 else if ((int *)varp == &p_terse)
8708 {
8709 char_u *p;
8710
8711 p = vim_strchr(p_shm, SHM_SEARCH);
8712
8713 /* insert 's' in p_shm */
8714 if (p_terse && p == NULL)
8715 {
8716 STRCPY(IObuff, p_shm);
8717 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008718 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008719 }
8720 /* remove 's' from p_shm */
8721 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008722 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008723 }
8724
8725 /* when 'paste' is set or reset also change other options */
8726 else if ((int *)varp == &p_paste)
8727 {
8728 paste_option_changed();
8729 }
8730
8731 /* when 'insertmode' is set from an autocommand need to do work here */
8732 else if ((int *)varp == &p_im)
8733 {
8734 if (p_im)
8735 {
8736 if ((State & INSERT) == 0)
8737 need_start_insertmode = TRUE;
8738 stop_insert_mode = FALSE;
8739 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008740 /* only reset if it was set previously */
8741 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008742 {
8743 need_start_insertmode = FALSE;
8744 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008745 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008746 clear_cmdline = TRUE; /* remove "(insert)" */
8747 restart_edit = 0;
8748 }
8749 }
8750
8751 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8752 else if ((int *)varp == &p_ic && p_hls)
8753 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008754 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008755 }
8756
8757#ifdef FEAT_SEARCH_EXTRA
8758 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8759 else if ((int *)varp == &p_hls)
8760 {
Bram Moolenaar451fc7b2018-04-27 22:53:07 +02008761 set_no_hlsearch(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008762 }
8763#endif
8764
Bram Moolenaar071d4272004-06-13 20:20:40 +00008765 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8766 * at the end of normal_cmd() */
8767 else if ((int *)varp == &curwin->w_p_scb)
8768 {
8769 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008770 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008771 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008772 curwin->w_scbind_pos = curwin->w_topline;
8773 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008774 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008775
Bram Moolenaar4033c552017-09-16 20:54:51 +02008776#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008777 /* There can be only one window with 'previewwindow' set. */
8778 else if ((int *)varp == &curwin->w_p_pvw)
8779 {
8780 if (curwin->w_p_pvw)
8781 {
8782 win_T *win;
8783
Bram Moolenaar29323592016-07-24 22:04:11 +02008784 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008785 if (win->w_p_pvw && win != curwin)
8786 {
8787 curwin->w_p_pvw = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008788 return N_("E590: A preview window already exists");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008789 }
8790 }
8791 }
8792#endif
8793
8794 /* when 'textmode' is set or reset also change 'fileformat' */
8795 else if ((int *)varp == &curbuf->b_p_tx)
8796 {
8797 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8798 }
8799
8800 /* when 'textauto' is set or reset also change 'fileformats' */
8801 else if ((int *)varp == &p_ta)
Bram Moolenaarabab0b02019-03-30 18:47:01 +01008802 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008803 set_string_option_direct((char_u *)"ffs", -1,
8804 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008805 OPT_FREE | opt_flags, 0);
Bram Moolenaarabab0b02019-03-30 18:47:01 +01008806 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008807
8808 /*
8809 * When 'lisp' option changes include/exclude '-' in
8810 * keyword characters.
8811 */
8812#ifdef FEAT_LISP
8813 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8814 {
8815 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8816 }
8817#endif
8818
8819#ifdef FEAT_TITLE
8820 /* when 'title' changed, may need to change the title; same for 'icon' */
Bram Moolenaar84a93082018-06-16 22:58:15 +02008821 else if ((int *)varp == &p_title || (int *)varp == &p_icon)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008822 {
Bram Moolenaar84a93082018-06-16 22:58:15 +02008823 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008824 }
8825#endif
8826
8827 else if ((int *)varp == &curbuf->b_changed)
8828 {
8829 if (!value)
8830 save_file_ff(curbuf); /* Buffer is unchanged */
8831#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008832 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008833#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008834 modified_was_set = value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008835 }
8836
8837#ifdef BACKSLASH_IN_FILENAME
8838 else if ((int *)varp == &p_ssl)
8839 {
8840 if (p_ssl)
8841 {
8842 psepc = '/';
8843 psepcN = '\\';
8844 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008845 }
8846 else
8847 {
8848 psepc = '\\';
8849 psepcN = '/';
8850 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008851 }
8852
8853 /* need to adjust the file name arguments and buffer names. */
8854 buflist_slash_adjust();
8855 alist_slash_adjust();
8856# ifdef FEAT_EVAL
8857 scriptnames_slash_adjust();
8858# endif
8859 }
8860#endif
8861
8862 /* If 'wrap' is set, set w_leftcol to zero. */
8863 else if ((int *)varp == &curwin->w_p_wrap)
8864 {
8865 if (curwin->w_p_wrap)
8866 curwin->w_leftcol = 0;
8867 }
8868
Bram Moolenaar071d4272004-06-13 20:20:40 +00008869 else if ((int *)varp == &p_ea)
8870 {
8871 if (p_ea && !old_value)
8872 win_equal(curwin, FALSE, 0);
8873 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008874
8875 else if ((int *)varp == &p_wiv)
8876 {
8877 /*
8878 * When 'weirdinvert' changed, set/reset 't_xs'.
8879 * Then set 'weirdinvert' according to value of 't_xs'.
8880 */
8881 if (p_wiv && !old_value)
8882 T_XS = (char_u *)"y";
8883 else if (!p_wiv && old_value)
8884 T_XS = empty_option;
8885 p_wiv = (*T_XS != NUL);
8886 }
8887
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008888#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008889 else if ((int *)varp == &p_beval)
8890 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008891 if (!balloonEvalForTerm)
8892 {
8893 if (p_beval && !old_value)
8894 gui_mch_enable_beval_area(balloonEval);
8895 else if (!p_beval && old_value)
8896 gui_mch_disable_beval_area(balloonEval);
8897 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008898 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008899#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008900#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008901 else if ((int *)varp == &p_bevalterm)
8902 {
8903 mch_bevalterm_changed();
8904 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008905#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008906
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008907#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008908 else if ((int *)varp == &p_acd)
8909 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008910 /* Change directories when the 'acd' option is set now. */
Bram Moolenaar6f470022018-04-10 18:47:20 +02008911 DO_AUTOCHDIR;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008912 }
8913#endif
8914
8915#ifdef FEAT_DIFF
8916 /* 'diff' */
8917 else if ((int *)varp == &curwin->w_p_diff)
8918 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008919 /* May add or remove the buffer from the list of diff buffers. */
8920 diff_buf_adjust(curwin);
8921# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008922 if (foldmethodIsDiff(curwin))
8923 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008924# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008925 }
8926#endif
8927
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008928#ifdef HAVE_INPUT_METHOD
Bram Moolenaar071d4272004-06-13 20:20:40 +00008929 /* 'imdisable' */
8930 else if ((int *)varp == &p_imdisable)
8931 {
8932 /* Only de-activate it here, it will be enabled when changing mode. */
8933 if (p_imdisable)
8934 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008935 else if (State & INSERT)
8936 /* When the option is set from an autocommand, it may need to take
8937 * effect right away. */
8938 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008939 }
8940#endif
8941
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008942#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008943 /* 'spell' */
8944 else if ((int *)varp == &curwin->w_p_spell)
8945 {
8946 if (curwin->w_p_spell)
8947 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008948 char *errmsg = did_set_spelllang(curwin);
8949
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008950 if (errmsg != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008951 emsg(_(errmsg));
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008952 }
8953 }
8954#endif
8955
Bram Moolenaar071d4272004-06-13 20:20:40 +00008956#ifdef FEAT_ARABIC
8957 if ((int *)varp == &curwin->w_p_arab)
8958 {
8959 if (curwin->w_p_arab)
8960 {
8961 /*
8962 * 'arabic' is set, handle various sub-settings.
8963 */
8964 if (!p_tbidi)
8965 {
8966 /* set rightleft mode */
8967 if (!curwin->w_p_rl)
8968 {
8969 curwin->w_p_rl = TRUE;
8970 changed_window_setting();
8971 }
8972
8973 /* Enable Arabic shaping (major part of what Arabic requires) */
8974 if (!p_arshape)
8975 {
8976 p_arshape = TRUE;
8977 redraw_later_clear();
8978 }
8979 }
8980
8981 /* Arabic requires a utf-8 encoding, inform the user if its not
8982 * set. */
8983 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008984 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008985 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8986
Bram Moolenaar8820b482017-03-16 17:23:31 +01008987 msg_source(HL_ATTR(HLF_W));
Bram Moolenaar32526b32019-01-19 17:43:09 +01008988 msg_attr(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008989#ifdef FEAT_EVAL
8990 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8991#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008992 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008993
Bram Moolenaar071d4272004-06-13 20:20:40 +00008994 /* set 'delcombine' */
8995 p_deco = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008996
8997# ifdef FEAT_KEYMAP
8998 /* Force-set the necessary keymap for arabic */
8999 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
9000 OPT_LOCAL);
9001# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009002 }
9003 else
9004 {
9005 /*
9006 * 'arabic' is reset, handle various sub-settings.
9007 */
9008 if (!p_tbidi)
9009 {
9010 /* reset rightleft mode */
9011 if (curwin->w_p_rl)
9012 {
9013 curwin->w_p_rl = FALSE;
9014 changed_window_setting();
9015 }
9016
9017 /* 'arabicshape' isn't reset, it is a global option and
9018 * another window may still need it "on". */
9019 }
9020
9021 /* 'delcombine' isn't reset, it is a global option and another
9022 * window may still want it "on". */
9023
9024# ifdef FEAT_KEYMAP
9025 /* Revert to the default keymap */
9026 curbuf->b_p_iminsert = B_IMODE_NONE;
9027 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
9028# endif
9029 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00009030 }
9031
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00009032#endif
9033
Bram Moolenaar61be73b2016-04-29 22:59:22 +02009034#ifdef FEAT_TERMGUICOLORS
9035 /* 'termguicolors' */
9036 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02009037 {
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009038# ifdef FEAT_VTP
9039 /* Do not turn on 'tgc' when 24-bit colors are not supported. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02009040 if (
9041# ifdef VIMDLL
9042 !gui.in_use && !gui.starting &&
9043# endif
9044 !has_vtp_working())
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009045 {
9046 p_tgc = 0;
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01009047 return N_("E954: 24-bit colors are not supported on this environment");
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009048 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02009049 if (is_term_win32())
9050 swap_tcap();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009051# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02009052# ifdef FEAT_GUI
9053 if (!gui.in_use && !gui.starting)
9054# endif
9055 highlight_gui_started();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009056# ifdef FEAT_VTP
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009057 /* reset t_Co */
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02009058 if (is_term_win32())
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02009059 {
9060 control_console_color_rgb();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009061 set_termname(T_NAME);
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02009062 init_highlight(TRUE, FALSE);
9063 }
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009064# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02009065 }
9066#endif
9067
Bram Moolenaar071d4272004-06-13 20:20:40 +00009068 /*
9069 * End of handling side effects for bool options.
9070 */
9071
Bram Moolenaar53744302015-07-17 17:38:22 +02009072 /* after handling side effects, call autocommand */
9073
Bram Moolenaar071d4272004-06-13 20:20:40 +00009074 options[opt_idx].flags |= P_WAS_SET;
9075
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009076#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009077 // Don't do this while starting up or recursively.
9078 if (!starting && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009079 {
Bram Moolenaard7c96872019-06-15 17:12:48 +02009080 char_u buf_old[2], buf_old_global[2], buf_new[2], buf_type[7];
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009081
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009082 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009083 vim_snprintf((char *)buf_old_global, 2, "%d",
9084 old_global_value ? TRUE: FALSE);
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009085 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009086 vim_snprintf((char *)buf_type, 7, "%s",
9087 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009088 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9089 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9090 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009091 if (opt_flags & OPT_LOCAL)
9092 {
9093 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
9094 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9095 }
9096 if (opt_flags & OPT_GLOBAL)
9097 {
9098 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
9099 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old, -1);
9100 }
9101 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9102 {
9103 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
9104 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9105 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old_global, -1);
9106 }
9107 if (opt_flags & OPT_MODELINE)
9108 {
9109 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
9110 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9111 }
9112 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname,
9113 NULL, FALSE, NULL);
Bram Moolenaar53744302015-07-17 17:38:22 +02009114 reset_v_option_vars();
9115 }
9116#endif
9117
Bram Moolenaar071d4272004-06-13 20:20:40 +00009118 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009119 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009120 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009121 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009122 check_redraw(options[opt_idx].flags);
9123
9124 return NULL;
9125}
9126
9127/*
9128 * Set the value of a number option, and take care of side effects.
9129 * Returns NULL for success, or an error message for an error.
9130 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009131 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009132set_num_option(
9133 int opt_idx, /* index in options[] table */
9134 char_u *varp, /* pointer to the option variable */
9135 long value, /* new value */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009136 char *errbuf, /* buffer for error messages */
Bram Moolenaar9b578142016-01-30 19:39:49 +01009137 size_t errbuflen, /* length of "errbuf" */
9138 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00009139 OPT_MODELINE */
9140{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009141 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009142 long old_value = *(long *)varp;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02009143#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02009144 long old_global_value = 0; // only used when setting a local and
9145 // global option
Bram Moolenaar983f2f12019-06-16 16:41:41 +02009146#endif
Bram Moolenaard7c96872019-06-15 17:12:48 +02009147 long old_Rows = Rows; // remember old Rows
9148 long old_Columns = Columns; // remember old Columns
Bram Moolenaar071d4272004-06-13 20:20:40 +00009149 long *pp = (long *)varp;
9150
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009151 /* Disallow changing some options from secure mode. */
9152 if ((secure
9153#ifdef HAVE_SANDBOX
9154 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00009155#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009156 ) && (options[opt_idx].flags & P_SECURE))
9157 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009158
Bram Moolenaar983f2f12019-06-16 16:41:41 +02009159#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02009160 // Save the global value before changing anything. This is needed as for
9161 // a global-only option setting the "local value" infact sets the global
9162 // value (since there is only one value).
9163 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
Bram Moolenaar983f2f12019-06-16 16:41:41 +02009164 old_global_value = *(long *)get_varp_scope(&(options[opt_idx]),
9165 OPT_GLOBAL);
9166#endif
Bram Moolenaard7c96872019-06-15 17:12:48 +02009167
Bram Moolenaar071d4272004-06-13 20:20:40 +00009168 *pp = value;
9169#ifdef FEAT_EVAL
9170 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02009171 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009172#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009173#ifdef FEAT_GUI
9174 need_mouse_correct = TRUE;
9175#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009176
Bram Moolenaar14f24742012-08-08 18:01:05 +02009177 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009178 {
9179 errmsg = e_positive;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02009180#ifdef FEAT_VARTABS
9181 // Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use.
9182 curbuf->b_p_sw = tabstop_count(curbuf->b_p_vts_array) > 0
9183 ? tabstop_first(curbuf->b_p_vts_array)
9184 : curbuf->b_p_ts;
9185#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00009186 curbuf->b_p_sw = curbuf->b_p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02009187#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009188 }
9189
9190 /*
9191 * Number options that need some action when changed
9192 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009193 if (pp == &p_wh || pp == &p_hh)
9194 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009195 // 'winheight' and 'helpheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009196 if (p_wh < 1)
9197 {
9198 errmsg = e_positive;
9199 p_wh = 1;
9200 }
9201 if (p_wmh > p_wh)
9202 {
9203 errmsg = e_winheight;
9204 p_wh = p_wmh;
9205 }
9206 if (p_hh < 0)
9207 {
9208 errmsg = e_positive;
9209 p_hh = 0;
9210 }
9211
9212 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01009213 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009214 {
9215 if (pp == &p_wh && curwin->w_height < p_wh)
9216 win_setheight((int)p_wh);
9217 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
9218 win_setheight((int)p_hh);
9219 }
9220 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009221 else if (pp == &p_wmh)
9222 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009223 // 'winminheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009224 if (p_wmh < 0)
9225 {
9226 errmsg = e_positive;
9227 p_wmh = 0;
9228 }
9229 if (p_wmh > p_wh)
9230 {
9231 errmsg = e_winheight;
9232 p_wmh = p_wh;
9233 }
9234 win_setminheight();
9235 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009236 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009237 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009238 // 'winwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009239 if (p_wiw < 1)
9240 {
9241 errmsg = e_positive;
9242 p_wiw = 1;
9243 }
9244 if (p_wmw > p_wiw)
9245 {
9246 errmsg = e_winwidth;
9247 p_wiw = p_wmw;
9248 }
9249
9250 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01009251 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009252 win_setwidth((int)p_wiw);
9253 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009254 else if (pp == &p_wmw)
9255 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009256 // 'winminwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009257 if (p_wmw < 0)
9258 {
9259 errmsg = e_positive;
9260 p_wmw = 0;
9261 }
9262 if (p_wmw > p_wiw)
9263 {
9264 errmsg = e_winwidth;
9265 p_wmw = p_wiw;
9266 }
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009267 win_setminwidth();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009268 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009269
Bram Moolenaar071d4272004-06-13 20:20:40 +00009270 /* (re)set last window status line */
9271 else if (pp == &p_ls)
9272 {
9273 last_status(FALSE);
9274 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009275
9276 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00009277 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009278 {
9279 shell_new_rows(); /* recompute window positions and heights */
9280 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009281
9282#ifdef FEAT_GUI
9283 else if (pp == &p_linespace)
9284 {
Bram Moolenaar02743632005-07-25 20:42:36 +00009285 /* Recompute gui.char_height and resize the Vim window to keep the
9286 * same number of lines. */
9287 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00009288 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009289 }
9290#endif
9291
9292#ifdef FEAT_FOLDING
9293 /* 'foldlevel' */
9294 else if (pp == &curwin->w_p_fdl)
9295 {
9296 if (curwin->w_p_fdl < 0)
9297 curwin->w_p_fdl = 0;
9298 newFoldLevel();
9299 }
9300
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00009301 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009302 else if (pp == &curwin->w_p_fml)
9303 {
9304 foldUpdateAll(curwin);
9305 }
9306
9307 /* 'foldnestmax' */
9308 else if (pp == &curwin->w_p_fdn)
9309 {
9310 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
9311 foldUpdateAll(curwin);
9312 }
9313
9314 /* 'foldcolumn' */
9315 else if (pp == &curwin->w_p_fdc)
9316 {
9317 if (curwin->w_p_fdc < 0)
9318 {
9319 errmsg = e_positive;
9320 curwin->w_p_fdc = 0;
9321 }
9322 else if (curwin->w_p_fdc > 12)
9323 {
9324 errmsg = e_invarg;
9325 curwin->w_p_fdc = 12;
9326 }
9327 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009328#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009329
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009330#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009331 /* 'shiftwidth' or 'tabstop' */
9332 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
9333 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009334# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00009335 if (foldmethodIsIndent(curwin))
9336 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009337# endif
9338# ifdef FEAT_CINDENT
9339 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
9340 * parse 'cinoptions'. */
9341 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
9342 parse_cino(curbuf);
9343# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009344 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009345#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009346
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009347 /* 'maxcombine' */
9348 else if (pp == &p_mco)
9349 {
9350 if (p_mco > MAX_MCO)
9351 p_mco = MAX_MCO;
9352 else if (p_mco < 0)
9353 p_mco = 0;
9354 screenclear(); /* will re-allocate the screen */
9355 }
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009356
Bram Moolenaar071d4272004-06-13 20:20:40 +00009357 else if (pp == &curbuf->b_p_iminsert)
9358 {
9359 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
9360 {
9361 errmsg = e_invarg;
9362 curbuf->b_p_iminsert = B_IMODE_NONE;
9363 }
9364 p_iminsert = curbuf->b_p_iminsert;
9365 if (termcap_active) /* don't do this in the alternate screen */
9366 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02009367#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009368 /* Show/unshow value of 'keymap' in status lines. */
9369 status_redraw_curbuf();
9370#endif
9371 }
9372
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02009373#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
9374 /* 'imstyle' */
9375 else if (pp == &p_imst)
9376 {
9377 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
9378 errmsg = e_invarg;
9379 }
9380#endif
9381
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009382 else if (pp == &p_window)
9383 {
9384 if (p_window < 1)
9385 p_window = 1;
9386 else if (p_window >= Rows)
9387 p_window = Rows - 1;
9388 }
9389
Bram Moolenaar071d4272004-06-13 20:20:40 +00009390 else if (pp == &curbuf->b_p_imsearch)
9391 {
9392 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
9393 {
9394 errmsg = e_invarg;
9395 curbuf->b_p_imsearch = B_IMODE_NONE;
9396 }
9397 p_imsearch = curbuf->b_p_imsearch;
9398 }
9399
9400#ifdef FEAT_TITLE
9401 /* if 'titlelen' has changed, redraw the title */
9402 else if (pp == &p_titlelen)
9403 {
9404 if (p_titlelen < 0)
9405 {
9406 errmsg = e_positive;
9407 p_titlelen = 85;
9408 }
9409 if (starting != NO_SCREEN && old_value != p_titlelen)
9410 need_maketitle = TRUE;
9411 }
9412#endif
9413
9414 /* if p_ch changed value, change the command line height */
9415 else if (pp == &p_ch)
9416 {
9417 if (p_ch < 1)
9418 {
9419 errmsg = e_positive;
9420 p_ch = 1;
9421 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009422 if (p_ch > Rows - min_rows() + 1)
9423 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009424
9425 /* Only compute the new window layout when startup has been
9426 * completed. Otherwise the frame sizes may be wrong. */
9427 if (p_ch != old_value && full_screen
9428#ifdef FEAT_GUI
9429 && !gui.starting
9430#endif
9431 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009432 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009433 }
9434
9435 /* when 'updatecount' changes from zero to non-zero, open swap files */
9436 else if (pp == &p_uc)
9437 {
9438 if (p_uc < 0)
9439 {
9440 errmsg = e_positive;
9441 p_uc = 100;
9442 }
9443 if (p_uc && !old_value)
9444 ml_open_files();
9445 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009446#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009447 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009448 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009449 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009450 {
9451 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009452 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009453 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009454 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009455 {
9456 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009457 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009458 }
9459 }
9460#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009461#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009462 else if (pp == &p_mzq)
9463 mzvim_reset_timer();
9464#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009465
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009466#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9467 /* 'pyxversion' */
9468 else if (pp == &p_pyx)
9469 {
9470 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9471 errmsg = e_invarg;
9472 }
9473#endif
9474
Bram Moolenaar071d4272004-06-13 20:20:40 +00009475 /* sync undo before 'undolevels' changes */
9476 else if (pp == &p_ul)
9477 {
9478 /* use the old value, otherwise u_sync() may not work properly */
9479 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009480 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009481 p_ul = value;
9482 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009483 else if (pp == &curbuf->b_p_ul)
9484 {
9485 /* use the old value, otherwise u_sync() may not work properly */
9486 curbuf->b_p_ul = old_value;
9487 u_sync(TRUE);
9488 curbuf->b_p_ul = value;
9489 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009490
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009491#ifdef FEAT_LINEBREAK
9492 /* 'numberwidth' must be positive */
9493 else if (pp == &curwin->w_p_nuw)
9494 {
9495 if (curwin->w_p_nuw < 1)
9496 {
9497 errmsg = e_positive;
9498 curwin->w_p_nuw = 1;
9499 }
Bram Moolenaarf8a07122019-07-01 22:06:07 +02009500 if (curwin->w_p_nuw > 20)
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009501 {
9502 errmsg = e_invarg;
Bram Moolenaarf8a07122019-07-01 22:06:07 +02009503 curwin->w_p_nuw = 20;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009504 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009505 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009506 }
9507#endif
9508
Bram Moolenaar1a384422010-07-14 19:53:30 +02009509 else if (pp == &curbuf->b_p_tw)
9510 {
9511 if (curbuf->b_p_tw < 0)
9512 {
9513 errmsg = e_positive;
9514 curbuf->b_p_tw = 0;
9515 }
9516#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009517 {
9518 win_T *wp;
9519 tabpage_T *tp;
9520
9521 FOR_ALL_TAB_WINDOWS(tp, wp)
9522 check_colorcolumn(wp);
9523 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009524#endif
9525 }
9526
Bram Moolenaar071d4272004-06-13 20:20:40 +00009527 /*
9528 * Check the bounds for numeric options here
9529 */
9530 if (Rows < min_rows() && full_screen)
9531 {
9532 if (errbuf != NULL)
9533 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009534 vim_snprintf((char *)errbuf, errbuflen,
9535 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009536 errmsg = errbuf;
9537 }
9538 Rows = min_rows();
9539 }
9540 if (Columns < MIN_COLUMNS && full_screen)
9541 {
9542 if (errbuf != NULL)
9543 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009544 vim_snprintf((char *)errbuf, errbuflen,
9545 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009546 errmsg = errbuf;
9547 }
9548 Columns = MIN_COLUMNS;
9549 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009550 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009551
Bram Moolenaar071d4272004-06-13 20:20:40 +00009552 /*
9553 * If the screen (shell) height has been changed, assume it is the
9554 * physical screenheight.
9555 */
9556 if (old_Rows != Rows || old_Columns != Columns)
9557 {
9558 /* Changing the screen size is not allowed while updating the screen. */
9559 if (updating_screen)
9560 *pp = old_value;
9561 else if (full_screen
9562#ifdef FEAT_GUI
9563 && !gui.starting
9564#endif
9565 )
9566 set_shellsize((int)Columns, (int)Rows, TRUE);
9567 else
9568 {
9569 /* Postpone the resizing; check the size and cmdline position for
9570 * messages. */
9571 check_shellsize();
9572 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9573 cmdline_row = Rows - p_ch;
9574 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009575 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009576 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009577 }
9578
Bram Moolenaar071d4272004-06-13 20:20:40 +00009579 if (curbuf->b_p_ts <= 0)
9580 {
9581 errmsg = e_positive;
9582 curbuf->b_p_ts = 8;
9583 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009584 if (p_tm < 0)
9585 {
9586 errmsg = e_positive;
9587 p_tm = 0;
9588 }
9589 if ((curwin->w_p_scr <= 0
9590 || (curwin->w_p_scr > curwin->w_height
9591 && curwin->w_height > 0))
9592 && full_screen)
9593 {
9594 if (pp == &(curwin->w_p_scr))
9595 {
9596 if (curwin->w_p_scr != 0)
9597 errmsg = e_scroll;
9598 win_comp_scroll(curwin);
9599 }
9600 /* If 'scroll' became invalid because of a side effect silently adjust
9601 * it. */
9602 else if (curwin->w_p_scr <= 0)
9603 curwin->w_p_scr = 1;
9604 else /* curwin->w_p_scr > curwin->w_height */
9605 curwin->w_p_scr = curwin->w_height;
9606 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009607 if (p_hi < 0)
9608 {
9609 errmsg = e_positive;
9610 p_hi = 0;
9611 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009612 else if (p_hi > 10000)
9613 {
9614 errmsg = e_invarg;
9615 p_hi = 10000;
9616 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009617 if (p_re < 0 || p_re > 2)
9618 {
9619 errmsg = e_invarg;
9620 p_re = 0;
9621 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009622 if (p_report < 0)
9623 {
9624 errmsg = e_positive;
9625 p_report = 1;
9626 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009627 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009628 {
9629 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9630 p_sj = Rows / 2;
9631 else
9632 {
9633 errmsg = e_scroll;
9634 p_sj = 1;
9635 }
9636 }
9637 if (p_so < 0 && full_screen)
9638 {
Bram Moolenaar375e3392019-01-31 18:26:10 +01009639 errmsg = e_positive;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009640 p_so = 0;
9641 }
9642 if (p_siso < 0 && full_screen)
9643 {
9644 errmsg = e_positive;
9645 p_siso = 0;
9646 }
9647#ifdef FEAT_CMDWIN
9648 if (p_cwh < 1)
9649 {
9650 errmsg = e_positive;
9651 p_cwh = 1;
9652 }
9653#endif
9654 if (p_ut < 0)
9655 {
9656 errmsg = e_positive;
9657 p_ut = 2000;
9658 }
9659 if (p_ss < 0)
9660 {
9661 errmsg = e_positive;
9662 p_ss = 0;
9663 }
9664
9665 /* May set global value for local option. */
9666 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9667 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9668
9669 options[opt_idx].flags |= P_WAS_SET;
9670
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009671#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009672 // Don't do this while starting up, failure or recursively.
9673 if (!starting && errmsg == NULL && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009674 {
Bram Moolenaard7c96872019-06-15 17:12:48 +02009675 char_u buf_old[11], buf_old_global[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009676 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009677 vim_snprintf((char *)buf_old_global, 10, "%ld", old_global_value);
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009678 vim_snprintf((char *)buf_new, 10, "%ld", value);
9679 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009680 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9681 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9682 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009683 if (opt_flags & OPT_LOCAL)
9684 {
9685 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
9686 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9687 }
9688 if (opt_flags & OPT_GLOBAL)
9689 {
9690 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
9691 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old, -1);
9692 }
9693 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9694 {
9695 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
9696 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9697 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old_global, -1);
9698 }
9699 if (opt_flags & OPT_MODELINE)
9700 {
9701 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
9702 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9703 }
9704 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname,
9705 NULL, FALSE, NULL);
Bram Moolenaar53744302015-07-17 17:38:22 +02009706 reset_v_option_vars();
9707 }
9708#endif
9709
Bram Moolenaar071d4272004-06-13 20:20:40 +00009710 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009711 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009712 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009713 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009714 check_redraw(options[opt_idx].flags);
9715
9716 return errmsg;
9717}
9718
9719/*
9720 * Called after an option changed: check if something needs to be redrawn.
9721 */
9722 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009723check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009724{
9725 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009726 int doclear = (flags & P_RCLR) == P_RCLR;
9727 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009728
Bram Moolenaar071d4272004-06-13 20:20:40 +00009729 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9730 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009731
9732 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9733 changed_window_setting();
9734 if (flags & P_RBUF)
9735 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009736 if (flags & P_RWINONLY)
9737 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009738 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009739 redraw_all_later(CLEAR);
9740 else if (all)
9741 redraw_all_later(NOT_VALID);
9742}
9743
9744/*
9745 * Find index for option 'arg'.
9746 * Return -1 if not found.
9747 */
9748 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009749findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009750{
9751 int opt_idx;
9752 char *s, *p;
9753 static short quick_tab[27] = {0, 0}; /* quick access table */
9754 int is_term_opt;
9755
9756 /*
9757 * For first call: Initialize the quick-access table.
9758 * It contains the index for the first option that starts with a certain
9759 * letter. There are 26 letters, plus the first "t_" option.
9760 */
9761 if (quick_tab[1] == 0)
9762 {
9763 p = options[0].fullname;
9764 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9765 {
9766 if (s[0] != p[0])
9767 {
9768 if (s[0] == 't' && s[1] == '_')
9769 quick_tab[26] = opt_idx;
9770 else
9771 quick_tab[CharOrdLow(s[0])] = opt_idx;
9772 }
9773 p = s;
9774 }
9775 }
9776
9777 /*
9778 * Check for name starting with an illegal character.
9779 */
9780#ifdef EBCDIC
9781 if (!islower(arg[0]))
9782#else
9783 if (arg[0] < 'a' || arg[0] > 'z')
9784#endif
9785 return -1;
9786
9787 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9788 if (is_term_opt)
9789 opt_idx = quick_tab[26];
9790 else
9791 opt_idx = quick_tab[CharOrdLow(arg[0])];
9792 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9793 {
9794 if (STRCMP(arg, s) == 0) /* match full name */
9795 break;
9796 }
9797 if (s == NULL && !is_term_opt)
9798 {
9799 opt_idx = quick_tab[CharOrdLow(arg[0])];
9800 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9801 {
9802 s = options[opt_idx].shortname;
9803 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9804 break;
9805 s = NULL;
9806 }
9807 }
9808 if (s == NULL)
9809 opt_idx = -1;
9810 return opt_idx;
9811}
9812
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009813#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009814/*
9815 * Get the value for an option.
9816 *
9817 * Returns:
9818 * Number or Toggle option: 1, *numval gets value.
9819 * String option: 0, *stringval gets allocated string.
9820 * Hidden Number or Toggle option: -1.
9821 * hidden String option: -2.
9822 * unknown option: -3.
9823 */
9824 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009825get_option_value(
9826 char_u *name,
9827 long *numval,
9828 char_u **stringval, /* NULL when only checking existence */
9829 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009830{
9831 int opt_idx;
9832 char_u *varp;
9833
9834 opt_idx = findoption(name);
9835 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009836 {
9837 int key;
9838
9839 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009840 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009841 {
9842 char_u key_name[2];
9843 char_u *p;
9844
9845 if (key < 0)
9846 {
9847 key_name[0] = KEY2TERMCAP0(key);
9848 key_name[1] = KEY2TERMCAP1(key);
9849 }
9850 else
9851 {
9852 key_name[0] = KS_KEY;
9853 key_name[1] = (key & 0xff);
9854 }
9855 p = find_termcode(key_name);
9856 if (p != NULL)
9857 {
9858 if (stringval != NULL)
9859 *stringval = vim_strsave(p);
9860 return 0;
9861 }
9862 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009863 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009864 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009865
9866 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9867
9868 if (options[opt_idx].flags & P_STRING)
9869 {
9870 if (varp == NULL) /* hidden option */
9871 return -2;
9872 if (stringval != NULL)
9873 {
9874#ifdef FEAT_CRYPT
9875 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009876 if ((char_u **)varp == &curbuf->b_p_key
9877 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009878 *stringval = vim_strsave((char_u *)"*****");
9879 else
9880#endif
9881 *stringval = vim_strsave(*(char_u **)(varp));
9882 }
9883 return 0;
9884 }
9885
9886 if (varp == NULL) /* hidden option */
9887 return -1;
9888 if (options[opt_idx].flags & P_NUM)
9889 *numval = *(long *)varp;
9890 else
9891 {
9892 /* Special case: 'modified' is b_changed, but we also want to consider
9893 * it set when 'ff' or 'fenc' changed. */
9894 if ((int *)varp == &curbuf->b_changed)
9895 *numval = curbufIsChanged();
9896 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009897 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009898 }
9899 return 1;
9900}
9901#endif
9902
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009903#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009904/*
9905 * Returns the option attributes and its value. Unlike the above function it
9906 * will return either global value or local value of the option depending on
9907 * what was requested, but it will never return global value if it was
9908 * requested to return local one and vice versa. Neither it will return
9909 * buffer-local value if it was requested to return window-local one.
9910 *
9911 * Pretends that option is absent if it is not present in the requested scope
9912 * (i.e. has no global, window-local or buffer-local value depending on
9913 * opt_type). Uses
9914 *
9915 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009916 * 0 hidden or unknown option, also option that does not have requested
9917 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009918 * see SOPT_* in vim.h for other flags
9919 *
9920 * Possible opt_type values: see SREQ_* in vim.h
9921 */
9922 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009923get_option_value_strict(
9924 char_u *name,
9925 long *numval,
9926 char_u **stringval, /* NULL when only obtaining attributes */
9927 int opt_type,
9928 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009929{
9930 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009931 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009932 struct vimoption *p;
9933 int r = 0;
9934
9935 opt_idx = findoption(name);
9936 if (opt_idx < 0)
9937 return 0;
9938
9939 p = &(options[opt_idx]);
9940
9941 /* Hidden option */
9942 if (p->var == NULL)
9943 return 0;
9944
9945 if (p->flags & P_BOOL)
9946 r |= SOPT_BOOL;
9947 else if (p->flags & P_NUM)
9948 r |= SOPT_NUM;
9949 else if (p->flags & P_STRING)
9950 r |= SOPT_STRING;
9951
9952 if (p->indir == PV_NONE)
9953 {
9954 if (opt_type == SREQ_GLOBAL)
9955 r |= SOPT_GLOBAL;
9956 else
9957 return 0; /* Did not request global-only option */
9958 }
9959 else
9960 {
9961 if (p->indir & PV_BOTH)
9962 r |= SOPT_GLOBAL;
9963 else if (opt_type == SREQ_GLOBAL)
9964 return 0; /* Requested global option */
9965
9966 if (p->indir & PV_WIN)
9967 {
9968 if (opt_type == SREQ_BUF)
9969 return 0; /* Did not request window-local option */
9970 else
9971 r |= SOPT_WIN;
9972 }
9973 else if (p->indir & PV_BUF)
9974 {
9975 if (opt_type == SREQ_WIN)
9976 return 0; /* Did not request buffer-local option */
9977 else
9978 r |= SOPT_BUF;
9979 }
9980 }
9981
9982 if (stringval == NULL)
9983 return r;
9984
9985 if (opt_type == SREQ_GLOBAL)
9986 varp = p->var;
9987 else
9988 {
9989 if (opt_type == SREQ_BUF)
9990 {
9991 /* Special case: 'modified' is b_changed, but we also want to
9992 * consider it set when 'ff' or 'fenc' changed. */
9993 if (p->indir == PV_MOD)
9994 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009995 *numval = bufIsChanged((buf_T *)from);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009996 varp = NULL;
9997 }
9998#ifdef FEAT_CRYPT
9999 else if (p->indir == PV_KEY)
10000 {
10001 /* never return the value of the crypt key */
10002 *stringval = NULL;
10003 varp = NULL;
10004 }
10005#endif
10006 else
10007 {
Bram Moolenaardefe6422018-06-24 15:14:07 +020010008 buf_T *save_curbuf = curbuf;
10009
10010 // only getting a pointer, no need to use aucmd_prepbuf()
10011 curbuf = (buf_T *)from;
10012 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010013 varp = get_varp(p);
Bram Moolenaardefe6422018-06-24 15:14:07 +020010014 curbuf = save_curbuf;
10015 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010016 }
10017 }
10018 else if (opt_type == SREQ_WIN)
10019 {
Bram Moolenaardefe6422018-06-24 15:14:07 +020010020 win_T *save_curwin = curwin;
10021
10022 curwin = (win_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010023 curbuf = curwin->w_buffer;
10024 varp = get_varp(p);
10025 curwin = save_curwin;
10026 curbuf = curwin->w_buffer;
10027 }
10028 if (varp == p->var)
10029 return (r | SOPT_UNSET);
10030 }
10031
10032 if (varp != NULL)
10033 {
10034 if (p->flags & P_STRING)
10035 *stringval = vim_strsave(*(char_u **)(varp));
10036 else if (p->flags & P_NUM)
10037 *numval = *(long *) varp;
10038 else
10039 *numval = *(int *)varp;
10040 }
10041
10042 return r;
10043}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010044
10045/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010046 * Iterate over options. First argument is a pointer to a pointer to a
10047 * structure inside options[] array, second is option type like in the above
10048 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010049 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010050 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010051 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010052 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010053 * first argument to NULL.
10054 *
10055 * Returns full option name for current option on each call.
10056 */
10057 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010058option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010059{
10060 struct vimoption *ret = NULL;
10061 do
10062 {
10063 if (*option == NULL)
10064 *option = (void *) options;
10065 else if (((struct vimoption *) (*option))->fullname == NULL)
10066 {
10067 *option = NULL;
10068 return NULL;
10069 }
10070 else
10071 *option = (void *) (((struct vimoption *) (*option)) + 1);
10072
10073 ret = ((struct vimoption *) (*option));
10074
10075 /* Hidden option */
10076 if (ret->var == NULL)
10077 {
10078 ret = NULL;
10079 continue;
10080 }
10081
10082 switch (opt_type)
10083 {
10084 case SREQ_GLOBAL:
10085 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
10086 ret = NULL;
10087 break;
10088 case SREQ_BUF:
10089 if (!(ret->indir & PV_BUF))
10090 ret = NULL;
10091 break;
10092 case SREQ_WIN:
10093 if (!(ret->indir & PV_WIN))
10094 ret = NULL;
10095 break;
10096 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +010010097 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010098 return NULL;
10099 }
10100 }
10101 while (ret == NULL);
10102
10103 return (char_u *)ret->fullname;
10104}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010105#endif
10106
Bram Moolenaar071d4272004-06-13 20:20:40 +000010107/*
10108 * Set the value of option "name".
10109 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010110 *
10111 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010112 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010113 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010114set_option_value(
10115 char_u *name,
10116 long number,
10117 char_u *string,
10118 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010119{
10120 int opt_idx;
10121 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +000010122 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010123
10124 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010125 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +010010126 {
10127 int key;
10128
10129 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010130 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +010010131 {
10132 char_u key_name[2];
10133
10134 if (key < 0)
10135 {
10136 key_name[0] = KEY2TERMCAP0(key);
10137 key_name[1] = KEY2TERMCAP1(key);
10138 }
10139 else
10140 {
10141 key_name[0] = KS_KEY;
10142 key_name[1] = (key & 0xff);
10143 }
10144 add_termcode(key_name, string, FALSE);
10145 if (full_screen)
10146 ttest(FALSE);
10147 redraw_all_later(CLEAR);
10148 return NULL;
10149 }
10150
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010151 semsg(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +010010152 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010153 else
10154 {
10155 flags = options[opt_idx].flags;
10156#ifdef HAVE_SANDBOX
10157 /* Disallow changing some options in the sandbox */
10158 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010159 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010160 emsg(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010161 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010162 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010163#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010164 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010165 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010166 else
10167 {
Bram Moolenaarb3163762008-07-08 15:15:08 +000010168 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010169 if (varp != NULL) /* hidden option is not changed */
10170 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010171 if (number == 0 && string != NULL)
10172 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +000010173 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010174
10175 /* Either we are given a string or we are setting option
10176 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +000010177 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010178 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +000010179 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010180 {
10181 /* There's another character after zeros or the string
10182 * is empty. In both cases, we are trying to set a
10183 * num option using a string. */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010184 semsg(_("E521: Number required: &%s = '%s'"),
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010185 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010186 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010187
10188 }
10189 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010190 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010191 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +000010192 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010193 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010194 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010195 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010196 }
10197 }
10198 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010199 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010200}
10201
10202/*
10203 * Get the terminal code for a terminal option.
10204 * Returns NULL when not found.
10205 */
10206 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010207get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010208{
10209 int opt_idx;
10210 char_u *varp;
10211
10212 if (tname[0] != 't' || tname[1] != '_' ||
10213 tname[2] == NUL || tname[3] == NUL)
10214 return NULL;
10215 if ((opt_idx = findoption(tname)) >= 0)
10216 {
10217 varp = get_varp(&(options[opt_idx]));
10218 if (varp != NULL)
10219 varp = *(char_u **)(varp);
10220 return varp;
10221 }
10222 return find_termcode(tname + 2);
10223}
10224
10225 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010226get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010227{
10228 int i;
10229
10230 i = findoption((char_u *)"hl");
10231 if (i >= 0)
10232 return options[i].def_val[VI_DEFAULT];
10233 return (char_u *)NULL;
10234}
10235
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010236 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010237get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010238{
10239 int i;
10240
10241 i = findoption((char_u *)"enc");
10242 if (i >= 0)
10243 return options[i].def_val[VI_DEFAULT];
10244 return (char_u *)NULL;
10245}
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010246
Bram Moolenaar071d4272004-06-13 20:20:40 +000010247/*
10248 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010249 * When "has_lt" is true there is a '<' before "*arg_arg".
10250 * Returns 0 when the key is not recognized.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010251 */
10252 static int
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010253find_key_option(char_u *arg_arg, int has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010254{
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010255 int key = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010256 int modifiers;
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010257 char_u *arg = arg_arg;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010258
10259 /*
10260 * Don't use get_special_key_code() for t_xx, we don't want it to call
10261 * add_termcap_entry().
10262 */
10263 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
10264 key = TERMCAP2KEY(arg[2], arg[3]);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010265 else if (has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010266 {
10267 --arg; /* put arg at the '<' */
10268 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +020010269 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010270 if (modifiers) /* can't handle modifiers here */
10271 key = 0;
10272 }
10273 return key;
10274}
10275
10276/*
10277 * if 'all' == 0: show changed options
10278 * if 'all' == 1: show all normal options
10279 * if 'all' == 2: show all terminal options
10280 */
10281 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010282showoptions(
10283 int all,
10284 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010285{
10286 struct vimoption *p;
10287 int col;
10288 int isterm;
10289 char_u *varp;
10290 struct vimoption **items;
10291 int item_count;
10292 int run;
10293 int row, rows;
10294 int cols;
10295 int i;
10296 int len;
10297
10298#define INC 20
10299#define GAP 3
10300
Bram Moolenaarc799fe22019-05-28 23:08:19 +020010301 items = ALLOC_MULT(struct vimoption *, PARAM_COUNT);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010302 if (items == NULL)
10303 return;
10304
10305 /* Highlight title */
10306 if (all == 2)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010307 msg_puts_title(_("\n--- Terminal codes ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010308 else if (opt_flags & OPT_GLOBAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010309 msg_puts_title(_("\n--- Global option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010310 else if (opt_flags & OPT_LOCAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010311 msg_puts_title(_("\n--- Local option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010312 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010313 msg_puts_title(_("\n--- Options ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010314
10315 /*
10316 * do the loop two times:
10317 * 1. display the short items
10318 * 2. display the long items (only strings and numbers)
10319 */
10320 for (run = 1; run <= 2 && !got_int; ++run)
10321 {
10322 /*
10323 * collect the items in items[]
10324 */
10325 item_count = 0;
10326 for (p = &options[0]; p->fullname != NULL; p++)
10327 {
Bram Moolenaarf86db782018-10-25 13:31:37 +020010328 // apply :filter /pat/
10329 if (message_filtered((char_u *) p->fullname))
10330 continue;
10331
Bram Moolenaar071d4272004-06-13 20:20:40 +000010332 varp = NULL;
10333 isterm = istermoption(p);
10334 if (opt_flags != 0)
10335 {
10336 if (p->indir != PV_NONE && !isterm)
10337 varp = get_varp_scope(p, opt_flags);
10338 }
10339 else
10340 varp = get_varp(p);
10341 if (varp != NULL
10342 && ((all == 2 && isterm)
10343 || (all == 1 && !isterm)
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010344 || (all == 0 && !optval_default(p, varp, p_cp))))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010345 {
10346 if (p->flags & P_BOOL)
10347 len = 1; /* a toggle option fits always */
10348 else
10349 {
10350 option_value2string(p, opt_flags);
10351 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
10352 }
10353 if ((len <= INC - GAP && run == 1) ||
10354 (len > INC - GAP && run == 2))
10355 items[item_count++] = p;
10356 }
10357 }
10358
10359 /*
10360 * display the items
10361 */
10362 if (run == 1)
10363 {
10364 cols = (Columns + GAP - 3) / INC;
10365 if (cols == 0)
10366 cols = 1;
10367 rows = (item_count + cols - 1) / cols;
10368 }
10369 else /* run == 2 */
10370 rows = item_count;
10371 for (row = 0; row < rows && !got_int; ++row)
10372 {
10373 msg_putchar('\n'); /* go to next line */
10374 if (got_int) /* 'q' typed in more */
10375 break;
10376 col = 0;
10377 for (i = row; i < item_count; i += rows)
10378 {
10379 msg_col = col; /* make columns */
10380 showoneopt(items[i], opt_flags);
10381 col += INC;
10382 }
10383 out_flush();
10384 ui_breakcheck();
10385 }
10386 }
10387 vim_free(items);
10388}
10389
10390/*
10391 * Return TRUE if option "p" has its default value.
10392 */
10393 static int
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010394optval_default(struct vimoption *p, char_u *varp, int compatible)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010395{
10396 int dvi;
10397
10398 if (varp == NULL)
10399 return TRUE; /* hidden option is always at default */
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010400 dvi = ((p->flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010401 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010402 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010403 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010404 /* the cast to long is required for Manx C, long_i is
10405 * needed for MSVC */
10406 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010407 /* P_STRING */
10408 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
10409}
10410
10411/*
10412 * showoneopt: show the value of one option
10413 * must not be called with a hidden option!
10414 */
10415 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010416showoneopt(
10417 struct vimoption *p,
10418 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010419{
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010420 char_u *varp;
10421 int save_silent = silent_mode;
10422
10423 silent_mode = FALSE;
10424 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010425
10426 varp = get_varp_scope(p, opt_flags);
10427
10428 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
10429 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
10430 ? !curbufIsChanged() : !*(int *)varp))
Bram Moolenaar32526b32019-01-19 17:43:09 +010010431 msg_puts("no");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010432 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010433 msg_puts("--");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010434 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010435 msg_puts(" ");
10436 msg_puts(p->fullname);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010437 if (!(p->flags & P_BOOL))
10438 {
10439 msg_putchar('=');
10440 /* put value string in NameBuff */
10441 option_value2string(p, opt_flags);
10442 msg_outtrans(NameBuff);
10443 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010444
10445 silent_mode = save_silent;
10446 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010447}
10448
10449/*
10450 * Write modified options as ":set" commands to a file.
10451 *
10452 * There are three values for "opt_flags":
10453 * OPT_GLOBAL: Write global option values and fresh values of
10454 * buffer-local options (used for start of a session
10455 * file).
10456 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10457 * curwin (used for a vimrc file).
10458 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10459 * and local values for window-local options of
10460 * curwin. Local values are also written when at the
10461 * default value, because a modeline or autocommand
10462 * may have set them when doing ":edit file" and the
10463 * user has set them back at the default or fresh
10464 * value.
10465 * When "local_only" is TRUE, don't write fresh
10466 * values, only local values (for ":mkview").
10467 * (fresh value = value used for a new buffer or window for a local option).
10468 *
10469 * Return FAIL on error, OK otherwise.
10470 */
10471 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010472makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010473{
10474 struct vimoption *p;
10475 char_u *varp; /* currently used value */
10476 char_u *varp_fresh; /* local value */
10477 char_u *varp_local = NULL; /* fresh value */
10478 char *cmd;
10479 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010480 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010481
10482 /*
10483 * The options that don't have a default (terminal name, columns, lines)
10484 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010485 * Do the loop over "options[]" twice: once for options with the
10486 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010487 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010488 for (pri = 1; pri >= 0; --pri)
10489 {
10490 for (p = &options[0]; !istermoption(p); p++)
10491 if (!(p->flags & P_NO_MKRC)
10492 && !istermoption(p)
10493 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010494 {
10495 /* skip global option when only doing locals */
10496 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10497 continue;
10498
10499 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10500 * file, they are always buffer-specific. */
10501 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10502 continue;
10503
10504 /* Global values are only written when not at the default value. */
10505 varp = get_varp_scope(p, opt_flags);
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010506 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp, p_cp))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010507 continue;
10508
10509 round = 2;
10510 if (p->indir != PV_NONE)
10511 {
10512 if (p->var == VAR_WIN)
10513 {
10514 /* skip window-local option when only doing globals */
10515 if (!(opt_flags & OPT_LOCAL))
10516 continue;
10517 /* When fresh value of window-local option is not at the
10518 * default, need to write it too. */
10519 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10520 {
10521 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010522 if (!optval_default(p, varp_fresh, p_cp))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010523 {
10524 round = 1;
10525 varp_local = varp;
10526 varp = varp_fresh;
10527 }
10528 }
10529 }
10530 }
10531
10532 /* Round 1: fresh value for window-local options.
10533 * Round 2: other values */
10534 for ( ; round <= 2; varp = varp_local, ++round)
10535 {
10536 if (round == 1 || (opt_flags & OPT_GLOBAL))
10537 cmd = "set";
10538 else
10539 cmd = "setlocal";
10540
10541 if (p->flags & P_BOOL)
10542 {
10543 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10544 return FAIL;
10545 }
10546 else if (p->flags & P_NUM)
10547 {
10548 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10549 return FAIL;
10550 }
10551 else /* P_STRING */
10552 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010553 int do_endif = FALSE;
10554
Bram Moolenaar071d4272004-06-13 20:20:40 +000010555 /* Don't set 'syntax' and 'filetype' again if the value is
10556 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010557 if (
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +010010558#if defined(FEAT_SYN_HL)
10559 p->indir == PV_SYN ||
10560#endif
10561 p->indir == PV_FT)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010562 {
10563 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10564 *(char_u **)(varp)) < 0
10565 || put_eol(fd) < 0)
10566 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010567 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010568 }
10569 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010570 p->flags) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010571 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010572 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010573 {
10574 if (put_line(fd, "endif") == FAIL)
10575 return FAIL;
10576 }
10577 }
10578 }
10579 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010580 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010581 return OK;
10582}
10583
10584#if defined(FEAT_FOLDING) || defined(PROTO)
10585/*
10586 * Generate set commands for the local fold options only. Used when
10587 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10588 */
10589 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010590makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010591{
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010592 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, 0) == FAIL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010593# ifdef FEAT_EVAL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010594 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010595 == FAIL
10596# endif
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010597 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010598 == FAIL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010599 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010600 == FAIL
10601 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10602 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10603 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10604 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10605 )
10606 return FAIL;
10607
10608 return OK;
10609}
10610#endif
10611
10612 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010613put_setstring(
10614 FILE *fd,
10615 char *cmd,
10616 char *name,
10617 char_u **valuep,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010618 long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010619{
10620 char_u *s;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010621 char_u *buf = NULL;
10622 char_u *part = NULL;
10623 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010624
10625 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10626 return FAIL;
10627 if (*valuep != NULL)
10628 {
10629 /* Output 'pastetoggle' as key names. For other
10630 * options some characters have to be escaped with
10631 * CTRL-V or backslash */
10632 if (valuep == &p_pt)
10633 {
10634 s = *valuep;
10635 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010636 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010637 return FAIL;
10638 }
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010639 // expand the option value, replace $HOME by ~
10640 else if ((flags & P_EXPAND) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010641 {
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010642 int size = (int)STRLEN(*valuep) + 1;
10643
10644 // replace home directory in the whole option value into "buf"
10645 buf = alloc(size);
Bram Moolenaarf8441472011-04-28 17:24:58 +020010646 if (buf == NULL)
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010647 goto fail;
10648 home_replace(NULL, *valuep, buf, size, FALSE);
10649
10650 // If the option value is longer than MAXPATHL, we need to append
10651 // earch comma separated part of the option separately, so that it
10652 // can be expanded when read back.
10653 if (size >= MAXPATHL && (flags & P_COMMA) != 0
10654 && vim_strchr(*valuep, ',') != NULL)
10655 {
10656 part = alloc(size);
10657 if (part == NULL)
10658 goto fail;
10659
10660 // write line break to clear the option, e.g. ':set rtp='
10661 if (put_eol(fd) == FAIL)
10662 goto fail;
10663
10664 p = buf;
10665 while (*p != NUL)
10666 {
10667 // for each comma separated option part, append value to
10668 // the option, :set rtp+=value
10669 if (fprintf(fd, "%s %s+=", cmd, name) < 0)
10670 goto fail;
10671 (void)copy_option_part(&p, part, size, ",");
10672 if (put_escstr(fd, part, 2) == FAIL || put_eol(fd) == FAIL)
10673 goto fail;
10674 }
10675 vim_free(buf);
10676 vim_free(part);
10677 return OK;
10678 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010679 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010680 {
10681 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010682 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010683 }
10684 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010685 }
10686 else if (put_escstr(fd, *valuep, 2) == FAIL)
10687 return FAIL;
10688 }
10689 if (put_eol(fd) < 0)
10690 return FAIL;
10691 return OK;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010692fail:
10693 vim_free(buf);
10694 vim_free(part);
10695 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010696}
10697
10698 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010699put_setnum(
10700 FILE *fd,
10701 char *cmd,
10702 char *name,
10703 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010704{
10705 long wc;
10706
10707 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10708 return FAIL;
10709 if (wc_use_keyname((char_u *)valuep, &wc))
10710 {
10711 /* print 'wildchar' and 'wildcharm' as a key name */
10712 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10713 return FAIL;
10714 }
10715 else if (fprintf(fd, "%ld", *valuep) < 0)
10716 return FAIL;
10717 if (put_eol(fd) < 0)
10718 return FAIL;
10719 return OK;
10720}
10721
10722 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010723put_setbool(
10724 FILE *fd,
10725 char *cmd,
10726 char *name,
10727 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010728{
Bram Moolenaar893de922007-10-02 18:40:57 +000010729 if (value < 0) /* global/local option using global value */
10730 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010731 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10732 || put_eol(fd) < 0)
10733 return FAIL;
10734 return OK;
10735}
10736
10737/*
10738 * Clear all the terminal options.
10739 * If the option has been allocated, free the memory.
10740 * Terminal options are never hidden or indirect.
10741 */
10742 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010743clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010744{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010745 /*
10746 * Reset a few things before clearing the old options. This may cause
10747 * outputting a few things that the terminal doesn't understand, but the
10748 * screen will be cleared later, so this is OK.
10749 */
10750#ifdef FEAT_MOUSE_TTY
10751 mch_setmouse(FALSE); /* switch mouse off */
10752#endif
10753#ifdef FEAT_TITLE
Bram Moolenaar40385db2018-08-07 22:31:44 +020010754 mch_restore_title(SAVE_RESTORE_BOTH); /* restore window titles */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010755#endif
10756#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10757 /* When starting the GUI close the display opened for the clipboard.
10758 * After restoring the title, because that will need the display. */
10759 if (gui.starting)
10760 clear_xterm_clip();
10761#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010762 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010763
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010764 free_termoptions();
10765}
10766
10767 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010768free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010769{
10770 struct vimoption *p;
10771
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010772 for (p = options; p->fullname != NULL; p++)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010773 if (istermoption(p))
10774 {
10775 if (p->flags & P_ALLOCED)
10776 free_string_option(*(char_u **)(p->var));
10777 if (p->flags & P_DEF_ALLOCED)
10778 free_string_option(p->def_val[VI_DEFAULT]);
10779 *(char_u **)(p->var) = empty_option;
10780 p->def_val[VI_DEFAULT] = empty_option;
10781 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010782#ifdef FEAT_EVAL
10783 // remember where the option was cleared
10784 set_option_sctx_idx((int)(p - options), OPT_GLOBAL, current_sctx);
10785#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010786 }
10787 clear_termcodes();
10788}
10789
10790/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010791 * Free the string for one term option, if it was allocated.
10792 * Set the string to empty_option and clear allocated flag.
10793 * "var" points to the option value.
10794 */
10795 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010796free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010797{
10798 struct vimoption *p;
10799
10800 for (p = &options[0]; p->fullname != NULL; p++)
10801 if (p->var == var)
10802 {
10803 if (p->flags & P_ALLOCED)
10804 free_string_option(*(char_u **)(p->var));
10805 *(char_u **)(p->var) = empty_option;
10806 p->flags &= ~P_ALLOCED;
10807 break;
10808 }
10809}
10810
10811/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010812 * Set the terminal option defaults to the current value.
10813 * Used after setting the terminal name.
10814 */
10815 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010816set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010817{
10818 struct vimoption *p;
10819
10820 for (p = &options[0]; p->fullname != NULL; p++)
10821 {
10822 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10823 {
10824 if (p->flags & P_DEF_ALLOCED)
10825 {
10826 free_string_option(p->def_val[VI_DEFAULT]);
10827 p->flags &= ~P_DEF_ALLOCED;
10828 }
10829 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10830 if (p->flags & P_ALLOCED)
10831 {
10832 p->flags |= P_DEF_ALLOCED;
10833 p->flags &= ~P_ALLOCED; /* don't free the value now */
10834 }
10835 }
10836 }
10837}
10838
10839/*
10840 * return TRUE if 'p' starts with 't_'
10841 */
10842 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010843istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010844{
10845 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10846}
10847
10848/*
10849 * Compute columns for ruler and shown command. 'sc_col' is also used to
10850 * decide what the maximum length of a message on the status line can be.
10851 * If there is a status line for the last window, 'sc_col' is independent
10852 * of 'ru_col'.
10853 */
10854
10855#define COL_RULER 17 /* columns needed by standard ruler */
10856
10857 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010858comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010859{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010860#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010861 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010862
10863 sc_col = 0;
10864 ru_col = 0;
10865 if (p_ru)
10866 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010867# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010868 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010869# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010870 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010871# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010872 /* no last status line, adjust sc_col */
10873 if (!last_has_status)
10874 sc_col = ru_col;
10875 }
10876 if (p_sc)
10877 {
10878 sc_col += SHOWCMD_COLS;
10879 if (!p_ru || last_has_status) /* no need for separating space */
10880 ++sc_col;
10881 }
10882 sc_col = Columns - sc_col;
10883 ru_col = Columns - ru_col;
10884 if (sc_col <= 0) /* screen too narrow, will become a mess */
10885 sc_col = 1;
10886 if (ru_col <= 0)
10887 ru_col = 1;
10888#else
10889 sc_col = Columns;
10890 ru_col = Columns;
10891#endif
10892}
10893
Bram Moolenaar113e1072019-01-20 15:30:40 +010010894#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010895/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010896 * Unset local option value, similar to ":set opt<".
10897 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010898 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010899unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010900{
10901 struct vimoption *p;
10902 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010903 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010904
10905 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010906 if (opt_idx < 0)
10907 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010908 p = &(options[opt_idx]);
10909
10910 switch ((int)p->indir)
10911 {
10912 /* global option with local value: use local value if it's been set */
10913 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010914 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010915 break;
10916 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010917 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010918 break;
10919 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010920 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010921 break;
10922 case PV_AR:
10923 buf->b_p_ar = -1;
10924 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010925 case PV_BKC:
10926 clear_string_option(&buf->b_p_bkc);
10927 buf->b_bkc_flags = 0;
10928 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010929 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010930 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010931 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010932 case PV_TC:
10933 clear_string_option(&buf->b_p_tc);
10934 buf->b_tc_flags = 0;
10935 break;
Bram Moolenaar375e3392019-01-31 18:26:10 +010010936 case PV_SISO:
10937 curwin->w_p_siso = -1;
10938 break;
10939 case PV_SO:
10940 curwin->w_p_so = -1;
10941 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010942#ifdef FEAT_FIND_ID
10943 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010944 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010945 break;
10946 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010947 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010948 break;
10949#endif
10950#ifdef FEAT_INS_EXPAND
10951 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010952 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010953 break;
10954 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010955 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010956 break;
10957#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010958 case PV_FP:
10959 clear_string_option(&buf->b_p_fp);
10960 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010961#ifdef FEAT_QUICKFIX
10962 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010963 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010964 break;
10965 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010966 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010967 break;
10968 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010969 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010970 break;
10971#endif
10972#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10973 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010974 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010975 break;
10976#endif
10977#if defined(FEAT_CRYPT)
10978 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010979 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010980 break;
10981#endif
10982#ifdef FEAT_STL_OPT
10983 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010984 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010985 break;
10986#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010987 case PV_UL:
10988 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10989 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010990#ifdef FEAT_LISP
10991 case PV_LW:
10992 clear_string_option(&buf->b_p_lw);
10993 break;
10994#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010995 case PV_MENC:
10996 clear_string_option(&buf->b_p_menc);
10997 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010998 }
10999}
Bram Moolenaar113e1072019-01-20 15:30:40 +010011000#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020011001
11002/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011003 * Get pointer to option variable, depending on local or global scope.
11004 */
11005 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011006get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011007{
11008 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
11009 {
11010 if (p->var == VAR_WIN)
11011 return (char_u *)GLOBAL_WO(get_varp(p));
11012 return p->var;
11013 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000011014 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011015 {
11016 switch ((int)p->indir)
11017 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011018 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011019#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011020 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
11021 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
11022 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011023#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011024 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
11025 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
11026 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000011027 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011028 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011029 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar375e3392019-01-31 18:26:10 +010011030 case PV_SISO: return (char_u *)&(curwin->w_p_siso);
11031 case PV_SO: return (char_u *)&(curwin->w_p_so);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011032#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011033 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
11034 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011035#endif
11036#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011037 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
11038 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011039#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011040#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11041 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
11042#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011043#if defined(FEAT_CRYPT)
11044 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
11045#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011046#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011047 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011048#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011049 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011050#ifdef FEAT_LISP
11051 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
11052#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011053 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011054 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011055 }
11056 return NULL; /* "cannot happen" */
11057 }
11058 return get_varp(p);
11059}
11060
11061/*
11062 * Get pointer to option variable.
11063 */
11064 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011065get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011066{
11067 /* hidden option, always return NULL */
11068 if (p->var == NULL)
11069 return NULL;
11070
11071 switch ((int)p->indir)
11072 {
11073 case PV_NONE: return p->var;
11074
11075 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011076 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011077 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011078 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011079 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011080 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011081 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000011082 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000011083 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011084 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011085 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011086 case PV_TC: return *curbuf->b_p_tc != NUL
11087 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011088 case PV_BKC: return *curbuf->b_p_bkc != NUL
11089 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar375e3392019-01-31 18:26:10 +010011090 case PV_SISO: return curwin->w_p_siso >= 0
11091 ? (char_u *)&(curwin->w_p_siso) : p->var;
11092 case PV_SO: return curwin->w_p_so >= 0
11093 ? (char_u *)&(curwin->w_p_so) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011094#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011095 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011096 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011097 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011098 ? (char_u *)&(curbuf->b_p_inc) : p->var;
11099#endif
11100#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011101 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011102 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011103 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011104 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
11105#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011106 case PV_FP: return *curbuf->b_p_fp != NUL
11107 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011108#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011109 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011110 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011111 case PV_GP: return *curbuf->b_p_gp != NUL
11112 ? (char_u *)&(curbuf->b_p_gp) : p->var;
11113 case PV_MP: return *curbuf->b_p_mp != NUL
11114 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011115#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011116#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11117 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
11118 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
11119#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011120#if defined(FEAT_CRYPT)
11121 case PV_CM: return *curbuf->b_p_cm != NUL
11122 ? (char_u *)&(curbuf->b_p_cm) : p->var;
11123#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011124#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011125 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011126 ? (char_u *)&(curwin->w_p_stl) : p->var;
11127#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011128 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
11129 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011130#ifdef FEAT_LISP
11131 case PV_LW: return *curbuf->b_p_lw != NUL
11132 ? (char_u *)&(curbuf->b_p_lw) : p->var;
11133#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011134 case PV_MENC: return *curbuf->b_p_menc != NUL
11135 ? (char_u *)&(curbuf->b_p_menc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011136#ifdef FEAT_ARABIC
11137 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
11138#endif
11139 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011140#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000011141 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
11142#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011143#ifdef FEAT_SYN_HL
11144 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
11145 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020011146 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011147#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011148#ifdef FEAT_DIFF
11149 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
11150#endif
11151#ifdef FEAT_FOLDING
11152 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
11153 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
11154 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
11155 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
11156 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
11157 case PV_FML: return (char_u *)&(curwin->w_p_fml);
11158 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
11159# ifdef FEAT_EVAL
11160 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
11161 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
11162# endif
11163 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
11164#endif
11165 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020011166 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011167#ifdef FEAT_LINEBREAK
11168 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
11169#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011170 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000011171 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020011172#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011173 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
11174#endif
11175#ifdef FEAT_RIGHTLEFT
11176 case PV_RL: return (char_u *)&(curwin->w_p_rl);
11177 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
11178#endif
11179 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
11180 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
11181#ifdef FEAT_LINEBREAK
11182 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020011183 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
11184 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011185#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011186 case PV_WCR: return (char_u *)&(curwin->w_p_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011187 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011188 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011189#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011190 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
11191 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
11192#endif
11193#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011194 case PV_TWK: return (char_u *)&(curwin->w_p_twk);
11195 case PV_TWS: return (char_u *)&(curwin->w_p_tws);
11196 case PV_TWSL: return (char_u *)&(curbuf->b_p_twsl);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011197#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011198
11199 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
11200 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011201 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011202 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
11203 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011204 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
11205 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
11206#ifdef FEAT_CINDENT
11207 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
11208 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
11209 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
11210#endif
11211#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11212 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
11213#endif
11214#ifdef FEAT_COMMENTS
11215 case PV_COM: return (char_u *)&(curbuf->b_p_com);
11216#endif
11217#ifdef FEAT_FOLDING
11218 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
11219#endif
11220#ifdef FEAT_INS_EXPAND
11221 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
Bram Moolenaarac3150d2019-07-28 16:36:39 +020011222# ifdef BACKSLASH_IN_FILENAME
11223 case PV_CSL: return (char_u *)&(curbuf->b_p_csl);
11224# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011225#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011226#ifdef FEAT_COMPL_FUNC
11227 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011228 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011229#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +020011230#ifdef FEAT_EVAL
11231 case PV_TFU: return (char_u *)&(curbuf->b_p_tfu);
11232#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011233 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020011234 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011235 case PV_ET: return (char_u *)&(curbuf->b_p_et);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011236 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011237 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011238 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011239 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011240 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011241 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
11242 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
11243 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
11244 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
11245#ifdef FEAT_FIND_ID
11246# ifdef FEAT_EVAL
11247 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
11248# endif
11249#endif
11250#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11251 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
11252 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
11253#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011254#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011255 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
11256#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011257#ifdef FEAT_CRYPT
11258 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
11259#endif
11260#ifdef FEAT_LISP
11261 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
11262#endif
11263 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
11264 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
11265 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
11266 case PV_MOD: return (char_u *)&(curbuf->b_changed);
11267 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011268 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011269#ifdef FEAT_TEXTOBJ
11270 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
11271#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011272 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
11273#ifdef FEAT_SMARTINDENT
11274 case PV_SI: return (char_u *)&(curbuf->b_p_si);
11275#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011276 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011277 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
11278#ifdef FEAT_SEARCHPATH
11279 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
11280#endif
11281 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
11282#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011283 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011284 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
11285#endif
11286#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020011287 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
11288 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
11289 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011290#endif
11291 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
11292 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
11293 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
11294 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011295#ifdef FEAT_PERSISTENT_UNDO
11296 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
11297#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011298 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
11299#ifdef FEAT_KEYMAP
11300 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
11301#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011302#ifdef FEAT_SIGNS
11303 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
11304#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011305#ifdef FEAT_VARTABS
11306 case PV_VSTS: return (char_u *)&(curbuf->b_p_vsts);
11307 case PV_VTS: return (char_u *)&(curbuf->b_p_vts);
11308#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010011309 default: iemsg(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011310 }
11311 /* always return a valid pointer to avoid a crash! */
11312 return (char_u *)&(curbuf->b_p_wm);
11313}
11314
11315/*
11316 * Get the value of 'equalprg', either the buffer-local one or the global one.
11317 */
11318 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011319get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011320{
11321 if (*curbuf->b_p_ep == NUL)
11322 return p_ep;
11323 return curbuf->b_p_ep;
11324}
11325
Bram Moolenaar071d4272004-06-13 20:20:40 +000011326/*
11327 * Copy options from one window to another.
11328 * Used when splitting a window.
11329 */
11330 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011331win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011332{
11333 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
11334 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020011335#if defined(FEAT_LINEBREAK)
11336 briopt_check(wp_to);
11337#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011338}
Bram Moolenaar071d4272004-06-13 20:20:40 +000011339
11340/*
11341 * Copy the options from one winopt_T to another.
11342 * Doesn't free the old option values in "to", use clear_winopt() for that.
11343 * The 'scroll' option is not copied, because it depends on the window height.
11344 * The 'previewwindow' option is reset, there can be only one preview window.
11345 */
11346 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011347copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011348{
11349#ifdef FEAT_ARABIC
11350 to->wo_arab = from->wo_arab;
11351#endif
11352 to->wo_list = from->wo_list;
11353 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020011354 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011355#ifdef FEAT_LINEBREAK
11356 to->wo_nuw = from->wo_nuw;
11357#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011358#ifdef FEAT_RIGHTLEFT
11359 to->wo_rl = from->wo_rl;
11360 to->wo_rlc = vim_strsave(from->wo_rlc);
11361#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011362#ifdef FEAT_STL_OPT
11363 to->wo_stl = vim_strsave(from->wo_stl);
11364#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011365 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011366#ifdef FEAT_DIFF
11367 to->wo_wrap_save = from->wo_wrap_save;
11368#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011369#ifdef FEAT_LINEBREAK
11370 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020011371 to->wo_bri = from->wo_bri;
11372 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011373#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011374 to->wo_wcr = vim_strsave(from->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011375 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011376 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010011377 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011378 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011379#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000011380 to->wo_spell = from->wo_spell;
11381#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011382#ifdef FEAT_SYN_HL
11383 to->wo_cuc = from->wo_cuc;
11384 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020011385 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011386#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011387#ifdef FEAT_DIFF
11388 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011389 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011390#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011391#ifdef FEAT_CONCEAL
11392 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020011393 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011394#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011395#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011396 to->wo_twk = vim_strsave(from->wo_twk);
11397 to->wo_tws = vim_strsave(from->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011398#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011399#ifdef FEAT_FOLDING
11400 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011401 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011402 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011403 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011404 to->wo_fdi = vim_strsave(from->wo_fdi);
11405 to->wo_fml = from->wo_fml;
11406 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011407 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011408 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011409 to->wo_fdm_save = from->wo_diff_saved
11410 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011411 to->wo_fdn = from->wo_fdn;
11412# ifdef FEAT_EVAL
11413 to->wo_fde = vim_strsave(from->wo_fde);
11414 to->wo_fdt = vim_strsave(from->wo_fdt);
11415# endif
11416 to->wo_fmr = vim_strsave(from->wo_fmr);
11417#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011418#ifdef FEAT_SIGNS
11419 to->wo_scl = vim_strsave(from->wo_scl);
11420#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011421 check_winopt(to); /* don't want NULL pointers */
11422}
11423
11424/*
11425 * Check string options in a window for a NULL value.
11426 */
11427 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011428check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011429{
11430 check_winopt(&win->w_onebuf_opt);
11431 check_winopt(&win->w_allbuf_opt);
11432}
11433
11434/*
11435 * Check for NULL pointers in a winopt_T and replace them with empty_option.
11436 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020011437 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011438check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011439{
11440#ifdef FEAT_FOLDING
11441 check_string_option(&wop->wo_fdi);
11442 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011443 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011444# ifdef FEAT_EVAL
11445 check_string_option(&wop->wo_fde);
11446 check_string_option(&wop->wo_fdt);
11447# endif
11448 check_string_option(&wop->wo_fmr);
11449#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011450#ifdef FEAT_SIGNS
11451 check_string_option(&wop->wo_scl);
11452#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011453#ifdef FEAT_RIGHTLEFT
11454 check_string_option(&wop->wo_rlc);
11455#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011456#ifdef FEAT_STL_OPT
11457 check_string_option(&wop->wo_stl);
11458#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011459#ifdef FEAT_SYN_HL
11460 check_string_option(&wop->wo_cc);
11461#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011462#ifdef FEAT_CONCEAL
11463 check_string_option(&wop->wo_cocu);
11464#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011465#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011466 check_string_option(&wop->wo_twk);
11467 check_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011468#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011469#ifdef FEAT_LINEBREAK
11470 check_string_option(&wop->wo_briopt);
11471#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011472 check_string_option(&wop->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011473}
11474
11475/*
11476 * Free the allocated memory inside a winopt_T.
11477 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011478 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011479clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011480{
11481#ifdef FEAT_FOLDING
11482 clear_string_option(&wop->wo_fdi);
11483 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011484 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011485# ifdef FEAT_EVAL
11486 clear_string_option(&wop->wo_fde);
11487 clear_string_option(&wop->wo_fdt);
11488# endif
11489 clear_string_option(&wop->wo_fmr);
11490#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011491#ifdef FEAT_SIGNS
11492 clear_string_option(&wop->wo_scl);
11493#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011494#ifdef FEAT_LINEBREAK
11495 clear_string_option(&wop->wo_briopt);
11496#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011497 clear_string_option(&wop->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011498#ifdef FEAT_RIGHTLEFT
11499 clear_string_option(&wop->wo_rlc);
11500#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011501#ifdef FEAT_STL_OPT
11502 clear_string_option(&wop->wo_stl);
11503#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011504#ifdef FEAT_SYN_HL
11505 clear_string_option(&wop->wo_cc);
11506#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011507#ifdef FEAT_CONCEAL
11508 clear_string_option(&wop->wo_cocu);
11509#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011510#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011511 clear_string_option(&wop->wo_twk);
11512 clear_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011513#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011514}
11515
11516/*
11517 * Copy global option values to local options for one buffer.
11518 * Used when creating a new buffer and sometimes when entering a buffer.
11519 * flags:
11520 * BCO_ENTER We will enter the buf buffer.
11521 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11522 * appropriate.
11523 * BCO_NOHELP Don't copy the values to a help buffer.
11524 */
11525 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011526buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011527{
11528 int should_copy = TRUE;
11529 char_u *save_p_isk = NULL; /* init for GCC */
11530 int dont_do_help;
11531 int did_isk = FALSE;
11532
11533 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011534 * Skip this when the option defaults have not been set yet. Happens when
11535 * main() allocates the first buffer.
11536 */
11537 if (p_cpo != NULL)
11538 {
11539 /*
11540 * Always copy when entering and 'cpo' contains 'S'.
11541 * Don't copy when already initialized.
11542 * Don't copy when 'cpo' contains 's' and not entering.
11543 * 'S' BCO_ENTER initialized 's' should_copy
11544 * yes yes X X TRUE
11545 * yes no yes X FALSE
11546 * no X yes X FALSE
11547 * X no no yes FALSE
11548 * X no no no TRUE
11549 * no yes no X TRUE
11550 */
11551 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11552 && (buf->b_p_initialized
11553 || (!(flags & BCO_ENTER)
11554 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11555 should_copy = FALSE;
11556
11557 if (should_copy || (flags & BCO_ALWAYS))
11558 {
11559 /* Don't copy the options specific to a help buffer when
11560 * BCO_NOHELP is given or the options were initialized already
11561 * (jumping back to a help file with CTRL-T or CTRL-O) */
11562 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11563 || buf->b_p_initialized;
11564 if (dont_do_help) /* don't free b_p_isk */
11565 {
11566 save_p_isk = buf->b_p_isk;
11567 buf->b_p_isk = NULL;
11568 }
11569 /*
Bram Moolenaar40385db2018-08-07 22:31:44 +020011570 * Always free the allocated strings. If not already initialized,
11571 * reset 'readonly' and copy 'fileformat'.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011572 */
11573 if (!buf->b_p_initialized)
11574 {
11575 free_buf_options(buf, TRUE);
11576 buf->b_p_ro = FALSE; /* don't copy readonly */
11577 buf->b_p_tx = p_tx;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011578 buf->b_p_fenc = vim_strsave(p_fenc);
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011579 switch (*p_ffs)
11580 {
11581 case 'm':
11582 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11583 case 'd':
11584 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11585 case 'u':
11586 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11587 default:
11588 buf->b_p_ff = vim_strsave(p_ff);
11589 }
11590 if (buf->b_p_ff != NULL)
11591 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011592 buf->b_p_bh = empty_option;
11593 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011594 }
11595 else
11596 free_buf_options(buf, FALSE);
11597
11598 buf->b_p_ai = p_ai;
11599 buf->b_p_ai_nopaste = p_ai_nopaste;
11600 buf->b_p_sw = p_sw;
11601 buf->b_p_tw = p_tw;
11602 buf->b_p_tw_nopaste = p_tw_nopaste;
11603 buf->b_p_tw_nobin = p_tw_nobin;
11604 buf->b_p_wm = p_wm;
11605 buf->b_p_wm_nopaste = p_wm_nopaste;
11606 buf->b_p_wm_nobin = p_wm_nobin;
11607 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011608 buf->b_p_bomb = p_bomb;
Bram Moolenaarb388be02015-07-22 22:19:38 +020011609 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011610 buf->b_p_et = p_et;
11611 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011612 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011613 buf->b_p_ml = p_ml;
11614 buf->b_p_ml_nobin = p_ml_nobin;
11615 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011616 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011617#ifdef FEAT_INS_EXPAND
11618 buf->b_p_cpt = vim_strsave(p_cpt);
Bram Moolenaarac3150d2019-07-28 16:36:39 +020011619# ifdef BACKSLASH_IN_FILENAME
11620 buf->b_p_csl = vim_strsave(p_csl);
11621# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011622#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011623#ifdef FEAT_COMPL_FUNC
11624 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011625 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011626#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +020011627#ifdef FEAT_EVAL
11628 buf->b_p_tfu = vim_strsave(p_tfu);
11629#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011630 buf->b_p_sts = p_sts;
11631 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011632#ifdef FEAT_VARTABS
11633 buf->b_p_vsts = vim_strsave(p_vsts);
11634 if (p_vsts && p_vsts != empty_option)
11635 tabstop_set(p_vsts, &buf->b_p_vsts_array);
11636 else
11637 buf->b_p_vsts_array = 0;
11638 buf->b_p_vsts_nopaste = p_vsts_nopaste
11639 ? vim_strsave(p_vsts_nopaste) : NULL;
11640#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011641 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011642#ifdef FEAT_COMMENTS
11643 buf->b_p_com = vim_strsave(p_com);
11644#endif
11645#ifdef FEAT_FOLDING
11646 buf->b_p_cms = vim_strsave(p_cms);
11647#endif
11648 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011649 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011650 buf->b_p_nf = vim_strsave(p_nf);
11651 buf->b_p_mps = vim_strsave(p_mps);
11652#ifdef FEAT_SMARTINDENT
11653 buf->b_p_si = p_si;
11654#endif
11655 buf->b_p_ci = p_ci;
11656#ifdef FEAT_CINDENT
11657 buf->b_p_cin = p_cin;
11658 buf->b_p_cink = vim_strsave(p_cink);
11659 buf->b_p_cino = vim_strsave(p_cino);
11660#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011661 /* Don't copy 'filetype', it must be detected */
11662 buf->b_p_ft = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011663 buf->b_p_pi = p_pi;
11664#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11665 buf->b_p_cinw = vim_strsave(p_cinw);
11666#endif
11667#ifdef FEAT_LISP
11668 buf->b_p_lisp = p_lisp;
11669#endif
11670#ifdef FEAT_SYN_HL
11671 /* Don't copy 'syntax', it must be set */
11672 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011673 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011674 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011675#endif
11676#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011677 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011678 (void)compile_cap_prog(&buf->b_s);
11679 buf->b_s.b_p_spf = vim_strsave(p_spf);
11680 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011681#endif
11682#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11683 buf->b_p_inde = vim_strsave(p_inde);
11684 buf->b_p_indk = vim_strsave(p_indk);
11685#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011686 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011687#if defined(FEAT_EVAL)
11688 buf->b_p_fex = vim_strsave(p_fex);
11689#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011690#ifdef FEAT_CRYPT
11691 buf->b_p_key = vim_strsave(p_key);
11692#endif
11693#ifdef FEAT_SEARCHPATH
11694 buf->b_p_sua = vim_strsave(p_sua);
11695#endif
11696#ifdef FEAT_KEYMAP
11697 buf->b_p_keymap = vim_strsave(p_keymap);
11698 buf->b_kmap_state |= KEYMAP_INIT;
11699#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011700#ifdef FEAT_TERMINAL
11701 buf->b_p_twsl = p_twsl;
11702#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011703 /* This isn't really an option, but copying the langmap and IME
11704 * state from the current buffer is better than resetting it. */
11705 buf->b_p_iminsert = p_iminsert;
11706 buf->b_p_imsearch = p_imsearch;
11707
11708 /* options that are normally global but also have a local value
11709 * are not copied, start using the global value */
11710 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011711 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011712 buf->b_p_bkc = empty_option;
11713 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011714#ifdef FEAT_QUICKFIX
11715 buf->b_p_gp = empty_option;
11716 buf->b_p_mp = empty_option;
11717 buf->b_p_efm = empty_option;
11718#endif
11719 buf->b_p_ep = empty_option;
11720 buf->b_p_kp = empty_option;
11721 buf->b_p_path = empty_option;
11722 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011723 buf->b_p_tc = empty_option;
11724 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011725#ifdef FEAT_FIND_ID
11726 buf->b_p_def = empty_option;
11727 buf->b_p_inc = empty_option;
11728# ifdef FEAT_EVAL
11729 buf->b_p_inex = vim_strsave(p_inex);
11730# endif
11731#endif
11732#ifdef FEAT_INS_EXPAND
11733 buf->b_p_dict = empty_option;
11734 buf->b_p_tsr = empty_option;
11735#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011736#ifdef FEAT_TEXTOBJ
11737 buf->b_p_qe = vim_strsave(p_qe);
11738#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011739#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11740 buf->b_p_bexpr = empty_option;
11741#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011742#if defined(FEAT_CRYPT)
11743 buf->b_p_cm = empty_option;
11744#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011745#ifdef FEAT_PERSISTENT_UNDO
11746 buf->b_p_udf = p_udf;
11747#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011748#ifdef FEAT_LISP
11749 buf->b_p_lw = empty_option;
11750#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011751 buf->b_p_menc = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011752
11753 /*
11754 * Don't copy the options set by ex_help(), use the saved values,
11755 * when going from a help buffer to a non-help buffer.
11756 * Don't touch these at all when BCO_NOHELP is used and going from
11757 * or to a help buffer.
11758 */
11759 if (dont_do_help)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011760 {
Bram Moolenaar071d4272004-06-13 20:20:40 +000011761 buf->b_p_isk = save_p_isk;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011762#ifdef FEAT_VARTABS
11763 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11764 tabstop_set(p_vts, &buf->b_p_vts_array);
11765 else
11766 buf->b_p_vts_array = NULL;
11767#endif
11768 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011769 else
11770 {
11771 buf->b_p_isk = vim_strsave(p_isk);
11772 did_isk = TRUE;
11773 buf->b_p_ts = p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011774#ifdef FEAT_VARTABS
11775 buf->b_p_vts = vim_strsave(p_vts);
11776 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11777 tabstop_set(p_vts, &buf->b_p_vts_array);
11778 else
11779 buf->b_p_vts_array = NULL;
11780#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011781 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011782 if (buf->b_p_bt[0] == 'h')
11783 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011784 buf->b_p_ma = p_ma;
11785 }
11786 }
11787
11788 /*
11789 * When the options should be copied (ignoring BCO_ALWAYS), set the
11790 * flag that indicates that the options have been initialized.
11791 */
11792 if (should_copy)
11793 buf->b_p_initialized = TRUE;
11794 }
11795
11796 check_buf_options(buf); /* make sure we don't have NULLs */
11797 if (did_isk)
11798 (void)buf_init_chartab(buf, FALSE);
11799}
11800
11801/*
11802 * Reset the 'modifiable' option and its default value.
11803 */
11804 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011805reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011806{
11807 int opt_idx;
11808
11809 curbuf->b_p_ma = FALSE;
11810 p_ma = FALSE;
11811 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011812 if (opt_idx >= 0)
11813 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011814}
11815
11816/*
11817 * Set the global value for 'iminsert' to the local value.
11818 */
11819 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011820set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011821{
11822 p_iminsert = curbuf->b_p_iminsert;
11823}
11824
11825/*
11826 * Set the global value for 'imsearch' to the local value.
11827 */
11828 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011829set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011830{
11831 p_imsearch = curbuf->b_p_imsearch;
11832}
11833
11834#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11835static int expand_option_idx = -1;
11836static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11837static int expand_option_flags = 0;
11838
11839 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011840set_context_in_set_cmd(
11841 expand_T *xp,
11842 char_u *arg,
11843 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011844{
11845 int nextchar;
11846 long_u flags = 0; /* init for GCC */
11847 int opt_idx = 0; /* init for GCC */
11848 char_u *p;
11849 char_u *s;
11850 int is_term_option = FALSE;
11851 int key;
11852
11853 expand_option_flags = opt_flags;
11854
11855 xp->xp_context = EXPAND_SETTINGS;
11856 if (*arg == NUL)
11857 {
11858 xp->xp_pattern = arg;
11859 return;
11860 }
11861 p = arg + STRLEN(arg) - 1;
11862 if (*p == ' ' && *(p - 1) != '\\')
11863 {
11864 xp->xp_pattern = p + 1;
11865 return;
11866 }
11867 while (p > arg)
11868 {
11869 s = p;
11870 /* count number of backslashes before ' ' or ',' */
11871 if (*p == ' ' || *p == ',')
11872 {
11873 while (s > arg && *(s - 1) == '\\')
11874 --s;
11875 }
11876 /* break at a space with an even number of backslashes */
11877 if (*p == ' ' && ((p - s) & 1) == 0)
11878 {
11879 ++p;
11880 break;
11881 }
11882 --p;
11883 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011884 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011885 {
11886 xp->xp_context = EXPAND_BOOL_SETTINGS;
11887 p += 2;
11888 }
11889 if (STRNCMP(p, "inv", 3) == 0)
11890 {
11891 xp->xp_context = EXPAND_BOOL_SETTINGS;
11892 p += 3;
11893 }
11894 xp->xp_pattern = arg = p;
11895 if (*arg == '<')
11896 {
11897 while (*p != '>')
11898 if (*p++ == NUL) /* expand terminal option name */
11899 return;
11900 key = get_special_key_code(arg + 1);
11901 if (key == 0) /* unknown name */
11902 {
11903 xp->xp_context = EXPAND_NOTHING;
11904 return;
11905 }
11906 nextchar = *++p;
11907 is_term_option = TRUE;
11908 expand_option_name[2] = KEY2TERMCAP0(key);
11909 expand_option_name[3] = KEY2TERMCAP1(key);
11910 }
11911 else
11912 {
11913 if (p[0] == 't' && p[1] == '_')
11914 {
11915 p += 2;
11916 if (*p != NUL)
11917 ++p;
11918 if (*p == NUL)
11919 return; /* expand option name */
11920 nextchar = *++p;
11921 is_term_option = TRUE;
11922 expand_option_name[2] = p[-2];
11923 expand_option_name[3] = p[-1];
11924 }
11925 else
11926 {
11927 /* Allow * wildcard */
11928 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11929 p++;
11930 if (*p == NUL)
11931 return;
11932 nextchar = *p;
11933 *p = NUL;
11934 opt_idx = findoption(arg);
11935 *p = nextchar;
11936 if (opt_idx == -1 || options[opt_idx].var == NULL)
11937 {
11938 xp->xp_context = EXPAND_NOTHING;
11939 return;
11940 }
11941 flags = options[opt_idx].flags;
11942 if (flags & P_BOOL)
11943 {
11944 xp->xp_context = EXPAND_NOTHING;
11945 return;
11946 }
11947 }
11948 }
11949 /* handle "-=" and "+=" */
11950 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11951 {
11952 ++p;
11953 nextchar = '=';
11954 }
11955 if ((nextchar != '=' && nextchar != ':')
11956 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11957 {
11958 xp->xp_context = EXPAND_UNSUCCESSFUL;
11959 return;
11960 }
11961 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11962 {
11963 xp->xp_context = EXPAND_OLD_SETTING;
11964 if (is_term_option)
11965 expand_option_idx = -1;
11966 else
11967 expand_option_idx = opt_idx;
11968 xp->xp_pattern = p + 1;
11969 return;
11970 }
11971 xp->xp_context = EXPAND_NOTHING;
11972 if (is_term_option || (flags & P_NUM))
11973 return;
11974
11975 xp->xp_pattern = p + 1;
11976
11977 if (flags & P_EXPAND)
11978 {
11979 p = options[opt_idx].var;
11980 if (p == (char_u *)&p_bdir
11981 || p == (char_u *)&p_dir
11982 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011983 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011984 || p == (char_u *)&p_rtp
11985#ifdef FEAT_SEARCHPATH
11986 || p == (char_u *)&p_cdpath
11987#endif
11988#ifdef FEAT_SESSION
11989 || p == (char_u *)&p_vdir
11990#endif
11991 )
11992 {
11993 xp->xp_context = EXPAND_DIRECTORIES;
11994 if (p == (char_u *)&p_path
11995#ifdef FEAT_SEARCHPATH
11996 || p == (char_u *)&p_cdpath
11997#endif
11998 )
11999 xp->xp_backslash = XP_BS_THREE;
12000 else
12001 xp->xp_backslash = XP_BS_ONE;
12002 }
12003 else
12004 {
12005 xp->xp_context = EXPAND_FILES;
12006 /* for 'tags' need three backslashes for a space */
12007 if (p == (char_u *)&p_tags)
12008 xp->xp_backslash = XP_BS_THREE;
12009 else
12010 xp->xp_backslash = XP_BS_ONE;
12011 }
12012 }
12013
12014 /* For an option that is a list of file names, find the start of the
12015 * last file name. */
12016 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
12017 {
12018 /* count number of backslashes before ' ' or ',' */
12019 if (*p == ' ' || *p == ',')
12020 {
12021 s = p;
12022 while (s > xp->xp_pattern && *(s - 1) == '\\')
12023 --s;
12024 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
12025 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
12026 {
12027 xp->xp_pattern = p + 1;
12028 break;
12029 }
12030 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000012031
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000012032#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000012033 /* for 'spellsuggest' start at "file:" */
12034 if (options[opt_idx].var == (char_u *)&p_sps
12035 && STRNCMP(p, "file:", 5) == 0)
12036 {
12037 xp->xp_pattern = p + 5;
12038 break;
12039 }
12040#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012041 }
12042
12043 return;
12044}
12045
12046 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012047ExpandSettings(
12048 expand_T *xp,
12049 regmatch_T *regmatch,
12050 int *num_file,
12051 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012052{
12053 int num_normal = 0; /* Nr of matching non-term-code settings */
12054 int num_term = 0; /* Nr of matching terminal code settings */
12055 int opt_idx;
12056 int match;
12057 int count = 0;
12058 char_u *str;
12059 int loop;
12060 int is_term_opt;
12061 char_u name_buf[MAX_KEY_NAME_LEN];
12062 static char *(names[]) = {"all", "termcap"};
12063 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
12064
12065 /* do this loop twice:
12066 * loop == 0: count the number of matching options
12067 * loop == 1: copy the matching options into allocated memory
12068 */
12069 for (loop = 0; loop <= 1; ++loop)
12070 {
12071 regmatch->rm_ic = ic;
12072 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
12073 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000012074 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
12075 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012076 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
12077 {
12078 if (loop == 0)
12079 num_normal++;
12080 else
12081 (*file)[count++] = vim_strsave((char_u *)names[match]);
12082 }
12083 }
12084 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
12085 opt_idx++)
12086 {
12087 if (options[opt_idx].var == NULL)
12088 continue;
12089 if (xp->xp_context == EXPAND_BOOL_SETTINGS
12090 && !(options[opt_idx].flags & P_BOOL))
12091 continue;
12092 is_term_opt = istermoption(&options[opt_idx]);
12093 if (is_term_opt && num_normal > 0)
12094 continue;
12095 match = FALSE;
12096 if (vim_regexec(regmatch, str, (colnr_T)0)
12097 || (options[opt_idx].shortname != NULL
12098 && vim_regexec(regmatch,
12099 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
12100 match = TRUE;
12101 else if (is_term_opt)
12102 {
12103 name_buf[0] = '<';
12104 name_buf[1] = 't';
12105 name_buf[2] = '_';
12106 name_buf[3] = str[2];
12107 name_buf[4] = str[3];
12108 name_buf[5] = '>';
12109 name_buf[6] = NUL;
12110 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12111 {
12112 match = TRUE;
12113 str = name_buf;
12114 }
12115 }
12116 if (match)
12117 {
12118 if (loop == 0)
12119 {
12120 if (is_term_opt)
12121 num_term++;
12122 else
12123 num_normal++;
12124 }
12125 else
12126 (*file)[count++] = vim_strsave(str);
12127 }
12128 }
12129 /*
12130 * Check terminal key codes, these are not in the option table
12131 */
12132 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
12133 {
12134 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
12135 {
12136 if (!isprint(str[0]) || !isprint(str[1]))
12137 continue;
12138
12139 name_buf[0] = 't';
12140 name_buf[1] = '_';
12141 name_buf[2] = str[0];
12142 name_buf[3] = str[1];
12143 name_buf[4] = NUL;
12144
12145 match = FALSE;
12146 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12147 match = TRUE;
12148 else
12149 {
12150 name_buf[0] = '<';
12151 name_buf[1] = 't';
12152 name_buf[2] = '_';
12153 name_buf[3] = str[0];
12154 name_buf[4] = str[1];
12155 name_buf[5] = '>';
12156 name_buf[6] = NUL;
12157
12158 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12159 match = TRUE;
12160 }
12161 if (match)
12162 {
12163 if (loop == 0)
12164 num_term++;
12165 else
12166 (*file)[count++] = vim_strsave(name_buf);
12167 }
12168 }
12169
12170 /*
12171 * Check special key names.
12172 */
12173 regmatch->rm_ic = TRUE; /* ignore case here */
12174 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
12175 {
12176 name_buf[0] = '<';
12177 STRCPY(name_buf + 1, str);
12178 STRCAT(name_buf, ">");
12179
12180 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12181 {
12182 if (loop == 0)
12183 num_term++;
12184 else
12185 (*file)[count++] = vim_strsave(name_buf);
12186 }
12187 }
12188 }
12189 if (loop == 0)
12190 {
12191 if (num_normal > 0)
12192 *num_file = num_normal;
12193 else if (num_term > 0)
12194 *num_file = num_term;
12195 else
12196 return OK;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020012197 *file = ALLOC_MULT(char_u *, *num_file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012198 if (*file == NULL)
12199 {
12200 *file = (char_u **)"";
12201 return FAIL;
12202 }
12203 }
12204 }
12205 return OK;
12206}
12207
12208 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012209ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012210{
12211 char_u *var = NULL; /* init for GCC */
12212 char_u *buf;
12213
12214 *num_file = 0;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020012215 *file = ALLOC_ONE(char_u *);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012216 if (*file == NULL)
12217 return FAIL;
12218
12219 /*
12220 * For a terminal key code expand_option_idx is < 0.
12221 */
12222 if (expand_option_idx < 0)
12223 {
12224 var = find_termcode(expand_option_name + 2);
12225 if (var == NULL)
12226 expand_option_idx = findoption(expand_option_name);
12227 }
12228
12229 if (expand_option_idx >= 0)
12230 {
12231 /* put string of option value in NameBuff */
12232 option_value2string(&options[expand_option_idx], expand_option_flags);
12233 var = NameBuff;
12234 }
12235 else if (var == NULL)
12236 var = (char_u *)"";
12237
12238 /* A backslash is required before some characters. This is the reverse of
12239 * what happens in do_set(). */
12240 buf = vim_strsave_escaped(var, escape_chars);
12241
12242 if (buf == NULL)
12243 {
Bram Moolenaard23a8232018-02-10 18:45:26 +010012244 VIM_CLEAR(*file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012245 return FAIL;
12246 }
12247
12248#ifdef BACKSLASH_IN_FILENAME
12249 /* For MS-Windows et al. we don't double backslashes at the start and
12250 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012251 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012252 if (var[0] == '\\' && var[1] == '\\'
12253 && expand_option_idx >= 0
12254 && (options[expand_option_idx].flags & P_EXPAND)
12255 && vim_isfilec(var[2])
12256 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000012257 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012258#endif
12259
12260 *file[0] = buf;
12261 *num_file = 1;
12262 return OK;
12263}
12264#endif
12265
12266/*
12267 * Get the value for the numeric or string option *opp in a nice format into
12268 * NameBuff[]. Must not be called with a hidden option!
12269 */
12270 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012271option_value2string(
12272 struct vimoption *opp,
12273 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012274{
12275 char_u *varp;
12276
12277 varp = get_varp_scope(opp, opt_flags);
12278
12279 if (opp->flags & P_NUM)
12280 {
12281 long wc = 0;
12282
12283 if (wc_use_keyname(varp, &wc))
12284 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
12285 else if (wc != 0)
12286 STRCPY(NameBuff, transchar((int)wc));
12287 else
12288 sprintf((char *)NameBuff, "%ld", *(long *)varp);
12289 }
12290 else /* P_STRING */
12291 {
12292 varp = *(char_u **)(varp);
12293 if (varp == NULL) /* just in case */
12294 NameBuff[0] = NUL;
12295#ifdef FEAT_CRYPT
12296 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000012297 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012298 STRCPY(NameBuff, "*****");
12299#endif
12300 else if (opp->flags & P_EXPAND)
12301 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
12302 /* Translate 'pastetoggle' into special key names */
12303 else if ((char_u **)opp->var == &p_pt)
12304 str2specialbuf(p_pt, NameBuff, MAXPATHL);
12305 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000012306 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012307 }
12308}
12309
12310/*
12311 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
12312 * printed as a keyname.
12313 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
12314 */
12315 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012316wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012317{
12318 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
12319 {
12320 *wcp = *(long *)varp;
12321 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
12322 return TRUE;
12323 }
12324 return FALSE;
12325}
12326
Bram Moolenaar01615492015-02-03 13:00:38 +010012327#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012328/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012329 * Any character has an equivalent 'langmap' character. This is used for
12330 * keyboards that have a special language mode that sends characters above
12331 * 128 (although other characters can be translated too). The "to" field is a
12332 * Vim command character. This avoids having to switch the keyboard back to
12333 * ASCII mode when leaving Insert mode.
12334 *
12335 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
12336 * commands.
Bram Moolenaarfc3abf42019-01-24 15:54:21 +010012337 * langmap_mapga.ga_data is a sorted table of langmap_entry_T. This does the
12338 * same as langmap_mapchar[] for characters >= 256.
12339 *
12340 * Use growarray for 'langmap' chars >= 256
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012341 */
12342typedef struct
12343{
12344 int from;
12345 int to;
12346} langmap_entry_T;
12347
12348static garray_T langmap_mapga;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012349
12350/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012351 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
12352 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012353 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012354 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012355langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012356{
12357 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020012358 int a = 0;
12359 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012360
12361 /* Do a binary search for an existing entry. */
12362 while (a != b)
12363 {
12364 int i = (a + b) / 2;
12365 int d = entries[i].from - from;
12366
12367 if (d == 0)
12368 {
12369 entries[i].to = to;
12370 return;
12371 }
12372 if (d < 0)
12373 a = i + 1;
12374 else
12375 b = i;
12376 }
12377
12378 if (ga_grow(&langmap_mapga, 1) != OK)
12379 return; /* out of memory */
12380
12381 /* insert new entry at position "a" */
12382 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
12383 mch_memmove(entries + 1, entries,
12384 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
12385 ++langmap_mapga.ga_len;
12386 entries[0].from = from;
12387 entries[0].to = to;
12388}
12389
12390/*
12391 * Apply 'langmap' to multi-byte character "c" and return the result.
12392 */
12393 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012394langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012395{
12396 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
12397 int a = 0;
12398 int b = langmap_mapga.ga_len;
12399
12400 while (a != b)
12401 {
12402 int i = (a + b) / 2;
12403 int d = entries[i].from - c;
12404
12405 if (d == 0)
12406 return entries[i].to; /* found matching entry */
12407 if (d < 0)
12408 a = i + 1;
12409 else
12410 b = i;
12411 }
12412 return c; /* no entry found, return "c" unmodified */
12413}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012414
12415 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012416langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012417{
12418 int i;
12419
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012420 for (i = 0; i < 256; i++)
12421 langmap_mapchar[i] = i; /* we init with a one-to-one map */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012422 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012423}
12424
12425/*
12426 * Called when langmap option is set; the language map can be
12427 * changed at any time!
12428 */
12429 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012430langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012431{
12432 char_u *p;
12433 char_u *p2;
12434 int from, to;
12435
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012436 ga_clear(&langmap_mapga); /* clear the previous map first */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012437 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012438
12439 for (p = p_langmap; p[0] != NUL; )
12440 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000012441 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012442 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012443 {
12444 if (p2[0] == '\\' && p2[1] != NUL)
12445 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012446 }
12447 if (p2[0] == ';')
12448 ++p2; /* abcd;ABCD form, p2 points to A */
12449 else
12450 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
12451 while (p[0])
12452 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012453 if (p[0] == ',')
12454 {
12455 ++p;
12456 break;
12457 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012458 if (p[0] == '\\' && p[1] != NUL)
12459 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012460 from = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012461 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012462 if (p2 == NULL)
12463 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012464 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012465 if (p[0] != ',')
12466 {
12467 if (p[0] == '\\')
12468 ++p;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012469 to = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012470 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012471 }
12472 else
12473 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012474 if (p2[0] != ',')
12475 {
12476 if (p2[0] == '\\')
12477 ++p2;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012478 to = (*mb_ptr2char)(p2);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012479 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012480 }
12481 if (to == NUL)
12482 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012483 semsg(_("E357: 'langmap': Matching character missing for %s"),
Bram Moolenaar071d4272004-06-13 20:20:40 +000012484 transchar(from));
12485 return;
12486 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012487
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012488 if (from >= 256)
12489 langmap_set_entry(from, to);
12490 else
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012491 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012492
12493 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012494 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012495 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012496 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012497 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012498 if (*p == ';')
12499 {
12500 p = p2;
12501 if (p[0] != NUL)
12502 {
12503 if (p[0] != ',')
12504 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012505 semsg(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012506 return;
12507 }
12508 ++p;
12509 }
12510 break;
12511 }
12512 }
12513 }
12514 }
12515}
12516#endif
12517
12518/*
12519 * Return TRUE if format option 'x' is in effect.
12520 * Take care of no formatting when 'paste' is set.
12521 */
12522 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012523has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012524{
12525 if (p_paste)
12526 return FALSE;
12527 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12528}
12529
12530/*
12531 * Return TRUE if "x" is present in 'shortmess' option, or
12532 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12533 */
12534 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012535shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012536{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012537 return p_shm != NULL &&
12538 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012539 || (vim_strchr(p_shm, 'a') != NULL
12540 && vim_strchr((char_u *)SHM_A, x) != NULL));
12541}
12542
12543/*
12544 * paste_option_changed() - Called after p_paste was set or reset.
12545 */
12546 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012547paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012548{
12549 static int old_p_paste = FALSE;
12550 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012551 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012552#ifdef FEAT_CMDL_INFO
12553 static int save_ru = 0;
12554#endif
12555#ifdef FEAT_RIGHTLEFT
12556 static int save_ri = 0;
12557 static int save_hkmap = 0;
12558#endif
12559 buf_T *buf;
12560
12561 if (p_paste)
12562 {
12563 /*
12564 * Paste switched from off to on.
12565 * Save the current values, so they can be restored later.
12566 */
12567 if (!old_p_paste)
12568 {
12569 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012570 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012571 {
12572 buf->b_p_tw_nopaste = buf->b_p_tw;
12573 buf->b_p_wm_nopaste = buf->b_p_wm;
12574 buf->b_p_sts_nopaste = buf->b_p_sts;
12575 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012576 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012577#ifdef FEAT_VARTABS
12578 if (buf->b_p_vsts_nopaste)
12579 vim_free(buf->b_p_vsts_nopaste);
12580 buf->b_p_vsts_nopaste = buf->b_p_vsts && buf->b_p_vsts != empty_option
12581 ? vim_strsave(buf->b_p_vsts) : NULL;
12582#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012583 }
12584
12585 /* save global options */
12586 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012587 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012588#ifdef FEAT_CMDL_INFO
12589 save_ru = p_ru;
12590#endif
12591#ifdef FEAT_RIGHTLEFT
12592 save_ri = p_ri;
12593 save_hkmap = p_hkmap;
12594#endif
12595 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012596 p_ai_nopaste = p_ai;
12597 p_et_nopaste = p_et;
12598 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012599 p_tw_nopaste = p_tw;
12600 p_wm_nopaste = p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012601#ifdef FEAT_VARTABS
12602 if (p_vsts_nopaste)
12603 vim_free(p_vsts_nopaste);
12604 p_vsts_nopaste = p_vsts && p_vsts != empty_option ? vim_strsave(p_vsts) : NULL;
12605#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012606 }
12607
12608 /*
12609 * Always set the option values, also when 'paste' is set when it is
12610 * already on.
12611 */
12612 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012613 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012614 {
12615 buf->b_p_tw = 0; /* textwidth is 0 */
12616 buf->b_p_wm = 0; /* wrapmargin is 0 */
12617 buf->b_p_sts = 0; /* softtabstop is 0 */
12618 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012619 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012620#ifdef FEAT_VARTABS
12621 if (buf->b_p_vsts)
12622 free_string_option(buf->b_p_vsts);
12623 buf->b_p_vsts = empty_option;
12624 if (buf->b_p_vsts_array)
12625 vim_free(buf->b_p_vsts_array);
12626 buf->b_p_vsts_array = 0;
12627#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012628 }
12629
12630 /* set global options */
12631 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012632 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012633#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012634 if (p_ru)
12635 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012636 p_ru = 0; /* no ruler */
12637#endif
12638#ifdef FEAT_RIGHTLEFT
12639 p_ri = 0; /* no reverse insert */
12640 p_hkmap = 0; /* no Hebrew keyboard */
12641#endif
12642 /* set global values for local buffer options */
12643 p_tw = 0;
12644 p_wm = 0;
12645 p_sts = 0;
12646 p_ai = 0;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012647#ifdef FEAT_VARTABS
12648 if (p_vsts)
12649 free_string_option(p_vsts);
12650 p_vsts = empty_option;
12651#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012652 }
12653
12654 /*
12655 * Paste switched from on to off: Restore saved values.
12656 */
12657 else if (old_p_paste)
12658 {
12659 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012660 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012661 {
12662 buf->b_p_tw = buf->b_p_tw_nopaste;
12663 buf->b_p_wm = buf->b_p_wm_nopaste;
12664 buf->b_p_sts = buf->b_p_sts_nopaste;
12665 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012666 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012667#ifdef FEAT_VARTABS
12668 if (buf->b_p_vsts)
12669 free_string_option(buf->b_p_vsts);
12670 buf->b_p_vsts = buf->b_p_vsts_nopaste
12671 ? vim_strsave(buf->b_p_vsts_nopaste) : empty_option;
12672 if (buf->b_p_vsts_array)
12673 vim_free(buf->b_p_vsts_array);
12674 if (buf->b_p_vsts && buf->b_p_vsts != empty_option)
12675 tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array);
12676 else
12677 buf->b_p_vsts_array = 0;
12678#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012679 }
12680
12681 /* restore global options */
12682 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012683 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012684#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012685 if (p_ru != save_ru)
12686 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012687 p_ru = save_ru;
12688#endif
12689#ifdef FEAT_RIGHTLEFT
12690 p_ri = save_ri;
12691 p_hkmap = save_hkmap;
12692#endif
12693 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012694 p_ai = p_ai_nopaste;
12695 p_et = p_et_nopaste;
12696 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012697 p_tw = p_tw_nopaste;
12698 p_wm = p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012699#ifdef FEAT_VARTABS
12700 if (p_vsts)
12701 free_string_option(p_vsts);
12702 p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option;
12703#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012704 }
12705
12706 old_p_paste = p_paste;
12707}
12708
12709/*
12710 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12711 *
12712 * Reset 'compatible' and set the values for options that didn't get set yet
12713 * to the Vim defaults.
12714 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012715 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012716 */
12717 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012718vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012719{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012720 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012721 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012722 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012723
12724 if (!option_was_set((char_u *)"cp"))
12725 {
12726 p_cp = FALSE;
12727 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12728 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12729 set_option_default(opt_idx, OPT_FREE, FALSE);
12730 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012731 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012732 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012733
12734 if (fname != NULL)
12735 {
12736 p = vim_getenv(envname, &dofree);
12737 if (p == NULL)
12738 {
12739 /* Set $MYVIMRC to the first vimrc file found. */
12740 p = FullName_save(fname, FALSE);
12741 if (p != NULL)
12742 {
12743 vim_setenv(envname, p);
12744 vim_free(p);
12745 }
12746 }
12747 else if (dofree)
12748 vim_free(p);
12749 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012750}
12751
12752/*
12753 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12754 */
12755 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012756change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012757{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012758 int opt_idx;
12759
Bram Moolenaar071d4272004-06-13 20:20:40 +000012760 if (p_cp != on)
12761 {
12762 p_cp = on;
12763 compatible_set();
12764 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012765 opt_idx = findoption((char_u *)"cp");
12766 if (opt_idx >= 0)
12767 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012768}
12769
12770/*
12771 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012772 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012773 */
12774 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012775option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012776{
12777 int idx;
12778
12779 idx = findoption(name);
12780 if (idx < 0) /* unknown option */
12781 return FALSE;
12782 if (options[idx].flags & P_WAS_SET)
12783 return TRUE;
12784 return FALSE;
12785}
12786
12787/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012788 * Reset the flag indicating option "name" was set.
12789 */
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012790 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012791reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012792{
12793 int idx = findoption(name);
12794
12795 if (idx >= 0)
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012796 {
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012797 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012798 return OK;
12799 }
12800 return FAIL;
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012801}
12802
12803/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012804 * compatible_set() - Called when 'compatible' has been set or unset.
12805 *
12806 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12807 * flag) to a Vi compatible value.
12808 * When 'compatible' is unset: Set all options that have a different default
12809 * for Vim (without the P_VI_DEF flag) to that default.
12810 */
12811 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012812compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012813{
12814 int opt_idx;
12815
12816 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12817 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12818 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12819 set_option_default(opt_idx, OPT_FREE, p_cp);
12820 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012821 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012822}
12823
12824#ifdef FEAT_LINEBREAK
12825
Bram Moolenaar071d4272004-06-13 20:20:40 +000012826/*
12827 * fill_breakat_flags() -- called when 'breakat' changes value.
12828 */
12829 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012830fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012831{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012832 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012833 int i;
12834
12835 for (i = 0; i < 256; i++)
12836 breakat_flags[i] = FALSE;
12837
12838 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012839 for (p = p_breakat; *p; p++)
12840 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012841}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012842#endif
12843
12844/*
12845 * Check an option that can be a range of string values.
12846 *
12847 * Return OK for correct value, FAIL otherwise.
12848 * Empty is always OK.
12849 */
12850 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012851check_opt_strings(
12852 char_u *val,
12853 char **values,
12854 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012855{
12856 return opt_strings_flags(val, values, NULL, list);
12857}
12858
12859/*
12860 * Handle an option that can be a range of string values.
12861 * Set a flag in "*flagp" for each string present.
12862 *
12863 * Return OK for correct value, FAIL otherwise.
12864 * Empty is always OK.
12865 */
12866 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012867opt_strings_flags(
12868 char_u *val, /* new value */
12869 char **values, /* array of valid string values */
12870 unsigned *flagp,
12871 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012872{
12873 int i;
12874 int len;
12875 unsigned new_flags = 0;
12876
12877 while (*val)
12878 {
12879 for (i = 0; ; ++i)
12880 {
12881 if (values[i] == NULL) /* val not found in values[] */
12882 return FAIL;
12883
12884 len = (int)STRLEN(values[i]);
12885 if (STRNCMP(values[i], val, len) == 0
12886 && ((list && val[len] == ',') || val[len] == NUL))
12887 {
12888 val += len + (val[len] == ',');
12889 new_flags |= (1 << i);
12890 break; /* check next item in val list */
12891 }
12892 }
12893 }
12894 if (flagp != NULL)
12895 *flagp = new_flags;
12896
12897 return OK;
12898}
12899
12900/*
12901 * Read the 'wildmode' option, fill wim_flags[].
12902 */
12903 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012904check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012905{
12906 char_u new_wim_flags[4];
12907 char_u *p;
12908 int i;
12909 int idx = 0;
12910
12911 for (i = 0; i < 4; ++i)
12912 new_wim_flags[i] = 0;
12913
12914 for (p = p_wim; *p; ++p)
12915 {
12916 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12917 ;
12918 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12919 return FAIL;
12920 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12921 new_wim_flags[idx] |= WIM_LONGEST;
12922 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12923 new_wim_flags[idx] |= WIM_FULL;
12924 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12925 new_wim_flags[idx] |= WIM_LIST;
12926 else
12927 return FAIL;
12928 p += i;
12929 if (*p == NUL)
12930 break;
12931 if (*p == ',')
12932 {
12933 if (idx == 3)
12934 return FAIL;
12935 ++idx;
12936 }
12937 }
12938
12939 /* fill remaining entries with last flag */
12940 while (idx < 3)
12941 {
12942 new_wim_flags[idx + 1] = new_wim_flags[idx];
12943 ++idx;
12944 }
12945
12946 /* only when there are no errors, wim_flags[] is changed */
12947 for (i = 0; i < 4; ++i)
12948 wim_flags[i] = new_wim_flags[i];
12949 return OK;
12950}
12951
12952/*
12953 * Check if backspacing over something is allowed.
12954 */
12955 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012956can_bs(
12957 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012958{
Bram Moolenaar6b810d92018-06-04 17:28:44 +020012959#ifdef FEAT_JOB_CHANNEL
12960 if (what == BS_START && bt_prompt(curbuf))
12961 return FALSE;
12962#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012963 switch (*p_bs)
12964 {
12965 case '2': return TRUE;
12966 case '1': return (what != BS_START);
12967 case '0': return FALSE;
12968 }
12969 return vim_strchr(p_bs, what) != NULL;
12970}
12971
12972/*
12973 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12974 * the file must be considered changed when the value is different.
12975 */
12976 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012977save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012978{
12979 buf->b_start_ffc = *buf->b_p_ff;
12980 buf->b_start_eol = buf->b_p_eol;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012981 buf->b_start_bomb = buf->b_p_bomb;
12982
Bram Moolenaar071d4272004-06-13 20:20:40 +000012983 /* Only use free/alloc when necessary, they take time. */
12984 if (buf->b_start_fenc == NULL
12985 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12986 {
12987 vim_free(buf->b_start_fenc);
12988 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12989 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012990}
12991
12992/*
12993 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12994 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012995 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12996 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012997 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012998 * When "ignore_empty" is true don't consider a new, empty buffer to be
12999 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000013000 */
13001 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013002file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000013003{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000013004 /* In a buffer that was never loaded the options are not valid. */
13005 if (buf->b_flags & BF_NEVERLOADED)
13006 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010013007 if (ignore_empty
13008 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000013009 && buf->b_ml.ml_line_count == 1
13010 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
13011 return FALSE;
13012 if (buf->b_start_ffc != *buf->b_p_ff)
13013 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020013014 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000013015 return TRUE;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000013016 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
13017 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000013018 if (buf->b_start_fenc == NULL)
13019 return (*buf->b_p_fenc != NUL);
13020 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +000013021}
13022
13023/*
13024 * return OK if "p" is a valid fileformat name, FAIL otherwise.
13025 */
13026 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013027check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000013028{
13029 return check_opt_strings(p, p_ff_values, FALSE);
13030}
Bram Moolenaar14f24742012-08-08 18:01:05 +020013031
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010013032#if defined(FEAT_VARTABS) || defined(PROTO)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013033
13034/*
13035 * Set the integer values corresponding to the string setting of 'vartabstop'.
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010013036 * "array" will be set, caller must free it if needed.
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013037 */
13038 int
13039tabstop_set(char_u *var, int **array)
13040{
13041 int valcount = 1;
13042 int t;
13043 char_u *cp;
13044
Bram Moolenaar64f41072018-10-15 22:51:50 +020013045 if (var[0] == NUL || (var[0] == '0' && var[1] == NUL))
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013046 {
13047 *array = NULL;
13048 return TRUE;
13049 }
13050
Bram Moolenaar64f41072018-10-15 22:51:50 +020013051 for (cp = var; *cp != NUL; ++cp)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013052 {
Bram Moolenaar64f41072018-10-15 22:51:50 +020013053 if (cp == var || cp[-1] == ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013054 {
13055 char_u *end;
Bram Moolenaar64f41072018-10-15 22:51:50 +020013056
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013057 if (strtol((char *)cp, (char **)&end, 10) <= 0)
13058 {
13059 if (cp != end)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010013060 emsg(_(e_positive));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013061 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010013062 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013063 return FALSE;
13064 }
13065 }
13066
13067 if (VIM_ISDIGIT(*cp))
13068 continue;
Bram Moolenaar64f41072018-10-15 22:51:50 +020013069 if (cp[0] == ',' && cp > var && cp[-1] != ',' && cp[1] != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013070 {
13071 ++valcount;
13072 continue;
13073 }
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010013074 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013075 return FALSE;
13076 }
13077
Bram Moolenaarc799fe22019-05-28 23:08:19 +020013078 *array = ALLOC_MULT(int, valcount + 1);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010013079 if (*array == NULL)
13080 return FALSE;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013081 (*array)[0] = valcount;
13082
13083 t = 1;
Bram Moolenaar64f41072018-10-15 22:51:50 +020013084 for (cp = var; *cp != NUL;)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013085 {
13086 (*array)[t++] = atoi((char *)cp);
Bram Moolenaar64f41072018-10-15 22:51:50 +020013087 while (*cp != NUL && *cp != ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013088 ++cp;
Bram Moolenaar64f41072018-10-15 22:51:50 +020013089 if (*cp != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013090 ++cp;
13091 }
13092
13093 return TRUE;
13094}
13095
13096/*
13097 * Calculate the number of screen spaces a tab will occupy.
13098 * If "vts" is set then the tab widths are taken from that array,
13099 * otherwise the value of ts is used.
13100 */
13101 int
13102tabstop_padding(colnr_T col, int ts_arg, int *vts)
13103{
13104 int ts = ts_arg == 0 ? 8 : ts_arg;
13105 int tabcount;
13106 colnr_T tabcol = 0;
13107 int t;
13108 int padding = 0;
13109
13110 if (vts == NULL || vts[0] == 0)
13111 return ts - (col % ts);
13112
13113 tabcount = vts[0];
13114
13115 for (t = 1; t <= tabcount; ++t)
13116 {
13117 tabcol += vts[t];
13118 if (tabcol > col)
13119 {
13120 padding = (int)(tabcol - col);
13121 break;
13122 }
13123 }
13124 if (t > tabcount)
13125 padding = vts[tabcount] - (int)((col - tabcol) % vts[tabcount]);
13126
13127 return padding;
13128}
13129
13130/*
13131 * Find the size of the tab that covers a particular column.
13132 */
13133 int
13134tabstop_at(colnr_T col, int ts, int *vts)
13135{
13136 int tabcount;
13137 colnr_T tabcol = 0;
13138 int t;
13139 int tab_size = 0;
13140
13141 if (vts == 0 || vts[0] == 0)
13142 return ts;
13143
13144 tabcount = vts[0];
13145 for (t = 1; t <= tabcount; ++t)
13146 {
13147 tabcol += vts[t];
13148 if (tabcol > col)
13149 {
13150 tab_size = vts[t];
13151 break;
13152 }
13153 }
13154 if (t > tabcount)
13155 tab_size = vts[tabcount];
13156
13157 return tab_size;
13158}
13159
13160/*
13161 * Find the column on which a tab starts.
13162 */
13163 colnr_T
13164tabstop_start(colnr_T col, int ts, int *vts)
13165{
13166 int tabcount;
13167 colnr_T tabcol = 0;
13168 int t;
13169 int excess;
13170
Bram Moolenaar0119a592018-06-24 23:53:28 +020013171 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013172 return (col / ts) * ts;
13173
13174 tabcount = vts[0];
13175 for (t = 1; t <= tabcount; ++t)
13176 {
13177 tabcol += vts[t];
13178 if (tabcol > col)
13179 return tabcol - vts[t];
13180 }
13181
13182 excess = tabcol % vts[tabcount];
13183 return excess + ((col - excess) / vts[tabcount]) * vts[tabcount];
13184}
13185
13186/*
13187 * Find the number of tabs and spaces necessary to get from one column
13188 * to another.
13189 */
13190 void
13191tabstop_fromto(
13192 colnr_T start_col,
13193 colnr_T end_col,
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013194 int ts_arg,
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013195 int *vts,
13196 int *ntabs,
13197 int *nspcs)
13198{
13199 int spaces = end_col - start_col;
13200 colnr_T tabcol = 0;
13201 int padding = 0;
13202 int tabcount;
13203 int t;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013204 int ts = ts_arg == 0 ? curbuf->b_p_ts : ts_arg;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013205
Bram Moolenaar0119a592018-06-24 23:53:28 +020013206 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013207 {
13208 int tabs = 0;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013209 int initspc = 0;
Bram Moolenaar0119a592018-06-24 23:53:28 +020013210
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013211 initspc = ts - (start_col % ts);
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013212 if (spaces >= initspc)
13213 {
13214 spaces -= initspc;
13215 tabs++;
13216 }
13217 tabs += spaces / ts;
13218 spaces -= (spaces / ts) * ts;
13219
13220 *ntabs = tabs;
13221 *nspcs = spaces;
13222 return;
13223 }
13224
13225 /* Find the padding needed to reach the next tabstop. */
13226 tabcount = vts[0];
13227 for (t = 1; t <= tabcount; ++t)
13228 {
13229 tabcol += vts[t];
13230 if (tabcol > start_col)
13231 {
13232 padding = (int)(tabcol - start_col);
13233 break;
13234 }
13235 }
13236 if (t > tabcount)
13237 padding = vts[tabcount] - (int)((start_col - tabcol) % vts[tabcount]);
13238
13239 /* If the space needed is less than the padding no tabs can be used. */
13240 if (spaces < padding)
13241 {
13242 *ntabs = 0;
13243 *nspcs = spaces;
13244 return;
13245 }
13246
13247 *ntabs = 1;
13248 spaces -= padding;
13249
13250 /* At least one tab has been used. See if any more will fit. */
13251 while (spaces != 0 && ++t <= tabcount)
13252 {
13253 padding = vts[t];
13254 if (spaces < padding)
13255 {
13256 *nspcs = spaces;
13257 return;
13258 }
13259 ++*ntabs;
13260 spaces -= padding;
13261 }
13262
13263 *ntabs += spaces / vts[tabcount];
13264 *nspcs = spaces % vts[tabcount];
13265}
13266
13267/*
13268 * See if two tabstop arrays contain the same values.
13269 */
13270 int
13271tabstop_eq(int *ts1, int *ts2)
13272{
13273 int t;
13274
13275 if ((ts1 == 0 && ts2) || (ts1 && ts2 == 0))
13276 return FALSE;
13277 if (ts1 == ts2)
13278 return TRUE;
13279 if (ts1[0] != ts2[0])
13280 return FALSE;
13281
13282 for (t = 1; t <= ts1[0]; ++t)
13283 if (ts1[t] != ts2[t])
13284 return FALSE;
13285
13286 return TRUE;
13287}
13288
Bram Moolenaar113e1072019-01-20 15:30:40 +010013289#if defined(FEAT_BEVAL) || defined(PROTO)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013290/*
13291 * Copy a tabstop array, allocating space for the new array.
13292 */
13293 int *
13294tabstop_copy(int *oldts)
13295{
13296 int *newts;
13297 int t;
13298
Bram Moolenaar6ee96582019-04-27 22:06:37 +020013299 if (oldts == NULL)
13300 return NULL;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020013301 newts = ALLOC_MULT(int, oldts[0] + 1);
Bram Moolenaar6ee96582019-04-27 22:06:37 +020013302 if (newts != NULL)
13303 for (t = 0; t <= oldts[0]; ++t)
13304 newts[t] = oldts[t];
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013305 return newts;
13306}
Bram Moolenaar113e1072019-01-20 15:30:40 +010013307#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013308
13309/*
13310 * Return a count of the number of tabstops.
13311 */
13312 int
13313tabstop_count(int *ts)
13314{
13315 return ts != NULL ? ts[0] : 0;
13316}
13317
13318/*
13319 * Return the first tabstop, or 8 if there are no tabstops defined.
13320 */
13321 int
13322tabstop_first(int *ts)
13323{
13324 return ts != NULL ? ts[1] : 8;
13325}
13326
13327#endif
13328
Bram Moolenaar14f24742012-08-08 18:01:05 +020013329/*
13330 * Return the effective shiftwidth value for current buffer, using the
13331 * 'tabstop' value when 'shiftwidth' is zero.
13332 */
13333 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013334get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020013335{
Bram Moolenaarf9514162018-11-22 03:08:29 +010013336 return get_sw_value_col(buf, 0);
13337}
13338
13339/*
13340 * Idem, using the first non-black in the current line.
13341 */
13342 long
13343get_sw_value_indent(buf_T *buf)
13344{
13345 pos_T pos = curwin->w_cursor;
13346
13347 pos.col = getwhitecols_curline();
13348 return get_sw_value_pos(buf, &pos);
13349}
13350
13351/*
13352 * Idem, using "pos".
13353 */
13354 long
13355get_sw_value_pos(buf_T *buf, pos_T *pos)
13356{
13357 pos_T save_cursor = curwin->w_cursor;
13358 long sw_value;
13359
13360 curwin->w_cursor = *pos;
13361 sw_value = get_sw_value_col(buf, get_nolist_virtcol());
13362 curwin->w_cursor = save_cursor;
13363 return sw_value;
13364}
13365
13366/*
13367 * Idem, using virtual column "col".
13368 */
13369 long
13370get_sw_value_col(buf_T *buf, colnr_T col UNUSED)
13371{
13372 return buf->b_p_sw ? buf->b_p_sw :
13373 #ifdef FEAT_VARTABS
13374 tabstop_at(col, buf->b_p_ts, buf->b_p_vts_array);
13375 #else
13376 buf->b_p_ts;
13377 #endif
Bram Moolenaar14f24742012-08-08 18:01:05 +020013378}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013379
13380/*
13381 * Return the effective softtabstop value for the current buffer, using the
Bram Moolenaar33d5ab32018-07-02 20:51:24 +020013382 * 'shiftwidth' value when 'softtabstop' is negative.
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013383 */
13384 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013385get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013386{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010013387 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013388}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013389
13390/*
Bram Moolenaar375e3392019-01-31 18:26:10 +010013391 * Return the effective 'scrolloff' value for the current window, using the
13392 * global value when appropriate.
13393 */
13394 long
13395get_scrolloff_value(void)
13396{
13397 return curwin->w_p_so < 0 ? p_so : curwin->w_p_so;
13398}
13399
13400/*
13401 * Return the effective 'sidescrolloff' value for the current window, using the
13402 * global value when appropriate.
13403 */
13404 long
13405get_sidescrolloff_value(void)
13406{
13407 return curwin->w_p_siso < 0 ? p_siso : curwin->w_p_siso;
13408}
13409
13410/*
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013411 * Check matchpairs option for "*initc".
13412 * If there is a match set "*initc" to the matching character and "*findc" to
13413 * the opposite character. Set "*backwards" to the direction.
13414 * When "switchit" is TRUE swap the direction.
13415 */
13416 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010013417find_mps_values(
13418 int *initc,
13419 int *findc,
13420 int *backwards,
13421 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013422{
13423 char_u *ptr;
13424
13425 ptr = curbuf->b_p_mps;
13426 while (*ptr != NUL)
13427 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013428 if (has_mbyte)
13429 {
13430 char_u *prev;
13431
13432 if (mb_ptr2char(ptr) == *initc)
13433 {
13434 if (switchit)
13435 {
13436 *findc = *initc;
13437 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13438 *backwards = TRUE;
13439 }
13440 else
13441 {
13442 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13443 *backwards = FALSE;
13444 }
13445 return;
13446 }
13447 prev = ptr;
13448 ptr += mb_ptr2len(ptr) + 1;
13449 if (mb_ptr2char(ptr) == *initc)
13450 {
13451 if (switchit)
13452 {
13453 *findc = *initc;
13454 *initc = mb_ptr2char(prev);
13455 *backwards = FALSE;
13456 }
13457 else
13458 {
13459 *findc = mb_ptr2char(prev);
13460 *backwards = TRUE;
13461 }
13462 return;
13463 }
13464 ptr += mb_ptr2len(ptr);
13465 }
13466 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013467 {
13468 if (*ptr == *initc)
13469 {
13470 if (switchit)
13471 {
13472 *backwards = TRUE;
13473 *findc = *initc;
13474 *initc = ptr[2];
13475 }
13476 else
13477 {
13478 *backwards = FALSE;
13479 *findc = ptr[2];
13480 }
13481 return;
13482 }
13483 ptr += 2;
13484 if (*ptr == *initc)
13485 {
13486 if (switchit)
13487 {
13488 *backwards = FALSE;
13489 *findc = *initc;
13490 *initc = ptr[-2];
13491 }
13492 else
13493 {
13494 *backwards = TRUE;
13495 *findc = ptr[-2];
13496 }
13497 return;
13498 }
13499 ++ptr;
13500 }
13501 if (*ptr == ',')
13502 ++ptr;
13503 }
13504}
Bram Moolenaar597a4222014-06-25 14:39:50 +020013505
13506#if defined(FEAT_LINEBREAK) || defined(PROTO)
13507/*
13508 * This is called when 'breakindentopt' is changed and when a window is
13509 * initialized.
13510 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013511 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013512briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020013513{
13514 char_u *p;
13515 int bri_shift = 0;
13516 long bri_min = 20;
13517 int bri_sbr = FALSE;
13518
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013519 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013520 while (*p != NUL)
13521 {
13522 if (STRNCMP(p, "shift:", 6) == 0
13523 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
13524 {
13525 p += 6;
13526 bri_shift = getdigits(&p);
13527 }
13528 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
13529 {
13530 p += 4;
13531 bri_min = getdigits(&p);
13532 }
13533 else if (STRNCMP(p, "sbr", 3) == 0)
13534 {
13535 p += 3;
13536 bri_sbr = TRUE;
13537 }
13538 if (*p != ',' && *p != NUL)
13539 return FAIL;
13540 if (*p == ',')
13541 ++p;
13542 }
13543
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013544 wp->w_p_brishift = bri_shift;
13545 wp->w_p_brimin = bri_min;
13546 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013547
13548 return OK;
13549}
13550#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013551
13552/*
13553 * Get the local or global value of 'backupcopy'.
13554 */
13555 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013556get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013557{
13558 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
13559}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020013560
13561#if defined(FEAT_SIGNS) || defined(PROTO)
13562/*
13563 * Return TRUE when window "wp" has a column to draw signs in.
13564 */
13565 int
13566signcolumn_on(win_T *wp)
13567{
Bram Moolenaar394c5d82019-06-17 21:48:05 +020013568 // If 'signcolumn' is set to 'number', signs are displayed in the 'number'
13569 // column (if present). Otherwise signs are to be displayed in the sign
13570 // column.
13571 if (*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
13572 return wp->w_buffer->b_signlist != NULL && !wp->w_p_nu && !wp->w_p_rnu;
13573
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020013574 if (*wp->w_p_scl == 'n')
13575 return FALSE;
13576 if (*wp->w_p_scl == 'y')
13577 return TRUE;
13578 return (wp->w_buffer->b_signlist != NULL
13579# ifdef FEAT_NETBEANS_INTG
13580 || wp->w_buffer->b_has_sign_column
13581# endif
13582 );
13583}
13584#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013585
13586#if defined(FEAT_EVAL) || defined(PROTO)
13587/*
13588 * Get window or buffer local options.
13589 */
13590 dict_T *
13591get_winbuf_options(int bufopt)
13592{
13593 dict_T *d;
13594 int opt_idx;
13595
13596 d = dict_alloc();
13597 if (d == NULL)
13598 return NULL;
13599
13600 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
13601 {
13602 struct vimoption *opt = &options[opt_idx];
13603
13604 if ((bufopt && (opt->indir & PV_BUF))
13605 || (!bufopt && (opt->indir & PV_WIN)))
13606 {
13607 char_u *varp = get_varp(opt);
13608
13609 if (varp != NULL)
13610 {
13611 if (opt->flags & P_STRING)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013612 dict_add_string(d, opt->fullname, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020013613 else if (opt->flags & P_NUM)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013614 dict_add_number(d, opt->fullname, *(long *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013615 else
Bram Moolenaare0be1672018-07-08 16:50:37 +020013616 dict_add_number(d, opt->fullname, *(int *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013617 }
13618 }
13619 }
13620
13621 return d;
13622}
13623#endif