blob: bf253a461bb2eb695bc5fa84c386e3ec5848a9ad [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);
Bram Moolenaarc7f1e402019-08-03 13:29:46 +02007934 curbuf->b_flags |= BF_SYN_SET;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007935 --syn_recursive;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007936 }
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007937#endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007938 else if (varp == &(curbuf->b_p_ft))
7939 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007940 /* 'filetype' is set, trigger the FileType autocommand.
7941 * Skip this when called from a modeline and the filetype was
Bram Moolenaara5616b02018-06-17 19:08:30 +02007942 * already set to this value. */
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007943 if (!(opt_flags & OPT_MODELINE) || value_changed)
Bram Moolenaar90492982017-06-22 14:16:31 +02007944 {
Bram Moolenaar916a8182018-11-25 02:18:29 +01007945 static int ft_recursive = 0;
7946 int secure_save = secure;
7947
7948 // Reset the secure flag, since the value of 'filetype' has
7949 // been checked to be safe.
7950 secure = 0;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007951
7952 ++ft_recursive;
Bram Moolenaar90492982017-06-22 14:16:31 +02007953 did_filetype = TRUE;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007954 // Only pass TRUE for "force" when the value changed or not
7955 // used recursively, to avoid endless recurrence.
7956 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname,
7957 value_changed || ft_recursive == 1, curbuf);
7958 --ft_recursive;
Bram Moolenaar163095f2017-07-09 15:41:53 +02007959 /* Just in case the old "curbuf" is now invalid. */
7960 if (varp != &(curbuf->b_p_ft))
7961 varp = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007962
7963 secure = secure_save;
Bram Moolenaar90492982017-06-22 14:16:31 +02007964 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007965 }
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007966#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007967 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007968 {
7969 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007970 char_u *q = curwin->w_s->b_p_spl;
7971
7972 /* Skip the first name if it is "cjk". */
7973 if (STRNCMP(q, "cjk,", 4) == 0)
7974 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007975
7976 /*
7977 * Source the spell/LANG.vim in 'runtimepath'.
7978 * They could set 'spellcapcheck' depending on the language.
7979 * Use the first name in 'spelllang' up to '_region' or
7980 * '.encoding'.
7981 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007982 for (p = q; *p != NUL; ++p)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01007983 if (!ASCII_ISALNUM(*p) && *p != '-')
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007984 break;
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007985 if (p > q)
7986 {
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02007987 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
7988 (int)(p - q), q);
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007989 source_runtime(fname, DIP_ALL);
7990 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007991 }
7992#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007993 }
7994
7995#ifdef FEAT_MOUSE
7996 if (varp == &p_mouse)
7997 {
7998# ifdef FEAT_MOUSE_TTY
7999 if (*p_mouse == NUL)
8000 mch_setmouse(FALSE); /* switch mouse off */
8001 else
8002# endif
8003 setmouse(); /* in case 'mouse' changed */
8004 }
8005#endif
8006
Bram Moolenaar913077c2012-03-28 19:59:04 +02008007 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008008 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008009 curwin->w_set_curswant = TRUE;
8010
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00008011#ifdef FEAT_GUI
8012 /* check redraw when it's not a GUI option or the GUI is active. */
8013 if (!redraw_gui_only || gui.in_use)
8014#endif
8015 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008016
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008017#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
8018 if (did_swaptcap)
8019 {
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008020 set_termname((char_u *)"win32");
8021 init_highlight(TRUE, FALSE);
8022 }
8023#endif
8024
Bram Moolenaar071d4272004-06-13 20:20:40 +00008025 return errmsg;
8026}
8027
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01008028#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02008029/*
8030 * Simple int comparison function for use with qsort()
8031 */
8032 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01008033int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02008034{
8035 return *(const int *)a - *(const int *)b;
8036}
8037
8038/*
8039 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
8040 * Returns error message, NULL if it's OK.
8041 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008042 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008043check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02008044{
8045 char_u *s;
8046 int col;
8047 int count = 0;
8048 int color_cols[256];
8049 int i;
8050 int j = 0;
8051
Bram Moolenaar50f834d2011-09-21 13:40:17 +02008052 if (wp->w_buffer == NULL)
8053 return NULL; /* buffer was closed */
8054
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008055 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02008056 {
8057 if (*s == '-' || *s == '+')
8058 {
8059 /* -N and +N: add to 'textwidth' */
8060 col = (*s == '-') ? -1 : 1;
8061 ++s;
8062 if (!VIM_ISDIGIT(*s))
8063 return e_invarg;
8064 col = col * getdigits(&s);
8065 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008066 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02008067 col += wp->w_buffer->b_p_tw;
8068 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008069 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02008070 }
8071 else if (VIM_ISDIGIT(*s))
8072 col = getdigits(&s);
8073 else
8074 return e_invarg;
8075 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008076skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02008077 if (*s == NUL)
8078 break;
8079 if (*s != ',')
8080 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008081 if (*++s == NUL)
8082 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02008083 }
8084
8085 vim_free(wp->w_p_cc_cols);
8086 if (count == 0)
8087 wp->w_p_cc_cols = NULL;
8088 else
8089 {
Bram Moolenaarc799fe22019-05-28 23:08:19 +02008090 wp->w_p_cc_cols = ALLOC_MULT(int, count + 1);
Bram Moolenaar1a384422010-07-14 19:53:30 +02008091 if (wp->w_p_cc_cols != NULL)
8092 {
8093 /* sort the columns for faster usage on screen redraw inside
8094 * win_line() */
8095 qsort(color_cols, count, sizeof(int), int_cmp);
8096
8097 for (i = 0; i < count; ++i)
8098 /* skip duplicates */
8099 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
8100 wp->w_p_cc_cols[j++] = color_cols[i];
8101 wp->w_p_cc_cols[j] = -1; /* end marker */
8102 }
8103 }
8104
8105 return NULL; /* no error */
8106}
8107#endif
8108
Bram Moolenaar071d4272004-06-13 20:20:40 +00008109/*
8110 * Handle setting 'listchars' or 'fillchars'.
8111 * Returns error message, NULL if it's OK.
8112 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008113 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008114set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008115{
8116 int round, i, len, entries;
8117 char_u *p, *s;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008118 int c1 = 0, c2 = 0, c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008119 struct charstab
8120 {
8121 int *cp;
8122 char *name;
8123 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00008124 static struct charstab filltab[] =
8125 {
8126 {&fill_stl, "stl"},
8127 {&fill_stlnc, "stlnc"},
8128 {&fill_vert, "vert"},
8129 {&fill_fold, "fold"},
8130 {&fill_diff, "diff"},
8131 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00008132 static struct charstab lcstab[] =
8133 {
8134 {&lcs_eol, "eol"},
8135 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008136 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00008137 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02008138 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00008139 {&lcs_tab2, "tab"},
8140 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02008141#ifdef FEAT_CONCEAL
8142 {&lcs_conceal, "conceal"},
8143#else
8144 {NULL, "conceal"},
8145#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008146 };
8147 struct charstab *tab;
8148
Bram Moolenaar071d4272004-06-13 20:20:40 +00008149 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008150 {
8151 tab = lcstab;
8152 entries = sizeof(lcstab) / sizeof(struct charstab);
8153 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008154 else
8155 {
8156 tab = filltab;
8157 entries = sizeof(filltab) / sizeof(struct charstab);
8158 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008159
8160 /* first round: check for valid value, second round: assign values */
8161 for (round = 0; round <= 1; ++round)
8162 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008163 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008164 {
8165 /* After checking that the value is valid: set defaults: space for
8166 * 'fillchars', NUL for 'listchars' */
8167 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008168 if (tab[i].cp != NULL)
8169 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar83a52172019-01-16 22:41:54 +01008170
Bram Moolenaar071d4272004-06-13 20:20:40 +00008171 if (varp == &p_lcs)
Bram Moolenaar83a52172019-01-16 22:41:54 +01008172 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008173 lcs_tab1 = NUL;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008174 lcs_tab3 = NUL;
8175 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008176 else
8177 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008178 }
8179 p = *varp;
8180 while (*p)
8181 {
8182 for (i = 0; i < entries; ++i)
8183 {
8184 len = (int)STRLEN(tab[i].name);
8185 if (STRNCMP(p, tab[i].name, len) == 0
8186 && p[len] == ':'
8187 && p[len + 1] != NUL)
8188 {
Bram Moolenaar2c519cf2019-03-21 21:45:34 +01008189 c2 = c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008190 s = p + len + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008191 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00008192 if (mb_char2cells(c1) > 1)
8193 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008194 if (tab[i].cp == &lcs_tab2)
8195 {
8196 if (*s == NUL)
8197 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008198 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00008199 if (mb_char2cells(c2) > 1)
8200 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008201 if (!(*s == ',' || *s == NUL))
8202 {
Bram Moolenaar83a52172019-01-16 22:41:54 +01008203 c3 = mb_ptr2char_adv(&s);
8204 if (mb_char2cells(c3) > 1)
8205 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008206 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008207 }
Bram Moolenaar83a52172019-01-16 22:41:54 +01008208
Bram Moolenaar071d4272004-06-13 20:20:40 +00008209 if (*s == ',' || *s == NUL)
8210 {
8211 if (round)
8212 {
8213 if (tab[i].cp == &lcs_tab2)
8214 {
8215 lcs_tab1 = c1;
8216 lcs_tab2 = c2;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008217 lcs_tab3 = c3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008218 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008219 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008220 *(tab[i].cp) = c1;
8221
8222 }
8223 p = s;
8224 break;
8225 }
8226 }
8227 }
8228
8229 if (i == entries)
8230 return e_invarg;
8231 if (*p == ',')
8232 ++p;
8233 }
8234 }
8235
8236 return NULL; /* no error */
8237}
8238
8239#ifdef FEAT_STL_OPT
8240/*
8241 * Check validity of options with the 'statusline' format.
8242 * Return error message or NULL.
8243 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008244 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008245check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008246{
8247 int itemcnt = 0;
8248 int groupdepth = 0;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008249 static char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00008250
8251 while (*s && itemcnt < STL_MAX_ITEM)
8252 {
8253 /* Check for valid keys after % sequences */
8254 while (*s && *s != '%')
8255 s++;
8256 if (!*s)
8257 break;
8258 s++;
8259 if (*s != '%' && *s != ')')
8260 ++itemcnt;
8261 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
8262 {
8263 s++;
8264 continue;
8265 }
8266 if (*s == ')')
8267 {
8268 s++;
8269 if (--groupdepth < 0)
8270 break;
8271 continue;
8272 }
8273 if (*s == '-')
8274 s++;
8275 while (VIM_ISDIGIT(*s))
8276 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00008277 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008278 continue;
8279 if (*s == '.')
8280 {
8281 s++;
8282 while (*s && VIM_ISDIGIT(*s))
8283 s++;
8284 }
8285 if (*s == '(')
8286 {
8287 groupdepth++;
8288 continue;
8289 }
8290 if (vim_strchr(STL_ALL, *s) == NULL)
8291 {
8292 return illegal_char(errbuf, *s);
8293 }
8294 if (*s == '{')
8295 {
8296 s++;
8297 while (*s != '}' && *s)
8298 s++;
8299 if (*s != '}')
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008300 return N_("E540: Unclosed expression sequence");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008301 }
8302 }
8303 if (itemcnt >= STL_MAX_ITEM)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008304 return N_("E541: too many items");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008305 if (groupdepth != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008306 return N_("E542: unbalanced groups");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008307 return NULL;
8308}
8309#endif
8310
8311#ifdef FEAT_CLIPBOARD
8312/*
8313 * Extract the items in the 'clipboard' option and set global values.
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008314 * Return an error message or NULL for success.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008315 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008316 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008317check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008318{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008319 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008320 int new_autoselect_star = FALSE;
8321 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008322 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008323 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008324 regprog_T *new_exclude_prog = NULL;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008325 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008326 char_u *p;
8327
8328 for (p = p_cb; *p != NUL; )
8329 {
8330 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
8331 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008332 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008333 p += 7;
8334 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02008335 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008336 && (p[11] == ',' || p[11] == NUL))
8337 {
8338 new_unnamed |= CLIP_UNNAMED_PLUS;
8339 p += 11;
8340 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008341 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008342 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008343 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02008344 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008345 p += 10;
8346 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02008347 else if (STRNCMP(p, "autoselectplus", 14) == 0
8348 && (p[14] == ',' || p[14] == NUL))
8349 {
8350 new_autoselect_plus = TRUE;
8351 p += 14;
8352 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008353 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008354 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008355 {
8356 new_autoselectml = TRUE;
8357 p += 12;
8358 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008359 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
8360 {
8361 new_html = TRUE;
8362 p += 4;
8363 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008364 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
8365 {
8366 p += 8;
8367 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
8368 if (new_exclude_prog == NULL)
8369 errmsg = e_invarg;
8370 break;
8371 }
8372 else
8373 {
8374 errmsg = e_invarg;
8375 break;
8376 }
8377 if (*p == ',')
8378 ++p;
8379 }
8380 if (errmsg == NULL)
8381 {
8382 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008383 clip_autoselect_star = new_autoselect_star;
8384 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008385 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008386 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008387 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008388 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008389#ifdef FEAT_GUI_GTK
8390 if (gui.in_use)
8391 {
8392 gui_gtk_set_selection_targets();
8393 gui_gtk_set_dnd_targets();
8394 }
8395#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008396 }
8397 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008398 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008399
8400 return errmsg;
8401}
8402#endif
8403
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008404#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008405/*
8406 * Handle side effects of setting 'spell'.
8407 * Return an error message or NULL for success.
8408 */
8409 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008410did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008411{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008412 char *errmsg = NULL;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008413 win_T *wp;
8414 int l;
8415
8416 if (is_spellfile)
8417 {
8418 l = (int)STRLEN(curwin->w_s->b_p_spf);
8419 if (l > 0 && (l < 4
8420 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8421 errmsg = e_invarg;
8422 }
8423
8424 if (errmsg == NULL)
8425 {
8426 FOR_ALL_WINDOWS(wp)
8427 if (wp->w_buffer == curbuf && wp->w_p_spell)
8428 {
8429 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008430 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008431 }
8432 }
8433 return errmsg;
8434}
8435
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008436/*
8437 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8438 * Return error message when failed, NULL when OK.
8439 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008440 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008441compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008442{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008443 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008444 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008445
Bram Moolenaar860cae12010-06-05 23:22:07 +02008446 if (*synblock->b_p_spc == NUL)
8447 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008448 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008449 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008450 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008451 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008452 if (re != NULL)
8453 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008454 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008455 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008456 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008457 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008458 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008459 return e_invarg;
8460 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008461 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008462 }
8463
Bram Moolenaar473de612013-06-08 18:19:48 +02008464 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008465 return NULL;
8466}
8467#endif
8468
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008469#if defined(FEAT_EVAL) || defined(PROTO)
8470/*
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008471 * Set the script_ctx for an option, taking care of setting the buffer- or
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008472 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008473 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008474 static void
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008475set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008476{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008477 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8478 int indir = (int)options[opt_idx].indir;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008479 sctx_T new_script_ctx = script_ctx;
8480
8481 new_script_ctx.sc_lnum += sourcing_lnum;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008482
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008483 /* Remember where the option was set. For local options need to do that
8484 * in the buffer or window structure. */
8485 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008486 options[opt_idx].script_ctx = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008487 if (both || (opt_flags & OPT_LOCAL))
8488 {
8489 if (indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008490 curbuf->b_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008491 else if (indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008492 curwin->w_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008493 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008494}
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02008495
8496/*
8497 * Set the script_ctx for a termcap option.
8498 * "name" must be the two character code, e.g. "RV".
8499 * When "name" is NULL use "opt_idx".
8500 */
8501 void
8502set_term_option_sctx_idx(char *name, int opt_idx)
8503{
8504 char_u buf[5];
8505 int idx;
8506
8507 if (name == NULL)
8508 idx = opt_idx;
8509 else
8510 {
8511 buf[0] = 't';
8512 buf[1] = '_';
8513 buf[2] = name[0];
8514 buf[3] = name[1];
8515 buf[4] = 0;
8516 idx = findoption(buf);
8517 }
8518 if (idx >= 0)
8519 set_option_sctx_idx(idx, OPT_GLOBAL, current_sctx);
8520}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008521#endif
8522
Bram Moolenaar071d4272004-06-13 20:20:40 +00008523/*
8524 * Set the value of a boolean option, and take care of side effects.
8525 * Returns NULL for success, or an error message for an error.
8526 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008527 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008528set_bool_option(
8529 int opt_idx, /* index in options[] table */
8530 char_u *varp, /* pointer to the option variable */
8531 int value, /* new value */
8532 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008533{
8534 int old_value = *(int *)varp;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008535#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02008536 int old_global_value = 0;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008537#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008538
Bram Moolenaar071d4272004-06-13 20:20:40 +00008539 /* Disallow changing some options from secure mode */
8540 if ((secure
8541#ifdef HAVE_SANDBOX
8542 || sandbox != 0
8543#endif
8544 ) && (options[opt_idx].flags & P_SECURE))
8545 return e_secure;
8546
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008547#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02008548 // Save the global value before changing anything. This is needed as for
8549 // a global-only option setting the "local value" in fact sets the global
8550 // value (since there is only one value).
8551 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8552 old_global_value = *(int *)get_varp_scope(&(options[opt_idx]),
8553 OPT_GLOBAL);
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008554#endif
Bram Moolenaard7c96872019-06-15 17:12:48 +02008555
Bram Moolenaar071d4272004-06-13 20:20:40 +00008556 *(int *)varp = value; /* set the new value */
8557#ifdef FEAT_EVAL
8558 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008559 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008560#endif
8561
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008562#ifdef FEAT_GUI
8563 need_mouse_correct = TRUE;
8564#endif
8565
Bram Moolenaar071d4272004-06-13 20:20:40 +00008566 /* May set global value for local option. */
8567 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8568 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8569
8570 /*
8571 * Handle side effects of changing a bool option.
8572 */
8573
8574 /* 'compatible' */
8575 if ((int *)varp == &p_cp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008576 compatible_set();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008577
Bram Moolenaar920694c2016-08-21 17:45:02 +02008578#ifdef FEAT_LANGMAP
8579 if ((int *)varp == &p_lrm)
8580 /* 'langremap' -> !'langnoremap' */
8581 p_lnr = !p_lrm;
8582 else if ((int *)varp == &p_lnr)
8583 /* 'langnoremap' -> !'langremap' */
8584 p_lrm = !p_lnr;
8585#endif
8586
Bram Moolenaar8c63e0e2018-09-25 22:17:54 +02008587#ifdef FEAT_SYN_HL
8588 else if ((int *)varp == &curwin->w_p_cul && !value && old_value)
8589 reset_cursorline();
8590#endif
8591
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008592#ifdef FEAT_PERSISTENT_UNDO
8593 /* 'undofile' */
8594 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8595 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008596 /* Only take action when the option was set. When reset we do not
8597 * delete the undo file, the option may be set again without making
8598 * any changes in between. */
8599 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008600 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008601 char_u hash[UNDO_HASH_SIZE];
8602 buf_T *save_curbuf = curbuf;
8603
Bram Moolenaar29323592016-07-24 22:04:11 +02008604 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008605 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008606 /* When 'undofile' is set globally: for every buffer, otherwise
8607 * only for the current buffer: Try to read in the undofile,
8608 * if one exists, the buffer wasn't changed and the buffer was
8609 * loaded */
8610 if ((curbuf == save_curbuf
8611 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8612 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8613 {
8614 u_compute_hash(hash);
8615 u_read_undo(NULL, hash, curbuf->b_fname);
8616 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008617 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008618 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008619 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008620 }
8621#endif
8622
Bram Moolenaar071d4272004-06-13 20:20:40 +00008623 else if ((int *)varp == &curbuf->b_p_ro)
8624 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008625 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008626 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8627 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008628
8629 /* when 'readonly' is set may give W10 again */
8630 if (curbuf->b_p_ro)
8631 curbuf->b_did_warn = FALSE;
8632
Bram Moolenaar071d4272004-06-13 20:20:40 +00008633#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008634 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008635#endif
8636 }
8637
Bram Moolenaar9c449722010-07-20 18:44:27 +02008638#ifdef FEAT_GUI
8639 else if ((int *)varp == &p_mh)
8640 {
8641 if (!p_mh)
8642 gui_mch_mousehide(FALSE);
8643 }
8644#endif
8645
Bram Moolenaara539df02010-08-01 14:35:05 +02008646 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008647 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008648 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008649# ifdef FEAT_TERMINAL
8650 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaard7db27b2018-03-07 23:02:33 +01008651 if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf)
8652 && curbuf->b_term != NULL && !term_is_finished(curbuf))))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008653 {
8654 curbuf->b_p_ma = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008655 return N_("E946: Cannot make a terminal with running job modifiable");
Bram Moolenaar423802d2017-07-30 16:52:24 +02008656 }
8657# endif
8658# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008659 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008660# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008661 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008662#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008663 /* when 'endofline' is changed, redraw the window title */
8664 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008665 {
8666 redraw_titles();
8667 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008668 /* when 'fixeol' is changed, redraw the window title */
8669 else if ((int *)varp == &curbuf->b_p_fixeol)
8670 {
8671 redraw_titles();
8672 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008673 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008674 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008675 {
8676 redraw_titles();
8677 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008678#endif
8679
8680 /* when 'bin' is set also set some other options */
8681 else if ((int *)varp == &curbuf->b_p_bin)
8682 {
8683 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8684#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008685 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008686#endif
8687 }
8688
Bram Moolenaar071d4272004-06-13 20:20:40 +00008689 /* when 'buflisted' changes, trigger autocommands */
8690 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8691 {
8692 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8693 NULL, NULL, TRUE, curbuf);
8694 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008695
8696 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8697 else if ((int *)varp == &curbuf->b_p_swf)
8698 {
8699 if (curbuf->b_p_swf && p_uc)
8700 ml_open_file(curbuf); /* create the swap file */
8701 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008702 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8703 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008704 mf_close_file(curbuf, TRUE); /* remove the swap file */
8705 }
8706
8707 /* when 'terse' is set change 'shortmess' */
8708 else if ((int *)varp == &p_terse)
8709 {
8710 char_u *p;
8711
8712 p = vim_strchr(p_shm, SHM_SEARCH);
8713
8714 /* insert 's' in p_shm */
8715 if (p_terse && p == NULL)
8716 {
8717 STRCPY(IObuff, p_shm);
8718 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008719 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008720 }
8721 /* remove 's' from p_shm */
8722 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008723 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008724 }
8725
8726 /* when 'paste' is set or reset also change other options */
8727 else if ((int *)varp == &p_paste)
8728 {
8729 paste_option_changed();
8730 }
8731
8732 /* when 'insertmode' is set from an autocommand need to do work here */
8733 else if ((int *)varp == &p_im)
8734 {
8735 if (p_im)
8736 {
8737 if ((State & INSERT) == 0)
8738 need_start_insertmode = TRUE;
8739 stop_insert_mode = FALSE;
8740 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008741 /* only reset if it was set previously */
8742 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008743 {
8744 need_start_insertmode = FALSE;
8745 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008746 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008747 clear_cmdline = TRUE; /* remove "(insert)" */
8748 restart_edit = 0;
8749 }
8750 }
8751
8752 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8753 else if ((int *)varp == &p_ic && p_hls)
8754 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008755 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008756 }
8757
8758#ifdef FEAT_SEARCH_EXTRA
8759 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8760 else if ((int *)varp == &p_hls)
8761 {
Bram Moolenaar451fc7b2018-04-27 22:53:07 +02008762 set_no_hlsearch(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008763 }
8764#endif
8765
Bram Moolenaar071d4272004-06-13 20:20:40 +00008766 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8767 * at the end of normal_cmd() */
8768 else if ((int *)varp == &curwin->w_p_scb)
8769 {
8770 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008771 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008772 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008773 curwin->w_scbind_pos = curwin->w_topline;
8774 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008775 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008776
Bram Moolenaar4033c552017-09-16 20:54:51 +02008777#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008778 /* There can be only one window with 'previewwindow' set. */
8779 else if ((int *)varp == &curwin->w_p_pvw)
8780 {
8781 if (curwin->w_p_pvw)
8782 {
8783 win_T *win;
8784
Bram Moolenaar29323592016-07-24 22:04:11 +02008785 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008786 if (win->w_p_pvw && win != curwin)
8787 {
8788 curwin->w_p_pvw = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008789 return N_("E590: A preview window already exists");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008790 }
8791 }
8792 }
8793#endif
8794
8795 /* when 'textmode' is set or reset also change 'fileformat' */
8796 else if ((int *)varp == &curbuf->b_p_tx)
8797 {
8798 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8799 }
8800
8801 /* when 'textauto' is set or reset also change 'fileformats' */
8802 else if ((int *)varp == &p_ta)
Bram Moolenaarabab0b02019-03-30 18:47:01 +01008803 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008804 set_string_option_direct((char_u *)"ffs", -1,
8805 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008806 OPT_FREE | opt_flags, 0);
Bram Moolenaarabab0b02019-03-30 18:47:01 +01008807 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008808
8809 /*
8810 * When 'lisp' option changes include/exclude '-' in
8811 * keyword characters.
8812 */
8813#ifdef FEAT_LISP
8814 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8815 {
8816 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8817 }
8818#endif
8819
8820#ifdef FEAT_TITLE
8821 /* when 'title' changed, may need to change the title; same for 'icon' */
Bram Moolenaar84a93082018-06-16 22:58:15 +02008822 else if ((int *)varp == &p_title || (int *)varp == &p_icon)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008823 {
Bram Moolenaar84a93082018-06-16 22:58:15 +02008824 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008825 }
8826#endif
8827
8828 else if ((int *)varp == &curbuf->b_changed)
8829 {
8830 if (!value)
8831 save_file_ff(curbuf); /* Buffer is unchanged */
8832#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008833 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008834#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008835 modified_was_set = value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008836 }
8837
8838#ifdef BACKSLASH_IN_FILENAME
8839 else if ((int *)varp == &p_ssl)
8840 {
8841 if (p_ssl)
8842 {
8843 psepc = '/';
8844 psepcN = '\\';
8845 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008846 }
8847 else
8848 {
8849 psepc = '\\';
8850 psepcN = '/';
8851 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008852 }
8853
8854 /* need to adjust the file name arguments and buffer names. */
8855 buflist_slash_adjust();
8856 alist_slash_adjust();
8857# ifdef FEAT_EVAL
8858 scriptnames_slash_adjust();
8859# endif
8860 }
8861#endif
8862
8863 /* If 'wrap' is set, set w_leftcol to zero. */
8864 else if ((int *)varp == &curwin->w_p_wrap)
8865 {
8866 if (curwin->w_p_wrap)
8867 curwin->w_leftcol = 0;
8868 }
8869
Bram Moolenaar071d4272004-06-13 20:20:40 +00008870 else if ((int *)varp == &p_ea)
8871 {
8872 if (p_ea && !old_value)
8873 win_equal(curwin, FALSE, 0);
8874 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008875
8876 else if ((int *)varp == &p_wiv)
8877 {
8878 /*
8879 * When 'weirdinvert' changed, set/reset 't_xs'.
8880 * Then set 'weirdinvert' according to value of 't_xs'.
8881 */
8882 if (p_wiv && !old_value)
8883 T_XS = (char_u *)"y";
8884 else if (!p_wiv && old_value)
8885 T_XS = empty_option;
8886 p_wiv = (*T_XS != NUL);
8887 }
8888
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008889#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008890 else if ((int *)varp == &p_beval)
8891 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008892 if (!balloonEvalForTerm)
8893 {
8894 if (p_beval && !old_value)
8895 gui_mch_enable_beval_area(balloonEval);
8896 else if (!p_beval && old_value)
8897 gui_mch_disable_beval_area(balloonEval);
8898 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008899 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008900#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008901#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008902 else if ((int *)varp == &p_bevalterm)
8903 {
8904 mch_bevalterm_changed();
8905 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008906#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008907
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008908#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008909 else if ((int *)varp == &p_acd)
8910 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008911 /* Change directories when the 'acd' option is set now. */
Bram Moolenaar6f470022018-04-10 18:47:20 +02008912 DO_AUTOCHDIR;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008913 }
8914#endif
8915
8916#ifdef FEAT_DIFF
8917 /* 'diff' */
8918 else if ((int *)varp == &curwin->w_p_diff)
8919 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008920 /* May add or remove the buffer from the list of diff buffers. */
8921 diff_buf_adjust(curwin);
8922# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008923 if (foldmethodIsDiff(curwin))
8924 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008925# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008926 }
8927#endif
8928
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008929#ifdef HAVE_INPUT_METHOD
Bram Moolenaar071d4272004-06-13 20:20:40 +00008930 /* 'imdisable' */
8931 else if ((int *)varp == &p_imdisable)
8932 {
8933 /* Only de-activate it here, it will be enabled when changing mode. */
8934 if (p_imdisable)
8935 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008936 else if (State & INSERT)
8937 /* When the option is set from an autocommand, it may need to take
8938 * effect right away. */
8939 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008940 }
8941#endif
8942
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008943#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008944 /* 'spell' */
8945 else if ((int *)varp == &curwin->w_p_spell)
8946 {
8947 if (curwin->w_p_spell)
8948 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008949 char *errmsg = did_set_spelllang(curwin);
8950
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008951 if (errmsg != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008952 emsg(_(errmsg));
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008953 }
8954 }
8955#endif
8956
Bram Moolenaar071d4272004-06-13 20:20:40 +00008957#ifdef FEAT_ARABIC
8958 if ((int *)varp == &curwin->w_p_arab)
8959 {
8960 if (curwin->w_p_arab)
8961 {
8962 /*
8963 * 'arabic' is set, handle various sub-settings.
8964 */
8965 if (!p_tbidi)
8966 {
8967 /* set rightleft mode */
8968 if (!curwin->w_p_rl)
8969 {
8970 curwin->w_p_rl = TRUE;
8971 changed_window_setting();
8972 }
8973
8974 /* Enable Arabic shaping (major part of what Arabic requires) */
8975 if (!p_arshape)
8976 {
8977 p_arshape = TRUE;
8978 redraw_later_clear();
8979 }
8980 }
8981
8982 /* Arabic requires a utf-8 encoding, inform the user if its not
8983 * set. */
8984 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008985 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008986 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8987
Bram Moolenaar8820b482017-03-16 17:23:31 +01008988 msg_source(HL_ATTR(HLF_W));
Bram Moolenaar32526b32019-01-19 17:43:09 +01008989 msg_attr(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008990#ifdef FEAT_EVAL
8991 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8992#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008993 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008994
Bram Moolenaar071d4272004-06-13 20:20:40 +00008995 /* set 'delcombine' */
8996 p_deco = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008997
8998# ifdef FEAT_KEYMAP
8999 /* Force-set the necessary keymap for arabic */
9000 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
9001 OPT_LOCAL);
9002# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009003 }
9004 else
9005 {
9006 /*
9007 * 'arabic' is reset, handle various sub-settings.
9008 */
9009 if (!p_tbidi)
9010 {
9011 /* reset rightleft mode */
9012 if (curwin->w_p_rl)
9013 {
9014 curwin->w_p_rl = FALSE;
9015 changed_window_setting();
9016 }
9017
9018 /* 'arabicshape' isn't reset, it is a global option and
9019 * another window may still need it "on". */
9020 }
9021
9022 /* 'delcombine' isn't reset, it is a global option and another
9023 * window may still want it "on". */
9024
9025# ifdef FEAT_KEYMAP
9026 /* Revert to the default keymap */
9027 curbuf->b_p_iminsert = B_IMODE_NONE;
9028 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
9029# endif
9030 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00009031 }
9032
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00009033#endif
9034
Bram Moolenaar61be73b2016-04-29 22:59:22 +02009035#ifdef FEAT_TERMGUICOLORS
9036 /* 'termguicolors' */
9037 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02009038 {
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009039# ifdef FEAT_VTP
9040 /* Do not turn on 'tgc' when 24-bit colors are not supported. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02009041 if (
9042# ifdef VIMDLL
9043 !gui.in_use && !gui.starting &&
9044# endif
9045 !has_vtp_working())
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009046 {
9047 p_tgc = 0;
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01009048 return N_("E954: 24-bit colors are not supported on this environment");
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009049 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02009050 if (is_term_win32())
9051 swap_tcap();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009052# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02009053# ifdef FEAT_GUI
9054 if (!gui.in_use && !gui.starting)
9055# endif
9056 highlight_gui_started();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009057# ifdef FEAT_VTP
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009058 /* reset t_Co */
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02009059 if (is_term_win32())
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02009060 {
9061 control_console_color_rgb();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009062 set_termname(T_NAME);
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02009063 init_highlight(TRUE, FALSE);
9064 }
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009065# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02009066 }
9067#endif
9068
Bram Moolenaar071d4272004-06-13 20:20:40 +00009069 /*
9070 * End of handling side effects for bool options.
9071 */
9072
Bram Moolenaar53744302015-07-17 17:38:22 +02009073 /* after handling side effects, call autocommand */
9074
Bram Moolenaar071d4272004-06-13 20:20:40 +00009075 options[opt_idx].flags |= P_WAS_SET;
9076
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009077#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009078 // Don't do this while starting up or recursively.
9079 if (!starting && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009080 {
Bram Moolenaard7c96872019-06-15 17:12:48 +02009081 char_u buf_old[2], buf_old_global[2], buf_new[2], buf_type[7];
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009082
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009083 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009084 vim_snprintf((char *)buf_old_global, 2, "%d",
9085 old_global_value ? TRUE: FALSE);
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009086 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009087 vim_snprintf((char *)buf_type, 7, "%s",
9088 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009089 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9090 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9091 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009092 if (opt_flags & OPT_LOCAL)
9093 {
9094 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
9095 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9096 }
9097 if (opt_flags & OPT_GLOBAL)
9098 {
9099 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
9100 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old, -1);
9101 }
9102 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9103 {
9104 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
9105 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9106 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old_global, -1);
9107 }
9108 if (opt_flags & OPT_MODELINE)
9109 {
9110 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
9111 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9112 }
9113 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname,
9114 NULL, FALSE, NULL);
Bram Moolenaar53744302015-07-17 17:38:22 +02009115 reset_v_option_vars();
9116 }
9117#endif
9118
Bram Moolenaar071d4272004-06-13 20:20:40 +00009119 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009120 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009121 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009122 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009123 check_redraw(options[opt_idx].flags);
9124
9125 return NULL;
9126}
9127
9128/*
9129 * Set the value of a number option, and take care of side effects.
9130 * Returns NULL for success, or an error message for an error.
9131 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009132 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009133set_num_option(
9134 int opt_idx, /* index in options[] table */
9135 char_u *varp, /* pointer to the option variable */
9136 long value, /* new value */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009137 char *errbuf, /* buffer for error messages */
Bram Moolenaar9b578142016-01-30 19:39:49 +01009138 size_t errbuflen, /* length of "errbuf" */
9139 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00009140 OPT_MODELINE */
9141{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009142 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009143 long old_value = *(long *)varp;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02009144#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02009145 long old_global_value = 0; // only used when setting a local and
9146 // global option
Bram Moolenaar983f2f12019-06-16 16:41:41 +02009147#endif
Bram Moolenaard7c96872019-06-15 17:12:48 +02009148 long old_Rows = Rows; // remember old Rows
9149 long old_Columns = Columns; // remember old Columns
Bram Moolenaar071d4272004-06-13 20:20:40 +00009150 long *pp = (long *)varp;
9151
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009152 /* Disallow changing some options from secure mode. */
9153 if ((secure
9154#ifdef HAVE_SANDBOX
9155 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00009156#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009157 ) && (options[opt_idx].flags & P_SECURE))
9158 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009159
Bram Moolenaar983f2f12019-06-16 16:41:41 +02009160#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02009161 // Save the global value before changing anything. This is needed as for
9162 // a global-only option setting the "local value" infact sets the global
9163 // value (since there is only one value).
9164 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
Bram Moolenaar983f2f12019-06-16 16:41:41 +02009165 old_global_value = *(long *)get_varp_scope(&(options[opt_idx]),
9166 OPT_GLOBAL);
9167#endif
Bram Moolenaard7c96872019-06-15 17:12:48 +02009168
Bram Moolenaar071d4272004-06-13 20:20:40 +00009169 *pp = value;
9170#ifdef FEAT_EVAL
9171 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02009172 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009173#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009174#ifdef FEAT_GUI
9175 need_mouse_correct = TRUE;
9176#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009177
Bram Moolenaar14f24742012-08-08 18:01:05 +02009178 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009179 {
9180 errmsg = e_positive;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02009181#ifdef FEAT_VARTABS
9182 // Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use.
9183 curbuf->b_p_sw = tabstop_count(curbuf->b_p_vts_array) > 0
9184 ? tabstop_first(curbuf->b_p_vts_array)
9185 : curbuf->b_p_ts;
9186#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00009187 curbuf->b_p_sw = curbuf->b_p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02009188#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009189 }
9190
9191 /*
9192 * Number options that need some action when changed
9193 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009194 if (pp == &p_wh || pp == &p_hh)
9195 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009196 // 'winheight' and 'helpheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009197 if (p_wh < 1)
9198 {
9199 errmsg = e_positive;
9200 p_wh = 1;
9201 }
9202 if (p_wmh > p_wh)
9203 {
9204 errmsg = e_winheight;
9205 p_wh = p_wmh;
9206 }
9207 if (p_hh < 0)
9208 {
9209 errmsg = e_positive;
9210 p_hh = 0;
9211 }
9212
9213 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01009214 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009215 {
9216 if (pp == &p_wh && curwin->w_height < p_wh)
9217 win_setheight((int)p_wh);
9218 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
9219 win_setheight((int)p_hh);
9220 }
9221 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009222 else if (pp == &p_wmh)
9223 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009224 // 'winminheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009225 if (p_wmh < 0)
9226 {
9227 errmsg = e_positive;
9228 p_wmh = 0;
9229 }
9230 if (p_wmh > p_wh)
9231 {
9232 errmsg = e_winheight;
9233 p_wmh = p_wh;
9234 }
9235 win_setminheight();
9236 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009237 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009238 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009239 // 'winwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009240 if (p_wiw < 1)
9241 {
9242 errmsg = e_positive;
9243 p_wiw = 1;
9244 }
9245 if (p_wmw > p_wiw)
9246 {
9247 errmsg = e_winwidth;
9248 p_wiw = p_wmw;
9249 }
9250
9251 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01009252 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009253 win_setwidth((int)p_wiw);
9254 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009255 else if (pp == &p_wmw)
9256 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009257 // 'winminwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009258 if (p_wmw < 0)
9259 {
9260 errmsg = e_positive;
9261 p_wmw = 0;
9262 }
9263 if (p_wmw > p_wiw)
9264 {
9265 errmsg = e_winwidth;
9266 p_wmw = p_wiw;
9267 }
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009268 win_setminwidth();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009269 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009270
Bram Moolenaar071d4272004-06-13 20:20:40 +00009271 /* (re)set last window status line */
9272 else if (pp == &p_ls)
9273 {
9274 last_status(FALSE);
9275 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009276
9277 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00009278 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009279 {
9280 shell_new_rows(); /* recompute window positions and heights */
9281 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009282
9283#ifdef FEAT_GUI
9284 else if (pp == &p_linespace)
9285 {
Bram Moolenaar02743632005-07-25 20:42:36 +00009286 /* Recompute gui.char_height and resize the Vim window to keep the
9287 * same number of lines. */
9288 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00009289 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009290 }
9291#endif
9292
9293#ifdef FEAT_FOLDING
9294 /* 'foldlevel' */
9295 else if (pp == &curwin->w_p_fdl)
9296 {
9297 if (curwin->w_p_fdl < 0)
9298 curwin->w_p_fdl = 0;
9299 newFoldLevel();
9300 }
9301
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00009302 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009303 else if (pp == &curwin->w_p_fml)
9304 {
9305 foldUpdateAll(curwin);
9306 }
9307
9308 /* 'foldnestmax' */
9309 else if (pp == &curwin->w_p_fdn)
9310 {
9311 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
9312 foldUpdateAll(curwin);
9313 }
9314
9315 /* 'foldcolumn' */
9316 else if (pp == &curwin->w_p_fdc)
9317 {
9318 if (curwin->w_p_fdc < 0)
9319 {
9320 errmsg = e_positive;
9321 curwin->w_p_fdc = 0;
9322 }
9323 else if (curwin->w_p_fdc > 12)
9324 {
9325 errmsg = e_invarg;
9326 curwin->w_p_fdc = 12;
9327 }
9328 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009329#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009330
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009331#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009332 /* 'shiftwidth' or 'tabstop' */
9333 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
9334 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009335# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00009336 if (foldmethodIsIndent(curwin))
9337 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009338# endif
9339# ifdef FEAT_CINDENT
9340 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
9341 * parse 'cinoptions'. */
9342 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
9343 parse_cino(curbuf);
9344# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009345 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009346#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009347
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009348 /* 'maxcombine' */
9349 else if (pp == &p_mco)
9350 {
9351 if (p_mco > MAX_MCO)
9352 p_mco = MAX_MCO;
9353 else if (p_mco < 0)
9354 p_mco = 0;
9355 screenclear(); /* will re-allocate the screen */
9356 }
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009357
Bram Moolenaar071d4272004-06-13 20:20:40 +00009358 else if (pp == &curbuf->b_p_iminsert)
9359 {
9360 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
9361 {
9362 errmsg = e_invarg;
9363 curbuf->b_p_iminsert = B_IMODE_NONE;
9364 }
9365 p_iminsert = curbuf->b_p_iminsert;
9366 if (termcap_active) /* don't do this in the alternate screen */
9367 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02009368#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009369 /* Show/unshow value of 'keymap' in status lines. */
9370 status_redraw_curbuf();
9371#endif
9372 }
9373
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02009374#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
9375 /* 'imstyle' */
9376 else if (pp == &p_imst)
9377 {
9378 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
9379 errmsg = e_invarg;
9380 }
9381#endif
9382
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009383 else if (pp == &p_window)
9384 {
9385 if (p_window < 1)
9386 p_window = 1;
9387 else if (p_window >= Rows)
9388 p_window = Rows - 1;
9389 }
9390
Bram Moolenaar071d4272004-06-13 20:20:40 +00009391 else if (pp == &curbuf->b_p_imsearch)
9392 {
9393 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
9394 {
9395 errmsg = e_invarg;
9396 curbuf->b_p_imsearch = B_IMODE_NONE;
9397 }
9398 p_imsearch = curbuf->b_p_imsearch;
9399 }
9400
9401#ifdef FEAT_TITLE
9402 /* if 'titlelen' has changed, redraw the title */
9403 else if (pp == &p_titlelen)
9404 {
9405 if (p_titlelen < 0)
9406 {
9407 errmsg = e_positive;
9408 p_titlelen = 85;
9409 }
9410 if (starting != NO_SCREEN && old_value != p_titlelen)
9411 need_maketitle = TRUE;
9412 }
9413#endif
9414
9415 /* if p_ch changed value, change the command line height */
9416 else if (pp == &p_ch)
9417 {
9418 if (p_ch < 1)
9419 {
9420 errmsg = e_positive;
9421 p_ch = 1;
9422 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009423 if (p_ch > Rows - min_rows() + 1)
9424 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009425
9426 /* Only compute the new window layout when startup has been
9427 * completed. Otherwise the frame sizes may be wrong. */
9428 if (p_ch != old_value && full_screen
9429#ifdef FEAT_GUI
9430 && !gui.starting
9431#endif
9432 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009433 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009434 }
9435
9436 /* when 'updatecount' changes from zero to non-zero, open swap files */
9437 else if (pp == &p_uc)
9438 {
9439 if (p_uc < 0)
9440 {
9441 errmsg = e_positive;
9442 p_uc = 100;
9443 }
9444 if (p_uc && !old_value)
9445 ml_open_files();
9446 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009447#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009448 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009449 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009450 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009451 {
9452 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009453 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009454 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009455 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009456 {
9457 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009458 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009459 }
9460 }
9461#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009462#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009463 else if (pp == &p_mzq)
9464 mzvim_reset_timer();
9465#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009466
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009467#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9468 /* 'pyxversion' */
9469 else if (pp == &p_pyx)
9470 {
9471 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9472 errmsg = e_invarg;
9473 }
9474#endif
9475
Bram Moolenaar071d4272004-06-13 20:20:40 +00009476 /* sync undo before 'undolevels' changes */
9477 else if (pp == &p_ul)
9478 {
9479 /* use the old value, otherwise u_sync() may not work properly */
9480 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009481 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009482 p_ul = value;
9483 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009484 else if (pp == &curbuf->b_p_ul)
9485 {
9486 /* use the old value, otherwise u_sync() may not work properly */
9487 curbuf->b_p_ul = old_value;
9488 u_sync(TRUE);
9489 curbuf->b_p_ul = value;
9490 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009491
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009492#ifdef FEAT_LINEBREAK
9493 /* 'numberwidth' must be positive */
9494 else if (pp == &curwin->w_p_nuw)
9495 {
9496 if (curwin->w_p_nuw < 1)
9497 {
9498 errmsg = e_positive;
9499 curwin->w_p_nuw = 1;
9500 }
Bram Moolenaarf8a07122019-07-01 22:06:07 +02009501 if (curwin->w_p_nuw > 20)
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009502 {
9503 errmsg = e_invarg;
Bram Moolenaarf8a07122019-07-01 22:06:07 +02009504 curwin->w_p_nuw = 20;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009505 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009506 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009507 }
9508#endif
9509
Bram Moolenaar1a384422010-07-14 19:53:30 +02009510 else if (pp == &curbuf->b_p_tw)
9511 {
9512 if (curbuf->b_p_tw < 0)
9513 {
9514 errmsg = e_positive;
9515 curbuf->b_p_tw = 0;
9516 }
9517#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009518 {
9519 win_T *wp;
9520 tabpage_T *tp;
9521
9522 FOR_ALL_TAB_WINDOWS(tp, wp)
9523 check_colorcolumn(wp);
9524 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009525#endif
9526 }
9527
Bram Moolenaar071d4272004-06-13 20:20:40 +00009528 /*
9529 * Check the bounds for numeric options here
9530 */
9531 if (Rows < min_rows() && full_screen)
9532 {
9533 if (errbuf != NULL)
9534 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009535 vim_snprintf((char *)errbuf, errbuflen,
9536 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009537 errmsg = errbuf;
9538 }
9539 Rows = min_rows();
9540 }
9541 if (Columns < MIN_COLUMNS && full_screen)
9542 {
9543 if (errbuf != NULL)
9544 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009545 vim_snprintf((char *)errbuf, errbuflen,
9546 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009547 errmsg = errbuf;
9548 }
9549 Columns = MIN_COLUMNS;
9550 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009551 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009552
Bram Moolenaar071d4272004-06-13 20:20:40 +00009553 /*
9554 * If the screen (shell) height has been changed, assume it is the
9555 * physical screenheight.
9556 */
9557 if (old_Rows != Rows || old_Columns != Columns)
9558 {
9559 /* Changing the screen size is not allowed while updating the screen. */
9560 if (updating_screen)
9561 *pp = old_value;
9562 else if (full_screen
9563#ifdef FEAT_GUI
9564 && !gui.starting
9565#endif
9566 )
9567 set_shellsize((int)Columns, (int)Rows, TRUE);
9568 else
9569 {
9570 /* Postpone the resizing; check the size and cmdline position for
9571 * messages. */
9572 check_shellsize();
9573 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9574 cmdline_row = Rows - p_ch;
9575 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009576 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009577 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009578 }
9579
Bram Moolenaar071d4272004-06-13 20:20:40 +00009580 if (curbuf->b_p_ts <= 0)
9581 {
9582 errmsg = e_positive;
9583 curbuf->b_p_ts = 8;
9584 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009585 if (p_tm < 0)
9586 {
9587 errmsg = e_positive;
9588 p_tm = 0;
9589 }
9590 if ((curwin->w_p_scr <= 0
9591 || (curwin->w_p_scr > curwin->w_height
9592 && curwin->w_height > 0))
9593 && full_screen)
9594 {
9595 if (pp == &(curwin->w_p_scr))
9596 {
9597 if (curwin->w_p_scr != 0)
9598 errmsg = e_scroll;
9599 win_comp_scroll(curwin);
9600 }
9601 /* If 'scroll' became invalid because of a side effect silently adjust
9602 * it. */
9603 else if (curwin->w_p_scr <= 0)
9604 curwin->w_p_scr = 1;
9605 else /* curwin->w_p_scr > curwin->w_height */
9606 curwin->w_p_scr = curwin->w_height;
9607 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009608 if (p_hi < 0)
9609 {
9610 errmsg = e_positive;
9611 p_hi = 0;
9612 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009613 else if (p_hi > 10000)
9614 {
9615 errmsg = e_invarg;
9616 p_hi = 10000;
9617 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009618 if (p_re < 0 || p_re > 2)
9619 {
9620 errmsg = e_invarg;
9621 p_re = 0;
9622 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009623 if (p_report < 0)
9624 {
9625 errmsg = e_positive;
9626 p_report = 1;
9627 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009628 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009629 {
9630 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9631 p_sj = Rows / 2;
9632 else
9633 {
9634 errmsg = e_scroll;
9635 p_sj = 1;
9636 }
9637 }
9638 if (p_so < 0 && full_screen)
9639 {
Bram Moolenaar375e3392019-01-31 18:26:10 +01009640 errmsg = e_positive;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009641 p_so = 0;
9642 }
9643 if (p_siso < 0 && full_screen)
9644 {
9645 errmsg = e_positive;
9646 p_siso = 0;
9647 }
9648#ifdef FEAT_CMDWIN
9649 if (p_cwh < 1)
9650 {
9651 errmsg = e_positive;
9652 p_cwh = 1;
9653 }
9654#endif
9655 if (p_ut < 0)
9656 {
9657 errmsg = e_positive;
9658 p_ut = 2000;
9659 }
9660 if (p_ss < 0)
9661 {
9662 errmsg = e_positive;
9663 p_ss = 0;
9664 }
9665
9666 /* May set global value for local option. */
9667 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9668 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9669
9670 options[opt_idx].flags |= P_WAS_SET;
9671
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009672#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009673 // Don't do this while starting up, failure or recursively.
9674 if (!starting && errmsg == NULL && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009675 {
Bram Moolenaard7c96872019-06-15 17:12:48 +02009676 char_u buf_old[11], buf_old_global[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009677 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009678 vim_snprintf((char *)buf_old_global, 10, "%ld", old_global_value);
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009679 vim_snprintf((char *)buf_new, 10, "%ld", value);
9680 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009681 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9682 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9683 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009684 if (opt_flags & OPT_LOCAL)
9685 {
9686 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
9687 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9688 }
9689 if (opt_flags & OPT_GLOBAL)
9690 {
9691 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
9692 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old, -1);
9693 }
9694 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9695 {
9696 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
9697 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9698 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old_global, -1);
9699 }
9700 if (opt_flags & OPT_MODELINE)
9701 {
9702 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
9703 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9704 }
9705 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname,
9706 NULL, FALSE, NULL);
Bram Moolenaar53744302015-07-17 17:38:22 +02009707 reset_v_option_vars();
9708 }
9709#endif
9710
Bram Moolenaar071d4272004-06-13 20:20:40 +00009711 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009712 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009713 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009714 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009715 check_redraw(options[opt_idx].flags);
9716
9717 return errmsg;
9718}
9719
9720/*
9721 * Called after an option changed: check if something needs to be redrawn.
9722 */
9723 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009724check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009725{
9726 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009727 int doclear = (flags & P_RCLR) == P_RCLR;
9728 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009729
Bram Moolenaar071d4272004-06-13 20:20:40 +00009730 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9731 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009732
9733 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9734 changed_window_setting();
9735 if (flags & P_RBUF)
9736 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009737 if (flags & P_RWINONLY)
9738 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009739 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009740 redraw_all_later(CLEAR);
9741 else if (all)
9742 redraw_all_later(NOT_VALID);
9743}
9744
9745/*
9746 * Find index for option 'arg'.
9747 * Return -1 if not found.
9748 */
9749 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009750findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009751{
9752 int opt_idx;
9753 char *s, *p;
9754 static short quick_tab[27] = {0, 0}; /* quick access table */
9755 int is_term_opt;
9756
9757 /*
9758 * For first call: Initialize the quick-access table.
9759 * It contains the index for the first option that starts with a certain
9760 * letter. There are 26 letters, plus the first "t_" option.
9761 */
9762 if (quick_tab[1] == 0)
9763 {
9764 p = options[0].fullname;
9765 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9766 {
9767 if (s[0] != p[0])
9768 {
9769 if (s[0] == 't' && s[1] == '_')
9770 quick_tab[26] = opt_idx;
9771 else
9772 quick_tab[CharOrdLow(s[0])] = opt_idx;
9773 }
9774 p = s;
9775 }
9776 }
9777
9778 /*
9779 * Check for name starting with an illegal character.
9780 */
9781#ifdef EBCDIC
9782 if (!islower(arg[0]))
9783#else
9784 if (arg[0] < 'a' || arg[0] > 'z')
9785#endif
9786 return -1;
9787
9788 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9789 if (is_term_opt)
9790 opt_idx = quick_tab[26];
9791 else
9792 opt_idx = quick_tab[CharOrdLow(arg[0])];
9793 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9794 {
9795 if (STRCMP(arg, s) == 0) /* match full name */
9796 break;
9797 }
9798 if (s == NULL && !is_term_opt)
9799 {
9800 opt_idx = quick_tab[CharOrdLow(arg[0])];
9801 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9802 {
9803 s = options[opt_idx].shortname;
9804 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9805 break;
9806 s = NULL;
9807 }
9808 }
9809 if (s == NULL)
9810 opt_idx = -1;
9811 return opt_idx;
9812}
9813
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009814#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009815/*
9816 * Get the value for an option.
9817 *
9818 * Returns:
9819 * Number or Toggle option: 1, *numval gets value.
9820 * String option: 0, *stringval gets allocated string.
9821 * Hidden Number or Toggle option: -1.
9822 * hidden String option: -2.
9823 * unknown option: -3.
9824 */
9825 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009826get_option_value(
9827 char_u *name,
9828 long *numval,
9829 char_u **stringval, /* NULL when only checking existence */
9830 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009831{
9832 int opt_idx;
9833 char_u *varp;
9834
9835 opt_idx = findoption(name);
9836 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009837 {
9838 int key;
9839
9840 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009841 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009842 {
9843 char_u key_name[2];
9844 char_u *p;
9845
9846 if (key < 0)
9847 {
9848 key_name[0] = KEY2TERMCAP0(key);
9849 key_name[1] = KEY2TERMCAP1(key);
9850 }
9851 else
9852 {
9853 key_name[0] = KS_KEY;
9854 key_name[1] = (key & 0xff);
9855 }
9856 p = find_termcode(key_name);
9857 if (p != NULL)
9858 {
9859 if (stringval != NULL)
9860 *stringval = vim_strsave(p);
9861 return 0;
9862 }
9863 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009864 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009865 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009866
9867 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9868
9869 if (options[opt_idx].flags & P_STRING)
9870 {
9871 if (varp == NULL) /* hidden option */
9872 return -2;
9873 if (stringval != NULL)
9874 {
9875#ifdef FEAT_CRYPT
9876 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009877 if ((char_u **)varp == &curbuf->b_p_key
9878 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009879 *stringval = vim_strsave((char_u *)"*****");
9880 else
9881#endif
9882 *stringval = vim_strsave(*(char_u **)(varp));
9883 }
9884 return 0;
9885 }
9886
9887 if (varp == NULL) /* hidden option */
9888 return -1;
9889 if (options[opt_idx].flags & P_NUM)
9890 *numval = *(long *)varp;
9891 else
9892 {
9893 /* Special case: 'modified' is b_changed, but we also want to consider
9894 * it set when 'ff' or 'fenc' changed. */
9895 if ((int *)varp == &curbuf->b_changed)
9896 *numval = curbufIsChanged();
9897 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009898 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009899 }
9900 return 1;
9901}
9902#endif
9903
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009904#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009905/*
9906 * Returns the option attributes and its value. Unlike the above function it
9907 * will return either global value or local value of the option depending on
9908 * what was requested, but it will never return global value if it was
9909 * requested to return local one and vice versa. Neither it will return
9910 * buffer-local value if it was requested to return window-local one.
9911 *
9912 * Pretends that option is absent if it is not present in the requested scope
9913 * (i.e. has no global, window-local or buffer-local value depending on
9914 * opt_type). Uses
9915 *
9916 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009917 * 0 hidden or unknown option, also option that does not have requested
9918 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009919 * see SOPT_* in vim.h for other flags
9920 *
9921 * Possible opt_type values: see SREQ_* in vim.h
9922 */
9923 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009924get_option_value_strict(
9925 char_u *name,
9926 long *numval,
9927 char_u **stringval, /* NULL when only obtaining attributes */
9928 int opt_type,
9929 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009930{
9931 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009932 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009933 struct vimoption *p;
9934 int r = 0;
9935
9936 opt_idx = findoption(name);
9937 if (opt_idx < 0)
9938 return 0;
9939
9940 p = &(options[opt_idx]);
9941
9942 /* Hidden option */
9943 if (p->var == NULL)
9944 return 0;
9945
9946 if (p->flags & P_BOOL)
9947 r |= SOPT_BOOL;
9948 else if (p->flags & P_NUM)
9949 r |= SOPT_NUM;
9950 else if (p->flags & P_STRING)
9951 r |= SOPT_STRING;
9952
9953 if (p->indir == PV_NONE)
9954 {
9955 if (opt_type == SREQ_GLOBAL)
9956 r |= SOPT_GLOBAL;
9957 else
9958 return 0; /* Did not request global-only option */
9959 }
9960 else
9961 {
9962 if (p->indir & PV_BOTH)
9963 r |= SOPT_GLOBAL;
9964 else if (opt_type == SREQ_GLOBAL)
9965 return 0; /* Requested global option */
9966
9967 if (p->indir & PV_WIN)
9968 {
9969 if (opt_type == SREQ_BUF)
9970 return 0; /* Did not request window-local option */
9971 else
9972 r |= SOPT_WIN;
9973 }
9974 else if (p->indir & PV_BUF)
9975 {
9976 if (opt_type == SREQ_WIN)
9977 return 0; /* Did not request buffer-local option */
9978 else
9979 r |= SOPT_BUF;
9980 }
9981 }
9982
9983 if (stringval == NULL)
9984 return r;
9985
9986 if (opt_type == SREQ_GLOBAL)
9987 varp = p->var;
9988 else
9989 {
9990 if (opt_type == SREQ_BUF)
9991 {
9992 /* Special case: 'modified' is b_changed, but we also want to
9993 * consider it set when 'ff' or 'fenc' changed. */
9994 if (p->indir == PV_MOD)
9995 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009996 *numval = bufIsChanged((buf_T *)from);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009997 varp = NULL;
9998 }
9999#ifdef FEAT_CRYPT
10000 else if (p->indir == PV_KEY)
10001 {
10002 /* never return the value of the crypt key */
10003 *stringval = NULL;
10004 varp = NULL;
10005 }
10006#endif
10007 else
10008 {
Bram Moolenaardefe6422018-06-24 15:14:07 +020010009 buf_T *save_curbuf = curbuf;
10010
10011 // only getting a pointer, no need to use aucmd_prepbuf()
10012 curbuf = (buf_T *)from;
10013 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010014 varp = get_varp(p);
Bram Moolenaardefe6422018-06-24 15:14:07 +020010015 curbuf = save_curbuf;
10016 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010017 }
10018 }
10019 else if (opt_type == SREQ_WIN)
10020 {
Bram Moolenaardefe6422018-06-24 15:14:07 +020010021 win_T *save_curwin = curwin;
10022
10023 curwin = (win_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010024 curbuf = curwin->w_buffer;
10025 varp = get_varp(p);
10026 curwin = save_curwin;
10027 curbuf = curwin->w_buffer;
10028 }
10029 if (varp == p->var)
10030 return (r | SOPT_UNSET);
10031 }
10032
10033 if (varp != NULL)
10034 {
10035 if (p->flags & P_STRING)
10036 *stringval = vim_strsave(*(char_u **)(varp));
10037 else if (p->flags & P_NUM)
10038 *numval = *(long *) varp;
10039 else
10040 *numval = *(int *)varp;
10041 }
10042
10043 return r;
10044}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010045
10046/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010047 * Iterate over options. First argument is a pointer to a pointer to a
10048 * structure inside options[] array, second is option type like in the above
10049 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010050 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010051 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010052 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010053 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010054 * first argument to NULL.
10055 *
10056 * Returns full option name for current option on each call.
10057 */
10058 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010059option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010060{
10061 struct vimoption *ret = NULL;
10062 do
10063 {
10064 if (*option == NULL)
10065 *option = (void *) options;
10066 else if (((struct vimoption *) (*option))->fullname == NULL)
10067 {
10068 *option = NULL;
10069 return NULL;
10070 }
10071 else
10072 *option = (void *) (((struct vimoption *) (*option)) + 1);
10073
10074 ret = ((struct vimoption *) (*option));
10075
10076 /* Hidden option */
10077 if (ret->var == NULL)
10078 {
10079 ret = NULL;
10080 continue;
10081 }
10082
10083 switch (opt_type)
10084 {
10085 case SREQ_GLOBAL:
10086 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
10087 ret = NULL;
10088 break;
10089 case SREQ_BUF:
10090 if (!(ret->indir & PV_BUF))
10091 ret = NULL;
10092 break;
10093 case SREQ_WIN:
10094 if (!(ret->indir & PV_WIN))
10095 ret = NULL;
10096 break;
10097 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +010010098 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010099 return NULL;
10100 }
10101 }
10102 while (ret == NULL);
10103
10104 return (char_u *)ret->fullname;
10105}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010106#endif
10107
Bram Moolenaar071d4272004-06-13 20:20:40 +000010108/*
10109 * Set the value of option "name".
10110 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010111 *
10112 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010113 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010114 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010115set_option_value(
10116 char_u *name,
10117 long number,
10118 char_u *string,
10119 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010120{
10121 int opt_idx;
10122 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +000010123 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010124
10125 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010126 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +010010127 {
10128 int key;
10129
10130 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010131 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +010010132 {
10133 char_u key_name[2];
10134
10135 if (key < 0)
10136 {
10137 key_name[0] = KEY2TERMCAP0(key);
10138 key_name[1] = KEY2TERMCAP1(key);
10139 }
10140 else
10141 {
10142 key_name[0] = KS_KEY;
10143 key_name[1] = (key & 0xff);
10144 }
10145 add_termcode(key_name, string, FALSE);
10146 if (full_screen)
10147 ttest(FALSE);
10148 redraw_all_later(CLEAR);
10149 return NULL;
10150 }
10151
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010152 semsg(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +010010153 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010154 else
10155 {
10156 flags = options[opt_idx].flags;
10157#ifdef HAVE_SANDBOX
10158 /* Disallow changing some options in the sandbox */
10159 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010160 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010161 emsg(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010162 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010163 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010164#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010165 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010166 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010167 else
10168 {
Bram Moolenaarb3163762008-07-08 15:15:08 +000010169 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010170 if (varp != NULL) /* hidden option is not changed */
10171 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010172 if (number == 0 && string != NULL)
10173 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +000010174 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010175
10176 /* Either we are given a string or we are setting option
10177 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +000010178 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010179 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +000010180 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010181 {
10182 /* There's another character after zeros or the string
10183 * is empty. In both cases, we are trying to set a
10184 * num option using a string. */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010185 semsg(_("E521: Number required: &%s = '%s'"),
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010186 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010187 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010188
10189 }
10190 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010191 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010192 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +000010193 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010194 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010195 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010196 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010197 }
10198 }
10199 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010200 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010201}
10202
10203/*
10204 * Get the terminal code for a terminal option.
10205 * Returns NULL when not found.
10206 */
10207 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010208get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010209{
10210 int opt_idx;
10211 char_u *varp;
10212
10213 if (tname[0] != 't' || tname[1] != '_' ||
10214 tname[2] == NUL || tname[3] == NUL)
10215 return NULL;
10216 if ((opt_idx = findoption(tname)) >= 0)
10217 {
10218 varp = get_varp(&(options[opt_idx]));
10219 if (varp != NULL)
10220 varp = *(char_u **)(varp);
10221 return varp;
10222 }
10223 return find_termcode(tname + 2);
10224}
10225
10226 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010227get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010228{
10229 int i;
10230
10231 i = findoption((char_u *)"hl");
10232 if (i >= 0)
10233 return options[i].def_val[VI_DEFAULT];
10234 return (char_u *)NULL;
10235}
10236
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010237 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010238get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010239{
10240 int i;
10241
10242 i = findoption((char_u *)"enc");
10243 if (i >= 0)
10244 return options[i].def_val[VI_DEFAULT];
10245 return (char_u *)NULL;
10246}
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010247
Bram Moolenaar071d4272004-06-13 20:20:40 +000010248/*
10249 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010250 * When "has_lt" is true there is a '<' before "*arg_arg".
10251 * Returns 0 when the key is not recognized.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010252 */
10253 static int
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010254find_key_option(char_u *arg_arg, int has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010255{
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010256 int key = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010257 int modifiers;
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010258 char_u *arg = arg_arg;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010259
10260 /*
10261 * Don't use get_special_key_code() for t_xx, we don't want it to call
10262 * add_termcap_entry().
10263 */
10264 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
10265 key = TERMCAP2KEY(arg[2], arg[3]);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010266 else if (has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010267 {
10268 --arg; /* put arg at the '<' */
10269 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +020010270 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010271 if (modifiers) /* can't handle modifiers here */
10272 key = 0;
10273 }
10274 return key;
10275}
10276
10277/*
10278 * if 'all' == 0: show changed options
10279 * if 'all' == 1: show all normal options
10280 * if 'all' == 2: show all terminal options
10281 */
10282 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010283showoptions(
10284 int all,
10285 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010286{
10287 struct vimoption *p;
10288 int col;
10289 int isterm;
10290 char_u *varp;
10291 struct vimoption **items;
10292 int item_count;
10293 int run;
10294 int row, rows;
10295 int cols;
10296 int i;
10297 int len;
10298
10299#define INC 20
10300#define GAP 3
10301
Bram Moolenaarc799fe22019-05-28 23:08:19 +020010302 items = ALLOC_MULT(struct vimoption *, PARAM_COUNT);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010303 if (items == NULL)
10304 return;
10305
10306 /* Highlight title */
10307 if (all == 2)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010308 msg_puts_title(_("\n--- Terminal codes ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010309 else if (opt_flags & OPT_GLOBAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010310 msg_puts_title(_("\n--- Global option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010311 else if (opt_flags & OPT_LOCAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010312 msg_puts_title(_("\n--- Local option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010313 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010314 msg_puts_title(_("\n--- Options ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010315
10316 /*
10317 * do the loop two times:
10318 * 1. display the short items
10319 * 2. display the long items (only strings and numbers)
10320 */
10321 for (run = 1; run <= 2 && !got_int; ++run)
10322 {
10323 /*
10324 * collect the items in items[]
10325 */
10326 item_count = 0;
10327 for (p = &options[0]; p->fullname != NULL; p++)
10328 {
Bram Moolenaarf86db782018-10-25 13:31:37 +020010329 // apply :filter /pat/
10330 if (message_filtered((char_u *) p->fullname))
10331 continue;
10332
Bram Moolenaar071d4272004-06-13 20:20:40 +000010333 varp = NULL;
10334 isterm = istermoption(p);
10335 if (opt_flags != 0)
10336 {
10337 if (p->indir != PV_NONE && !isterm)
10338 varp = get_varp_scope(p, opt_flags);
10339 }
10340 else
10341 varp = get_varp(p);
10342 if (varp != NULL
10343 && ((all == 2 && isterm)
10344 || (all == 1 && !isterm)
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010345 || (all == 0 && !optval_default(p, varp, p_cp))))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010346 {
10347 if (p->flags & P_BOOL)
10348 len = 1; /* a toggle option fits always */
10349 else
10350 {
10351 option_value2string(p, opt_flags);
10352 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
10353 }
10354 if ((len <= INC - GAP && run == 1) ||
10355 (len > INC - GAP && run == 2))
10356 items[item_count++] = p;
10357 }
10358 }
10359
10360 /*
10361 * display the items
10362 */
10363 if (run == 1)
10364 {
10365 cols = (Columns + GAP - 3) / INC;
10366 if (cols == 0)
10367 cols = 1;
10368 rows = (item_count + cols - 1) / cols;
10369 }
10370 else /* run == 2 */
10371 rows = item_count;
10372 for (row = 0; row < rows && !got_int; ++row)
10373 {
10374 msg_putchar('\n'); /* go to next line */
10375 if (got_int) /* 'q' typed in more */
10376 break;
10377 col = 0;
10378 for (i = row; i < item_count; i += rows)
10379 {
10380 msg_col = col; /* make columns */
10381 showoneopt(items[i], opt_flags);
10382 col += INC;
10383 }
10384 out_flush();
10385 ui_breakcheck();
10386 }
10387 }
10388 vim_free(items);
10389}
10390
10391/*
10392 * Return TRUE if option "p" has its default value.
10393 */
10394 static int
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010395optval_default(struct vimoption *p, char_u *varp, int compatible)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010396{
10397 int dvi;
10398
10399 if (varp == NULL)
10400 return TRUE; /* hidden option is always at default */
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010401 dvi = ((p->flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010402 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010403 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010404 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010405 /* the cast to long is required for Manx C, long_i is
10406 * needed for MSVC */
10407 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010408 /* P_STRING */
10409 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
10410}
10411
10412/*
10413 * showoneopt: show the value of one option
10414 * must not be called with a hidden option!
10415 */
10416 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010417showoneopt(
10418 struct vimoption *p,
10419 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010420{
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010421 char_u *varp;
10422 int save_silent = silent_mode;
10423
10424 silent_mode = FALSE;
10425 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010426
10427 varp = get_varp_scope(p, opt_flags);
10428
10429 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
10430 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
10431 ? !curbufIsChanged() : !*(int *)varp))
Bram Moolenaar32526b32019-01-19 17:43:09 +010010432 msg_puts("no");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010433 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010434 msg_puts("--");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010435 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010436 msg_puts(" ");
10437 msg_puts(p->fullname);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010438 if (!(p->flags & P_BOOL))
10439 {
10440 msg_putchar('=');
10441 /* put value string in NameBuff */
10442 option_value2string(p, opt_flags);
10443 msg_outtrans(NameBuff);
10444 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010445
10446 silent_mode = save_silent;
10447 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010448}
10449
10450/*
10451 * Write modified options as ":set" commands to a file.
10452 *
10453 * There are three values for "opt_flags":
10454 * OPT_GLOBAL: Write global option values and fresh values of
10455 * buffer-local options (used for start of a session
10456 * file).
10457 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10458 * curwin (used for a vimrc file).
10459 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10460 * and local values for window-local options of
10461 * curwin. Local values are also written when at the
10462 * default value, because a modeline or autocommand
10463 * may have set them when doing ":edit file" and the
10464 * user has set them back at the default or fresh
10465 * value.
10466 * When "local_only" is TRUE, don't write fresh
10467 * values, only local values (for ":mkview").
10468 * (fresh value = value used for a new buffer or window for a local option).
10469 *
10470 * Return FAIL on error, OK otherwise.
10471 */
10472 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010473makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010474{
10475 struct vimoption *p;
10476 char_u *varp; /* currently used value */
10477 char_u *varp_fresh; /* local value */
10478 char_u *varp_local = NULL; /* fresh value */
10479 char *cmd;
10480 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010481 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010482
10483 /*
10484 * The options that don't have a default (terminal name, columns, lines)
10485 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010486 * Do the loop over "options[]" twice: once for options with the
10487 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010488 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010489 for (pri = 1; pri >= 0; --pri)
10490 {
10491 for (p = &options[0]; !istermoption(p); p++)
10492 if (!(p->flags & P_NO_MKRC)
10493 && !istermoption(p)
10494 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010495 {
10496 /* skip global option when only doing locals */
10497 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10498 continue;
10499
10500 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10501 * file, they are always buffer-specific. */
10502 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10503 continue;
10504
10505 /* Global values are only written when not at the default value. */
10506 varp = get_varp_scope(p, opt_flags);
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010507 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp, p_cp))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010508 continue;
10509
10510 round = 2;
10511 if (p->indir != PV_NONE)
10512 {
10513 if (p->var == VAR_WIN)
10514 {
10515 /* skip window-local option when only doing globals */
10516 if (!(opt_flags & OPT_LOCAL))
10517 continue;
10518 /* When fresh value of window-local option is not at the
10519 * default, need to write it too. */
10520 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10521 {
10522 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010523 if (!optval_default(p, varp_fresh, p_cp))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010524 {
10525 round = 1;
10526 varp_local = varp;
10527 varp = varp_fresh;
10528 }
10529 }
10530 }
10531 }
10532
10533 /* Round 1: fresh value for window-local options.
10534 * Round 2: other values */
10535 for ( ; round <= 2; varp = varp_local, ++round)
10536 {
10537 if (round == 1 || (opt_flags & OPT_GLOBAL))
10538 cmd = "set";
10539 else
10540 cmd = "setlocal";
10541
10542 if (p->flags & P_BOOL)
10543 {
10544 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10545 return FAIL;
10546 }
10547 else if (p->flags & P_NUM)
10548 {
10549 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10550 return FAIL;
10551 }
10552 else /* P_STRING */
10553 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010554 int do_endif = FALSE;
10555
Bram Moolenaar071d4272004-06-13 20:20:40 +000010556 /* Don't set 'syntax' and 'filetype' again if the value is
10557 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010558 if (
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +010010559#if defined(FEAT_SYN_HL)
10560 p->indir == PV_SYN ||
10561#endif
10562 p->indir == PV_FT)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010563 {
10564 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10565 *(char_u **)(varp)) < 0
10566 || put_eol(fd) < 0)
10567 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010568 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010569 }
10570 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010571 p->flags) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010572 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010573 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010574 {
10575 if (put_line(fd, "endif") == FAIL)
10576 return FAIL;
10577 }
10578 }
10579 }
10580 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010581 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010582 return OK;
10583}
10584
10585#if defined(FEAT_FOLDING) || defined(PROTO)
10586/*
10587 * Generate set commands for the local fold options only. Used when
10588 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10589 */
10590 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010591makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010592{
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010593 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, 0) == FAIL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010594# ifdef FEAT_EVAL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010595 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010596 == FAIL
10597# endif
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010598 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010599 == FAIL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010600 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010601 == FAIL
10602 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10603 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10604 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10605 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10606 )
10607 return FAIL;
10608
10609 return OK;
10610}
10611#endif
10612
10613 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010614put_setstring(
10615 FILE *fd,
10616 char *cmd,
10617 char *name,
10618 char_u **valuep,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010619 long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010620{
10621 char_u *s;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010622 char_u *buf = NULL;
10623 char_u *part = NULL;
10624 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010625
10626 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10627 return FAIL;
10628 if (*valuep != NULL)
10629 {
10630 /* Output 'pastetoggle' as key names. For other
10631 * options some characters have to be escaped with
10632 * CTRL-V or backslash */
10633 if (valuep == &p_pt)
10634 {
10635 s = *valuep;
10636 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010637 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010638 return FAIL;
10639 }
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010640 // expand the option value, replace $HOME by ~
10641 else if ((flags & P_EXPAND) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010642 {
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010643 int size = (int)STRLEN(*valuep) + 1;
10644
10645 // replace home directory in the whole option value into "buf"
10646 buf = alloc(size);
Bram Moolenaarf8441472011-04-28 17:24:58 +020010647 if (buf == NULL)
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010648 goto fail;
10649 home_replace(NULL, *valuep, buf, size, FALSE);
10650
10651 // If the option value is longer than MAXPATHL, we need to append
10652 // earch comma separated part of the option separately, so that it
10653 // can be expanded when read back.
10654 if (size >= MAXPATHL && (flags & P_COMMA) != 0
10655 && vim_strchr(*valuep, ',') != NULL)
10656 {
10657 part = alloc(size);
10658 if (part == NULL)
10659 goto fail;
10660
10661 // write line break to clear the option, e.g. ':set rtp='
10662 if (put_eol(fd) == FAIL)
10663 goto fail;
10664
10665 p = buf;
10666 while (*p != NUL)
10667 {
10668 // for each comma separated option part, append value to
10669 // the option, :set rtp+=value
10670 if (fprintf(fd, "%s %s+=", cmd, name) < 0)
10671 goto fail;
10672 (void)copy_option_part(&p, part, size, ",");
10673 if (put_escstr(fd, part, 2) == FAIL || put_eol(fd) == FAIL)
10674 goto fail;
10675 }
10676 vim_free(buf);
10677 vim_free(part);
10678 return OK;
10679 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010680 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010681 {
10682 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010683 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010684 }
10685 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010686 }
10687 else if (put_escstr(fd, *valuep, 2) == FAIL)
10688 return FAIL;
10689 }
10690 if (put_eol(fd) < 0)
10691 return FAIL;
10692 return OK;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010693fail:
10694 vim_free(buf);
10695 vim_free(part);
10696 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010697}
10698
10699 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010700put_setnum(
10701 FILE *fd,
10702 char *cmd,
10703 char *name,
10704 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010705{
10706 long wc;
10707
10708 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10709 return FAIL;
10710 if (wc_use_keyname((char_u *)valuep, &wc))
10711 {
10712 /* print 'wildchar' and 'wildcharm' as a key name */
10713 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10714 return FAIL;
10715 }
10716 else if (fprintf(fd, "%ld", *valuep) < 0)
10717 return FAIL;
10718 if (put_eol(fd) < 0)
10719 return FAIL;
10720 return OK;
10721}
10722
10723 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010724put_setbool(
10725 FILE *fd,
10726 char *cmd,
10727 char *name,
10728 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010729{
Bram Moolenaar893de922007-10-02 18:40:57 +000010730 if (value < 0) /* global/local option using global value */
10731 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010732 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10733 || put_eol(fd) < 0)
10734 return FAIL;
10735 return OK;
10736}
10737
10738/*
10739 * Clear all the terminal options.
10740 * If the option has been allocated, free the memory.
10741 * Terminal options are never hidden or indirect.
10742 */
10743 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010744clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010745{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010746 /*
10747 * Reset a few things before clearing the old options. This may cause
10748 * outputting a few things that the terminal doesn't understand, but the
10749 * screen will be cleared later, so this is OK.
10750 */
10751#ifdef FEAT_MOUSE_TTY
10752 mch_setmouse(FALSE); /* switch mouse off */
10753#endif
10754#ifdef FEAT_TITLE
Bram Moolenaar40385db2018-08-07 22:31:44 +020010755 mch_restore_title(SAVE_RESTORE_BOTH); /* restore window titles */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010756#endif
10757#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10758 /* When starting the GUI close the display opened for the clipboard.
10759 * After restoring the title, because that will need the display. */
10760 if (gui.starting)
10761 clear_xterm_clip();
10762#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010763 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010764
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010765 free_termoptions();
10766}
10767
10768 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010769free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010770{
10771 struct vimoption *p;
10772
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010773 for (p = options; p->fullname != NULL; p++)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010774 if (istermoption(p))
10775 {
10776 if (p->flags & P_ALLOCED)
10777 free_string_option(*(char_u **)(p->var));
10778 if (p->flags & P_DEF_ALLOCED)
10779 free_string_option(p->def_val[VI_DEFAULT]);
10780 *(char_u **)(p->var) = empty_option;
10781 p->def_val[VI_DEFAULT] = empty_option;
10782 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010783#ifdef FEAT_EVAL
10784 // remember where the option was cleared
10785 set_option_sctx_idx((int)(p - options), OPT_GLOBAL, current_sctx);
10786#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010787 }
10788 clear_termcodes();
10789}
10790
10791/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010792 * Free the string for one term option, if it was allocated.
10793 * Set the string to empty_option and clear allocated flag.
10794 * "var" points to the option value.
10795 */
10796 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010797free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010798{
10799 struct vimoption *p;
10800
10801 for (p = &options[0]; p->fullname != NULL; p++)
10802 if (p->var == var)
10803 {
10804 if (p->flags & P_ALLOCED)
10805 free_string_option(*(char_u **)(p->var));
10806 *(char_u **)(p->var) = empty_option;
10807 p->flags &= ~P_ALLOCED;
10808 break;
10809 }
10810}
10811
10812/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010813 * Set the terminal option defaults to the current value.
10814 * Used after setting the terminal name.
10815 */
10816 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010817set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010818{
10819 struct vimoption *p;
10820
10821 for (p = &options[0]; p->fullname != NULL; p++)
10822 {
10823 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10824 {
10825 if (p->flags & P_DEF_ALLOCED)
10826 {
10827 free_string_option(p->def_val[VI_DEFAULT]);
10828 p->flags &= ~P_DEF_ALLOCED;
10829 }
10830 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10831 if (p->flags & P_ALLOCED)
10832 {
10833 p->flags |= P_DEF_ALLOCED;
10834 p->flags &= ~P_ALLOCED; /* don't free the value now */
10835 }
10836 }
10837 }
10838}
10839
10840/*
10841 * return TRUE if 'p' starts with 't_'
10842 */
10843 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010844istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010845{
10846 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10847}
10848
10849/*
10850 * Compute columns for ruler and shown command. 'sc_col' is also used to
10851 * decide what the maximum length of a message on the status line can be.
10852 * If there is a status line for the last window, 'sc_col' is independent
10853 * of 'ru_col'.
10854 */
10855
10856#define COL_RULER 17 /* columns needed by standard ruler */
10857
10858 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010859comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010860{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010861#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010862 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010863
10864 sc_col = 0;
10865 ru_col = 0;
10866 if (p_ru)
10867 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010868# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010869 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010870# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010871 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010872# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010873 /* no last status line, adjust sc_col */
10874 if (!last_has_status)
10875 sc_col = ru_col;
10876 }
10877 if (p_sc)
10878 {
10879 sc_col += SHOWCMD_COLS;
10880 if (!p_ru || last_has_status) /* no need for separating space */
10881 ++sc_col;
10882 }
10883 sc_col = Columns - sc_col;
10884 ru_col = Columns - ru_col;
10885 if (sc_col <= 0) /* screen too narrow, will become a mess */
10886 sc_col = 1;
10887 if (ru_col <= 0)
10888 ru_col = 1;
10889#else
10890 sc_col = Columns;
10891 ru_col = Columns;
10892#endif
10893}
10894
Bram Moolenaar113e1072019-01-20 15:30:40 +010010895#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010896/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010897 * Unset local option value, similar to ":set opt<".
10898 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010899 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010900unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010901{
10902 struct vimoption *p;
10903 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010904 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010905
10906 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010907 if (opt_idx < 0)
10908 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010909 p = &(options[opt_idx]);
10910
10911 switch ((int)p->indir)
10912 {
10913 /* global option with local value: use local value if it's been set */
10914 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010915 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010916 break;
10917 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010918 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010919 break;
10920 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010921 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010922 break;
10923 case PV_AR:
10924 buf->b_p_ar = -1;
10925 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010926 case PV_BKC:
10927 clear_string_option(&buf->b_p_bkc);
10928 buf->b_bkc_flags = 0;
10929 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010930 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010931 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010932 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010933 case PV_TC:
10934 clear_string_option(&buf->b_p_tc);
10935 buf->b_tc_flags = 0;
10936 break;
Bram Moolenaar375e3392019-01-31 18:26:10 +010010937 case PV_SISO:
10938 curwin->w_p_siso = -1;
10939 break;
10940 case PV_SO:
10941 curwin->w_p_so = -1;
10942 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010943#ifdef FEAT_FIND_ID
10944 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010945 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010946 break;
10947 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010948 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010949 break;
10950#endif
10951#ifdef FEAT_INS_EXPAND
10952 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010953 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010954 break;
10955 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010956 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010957 break;
10958#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010959 case PV_FP:
10960 clear_string_option(&buf->b_p_fp);
10961 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010962#ifdef FEAT_QUICKFIX
10963 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010964 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010965 break;
10966 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010967 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010968 break;
10969 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010970 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010971 break;
10972#endif
10973#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10974 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010975 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010976 break;
10977#endif
10978#if defined(FEAT_CRYPT)
10979 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010980 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010981 break;
10982#endif
10983#ifdef FEAT_STL_OPT
10984 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010985 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010986 break;
10987#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010988 case PV_UL:
10989 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10990 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010991#ifdef FEAT_LISP
10992 case PV_LW:
10993 clear_string_option(&buf->b_p_lw);
10994 break;
10995#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010996 case PV_MENC:
10997 clear_string_option(&buf->b_p_menc);
10998 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010999 }
11000}
Bram Moolenaar113e1072019-01-20 15:30:40 +010011001#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020011002
11003/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011004 * Get pointer to option variable, depending on local or global scope.
11005 */
11006 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011007get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011008{
11009 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
11010 {
11011 if (p->var == VAR_WIN)
11012 return (char_u *)GLOBAL_WO(get_varp(p));
11013 return p->var;
11014 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000011015 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011016 {
11017 switch ((int)p->indir)
11018 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011019 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011020#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011021 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
11022 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
11023 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011024#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011025 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
11026 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
11027 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000011028 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011029 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011030 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar375e3392019-01-31 18:26:10 +010011031 case PV_SISO: return (char_u *)&(curwin->w_p_siso);
11032 case PV_SO: return (char_u *)&(curwin->w_p_so);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011033#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011034 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
11035 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011036#endif
11037#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011038 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
11039 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011040#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011041#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11042 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
11043#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011044#if defined(FEAT_CRYPT)
11045 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
11046#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011047#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011048 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011049#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011050 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011051#ifdef FEAT_LISP
11052 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
11053#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011054 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011055 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011056 }
11057 return NULL; /* "cannot happen" */
11058 }
11059 return get_varp(p);
11060}
11061
11062/*
11063 * Get pointer to option variable.
11064 */
11065 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011066get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011067{
11068 /* hidden option, always return NULL */
11069 if (p->var == NULL)
11070 return NULL;
11071
11072 switch ((int)p->indir)
11073 {
11074 case PV_NONE: return p->var;
11075
11076 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011077 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011078 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011079 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011080 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011081 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011082 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000011083 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000011084 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011085 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011086 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011087 case PV_TC: return *curbuf->b_p_tc != NUL
11088 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011089 case PV_BKC: return *curbuf->b_p_bkc != NUL
11090 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar375e3392019-01-31 18:26:10 +010011091 case PV_SISO: return curwin->w_p_siso >= 0
11092 ? (char_u *)&(curwin->w_p_siso) : p->var;
11093 case PV_SO: return curwin->w_p_so >= 0
11094 ? (char_u *)&(curwin->w_p_so) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011095#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011096 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011097 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011098 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011099 ? (char_u *)&(curbuf->b_p_inc) : p->var;
11100#endif
11101#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011102 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011103 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011104 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011105 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
11106#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011107 case PV_FP: return *curbuf->b_p_fp != NUL
11108 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011109#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011110 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011111 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011112 case PV_GP: return *curbuf->b_p_gp != NUL
11113 ? (char_u *)&(curbuf->b_p_gp) : p->var;
11114 case PV_MP: return *curbuf->b_p_mp != NUL
11115 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011116#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011117#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11118 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
11119 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
11120#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011121#if defined(FEAT_CRYPT)
11122 case PV_CM: return *curbuf->b_p_cm != NUL
11123 ? (char_u *)&(curbuf->b_p_cm) : p->var;
11124#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011125#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011126 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011127 ? (char_u *)&(curwin->w_p_stl) : p->var;
11128#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011129 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
11130 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011131#ifdef FEAT_LISP
11132 case PV_LW: return *curbuf->b_p_lw != NUL
11133 ? (char_u *)&(curbuf->b_p_lw) : p->var;
11134#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011135 case PV_MENC: return *curbuf->b_p_menc != NUL
11136 ? (char_u *)&(curbuf->b_p_menc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011137#ifdef FEAT_ARABIC
11138 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
11139#endif
11140 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011141#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000011142 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
11143#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011144#ifdef FEAT_SYN_HL
11145 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
11146 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020011147 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011148#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011149#ifdef FEAT_DIFF
11150 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
11151#endif
11152#ifdef FEAT_FOLDING
11153 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
11154 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
11155 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
11156 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
11157 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
11158 case PV_FML: return (char_u *)&(curwin->w_p_fml);
11159 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
11160# ifdef FEAT_EVAL
11161 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
11162 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
11163# endif
11164 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
11165#endif
11166 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020011167 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011168#ifdef FEAT_LINEBREAK
11169 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
11170#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011171 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000011172 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020011173#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011174 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
11175#endif
11176#ifdef FEAT_RIGHTLEFT
11177 case PV_RL: return (char_u *)&(curwin->w_p_rl);
11178 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
11179#endif
11180 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
11181 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
11182#ifdef FEAT_LINEBREAK
11183 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020011184 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
11185 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011186#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011187 case PV_WCR: return (char_u *)&(curwin->w_p_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011188 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011189 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011190#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011191 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
11192 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
11193#endif
11194#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011195 case PV_TWK: return (char_u *)&(curwin->w_p_twk);
11196 case PV_TWS: return (char_u *)&(curwin->w_p_tws);
11197 case PV_TWSL: return (char_u *)&(curbuf->b_p_twsl);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011198#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011199
11200 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
11201 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011202 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011203 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
11204 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011205 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
11206 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
11207#ifdef FEAT_CINDENT
11208 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
11209 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
11210 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
11211#endif
11212#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11213 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
11214#endif
11215#ifdef FEAT_COMMENTS
11216 case PV_COM: return (char_u *)&(curbuf->b_p_com);
11217#endif
11218#ifdef FEAT_FOLDING
11219 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
11220#endif
11221#ifdef FEAT_INS_EXPAND
11222 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
Bram Moolenaarac3150d2019-07-28 16:36:39 +020011223# ifdef BACKSLASH_IN_FILENAME
11224 case PV_CSL: return (char_u *)&(curbuf->b_p_csl);
11225# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011226#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011227#ifdef FEAT_COMPL_FUNC
11228 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011229 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011230#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +020011231#ifdef FEAT_EVAL
11232 case PV_TFU: return (char_u *)&(curbuf->b_p_tfu);
11233#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011234 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020011235 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011236 case PV_ET: return (char_u *)&(curbuf->b_p_et);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011237 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011238 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011239 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011240 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011241 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011242 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
11243 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
11244 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
11245 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
11246#ifdef FEAT_FIND_ID
11247# ifdef FEAT_EVAL
11248 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
11249# endif
11250#endif
11251#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11252 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
11253 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
11254#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011255#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011256 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
11257#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011258#ifdef FEAT_CRYPT
11259 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
11260#endif
11261#ifdef FEAT_LISP
11262 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
11263#endif
11264 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
11265 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
11266 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
11267 case PV_MOD: return (char_u *)&(curbuf->b_changed);
11268 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011269 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011270#ifdef FEAT_TEXTOBJ
11271 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
11272#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011273 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
11274#ifdef FEAT_SMARTINDENT
11275 case PV_SI: return (char_u *)&(curbuf->b_p_si);
11276#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011277 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011278 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
11279#ifdef FEAT_SEARCHPATH
11280 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
11281#endif
11282 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
11283#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011284 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011285 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
11286#endif
11287#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020011288 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
11289 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
11290 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011291#endif
11292 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
11293 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
11294 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
11295 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011296#ifdef FEAT_PERSISTENT_UNDO
11297 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
11298#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011299 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
11300#ifdef FEAT_KEYMAP
11301 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
11302#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011303#ifdef FEAT_SIGNS
11304 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
11305#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011306#ifdef FEAT_VARTABS
11307 case PV_VSTS: return (char_u *)&(curbuf->b_p_vsts);
11308 case PV_VTS: return (char_u *)&(curbuf->b_p_vts);
11309#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010011310 default: iemsg(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011311 }
11312 /* always return a valid pointer to avoid a crash! */
11313 return (char_u *)&(curbuf->b_p_wm);
11314}
11315
11316/*
11317 * Get the value of 'equalprg', either the buffer-local one or the global one.
11318 */
11319 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011320get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011321{
11322 if (*curbuf->b_p_ep == NUL)
11323 return p_ep;
11324 return curbuf->b_p_ep;
11325}
11326
Bram Moolenaar071d4272004-06-13 20:20:40 +000011327/*
11328 * Copy options from one window to another.
11329 * Used when splitting a window.
11330 */
11331 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011332win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011333{
11334 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
11335 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020011336#if defined(FEAT_LINEBREAK)
11337 briopt_check(wp_to);
11338#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011339}
Bram Moolenaar071d4272004-06-13 20:20:40 +000011340
11341/*
11342 * Copy the options from one winopt_T to another.
11343 * Doesn't free the old option values in "to", use clear_winopt() for that.
11344 * The 'scroll' option is not copied, because it depends on the window height.
11345 * The 'previewwindow' option is reset, there can be only one preview window.
11346 */
11347 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011348copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011349{
11350#ifdef FEAT_ARABIC
11351 to->wo_arab = from->wo_arab;
11352#endif
11353 to->wo_list = from->wo_list;
11354 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020011355 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011356#ifdef FEAT_LINEBREAK
11357 to->wo_nuw = from->wo_nuw;
11358#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011359#ifdef FEAT_RIGHTLEFT
11360 to->wo_rl = from->wo_rl;
11361 to->wo_rlc = vim_strsave(from->wo_rlc);
11362#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011363#ifdef FEAT_STL_OPT
11364 to->wo_stl = vim_strsave(from->wo_stl);
11365#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011366 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011367#ifdef FEAT_DIFF
11368 to->wo_wrap_save = from->wo_wrap_save;
11369#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011370#ifdef FEAT_LINEBREAK
11371 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020011372 to->wo_bri = from->wo_bri;
11373 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011374#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011375 to->wo_wcr = vim_strsave(from->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011376 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011377 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010011378 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011379 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011380#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000011381 to->wo_spell = from->wo_spell;
11382#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011383#ifdef FEAT_SYN_HL
11384 to->wo_cuc = from->wo_cuc;
11385 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020011386 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011387#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011388#ifdef FEAT_DIFF
11389 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011390 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011391#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011392#ifdef FEAT_CONCEAL
11393 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020011394 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011395#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011396#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011397 to->wo_twk = vim_strsave(from->wo_twk);
11398 to->wo_tws = vim_strsave(from->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011399#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011400#ifdef FEAT_FOLDING
11401 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011402 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011403 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011404 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011405 to->wo_fdi = vim_strsave(from->wo_fdi);
11406 to->wo_fml = from->wo_fml;
11407 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011408 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011409 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011410 to->wo_fdm_save = from->wo_diff_saved
11411 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011412 to->wo_fdn = from->wo_fdn;
11413# ifdef FEAT_EVAL
11414 to->wo_fde = vim_strsave(from->wo_fde);
11415 to->wo_fdt = vim_strsave(from->wo_fdt);
11416# endif
11417 to->wo_fmr = vim_strsave(from->wo_fmr);
11418#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011419#ifdef FEAT_SIGNS
11420 to->wo_scl = vim_strsave(from->wo_scl);
11421#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011422 check_winopt(to); /* don't want NULL pointers */
11423}
11424
11425/*
11426 * Check string options in a window for a NULL value.
11427 */
11428 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011429check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011430{
11431 check_winopt(&win->w_onebuf_opt);
11432 check_winopt(&win->w_allbuf_opt);
11433}
11434
11435/*
11436 * Check for NULL pointers in a winopt_T and replace them with empty_option.
11437 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020011438 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011439check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011440{
11441#ifdef FEAT_FOLDING
11442 check_string_option(&wop->wo_fdi);
11443 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011444 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011445# ifdef FEAT_EVAL
11446 check_string_option(&wop->wo_fde);
11447 check_string_option(&wop->wo_fdt);
11448# endif
11449 check_string_option(&wop->wo_fmr);
11450#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011451#ifdef FEAT_SIGNS
11452 check_string_option(&wop->wo_scl);
11453#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011454#ifdef FEAT_RIGHTLEFT
11455 check_string_option(&wop->wo_rlc);
11456#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011457#ifdef FEAT_STL_OPT
11458 check_string_option(&wop->wo_stl);
11459#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011460#ifdef FEAT_SYN_HL
11461 check_string_option(&wop->wo_cc);
11462#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011463#ifdef FEAT_CONCEAL
11464 check_string_option(&wop->wo_cocu);
11465#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011466#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011467 check_string_option(&wop->wo_twk);
11468 check_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011469#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011470#ifdef FEAT_LINEBREAK
11471 check_string_option(&wop->wo_briopt);
11472#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011473 check_string_option(&wop->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011474}
11475
11476/*
11477 * Free the allocated memory inside a winopt_T.
11478 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011479 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011480clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011481{
11482#ifdef FEAT_FOLDING
11483 clear_string_option(&wop->wo_fdi);
11484 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011485 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011486# ifdef FEAT_EVAL
11487 clear_string_option(&wop->wo_fde);
11488 clear_string_option(&wop->wo_fdt);
11489# endif
11490 clear_string_option(&wop->wo_fmr);
11491#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011492#ifdef FEAT_SIGNS
11493 clear_string_option(&wop->wo_scl);
11494#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011495#ifdef FEAT_LINEBREAK
11496 clear_string_option(&wop->wo_briopt);
11497#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011498 clear_string_option(&wop->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011499#ifdef FEAT_RIGHTLEFT
11500 clear_string_option(&wop->wo_rlc);
11501#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011502#ifdef FEAT_STL_OPT
11503 clear_string_option(&wop->wo_stl);
11504#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011505#ifdef FEAT_SYN_HL
11506 clear_string_option(&wop->wo_cc);
11507#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011508#ifdef FEAT_CONCEAL
11509 clear_string_option(&wop->wo_cocu);
11510#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011511#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011512 clear_string_option(&wop->wo_twk);
11513 clear_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011514#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011515}
11516
11517/*
11518 * Copy global option values to local options for one buffer.
11519 * Used when creating a new buffer and sometimes when entering a buffer.
11520 * flags:
11521 * BCO_ENTER We will enter the buf buffer.
11522 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11523 * appropriate.
11524 * BCO_NOHELP Don't copy the values to a help buffer.
11525 */
11526 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011527buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011528{
11529 int should_copy = TRUE;
11530 char_u *save_p_isk = NULL; /* init for GCC */
11531 int dont_do_help;
11532 int did_isk = FALSE;
11533
11534 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011535 * Skip this when the option defaults have not been set yet. Happens when
11536 * main() allocates the first buffer.
11537 */
11538 if (p_cpo != NULL)
11539 {
11540 /*
11541 * Always copy when entering and 'cpo' contains 'S'.
11542 * Don't copy when already initialized.
11543 * Don't copy when 'cpo' contains 's' and not entering.
11544 * 'S' BCO_ENTER initialized 's' should_copy
11545 * yes yes X X TRUE
11546 * yes no yes X FALSE
11547 * no X yes X FALSE
11548 * X no no yes FALSE
11549 * X no no no TRUE
11550 * no yes no X TRUE
11551 */
11552 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11553 && (buf->b_p_initialized
11554 || (!(flags & BCO_ENTER)
11555 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11556 should_copy = FALSE;
11557
11558 if (should_copy || (flags & BCO_ALWAYS))
11559 {
11560 /* Don't copy the options specific to a help buffer when
11561 * BCO_NOHELP is given or the options were initialized already
11562 * (jumping back to a help file with CTRL-T or CTRL-O) */
11563 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11564 || buf->b_p_initialized;
11565 if (dont_do_help) /* don't free b_p_isk */
11566 {
11567 save_p_isk = buf->b_p_isk;
11568 buf->b_p_isk = NULL;
11569 }
11570 /*
Bram Moolenaar40385db2018-08-07 22:31:44 +020011571 * Always free the allocated strings. If not already initialized,
11572 * reset 'readonly' and copy 'fileformat'.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011573 */
11574 if (!buf->b_p_initialized)
11575 {
11576 free_buf_options(buf, TRUE);
11577 buf->b_p_ro = FALSE; /* don't copy readonly */
11578 buf->b_p_tx = p_tx;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011579 buf->b_p_fenc = vim_strsave(p_fenc);
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011580 switch (*p_ffs)
11581 {
11582 case 'm':
11583 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11584 case 'd':
11585 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11586 case 'u':
11587 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11588 default:
11589 buf->b_p_ff = vim_strsave(p_ff);
11590 }
11591 if (buf->b_p_ff != NULL)
11592 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011593 buf->b_p_bh = empty_option;
11594 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011595 }
11596 else
11597 free_buf_options(buf, FALSE);
11598
11599 buf->b_p_ai = p_ai;
11600 buf->b_p_ai_nopaste = p_ai_nopaste;
11601 buf->b_p_sw = p_sw;
11602 buf->b_p_tw = p_tw;
11603 buf->b_p_tw_nopaste = p_tw_nopaste;
11604 buf->b_p_tw_nobin = p_tw_nobin;
11605 buf->b_p_wm = p_wm;
11606 buf->b_p_wm_nopaste = p_wm_nopaste;
11607 buf->b_p_wm_nobin = p_wm_nobin;
11608 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011609 buf->b_p_bomb = p_bomb;
Bram Moolenaarb388be02015-07-22 22:19:38 +020011610 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011611 buf->b_p_et = p_et;
11612 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011613 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011614 buf->b_p_ml = p_ml;
11615 buf->b_p_ml_nobin = p_ml_nobin;
11616 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011617 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011618#ifdef FEAT_INS_EXPAND
11619 buf->b_p_cpt = vim_strsave(p_cpt);
Bram Moolenaarac3150d2019-07-28 16:36:39 +020011620# ifdef BACKSLASH_IN_FILENAME
11621 buf->b_p_csl = vim_strsave(p_csl);
11622# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011623#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011624#ifdef FEAT_COMPL_FUNC
11625 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011626 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011627#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +020011628#ifdef FEAT_EVAL
11629 buf->b_p_tfu = vim_strsave(p_tfu);
11630#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011631 buf->b_p_sts = p_sts;
11632 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011633#ifdef FEAT_VARTABS
11634 buf->b_p_vsts = vim_strsave(p_vsts);
11635 if (p_vsts && p_vsts != empty_option)
11636 tabstop_set(p_vsts, &buf->b_p_vsts_array);
11637 else
11638 buf->b_p_vsts_array = 0;
11639 buf->b_p_vsts_nopaste = p_vsts_nopaste
11640 ? vim_strsave(p_vsts_nopaste) : NULL;
11641#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011642 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011643#ifdef FEAT_COMMENTS
11644 buf->b_p_com = vim_strsave(p_com);
11645#endif
11646#ifdef FEAT_FOLDING
11647 buf->b_p_cms = vim_strsave(p_cms);
11648#endif
11649 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011650 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011651 buf->b_p_nf = vim_strsave(p_nf);
11652 buf->b_p_mps = vim_strsave(p_mps);
11653#ifdef FEAT_SMARTINDENT
11654 buf->b_p_si = p_si;
11655#endif
11656 buf->b_p_ci = p_ci;
11657#ifdef FEAT_CINDENT
11658 buf->b_p_cin = p_cin;
11659 buf->b_p_cink = vim_strsave(p_cink);
11660 buf->b_p_cino = vim_strsave(p_cino);
11661#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011662 /* Don't copy 'filetype', it must be detected */
11663 buf->b_p_ft = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011664 buf->b_p_pi = p_pi;
11665#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11666 buf->b_p_cinw = vim_strsave(p_cinw);
11667#endif
11668#ifdef FEAT_LISP
11669 buf->b_p_lisp = p_lisp;
11670#endif
11671#ifdef FEAT_SYN_HL
11672 /* Don't copy 'syntax', it must be set */
11673 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011674 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011675 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011676#endif
11677#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011678 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011679 (void)compile_cap_prog(&buf->b_s);
11680 buf->b_s.b_p_spf = vim_strsave(p_spf);
11681 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011682#endif
11683#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11684 buf->b_p_inde = vim_strsave(p_inde);
11685 buf->b_p_indk = vim_strsave(p_indk);
11686#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011687 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011688#if defined(FEAT_EVAL)
11689 buf->b_p_fex = vim_strsave(p_fex);
11690#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011691#ifdef FEAT_CRYPT
11692 buf->b_p_key = vim_strsave(p_key);
11693#endif
11694#ifdef FEAT_SEARCHPATH
11695 buf->b_p_sua = vim_strsave(p_sua);
11696#endif
11697#ifdef FEAT_KEYMAP
11698 buf->b_p_keymap = vim_strsave(p_keymap);
11699 buf->b_kmap_state |= KEYMAP_INIT;
11700#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011701#ifdef FEAT_TERMINAL
11702 buf->b_p_twsl = p_twsl;
11703#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011704 /* This isn't really an option, but copying the langmap and IME
11705 * state from the current buffer is better than resetting it. */
11706 buf->b_p_iminsert = p_iminsert;
11707 buf->b_p_imsearch = p_imsearch;
11708
11709 /* options that are normally global but also have a local value
11710 * are not copied, start using the global value */
11711 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011712 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011713 buf->b_p_bkc = empty_option;
11714 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011715#ifdef FEAT_QUICKFIX
11716 buf->b_p_gp = empty_option;
11717 buf->b_p_mp = empty_option;
11718 buf->b_p_efm = empty_option;
11719#endif
11720 buf->b_p_ep = empty_option;
11721 buf->b_p_kp = empty_option;
11722 buf->b_p_path = empty_option;
11723 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011724 buf->b_p_tc = empty_option;
11725 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011726#ifdef FEAT_FIND_ID
11727 buf->b_p_def = empty_option;
11728 buf->b_p_inc = empty_option;
11729# ifdef FEAT_EVAL
11730 buf->b_p_inex = vim_strsave(p_inex);
11731# endif
11732#endif
11733#ifdef FEAT_INS_EXPAND
11734 buf->b_p_dict = empty_option;
11735 buf->b_p_tsr = empty_option;
11736#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011737#ifdef FEAT_TEXTOBJ
11738 buf->b_p_qe = vim_strsave(p_qe);
11739#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011740#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11741 buf->b_p_bexpr = empty_option;
11742#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011743#if defined(FEAT_CRYPT)
11744 buf->b_p_cm = empty_option;
11745#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011746#ifdef FEAT_PERSISTENT_UNDO
11747 buf->b_p_udf = p_udf;
11748#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011749#ifdef FEAT_LISP
11750 buf->b_p_lw = empty_option;
11751#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011752 buf->b_p_menc = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011753
11754 /*
11755 * Don't copy the options set by ex_help(), use the saved values,
11756 * when going from a help buffer to a non-help buffer.
11757 * Don't touch these at all when BCO_NOHELP is used and going from
11758 * or to a help buffer.
11759 */
11760 if (dont_do_help)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011761 {
Bram Moolenaar071d4272004-06-13 20:20:40 +000011762 buf->b_p_isk = save_p_isk;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011763#ifdef FEAT_VARTABS
11764 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11765 tabstop_set(p_vts, &buf->b_p_vts_array);
11766 else
11767 buf->b_p_vts_array = NULL;
11768#endif
11769 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011770 else
11771 {
11772 buf->b_p_isk = vim_strsave(p_isk);
11773 did_isk = TRUE;
11774 buf->b_p_ts = p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011775#ifdef FEAT_VARTABS
11776 buf->b_p_vts = vim_strsave(p_vts);
11777 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11778 tabstop_set(p_vts, &buf->b_p_vts_array);
11779 else
11780 buf->b_p_vts_array = NULL;
11781#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011782 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011783 if (buf->b_p_bt[0] == 'h')
11784 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011785 buf->b_p_ma = p_ma;
11786 }
11787 }
11788
11789 /*
11790 * When the options should be copied (ignoring BCO_ALWAYS), set the
11791 * flag that indicates that the options have been initialized.
11792 */
11793 if (should_copy)
11794 buf->b_p_initialized = TRUE;
11795 }
11796
11797 check_buf_options(buf); /* make sure we don't have NULLs */
11798 if (did_isk)
11799 (void)buf_init_chartab(buf, FALSE);
11800}
11801
11802/*
11803 * Reset the 'modifiable' option and its default value.
11804 */
11805 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011806reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011807{
11808 int opt_idx;
11809
11810 curbuf->b_p_ma = FALSE;
11811 p_ma = FALSE;
11812 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011813 if (opt_idx >= 0)
11814 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011815}
11816
11817/*
11818 * Set the global value for 'iminsert' to the local value.
11819 */
11820 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011821set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011822{
11823 p_iminsert = curbuf->b_p_iminsert;
11824}
11825
11826/*
11827 * Set the global value for 'imsearch' to the local value.
11828 */
11829 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011830set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011831{
11832 p_imsearch = curbuf->b_p_imsearch;
11833}
11834
11835#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11836static int expand_option_idx = -1;
11837static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11838static int expand_option_flags = 0;
11839
11840 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011841set_context_in_set_cmd(
11842 expand_T *xp,
11843 char_u *arg,
11844 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011845{
11846 int nextchar;
11847 long_u flags = 0; /* init for GCC */
11848 int opt_idx = 0; /* init for GCC */
11849 char_u *p;
11850 char_u *s;
11851 int is_term_option = FALSE;
11852 int key;
11853
11854 expand_option_flags = opt_flags;
11855
11856 xp->xp_context = EXPAND_SETTINGS;
11857 if (*arg == NUL)
11858 {
11859 xp->xp_pattern = arg;
11860 return;
11861 }
11862 p = arg + STRLEN(arg) - 1;
11863 if (*p == ' ' && *(p - 1) != '\\')
11864 {
11865 xp->xp_pattern = p + 1;
11866 return;
11867 }
11868 while (p > arg)
11869 {
11870 s = p;
11871 /* count number of backslashes before ' ' or ',' */
11872 if (*p == ' ' || *p == ',')
11873 {
11874 while (s > arg && *(s - 1) == '\\')
11875 --s;
11876 }
11877 /* break at a space with an even number of backslashes */
11878 if (*p == ' ' && ((p - s) & 1) == 0)
11879 {
11880 ++p;
11881 break;
11882 }
11883 --p;
11884 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011885 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011886 {
11887 xp->xp_context = EXPAND_BOOL_SETTINGS;
11888 p += 2;
11889 }
11890 if (STRNCMP(p, "inv", 3) == 0)
11891 {
11892 xp->xp_context = EXPAND_BOOL_SETTINGS;
11893 p += 3;
11894 }
11895 xp->xp_pattern = arg = p;
11896 if (*arg == '<')
11897 {
11898 while (*p != '>')
11899 if (*p++ == NUL) /* expand terminal option name */
11900 return;
11901 key = get_special_key_code(arg + 1);
11902 if (key == 0) /* unknown name */
11903 {
11904 xp->xp_context = EXPAND_NOTHING;
11905 return;
11906 }
11907 nextchar = *++p;
11908 is_term_option = TRUE;
11909 expand_option_name[2] = KEY2TERMCAP0(key);
11910 expand_option_name[3] = KEY2TERMCAP1(key);
11911 }
11912 else
11913 {
11914 if (p[0] == 't' && p[1] == '_')
11915 {
11916 p += 2;
11917 if (*p != NUL)
11918 ++p;
11919 if (*p == NUL)
11920 return; /* expand option name */
11921 nextchar = *++p;
11922 is_term_option = TRUE;
11923 expand_option_name[2] = p[-2];
11924 expand_option_name[3] = p[-1];
11925 }
11926 else
11927 {
11928 /* Allow * wildcard */
11929 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11930 p++;
11931 if (*p == NUL)
11932 return;
11933 nextchar = *p;
11934 *p = NUL;
11935 opt_idx = findoption(arg);
11936 *p = nextchar;
11937 if (opt_idx == -1 || options[opt_idx].var == NULL)
11938 {
11939 xp->xp_context = EXPAND_NOTHING;
11940 return;
11941 }
11942 flags = options[opt_idx].flags;
11943 if (flags & P_BOOL)
11944 {
11945 xp->xp_context = EXPAND_NOTHING;
11946 return;
11947 }
11948 }
11949 }
11950 /* handle "-=" and "+=" */
11951 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11952 {
11953 ++p;
11954 nextchar = '=';
11955 }
11956 if ((nextchar != '=' && nextchar != ':')
11957 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11958 {
11959 xp->xp_context = EXPAND_UNSUCCESSFUL;
11960 return;
11961 }
11962 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11963 {
11964 xp->xp_context = EXPAND_OLD_SETTING;
11965 if (is_term_option)
11966 expand_option_idx = -1;
11967 else
11968 expand_option_idx = opt_idx;
11969 xp->xp_pattern = p + 1;
11970 return;
11971 }
11972 xp->xp_context = EXPAND_NOTHING;
11973 if (is_term_option || (flags & P_NUM))
11974 return;
11975
11976 xp->xp_pattern = p + 1;
11977
11978 if (flags & P_EXPAND)
11979 {
11980 p = options[opt_idx].var;
11981 if (p == (char_u *)&p_bdir
11982 || p == (char_u *)&p_dir
11983 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011984 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011985 || p == (char_u *)&p_rtp
11986#ifdef FEAT_SEARCHPATH
11987 || p == (char_u *)&p_cdpath
11988#endif
11989#ifdef FEAT_SESSION
11990 || p == (char_u *)&p_vdir
11991#endif
11992 )
11993 {
11994 xp->xp_context = EXPAND_DIRECTORIES;
11995 if (p == (char_u *)&p_path
11996#ifdef FEAT_SEARCHPATH
11997 || p == (char_u *)&p_cdpath
11998#endif
11999 )
12000 xp->xp_backslash = XP_BS_THREE;
12001 else
12002 xp->xp_backslash = XP_BS_ONE;
12003 }
12004 else
12005 {
12006 xp->xp_context = EXPAND_FILES;
12007 /* for 'tags' need three backslashes for a space */
12008 if (p == (char_u *)&p_tags)
12009 xp->xp_backslash = XP_BS_THREE;
12010 else
12011 xp->xp_backslash = XP_BS_ONE;
12012 }
12013 }
12014
12015 /* For an option that is a list of file names, find the start of the
12016 * last file name. */
12017 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
12018 {
12019 /* count number of backslashes before ' ' or ',' */
12020 if (*p == ' ' || *p == ',')
12021 {
12022 s = p;
12023 while (s > xp->xp_pattern && *(s - 1) == '\\')
12024 --s;
12025 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
12026 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
12027 {
12028 xp->xp_pattern = p + 1;
12029 break;
12030 }
12031 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000012032
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000012033#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000012034 /* for 'spellsuggest' start at "file:" */
12035 if (options[opt_idx].var == (char_u *)&p_sps
12036 && STRNCMP(p, "file:", 5) == 0)
12037 {
12038 xp->xp_pattern = p + 5;
12039 break;
12040 }
12041#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012042 }
12043
12044 return;
12045}
12046
12047 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012048ExpandSettings(
12049 expand_T *xp,
12050 regmatch_T *regmatch,
12051 int *num_file,
12052 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012053{
12054 int num_normal = 0; /* Nr of matching non-term-code settings */
12055 int num_term = 0; /* Nr of matching terminal code settings */
12056 int opt_idx;
12057 int match;
12058 int count = 0;
12059 char_u *str;
12060 int loop;
12061 int is_term_opt;
12062 char_u name_buf[MAX_KEY_NAME_LEN];
12063 static char *(names[]) = {"all", "termcap"};
12064 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
12065
12066 /* do this loop twice:
12067 * loop == 0: count the number of matching options
12068 * loop == 1: copy the matching options into allocated memory
12069 */
12070 for (loop = 0; loop <= 1; ++loop)
12071 {
12072 regmatch->rm_ic = ic;
12073 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
12074 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000012075 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
12076 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012077 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
12078 {
12079 if (loop == 0)
12080 num_normal++;
12081 else
12082 (*file)[count++] = vim_strsave((char_u *)names[match]);
12083 }
12084 }
12085 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
12086 opt_idx++)
12087 {
12088 if (options[opt_idx].var == NULL)
12089 continue;
12090 if (xp->xp_context == EXPAND_BOOL_SETTINGS
12091 && !(options[opt_idx].flags & P_BOOL))
12092 continue;
12093 is_term_opt = istermoption(&options[opt_idx]);
12094 if (is_term_opt && num_normal > 0)
12095 continue;
12096 match = FALSE;
12097 if (vim_regexec(regmatch, str, (colnr_T)0)
12098 || (options[opt_idx].shortname != NULL
12099 && vim_regexec(regmatch,
12100 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
12101 match = TRUE;
12102 else if (is_term_opt)
12103 {
12104 name_buf[0] = '<';
12105 name_buf[1] = 't';
12106 name_buf[2] = '_';
12107 name_buf[3] = str[2];
12108 name_buf[4] = str[3];
12109 name_buf[5] = '>';
12110 name_buf[6] = NUL;
12111 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12112 {
12113 match = TRUE;
12114 str = name_buf;
12115 }
12116 }
12117 if (match)
12118 {
12119 if (loop == 0)
12120 {
12121 if (is_term_opt)
12122 num_term++;
12123 else
12124 num_normal++;
12125 }
12126 else
12127 (*file)[count++] = vim_strsave(str);
12128 }
12129 }
12130 /*
12131 * Check terminal key codes, these are not in the option table
12132 */
12133 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
12134 {
12135 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
12136 {
12137 if (!isprint(str[0]) || !isprint(str[1]))
12138 continue;
12139
12140 name_buf[0] = 't';
12141 name_buf[1] = '_';
12142 name_buf[2] = str[0];
12143 name_buf[3] = str[1];
12144 name_buf[4] = NUL;
12145
12146 match = FALSE;
12147 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12148 match = TRUE;
12149 else
12150 {
12151 name_buf[0] = '<';
12152 name_buf[1] = 't';
12153 name_buf[2] = '_';
12154 name_buf[3] = str[0];
12155 name_buf[4] = str[1];
12156 name_buf[5] = '>';
12157 name_buf[6] = NUL;
12158
12159 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12160 match = TRUE;
12161 }
12162 if (match)
12163 {
12164 if (loop == 0)
12165 num_term++;
12166 else
12167 (*file)[count++] = vim_strsave(name_buf);
12168 }
12169 }
12170
12171 /*
12172 * Check special key names.
12173 */
12174 regmatch->rm_ic = TRUE; /* ignore case here */
12175 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
12176 {
12177 name_buf[0] = '<';
12178 STRCPY(name_buf + 1, str);
12179 STRCAT(name_buf, ">");
12180
12181 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12182 {
12183 if (loop == 0)
12184 num_term++;
12185 else
12186 (*file)[count++] = vim_strsave(name_buf);
12187 }
12188 }
12189 }
12190 if (loop == 0)
12191 {
12192 if (num_normal > 0)
12193 *num_file = num_normal;
12194 else if (num_term > 0)
12195 *num_file = num_term;
12196 else
12197 return OK;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020012198 *file = ALLOC_MULT(char_u *, *num_file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012199 if (*file == NULL)
12200 {
12201 *file = (char_u **)"";
12202 return FAIL;
12203 }
12204 }
12205 }
12206 return OK;
12207}
12208
12209 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012210ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012211{
12212 char_u *var = NULL; /* init for GCC */
12213 char_u *buf;
12214
12215 *num_file = 0;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020012216 *file = ALLOC_ONE(char_u *);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012217 if (*file == NULL)
12218 return FAIL;
12219
12220 /*
12221 * For a terminal key code expand_option_idx is < 0.
12222 */
12223 if (expand_option_idx < 0)
12224 {
12225 var = find_termcode(expand_option_name + 2);
12226 if (var == NULL)
12227 expand_option_idx = findoption(expand_option_name);
12228 }
12229
12230 if (expand_option_idx >= 0)
12231 {
12232 /* put string of option value in NameBuff */
12233 option_value2string(&options[expand_option_idx], expand_option_flags);
12234 var = NameBuff;
12235 }
12236 else if (var == NULL)
12237 var = (char_u *)"";
12238
12239 /* A backslash is required before some characters. This is the reverse of
12240 * what happens in do_set(). */
12241 buf = vim_strsave_escaped(var, escape_chars);
12242
12243 if (buf == NULL)
12244 {
Bram Moolenaard23a8232018-02-10 18:45:26 +010012245 VIM_CLEAR(*file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012246 return FAIL;
12247 }
12248
12249#ifdef BACKSLASH_IN_FILENAME
12250 /* For MS-Windows et al. we don't double backslashes at the start and
12251 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012252 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012253 if (var[0] == '\\' && var[1] == '\\'
12254 && expand_option_idx >= 0
12255 && (options[expand_option_idx].flags & P_EXPAND)
12256 && vim_isfilec(var[2])
12257 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000012258 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012259#endif
12260
12261 *file[0] = buf;
12262 *num_file = 1;
12263 return OK;
12264}
12265#endif
12266
12267/*
12268 * Get the value for the numeric or string option *opp in a nice format into
12269 * NameBuff[]. Must not be called with a hidden option!
12270 */
12271 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012272option_value2string(
12273 struct vimoption *opp,
12274 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012275{
12276 char_u *varp;
12277
12278 varp = get_varp_scope(opp, opt_flags);
12279
12280 if (opp->flags & P_NUM)
12281 {
12282 long wc = 0;
12283
12284 if (wc_use_keyname(varp, &wc))
12285 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
12286 else if (wc != 0)
12287 STRCPY(NameBuff, transchar((int)wc));
12288 else
12289 sprintf((char *)NameBuff, "%ld", *(long *)varp);
12290 }
12291 else /* P_STRING */
12292 {
12293 varp = *(char_u **)(varp);
12294 if (varp == NULL) /* just in case */
12295 NameBuff[0] = NUL;
12296#ifdef FEAT_CRYPT
12297 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000012298 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012299 STRCPY(NameBuff, "*****");
12300#endif
12301 else if (opp->flags & P_EXPAND)
12302 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
12303 /* Translate 'pastetoggle' into special key names */
12304 else if ((char_u **)opp->var == &p_pt)
12305 str2specialbuf(p_pt, NameBuff, MAXPATHL);
12306 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000012307 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012308 }
12309}
12310
12311/*
12312 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
12313 * printed as a keyname.
12314 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
12315 */
12316 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012317wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012318{
12319 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
12320 {
12321 *wcp = *(long *)varp;
12322 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
12323 return TRUE;
12324 }
12325 return FALSE;
12326}
12327
Bram Moolenaar01615492015-02-03 13:00:38 +010012328#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012329/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012330 * Any character has an equivalent 'langmap' character. This is used for
12331 * keyboards that have a special language mode that sends characters above
12332 * 128 (although other characters can be translated too). The "to" field is a
12333 * Vim command character. This avoids having to switch the keyboard back to
12334 * ASCII mode when leaving Insert mode.
12335 *
12336 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
12337 * commands.
Bram Moolenaarfc3abf42019-01-24 15:54:21 +010012338 * langmap_mapga.ga_data is a sorted table of langmap_entry_T. This does the
12339 * same as langmap_mapchar[] for characters >= 256.
12340 *
12341 * Use growarray for 'langmap' chars >= 256
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012342 */
12343typedef struct
12344{
12345 int from;
12346 int to;
12347} langmap_entry_T;
12348
12349static garray_T langmap_mapga;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012350
12351/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012352 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
12353 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012354 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012355 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012356langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012357{
12358 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020012359 int a = 0;
12360 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012361
12362 /* Do a binary search for an existing entry. */
12363 while (a != b)
12364 {
12365 int i = (a + b) / 2;
12366 int d = entries[i].from - from;
12367
12368 if (d == 0)
12369 {
12370 entries[i].to = to;
12371 return;
12372 }
12373 if (d < 0)
12374 a = i + 1;
12375 else
12376 b = i;
12377 }
12378
12379 if (ga_grow(&langmap_mapga, 1) != OK)
12380 return; /* out of memory */
12381
12382 /* insert new entry at position "a" */
12383 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
12384 mch_memmove(entries + 1, entries,
12385 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
12386 ++langmap_mapga.ga_len;
12387 entries[0].from = from;
12388 entries[0].to = to;
12389}
12390
12391/*
12392 * Apply 'langmap' to multi-byte character "c" and return the result.
12393 */
12394 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012395langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012396{
12397 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
12398 int a = 0;
12399 int b = langmap_mapga.ga_len;
12400
12401 while (a != b)
12402 {
12403 int i = (a + b) / 2;
12404 int d = entries[i].from - c;
12405
12406 if (d == 0)
12407 return entries[i].to; /* found matching entry */
12408 if (d < 0)
12409 a = i + 1;
12410 else
12411 b = i;
12412 }
12413 return c; /* no entry found, return "c" unmodified */
12414}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012415
12416 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012417langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012418{
12419 int i;
12420
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012421 for (i = 0; i < 256; i++)
12422 langmap_mapchar[i] = i; /* we init with a one-to-one map */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012423 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012424}
12425
12426/*
12427 * Called when langmap option is set; the language map can be
12428 * changed at any time!
12429 */
12430 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012431langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012432{
12433 char_u *p;
12434 char_u *p2;
12435 int from, to;
12436
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012437 ga_clear(&langmap_mapga); /* clear the previous map first */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012438 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012439
12440 for (p = p_langmap; p[0] != NUL; )
12441 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000012442 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012443 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012444 {
12445 if (p2[0] == '\\' && p2[1] != NUL)
12446 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012447 }
12448 if (p2[0] == ';')
12449 ++p2; /* abcd;ABCD form, p2 points to A */
12450 else
12451 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
12452 while (p[0])
12453 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012454 if (p[0] == ',')
12455 {
12456 ++p;
12457 break;
12458 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012459 if (p[0] == '\\' && p[1] != NUL)
12460 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012461 from = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012462 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012463 if (p2 == NULL)
12464 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012465 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012466 if (p[0] != ',')
12467 {
12468 if (p[0] == '\\')
12469 ++p;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012470 to = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012471 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012472 }
12473 else
12474 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012475 if (p2[0] != ',')
12476 {
12477 if (p2[0] == '\\')
12478 ++p2;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012479 to = (*mb_ptr2char)(p2);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012480 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012481 }
12482 if (to == NUL)
12483 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012484 semsg(_("E357: 'langmap': Matching character missing for %s"),
Bram Moolenaar071d4272004-06-13 20:20:40 +000012485 transchar(from));
12486 return;
12487 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012488
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012489 if (from >= 256)
12490 langmap_set_entry(from, to);
12491 else
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012492 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012493
12494 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012495 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012496 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012497 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012498 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012499 if (*p == ';')
12500 {
12501 p = p2;
12502 if (p[0] != NUL)
12503 {
12504 if (p[0] != ',')
12505 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012506 semsg(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012507 return;
12508 }
12509 ++p;
12510 }
12511 break;
12512 }
12513 }
12514 }
12515 }
12516}
12517#endif
12518
12519/*
12520 * Return TRUE if format option 'x' is in effect.
12521 * Take care of no formatting when 'paste' is set.
12522 */
12523 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012524has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012525{
12526 if (p_paste)
12527 return FALSE;
12528 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12529}
12530
12531/*
12532 * Return TRUE if "x" is present in 'shortmess' option, or
12533 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12534 */
12535 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012536shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012537{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012538 return p_shm != NULL &&
12539 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012540 || (vim_strchr(p_shm, 'a') != NULL
12541 && vim_strchr((char_u *)SHM_A, x) != NULL));
12542}
12543
12544/*
12545 * paste_option_changed() - Called after p_paste was set or reset.
12546 */
12547 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012548paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012549{
12550 static int old_p_paste = FALSE;
12551 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012552 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012553#ifdef FEAT_CMDL_INFO
12554 static int save_ru = 0;
12555#endif
12556#ifdef FEAT_RIGHTLEFT
12557 static int save_ri = 0;
12558 static int save_hkmap = 0;
12559#endif
12560 buf_T *buf;
12561
12562 if (p_paste)
12563 {
12564 /*
12565 * Paste switched from off to on.
12566 * Save the current values, so they can be restored later.
12567 */
12568 if (!old_p_paste)
12569 {
12570 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012571 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012572 {
12573 buf->b_p_tw_nopaste = buf->b_p_tw;
12574 buf->b_p_wm_nopaste = buf->b_p_wm;
12575 buf->b_p_sts_nopaste = buf->b_p_sts;
12576 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012577 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012578#ifdef FEAT_VARTABS
12579 if (buf->b_p_vsts_nopaste)
12580 vim_free(buf->b_p_vsts_nopaste);
12581 buf->b_p_vsts_nopaste = buf->b_p_vsts && buf->b_p_vsts != empty_option
12582 ? vim_strsave(buf->b_p_vsts) : NULL;
12583#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012584 }
12585
12586 /* save global options */
12587 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012588 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012589#ifdef FEAT_CMDL_INFO
12590 save_ru = p_ru;
12591#endif
12592#ifdef FEAT_RIGHTLEFT
12593 save_ri = p_ri;
12594 save_hkmap = p_hkmap;
12595#endif
12596 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012597 p_ai_nopaste = p_ai;
12598 p_et_nopaste = p_et;
12599 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012600 p_tw_nopaste = p_tw;
12601 p_wm_nopaste = p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012602#ifdef FEAT_VARTABS
12603 if (p_vsts_nopaste)
12604 vim_free(p_vsts_nopaste);
12605 p_vsts_nopaste = p_vsts && p_vsts != empty_option ? vim_strsave(p_vsts) : NULL;
12606#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012607 }
12608
12609 /*
12610 * Always set the option values, also when 'paste' is set when it is
12611 * already on.
12612 */
12613 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012614 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012615 {
12616 buf->b_p_tw = 0; /* textwidth is 0 */
12617 buf->b_p_wm = 0; /* wrapmargin is 0 */
12618 buf->b_p_sts = 0; /* softtabstop is 0 */
12619 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012620 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012621#ifdef FEAT_VARTABS
12622 if (buf->b_p_vsts)
12623 free_string_option(buf->b_p_vsts);
12624 buf->b_p_vsts = empty_option;
12625 if (buf->b_p_vsts_array)
12626 vim_free(buf->b_p_vsts_array);
12627 buf->b_p_vsts_array = 0;
12628#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012629 }
12630
12631 /* set global options */
12632 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012633 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012634#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012635 if (p_ru)
12636 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012637 p_ru = 0; /* no ruler */
12638#endif
12639#ifdef FEAT_RIGHTLEFT
12640 p_ri = 0; /* no reverse insert */
12641 p_hkmap = 0; /* no Hebrew keyboard */
12642#endif
12643 /* set global values for local buffer options */
12644 p_tw = 0;
12645 p_wm = 0;
12646 p_sts = 0;
12647 p_ai = 0;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012648#ifdef FEAT_VARTABS
12649 if (p_vsts)
12650 free_string_option(p_vsts);
12651 p_vsts = empty_option;
12652#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012653 }
12654
12655 /*
12656 * Paste switched from on to off: Restore saved values.
12657 */
12658 else if (old_p_paste)
12659 {
12660 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012661 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012662 {
12663 buf->b_p_tw = buf->b_p_tw_nopaste;
12664 buf->b_p_wm = buf->b_p_wm_nopaste;
12665 buf->b_p_sts = buf->b_p_sts_nopaste;
12666 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012667 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012668#ifdef FEAT_VARTABS
12669 if (buf->b_p_vsts)
12670 free_string_option(buf->b_p_vsts);
12671 buf->b_p_vsts = buf->b_p_vsts_nopaste
12672 ? vim_strsave(buf->b_p_vsts_nopaste) : empty_option;
12673 if (buf->b_p_vsts_array)
12674 vim_free(buf->b_p_vsts_array);
12675 if (buf->b_p_vsts && buf->b_p_vsts != empty_option)
12676 tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array);
12677 else
12678 buf->b_p_vsts_array = 0;
12679#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012680 }
12681
12682 /* restore global options */
12683 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012684 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012685#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012686 if (p_ru != save_ru)
12687 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012688 p_ru = save_ru;
12689#endif
12690#ifdef FEAT_RIGHTLEFT
12691 p_ri = save_ri;
12692 p_hkmap = save_hkmap;
12693#endif
12694 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012695 p_ai = p_ai_nopaste;
12696 p_et = p_et_nopaste;
12697 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012698 p_tw = p_tw_nopaste;
12699 p_wm = p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012700#ifdef FEAT_VARTABS
12701 if (p_vsts)
12702 free_string_option(p_vsts);
12703 p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option;
12704#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012705 }
12706
12707 old_p_paste = p_paste;
12708}
12709
12710/*
12711 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12712 *
12713 * Reset 'compatible' and set the values for options that didn't get set yet
12714 * to the Vim defaults.
12715 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012716 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012717 */
12718 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012719vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012720{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012721 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012722 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012723 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012724
12725 if (!option_was_set((char_u *)"cp"))
12726 {
12727 p_cp = FALSE;
12728 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12729 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12730 set_option_default(opt_idx, OPT_FREE, FALSE);
12731 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012732 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012733 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012734
12735 if (fname != NULL)
12736 {
12737 p = vim_getenv(envname, &dofree);
12738 if (p == NULL)
12739 {
12740 /* Set $MYVIMRC to the first vimrc file found. */
12741 p = FullName_save(fname, FALSE);
12742 if (p != NULL)
12743 {
12744 vim_setenv(envname, p);
12745 vim_free(p);
12746 }
12747 }
12748 else if (dofree)
12749 vim_free(p);
12750 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012751}
12752
12753/*
12754 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12755 */
12756 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012757change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012758{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012759 int opt_idx;
12760
Bram Moolenaar071d4272004-06-13 20:20:40 +000012761 if (p_cp != on)
12762 {
12763 p_cp = on;
12764 compatible_set();
12765 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012766 opt_idx = findoption((char_u *)"cp");
12767 if (opt_idx >= 0)
12768 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012769}
12770
12771/*
12772 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012773 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012774 */
12775 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012776option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012777{
12778 int idx;
12779
12780 idx = findoption(name);
12781 if (idx < 0) /* unknown option */
12782 return FALSE;
12783 if (options[idx].flags & P_WAS_SET)
12784 return TRUE;
12785 return FALSE;
12786}
12787
12788/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012789 * Reset the flag indicating option "name" was set.
12790 */
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012791 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012792reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012793{
12794 int idx = findoption(name);
12795
12796 if (idx >= 0)
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012797 {
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012798 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012799 return OK;
12800 }
12801 return FAIL;
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012802}
12803
12804/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012805 * compatible_set() - Called when 'compatible' has been set or unset.
12806 *
12807 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12808 * flag) to a Vi compatible value.
12809 * When 'compatible' is unset: Set all options that have a different default
12810 * for Vim (without the P_VI_DEF flag) to that default.
12811 */
12812 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012813compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012814{
12815 int opt_idx;
12816
12817 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12818 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12819 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12820 set_option_default(opt_idx, OPT_FREE, p_cp);
12821 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012822 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012823}
12824
12825#ifdef FEAT_LINEBREAK
12826
Bram Moolenaar071d4272004-06-13 20:20:40 +000012827/*
12828 * fill_breakat_flags() -- called when 'breakat' changes value.
12829 */
12830 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012831fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012832{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012833 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012834 int i;
12835
12836 for (i = 0; i < 256; i++)
12837 breakat_flags[i] = FALSE;
12838
12839 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012840 for (p = p_breakat; *p; p++)
12841 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012842}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012843#endif
12844
12845/*
12846 * Check an option that can be a range of string values.
12847 *
12848 * Return OK for correct value, FAIL otherwise.
12849 * Empty is always OK.
12850 */
12851 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012852check_opt_strings(
12853 char_u *val,
12854 char **values,
12855 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012856{
12857 return opt_strings_flags(val, values, NULL, list);
12858}
12859
12860/*
12861 * Handle an option that can be a range of string values.
12862 * Set a flag in "*flagp" for each string present.
12863 *
12864 * Return OK for correct value, FAIL otherwise.
12865 * Empty is always OK.
12866 */
12867 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012868opt_strings_flags(
12869 char_u *val, /* new value */
12870 char **values, /* array of valid string values */
12871 unsigned *flagp,
12872 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012873{
12874 int i;
12875 int len;
12876 unsigned new_flags = 0;
12877
12878 while (*val)
12879 {
12880 for (i = 0; ; ++i)
12881 {
12882 if (values[i] == NULL) /* val not found in values[] */
12883 return FAIL;
12884
12885 len = (int)STRLEN(values[i]);
12886 if (STRNCMP(values[i], val, len) == 0
12887 && ((list && val[len] == ',') || val[len] == NUL))
12888 {
12889 val += len + (val[len] == ',');
12890 new_flags |= (1 << i);
12891 break; /* check next item in val list */
12892 }
12893 }
12894 }
12895 if (flagp != NULL)
12896 *flagp = new_flags;
12897
12898 return OK;
12899}
12900
12901/*
12902 * Read the 'wildmode' option, fill wim_flags[].
12903 */
12904 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012905check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012906{
12907 char_u new_wim_flags[4];
12908 char_u *p;
12909 int i;
12910 int idx = 0;
12911
12912 for (i = 0; i < 4; ++i)
12913 new_wim_flags[i] = 0;
12914
12915 for (p = p_wim; *p; ++p)
12916 {
12917 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12918 ;
12919 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12920 return FAIL;
12921 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12922 new_wim_flags[idx] |= WIM_LONGEST;
12923 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12924 new_wim_flags[idx] |= WIM_FULL;
12925 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12926 new_wim_flags[idx] |= WIM_LIST;
12927 else
12928 return FAIL;
12929 p += i;
12930 if (*p == NUL)
12931 break;
12932 if (*p == ',')
12933 {
12934 if (idx == 3)
12935 return FAIL;
12936 ++idx;
12937 }
12938 }
12939
12940 /* fill remaining entries with last flag */
12941 while (idx < 3)
12942 {
12943 new_wim_flags[idx + 1] = new_wim_flags[idx];
12944 ++idx;
12945 }
12946
12947 /* only when there are no errors, wim_flags[] is changed */
12948 for (i = 0; i < 4; ++i)
12949 wim_flags[i] = new_wim_flags[i];
12950 return OK;
12951}
12952
12953/*
12954 * Check if backspacing over something is allowed.
12955 */
12956 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012957can_bs(
12958 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012959{
Bram Moolenaar6b810d92018-06-04 17:28:44 +020012960#ifdef FEAT_JOB_CHANNEL
12961 if (what == BS_START && bt_prompt(curbuf))
12962 return FALSE;
12963#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012964 switch (*p_bs)
12965 {
12966 case '2': return TRUE;
12967 case '1': return (what != BS_START);
12968 case '0': return FALSE;
12969 }
12970 return vim_strchr(p_bs, what) != NULL;
12971}
12972
12973/*
12974 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12975 * the file must be considered changed when the value is different.
12976 */
12977 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012978save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012979{
12980 buf->b_start_ffc = *buf->b_p_ff;
12981 buf->b_start_eol = buf->b_p_eol;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012982 buf->b_start_bomb = buf->b_p_bomb;
12983
Bram Moolenaar071d4272004-06-13 20:20:40 +000012984 /* Only use free/alloc when necessary, they take time. */
12985 if (buf->b_start_fenc == NULL
12986 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12987 {
12988 vim_free(buf->b_start_fenc);
12989 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12990 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012991}
12992
12993/*
12994 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12995 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012996 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12997 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012998 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012999 * When "ignore_empty" is true don't consider a new, empty buffer to be
13000 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000013001 */
13002 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013003file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000013004{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000013005 /* In a buffer that was never loaded the options are not valid. */
13006 if (buf->b_flags & BF_NEVERLOADED)
13007 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010013008 if (ignore_empty
13009 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000013010 && buf->b_ml.ml_line_count == 1
13011 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
13012 return FALSE;
13013 if (buf->b_start_ffc != *buf->b_p_ff)
13014 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020013015 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000013016 return TRUE;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000013017 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
13018 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000013019 if (buf->b_start_fenc == NULL)
13020 return (*buf->b_p_fenc != NUL);
13021 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +000013022}
13023
13024/*
13025 * return OK if "p" is a valid fileformat name, FAIL otherwise.
13026 */
13027 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013028check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000013029{
13030 return check_opt_strings(p, p_ff_values, FALSE);
13031}
Bram Moolenaar14f24742012-08-08 18:01:05 +020013032
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010013033#if defined(FEAT_VARTABS) || defined(PROTO)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013034
13035/*
13036 * Set the integer values corresponding to the string setting of 'vartabstop'.
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010013037 * "array" will be set, caller must free it if needed.
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013038 */
13039 int
13040tabstop_set(char_u *var, int **array)
13041{
13042 int valcount = 1;
13043 int t;
13044 char_u *cp;
13045
Bram Moolenaar64f41072018-10-15 22:51:50 +020013046 if (var[0] == NUL || (var[0] == '0' && var[1] == NUL))
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013047 {
13048 *array = NULL;
13049 return TRUE;
13050 }
13051
Bram Moolenaar64f41072018-10-15 22:51:50 +020013052 for (cp = var; *cp != NUL; ++cp)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013053 {
Bram Moolenaar64f41072018-10-15 22:51:50 +020013054 if (cp == var || cp[-1] == ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013055 {
13056 char_u *end;
Bram Moolenaar64f41072018-10-15 22:51:50 +020013057
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013058 if (strtol((char *)cp, (char **)&end, 10) <= 0)
13059 {
13060 if (cp != end)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010013061 emsg(_(e_positive));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013062 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010013063 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013064 return FALSE;
13065 }
13066 }
13067
13068 if (VIM_ISDIGIT(*cp))
13069 continue;
Bram Moolenaar64f41072018-10-15 22:51:50 +020013070 if (cp[0] == ',' && cp > var && cp[-1] != ',' && cp[1] != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013071 {
13072 ++valcount;
13073 continue;
13074 }
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010013075 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013076 return FALSE;
13077 }
13078
Bram Moolenaarc799fe22019-05-28 23:08:19 +020013079 *array = ALLOC_MULT(int, valcount + 1);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010013080 if (*array == NULL)
13081 return FALSE;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013082 (*array)[0] = valcount;
13083
13084 t = 1;
Bram Moolenaar64f41072018-10-15 22:51:50 +020013085 for (cp = var; *cp != NUL;)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013086 {
13087 (*array)[t++] = atoi((char *)cp);
Bram Moolenaar64f41072018-10-15 22:51:50 +020013088 while (*cp != NUL && *cp != ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013089 ++cp;
Bram Moolenaar64f41072018-10-15 22:51:50 +020013090 if (*cp != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013091 ++cp;
13092 }
13093
13094 return TRUE;
13095}
13096
13097/*
13098 * Calculate the number of screen spaces a tab will occupy.
13099 * If "vts" is set then the tab widths are taken from that array,
13100 * otherwise the value of ts is used.
13101 */
13102 int
13103tabstop_padding(colnr_T col, int ts_arg, int *vts)
13104{
13105 int ts = ts_arg == 0 ? 8 : ts_arg;
13106 int tabcount;
13107 colnr_T tabcol = 0;
13108 int t;
13109 int padding = 0;
13110
13111 if (vts == NULL || vts[0] == 0)
13112 return ts - (col % ts);
13113
13114 tabcount = vts[0];
13115
13116 for (t = 1; t <= tabcount; ++t)
13117 {
13118 tabcol += vts[t];
13119 if (tabcol > col)
13120 {
13121 padding = (int)(tabcol - col);
13122 break;
13123 }
13124 }
13125 if (t > tabcount)
13126 padding = vts[tabcount] - (int)((col - tabcol) % vts[tabcount]);
13127
13128 return padding;
13129}
13130
13131/*
13132 * Find the size of the tab that covers a particular column.
13133 */
13134 int
13135tabstop_at(colnr_T col, int ts, int *vts)
13136{
13137 int tabcount;
13138 colnr_T tabcol = 0;
13139 int t;
13140 int tab_size = 0;
13141
13142 if (vts == 0 || vts[0] == 0)
13143 return ts;
13144
13145 tabcount = vts[0];
13146 for (t = 1; t <= tabcount; ++t)
13147 {
13148 tabcol += vts[t];
13149 if (tabcol > col)
13150 {
13151 tab_size = vts[t];
13152 break;
13153 }
13154 }
13155 if (t > tabcount)
13156 tab_size = vts[tabcount];
13157
13158 return tab_size;
13159}
13160
13161/*
13162 * Find the column on which a tab starts.
13163 */
13164 colnr_T
13165tabstop_start(colnr_T col, int ts, int *vts)
13166{
13167 int tabcount;
13168 colnr_T tabcol = 0;
13169 int t;
13170 int excess;
13171
Bram Moolenaar0119a592018-06-24 23:53:28 +020013172 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013173 return (col / ts) * ts;
13174
13175 tabcount = vts[0];
13176 for (t = 1; t <= tabcount; ++t)
13177 {
13178 tabcol += vts[t];
13179 if (tabcol > col)
13180 return tabcol - vts[t];
13181 }
13182
13183 excess = tabcol % vts[tabcount];
13184 return excess + ((col - excess) / vts[tabcount]) * vts[tabcount];
13185}
13186
13187/*
13188 * Find the number of tabs and spaces necessary to get from one column
13189 * to another.
13190 */
13191 void
13192tabstop_fromto(
13193 colnr_T start_col,
13194 colnr_T end_col,
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013195 int ts_arg,
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013196 int *vts,
13197 int *ntabs,
13198 int *nspcs)
13199{
13200 int spaces = end_col - start_col;
13201 colnr_T tabcol = 0;
13202 int padding = 0;
13203 int tabcount;
13204 int t;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013205 int ts = ts_arg == 0 ? curbuf->b_p_ts : ts_arg;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013206
Bram Moolenaar0119a592018-06-24 23:53:28 +020013207 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013208 {
13209 int tabs = 0;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013210 int initspc = 0;
Bram Moolenaar0119a592018-06-24 23:53:28 +020013211
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013212 initspc = ts - (start_col % ts);
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013213 if (spaces >= initspc)
13214 {
13215 spaces -= initspc;
13216 tabs++;
13217 }
13218 tabs += spaces / ts;
13219 spaces -= (spaces / ts) * ts;
13220
13221 *ntabs = tabs;
13222 *nspcs = spaces;
13223 return;
13224 }
13225
13226 /* Find the padding needed to reach the next tabstop. */
13227 tabcount = vts[0];
13228 for (t = 1; t <= tabcount; ++t)
13229 {
13230 tabcol += vts[t];
13231 if (tabcol > start_col)
13232 {
13233 padding = (int)(tabcol - start_col);
13234 break;
13235 }
13236 }
13237 if (t > tabcount)
13238 padding = vts[tabcount] - (int)((start_col - tabcol) % vts[tabcount]);
13239
13240 /* If the space needed is less than the padding no tabs can be used. */
13241 if (spaces < padding)
13242 {
13243 *ntabs = 0;
13244 *nspcs = spaces;
13245 return;
13246 }
13247
13248 *ntabs = 1;
13249 spaces -= padding;
13250
13251 /* At least one tab has been used. See if any more will fit. */
13252 while (spaces != 0 && ++t <= tabcount)
13253 {
13254 padding = vts[t];
13255 if (spaces < padding)
13256 {
13257 *nspcs = spaces;
13258 return;
13259 }
13260 ++*ntabs;
13261 spaces -= padding;
13262 }
13263
13264 *ntabs += spaces / vts[tabcount];
13265 *nspcs = spaces % vts[tabcount];
13266}
13267
13268/*
13269 * See if two tabstop arrays contain the same values.
13270 */
13271 int
13272tabstop_eq(int *ts1, int *ts2)
13273{
13274 int t;
13275
13276 if ((ts1 == 0 && ts2) || (ts1 && ts2 == 0))
13277 return FALSE;
13278 if (ts1 == ts2)
13279 return TRUE;
13280 if (ts1[0] != ts2[0])
13281 return FALSE;
13282
13283 for (t = 1; t <= ts1[0]; ++t)
13284 if (ts1[t] != ts2[t])
13285 return FALSE;
13286
13287 return TRUE;
13288}
13289
Bram Moolenaar113e1072019-01-20 15:30:40 +010013290#if defined(FEAT_BEVAL) || defined(PROTO)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013291/*
13292 * Copy a tabstop array, allocating space for the new array.
13293 */
13294 int *
13295tabstop_copy(int *oldts)
13296{
13297 int *newts;
13298 int t;
13299
Bram Moolenaar6ee96582019-04-27 22:06:37 +020013300 if (oldts == NULL)
13301 return NULL;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020013302 newts = ALLOC_MULT(int, oldts[0] + 1);
Bram Moolenaar6ee96582019-04-27 22:06:37 +020013303 if (newts != NULL)
13304 for (t = 0; t <= oldts[0]; ++t)
13305 newts[t] = oldts[t];
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013306 return newts;
13307}
Bram Moolenaar113e1072019-01-20 15:30:40 +010013308#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013309
13310/*
13311 * Return a count of the number of tabstops.
13312 */
13313 int
13314tabstop_count(int *ts)
13315{
13316 return ts != NULL ? ts[0] : 0;
13317}
13318
13319/*
13320 * Return the first tabstop, or 8 if there are no tabstops defined.
13321 */
13322 int
13323tabstop_first(int *ts)
13324{
13325 return ts != NULL ? ts[1] : 8;
13326}
13327
13328#endif
13329
Bram Moolenaar14f24742012-08-08 18:01:05 +020013330/*
13331 * Return the effective shiftwidth value for current buffer, using the
13332 * 'tabstop' value when 'shiftwidth' is zero.
13333 */
13334 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013335get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020013336{
Bram Moolenaarf9514162018-11-22 03:08:29 +010013337 return get_sw_value_col(buf, 0);
13338}
13339
13340/*
13341 * Idem, using the first non-black in the current line.
13342 */
13343 long
13344get_sw_value_indent(buf_T *buf)
13345{
13346 pos_T pos = curwin->w_cursor;
13347
13348 pos.col = getwhitecols_curline();
13349 return get_sw_value_pos(buf, &pos);
13350}
13351
13352/*
13353 * Idem, using "pos".
13354 */
13355 long
13356get_sw_value_pos(buf_T *buf, pos_T *pos)
13357{
13358 pos_T save_cursor = curwin->w_cursor;
13359 long sw_value;
13360
13361 curwin->w_cursor = *pos;
13362 sw_value = get_sw_value_col(buf, get_nolist_virtcol());
13363 curwin->w_cursor = save_cursor;
13364 return sw_value;
13365}
13366
13367/*
13368 * Idem, using virtual column "col".
13369 */
13370 long
13371get_sw_value_col(buf_T *buf, colnr_T col UNUSED)
13372{
13373 return buf->b_p_sw ? buf->b_p_sw :
13374 #ifdef FEAT_VARTABS
13375 tabstop_at(col, buf->b_p_ts, buf->b_p_vts_array);
13376 #else
13377 buf->b_p_ts;
13378 #endif
Bram Moolenaar14f24742012-08-08 18:01:05 +020013379}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013380
13381/*
13382 * Return the effective softtabstop value for the current buffer, using the
Bram Moolenaar33d5ab32018-07-02 20:51:24 +020013383 * 'shiftwidth' value when 'softtabstop' is negative.
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013384 */
13385 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013386get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013387{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010013388 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013389}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013390
13391/*
Bram Moolenaar375e3392019-01-31 18:26:10 +010013392 * Return the effective 'scrolloff' value for the current window, using the
13393 * global value when appropriate.
13394 */
13395 long
13396get_scrolloff_value(void)
13397{
13398 return curwin->w_p_so < 0 ? p_so : curwin->w_p_so;
13399}
13400
13401/*
13402 * Return the effective 'sidescrolloff' value for the current window, using the
13403 * global value when appropriate.
13404 */
13405 long
13406get_sidescrolloff_value(void)
13407{
13408 return curwin->w_p_siso < 0 ? p_siso : curwin->w_p_siso;
13409}
13410
13411/*
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013412 * Check matchpairs option for "*initc".
13413 * If there is a match set "*initc" to the matching character and "*findc" to
13414 * the opposite character. Set "*backwards" to the direction.
13415 * When "switchit" is TRUE swap the direction.
13416 */
13417 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010013418find_mps_values(
13419 int *initc,
13420 int *findc,
13421 int *backwards,
13422 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013423{
13424 char_u *ptr;
13425
13426 ptr = curbuf->b_p_mps;
13427 while (*ptr != NUL)
13428 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013429 if (has_mbyte)
13430 {
13431 char_u *prev;
13432
13433 if (mb_ptr2char(ptr) == *initc)
13434 {
13435 if (switchit)
13436 {
13437 *findc = *initc;
13438 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13439 *backwards = TRUE;
13440 }
13441 else
13442 {
13443 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13444 *backwards = FALSE;
13445 }
13446 return;
13447 }
13448 prev = ptr;
13449 ptr += mb_ptr2len(ptr) + 1;
13450 if (mb_ptr2char(ptr) == *initc)
13451 {
13452 if (switchit)
13453 {
13454 *findc = *initc;
13455 *initc = mb_ptr2char(prev);
13456 *backwards = FALSE;
13457 }
13458 else
13459 {
13460 *findc = mb_ptr2char(prev);
13461 *backwards = TRUE;
13462 }
13463 return;
13464 }
13465 ptr += mb_ptr2len(ptr);
13466 }
13467 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013468 {
13469 if (*ptr == *initc)
13470 {
13471 if (switchit)
13472 {
13473 *backwards = TRUE;
13474 *findc = *initc;
13475 *initc = ptr[2];
13476 }
13477 else
13478 {
13479 *backwards = FALSE;
13480 *findc = ptr[2];
13481 }
13482 return;
13483 }
13484 ptr += 2;
13485 if (*ptr == *initc)
13486 {
13487 if (switchit)
13488 {
13489 *backwards = FALSE;
13490 *findc = *initc;
13491 *initc = ptr[-2];
13492 }
13493 else
13494 {
13495 *backwards = TRUE;
13496 *findc = ptr[-2];
13497 }
13498 return;
13499 }
13500 ++ptr;
13501 }
13502 if (*ptr == ',')
13503 ++ptr;
13504 }
13505}
Bram Moolenaar597a4222014-06-25 14:39:50 +020013506
13507#if defined(FEAT_LINEBREAK) || defined(PROTO)
13508/*
13509 * This is called when 'breakindentopt' is changed and when a window is
13510 * initialized.
13511 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013512 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013513briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020013514{
13515 char_u *p;
13516 int bri_shift = 0;
13517 long bri_min = 20;
13518 int bri_sbr = FALSE;
13519
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013520 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013521 while (*p != NUL)
13522 {
13523 if (STRNCMP(p, "shift:", 6) == 0
13524 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
13525 {
13526 p += 6;
13527 bri_shift = getdigits(&p);
13528 }
13529 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
13530 {
13531 p += 4;
13532 bri_min = getdigits(&p);
13533 }
13534 else if (STRNCMP(p, "sbr", 3) == 0)
13535 {
13536 p += 3;
13537 bri_sbr = TRUE;
13538 }
13539 if (*p != ',' && *p != NUL)
13540 return FAIL;
13541 if (*p == ',')
13542 ++p;
13543 }
13544
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013545 wp->w_p_brishift = bri_shift;
13546 wp->w_p_brimin = bri_min;
13547 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013548
13549 return OK;
13550}
13551#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013552
13553/*
13554 * Get the local or global value of 'backupcopy'.
13555 */
13556 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013557get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013558{
13559 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
13560}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020013561
13562#if defined(FEAT_SIGNS) || defined(PROTO)
13563/*
13564 * Return TRUE when window "wp" has a column to draw signs in.
13565 */
13566 int
13567signcolumn_on(win_T *wp)
13568{
Bram Moolenaar394c5d82019-06-17 21:48:05 +020013569 // If 'signcolumn' is set to 'number', signs are displayed in the 'number'
13570 // column (if present). Otherwise signs are to be displayed in the sign
13571 // column.
13572 if (*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
13573 return wp->w_buffer->b_signlist != NULL && !wp->w_p_nu && !wp->w_p_rnu;
13574
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020013575 if (*wp->w_p_scl == 'n')
13576 return FALSE;
13577 if (*wp->w_p_scl == 'y')
13578 return TRUE;
13579 return (wp->w_buffer->b_signlist != NULL
13580# ifdef FEAT_NETBEANS_INTG
13581 || wp->w_buffer->b_has_sign_column
13582# endif
13583 );
13584}
13585#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013586
13587#if defined(FEAT_EVAL) || defined(PROTO)
13588/*
13589 * Get window or buffer local options.
13590 */
13591 dict_T *
13592get_winbuf_options(int bufopt)
13593{
13594 dict_T *d;
13595 int opt_idx;
13596
13597 d = dict_alloc();
13598 if (d == NULL)
13599 return NULL;
13600
13601 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
13602 {
13603 struct vimoption *opt = &options[opt_idx];
13604
13605 if ((bufopt && (opt->indir & PV_BUF))
13606 || (!bufopt && (opt->indir & PV_WIN)))
13607 {
13608 char_u *varp = get_varp(opt);
13609
13610 if (varp != NULL)
13611 {
13612 if (opt->flags & P_STRING)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013613 dict_add_string(d, opt->fullname, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020013614 else if (opt->flags & P_NUM)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013615 dict_add_number(d, opt->fullname, *(long *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013616 else
Bram Moolenaare0be1672018-07-08 16:50:37 +020013617 dict_add_number(d, opt->fullname, *(int *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013618 }
13619 }
13620 }
13621
13622 return d;
13623}
13624#endif