blob: baa8d855c6a18f67ad33c0f2989566a8c4db46d1 [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 Moolenaar5e3cb7e2006-02-27 23:58:35 +000069#ifdef FEAT_MBYTE
70# define PV_BOMB OPT_BUF(BV_BOMB)
71#endif
72#define PV_CI OPT_BUF(BV_CI)
73#ifdef FEAT_CINDENT
74# define PV_CIN OPT_BUF(BV_CIN)
75# define PV_CINK OPT_BUF(BV_CINK)
76# define PV_CINO OPT_BUF(BV_CINO)
77#endif
78#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
79# define PV_CINW OPT_BUF(BV_CINW)
80#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020081#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000082#ifdef FEAT_FOLDING
83# define PV_CMS OPT_BUF(BV_CMS)
84#endif
85#ifdef FEAT_COMMENTS
86# define PV_COM OPT_BUF(BV_COM)
87#endif
88#ifdef FEAT_INS_EXPAND
89# define PV_CPT OPT_BUF(BV_CPT)
90# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
91# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
92#endif
93#ifdef FEAT_COMPL_FUNC
94# define PV_CFU OPT_BUF(BV_CFU)
95#endif
96#ifdef FEAT_FIND_ID
97# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
98# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
99#endif
100#define PV_EOL OPT_BUF(BV_EOL)
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200101#define PV_FIXEOL OPT_BUF(BV_FIXEOL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000102#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
103#define PV_ET OPT_BUF(BV_ET)
104#ifdef FEAT_MBYTE
105# define PV_FENC OPT_BUF(BV_FENC)
106#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000107#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
108# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
109#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100110#define PV_FP OPT_BOTH(OPT_BUF(BV_FP))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000111#ifdef FEAT_EVAL
112# define PV_FEX OPT_BUF(BV_FEX)
113#endif
114#define PV_FF OPT_BUF(BV_FF)
115#define PV_FLP OPT_BUF(BV_FLP)
116#define PV_FO OPT_BUF(BV_FO)
117#ifdef FEAT_AUTOCMD
118# define PV_FT OPT_BUF(BV_FT)
119#endif
120#define PV_IMI OPT_BUF(BV_IMI)
121#define PV_IMS OPT_BUF(BV_IMS)
122#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
123# define PV_INDE OPT_BUF(BV_INDE)
124# define PV_INDK OPT_BUF(BV_INDK)
125#endif
126#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
127# define PV_INEX OPT_BUF(BV_INEX)
128#endif
129#define PV_INF OPT_BUF(BV_INF)
130#define PV_ISK OPT_BUF(BV_ISK)
131#ifdef FEAT_CRYPT
132# define PV_KEY OPT_BUF(BV_KEY)
133#endif
134#ifdef FEAT_KEYMAP
135# define PV_KMAP OPT_BUF(BV_KMAP)
136#endif
137#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
138#ifdef FEAT_LISP
139# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100140# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000141#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +0100142#ifdef FEAT_MBYTE
143# define PV_MENC OPT_BOTH(OPT_BUF(BV_MENC))
144#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000145#define PV_MA OPT_BUF(BV_MA)
146#define PV_ML OPT_BUF(BV_ML)
147#define PV_MOD OPT_BUF(BV_MOD)
148#define PV_MPS OPT_BUF(BV_MPS)
149#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000150#ifdef FEAT_COMPL_FUNC
151# define PV_OFU OPT_BUF(BV_OFU)
152#endif
153#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
154#define PV_PI OPT_BUF(BV_PI)
155#ifdef FEAT_TEXTOBJ
156# define PV_QE OPT_BUF(BV_QE)
157#endif
158#define PV_RO OPT_BUF(BV_RO)
159#ifdef FEAT_SMARTINDENT
160# define PV_SI OPT_BUF(BV_SI)
161#endif
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100162#define PV_SN OPT_BUF(BV_SN)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000163#ifdef FEAT_SYN_HL
164# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000165# define PV_SYN OPT_BUF(BV_SYN)
166#endif
167#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000168# define PV_SPC OPT_BUF(BV_SPC)
169# define PV_SPF OPT_BUF(BV_SPF)
170# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000171#endif
172#define PV_STS OPT_BUF(BV_STS)
173#ifdef FEAT_SEARCHPATH
174# define PV_SUA OPT_BUF(BV_SUA)
175#endif
176#define PV_SW OPT_BUF(BV_SW)
177#define PV_SWF OPT_BUF(BV_SWF)
178#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
Bram Moolenaar0f6562e2015-11-24 18:48:14 +0100179#define PV_TC OPT_BOTH(OPT_BUF(BV_TC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000180#define PV_TS OPT_BUF(BV_TS)
181#define PV_TW OPT_BUF(BV_TW)
182#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200183#ifdef FEAT_PERSISTENT_UNDO
184# define PV_UDF OPT_BUF(BV_UDF)
185#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000186#define PV_WM OPT_BUF(BV_WM)
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 Moolenaar5e3cb7e2006-02-27 23:58:35 +0000200#ifdef FEAT_DIFF
201# define PV_DIFF OPT_WIN(WV_DIFF)
202#endif
203#ifdef FEAT_FOLDING
204# define PV_FDC OPT_WIN(WV_FDC)
205# define PV_FEN OPT_WIN(WV_FEN)
206# define PV_FDI OPT_WIN(WV_FDI)
207# define PV_FDL OPT_WIN(WV_FDL)
208# define PV_FDM OPT_WIN(WV_FDM)
209# define PV_FML OPT_WIN(WV_FML)
210# define PV_FDN OPT_WIN(WV_FDN)
211# ifdef FEAT_EVAL
212# define PV_FDE OPT_WIN(WV_FDE)
213# define PV_FDT OPT_WIN(WV_FDT)
214# endif
215# define PV_FMR OPT_WIN(WV_FMR)
216#endif
217#ifdef FEAT_LINEBREAK
218# define PV_LBR OPT_WIN(WV_LBR)
219#endif
220#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200221#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000222#ifdef FEAT_LINEBREAK
223# define PV_NUW OPT_WIN(WV_NUW)
224#endif
Bram Moolenaar4033c552017-09-16 20:54:51 +0200225#if defined(FEAT_QUICKFIX)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000226# define PV_PVW OPT_WIN(WV_PVW)
227#endif
228#ifdef FEAT_RIGHTLEFT
229# define PV_RL OPT_WIN(WV_RL)
230# define PV_RLC OPT_WIN(WV_RLC)
231#endif
232#ifdef FEAT_SCROLLBIND
233# define PV_SCBIND OPT_WIN(WV_SCBIND)
234#endif
235#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000236#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000237# define PV_SPELL OPT_WIN(WV_SPELL)
238#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000239#ifdef FEAT_SYN_HL
240# define PV_CUC OPT_WIN(WV_CUC)
241# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200242# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000243#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000244#ifdef FEAT_STL_OPT
245# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
246#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100247#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000248# define PV_WFH OPT_WIN(WV_WFH)
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000249# define PV_WFW OPT_WIN(WV_WFW)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000250#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200251#ifdef FEAT_CURSORBIND
252# define PV_CRBIND OPT_WIN(WV_CRBIND)
253#endif
254#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200255# define PV_COCU OPT_WIN(WV_COCU)
256# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200257#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200258#ifdef FEAT_TERMINAL
Bram Moolenaar1b0675c2017-07-15 14:04:01 +0200259# define PV_TK OPT_WIN(WV_TK)
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200260# define PV_TMS OPT_WIN(WV_TMS)
261#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;
285#ifdef FEAT_MBYTE
286static int p_bomb;
287#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000288static char_u *p_bh;
289static char_u *p_bt;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000290static int p_bl;
291static int p_ci;
292#ifdef FEAT_CINDENT
293static int p_cin;
294static char_u *p_cink;
295static char_u *p_cino;
296#endif
297#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
298static char_u *p_cinw;
299#endif
300#ifdef FEAT_COMMENTS
301static char_u *p_com;
302#endif
303#ifdef FEAT_FOLDING
304static char_u *p_cms;
305#endif
306#ifdef FEAT_INS_EXPAND
307static char_u *p_cpt;
308#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000309#ifdef FEAT_COMPL_FUNC
310static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000311static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000312#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000313static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200314static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000315static int p_et;
316#ifdef FEAT_MBYTE
317static char_u *p_fenc;
318#endif
319static char_u *p_ff;
320static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000321static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000322#ifdef FEAT_AUTOCMD
323static char_u *p_ft;
324#endif
325static long p_iminsert;
326static long p_imsearch;
327#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
328static char_u *p_inex;
329#endif
330#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
331static char_u *p_inde;
332static char_u *p_indk;
333#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000334#if defined(FEAT_EVAL)
335static char_u *p_fex;
336#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000337static int p_inf;
338static char_u *p_isk;
339#ifdef FEAT_CRYPT
340static char_u *p_key;
341#endif
342#ifdef FEAT_LISP
343static int p_lisp;
344#endif
345static int p_ml;
346static int p_ma;
347static int p_mod;
348static char_u *p_mps;
349static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000350static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000351#ifdef FEAT_TEXTOBJ
352static char_u *p_qe;
353#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000354static int p_ro;
355#ifdef FEAT_SMARTINDENT
356static int p_si;
357#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000358static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000359static long p_sts;
360#if defined(FEAT_SEARCHPATH)
361static char_u *p_sua;
362#endif
363static long p_sw;
364static int p_swf;
365#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000366static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000367static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000368#endif
369#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000370static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000371static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000372static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000373#endif
374static long p_ts;
375static long p_tw;
376static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200377#ifdef FEAT_PERSISTENT_UNDO
378static int p_udf;
379#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000380static long p_wm;
381#ifdef FEAT_KEYMAP
382static char_u *p_keymap;
383#endif
384
385/* Saved values for when 'bin' is set. */
386static int p_et_nobin;
387static int p_ml_nobin;
388static long p_tw_nobin;
389static long p_wm_nobin;
390
391/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200392static int p_ai_nopaste;
393static int p_et_nopaste;
394static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000395static long p_tw_nopaste;
396static long p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000397
398struct vimoption
399{
400 char *fullname; /* full option name */
401 char *shortname; /* permissible abbreviation */
402 long_u flags; /* see below */
403 char_u *var; /* global option: pointer to variable;
404 * window-local option: VAR_WIN;
405 * buffer-local option: global value */
406 idopt_T indir; /* global option: PV_NONE;
407 * local option: indirect option index */
408 char_u *def_val[2]; /* default values for variable (vi and vim) */
409#ifdef FEAT_EVAL
410 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000411# define SCRIPTID_INIT , 0
412#else
413# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000414#endif
415};
416
417#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
418#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
419
420/*
421 * Flags
422 */
423#define P_BOOL 0x01 /* the option is boolean */
424#define P_NUM 0x02 /* the option is numeric */
425#define P_STRING 0x04 /* the option is a string */
426#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000427 must use free_string_option() when
428 assigning new value. Not set if default is
429 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000430#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
431 never be used for local or hidden options! */
432#define P_NODEFAULT 0x40 /* don't set to default value */
433#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
434 use vim_free() when assigning new value */
435#define P_WAS_SET 0x100 /* option has been set/reset */
436#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
437#define P_VI_DEF 0x400 /* Use Vi default for Vim */
438#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
439
440 /* when option changed, what to display: */
441#define P_RSTAT 0x1000 /* redraw status lines */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100442#define P_RWIN 0x2000 /* redraw current window and recompute text */
443#define P_RBUF 0x4000 /* redraw current buffer and recompute text */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000444#define P_RALL 0x6000 /* redraw all windows */
445#define P_RCLR 0x7000 /* clear and redraw all */
446
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200447#define P_COMMA 0x8000 /* comma separated list */
448#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
449 * commas */
450#define P_NODUP 0x20000L /* don't allow duplicate strings */
451#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000452
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200453#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
454#define P_GETTEXT 0x100000L /* expand default value with _() */
455#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
456#define P_NFNAME 0x400000L /* only normal file name chars allowed */
457#define P_INSECURE 0x800000L /* option was set from a modeline */
458#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7554da42016-11-25 22:04:13 +0100459 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200460#define P_NO_ML 0x2000000L /* not allowed in modeline */
461#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200462 * there is a redraw flag */
Bram Moolenaar7554da42016-11-25 22:04:13 +0100463#define P_NDNAME 0x8000000L /* only normal dir name chars allowed */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100464#define P_RWINONLY 0x10000000L /* only redraw current window */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000465
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000466#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
467
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000468/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
469 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100470#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000471# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000472#else
473# define ISP_LATIN1 (char_u *)"@,161-255"
474#endif
475
Bram Moolenaar05fbfdc2017-08-14 22:35:08 +0200476# 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 +0000477
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +0100478/* Default python version for pyx* commands */
479#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
480# define DEFAULT_PYTHON_VER 0
481#elif defined(FEAT_PYTHON3)
482# define DEFAULT_PYTHON_VER 3
483#elif defined(FEAT_PYTHON)
484# define DEFAULT_PYTHON_VER 2
485#else
486# define DEFAULT_PYTHON_VER 0
487#endif
488
Bram Moolenaar071d4272004-06-13 20:20:40 +0000489/*
490 * options[] is initialized here.
491 * The order of the options MUST be alphabetic for ":set all" and findoption().
492 * All option names MUST start with a lowercase letter (for findoption()).
493 * Exception: "t_" options are at the end.
494 * The options with a NULL variable are 'hidden': a set command for them is
495 * ignored and they are not printed.
496 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100497static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000498{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200499 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000500#ifdef FEAT_RIGHTLEFT
501 (char_u *)&p_aleph, PV_NONE,
502#else
503 (char_u *)NULL, PV_NONE,
504#endif
505 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100506#if (defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000507 (char_u *)128L,
508#else
509 (char_u *)224L,
510#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000511 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000512 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
513#if defined(FEAT_GUI) && defined(MACOS_X)
514 (char_u *)&p_antialias, PV_NONE,
515 {(char_u *)FALSE, (char_u *)FALSE}
516#else
517 (char_u *)NULL, PV_NONE,
518 {(char_u *)FALSE, (char_u *)FALSE}
519#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000520 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200521 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000522#ifdef FEAT_ARABIC
523 (char_u *)VAR_WIN, PV_ARAB,
524#else
525 (char_u *)NULL, PV_NONE,
526#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000527 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000528 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
529#ifdef FEAT_ARABIC
530 (char_u *)&p_arshape, PV_NONE,
531#else
532 (char_u *)NULL, PV_NONE,
533#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000534 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000535 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
536#ifdef FEAT_RIGHTLEFT
537 (char_u *)&p_ari, PV_NONE,
538#else
539 (char_u *)NULL, PV_NONE,
540#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000541 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000542 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
543#ifdef FEAT_FKMAP
544 (char_u *)&p_altkeymap, PV_NONE,
545#else
546 (char_u *)NULL, PV_NONE,
547#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000548 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000549 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
550#if defined(FEAT_MBYTE)
551 (char_u *)&p_ambw, PV_NONE,
552 {(char_u *)"single", (char_u *)0L}
553#else
554 (char_u *)NULL, PV_NONE,
555 {(char_u *)0L, (char_u *)0L}
556#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000557 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000558 {"autochdir", "acd", P_BOOL|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100559#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000560 (char_u *)&p_acd, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100561 {(char_u *)FALSE, (char_u *)0L}
562#else
563 (char_u *)NULL, PV_NONE,
564 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000565#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +0100566 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000567 {"autoindent", "ai", P_BOOL|P_VI_DEF,
568 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000569 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000570 {"autoprint", "ap", P_BOOL|P_VI_DEF,
571 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000572 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000573 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000574 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000575 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000576 {"autowrite", "aw", P_BOOL|P_VI_DEF,
577 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000578 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000579 {"autowriteall","awa", P_BOOL|P_VI_DEF,
580 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000581 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000582 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
583 (char_u *)&p_bg, PV_NONE,
584 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100585#if (defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000586 (char_u *)"dark",
587#else
588 (char_u *)"light",
589#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000590 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200591 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000592 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000593 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000594 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
595 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000596 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200597 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200598 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000599#ifdef UNIX
600 {(char_u *)"yes", (char_u *)"auto"}
601#else
602 {(char_u *)"auto", (char_u *)"auto"}
603#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000604 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200605 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
606 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000607 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000608 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000609 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000610 (char_u *)&p_bex, PV_NONE,
611 {
612#ifdef VMS
613 (char_u *)"_",
614#else
615 (char_u *)"~",
616#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000617 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200618 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000619#ifdef FEAT_WILDIGN
620 (char_u *)&p_bsk, PV_NONE,
621 {(char_u *)"", (char_u *)0L}
622#else
623 (char_u *)NULL, PV_NONE,
624 {(char_u *)0L, (char_u *)0L}
625#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000626 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000627 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100628#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000629 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100630 {(char_u *)600L, (char_u *)0L}
631#else
632 (char_u *)NULL, PV_NONE,
633 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000634#endif
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100635 SCRIPTID_INIT},
636 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
637#ifdef FEAT_BEVAL
638 (char_u *)&p_beval, PV_NONE,
639 {(char_u *)FALSE, (char_u *)0L}
640#else
641 (char_u *)NULL, PV_NONE,
642 {(char_u *)0L, (char_u *)0L}
643#endif
644 SCRIPTID_INIT},
645 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
646#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
647 (char_u *)&p_bexpr, PV_BEXPR,
648 {(char_u *)"", (char_u *)0L}
649#else
650 (char_u *)NULL, PV_NONE,
651 {(char_u *)0L, (char_u *)0L}
652#endif
653 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000654 {"beautify", "bf", P_BOOL|P_VI_DEF,
655 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000656 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200657 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
658 (char_u *)&p_bo, PV_NONE,
659 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000660 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
661 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000662 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000663 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000664 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000665 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000666 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
667#ifdef FEAT_MBYTE
668 (char_u *)&p_bomb, PV_BOMB,
669#else
670 (char_u *)NULL, PV_NONE,
671#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000672 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000673 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
674#ifdef FEAT_LINEBREAK
675 (char_u *)&p_breakat, PV_NONE,
676 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
677#else
678 (char_u *)NULL, PV_NONE,
679 {(char_u *)0L, (char_u *)0L}
680#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000681 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200682 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
683#ifdef FEAT_LINEBREAK
684 (char_u *)VAR_WIN, PV_BRI,
685 {(char_u *)FALSE, (char_u *)0L}
686#else
687 (char_u *)NULL, PV_NONE,
688 {(char_u *)0L, (char_u *)0L}
689#endif
690 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200691 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
692 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200693#ifdef FEAT_LINEBREAK
694 (char_u *)VAR_WIN, PV_BRIOPT,
695 {(char_u *)"", (char_u *)NULL}
696#else
697 (char_u *)NULL, PV_NONE,
698 {(char_u *)"", (char_u *)NULL}
699#endif
700 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000701 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
702#ifdef FEAT_BROWSE
703 (char_u *)&p_bsdir, PV_NONE,
704 {(char_u *)"last", (char_u *)0L}
705#else
706 (char_u *)NULL, PV_NONE,
707 {(char_u *)0L, (char_u *)0L}
708#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000709 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000710 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000711 (char_u *)&p_bh, PV_BH,
712 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000713 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000714 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
715 (char_u *)&p_bl, PV_BL,
716 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000717 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000718 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000719 (char_u *)&p_bt, PV_BT,
720 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000721 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200722 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000723#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000724 (char_u *)&p_cmp, PV_NONE,
725 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000726#else
727 (char_u *)NULL, PV_NONE,
728 {(char_u *)0L, (char_u *)0L}
729#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000730 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000731 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
732#ifdef FEAT_SEARCHPATH
733 (char_u *)&p_cdpath, PV_NONE,
734 {(char_u *)",,", (char_u *)0L}
735#else
736 (char_u *)NULL, PV_NONE,
737 {(char_u *)0L, (char_u *)0L}
738#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000739 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000740 {"cedit", NULL, P_STRING,
741#ifdef FEAT_CMDWIN
742 (char_u *)&p_cedit, PV_NONE,
743 {(char_u *)"", (char_u *)CTRL_F_STR}
744#else
745 (char_u *)NULL, PV_NONE,
746 {(char_u *)0L, (char_u *)0L}
747#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000748 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000749 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
750#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
751 (char_u *)&p_ccv, PV_NONE,
752 {(char_u *)"", (char_u *)0L}
753#else
754 (char_u *)NULL, PV_NONE,
755 {(char_u *)0L, (char_u *)0L}
756#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000757 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000758 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
759#ifdef FEAT_CINDENT
760 (char_u *)&p_cin, PV_CIN,
761#else
762 (char_u *)NULL, PV_NONE,
763#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000764 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200765 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000766#ifdef FEAT_CINDENT
767 (char_u *)&p_cink, PV_CINK,
768 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
769#else
770 (char_u *)NULL, PV_NONE,
771 {(char_u *)0L, (char_u *)0L}
772#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000773 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200774 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000775#ifdef FEAT_CINDENT
776 (char_u *)&p_cino, PV_CINO,
777#else
778 (char_u *)NULL, PV_NONE,
779#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000780 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200781 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000782#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
783 (char_u *)&p_cinw, PV_CINW,
784 {(char_u *)"if,else,while,do,for,switch",
785 (char_u *)0L}
786#else
787 (char_u *)NULL, PV_NONE,
788 {(char_u *)0L, (char_u *)0L}
789#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000790 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200791 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000792#ifdef FEAT_CLIPBOARD
793 (char_u *)&p_cb, PV_NONE,
794# ifdef FEAT_XCLIPBOARD
795 {(char_u *)"autoselect,exclude:cons\\|linux",
796 (char_u *)0L}
797# else
798 {(char_u *)"", (char_u *)0L}
799# endif
800#else
801 (char_u *)NULL, PV_NONE,
802 {(char_u *)"", (char_u *)0L}
803#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000804 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000805 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
806 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000807 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000808 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
809#ifdef FEAT_CMDWIN
810 (char_u *)&p_cwh, PV_NONE,
811#else
812 (char_u *)NULL, PV_NONE,
813#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000814 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200815 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200816#ifdef FEAT_SYN_HL
817 (char_u *)VAR_WIN, PV_CC,
818#else
819 (char_u *)NULL, PV_NONE,
820#endif
821 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000822 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
823 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000824 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200825 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
826 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000827#ifdef FEAT_COMMENTS
828 (char_u *)&p_com, PV_COM,
829 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
830 (char_u *)0L}
831#else
832 (char_u *)NULL, PV_NONE,
833 {(char_u *)0L, (char_u *)0L}
834#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000835 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200836 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000837#ifdef FEAT_FOLDING
838 (char_u *)&p_cms, PV_CMS,
839 {(char_u *)"/*%s*/", (char_u *)0L}
840#else
841 (char_u *)NULL, PV_NONE,
842 {(char_u *)0L, (char_u *)0L}
843#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000844 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000845 /* P_PRI_MKRC isn't needed here, optval_default()
846 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000847 {"compatible", "cp", P_BOOL|P_RALL,
848 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000849 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200850 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000851#ifdef FEAT_INS_EXPAND
852 (char_u *)&p_cpt, PV_CPT,
853 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
854#else
855 (char_u *)NULL, PV_NONE,
856 {(char_u *)0L, (char_u *)0L}
857#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000858 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200859 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200860#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200861 (char_u *)VAR_WIN, PV_COCU,
862 {(char_u *)"", (char_u *)NULL}
863#else
864 (char_u *)NULL, PV_NONE,
865 {(char_u *)NULL, (char_u *)0L}
866#endif
867 SCRIPTID_INIT},
868 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
869#ifdef FEAT_CONCEAL
870 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200871#else
872 (char_u *)NULL, PV_NONE,
873#endif
874 {(char_u *)0L, (char_u *)0L}
875 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000876 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
877#ifdef FEAT_COMPL_FUNC
878 (char_u *)&p_cfu, PV_CFU,
879 {(char_u *)"", (char_u *)0L}
880#else
881 (char_u *)NULL, PV_NONE,
882 {(char_u *)0L, (char_u *)0L}
883#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000884 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200885 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000886#ifdef FEAT_INS_EXPAND
887 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000888 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000889#else
890 (char_u *)NULL, PV_NONE,
891 {(char_u *)0L, (char_u *)0L}
892#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000893 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000894 {"confirm", "cf", P_BOOL|P_VI_DEF,
895#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
896 (char_u *)&p_confirm, PV_NONE,
897#else
898 (char_u *)NULL, PV_NONE,
899#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000900 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000901 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000902 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000903 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000904 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
905 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000906 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000907 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
908 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000909 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
910 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200911 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200912#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200913 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200914 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200915#else
916 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200917 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200918#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200919 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000920 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
921#ifdef FEAT_CSCOPE
922 (char_u *)&p_cspc, PV_NONE,
923#else
924 (char_u *)NULL, PV_NONE,
925#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000926 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000927 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
928#ifdef FEAT_CSCOPE
929 (char_u *)&p_csprg, PV_NONE,
930 {(char_u *)"cscope", (char_u *)0L}
931#else
932 (char_u *)NULL, PV_NONE,
933 {(char_u *)0L, (char_u *)0L}
934#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000935 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200936 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000937#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
938 (char_u *)&p_csqf, PV_NONE,
939 {(char_u *)"", (char_u *)0L}
940#else
941 (char_u *)NULL, PV_NONE,
942 {(char_u *)0L, (char_u *)0L}
943#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000944 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200945 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
946#ifdef FEAT_CSCOPE
947 (char_u *)&p_csre, PV_NONE,
948#else
949 (char_u *)NULL, PV_NONE,
950#endif
951 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000952 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
953#ifdef FEAT_CSCOPE
954 (char_u *)&p_cst, PV_NONE,
955#else
956 (char_u *)NULL, PV_NONE,
957#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000958 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000959 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
960#ifdef FEAT_CSCOPE
961 (char_u *)&p_csto, PV_NONE,
962#else
963 (char_u *)NULL, PV_NONE,
964#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000965 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000966 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
967#ifdef FEAT_CSCOPE
968 (char_u *)&p_csverbose, PV_NONE,
969#else
970 (char_u *)NULL, PV_NONE,
971#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000972 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200973 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
974#ifdef FEAT_CURSORBIND
975 (char_u *)VAR_WIN, PV_CRBIND,
976#else
977 (char_u *)NULL, PV_NONE,
978#endif
979 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000980 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
981#ifdef FEAT_SYN_HL
982 (char_u *)VAR_WIN, PV_CUC,
983#else
984 (char_u *)NULL, PV_NONE,
985#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000986 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100987 {"cursorline", "cul", 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_CUL,
990#else
991 (char_u *)NULL, PV_NONE,
992#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000993 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000994 {"debug", NULL, P_STRING|P_VI_DEF,
995 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000996 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200997 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000998#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000999 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001000 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001001#else
1002 (char_u *)NULL, PV_NONE,
1003 {(char_u *)NULL, (char_u *)0L}
1004#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001005 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001006 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
1007#ifdef FEAT_MBYTE
1008 (char_u *)&p_deco, PV_NONE,
1009#else
1010 (char_u *)NULL, PV_NONE,
1011#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001012 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001013 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001014#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001015 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001016#else
1017 (char_u *)NULL, PV_NONE,
1018#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001019 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001020 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1021#ifdef FEAT_DIFF
1022 (char_u *)VAR_WIN, PV_DIFF,
1023#else
1024 (char_u *)NULL, PV_NONE,
1025#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001026 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001027 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001028#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1029 (char_u *)&p_dex, PV_NONE,
1030 {(char_u *)"", (char_u *)0L}
1031#else
1032 (char_u *)NULL, PV_NONE,
1033 {(char_u *)0L, (char_u *)0L}
1034#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001035 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001036 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1037 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001038#ifdef FEAT_DIFF
1039 (char_u *)&p_dip, PV_NONE,
1040 {(char_u *)"filler", (char_u *)NULL}
1041#else
1042 (char_u *)NULL, PV_NONE,
1043 {(char_u *)"", (char_u *)NULL}
1044#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001045 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001046 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1047#ifdef FEAT_DIGRAPHS
1048 (char_u *)&p_dg, PV_NONE,
1049#else
1050 (char_u *)NULL, PV_NONE,
1051#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001052 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001053 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1054 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001055 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001056 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001057 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001058 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001059 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001060 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001061 (char_u *)&p_ead, PV_NONE,
1062 {(char_u *)"both", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001063 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001064 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1065 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001066 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001067 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
1068#if defined(FEAT_MBYTE)
1069 (char_u *)&p_emoji, PV_NONE,
1070 {(char_u *)TRUE, (char_u *)0L}
1071#else
1072 (char_u *)NULL, PV_NONE,
1073 {(char_u *)0L, (char_u *)0L}
1074#endif
1075 SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001076 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001077#ifdef FEAT_MBYTE
1078 (char_u *)&p_enc, PV_NONE,
1079 {(char_u *)ENC_DFLT, (char_u *)0L}
1080#else
1081 (char_u *)NULL, PV_NONE,
1082 {(char_u *)0L, (char_u *)0L}
1083#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001084 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001085 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1086 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001087 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001088 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1089 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001090 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001091 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001092 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001093 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001094 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1095 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001096 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001097 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1098#ifdef FEAT_QUICKFIX
1099 (char_u *)&p_ef, PV_NONE,
1100 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1101#else
1102 (char_u *)NULL, PV_NONE,
1103 {(char_u *)NULL, (char_u *)0L}
1104#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001105 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001106 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001107#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001108 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001109 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001110#else
1111 (char_u *)NULL, PV_NONE,
1112 {(char_u *)NULL, (char_u *)0L}
1113#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001114 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001115 {"esckeys", "ek", P_BOOL|P_VIM,
1116 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001117 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001118 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001119#ifdef FEAT_AUTOCMD
1120 (char_u *)&p_ei, PV_NONE,
1121#else
1122 (char_u *)NULL, PV_NONE,
1123#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001124 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001125 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1126 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001127 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001128 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1129 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001130 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001131 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1132 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001133#ifdef FEAT_MBYTE
1134 (char_u *)&p_fenc, PV_FENC,
1135 {(char_u *)"", (char_u *)0L}
1136#else
1137 (char_u *)NULL, PV_NONE,
1138 {(char_u *)0L, (char_u *)0L}
1139#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001140 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001141 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001142#ifdef FEAT_MBYTE
1143 (char_u *)&p_fencs, PV_NONE,
1144 {(char_u *)"ucs-bom", (char_u *)0L}
1145#else
1146 (char_u *)NULL, PV_NONE,
1147 {(char_u *)0L, (char_u *)0L}
1148#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001149 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001150 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1151 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001152 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001153 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001154 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001155 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001156 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1157 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001158 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1159 (char_u *)&p_fic, PV_NONE,
1160 {
1161#ifdef CASE_INSENSITIVE_FILENAME
1162 (char_u *)TRUE,
1163#else
1164 (char_u *)FALSE,
1165#endif
1166 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001167 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001168#ifdef FEAT_AUTOCMD
1169 (char_u *)&p_ft, PV_FT,
1170 {(char_u *)"", (char_u *)0L}
1171#else
1172 (char_u *)NULL, PV_NONE,
1173 {(char_u *)0L, (char_u *)0L}
1174#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001175 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001176 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001177 (char_u *)&p_fcs, PV_NONE,
1178 {(char_u *)"vert:|,fold:-", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001179 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001180 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1181 (char_u *)&p_fixeol, PV_FIXEOL,
1182 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001183 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1184#ifdef FEAT_FKMAP
1185 (char_u *)&p_fkmap, PV_NONE,
1186#else
1187 (char_u *)NULL, PV_NONE,
1188#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001189 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001190 {"flash", "fl", P_BOOL|P_VI_DEF,
1191 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001192 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001193 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001194#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001195 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001196 {(char_u *)"", (char_u *)0L}
1197#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001198 (char_u *)NULL, PV_NONE,
1199 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001200#endif
1201 SCRIPTID_INIT},
1202 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1203#ifdef FEAT_FOLDING
1204 (char_u *)VAR_WIN, PV_FDC,
1205 {(char_u *)FALSE, (char_u *)0L}
1206#else
1207 (char_u *)NULL, PV_NONE,
1208 {(char_u *)NULL, (char_u *)0L}
1209#endif
1210 SCRIPTID_INIT},
1211 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1212#ifdef FEAT_FOLDING
1213 (char_u *)VAR_WIN, PV_FEN,
1214 {(char_u *)TRUE, (char_u *)0L}
1215#else
1216 (char_u *)NULL, PV_NONE,
1217 {(char_u *)NULL, (char_u *)0L}
1218#endif
1219 SCRIPTID_INIT},
1220 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1221#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1222 (char_u *)VAR_WIN, PV_FDE,
1223 {(char_u *)"0", (char_u *)NULL}
1224#else
1225 (char_u *)NULL, PV_NONE,
1226 {(char_u *)NULL, (char_u *)0L}
1227#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001228 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001229 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001230#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001231 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001232 {(char_u *)"#", (char_u *)NULL}
1233#else
1234 (char_u *)NULL, PV_NONE,
1235 {(char_u *)NULL, (char_u *)0L}
1236#endif
1237 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001238 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001239#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001240 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001241 {(char_u *)0L, (char_u *)0L}
1242#else
1243 (char_u *)NULL, PV_NONE,
1244 {(char_u *)NULL, (char_u *)0L}
1245#endif
1246 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001247 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001248#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001249 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001250 {(char_u *)-1L, (char_u *)0L}
1251#else
1252 (char_u *)NULL, PV_NONE,
1253 {(char_u *)NULL, (char_u *)0L}
1254#endif
1255 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001256 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001257 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001258#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001259 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001260 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001261#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001262 (char_u *)NULL, PV_NONE,
1263 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001264#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001265 SCRIPTID_INIT},
1266 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1267#ifdef FEAT_FOLDING
1268 (char_u *)VAR_WIN, PV_FDM,
1269 {(char_u *)"manual", (char_u *)NULL}
1270#else
1271 (char_u *)NULL, PV_NONE,
1272 {(char_u *)NULL, (char_u *)0L}
1273#endif
1274 SCRIPTID_INIT},
1275 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1276#ifdef FEAT_FOLDING
1277 (char_u *)VAR_WIN, PV_FML,
1278 {(char_u *)1L, (char_u *)0L}
1279#else
1280 (char_u *)NULL, PV_NONE,
1281 {(char_u *)NULL, (char_u *)0L}
1282#endif
1283 SCRIPTID_INIT},
1284 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1285#ifdef FEAT_FOLDING
1286 (char_u *)VAR_WIN, PV_FDN,
1287 {(char_u *)20L, (char_u *)0L}
1288#else
1289 (char_u *)NULL, PV_NONE,
1290 {(char_u *)NULL, (char_u *)0L}
1291#endif
1292 SCRIPTID_INIT},
1293 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1294#ifdef FEAT_FOLDING
1295 (char_u *)&p_fdo, PV_NONE,
1296 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1297 (char_u *)0L}
1298#else
1299 (char_u *)NULL, PV_NONE,
1300 {(char_u *)NULL, (char_u *)0L}
1301#endif
1302 SCRIPTID_INIT},
1303 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1304#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1305 (char_u *)VAR_WIN, PV_FDT,
1306 {(char_u *)"foldtext()", (char_u *)NULL}
1307#else
1308 (char_u *)NULL, PV_NONE,
1309 {(char_u *)NULL, (char_u *)0L}
1310#endif
1311 SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001312 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001313#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001314 (char_u *)&p_fex, PV_FEX,
1315 {(char_u *)"", (char_u *)0L}
1316#else
1317 (char_u *)NULL, PV_NONE,
1318 {(char_u *)0L, (char_u *)0L}
1319#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001320 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001321 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1322 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001323 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1324 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001325 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1326 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001327 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1328 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001329 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001330 (char_u *)&p_fp, PV_FP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001331 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001332 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1333#ifdef HAVE_FSYNC
1334 (char_u *)&p_fs, PV_NONE,
1335 {(char_u *)TRUE, (char_u *)0L}
1336#else
1337 (char_u *)NULL, PV_NONE,
1338 {(char_u *)FALSE, (char_u *)0L}
1339#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001340 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001341 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1342 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001343 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001344 {"graphic", "gr", P_BOOL|P_VI_DEF,
1345 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001346 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001347 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001348#ifdef FEAT_QUICKFIX
1349 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001350 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001351#else
1352 (char_u *)NULL, PV_NONE,
1353 {(char_u *)NULL, (char_u *)0L}
1354#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001355 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001356 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1357#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001358 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001359 {
1360# ifdef WIN3264
1361 /* may be changed to "grep -n" in os_win32.c */
1362 (char_u *)"findstr /n",
1363# else
1364# ifdef UNIX
1365 /* Add an extra file name so that grep will always
1366 * insert a file name in the match line. */
1367 (char_u *)"grep -n $* /dev/null",
1368# else
1369# ifdef VMS
1370 (char_u *)"SEARCH/NUMBERS ",
1371# else
1372 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001373# endif
1374# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001375# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001376 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001377#else
1378 (char_u *)NULL, PV_NONE,
1379 {(char_u *)NULL, (char_u *)0L}
1380#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001381 SCRIPTID_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001382 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001383#ifdef CURSOR_SHAPE
1384 (char_u *)&p_guicursor, PV_NONE,
1385 {
1386# ifdef FEAT_GUI
1387 (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 +01001388# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001389 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1390# endif
1391 (char_u *)0L}
1392#else
1393 (char_u *)NULL, PV_NONE,
1394 {(char_u *)NULL, (char_u *)0L}
1395#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001396 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001397 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001398#ifdef FEAT_GUI
1399 (char_u *)&p_guifont, PV_NONE,
1400 {(char_u *)"", (char_u *)0L}
1401#else
1402 (char_u *)NULL, PV_NONE,
1403 {(char_u *)NULL, (char_u *)0L}
1404#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001405 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001406 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001407#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1408 (char_u *)&p_guifontset, PV_NONE,
1409 {(char_u *)"", (char_u *)0L}
1410#else
1411 (char_u *)NULL, PV_NONE,
1412 {(char_u *)NULL, (char_u *)0L}
1413#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001414 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001415 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001416#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1417 (char_u *)&p_guifontwide, PV_NONE,
1418 {(char_u *)"", (char_u *)0L}
1419#else
1420 (char_u *)NULL, PV_NONE,
1421 {(char_u *)NULL, (char_u *)0L}
1422#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001423 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001424 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001425#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001426 (char_u *)&p_ghr, PV_NONE,
1427#else
1428 (char_u *)NULL, PV_NONE,
1429#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001430 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001431 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001432#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001433 (char_u *)&p_go, PV_NONE,
1434# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001435 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001436# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001437 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001438# endif
1439#else
1440 (char_u *)NULL, PV_NONE,
1441 {(char_u *)NULL, (char_u *)0L}
1442#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001443 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001444 {"guipty", NULL, P_BOOL|P_VI_DEF,
1445#if defined(FEAT_GUI)
1446 (char_u *)&p_guipty, PV_NONE,
1447#else
1448 (char_u *)NULL, PV_NONE,
1449#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001450 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001451 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001452#if defined(FEAT_GUI_TABLINE)
1453 (char_u *)&p_gtl, PV_NONE,
1454 {(char_u *)"", (char_u *)0L}
1455#else
1456 (char_u *)NULL, PV_NONE,
1457 {(char_u *)NULL, (char_u *)0L}
1458#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001459 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001460 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001461#if defined(FEAT_GUI_TABLINE)
1462 (char_u *)&p_gtt, PV_NONE,
1463 {(char_u *)"", (char_u *)0L}
1464#else
1465 (char_u *)NULL, PV_NONE,
1466 {(char_u *)NULL, (char_u *)0L}
1467#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001468 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001469 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1470 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001471 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001472 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1473 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001474 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1475 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001476 {"helpheight", "hh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001477 (char_u *)&p_hh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001478 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001479 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001480#ifdef FEAT_MULTI_LANG
1481 (char_u *)&p_hlg, PV_NONE,
1482 {(char_u *)"", (char_u *)0L}
1483#else
1484 (char_u *)NULL, PV_NONE,
1485 {(char_u *)0L, (char_u *)0L}
1486#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001487 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001488 {"hidden", "hid", P_BOOL|P_VI_DEF,
1489 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001490 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001491 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001492 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001493 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1494 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001495 {"history", "hi", P_NUM|P_VIM,
1496 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001497 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001498 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1499#ifdef FEAT_RIGHTLEFT
1500 (char_u *)&p_hkmap, PV_NONE,
1501#else
1502 (char_u *)NULL, PV_NONE,
1503#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001504 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001505 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1506#ifdef FEAT_RIGHTLEFT
1507 (char_u *)&p_hkmapp, PV_NONE,
1508#else
1509 (char_u *)NULL, PV_NONE,
1510#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001511 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001512 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1513 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001514 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001515 {"icon", NULL, P_BOOL|P_VI_DEF,
1516#ifdef FEAT_TITLE
1517 (char_u *)&p_icon, PV_NONE,
1518#else
1519 (char_u *)NULL, PV_NONE,
1520#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001521 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001522 {"iconstring", NULL, P_STRING|P_VI_DEF,
1523#ifdef FEAT_TITLE
1524 (char_u *)&p_iconstring, PV_NONE,
1525#else
1526 (char_u *)NULL, PV_NONE,
1527#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001528 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001529 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1530 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001531 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001532 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1533# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1534 (char_u *)&p_imaf, PV_NONE,
1535 {(char_u *)"", (char_u *)NULL}
1536# else
1537 (char_u *)NULL, PV_NONE,
1538 {(char_u *)NULL, (char_u *)0L}
1539# endif
1540 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001541 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001542#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001543 (char_u *)&p_imak, PV_NONE,
1544#else
1545 (char_u *)NULL, PV_NONE,
1546#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001547 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001548 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1549#ifdef USE_IM_CONTROL
1550 (char_u *)&p_imcmdline, PV_NONE,
1551#else
1552 (char_u *)NULL, PV_NONE,
1553#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001554 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001555 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1556#ifdef USE_IM_CONTROL
1557 (char_u *)&p_imdisable, PV_NONE,
1558#else
1559 (char_u *)NULL, PV_NONE,
1560#endif
1561#ifdef __sgi
1562 {(char_u *)TRUE, (char_u *)0L}
1563#else
1564 {(char_u *)FALSE, (char_u *)0L}
1565#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001566 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001567 {"iminsert", "imi", P_NUM|P_VI_DEF,
1568 (char_u *)&p_iminsert, PV_IMI,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001569 {(char_u *)B_IMODE_NONE, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001570 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001571 {"imsearch", "ims", P_NUM|P_VI_DEF,
1572 (char_u *)&p_imsearch, PV_IMS,
Bram Moolenaar4cf56bb2017-09-16 15:50:32 +02001573 {(char_u *)B_IMODE_USE_INSERT, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001574 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001575 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001576#if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001577 (char_u *)&p_imsf, PV_NONE,
1578 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001579#else
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001580 (char_u *)NULL, PV_NONE,
1581 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001582#endif
1583 SCRIPTID_INIT},
1584 {"imstyle", "imst", P_NUM|P_VI_DEF|P_SECURE,
1585#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1586 (char_u *)&p_imst, PV_NONE,
1587 {(char_u *)IM_OVER_THE_SPOT, (char_u *)0L}
1588#else
1589 (char_u *)NULL, PV_NONE,
1590 {(char_u *)0L, (char_u *)0L}
1591#endif
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001592 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001593 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1594#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001595 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001596 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1597#else
1598 (char_u *)NULL, PV_NONE,
1599 {(char_u *)0L, (char_u *)0L}
1600#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001601 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001602 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1603#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1604 (char_u *)&p_inex, PV_INEX,
1605 {(char_u *)"", (char_u *)0L}
1606#else
1607 (char_u *)NULL, PV_NONE,
1608 {(char_u *)0L, (char_u *)0L}
1609#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001610 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001611 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1612 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001613 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001614 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1615#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1616 (char_u *)&p_inde, PV_INDE,
1617 {(char_u *)"", (char_u *)0L}
1618#else
1619 (char_u *)NULL, PV_NONE,
1620 {(char_u *)0L, (char_u *)0L}
1621#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001622 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001623 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001624#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1625 (char_u *)&p_indk, PV_INDK,
1626 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1627#else
1628 (char_u *)NULL, PV_NONE,
1629 {(char_u *)0L, (char_u *)0L}
1630#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001631 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001632 {"infercase", "inf", P_BOOL|P_VI_DEF,
1633 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001634 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001635 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1636 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001637 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001638 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1639 (char_u *)&p_isf, PV_NONE,
1640 {
1641#ifdef BACKSLASH_IN_FILENAME
1642 /* Excluded are: & and ^ are special in cmd.exe
1643 * ( and ) are used in text separating fnames */
1644 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1645#else
1646# ifdef AMIGA
1647 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1648# else
1649# ifdef VMS
1650 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1651# else /* UNIX et al. */
1652# ifdef EBCDIC
1653 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1654# else
1655 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1656# endif
1657# endif
1658# endif
1659#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001660 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001661 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1662 (char_u *)&p_isi, PV_NONE,
1663 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001664#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001665 (char_u *)"@,48-57,_,128-167,224-235",
1666#else
1667# ifdef EBCDIC
1668 /* TODO: EBCDIC Check this! @ == isalpha()*/
1669 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1670 "112-120,128,140-142,156,158,172,"
1671 "174,186,191,203-207,219-225,235-239,"
1672 "251-254",
1673# else
1674 (char_u *)"@,48-57,_,192-255",
1675# endif
1676#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001677 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001678 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1679 (char_u *)&p_isk, PV_ISK,
1680 {
1681#ifdef EBCDIC
1682 (char_u *)"@,240-249,_",
1683 /* TODO: EBCDIC Check this! @ == isalpha()*/
1684 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1685 "112-120,128,140-142,156,158,172,"
1686 "174,186,191,203-207,219-225,235-239,"
1687 "251-254",
1688#else
1689 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001690# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001691 (char_u *)"@,48-57,_,128-167,224-235"
1692# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001693 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001694# endif
1695#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001696 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001697 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1698 (char_u *)&p_isp, PV_NONE,
1699 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001700#if defined(MSWIN) || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001701 || defined(VMS)
1702 (char_u *)"@,~-255",
1703#else
1704# ifdef EBCDIC
1705 /* all chars above 63 are printable */
1706 (char_u *)"63-255",
1707# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001708 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001709# endif
1710#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001711 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001712 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1713 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001714 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001715 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1716#ifdef FEAT_CRYPT
1717 (char_u *)&p_key, PV_KEY,
1718 {(char_u *)"", (char_u *)0L}
1719#else
1720 (char_u *)NULL, PV_NONE,
1721 {(char_u *)0L, (char_u *)0L}
1722#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001723 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001724 {"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 +00001725#ifdef FEAT_KEYMAP
1726 (char_u *)&p_keymap, PV_KMAP,
1727 {(char_u *)"", (char_u *)0L}
1728#else
1729 (char_u *)NULL, PV_NONE,
1730 {(char_u *)"", (char_u *)0L}
1731#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001732 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001733 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001734 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001735 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001736 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001737 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001738 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001739#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001740 (char_u *)":help",
1741#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001742# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001743 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001744# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001745# ifdef USEMAN_S
1746 (char_u *)"man -s",
1747# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001748 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001749# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001750# endif
1751#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001752 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001753 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001754#ifdef FEAT_LANGMAP
1755 (char_u *)&p_langmap, PV_NONE,
1756 {(char_u *)"", /* unmatched } */
1757#else
1758 (char_u *)NULL, PV_NONE,
1759 {(char_u *)NULL,
1760#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001761 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001762 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001763#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1764 (char_u *)&p_lm, PV_NONE,
1765#else
1766 (char_u *)NULL, PV_NONE,
1767#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001768 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001769 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1770#ifdef FEAT_LANGMAP
1771 (char_u *)&p_lnr, PV_NONE,
1772#else
1773 (char_u *)NULL, PV_NONE,
1774#endif
1775 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001776 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1777#ifdef FEAT_LANGMAP
1778 (char_u *)&p_lrm, PV_NONE,
1779#else
1780 (char_u *)NULL, PV_NONE,
1781#endif
Bram Moolenaarda9ce2c2016-09-02 19:34:10 +02001782 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001783 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001784 (char_u *)&p_ls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001785 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001786 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1787 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001788 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001789 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1790#ifdef FEAT_LINEBREAK
1791 (char_u *)VAR_WIN, PV_LBR,
1792#else
1793 (char_u *)NULL, PV_NONE,
1794#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001795 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001796 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1797 (char_u *)&Rows, PV_NONE,
1798 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001799#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001800 (char_u *)25L,
1801#else
1802 (char_u *)24L,
1803#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001804 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001805 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1806#ifdef FEAT_GUI
1807 (char_u *)&p_linespace, PV_NONE,
1808#else
1809 (char_u *)NULL, PV_NONE,
1810#endif
1811#ifdef FEAT_GUI_W32
1812 {(char_u *)1L, (char_u *)0L}
1813#else
1814 {(char_u *)0L, (char_u *)0L}
1815#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001816 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001817 {"lisp", NULL, P_BOOL|P_VI_DEF,
1818#ifdef FEAT_LISP
1819 (char_u *)&p_lisp, PV_LISP,
1820#else
1821 (char_u *)NULL, PV_NONE,
1822#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001823 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001824 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001825#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001826 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001827 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1828#else
1829 (char_u *)NULL, PV_NONE,
1830 {(char_u *)"", (char_u *)0L}
1831#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001832 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001833 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1834 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001835 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001836 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001837 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001838 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001839 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1840 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001841 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001842 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001843#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001844 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001845 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001846#else
1847 (char_u *)NULL, PV_NONE,
1848 {(char_u *)"", (char_u *)0L}
1849#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001850 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001851 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001852#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001853 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001854 {(char_u *)TRUE, (char_u *)0L}
1855#else
1856 (char_u *)NULL, PV_NONE,
1857 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001858#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001859 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001860 {"magic", NULL, P_BOOL|P_VI_DEF,
1861 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001862 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001863 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001864#ifdef FEAT_QUICKFIX
1865 (char_u *)&p_mef, PV_NONE,
1866 {(char_u *)"", (char_u *)0L}
1867#else
1868 (char_u *)NULL, PV_NONE,
1869 {(char_u *)NULL, (char_u *)0L}
1870#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001871 SCRIPTID_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001872 {"makeencoding","menc", P_STRING|P_VI_DEF,
1873#ifdef FEAT_MBYTE
1874 (char_u *)&p_menc, PV_MENC,
1875 {(char_u *)"", (char_u *)0L}
1876#else
1877 (char_u *)NULL, PV_NONE,
1878 {(char_u *)0L, (char_u *)0L}
1879#endif
1880 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001881 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1882#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001883 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001884# ifdef VMS
1885 {(char_u *)"MMS", (char_u *)0L}
1886# else
1887 {(char_u *)"make", (char_u *)0L}
1888# endif
1889#else
1890 (char_u *)NULL, PV_NONE,
1891 {(char_u *)NULL, (char_u *)0L}
1892#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001893 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001894 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001895 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001896 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1897 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001898 {"matchtime", "mat", P_NUM|P_VI_DEF,
1899 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001900 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001901 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001902#ifdef FEAT_MBYTE
1903 (char_u *)&p_mco, PV_NONE,
1904#else
1905 (char_u *)NULL, PV_NONE,
1906#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001907 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001908 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1909#ifdef FEAT_EVAL
1910 (char_u *)&p_mfd, PV_NONE,
1911#else
1912 (char_u *)NULL, PV_NONE,
1913#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001914 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001915 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1916 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001917 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001918 {"maxmem", "mm", P_NUM|P_VI_DEF,
1919 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001920 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1921 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001922 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1923 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001924 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001925 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1926 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001927 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1928 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001929 {"menuitems", "mis", P_NUM|P_VI_DEF,
1930#ifdef FEAT_MENU
1931 (char_u *)&p_mis, PV_NONE,
1932#else
1933 (char_u *)NULL, PV_NONE,
1934#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001935 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001936 {"mesg", NULL, P_BOOL|P_VI_DEF,
1937 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001938 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001939 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001940#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001941 (char_u *)&p_msm, PV_NONE,
1942 {(char_u *)"460000,2000,500", (char_u *)0L}
1943#else
1944 (char_u *)NULL, PV_NONE,
1945 {(char_u *)0L, (char_u *)0L}
1946#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001947 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001948 {"modeline", "ml", P_BOOL|P_VIM,
1949 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001950 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001951 {"modelines", "mls", P_NUM|P_VI_DEF,
1952 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001953 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001954 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1955 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001956 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001957 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1958 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001959 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001960 {"more", NULL, P_BOOL|P_VIM,
1961 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001962 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001963 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1964 (char_u *)&p_mouse, PV_NONE,
1965 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001966#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001967 (char_u *)"a",
1968#else
1969 (char_u *)"",
1970#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001971 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001972 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1973#ifdef FEAT_GUI
1974 (char_u *)&p_mousef, PV_NONE,
1975#else
1976 (char_u *)NULL, PV_NONE,
1977#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001978 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001979 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1980#ifdef FEAT_GUI
1981 (char_u *)&p_mh, PV_NONE,
1982#else
1983 (char_u *)NULL, PV_NONE,
1984#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001985 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001986 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1987 (char_u *)&p_mousem, PV_NONE,
1988 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001989#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001990 (char_u *)"popup",
1991#else
1992# if defined(MACOS)
1993 (char_u *)"popup_setpos",
1994# else
1995 (char_u *)"extend",
1996# endif
1997#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001998 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001999 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002000#ifdef FEAT_MOUSESHAPE
2001 (char_u *)&p_mouseshape, PV_NONE,
2002 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
2003#else
2004 (char_u *)NULL, PV_NONE,
2005 {(char_u *)NULL, (char_u *)0L}
2006#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002007 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002008 {"mousetime", "mouset", P_NUM|P_VI_DEF,
2009 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002010 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02002011 {"mzschemedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2012#if defined(DYNAMIC_MZSCHEME)
2013 (char_u *)&p_mzschemedll, PV_NONE,
2014 {(char_u *)DYNAMIC_MZSCH_DLL, (char_u *)0L}
2015#else
2016 (char_u *)NULL, PV_NONE,
2017 {(char_u *)"", (char_u *)0L}
2018#endif
2019 SCRIPTID_INIT},
2020 {"mzschemegcdll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2021#if defined(DYNAMIC_MZSCHEME)
2022 (char_u *)&p_mzschemegcdll, PV_NONE,
2023 {(char_u *)DYNAMIC_MZGC_DLL, (char_u *)0L}
2024#else
2025 (char_u *)NULL, PV_NONE,
2026 {(char_u *)"", (char_u *)0L}
2027#endif
2028 SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00002029 {"mzquantum", "mzq", P_NUM,
2030#ifdef FEAT_MZSCHEME
2031 (char_u *)&p_mzq, PV_NONE,
2032#else
2033 (char_u *)NULL, PV_NONE,
2034#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002035 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002036 {"novice", NULL, P_BOOL|P_VI_DEF,
2037 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002038 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002039 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002040 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01002041 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002042 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002043 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
2044 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002045 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002046 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
2047#ifdef FEAT_LINEBREAK
2048 (char_u *)VAR_WIN, PV_NUW,
2049#else
2050 (char_u *)NULL, PV_NONE,
2051#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002052 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00002053 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00002054#ifdef FEAT_COMPL_FUNC
2055 (char_u *)&p_ofu, PV_OFU,
2056 {(char_u *)"", (char_u *)0L}
2057#else
2058 (char_u *)NULL, PV_NONE,
2059 {(char_u *)0L, (char_u *)0L}
2060#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002061 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002062 {"open", NULL, P_BOOL|P_VI_DEF,
2063 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002064 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002065 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002066#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002067 (char_u *)&p_odev, PV_NONE,
2068#else
2069 (char_u *)NULL, PV_NONE,
2070#endif
2071 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002072 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002073 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2074 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002075 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002076 {"optimize", "opt", P_BOOL|P_VI_DEF,
2077 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002078 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002079 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002080 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02002081 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002082 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2083 |P_SECURE,
2084 (char_u *)&p_pp, PV_NONE,
2085 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2086 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002087 {"paragraphs", "para", P_STRING|P_VI_DEF,
2088 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002089 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002090 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002091 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002092 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002093 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002094 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2095 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002096 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002097 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2098#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2099 (char_u *)&p_pex, PV_NONE,
2100 {(char_u *)"", (char_u *)0L}
2101#else
2102 (char_u *)NULL, PV_NONE,
2103 {(char_u *)0L, (char_u *)0L}
2104#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002105 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002106 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002107 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002108 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002109 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002110 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002111 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002112#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002113 (char_u *)".,,",
2114#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002115 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002116#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002117 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002118 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002119#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002120 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002121 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002122#else
2123 (char_u *)NULL, PV_NONE,
2124 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002125#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002126 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002127 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2128 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002129 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002130 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002131#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002132 (char_u *)&p_pvh, PV_NONE,
2133#else
2134 (char_u *)NULL, PV_NONE,
2135#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002136 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002137 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002138#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002139 (char_u *)VAR_WIN, PV_PVW,
2140#else
2141 (char_u *)NULL, PV_NONE,
2142#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002143 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002144 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002145#ifdef FEAT_PRINTER
2146 (char_u *)&p_pdev, PV_NONE,
2147 {(char_u *)"", (char_u *)0L}
2148#else
2149 (char_u *)NULL, PV_NONE,
2150 {(char_u *)NULL, (char_u *)0L}
2151#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002152 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002153 {"printencoding", "penc", P_STRING|P_VI_DEF,
2154#ifdef FEAT_POSTSCRIPT
2155 (char_u *)&p_penc, PV_NONE,
2156 {(char_u *)"", (char_u *)0L}
2157#else
2158 (char_u *)NULL, PV_NONE,
2159 {(char_u *)NULL, (char_u *)0L}
2160#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002161 SCRIPTID_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002162 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002163#ifdef FEAT_POSTSCRIPT
2164 (char_u *)&p_pexpr, PV_NONE,
2165 {(char_u *)"", (char_u *)0L}
2166#else
2167 (char_u *)NULL, PV_NONE,
2168 {(char_u *)NULL, (char_u *)0L}
2169#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002170 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002171 {"printfont", "pfn", P_STRING|P_VI_DEF,
2172#ifdef FEAT_PRINTER
2173 (char_u *)&p_pfn, PV_NONE,
2174 {
2175# ifdef MSWIN
2176 (char_u *)"Courier_New:h10",
2177# else
2178 (char_u *)"courier",
2179# endif
2180 (char_u *)0L}
2181#else
2182 (char_u *)NULL, PV_NONE,
2183 {(char_u *)NULL, (char_u *)0L}
2184#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002185 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002186 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2187#ifdef FEAT_PRINTER
2188 (char_u *)&p_header, PV_NONE,
Bram Moolenaar0903d562017-08-26 22:30:15 +02002189 /* untranslated to avoid problems when 'encoding'
2190 * is changed */
2191 {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002192#else
2193 (char_u *)NULL, PV_NONE,
2194 {(char_u *)NULL, (char_u *)0L}
2195#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002196 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002197 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2198#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2199 (char_u *)&p_pmcs, PV_NONE,
2200 {(char_u *)"", (char_u *)0L}
2201#else
2202 (char_u *)NULL, PV_NONE,
2203 {(char_u *)NULL, (char_u *)0L}
2204#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002205 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002206 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2207#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2208 (char_u *)&p_pmfn, PV_NONE,
2209 {(char_u *)"", (char_u *)0L}
2210#else
2211 (char_u *)NULL, PV_NONE,
2212 {(char_u *)NULL, (char_u *)0L}
2213#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002214 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002215 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002216#ifdef FEAT_PRINTER
2217 (char_u *)&p_popt, PV_NONE,
2218 {(char_u *)"", (char_u *)0L}
2219#else
2220 (char_u *)NULL, PV_NONE,
2221 {(char_u *)NULL, (char_u *)0L}
2222#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002223 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002224 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002225 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002226 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002227 {"pumheight", "ph", P_NUM|P_VI_DEF,
2228#ifdef FEAT_INS_EXPAND
2229 (char_u *)&p_ph, PV_NONE,
2230#else
2231 (char_u *)NULL, PV_NONE,
2232#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002233 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002234 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002235#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002236 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002237 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002238#else
2239 (char_u *)NULL, PV_NONE,
2240 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002241#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002242 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002243 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002244#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002245 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002246 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002247#else
2248 (char_u *)NULL, PV_NONE,
2249 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002250#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002251 SCRIPTID_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002252 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2253#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2254 (char_u *)&p_pyx, PV_NONE,
2255#else
2256 (char_u *)NULL, PV_NONE,
2257#endif
2258 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
2259 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002260 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2261#ifdef FEAT_TEXTOBJ
2262 (char_u *)&p_qe, PV_QE,
2263 {(char_u *)"\\", (char_u *)0L}
2264#else
2265 (char_u *)NULL, PV_NONE,
2266 {(char_u *)NULL, (char_u *)0L}
2267#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002268 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002269 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2270 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002271 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002272 {"redraw", NULL, P_BOOL|P_VI_DEF,
2273 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002274 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002275 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2276#ifdef FEAT_RELTIME
2277 (char_u *)&p_rdt, PV_NONE,
2278#else
2279 (char_u *)NULL, PV_NONE,
2280#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002281 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002282 {"regexpengine", "re", P_NUM|P_VI_DEF,
2283 (char_u *)&p_re, PV_NONE,
2284 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002285 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2286 (char_u *)VAR_WIN, PV_RNU,
2287 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002288 {"remap", NULL, P_BOOL|P_VI_DEF,
2289 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002290 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002291 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002292#ifdef FEAT_RENDER_OPTIONS
2293 (char_u *)&p_rop, PV_NONE,
2294 {(char_u *)"", (char_u *)0L}
2295#else
2296 (char_u *)NULL, PV_NONE,
2297 {(char_u *)NULL, (char_u *)0L}
2298#endif
2299 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002300 {"report", NULL, P_NUM|P_VI_DEF,
2301 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002302 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002303 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2304#ifdef WIN3264
2305 (char_u *)&p_rs, PV_NONE,
2306#else
2307 (char_u *)NULL, PV_NONE,
2308#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002309 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002310 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2311#ifdef FEAT_RIGHTLEFT
2312 (char_u *)&p_ri, PV_NONE,
2313#else
2314 (char_u *)NULL, PV_NONE,
2315#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002316 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002317 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2318#ifdef FEAT_RIGHTLEFT
2319 (char_u *)VAR_WIN, PV_RL,
2320#else
2321 (char_u *)NULL, PV_NONE,
2322#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002323 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002324 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2325#ifdef FEAT_RIGHTLEFT
2326 (char_u *)VAR_WIN, PV_RLC,
2327 {(char_u *)"search", (char_u *)NULL}
2328#else
2329 (char_u *)NULL, PV_NONE,
2330 {(char_u *)NULL, (char_u *)0L}
2331#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002332 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002333 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002334#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002335 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002336 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002337#else
2338 (char_u *)NULL, PV_NONE,
2339 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002340#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002341 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002342 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2343#ifdef FEAT_CMDL_INFO
2344 (char_u *)&p_ru, PV_NONE,
2345#else
2346 (char_u *)NULL, PV_NONE,
2347#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002348 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002349 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2350#ifdef FEAT_STL_OPT
2351 (char_u *)&p_ruf, PV_NONE,
2352#else
2353 (char_u *)NULL, PV_NONE,
2354#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002355 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002356 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2357 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002358 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002359 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2360 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002361 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2362 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002363 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002364 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2365#ifdef FEAT_SCROLLBIND
2366 (char_u *)VAR_WIN, PV_SCBIND,
2367#else
2368 (char_u *)NULL, PV_NONE,
2369#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002370 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002371 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2372 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002373 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002374 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2375 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002376 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002377 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002378#ifdef FEAT_SCROLLBIND
2379 (char_u *)&p_sbo, PV_NONE,
2380 {(char_u *)"ver,jump", (char_u *)0L}
2381#else
2382 (char_u *)NULL, PV_NONE,
2383 {(char_u *)0L, (char_u *)0L}
2384#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002385 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002386 {"sections", "sect", P_STRING|P_VI_DEF,
2387 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002388 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2389 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002390 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2391 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002392 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002393 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002394 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002395 {(char_u *)"inclusive", (char_u *)0L}
2396 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002397 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002398 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002399 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002400 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002401#ifdef FEAT_SESSION
2402 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002403 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002404 (char_u *)0L}
2405#else
2406 (char_u *)NULL, PV_NONE,
2407 {(char_u *)0L, (char_u *)0L}
2408#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002409 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002410 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2411 (char_u *)&p_sh, PV_NONE,
2412 {
2413#ifdef VMS
2414 (char_u *)"-",
2415#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002416# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002417 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002418# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002419 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002420# endif
2421#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002422 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002423 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2424 (char_u *)&p_shcf, PV_NONE,
2425 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002426#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002427 (char_u *)"/c",
2428#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002429 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002430#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002431 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002432 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2433#ifdef FEAT_QUICKFIX
2434 (char_u *)&p_sp, PV_NONE,
2435 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002436#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002437 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002438#else
2439 (char_u *)">",
2440#endif
2441 (char_u *)0L}
2442#else
2443 (char_u *)NULL, PV_NONE,
2444 {(char_u *)0L, (char_u *)0L}
2445#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002446 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002447 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2448 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002449 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002450 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2451 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002452 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002453 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2454#ifdef BACKSLASH_IN_FILENAME
2455 (char_u *)&p_ssl, PV_NONE,
2456#else
2457 (char_u *)NULL, PV_NONE,
2458#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002459 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002460 {"shelltemp", "stmp", P_BOOL,
2461 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002462 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002463 {"shelltype", "st", P_NUM|P_VI_DEF,
2464#ifdef AMIGA
2465 (char_u *)&p_st, PV_NONE,
2466#else
2467 (char_u *)NULL, PV_NONE,
2468#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002469 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002470 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2471 (char_u *)&p_sxq, PV_NONE,
2472 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002473#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002474 (char_u *)"\"",
2475#else
2476 (char_u *)"",
2477#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002478 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002479 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2480 (char_u *)&p_sxe, PV_NONE,
2481 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002482#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002483 (char_u *)"\"&|<>()@^",
2484#else
2485 (char_u *)"",
2486#endif
2487 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002488 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2489 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002490 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002491 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2492 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002493 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002494 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2495 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002496 {(char_u *)"", (char_u *)"filnxtToO"}
2497 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002498 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002499 (char_u *)&p_sn, PV_SN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002500 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002501 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2502#ifdef FEAT_LINEBREAK
2503 (char_u *)&p_sbr, PV_NONE,
2504#else
2505 (char_u *)NULL, PV_NONE,
2506#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002507 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002508 {"showcmd", "sc", P_BOOL|P_VIM,
2509#ifdef FEAT_CMDL_INFO
2510 (char_u *)&p_sc, PV_NONE,
2511#else
2512 (char_u *)NULL, PV_NONE,
2513#endif
2514 {(char_u *)FALSE,
2515#ifdef UNIX
2516 (char_u *)FALSE
2517#else
2518 (char_u *)TRUE
2519#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002520 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002521 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2522 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002523 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002524 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2525 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002526 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002527 {"showmode", "smd", P_BOOL|P_VIM,
2528 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002529 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002530 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002531 (char_u *)&p_stal, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002532 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002533 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2534 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002535 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002536 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2537 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002538 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002539 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2540#ifdef FEAT_SIGNS
2541 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002542 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002543#else
2544 (char_u *)NULL, PV_NONE,
2545 {(char_u *)NULL, (char_u *)0L}
2546#endif
Bram Moolenaarb3384832016-08-12 18:51:58 +02002547 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002548 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2549 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002550 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002551 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2552 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002553 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002554 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2555#ifdef FEAT_SMARTINDENT
2556 (char_u *)&p_si, PV_SI,
2557#else
2558 (char_u *)NULL, PV_NONE,
2559#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002560 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002561 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2562 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002563 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002564 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2565 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002566 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002567 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2568 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002569 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002570 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002571#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002572 (char_u *)VAR_WIN, PV_SPELL,
2573#else
2574 (char_u *)NULL, PV_NONE,
2575#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002576 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002577 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002578#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002579 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002580 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002581#else
2582 (char_u *)NULL, PV_NONE,
2583 {(char_u *)0L, (char_u *)0L}
2584#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002585 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002586 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2587 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002588#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002589 (char_u *)&p_spf, PV_SPF,
2590 {(char_u *)"", (char_u *)0L}
2591#else
2592 (char_u *)NULL, PV_NONE,
2593 {(char_u *)0L, (char_u *)0L}
2594#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002595 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002596 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2597 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002598#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002599 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002600 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002601#else
2602 (char_u *)NULL, PV_NONE,
2603 {(char_u *)0L, (char_u *)0L}
2604#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002605 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002606 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002607#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002608 (char_u *)&p_sps, PV_NONE,
2609 {(char_u *)"best", (char_u *)0L}
2610#else
2611 (char_u *)NULL, PV_NONE,
2612 {(char_u *)0L, (char_u *)0L}
2613#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002614 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002615 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002616 (char_u *)&p_sb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002617 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002618 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002619 (char_u *)&p_spr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002620 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002621 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2622 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002623 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002624 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2625#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002626 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002627#else
2628 (char_u *)NULL, PV_NONE,
2629#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002630 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002631 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002632 (char_u *)&p_su, PV_NONE,
2633 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002634 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002635 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002636#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002637 (char_u *)&p_sua, PV_SUA,
2638 {(char_u *)"", (char_u *)0L}
2639#else
2640 (char_u *)NULL, PV_NONE,
2641 {(char_u *)0L, (char_u *)0L}
2642#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002643 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002644 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2645 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002646 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002647 {"swapsync", "sws", P_STRING|P_VI_DEF,
2648 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002649 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002650 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002651 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002652 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002653 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2654#ifdef FEAT_SYN_HL
2655 (char_u *)&p_smc, PV_SMC,
2656 {(char_u *)3000L, (char_u *)0L}
2657#else
2658 (char_u *)NULL, PV_NONE,
2659 {(char_u *)0L, (char_u *)0L}
2660#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002661 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002662 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002663#ifdef FEAT_SYN_HL
2664 (char_u *)&p_syn, PV_SYN,
2665 {(char_u *)"", (char_u *)0L}
2666#else
2667 (char_u *)NULL, PV_NONE,
2668 {(char_u *)0L, (char_u *)0L}
2669#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002670 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002671 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2672#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002673 (char_u *)&p_tal, PV_NONE,
2674#else
2675 (char_u *)NULL, PV_NONE,
2676#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002677 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002678 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002679 (char_u *)&p_tpm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002680 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002681 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2682 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002683 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002684 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2685 (char_u *)&p_tbs, PV_NONE,
2686#ifdef VMS /* binary searching doesn't appear to work on VMS */
2687 {(char_u *)0L, (char_u *)0L}
2688#else
2689 {(char_u *)TRUE, (char_u *)0L}
2690#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002691 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002692 {"tagcase", "tc", P_STRING|P_VIM,
2693 (char_u *)&p_tc, PV_TC,
2694 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002695 {"taglength", "tl", P_NUM|P_VI_DEF,
2696 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002697 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002698 {"tagrelative", "tr", P_BOOL|P_VIM,
2699 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002700 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002701 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002702 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002703 {
2704#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2705 (char_u *)"./tags,./TAGS,tags,TAGS",
2706#else
2707 (char_u *)"./tags,tags",
2708#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002709 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002710 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2711 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002712 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002713 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002714#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002715 (char_u *)&p_tcldll, PV_NONE,
2716 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002717#else
2718 (char_u *)NULL, PV_NONE,
2719 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002720#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002721 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002722 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2723 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002724 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002725 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2726#ifdef FEAT_ARABIC
2727 (char_u *)&p_tbidi, PV_NONE,
2728#else
2729 (char_u *)NULL, PV_NONE,
2730#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002731 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002732 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2733#ifdef FEAT_MBYTE
2734 (char_u *)&p_tenc, PV_NONE,
2735 {(char_u *)"", (char_u *)0L}
2736#else
2737 (char_u *)NULL, PV_NONE,
2738 {(char_u *)0L, (char_u *)0L}
2739#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002740 SCRIPTID_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002741 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2742#ifdef FEAT_TERMGUICOLORS
2743 (char_u *)&p_tgc, PV_NONE,
2744 {(char_u *)FALSE, (char_u *)FALSE}
2745#else
2746 (char_u*)NULL, PV_NONE,
2747 {(char_u *)FALSE, (char_u *)FALSE}
2748#endif
2749 SCRIPTID_INIT},
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002750 {"termkey", "tk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2751#ifdef FEAT_TERMINAL
2752 (char_u *)VAR_WIN, PV_TK,
Bram Moolenaar1f28b4c2017-07-28 13:48:34 +02002753 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002754#else
2755 (char_u *)NULL, PV_NONE,
2756 {(char_u *)NULL, (char_u *)0L}
2757#endif
2758 SCRIPTID_INIT},
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002759 {"termsize", "tms", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2760#ifdef FEAT_TERMINAL
2761 (char_u *)VAR_WIN, PV_TMS,
2762 {(char_u *)"", (char_u *)NULL}
2763#else
2764 (char_u *)NULL, PV_NONE,
2765 {(char_u *)NULL, (char_u *)0L}
2766#endif
2767 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002768 {"terse", NULL, P_BOOL|P_VI_DEF,
2769 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002770 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002771 {"textauto", "ta", P_BOOL|P_VIM,
2772 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002773 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2774 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002775 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2776 (char_u *)&p_tx, PV_TX,
2777 {
2778#ifdef USE_CRNL
2779 (char_u *)TRUE,
2780#else
2781 (char_u *)FALSE,
2782#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002783 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002784 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002785 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002786 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002787 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002788#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002789 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002790#else
2791 (char_u *)NULL, PV_NONE,
2792#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002793 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002794 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2795 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002796 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002797 {"timeout", "to", P_BOOL|P_VI_DEF,
2798 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002799 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002800 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2801 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002802 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002803 {"title", NULL, P_BOOL|P_VI_DEF,
2804#ifdef FEAT_TITLE
2805 (char_u *)&p_title, PV_NONE,
2806#else
2807 (char_u *)NULL, PV_NONE,
2808#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002809 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002810 {"titlelen", NULL, P_NUM|P_VI_DEF,
2811#ifdef FEAT_TITLE
2812 (char_u *)&p_titlelen, PV_NONE,
2813#else
2814 (char_u *)NULL, PV_NONE,
2815#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002816 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002817 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002818#ifdef FEAT_TITLE
2819 (char_u *)&p_titleold, PV_NONE,
2820 {(char_u *)N_("Thanks for flying Vim"),
2821 (char_u *)0L}
2822#else
2823 (char_u *)NULL, PV_NONE,
2824 {(char_u *)0L, (char_u *)0L}
2825#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002826 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002827 {"titlestring", NULL, P_STRING|P_VI_DEF,
2828#ifdef FEAT_TITLE
2829 (char_u *)&p_titlestring, PV_NONE,
2830#else
2831 (char_u *)NULL, PV_NONE,
2832#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002833 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002834 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002835#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002836 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002837 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002838#else
2839 (char_u *)NULL, PV_NONE,
2840 {(char_u *)0L, (char_u *)0L}
2841#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002842 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002843 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002844#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002845 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002846 {(char_u *)"small", (char_u *)0L}
2847#else
2848 (char_u *)NULL, PV_NONE,
2849 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002850#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002851 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002852 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2853 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002854 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002855 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2856 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002857 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002858 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2859 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002860 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002861 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2862 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002863 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002864 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2865#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2866 (char_u *)&p_ttym, PV_NONE,
2867#else
2868 (char_u *)NULL, PV_NONE,
2869#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002870 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002871 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2872 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002873 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002874 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2875 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002876 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002877 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2878 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002879#ifdef FEAT_PERSISTENT_UNDO
2880 (char_u *)&p_udir, PV_NONE,
2881 {(char_u *)".", (char_u *)0L}
2882#else
2883 (char_u *)NULL, PV_NONE,
2884 {(char_u *)0L, (char_u *)0L}
2885#endif
2886 SCRIPTID_INIT},
2887 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2888#ifdef FEAT_PERSISTENT_UNDO
2889 (char_u *)&p_udf, PV_UDF,
2890#else
2891 (char_u *)NULL, PV_NONE,
2892#endif
2893 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002894 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002895 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002896 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002897#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002898 (char_u *)1000L,
2899#else
2900 (char_u *)100L,
2901#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002902 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002903 {"undoreload", "ur", P_NUM|P_VI_DEF,
2904 (char_u *)&p_ur, PV_NONE,
2905 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002906 {"updatecount", "uc", P_NUM|P_VI_DEF,
2907 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002908 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002909 {"updatetime", "ut", P_NUM|P_VI_DEF,
2910 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002911 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002912 {"verbose", "vbs", P_NUM|P_VI_DEF,
2913 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002914 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002915 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2916 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002917 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002918 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2919#ifdef FEAT_SESSION
2920 (char_u *)&p_vdir, PV_NONE,
2921 {(char_u *)DFLT_VDIR, (char_u *)0L}
2922#else
2923 (char_u *)NULL, PV_NONE,
2924 {(char_u *)0L, (char_u *)0L}
2925#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002926 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002927 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002928#ifdef FEAT_SESSION
2929 (char_u *)&p_vop, PV_NONE,
2930 {(char_u *)"folds,options,cursor", (char_u *)0L}
2931#else
2932 (char_u *)NULL, PV_NONE,
2933 {(char_u *)0L, (char_u *)0L}
2934#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002935 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002936 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002937#ifdef FEAT_VIMINFO
2938 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002939#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002940 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002941#else
2942# ifdef AMIGA
2943 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002944 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002945# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002946 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002947# endif
2948#endif
2949#else
2950 (char_u *)NULL, PV_NONE,
2951 {(char_u *)0L, (char_u *)0L}
2952#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002953 SCRIPTID_INIT},
Bram Moolenaarc4da1132017-07-15 19:39:43 +02002954 {"viminfofile", "vif", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE|P_VI_DEF,
2955#ifdef FEAT_VIMINFO
2956 (char_u *)&p_viminfofile, PV_NONE,
2957 {(char_u *)"", (char_u *)0L}
2958#else
2959 (char_u *)NULL, PV_NONE,
2960 {(char_u *)0L, (char_u *)0L}
2961#endif
2962 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002963 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2964 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002965#ifdef FEAT_VIRTUALEDIT
2966 (char_u *)&p_ve, PV_NONE,
2967 {(char_u *)"", (char_u *)""}
2968#else
2969 (char_u *)NULL, PV_NONE,
2970 {(char_u *)0L, (char_u *)0L}
2971#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002972 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002973 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2974 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002975 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002976 {"w300", NULL, P_NUM|P_VI_DEF,
2977 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002978 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002979 {"w1200", NULL, P_NUM|P_VI_DEF,
2980 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002981 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002982 {"w9600", NULL, P_NUM|P_VI_DEF,
2983 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002984 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002985 {"warn", NULL, P_BOOL|P_VI_DEF,
2986 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002987 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002988 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2989 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002990 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002991 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002992 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002993 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002994 {"wildchar", "wc", P_NUM|P_VIM,
2995 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002996 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2997 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002998 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002999 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003000 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003001 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003002#ifdef FEAT_WILDIGN
3003 (char_u *)&p_wig, PV_NONE,
3004#else
3005 (char_u *)NULL, PV_NONE,
3006#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003007 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003008 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3009 (char_u *)&p_wic, PV_NONE,
3010 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003011 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
3012#ifdef FEAT_WILDMENU
3013 (char_u *)&p_wmnu, PV_NONE,
3014#else
3015 (char_u *)NULL, PV_NONE,
3016#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003017 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003018 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003019 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003020 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003021 {"wildoptions", "wop", P_STRING|P_VI_DEF,
3022#ifdef FEAT_CMDL_COMPL
3023 (char_u *)&p_wop, PV_NONE,
3024 {(char_u *)"", (char_u *)0L}
3025#else
3026 (char_u *)NULL, PV_NONE,
3027 {(char_u *)NULL, (char_u *)0L}
3028#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003029 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003030 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3031#ifdef FEAT_WAK
3032 (char_u *)&p_wak, PV_NONE,
3033 {(char_u *)"menu", (char_u *)0L}
3034#else
3035 (char_u *)NULL, PV_NONE,
3036 {(char_u *)NULL, (char_u *)0L}
3037#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003038 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003039 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003040 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003041 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003042 {"winheight", "wh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003043 (char_u *)&p_wh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003044 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003045 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003046 (char_u *)VAR_WIN, PV_WFH,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003047 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003048 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003049 (char_u *)VAR_WIN, PV_WFW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003050 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003051 {"winminheight", "wmh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003052 (char_u *)&p_wmh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003053 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003054 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003055 (char_u *)&p_wmw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003056 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003057 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar84ed4ad2017-08-17 11:33:42 +02003058#if defined(WIN3264) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003059 (char_u *)&p_winptydll, PV_NONE, {
3060# ifdef _WIN64
3061 (char_u *)"winpty64.dll",
3062# else
3063 (char_u *)"winpty32.dll",
3064# endif
3065 (char_u *)0L}
3066#else
3067 (char_u *)NULL, PV_NONE,
3068 {(char_u *)0L, (char_u *)0L}
3069#endif
3070 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003071 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003072 (char_u *)&p_wiw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003073 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003074 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3075 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003076 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003077 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3078 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003079 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003080 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3081 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003082 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003083 {"write", NULL, P_BOOL|P_VI_DEF,
3084 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003085 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003086 {"writeany", "wa", P_BOOL|P_VI_DEF,
3087 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003088 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003089 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3090 (char_u *)&p_wb, PV_NONE,
3091 {
3092#ifdef FEAT_WRITEBACKUP
3093 (char_u *)TRUE,
3094#else
3095 (char_u *)FALSE,
3096#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003097 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003098 {"writedelay", "wd", P_NUM|P_VI_DEF,
3099 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003100 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003101
3102/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003103#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003104 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003105 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003106
3107 p_term("t_AB", T_CAB)
3108 p_term("t_AF", T_CAF)
3109 p_term("t_AL", T_CAL)
3110 p_term("t_al", T_AL)
3111 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003112 p_term("t_BE", T_BE)
3113 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003114 p_term("t_cd", T_CD)
3115 p_term("t_ce", T_CE)
3116 p_term("t_cl", T_CL)
3117 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003118 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003119 p_term("t_Co", T_CCO)
3120 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003121 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003122 p_term("t_cs", T_CS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003123 p_term("t_CV", T_CSV)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003124 p_term("t_da", T_DA)
3125 p_term("t_db", T_DB)
3126 p_term("t_DL", T_CDL)
3127 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003128 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003129 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003130 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003131 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003132 p_term("t_IE", T_CIE)
3133 p_term("t_IS", T_CIS)
3134 p_term("t_ke", T_KE)
3135 p_term("t_ks", T_KS)
3136 p_term("t_le", T_LE)
3137 p_term("t_mb", T_MB)
3138 p_term("t_md", T_MD)
3139 p_term("t_me", T_ME)
3140 p_term("t_mr", T_MR)
3141 p_term("t_ms", T_MS)
3142 p_term("t_nd", T_ND)
3143 p_term("t_op", T_OP)
Bram Moolenaara20f83d2017-10-15 13:35:01 +02003144 p_term("t_RF", T_RFG)
Bram Moolenaare5401222015-06-25 19:16:56 +02003145 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003146 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003147 p_term("t_RI", T_CRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003148 p_term("t_RS", T_CRS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003149 p_term("t_RV", T_CRV)
3150 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003151 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003152 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003153 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003154 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003155 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003156 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003157 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003158 p_term("t_sr", T_SR)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003159 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003160 p_term("t_te", T_TE)
3161 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003162 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003163 p_term("t_ts", T_TS)
3164 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003165 p_term("t_ue", T_UE)
3166 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003167 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003168 p_term("t_vb", T_VB)
3169 p_term("t_ve", T_VE)
3170 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003171 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003172 p_term("t_vs", T_VS)
3173 p_term("t_WP", T_CWP)
3174 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003175 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003176 p_term("t_xs", T_XS)
3177 p_term("t_ZH", T_CZH)
3178 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003179 p_term("t_8f", T_8F)
3180 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003181
3182/* terminal key codes are not in here */
3183
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003184 /* end marker */
3185 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003186};
3187
3188#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3189
3190#ifdef FEAT_MBYTE
3191static char *(p_ambw_values[]) = {"single", "double", NULL};
3192#endif
3193static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003194static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003195static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003196#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003197static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003198#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003199#ifdef FEAT_CMDL_COMPL
3200static char *(p_wop_values[]) = {"tagfile", NULL};
3201#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003202#ifdef FEAT_WAK
3203static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3204#endif
3205static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003206static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3207static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003208static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003209#ifdef FEAT_BROWSE
3210static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3211#endif
3212#ifdef FEAT_SCROLLBIND
3213static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3214#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003215static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003216static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003217#ifdef FEAT_AUTOCMD
3218static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", NULL};
3219#else
3220static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003221#endif
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003222static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003223static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3224#ifdef FEAT_FOLDING
3225static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003226# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003227 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003228# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003229 NULL};
3230static char *(p_fcl_values[]) = {"all", NULL};
3231#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003232#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003233static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003234#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003235#ifdef FEAT_SIGNS
3236static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3237#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003238
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003239static void set_option_default(int, int opt_flags, int compatible);
3240static void set_options_default(int opt_flags);
3241static char_u *term_bg_default(void);
3242static void did_set_option(int opt_idx, int opt_flags, int new_value);
3243static char_u *illegal_char(char_u *, int);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003244#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003245static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003246#endif
3247#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003248static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003249#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003250static char_u *option_expand(int opt_idx, char_u *val);
3251static void didset_options(void);
3252static void didset_options2(void);
3253static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003254#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003255static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003256#else
3257# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3258#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003259static void set_string_option_global(int opt_idx, char_u **varp);
3260static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3261static char_u *did_set_string_option(int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char_u *errbuf, int opt_flags);
3262static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003263#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003264static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003265#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003266#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003267static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003268#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003269#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003270static char_u *did_set_spell_option(int is_spellfile);
3271static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003272#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003273#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003274static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003275#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003276static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3277static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3278static void check_redraw(long_u flags);
3279static int findoption(char_u *);
3280static int find_key_option(char_u *);
3281static void showoptions(int all, int opt_flags);
3282static int optval_default(struct vimoption *, char_u *varp);
3283static void showoneopt(struct vimoption *, int opt_flags);
3284static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3285static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3286static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3287static int istermoption(struct vimoption *);
3288static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3289static char_u *get_varp(struct vimoption *);
3290static void option_value2string(struct vimoption *, int opt_flags);
3291static void check_winopt(winopt_T *wop);
3292static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003293#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003294static void langmap_init(void);
3295static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003296#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003297static void paste_option_changed(void);
3298static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003299#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003300static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003301#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003302static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3303static int check_opt_strings(char_u *val, char **values, int);
3304static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003305#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003306static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003307#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003308
3309/*
3310 * Initialize the options, first part.
3311 *
3312 * Called only once from main(), just after creating the first buffer.
3313 */
3314 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003315set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003316{
3317 char_u *p;
3318 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003319 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003320
3321#ifdef FEAT_LANGMAP
3322 langmap_init();
3323#endif
3324
3325 /* Be Vi compatible by default */
3326 p_cp = TRUE;
3327
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003328 /* Use POSIX compatibility when $VIM_POSIX is set. */
3329 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003330 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003331 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003332 set_string_default("shm", (char_u *)"A");
3333 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003334
Bram Moolenaar071d4272004-06-13 20:20:40 +00003335 /*
3336 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003337 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003338 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003339 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003340#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003341 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003342# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003343 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003344# endif
3345#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003346 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003347 set_string_default("sh", p);
3348
3349#ifdef FEAT_WILDIGN
3350 /*
3351 * Set the default for 'backupskip' to include environment variables for
3352 * temp files.
3353 */
3354 {
3355# ifdef UNIX
3356 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3357# else
3358 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3359# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003360 int len;
3361 garray_T ga;
3362 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003363
3364 ga_init2(&ga, 1, 100);
3365 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3366 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003367 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003368# ifdef UNIX
3369 if (*names[n] == NUL)
3370 p = (char_u *)"/tmp";
3371 else
3372# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003373 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003374 if (p != NULL && *p != NUL)
3375 {
3376 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003377 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003378 if (ga_grow(&ga, len) == OK)
3379 {
3380 if (ga.ga_len > 0)
3381 STRCAT(ga.ga_data, ",");
3382 STRCAT(ga.ga_data, p);
3383 add_pathsep(ga.ga_data);
3384 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003385 ga.ga_len += len;
3386 }
3387 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003388 if (mustfree)
3389 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003390 }
3391 if (ga.ga_data != NULL)
3392 {
3393 set_string_default("bsk", ga.ga_data);
3394 vim_free(ga.ga_data);
3395 }
3396 }
3397#endif
3398
3399 /*
3400 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3401 */
3402 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003403 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003404 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003405#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3406 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3407#endif
3408 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003409#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003410 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003411 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003412#else
3413# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003414 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003415 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003416# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003417 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003418# endif
3419#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003420 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003421 opt_idx = findoption((char_u *)"maxmem");
3422 if (opt_idx >= 0)
3423 {
3424#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003425 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3426 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003427#endif
3428 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3429 }
3430 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003431 }
3432
Bram Moolenaar071d4272004-06-13 20:20:40 +00003433#ifdef FEAT_SEARCHPATH
3434 {
3435 char_u *cdpath;
3436 char_u *buf;
3437 int i;
3438 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003439 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003440
3441 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003442 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003443 if (cdpath != NULL)
3444 {
3445 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3446 if (buf != NULL)
3447 {
3448 buf[0] = ','; /* start with ",", current dir first */
3449 j = 1;
3450 for (i = 0; cdpath[i] != NUL; ++i)
3451 {
3452 if (vim_ispathlistsep(cdpath[i]))
3453 buf[j++] = ',';
3454 else
3455 {
3456 if (cdpath[i] == ' ' || cdpath[i] == ',')
3457 buf[j++] = '\\';
3458 buf[j++] = cdpath[i];
3459 }
3460 }
3461 buf[j] = NUL;
3462 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003463 if (opt_idx >= 0)
3464 {
3465 options[opt_idx].def_val[VI_DEFAULT] = buf;
3466 options[opt_idx].flags |= P_DEF_ALLOCED;
3467 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003468 else
3469 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003470 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003471 if (mustfree)
3472 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003473 }
3474 }
3475#endif
3476
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003477#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003478 /* Set print encoding on platforms that don't default to latin1 */
3479 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003480# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003481 (char_u *)"cp1252"
3482# else
3483# ifdef VMS
3484 (char_u *)"dec-mcs"
3485# else
3486# ifdef EBCDIC
3487 (char_u *)"ebcdic-uk"
3488# else
3489# ifdef MAC
3490 (char_u *)"mac-roman"
3491# else /* HPUX */
3492 (char_u *)"hp-roman8"
3493# endif
3494# endif
3495# endif
3496# endif
3497 );
3498#endif
3499
3500#ifdef FEAT_POSTSCRIPT
3501 /* 'printexpr' must be allocated to be able to evaluate it. */
3502 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003503# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003504 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003505# else
3506# ifdef VMS
3507 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3508
3509# else
3510 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3511# endif
3512# endif
3513 );
3514#endif
3515
3516 /*
3517 * Set all the options (except the terminal options) to their default
3518 * value. Also set the global value for local options.
3519 */
3520 set_options_default(0);
3521
3522#ifdef FEAT_GUI
3523 if (found_reverse_arg)
3524 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3525#endif
3526
3527 curbuf->b_p_initialized = TRUE;
3528 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003529 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003530 check_buf_options(curbuf);
3531 check_win_options(curwin);
3532 check_options();
3533
3534 /* Must be before option_expand(), because that one needs vim_isIDc() */
3535 didset_options();
3536
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003537#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003538 /* Use the current chartab for the generic chartab. This is not in
3539 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003540 init_spell_chartab();
3541#endif
3542
Bram Moolenaar071d4272004-06-13 20:20:40 +00003543 /*
3544 * Expand environment variables and things like "~" for the defaults.
3545 * If option_expand() returns non-NULL the variable is expanded. This can
3546 * only happen for non-indirect options.
3547 * Also set the default to the expanded value, so ":set" does not list
3548 * them.
3549 * Don't set the P_ALLOCED flag, because we don't want to free the
3550 * default.
3551 */
3552 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3553 {
3554 if ((options[opt_idx].flags & P_GETTEXT)
3555 && options[opt_idx].var != NULL)
3556 p = (char_u *)_(*(char **)options[opt_idx].var);
3557 else
3558 p = option_expand(opt_idx, NULL);
3559 if (p != NULL && (p = vim_strsave(p)) != NULL)
3560 {
3561 *(char_u **)options[opt_idx].var = p;
3562 /* VIMEXP
3563 * Defaults for all expanded options are currently the same for Vi
3564 * and Vim. When this changes, add some code here! Also need to
3565 * split P_DEF_ALLOCED in two.
3566 */
3567 if (options[opt_idx].flags & P_DEF_ALLOCED)
3568 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3569 options[opt_idx].def_val[VI_DEFAULT] = p;
3570 options[opt_idx].flags |= P_DEF_ALLOCED;
3571 }
3572 }
3573
Bram Moolenaar071d4272004-06-13 20:20:40 +00003574 save_file_ff(curbuf); /* Buffer is unchanged */
3575
Bram Moolenaar071d4272004-06-13 20:20:40 +00003576#if defined(FEAT_ARABIC)
3577 /* Detect use of mlterm.
3578 * Mlterm is a terminal emulator akin to xterm that has some special
3579 * abilities (bidi namely).
3580 * NOTE: mlterm's author is being asked to 'set' a variable
3581 * instead of an environment variable due to inheritance.
3582 */
3583 if (mch_getenv((char_u *)"MLTERM") != NULL)
3584 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3585#endif
3586
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003587 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003588
3589#ifdef FEAT_MBYTE
3590# if defined(WIN3264) && defined(FEAT_GETTEXT)
3591 /*
3592 * If $LANG isn't set, try to get a good value for it. This makes the
3593 * right language be used automatically. Don't do this for English.
3594 */
3595 if (mch_getenv((char_u *)"LANG") == NULL)
3596 {
3597 char buf[20];
3598
3599 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3600 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3601 * only the first two. */
3602 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3603 (LPTSTR)buf, 20);
3604 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3605 {
3606 /* There are a few exceptions (probably more) */
3607 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3608 STRCPY(buf, "zh_TW");
3609 else if (STRNICMP(buf, "chs", 3) == 0
3610 || STRNICMP(buf, "zhc", 3) == 0)
3611 STRCPY(buf, "zh_CN");
3612 else if (STRNICMP(buf, "jp", 2) == 0)
3613 STRCPY(buf, "ja");
3614 else
3615 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003616 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003617 }
3618 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003619# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003620# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003621 /* Moved to os_mac_conv.c to avoid dependency problems. */
3622 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003623# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003624# endif
3625
3626 /* enc_locale() will try to find the encoding of the current locale. */
3627 p = enc_locale();
3628 if (p != NULL)
3629 {
3630 char_u *save_enc;
3631
3632 /* Try setting 'encoding' and check if the value is valid.
3633 * If not, go back to the default "latin1". */
3634 save_enc = p_enc;
3635 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003636 if (STRCMP(p_enc, "gb18030") == 0)
3637 {
3638 /* We don't support "gb18030", but "cp936" is a good substitute
3639 * for practical purposes, thus use that. It's not an alias to
3640 * still support conversion between gb18030 and utf-8. */
3641 p_enc = vim_strsave((char_u *)"cp936");
3642 vim_free(p);
3643 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003644 if (mb_init() == NULL)
3645 {
3646 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003647 if (opt_idx >= 0)
3648 {
3649 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3650 options[opt_idx].flags |= P_DEF_ALLOCED;
3651 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003652
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003653#if defined(MSWIN) || defined(MACOS) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003654 if (STRCMP(p_enc, "latin1") == 0
3655# ifdef FEAT_MBYTE
3656 || enc_utf8
3657# endif
3658 )
3659 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003660 /* Adjust the default for 'isprint' and 'iskeyword' to match
3661 * latin1. Also set the defaults for when 'nocompatible' is
3662 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003663 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003664 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003665 set_string_option_direct((char_u *)"isk", -1,
3666 ISK_LATIN1, OPT_FREE, SID_NONE);
3667 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003668 if (opt_idx >= 0)
3669 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003670 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003671 if (opt_idx >= 0)
3672 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003673 (void)init_chartab();
3674 }
3675#endif
3676
Bram Moolenaar071d4272004-06-13 20:20:40 +00003677# if defined(WIN3264) && !defined(FEAT_GUI)
3678 /* Win32 console: When GetACP() returns a different value from
3679 * GetConsoleCP() set 'termencoding'. */
3680 if (GetACP() != GetConsoleCP())
3681 {
3682 char buf[50];
3683
3684 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3685 p_tenc = vim_strsave((char_u *)buf);
3686 if (p_tenc != NULL)
3687 {
3688 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003689 if (opt_idx >= 0)
3690 {
3691 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3692 options[opt_idx].flags |= P_DEF_ALLOCED;
3693 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003694 convert_setup(&input_conv, p_tenc, p_enc);
3695 convert_setup(&output_conv, p_enc, p_tenc);
3696 }
3697 else
3698 p_tenc = empty_option;
3699 }
3700# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003701# if defined(WIN3264) && defined(FEAT_MBYTE)
3702 /* $HOME may have characters in active code page. */
3703 init_homedir();
3704# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003705 }
3706 else
3707 {
3708 vim_free(p_enc);
3709 p_enc = save_enc;
3710 }
3711 }
3712#endif
3713
3714#ifdef FEAT_MULTI_LANG
3715 /* Set the default for 'helplang'. */
3716 set_helplang_default(get_mess_lang());
3717#endif
3718}
3719
3720/*
3721 * Set an option to its default value.
3722 * This does not take care of side effects!
3723 */
3724 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003725set_option_default(
3726 int opt_idx,
3727 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3728 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003729{
3730 char_u *varp; /* pointer to variable for current option */
3731 int dvi; /* index in def_val[] */
3732 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003733 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003734 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3735
3736 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3737 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003738 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003739 {
3740 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3741 if (flags & P_STRING)
3742 {
3743 /* Use set_string_option_direct() for local options to handle
3744 * freeing and allocating the value. */
3745 if (options[opt_idx].indir != PV_NONE)
3746 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003747 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003748 else
3749 {
3750 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3751 free_string_option(*(char_u **)(varp));
3752 *(char_u **)varp = options[opt_idx].def_val[dvi];
3753 options[opt_idx].flags &= ~P_ALLOCED;
3754 }
3755 }
3756 else if (flags & P_NUM)
3757 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003758 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003759 win_comp_scroll(curwin);
3760 else
3761 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003762 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003763 /* May also set global value for local option. */
3764 if (both)
3765 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3766 *(long *)varp;
3767 }
3768 }
3769 else /* P_BOOL */
3770 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003771 /* the cast to long is required for Manx C, long_i is needed for
3772 * MSVC */
3773 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003774#ifdef UNIX
3775 /* 'modeline' defaults to off for root */
3776 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3777 *(int *)varp = FALSE;
3778#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003779 /* May also set global value for local option. */
3780 if (both)
3781 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3782 *(int *)varp;
3783 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003784
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003785 /* The default value is not insecure. */
3786 flagsp = insecure_flag(opt_idx, opt_flags);
3787 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003788 }
3789
3790#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003791 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003792#endif
3793}
3794
3795/*
3796 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003797 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003798 */
3799 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003800set_options_default(
3801 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003802{
3803 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003804 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003805 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003806
3807 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003808 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003809#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003810 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003811 || (TRUE
3812# if defined(FEAT_MBYTE)
3813 && options[i].var != (char_u *)&p_enc
3814# endif
3815# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003816 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003817 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003818# endif
3819 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003820#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003821 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003822 set_option_default(i, opt_flags, p_cp);
3823
Bram Moolenaar071d4272004-06-13 20:20:40 +00003824 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003825 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003826 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003827#ifdef FEAT_CINDENT
3828 parse_cino(curbuf);
3829#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003830}
3831
3832/*
3833 * Set the Vi-default value of a string option.
3834 * Used for 'sh', 'backupskip' and 'term'.
3835 */
3836 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003837set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003838{
3839 char_u *p;
3840 int opt_idx;
3841
3842 p = vim_strsave(val);
3843 if (p != NULL) /* we don't want a NULL */
3844 {
3845 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003846 if (opt_idx >= 0)
3847 {
3848 if (options[opt_idx].flags & P_DEF_ALLOCED)
3849 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3850 options[opt_idx].def_val[VI_DEFAULT] = p;
3851 options[opt_idx].flags |= P_DEF_ALLOCED;
3852 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003853 }
3854}
3855
3856/*
3857 * Set the Vi-default value of a number option.
3858 * Used for 'lines' and 'columns'.
3859 */
3860 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003861set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003862{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003863 int opt_idx;
3864
3865 opt_idx = findoption((char_u *)name);
3866 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003867 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003868}
3869
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003870#if defined(EXITFREE) || defined(PROTO)
3871/*
3872 * Free all options.
3873 */
3874 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003875free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003876{
3877 int i;
3878
3879 for (i = 0; !istermoption(&options[i]); i++)
3880 {
3881 if (options[i].indir == PV_NONE)
3882 {
3883 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003884 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003885 free_string_option(*(char_u **)options[i].var);
3886 if (options[i].flags & P_DEF_ALLOCED)
3887 free_string_option(options[i].def_val[VI_DEFAULT]);
3888 }
3889 else if (options[i].var != VAR_WIN
3890 && (options[i].flags & P_STRING))
3891 /* buffer-local option: free global value */
3892 free_string_option(*(char_u **)options[i].var);
3893 }
3894}
3895#endif
3896
3897
Bram Moolenaar071d4272004-06-13 20:20:40 +00003898/*
3899 * Initialize the options, part two: After getting Rows and Columns and
3900 * setting 'term'.
3901 */
3902 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003903set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003904{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003905 int idx;
3906
Bram Moolenaar071d4272004-06-13 20:20:40 +00003907 /*
3908 * 'scroll' defaults to half the window height. Note that this default is
3909 * wrong when the window height changes.
3910 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003911 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003912 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003913 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003914 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003915 comp_col();
3916
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003917 /*
3918 * 'window' is only for backwards compatibility with Vi.
3919 * Default is Rows - 1.
3920 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003921 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003922 p_window = Rows - 1;
3923 set_number_default("window", Rows - 1);
3924
Bram Moolenaarf740b292006-02-16 22:11:02 +00003925 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003926#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003927 /*
3928 * If 'background' wasn't set by the user, try guessing the value,
3929 * depending on the terminal name. Only need to check for terminals
3930 * with a dark background, that can handle color.
3931 */
3932 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003933 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3934 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003935 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003936 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003937 /* don't mark it as set, when starting the GUI it may be
3938 * changed again */
3939 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003940 }
3941#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003942
3943#ifdef CURSOR_SHAPE
3944 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3945#endif
3946#ifdef FEAT_MOUSESHAPE
3947 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3948#endif
3949#ifdef FEAT_PRINTER
3950 (void)parse_printoptions(); /* parse 'printoptions' default value */
3951#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003952}
3953
3954/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003955 * Return "dark" or "light" depending on the kind of terminal.
3956 * This is just guessing! Recognized are:
3957 * "linux" Linux console
3958 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003959 * "cygwin.*" Cygwin shell
3960 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00003961 * We also check the COLORFGBG environment variable, which is set by
3962 * rxvt and derivatives. This variable contains either two or three
3963 * values separated by semicolons; we want the last value in either
3964 * case. If this value is 0-6 or 8, our background is dark.
3965 */
3966 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003967term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003968{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003969#if defined(WIN3264)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003970 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003971 return (char_u *)"dark";
3972#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003973 char_u *p;
3974
Bram Moolenaarf740b292006-02-16 22:11:02 +00003975 if (STRCMP(T_NAME, "linux") == 0
3976 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003977 || STRNCMP(T_NAME, "cygwin", 6) == 0
3978 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00003979 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3980 && (p = vim_strrchr(p, ';')) != NULL
3981 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3982 && p[2] == NUL))
3983 return (char_u *)"dark";
3984 return (char_u *)"light";
3985#endif
3986}
3987
3988/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003989 * Initialize the options, part three: After reading the .vimrc
3990 */
3991 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003992set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003993{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003994#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003995/*
3996 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3997 * This is done after other initializations, where 'shell' might have been
3998 * set, but only if they have not been set before.
3999 */
4000 char_u *p;
4001 int idx_srr;
4002 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004003# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004004 int idx_sp;
4005 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004006# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004007
4008 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004009 if (idx_srr < 0)
4010 do_srr = FALSE;
4011 else
4012 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004013# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004014 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004015 if (idx_sp < 0)
4016 do_sp = FALSE;
4017 else
4018 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004019# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004020 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004021 if (p != NULL)
4022 {
4023 /*
4024 * Default for p_sp is "| tee", for p_srr is ">".
4025 * For known shells it is changed here to include stderr.
4026 */
4027 if ( fnamecmp(p, "csh") == 0
4028 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004029# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004030 || fnamecmp(p, "csh.exe") == 0
4031 || fnamecmp(p, "tcsh.exe") == 0
4032# endif
4033 )
4034 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004035# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004036 if (do_sp)
4037 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004038# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004039 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004040# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004041 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004042# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004043 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4044 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004045# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004046 if (do_srr)
4047 {
4048 p_srr = (char_u *)">&";
4049 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4050 }
4051 }
4052 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004053 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004054 if ( fnamecmp(p, "sh") == 0
4055 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004056 || fnamecmp(p, "mksh") == 0
4057 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004058 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004059 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004060 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004061 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004062# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004063 || fnamecmp(p, "cmd") == 0
4064 || fnamecmp(p, "sh.exe") == 0
4065 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004066 || fnamecmp(p, "mksh.exe") == 0
4067 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004068 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004069 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004070 || fnamecmp(p, "bash.exe") == 0
4071 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004072# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004073 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004074 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004075# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004076 if (do_sp)
4077 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004078# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004079 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004080# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004081 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004082# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004083 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4084 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004085# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004086 if (do_srr)
4087 {
4088 p_srr = (char_u *)">%s 2>&1";
4089 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4090 }
4091 }
4092 vim_free(p);
4093 }
4094#endif
4095
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004096#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004097 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004098 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4099 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004100 * This is done after other initializations, where 'shell' might have been
4101 * set, but only if they have not been set before. Default for p_shcf is
4102 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004103 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004104 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004105 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004106 {
4107 int idx3;
4108
4109 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004110 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004111 {
4112 p_shcf = (char_u *)"-c";
4113 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4114 }
4115
Bram Moolenaar071d4272004-06-13 20:20:40 +00004116 /* Somehow Win32 requires the quotes around the redirection too */
4117 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004118 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004119 {
4120 p_sxq = (char_u *)"\"";
4121 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4122 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004123 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004124 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4125 {
4126 int idx3;
4127
4128 /*
4129 * cmd.exe on Windows will strip the first and last double quote given
4130 * on the command line, e.g. most of the time things like:
4131 * cmd /c "my path/to/echo" "my args to echo"
4132 * become:
4133 * my path/to/echo" "my args to echo
4134 * when executed.
4135 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004136 * To avoid this, set shellxquote to surround the command in
4137 * parenthesis. This appears to make most commands work, without
4138 * breaking commands that worked previously, such as
4139 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004140 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004141 idx3 = findoption((char_u *)"sxq");
4142 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4143 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004144 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004145 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4146 }
4147
Bram Moolenaara64ba222012-02-12 23:23:31 +01004148 idx3 = findoption((char_u *)"shcf");
4149 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4150 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004151 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004152 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4153 }
4154 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004155#endif
4156
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004157 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004158 {
4159 int idx_ffs = findoption((char_u *)"ffs");
4160
4161 /* Apply the first entry of 'fileformats' to the initial buffer. */
4162 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4163 set_fileformat(default_fileformat(), OPT_LOCAL);
4164 }
4165
Bram Moolenaar071d4272004-06-13 20:20:40 +00004166#ifdef FEAT_TITLE
4167 set_title_defaults();
4168#endif
4169}
4170
4171#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4172/*
4173 * When 'helplang' is still at its default value, set it to "lang".
4174 * Only the first two characters of "lang" are used.
4175 */
4176 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004177set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004178{
4179 int idx;
4180
4181 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4182 return;
4183 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004184 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004185 {
4186 if (options[idx].flags & P_ALLOCED)
4187 free_string_option(p_hlg);
4188 p_hlg = vim_strsave(lang);
4189 if (p_hlg == NULL)
4190 p_hlg = empty_option;
4191 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004192 {
4193 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4194 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4195 {
4196 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4197 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4198 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004199 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004200 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004201 options[idx].flags |= P_ALLOCED;
4202 }
4203}
4204#endif
4205
4206#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004207static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004208
4209 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004210gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004211{
4212 if (gui_get_lightness(gui.back_pixel) < 127)
4213 return (char_u *)"dark";
4214 return (char_u *)"light";
4215}
4216
4217/*
4218 * Option initializations that can only be done after opening the GUI window.
4219 */
4220 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004221init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004222{
4223 /* Set the 'background' option according to the lightness of the
4224 * background color, unless the user has set it already. */
4225 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4226 {
4227 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4228 highlight_changed();
4229 }
4230}
4231#endif
4232
4233#ifdef FEAT_TITLE
4234/*
4235 * 'title' and 'icon' only default to true if they have not been set or reset
4236 * in .vimrc and we can read the old value.
4237 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4238 * they can be reset. This reduces startup time when using X on a remote
4239 * machine.
4240 */
4241 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004242set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004243{
4244 int idx1;
4245 long val;
4246
4247 /*
4248 * If GUI is (going to be) used, we can always set the window title and
4249 * icon name. Saves a bit of time, because the X11 display server does
4250 * not need to be contacted.
4251 */
4252 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004253 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004254 {
4255#ifdef FEAT_GUI
4256 if (gui.starting || gui.in_use)
4257 val = TRUE;
4258 else
4259#endif
4260 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004261 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004262 p_title = val;
4263 }
4264 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004265 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004266 {
4267#ifdef FEAT_GUI
4268 if (gui.starting || gui.in_use)
4269 val = TRUE;
4270 else
4271#endif
4272 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004273 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004274 p_icon = val;
4275 }
4276}
4277#endif
4278
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004279#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4280 static void
4281trigger_optionsset_string(
4282 int opt_idx,
4283 int opt_flags,
4284 char_u *oldval,
4285 char_u *newval)
4286{
4287 if (oldval != NULL && newval != NULL)
4288 {
4289 char_u buf_type[7];
4290
4291 sprintf((char *)buf_type, "%s",
4292 (opt_flags & OPT_LOCAL) ? "local" : "global");
4293 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4294 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4295 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4296 apply_autocmds(EVENT_OPTIONSET,
4297 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4298 reset_v_option_vars();
4299 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004300}
4301#endif
4302
Bram Moolenaar071d4272004-06-13 20:20:40 +00004303/*
4304 * Parse 'arg' for option settings.
4305 *
4306 * 'arg' may be IObuff, but only when no errors can be present and option
4307 * does not need to be expanded with option_expand().
4308 * "opt_flags":
4309 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004310 * OPT_GLOBAL for ":setglobal"
4311 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004312 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004313 * OPT_WINONLY to only set window-local options
4314 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004315 *
4316 * returns FAIL if an error is detected, OK otherwise
4317 */
4318 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004319do_set(
4320 char_u *arg, /* option string (may be written to!) */
4321 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004322{
4323 int opt_idx;
4324 char_u *errmsg;
4325 char_u errbuf[80];
4326 char_u *startarg;
4327 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4328 int nextchar; /* next non-white char after option name */
4329 int afterchar; /* character just after option name */
4330 int len;
4331 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004332 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004333 int key;
4334 long_u flags; /* flags for current option */
4335 char_u *varp = NULL; /* pointer to variable for current option */
4336 int did_show = FALSE; /* already showed one value */
4337 int adding; /* "opt+=arg" */
4338 int prepending; /* "opt^=arg" */
4339 int removing; /* "opt-=arg" */
4340 int cp_val = 0;
4341 char_u key_name[2];
4342
4343 if (*arg == NUL)
4344 {
4345 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004346 did_show = TRUE;
4347 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004348 }
4349
4350 while (*arg != NUL) /* loop to process all options */
4351 {
4352 errmsg = NULL;
4353 startarg = arg; /* remember for error message */
4354
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004355 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4356 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004357 {
4358 /*
4359 * ":set all" show all options.
4360 * ":set all&" set all options to their default value.
4361 */
4362 arg += 3;
4363 if (*arg == '&')
4364 {
4365 ++arg;
4366 /* Only for :set command set global value of local options. */
4367 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004368 didset_options();
4369 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004370 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004371 }
4372 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004373 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004374 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004375 did_show = TRUE;
4376 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004377 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004378 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004379 {
4380 showoptions(2, opt_flags);
4381 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004382 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004383 arg += 7;
4384 }
4385 else
4386 {
4387 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004388 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004389 {
4390 prefix = 0;
4391 arg += 2;
4392 }
4393 else if (STRNCMP(arg, "inv", 3) == 0)
4394 {
4395 prefix = 2;
4396 arg += 3;
4397 }
4398
4399 /* find end of name */
4400 key = 0;
4401 if (*arg == '<')
4402 {
4403 nextchar = 0;
4404 opt_idx = -1;
4405 /* look out for <t_>;> */
4406 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4407 len = 5;
4408 else
4409 {
4410 len = 1;
4411 while (arg[len] != NUL && arg[len] != '>')
4412 ++len;
4413 }
4414 if (arg[len] != '>')
4415 {
4416 errmsg = e_invarg;
4417 goto skip;
4418 }
4419 arg[len] = NUL; /* put NUL after name */
4420 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4421 opt_idx = findoption(arg + 1);
4422 arg[len++] = '>'; /* restore '>' */
4423 if (opt_idx == -1)
4424 key = find_key_option(arg + 1);
4425 }
4426 else
4427 {
4428 len = 0;
4429 /*
4430 * The two characters after "t_" may not be alphanumeric.
4431 */
4432 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4433 len = 4;
4434 else
4435 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4436 ++len;
4437 nextchar = arg[len];
4438 arg[len] = NUL; /* put NUL after name */
4439 opt_idx = findoption(arg);
4440 arg[len] = nextchar; /* restore nextchar */
4441 if (opt_idx == -1)
4442 key = find_key_option(arg);
4443 }
4444
4445 /* remember character after option name */
4446 afterchar = arg[len];
4447
4448 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004449 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004450 ++len;
4451
4452 adding = FALSE;
4453 prepending = FALSE;
4454 removing = FALSE;
4455 if (arg[len] != NUL && arg[len + 1] == '=')
4456 {
4457 if (arg[len] == '+')
4458 {
4459 adding = TRUE; /* "+=" */
4460 ++len;
4461 }
4462 else if (arg[len] == '^')
4463 {
4464 prepending = TRUE; /* "^=" */
4465 ++len;
4466 }
4467 else if (arg[len] == '-')
4468 {
4469 removing = TRUE; /* "-=" */
4470 ++len;
4471 }
4472 }
4473 nextchar = arg[len];
4474
4475 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4476 {
4477 errmsg = (char_u *)N_("E518: Unknown option");
4478 goto skip;
4479 }
4480
4481 if (opt_idx >= 0)
4482 {
4483 if (options[opt_idx].var == NULL) /* hidden option: skip */
4484 {
4485 /* Only give an error message when requesting the value of
4486 * a hidden option, ignore setting it. */
4487 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4488 && (!(options[opt_idx].flags & P_BOOL)
4489 || nextchar == '?'))
4490 errmsg = (char_u *)N_("E519: Option not supported");
4491 goto skip;
4492 }
4493
4494 flags = options[opt_idx].flags;
4495 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4496 }
4497 else
4498 {
4499 flags = P_STRING;
4500 if (key < 0)
4501 {
4502 key_name[0] = KEY2TERMCAP0(key);
4503 key_name[1] = KEY2TERMCAP1(key);
4504 }
4505 else
4506 {
4507 key_name[0] = KS_KEY;
4508 key_name[1] = (key & 0xff);
4509 }
4510 }
4511
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004512 /* Skip all options that are not window-local (used when showing
4513 * an already loaded buffer in a window). */
4514 if ((opt_flags & OPT_WINONLY)
4515 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4516 goto skip;
4517
Bram Moolenaara3227e22006-03-08 21:32:40 +00004518 /* Skip all options that are window-local (used for :vimgrep). */
4519 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4520 && options[opt_idx].var == VAR_WIN)
4521 goto skip;
4522
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004523 /* Disallow changing some options from modelines. */
4524 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004525 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004526 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004527 {
4528 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4529 goto skip;
4530 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004531#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004532 /* In diff mode some options are overruled. This avoids that
4533 * 'foldmethod' becomes "marker" instead of "diff" and that
4534 * "wrap" gets set. */
4535 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004536 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004537 && (
4538#ifdef FEAT_FOLDING
4539 options[opt_idx].indir == PV_FDM ||
4540#endif
4541 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004542 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004543#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004544 }
4545
4546#ifdef HAVE_SANDBOX
4547 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004548 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004549 {
4550 errmsg = (char_u *)_(e_sandbox);
4551 goto skip;
4552 }
4553#endif
4554
4555 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4556 {
4557 arg += len;
4558 cp_val = p_cp;
4559 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4560 {
4561 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4562 {
4563 cp_val = FALSE;
4564 arg += 3;
4565 }
4566 else /* "opt&vi": set to Vi default */
4567 {
4568 cp_val = TRUE;
4569 arg += 2;
4570 }
4571 }
4572 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004573 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004574 {
4575 errmsg = e_trailing;
4576 goto skip;
4577 }
4578 }
4579
4580 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004581 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4582 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004583 */
4584 if (nextchar == '?'
4585 || (prefix == 1
4586 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4587 && !(flags & P_BOOL)))
4588 {
4589 /*
4590 * print value
4591 */
4592 if (did_show)
4593 msg_putchar('\n'); /* cursor below last one */
4594 else
4595 {
4596 gotocmdline(TRUE); /* cursor at status line */
4597 did_show = TRUE; /* remember that we did a line */
4598 }
4599 if (opt_idx >= 0)
4600 {
4601 showoneopt(&options[opt_idx], opt_flags);
4602#ifdef FEAT_EVAL
4603 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004604 {
4605 /* Mention where the option was last set. */
4606 if (varp == options[opt_idx].var)
4607 last_set_msg(options[opt_idx].scriptID);
4608 else if ((int)options[opt_idx].indir & PV_WIN)
4609 last_set_msg(curwin->w_p_scriptID[
4610 (int)options[opt_idx].indir & PV_MASK]);
4611 else if ((int)options[opt_idx].indir & PV_BUF)
4612 last_set_msg(curbuf->b_p_scriptID[
4613 (int)options[opt_idx].indir & PV_MASK]);
4614 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004615#endif
4616 }
4617 else
4618 {
4619 char_u *p;
4620
4621 p = find_termcode(key_name);
4622 if (p == NULL)
4623 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004624 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004625 goto skip;
4626 }
4627 else
4628 (void)show_one_termcode(key_name, p, TRUE);
4629 }
4630 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004631 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004632 errmsg = e_trailing;
4633 }
4634 else
4635 {
4636 if (flags & P_BOOL) /* boolean */
4637 {
4638 if (nextchar == '=' || nextchar == ':')
4639 {
4640 errmsg = e_invarg;
4641 goto skip;
4642 }
4643
4644 /*
4645 * ":set opt!": invert
4646 * ":set opt&": reset to default value
4647 * ":set opt<": reset to global value
4648 */
4649 if (nextchar == '!')
4650 value = *(int *)(varp) ^ 1;
4651 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004652 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004653 ((flags & P_VI_DEF) || cp_val)
4654 ? VI_DEFAULT : VIM_DEFAULT];
4655 else if (nextchar == '<')
4656 {
4657 /* For 'autoread' -1 means to use global value. */
4658 if ((int *)varp == &curbuf->b_p_ar
4659 && opt_flags == OPT_LOCAL)
4660 value = -1;
4661 else
4662 value = *(int *)get_varp_scope(&(options[opt_idx]),
4663 OPT_GLOBAL);
4664 }
4665 else
4666 {
4667 /*
4668 * ":set invopt": invert
4669 * ":set opt" or ":set noopt": set or reset
4670 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004671 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004672 {
4673 errmsg = e_trailing;
4674 goto skip;
4675 }
4676 if (prefix == 2) /* inv */
4677 value = *(int *)(varp) ^ 1;
4678 else
4679 value = prefix;
4680 }
4681
4682 errmsg = set_bool_option(opt_idx, varp, (int)value,
4683 opt_flags);
4684 }
4685 else /* numeric or string */
4686 {
4687 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4688 || prefix != 1)
4689 {
4690 errmsg = e_invarg;
4691 goto skip;
4692 }
4693
4694 if (flags & P_NUM) /* numeric */
4695 {
4696 /*
4697 * Different ways to set a number option:
4698 * & set to default value
4699 * < set to global value
4700 * <xx> accept special key codes for 'wildchar'
4701 * c accept any non-digit for 'wildchar'
4702 * [-]0-9 set number
4703 * other error
4704 */
4705 ++arg;
4706 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004707 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004708 ((flags & P_VI_DEF) || cp_val)
4709 ? VI_DEFAULT : VIM_DEFAULT];
4710 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004711 {
4712 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4713 * use the global value. */
4714 if ((long *)varp == &curbuf->b_p_ul
4715 && opt_flags == OPT_LOCAL)
4716 value = NO_LOCAL_UNDOLEVEL;
4717 else
4718 value = *(long *)get_varp_scope(
4719 &(options[opt_idx]), OPT_GLOBAL);
4720 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004721 else if (((long *)varp == &p_wc
4722 || (long *)varp == &p_wcm)
4723 && (*arg == '<'
4724 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004725 || (*arg != NUL
4726 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004727 && !VIM_ISDIGIT(*arg))))
4728 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004729 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004730 if (value == 0 && (long *)varp != &p_wcm)
4731 {
4732 errmsg = e_invarg;
4733 goto skip;
4734 }
4735 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004736 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4737 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004738 /* Allow negative (for 'undolevels'), octal and
4739 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004740 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4741 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004742 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004743 {
4744 errmsg = e_invarg;
4745 goto skip;
4746 }
4747 }
4748 else
4749 {
4750 errmsg = (char_u *)N_("E521: Number required after =");
4751 goto skip;
4752 }
4753
4754 if (adding)
4755 value = *(long *)varp + value;
4756 if (prepending)
4757 value = *(long *)varp * value;
4758 if (removing)
4759 value = *(long *)varp - value;
4760 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004761 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004762 }
4763 else if (opt_idx >= 0) /* string */
4764 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004765 char_u *save_arg = NULL;
4766 char_u *s = NULL;
4767 char_u *oldval = NULL; /* previous value if *varp */
4768 char_u *newval;
4769 char_u *origval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004770#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004771 char_u *saved_origval = NULL;
4772 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004773#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004774 unsigned newlen;
4775 int comma;
4776 int bs;
4777 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004778 was allocated */
4779
4780 /* When using ":set opt=val" for a global option
4781 * with a local value the local value will be
4782 * reset, use the global value here. */
4783 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004784 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004785 varp = options[opt_idx].var;
4786
4787 /* The old value is kept until we are sure that the
4788 * new value is valid. */
4789 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004790
4791 /* When setting the local value of a global
4792 * option, the old value may be the global value. */
4793 if (((int)options[opt_idx].indir & PV_BOTH)
4794 && (opt_flags & OPT_LOCAL))
4795 origval = *(char_u **)get_varp(
4796 &options[opt_idx]);
4797 else
4798 origval = oldval;
4799
Bram Moolenaar071d4272004-06-13 20:20:40 +00004800 if (nextchar == '&') /* set to default val */
4801 {
4802 newval = options[opt_idx].def_val[
4803 ((flags & P_VI_DEF) || cp_val)
4804 ? VI_DEFAULT : VIM_DEFAULT];
4805 if ((char_u **)varp == &p_bg)
4806 {
4807 /* guess the value of 'background' */
4808#ifdef FEAT_GUI
4809 if (gui.in_use)
4810 newval = gui_bg_default();
4811 else
4812#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004813 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004814 }
4815
4816 /* expand environment variables and ~ (since the
4817 * default value was already expanded, only
4818 * required when an environment variable was set
4819 * later */
4820 if (newval == NULL)
4821 newval = empty_option;
4822 else
4823 {
4824 s = option_expand(opt_idx, newval);
4825 if (s == NULL)
4826 s = newval;
4827 newval = vim_strsave(s);
4828 }
4829 new_value_alloced = TRUE;
4830 }
4831 else if (nextchar == '<') /* set to global val */
4832 {
4833 newval = vim_strsave(*(char_u **)get_varp_scope(
4834 &(options[opt_idx]), OPT_GLOBAL));
4835 new_value_alloced = TRUE;
4836 }
4837 else
4838 {
4839 ++arg; /* jump to after the '=' or ':' */
4840
4841 /*
4842 * Set 'keywordprg' to ":help" if an empty
4843 * value was passed to :set by the user.
4844 * Misuse errbuf[] for the resulting string.
4845 */
4846 if (varp == (char_u *)&p_kp
4847 && (*arg == NUL || *arg == ' '))
4848 {
4849 STRCPY(errbuf, ":help");
4850 save_arg = arg;
4851 arg = errbuf;
4852 }
4853 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004854 * Convert 'backspace' number to string, for
4855 * adding, prepending and removing string.
4856 */
4857 else if (varp == (char_u *)&p_bs
4858 && VIM_ISDIGIT(**(char_u **)varp))
4859 {
4860 i = getdigits((char_u **)varp);
4861 switch (i)
4862 {
4863 case 0:
4864 *(char_u **)varp = empty_option;
4865 break;
4866 case 1:
4867 *(char_u **)varp = vim_strsave(
4868 (char_u *)"indent,eol");
4869 break;
4870 case 2:
4871 *(char_u **)varp = vim_strsave(
4872 (char_u *)"indent,eol,start");
4873 break;
4874 }
4875 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004876 if (origval == oldval)
4877 origval = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004878 oldval = *(char_u **)varp;
4879 }
4880 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004881 * Convert 'whichwrap' number to string, for
4882 * backwards compatibility with Vim 3.0.
4883 * Misuse errbuf[] for the resulting string.
4884 */
4885 else if (varp == (char_u *)&p_ww
4886 && VIM_ISDIGIT(*arg))
4887 {
4888 *errbuf = NUL;
4889 i = getdigits(&arg);
4890 if (i & 1)
4891 STRCAT(errbuf, "b,");
4892 if (i & 2)
4893 STRCAT(errbuf, "s,");
4894 if (i & 4)
4895 STRCAT(errbuf, "h,l,");
4896 if (i & 8)
4897 STRCAT(errbuf, "<,>,");
4898 if (i & 16)
4899 STRCAT(errbuf, "[,],");
4900 if (*errbuf != NUL) /* remove trailing , */
4901 errbuf[STRLEN(errbuf) - 1] = NUL;
4902 save_arg = arg;
4903 arg = errbuf;
4904 }
4905 /*
4906 * Remove '>' before 'dir' and 'bdir', for
4907 * backwards compatibility with version 3.0
4908 */
4909 else if ( *arg == '>'
4910 && (varp == (char_u *)&p_dir
4911 || varp == (char_u *)&p_bdir))
4912 {
4913 ++arg;
4914 }
4915
Bram Moolenaar071d4272004-06-13 20:20:40 +00004916 /*
4917 * Copy the new string into allocated memory.
4918 * Can't use set_string_option_direct(), because
4919 * we need to remove the backslashes.
4920 */
4921 /* get a bit too much */
4922 newlen = (unsigned)STRLEN(arg) + 1;
4923 if (adding || prepending || removing)
4924 newlen += (unsigned)STRLEN(origval) + 1;
4925 newval = alloc(newlen);
4926 if (newval == NULL) /* out of mem, don't change */
4927 break;
4928 s = newval;
4929
4930 /*
4931 * Copy the string, skip over escaped chars.
4932 * For MS-DOS and WIN32 backslashes before normal
4933 * file name characters are not removed, and keep
4934 * backslash at start, for "\\machine\path", but
4935 * do remove it for "\\\\machine\\path".
4936 * The reverse is found in ExpandOldSetting().
4937 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004938 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004939 {
4940 if (*arg == '\\' && arg[1] != NUL
4941#ifdef BACKSLASH_IN_FILENAME
4942 && !((flags & P_EXPAND)
4943 && vim_isfilec(arg[1])
4944 && (arg[1] != '\\'
4945 || (s == newval
4946 && arg[2] != '\\')))
4947#endif
4948 )
4949 ++arg; /* remove backslash */
4950#ifdef FEAT_MBYTE
4951 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004952 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004953 {
4954 /* copy multibyte char */
4955 mch_memmove(s, arg, (size_t)i);
4956 arg += i;
4957 s += i;
4958 }
4959 else
4960#endif
4961 *s++ = *arg++;
4962 }
4963 *s = NUL;
4964
4965 /*
4966 * Expand environment variables and ~.
4967 * Don't do it when adding without inserting a
4968 * comma.
4969 */
4970 if (!(adding || prepending || removing)
4971 || (flags & P_COMMA))
4972 {
4973 s = option_expand(opt_idx, newval);
4974 if (s != NULL)
4975 {
4976 vim_free(newval);
4977 newlen = (unsigned)STRLEN(s) + 1;
4978 if (adding || prepending || removing)
4979 newlen += (unsigned)STRLEN(origval) + 1;
4980 newval = alloc(newlen);
4981 if (newval == NULL)
4982 break;
4983 STRCPY(newval, s);
4984 }
4985 }
4986
4987 /* locate newval[] in origval[] when removing it
4988 * and when adding to avoid duplicates */
4989 i = 0; /* init for GCC */
4990 if (removing || (flags & P_NODUP))
4991 {
4992 i = (int)STRLEN(newval);
4993 bs = 0;
4994 for (s = origval; *s; ++s)
4995 {
4996 if ((!(flags & P_COMMA)
4997 || s == origval
4998 || (s[-1] == ',' && !(bs & 1)))
4999 && STRNCMP(s, newval, i) == 0
5000 && (!(flags & P_COMMA)
5001 || s[i] == ','
5002 || s[i] == NUL))
5003 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005004 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005005 * even number of backslashes or a single
5006 * backslash preceded by a comma before it
5007 * is recognized as a separator */
5008 if ((s > origval + 1
5009 && s[-1] == '\\'
5010 && s[-2] != ',')
5011 || (s == origval + 1
5012 && s[-1] == '\\'))
5013
Bram Moolenaar071d4272004-06-13 20:20:40 +00005014 ++bs;
5015 else
5016 bs = 0;
5017 }
5018
5019 /* do not add if already there */
5020 if ((adding || prepending) && *s)
5021 {
5022 prepending = FALSE;
5023 adding = FALSE;
5024 STRCPY(newval, origval);
5025 }
5026 }
5027
5028 /* concatenate the two strings; add a ',' if
5029 * needed */
5030 if (adding || prepending)
5031 {
5032 comma = ((flags & P_COMMA) && *origval != NUL
5033 && *newval != NUL);
5034 if (adding)
5035 {
5036 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005037 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005038 if (comma && i > 1
5039 && (flags & P_ONECOMMA) == P_ONECOMMA
5040 && origval[i - 1] == ','
5041 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005042 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005043 mch_memmove(newval + i + comma, newval,
5044 STRLEN(newval) + 1);
5045 mch_memmove(newval, origval, (size_t)i);
5046 }
5047 else
5048 {
5049 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005050 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005051 }
5052 if (comma)
5053 newval[i] = ',';
5054 }
5055
5056 /* Remove newval[] from origval[]. (Note: "i" has
5057 * been set above and is used here). */
5058 if (removing)
5059 {
5060 STRCPY(newval, origval);
5061 if (*s)
5062 {
5063 /* may need to remove a comma */
5064 if (flags & P_COMMA)
5065 {
5066 if (s == origval)
5067 {
5068 /* include comma after string */
5069 if (s[i] == ',')
5070 ++i;
5071 }
5072 else
5073 {
5074 /* include comma before string */
5075 --s;
5076 ++i;
5077 }
5078 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005079 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005080 }
5081 }
5082
5083 if (flags & P_FLAGLIST)
5084 {
5085 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005086 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005087 {
5088 /* if options have P_FLAGLIST and
5089 * P_ONECOMMA such as 'whichwrap' */
5090 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005091 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005092 if (*s != ',' && *(s + 1) == ','
5093 && vim_strchr(s + 2, *s) != NULL)
5094 {
5095 /* Remove the duplicated value and
5096 * the next comma. */
5097 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005098 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005099 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005100 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005101 else
5102 {
5103 if ((!(flags & P_COMMA) || *s != ',')
5104 && vim_strchr(s + 1, *s) != NULL)
5105 {
5106 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005107 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005108 }
5109 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005110 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005111 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005112 }
5113
5114 if (save_arg != NULL) /* number for 'whichwrap' */
5115 arg = save_arg;
5116 new_value_alloced = TRUE;
5117 }
5118
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005119 /*
5120 * Set the new value.
5121 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005122 *(char_u **)(varp) = newval;
5123
Bram Moolenaar53744302015-07-17 17:38:22 +02005124#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005125 if (!starting
5126# ifdef FEAT_CRYPT
5127 && options[opt_idx].indir != PV_KEY
5128# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005129 && origval != NULL && newval != NULL)
5130 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005131 /* origval may be freed by
5132 * did_set_string_option(), make a copy. */
5133 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005134 /* newval (and varp) may become invalid if the
5135 * buffer is closed by autocommands. */
5136 saved_newval = vim_strsave(newval);
5137 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005138#endif
5139
Bram Moolenaar071d4272004-06-13 20:20:40 +00005140 /* Handle side effects, and set the global value for
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005141 * ":set" on local options. Note: when setting 'syntax'
5142 * or 'filetype' autocommands may be triggered that can
5143 * cause havoc. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005144 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5145 new_value_alloced, oldval, errbuf, opt_flags);
5146
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005147#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5148 if (errmsg == NULL)
5149 trigger_optionsset_string(opt_idx, opt_flags,
5150 saved_origval, saved_newval);
5151 vim_free(saved_origval);
5152 vim_free(saved_newval);
5153#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005154 /* If error detected, print the error message. */
5155 if (errmsg != NULL)
5156 goto skip;
5157 }
5158 else /* key code option */
5159 {
5160 char_u *p;
5161
5162 if (nextchar == '&')
5163 {
5164 if (add_termcap_entry(key_name, TRUE) == FAIL)
5165 errmsg = (char_u *)N_("E522: Not found in termcap");
5166 }
5167 else
5168 {
5169 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005170 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005171 if (*p == '\\' && p[1] != NUL)
5172 ++p;
5173 nextchar = *p;
5174 *p = NUL;
5175 add_termcode(key_name, arg, FALSE);
5176 *p = nextchar;
5177 }
5178 if (full_screen)
5179 ttest(FALSE);
5180 redraw_all_later(CLEAR);
5181 }
5182 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005183
Bram Moolenaar071d4272004-06-13 20:20:40 +00005184 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005185 did_set_option(opt_idx, opt_flags,
5186 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005187 }
5188
5189skip:
5190 /*
5191 * Advance to next argument.
5192 * - skip until a blank found, taking care of backslashes
5193 * - skip blanks
5194 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5195 */
5196 for (i = 0; i < 2 ; ++i)
5197 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005198 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005199 if (*arg++ == '\\' && *arg != NUL)
5200 ++arg;
5201 arg = skipwhite(arg);
5202 if (*arg != '=')
5203 break;
5204 }
5205 }
5206
5207 if (errmsg != NULL)
5208 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005209 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005210 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005211 if (i + (arg - startarg) < IOSIZE)
5212 {
5213 /* append the argument with the error */
5214 STRCAT(IObuff, ": ");
5215 mch_memmove(IObuff + i, startarg, (arg - startarg));
5216 IObuff[i + (arg - startarg)] = NUL;
5217 }
5218 /* make sure all characters are printable */
5219 trans_characters(IObuff, IOSIZE);
5220
5221 ++no_wait_return; /* wait_return done later */
5222 emsg(IObuff); /* show error highlighted */
5223 --no_wait_return;
5224
5225 return FAIL;
5226 }
5227
5228 arg = skipwhite(arg);
5229 }
5230
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005231theend:
5232 if (silent_mode && did_show)
5233 {
5234 /* After displaying option values in silent mode. */
5235 silent_mode = FALSE;
5236 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5237 msg_putchar('\n');
5238 cursor_on(); /* msg_start() switches it off */
5239 out_flush();
5240 silent_mode = TRUE;
5241 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5242 }
5243
Bram Moolenaar071d4272004-06-13 20:20:40 +00005244 return OK;
5245}
5246
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005247/*
5248 * Call this when an option has been given a new value through a user command.
5249 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5250 */
5251 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005252did_set_option(
5253 int opt_idx,
5254 int opt_flags, /* possibly with OPT_MODELINE */
5255 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005256{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005257 long_u *p;
5258
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005259 options[opt_idx].flags |= P_WAS_SET;
5260
5261 /* When an option is set in the sandbox, from a modeline or in secure mode
5262 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005263 * flag. */
5264 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005265 if (secure
5266#ifdef HAVE_SANDBOX
5267 || sandbox != 0
5268#endif
5269 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005270 *p = *p | P_INSECURE;
5271 else if (new_value)
5272 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005273}
5274
Bram Moolenaar071d4272004-06-13 20:20:40 +00005275 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005276illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005277{
5278 if (errbuf == NULL)
5279 return (char_u *)"";
5280 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005281 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005282 return errbuf;
5283}
5284
5285/*
5286 * Convert a key name or string into a key value.
5287 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005288 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005289 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005290 int
5291string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005292{
5293 if (*arg == '<')
5294 return find_key_option(arg + 1);
5295 if (*arg == '^')
5296 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005297 if (multi_byte)
5298 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005299 return *arg;
5300}
5301
5302#ifdef FEAT_CMDWIN
5303/*
5304 * Check value of 'cedit' and set cedit_key.
5305 * Returns NULL if value is OK, error message otherwise.
5306 */
5307 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005308check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005309{
5310 int n;
5311
5312 if (*p_cedit == NUL)
5313 cedit_key = -1;
5314 else
5315 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005316 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005317 if (vim_isprintc(n))
5318 return e_invarg;
5319 cedit_key = n;
5320 }
5321 return NULL;
5322}
5323#endif
5324
5325#ifdef FEAT_TITLE
5326/*
5327 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5328 * maketitle() to create and display it.
5329 * When switching the title or icon off, call mch_restore_title() to get
5330 * the old value back.
5331 */
5332 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005333did_set_title(
5334 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005335{
5336 if (starting != NO_SCREEN
5337#ifdef FEAT_GUI
5338 && !gui.starting
5339#endif
5340 )
5341 {
5342 maketitle();
5343 if (icon)
5344 {
5345 if (!p_icon)
5346 mch_restore_title(2);
5347 }
5348 else
5349 {
5350 if (!p_title)
5351 mch_restore_title(1);
5352 }
5353 }
5354}
5355#endif
5356
5357/*
5358 * set_options_bin - called when 'bin' changes value.
5359 */
5360 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005361set_options_bin(
5362 int oldval,
5363 int newval,
5364 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005365{
5366 /*
5367 * The option values that are changed when 'bin' changes are
5368 * copied when 'bin is set and restored when 'bin' is reset.
5369 */
5370 if (newval)
5371 {
5372 if (!oldval) /* switched on */
5373 {
5374 if (!(opt_flags & OPT_GLOBAL))
5375 {
5376 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5377 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5378 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5379 curbuf->b_p_et_nobin = curbuf->b_p_et;
5380 }
5381 if (!(opt_flags & OPT_LOCAL))
5382 {
5383 p_tw_nobin = p_tw;
5384 p_wm_nobin = p_wm;
5385 p_ml_nobin = p_ml;
5386 p_et_nobin = p_et;
5387 }
5388 }
5389
5390 if (!(opt_flags & OPT_GLOBAL))
5391 {
5392 curbuf->b_p_tw = 0; /* no automatic line wrap */
5393 curbuf->b_p_wm = 0; /* no automatic line wrap */
5394 curbuf->b_p_ml = 0; /* no modelines */
5395 curbuf->b_p_et = 0; /* no expandtab */
5396 }
5397 if (!(opt_flags & OPT_LOCAL))
5398 {
5399 p_tw = 0;
5400 p_wm = 0;
5401 p_ml = FALSE;
5402 p_et = FALSE;
5403 p_bin = TRUE; /* needed when called for the "-b" argument */
5404 }
5405 }
5406 else if (oldval) /* switched off */
5407 {
5408 if (!(opt_flags & OPT_GLOBAL))
5409 {
5410 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5411 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5412 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5413 curbuf->b_p_et = curbuf->b_p_et_nobin;
5414 }
5415 if (!(opt_flags & OPT_LOCAL))
5416 {
5417 p_tw = p_tw_nobin;
5418 p_wm = p_wm_nobin;
5419 p_ml = p_ml_nobin;
5420 p_et = p_et_nobin;
5421 }
5422 }
5423}
5424
5425#ifdef FEAT_VIMINFO
5426/*
5427 * Find the parameter represented by the given character (eg ', :, ", or /),
5428 * and return its associated value in the 'viminfo' string.
5429 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005430 * If the parameter is not specified in the string or there is no following
5431 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005432 */
5433 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005434get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005435{
5436 char_u *p;
5437
5438 p = find_viminfo_parameter(type);
5439 if (p != NULL && VIM_ISDIGIT(*p))
5440 return atoi((char *)p);
5441 return -1;
5442}
5443
5444/*
5445 * Find the parameter represented by the given character (eg ''', ':', '"', or
5446 * '/') in the 'viminfo' option and return a pointer to the string after it.
5447 * Return NULL if the parameter is not specified in the string.
5448 */
5449 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005450find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005451{
5452 char_u *p;
5453
5454 for (p = p_viminfo; *p; ++p)
5455 {
5456 if (*p == type)
5457 return p + 1;
5458 if (*p == 'n') /* 'n' is always the last one */
5459 break;
5460 p = vim_strchr(p, ','); /* skip until next ',' */
5461 if (p == NULL) /* hit the end without finding parameter */
5462 break;
5463 }
5464 return NULL;
5465}
5466#endif
5467
5468/*
5469 * Expand environment variables for some string options.
5470 * These string options cannot be indirect!
5471 * If "val" is NULL expand the current value of the option.
5472 * Return pointer to NameBuff, or NULL when not expanded.
5473 */
5474 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005475option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005476{
5477 /* if option doesn't need expansion nothing to do */
5478 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5479 return NULL;
5480
5481 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5482 * expand_env() would truncate the string. */
5483 if (val != NULL && STRLEN(val) > MAXPATHL)
5484 return NULL;
5485
5486 if (val == NULL)
5487 val = *(char_u **)options[opt_idx].var;
5488
5489 /*
5490 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5491 * Escape spaces when expanding 'tags', they are used to separate file
5492 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005493 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005494 */
5495 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005496 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005497#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005498 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5499#endif
5500 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005501 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5502 return NULL;
5503
5504 return NameBuff;
5505}
5506
5507/*
5508 * After setting various option values: recompute variables that depend on
5509 * option values.
5510 */
5511 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005512didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005513{
5514 /* initialize the table for 'iskeyword' et.al. */
5515 (void)init_chartab();
5516
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005517#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005518 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005519#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005520 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005521 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005522#ifdef FEAT_SESSION
5523 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5524 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5525#endif
5526#ifdef FEAT_FOLDING
5527 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5528#endif
5529 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005530 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005531#ifdef FEAT_VIRTUALEDIT
5532 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5533#endif
5534#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5535 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5536#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005537#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005538 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005539 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005540 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005541 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005542#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005543#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5544 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5545#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005546#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005547 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5548#endif
5549#ifdef FEAT_CMDWIN
5550 /* set cedit_key */
5551 (void)check_cedit();
5552#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005553#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005554 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005555#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005556#ifdef FEAT_LINEBREAK
5557 /* initialize the table for 'breakat'. */
5558 fill_breakat_flags();
5559#endif
5560
5561}
5562
5563/*
5564 * More side effects of setting options.
5565 */
5566 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005567didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005568{
5569 /* Initialize the highlight_attr[] table. */
5570 (void)highlight_changed();
5571
5572 /* Parse default for 'wildmode' */
5573 check_opt_wim();
5574
5575 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005576 /* Parse default for 'fillchars'. */
5577 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005578
5579#ifdef FEAT_CLIPBOARD
5580 /* Parse default for 'clipboard' */
5581 (void)check_clipboard_option();
5582#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005583}
5584
5585/*
5586 * Check for string options that are NULL (normally only termcap options).
5587 */
5588 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005589check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005590{
5591 int opt_idx;
5592
5593 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5594 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5595 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5596}
5597
5598/*
5599 * Check string options in a buffer for NULL value.
5600 */
5601 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005602check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005603{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005604 check_string_option(&buf->b_p_bh);
5605 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005606#ifdef FEAT_MBYTE
5607 check_string_option(&buf->b_p_fenc);
5608#endif
5609 check_string_option(&buf->b_p_ff);
5610#ifdef FEAT_FIND_ID
5611 check_string_option(&buf->b_p_def);
5612 check_string_option(&buf->b_p_inc);
5613# ifdef FEAT_EVAL
5614 check_string_option(&buf->b_p_inex);
5615# endif
5616#endif
5617#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5618 check_string_option(&buf->b_p_inde);
5619 check_string_option(&buf->b_p_indk);
5620#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005621#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5622 check_string_option(&buf->b_p_bexpr);
5623#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005624#if defined(FEAT_CRYPT)
5625 check_string_option(&buf->b_p_cm);
5626#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005627 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005628#if defined(FEAT_EVAL)
5629 check_string_option(&buf->b_p_fex);
5630#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005631#ifdef FEAT_CRYPT
5632 check_string_option(&buf->b_p_key);
5633#endif
5634 check_string_option(&buf->b_p_kp);
5635 check_string_option(&buf->b_p_mps);
5636 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005637 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005638 check_string_option(&buf->b_p_isk);
5639#ifdef FEAT_COMMENTS
5640 check_string_option(&buf->b_p_com);
5641#endif
5642#ifdef FEAT_FOLDING
5643 check_string_option(&buf->b_p_cms);
5644#endif
5645 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005646#ifdef FEAT_TEXTOBJ
5647 check_string_option(&buf->b_p_qe);
5648#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005649#ifdef FEAT_SYN_HL
5650 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005651 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005652#endif
5653#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005654 check_string_option(&buf->b_s.b_p_spc);
5655 check_string_option(&buf->b_s.b_p_spf);
5656 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005657#endif
5658#ifdef FEAT_SEARCHPATH
5659 check_string_option(&buf->b_p_sua);
5660#endif
5661#ifdef FEAT_CINDENT
5662 check_string_option(&buf->b_p_cink);
5663 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005664 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005665#endif
5666#ifdef FEAT_AUTOCMD
5667 check_string_option(&buf->b_p_ft);
5668#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005669#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5670 check_string_option(&buf->b_p_cinw);
5671#endif
5672#ifdef FEAT_INS_EXPAND
5673 check_string_option(&buf->b_p_cpt);
5674#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005675#ifdef FEAT_COMPL_FUNC
5676 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005677 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005678#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005679#ifdef FEAT_KEYMAP
5680 check_string_option(&buf->b_p_keymap);
5681#endif
5682#ifdef FEAT_QUICKFIX
5683 check_string_option(&buf->b_p_gp);
5684 check_string_option(&buf->b_p_mp);
5685 check_string_option(&buf->b_p_efm);
5686#endif
5687 check_string_option(&buf->b_p_ep);
5688 check_string_option(&buf->b_p_path);
5689 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005690 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005691#ifdef FEAT_INS_EXPAND
5692 check_string_option(&buf->b_p_dict);
5693 check_string_option(&buf->b_p_tsr);
5694#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005695#ifdef FEAT_LISP
5696 check_string_option(&buf->b_p_lw);
5697#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005698 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005699#ifdef FEAT_MBYTE
5700 check_string_option(&buf->b_p_menc);
5701#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005702}
5703
5704/*
5705 * Free the string allocated for an option.
5706 * Checks for the string being empty_option. This may happen if we're out of
5707 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5708 * check_options().
5709 * Does NOT check for P_ALLOCED flag!
5710 */
5711 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005712free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005713{
5714 if (p != empty_option)
5715 vim_free(p);
5716}
5717
5718 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005719clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005720{
5721 if (*pp != empty_option)
5722 vim_free(*pp);
5723 *pp = empty_option;
5724}
5725
5726 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005727check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005728{
5729 if (*pp == NULL)
5730 *pp = empty_option;
5731}
5732
5733/*
5734 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5735 */
5736 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005737set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005738{
5739 int opt_idx;
5740
5741 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5742 if (options[opt_idx].var == (char_u *)p)
5743 {
5744 options[opt_idx].flags |= P_ALLOCED;
5745 return;
5746 }
5747 return; /* cannot happen: didn't find it! */
5748}
5749
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005750#if defined(FEAT_EVAL) || defined(PROTO)
5751/*
5752 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5753 * Return FALSE when it wasn't.
5754 * Return -1 for an unknown option.
5755 */
5756 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005757was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005758{
5759 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005760 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005761
5762 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005763 {
5764 flagp = insecure_flag(idx, opt_flags);
5765 return (*flagp & P_INSECURE) != 0;
5766 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005767 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005768 return -1;
5769}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005770
5771/*
5772 * Get a pointer to the flags used for the P_INSECURE flag of option
5773 * "opt_idx". For some local options a local flags field is used.
5774 */
5775 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005776insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005777{
5778 if (opt_flags & OPT_LOCAL)
5779 switch ((int)options[opt_idx].indir)
5780 {
5781#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005782 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005783#endif
5784#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005785# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005786 case PV_FDE: return &curwin->w_p_fde_flags;
5787 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005788# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005789# ifdef FEAT_BEVAL
5790 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5791# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005792# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005793 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005794# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005795 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005796# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005797 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005798# endif
5799#endif
5800 }
5801
5802 /* Nothing special, return global flags field. */
5803 return &options[opt_idx].flags;
5804}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005805#endif
5806
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005807#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005808static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005809
5810/*
5811 * Redraw the window title and/or tab page text later.
5812 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005813static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005814{
5815 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005816 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005817}
5818#endif
5819
Bram Moolenaar071d4272004-06-13 20:20:40 +00005820/*
5821 * Set a string option to a new value (without checking the effect).
5822 * The string is copied into allocated memory.
5823 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005824 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005825 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005826 */
5827 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005828set_string_option_direct(
5829 char_u *name,
5830 int opt_idx,
5831 char_u *val,
5832 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5833 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005834{
5835 char_u *s;
5836 char_u **varp;
5837 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005838 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005839
Bram Moolenaar89d40322006-08-29 15:30:07 +00005840 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005841 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005842 idx = findoption(name);
5843 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005844 {
5845 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005846 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005847 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005848 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005849 }
5850
Bram Moolenaar89d40322006-08-29 15:30:07 +00005851 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005852 return;
5853
5854 s = vim_strsave(val);
5855 if (s != NULL)
5856 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005857 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005858 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005859 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005860 free_string_option(*varp);
5861 *varp = s;
5862
5863 /* For buffer/window local option may also set the global value. */
5864 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005865 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005866
Bram Moolenaar89d40322006-08-29 15:30:07 +00005867 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005868
5869 /* When setting both values of a global option with a local value,
5870 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005871 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005872 {
5873 free_string_option(*varp);
5874 *varp = empty_option;
5875 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005876# ifdef FEAT_EVAL
5877 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005878 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005879 set_sid == 0 ? current_SID : set_sid);
5880# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005881 }
5882}
5883
5884/*
5885 * Set global value for string option when it's a local option.
5886 */
5887 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005888set_string_option_global(
5889 int opt_idx, /* option index */
5890 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005891{
5892 char_u **p, *s;
5893
5894 /* the global value is always allocated */
5895 if (options[opt_idx].var == VAR_WIN)
5896 p = (char_u **)GLOBAL_WO(varp);
5897 else
5898 p = (char_u **)options[opt_idx].var;
5899 if (options[opt_idx].indir != PV_NONE
5900 && p != varp
5901 && (s = vim_strsave(*varp)) != NULL)
5902 {
5903 free_string_option(*p);
5904 *p = s;
5905 }
5906}
5907
5908/*
5909 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005910 *
5911 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005912 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005913 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005914set_string_option(
5915 int opt_idx,
5916 char_u *value,
5917 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005918{
5919 char_u *s;
5920 char_u **varp;
5921 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005922#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5923 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005924 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02005925#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005926 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005927
5928 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005929 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005930
5931 s = vim_strsave(value);
5932 if (s != NULL)
5933 {
5934 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5935 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005936 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005937 ? OPT_GLOBAL : OPT_LOCAL)
5938 : opt_flags);
5939 oldval = *varp;
5940 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005941
5942#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005943 if (!starting
5944# ifdef FEAT_CRYPT
5945 && options[opt_idx].indir != PV_KEY
5946# endif
5947 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005948 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005949 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005950 saved_newval = vim_strsave(s);
5951 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005952#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005953 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5954 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005955 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005956
Bram Moolenaar53744302015-07-17 17:38:22 +02005957#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005958 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005959 if (r == NULL)
5960 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005961 saved_oldval, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005962 vim_free(saved_oldval);
5963 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02005964#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005965 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005966 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005967}
5968
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005969#if defined(FEAT_KEYMAP) || defined(FEAT_AUTOCMD) || defined(FEAT_SYN_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005970/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01005971 * Return TRUE if "val" is a valid 'filetype' name.
5972 * Also used for 'syntax' and 'keymap'.
5973 */
5974 static int
5975valid_filetype(char_u *val)
5976{
5977 char_u *s;
5978
5979 for (s = val; *s != NUL; ++s)
5980 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
5981 return FALSE;
5982 return TRUE;
5983}
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005984#endif
Bram Moolenaard0b51382016-11-04 15:23:45 +01005985
5986/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00005987 * Handle string options that need some action to perform when changed.
5988 * Returns NULL for success, or an error message for an error.
5989 */
5990 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005991did_set_string_option(
5992 int opt_idx, /* index in options[] table */
5993 char_u **varp, /* pointer to the option variable */
5994 int new_value_alloced, /* new value was allocated */
5995 char_u *oldval, /* previous value of the option */
5996 char_u *errbuf, /* buffer for errors, or NULL */
5997 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005998{
5999 char_u *errmsg = NULL;
6000 char_u *s, *p;
6001 int did_chartab = FALSE;
6002 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006003 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006004#ifdef FEAT_GUI
6005 /* set when changing an option that only requires a redraw in the GUI */
6006 int redraw_gui_only = FALSE;
6007#endif
Bram Moolenaar90492982017-06-22 14:16:31 +02006008#ifdef FEAT_AUTOCMD
6009 int ft_changed = FALSE;
6010#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006011
6012 /* Get the global option to compare with, otherwise we would have to check
6013 * two values for all local options. */
6014 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6015
6016 /* Disallow changing some options from secure mode */
6017 if ((secure
6018#ifdef HAVE_SANDBOX
6019 || sandbox != 0
6020#endif
6021 ) && (options[opt_idx].flags & P_SECURE))
6022 {
6023 errmsg = e_secure;
6024 }
6025
Bram Moolenaar7554da42016-11-25 22:04:13 +01006026 /* Check for a "normal" directory or file name in some options. Disallow a
6027 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006028 * are often illegal in a file name. Be more permissive if "secure" is off.
6029 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01006030 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006031 && vim_strpbrk(*varp, (char_u *)(secure
6032 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006033 || ((options[opt_idx].flags & P_NDNAME)
6034 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006035 {
6036 errmsg = e_invarg;
6037 }
6038
Bram Moolenaar071d4272004-06-13 20:20:40 +00006039 /* 'term' */
6040 else if (varp == &T_NAME)
6041 {
6042 if (T_NAME[0] == NUL)
6043 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
6044#ifdef FEAT_GUI
6045 if (gui.in_use)
6046 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
6047 else if (term_is_gui(T_NAME))
6048 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
6049#endif
6050 else if (set_termname(T_NAME) == FAIL)
6051 errmsg = (char_u *)N_("E522: Not found in termcap");
6052 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006053 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006054 /* Screen colors may have changed. */
6055 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006056
6057 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6058 * P_ALLOCED flag on 'term'. */
6059 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006060 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006061 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006062 }
6063
6064 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006065 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006066 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006067 char_u *bkc = p_bkc;
6068 unsigned int *flags = &bkc_flags;
6069
6070 if (opt_flags & OPT_LOCAL)
6071 {
6072 bkc = curbuf->b_p_bkc;
6073 flags = &curbuf->b_bkc_flags;
6074 }
6075
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006076 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6077 /* make the local value empty: use the global value */
6078 *flags = 0;
6079 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006080 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006081 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6082 errmsg = e_invarg;
6083 if ((((int)*flags & BKC_AUTO) != 0)
6084 + (((int)*flags & BKC_YES) != 0)
6085 + (((int)*flags & BKC_NO) != 0) != 1)
6086 {
6087 /* Must have exactly one of "auto", "yes" and "no". */
6088 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6089 errmsg = e_invarg;
6090 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006091 }
6092 }
6093
6094 /* 'backupext' and 'patchmode' */
6095 else if (varp == &p_bex || varp == &p_pm)
6096 {
6097 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6098 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6099 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
6100 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006101#ifdef FEAT_LINEBREAK
6102 /* 'breakindentopt' */
6103 else if (varp == &curwin->w_p_briopt)
6104 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006105 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006106 errmsg = e_invarg;
6107 }
6108#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006109
6110 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006111 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006112 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006113 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006114 */
6115 else if ( varp == &p_isi
6116 || varp == &(curbuf->b_p_isk)
6117 || varp == &p_isp
6118 || varp == &p_isf)
6119 {
6120 if (init_chartab() == FAIL)
6121 {
6122 did_chartab = TRUE; /* need to restore it below */
6123 errmsg = e_invarg; /* error in value */
6124 }
6125 }
6126
6127 /* 'helpfile' */
6128 else if (varp == &p_hf)
6129 {
6130 /* May compute new values for $VIM and $VIMRUNTIME */
6131 if (didset_vim)
6132 {
6133 vim_setenv((char_u *)"VIM", (char_u *)"");
6134 didset_vim = FALSE;
6135 }
6136 if (didset_vimruntime)
6137 {
6138 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6139 didset_vimruntime = FALSE;
6140 }
6141 }
6142
Bram Moolenaar1a384422010-07-14 19:53:30 +02006143#ifdef FEAT_SYN_HL
6144 /* 'colorcolumn' */
6145 else if (varp == &curwin->w_p_cc)
6146 errmsg = check_colorcolumn(curwin);
6147#endif
6148
Bram Moolenaar071d4272004-06-13 20:20:40 +00006149#ifdef FEAT_MULTI_LANG
6150 /* 'helplang' */
6151 else if (varp == &p_hlg)
6152 {
6153 /* Check for "", "ab", "ab,cd", etc. */
6154 for (s = p_hlg; *s != NUL; s += 3)
6155 {
6156 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6157 {
6158 errmsg = e_invarg;
6159 break;
6160 }
6161 if (s[2] == NUL)
6162 break;
6163 }
6164 }
6165#endif
6166
6167 /* 'highlight' */
6168 else if (varp == &p_hl)
6169 {
6170 if (highlight_changed() == FAIL)
6171 errmsg = e_invarg; /* invalid flags */
6172 }
6173
6174 /* 'nrformats' */
6175 else if (gvarp == &p_nf)
6176 {
6177 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6178 errmsg = e_invarg;
6179 }
6180
6181#ifdef FEAT_SESSION
6182 /* 'sessionoptions' */
6183 else if (varp == &p_ssop)
6184 {
6185 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6186 errmsg = e_invarg;
6187 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6188 {
6189 /* Don't allow both "sesdir" and "curdir". */
6190 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6191 errmsg = e_invarg;
6192 }
6193 }
6194 /* 'viewoptions' */
6195 else if (varp == &p_vop)
6196 {
6197 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6198 errmsg = e_invarg;
6199 }
6200#endif
6201
6202 /* 'scrollopt' */
6203#ifdef FEAT_SCROLLBIND
6204 else if (varp == &p_sbo)
6205 {
6206 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6207 errmsg = e_invarg;
6208 }
6209#endif
6210
6211 /* 'ambiwidth' */
6212#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006213 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006214 {
6215 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6216 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006217 else if (set_chars_option(&p_lcs) != NULL)
6218 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006219 else if (set_chars_option(&p_fcs) != NULL)
6220 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006221 }
6222#endif
6223
6224 /* 'background' */
6225 else if (varp == &p_bg)
6226 {
6227 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6228 {
6229#ifdef FEAT_EVAL
6230 int dark = (*p_bg == 'd');
6231#endif
6232
6233 init_highlight(FALSE, FALSE);
6234
6235#ifdef FEAT_EVAL
6236 if (dark != (*p_bg == 'd')
6237 && get_var_value((char_u *)"g:colors_name") != NULL)
6238 {
6239 /* The color scheme must have set 'background' back to another
6240 * value, that's not what we want here. Disable the color
6241 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006242 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006243 free_string_option(p_bg);
6244 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6245 check_string_option(&p_bg);
6246 init_highlight(FALSE, FALSE);
6247 }
6248#endif
6249 }
6250 else
6251 errmsg = e_invarg;
6252 }
6253
6254 /* 'wildmode' */
6255 else if (varp == &p_wim)
6256 {
6257 if (check_opt_wim() == FAIL)
6258 errmsg = e_invarg;
6259 }
6260
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006261#ifdef FEAT_CMDL_COMPL
6262 /* 'wildoptions' */
6263 else if (varp == &p_wop)
6264 {
6265 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6266 errmsg = e_invarg;
6267 }
6268#endif
6269
Bram Moolenaar071d4272004-06-13 20:20:40 +00006270#ifdef FEAT_WAK
6271 /* 'winaltkeys' */
6272 else if (varp == &p_wak)
6273 {
6274 if (*p_wak == NUL
6275 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6276 errmsg = e_invarg;
6277# ifdef FEAT_MENU
6278# ifdef FEAT_GUI_MOTIF
6279 else if (gui.in_use)
6280 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6281# else
6282# ifdef FEAT_GUI_GTK
6283 else if (gui.in_use)
6284 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6285# endif
6286# endif
6287# endif
6288 }
6289#endif
6290
6291#ifdef FEAT_AUTOCMD
6292 /* 'eventignore' */
6293 else if (varp == &p_ei)
6294 {
6295 if (check_ei() == FAIL)
6296 errmsg = e_invarg;
6297 }
6298#endif
6299
6300#ifdef FEAT_MBYTE
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006301 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6302 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6303 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006304 {
6305 if (gvarp == &p_fenc)
6306 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006307 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006308 errmsg = e_modifiable;
6309 else if (vim_strchr(*varp, ',') != NULL)
6310 /* No comma allowed in 'fileencoding'; catches confusing it
6311 * with 'fileencodings'. */
6312 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006313 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006314 {
6315# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006316 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006317 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006318# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006319 /* Add 'fileencoding' to the swap file. */
6320 ml_setflags(curbuf);
6321 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006322 }
6323 if (errmsg == NULL)
6324 {
6325 /* canonize the value, so that STRCMP() can be used on it */
6326 p = enc_canonize(*varp);
6327 if (p != NULL)
6328 {
6329 vim_free(*varp);
6330 *varp = p;
6331 }
6332 if (varp == &p_enc)
6333 {
6334 errmsg = mb_init();
6335# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006336 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006337# endif
6338 }
6339 }
6340
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006341# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006342 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6343 {
6344 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6345 if (STRCMP(p_tenc, "utf-8") != 0)
6346 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6347 }
6348# endif
6349
6350 if (errmsg == NULL)
6351 {
6352# ifdef FEAT_KEYMAP
6353 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6354 * (with another encoding). */
6355 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6356 (void)keymap_init();
6357# endif
6358
6359 /* When 'termencoding' is not empty and 'encoding' changes or when
6360 * 'termencoding' changes, need to setup for keyboard input and
6361 * display output conversion. */
6362 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6363 {
6364 convert_setup(&input_conv, p_tenc, p_enc);
6365 convert_setup(&output_conv, p_enc, p_tenc);
6366 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006367
6368# if defined(WIN3264) && defined(FEAT_MBYTE)
6369 /* $HOME may have characters in active code page. */
6370 if (varp == &p_enc)
6371 init_homedir();
6372# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006373 }
6374 }
6375#endif
6376
6377#if defined(FEAT_POSTSCRIPT)
6378 else if (varp == &p_penc)
6379 {
6380 /* Canonize printencoding if VIM standard one */
6381 p = enc_canonize(p_penc);
6382 if (p != NULL)
6383 {
6384 vim_free(p_penc);
6385 p_penc = p;
6386 }
6387 else
6388 {
6389 /* Ensure lower case and '-' for '_' */
6390 for (s = p_penc; *s != NUL; s++)
6391 {
6392 if (*s == '_')
6393 *s = '-';
6394 else
6395 *s = TOLOWER_ASC(*s);
6396 }
6397 }
6398 }
6399#endif
6400
Bram Moolenaar9372a112005-12-06 19:59:18 +00006401#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006402 else if (varp == &p_imak)
6403 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006404 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006405 errmsg = e_invarg;
6406 }
6407#endif
6408
6409#ifdef FEAT_KEYMAP
6410 else if (varp == &curbuf->b_p_keymap)
6411 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006412 if (!valid_filetype(*varp))
6413 errmsg = e_invarg;
6414 else
6415 /* load or unload key mapping tables */
6416 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006417
Bram Moolenaarfab06232009-03-04 03:13:35 +00006418 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006419 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006420 if (*curbuf->b_p_keymap != NUL)
6421 {
6422 /* Installed a new keymap, switch on using it. */
6423 curbuf->b_p_iminsert = B_IMODE_LMAP;
6424 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6425 curbuf->b_p_imsearch = B_IMODE_LMAP;
6426 }
6427 else
6428 {
6429 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6430 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6431 curbuf->b_p_iminsert = B_IMODE_NONE;
6432 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6433 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6434 }
6435 if ((opt_flags & OPT_LOCAL) == 0)
6436 {
6437 set_iminsert_global();
6438 set_imsearch_global();
6439 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006440 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006441 }
6442 }
6443#endif
6444
6445 /* 'fileformat' */
6446 else if (gvarp == &p_ff)
6447 {
6448 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6449 errmsg = e_modifiable;
6450 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6451 errmsg = e_invarg;
6452 else
6453 {
6454 /* may also change 'textmode' */
6455 if (get_fileformat(curbuf) == EOL_DOS)
6456 curbuf->b_p_tx = TRUE;
6457 else
6458 curbuf->b_p_tx = FALSE;
6459#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006460 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006461#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006462 /* update flag in swap file */
6463 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006464 /* Redraw needed when switching to/from "mac": a CR in the text
6465 * will be displayed differently. */
6466 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6467 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006468 }
6469 }
6470
6471 /* 'fileformats' */
6472 else if (varp == &p_ffs)
6473 {
6474 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6475 errmsg = e_invarg;
6476 else
6477 {
6478 /* also change 'textauto' */
6479 if (*p_ffs == NUL)
6480 p_ta = FALSE;
6481 else
6482 p_ta = TRUE;
6483 }
6484 }
6485
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006486#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006487 /* 'cryptkey' */
6488 else if (gvarp == &p_key)
6489 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006490# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006491 /* Make sure the ":set" command doesn't show the new value in the
6492 * history. */
6493 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006494# endif
6495 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6496 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006497 ml_set_crypt_key(curbuf, oldval,
6498 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006499 }
6500
6501 else if (gvarp == &p_cm)
6502 {
6503 if (opt_flags & OPT_LOCAL)
6504 p = curbuf->b_p_cm;
6505 else
6506 p = p_cm;
6507 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6508 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006509 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006510 errmsg = e_invarg;
6511 else
6512 {
6513 /* When setting the global value to empty, make it "zip". */
6514 if (*p_cm == NUL)
6515 {
6516 if (new_value_alloced)
6517 free_string_option(p_cm);
6518 p_cm = vim_strsave((char_u *)"zip");
6519 new_value_alloced = TRUE;
6520 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006521 /* When using ":set cm=name" the local value is going to be empty.
6522 * Do that here, otherwise the crypt functions will still use the
6523 * local value. */
6524 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6525 {
6526 free_string_option(curbuf->b_p_cm);
6527 curbuf->b_p_cm = empty_option;
6528 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006529
6530 /* Need to update the swapfile when the effective method changed.
6531 * Set "s" to the effective old value, "p" to the effective new
6532 * method and compare. */
6533 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6534 s = p_cm; /* was previously using the global value */
6535 else
6536 s = oldval;
6537 if (*curbuf->b_p_cm == NUL)
6538 p = p_cm; /* is now using the global value */
6539 else
6540 p = curbuf->b_p_cm;
6541 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006542 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006543
6544 /* If the global value changes need to update the swapfile for all
6545 * buffers using that value. */
6546 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6547 {
6548 buf_T *buf;
6549
Bram Moolenaar29323592016-07-24 22:04:11 +02006550 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006551 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006552 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006553 }
6554 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006555 }
6556#endif
6557
6558 /* 'matchpairs' */
6559 else if (gvarp == &p_mps)
6560 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006561#ifdef FEAT_MBYTE
6562 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006563 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006564 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006565 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006566 int x2 = -1;
6567 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006568
6569 if (*p != NUL)
6570 p += mb_ptr2len(p);
6571 if (*p != NUL)
6572 x2 = *p++;
6573 if (*p != NUL)
6574 {
6575 x3 = mb_ptr2char(p);
6576 p += mb_ptr2len(p);
6577 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006578 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006579 {
6580 errmsg = e_invarg;
6581 break;
6582 }
6583 if (*p == NUL)
6584 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006585 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006586 }
6587 else
6588#endif
6589 {
6590 /* Check for "x:y,x:y" */
6591 for (p = *varp; *p != NUL; p += 4)
6592 {
6593 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6594 {
6595 errmsg = e_invarg;
6596 break;
6597 }
6598 if (p[3] == NUL)
6599 break;
6600 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006601 }
6602 }
6603
6604#ifdef FEAT_COMMENTS
6605 /* 'comments' */
6606 else if (gvarp == &p_com)
6607 {
6608 for (s = *varp; *s; )
6609 {
6610 while (*s && *s != ':')
6611 {
6612 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6613 && !VIM_ISDIGIT(*s) && *s != '-')
6614 {
6615 errmsg = illegal_char(errbuf, *s);
6616 break;
6617 }
6618 ++s;
6619 }
6620 if (*s++ == NUL)
6621 errmsg = (char_u *)N_("E524: Missing colon");
6622 else if (*s == ',' || *s == NUL)
6623 errmsg = (char_u *)N_("E525: Zero length string");
6624 if (errmsg != NULL)
6625 break;
6626 while (*s && *s != ',')
6627 {
6628 if (*s == '\\' && s[1] != NUL)
6629 ++s;
6630 ++s;
6631 }
6632 s = skip_to_option_part(s);
6633 }
6634 }
6635#endif
6636
6637 /* 'listchars' */
6638 else if (varp == &p_lcs)
6639 {
6640 errmsg = set_chars_option(varp);
6641 }
6642
Bram Moolenaar071d4272004-06-13 20:20:40 +00006643 /* 'fillchars' */
6644 else if (varp == &p_fcs)
6645 {
6646 errmsg = set_chars_option(varp);
6647 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006648
6649#ifdef FEAT_CMDWIN
6650 /* 'cedit' */
6651 else if (varp == &p_cedit)
6652 {
6653 errmsg = check_cedit();
6654 }
6655#endif
6656
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006657 /* 'verbosefile' */
6658 else if (varp == &p_vfile)
6659 {
6660 verbose_stop();
6661 if (*p_vfile != NUL && verbose_open() == FAIL)
6662 errmsg = e_invarg;
6663 }
6664
Bram Moolenaar071d4272004-06-13 20:20:40 +00006665#ifdef FEAT_VIMINFO
6666 /* 'viminfo' */
6667 else if (varp == &p_viminfo)
6668 {
6669 for (s = p_viminfo; *s;)
6670 {
6671 /* Check it's a valid character */
6672 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6673 {
6674 errmsg = illegal_char(errbuf, *s);
6675 break;
6676 }
6677 if (*s == 'n') /* name is always last one */
6678 {
6679 break;
6680 }
6681 else if (*s == 'r') /* skip until next ',' */
6682 {
6683 while (*++s && *s != ',')
6684 ;
6685 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006686 else if (*s == '%')
6687 {
6688 /* optional number */
6689 while (vim_isdigit(*++s))
6690 ;
6691 }
6692 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006693 ++s; /* no extra chars */
6694 else /* must have a number */
6695 {
6696 while (vim_isdigit(*++s))
6697 ;
6698
6699 if (!VIM_ISDIGIT(*(s - 1)))
6700 {
6701 if (errbuf != NULL)
6702 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006703 sprintf((char *)errbuf,
6704 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006705 transchar_byte(*(s - 1)));
6706 errmsg = errbuf;
6707 }
6708 else
6709 errmsg = (char_u *)"";
6710 break;
6711 }
6712 }
6713 if (*s == ',')
6714 ++s;
6715 else if (*s)
6716 {
6717 if (errbuf != NULL)
6718 errmsg = (char_u *)N_("E527: Missing comma");
6719 else
6720 errmsg = (char_u *)"";
6721 break;
6722 }
6723 }
6724 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6725 errmsg = (char_u *)N_("E528: Must specify a ' value");
6726 }
6727#endif /* FEAT_VIMINFO */
6728
6729 /* terminal options */
6730 else if (istermoption(&options[opt_idx]) && full_screen)
6731 {
6732 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6733 if (varp == &T_CCO)
6734 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006735 int colors = atoi((char *)T_CCO);
6736
6737 /* Only reinitialize colors if t_Co value has really changed to
6738 * avoid expensive reload of colorscheme if t_Co is set to the
6739 * same value multiple times. */
6740 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006741 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006742 t_colors = colors;
6743 if (t_colors <= 1)
6744 {
6745 if (new_value_alloced)
6746 vim_free(T_CCO);
6747 T_CCO = empty_option;
6748 }
6749 /* We now have a different color setup, initialize it again. */
6750 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006751 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006752 }
6753 ttest(FALSE);
6754 if (varp == &T_ME)
6755 {
6756 out_str(T_ME);
6757 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006758#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006759 /* Since t_me has been set, this probably means that the user
6760 * wants to use this as default colors. Need to reset default
6761 * background/foreground colors. */
6762 mch_set_normal_colors();
6763#endif
6764 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006765 if (varp == &T_BE && termcap_active)
6766 {
6767 if (*T_BE == NUL)
6768 /* When clearing t_BE we assume the user no longer wants
6769 * bracketed paste, thus disable it by writing t_BD. */
6770 out_str(T_BD);
6771 else
6772 out_str(T_BE);
6773 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006774 }
6775
6776#ifdef FEAT_LINEBREAK
6777 /* 'showbreak' */
6778 else if (varp == &p_sbr)
6779 {
6780 for (s = p_sbr; *s; )
6781 {
6782 if (ptr2cells(s) != 1)
6783 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006784 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006785 }
6786 }
6787#endif
6788
6789#ifdef FEAT_GUI
6790 /* 'guifont' */
6791 else if (varp == &p_guifont)
6792 {
6793 if (gui.in_use)
6794 {
6795 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006796# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006797 /*
6798 * Put up a font dialog and let the user select a new value.
6799 * If this is cancelled go back to the old value but don't
6800 * give an error message.
6801 */
6802 if (STRCMP(p, "*") == 0)
6803 {
6804 p = gui_mch_font_dialog(oldval);
6805
6806 if (new_value_alloced)
6807 free_string_option(p_guifont);
6808
6809 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6810 new_value_alloced = TRUE;
6811 }
6812# endif
6813 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6814 {
6815# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6816 if (STRCMP(p_guifont, "*") == 0)
6817 {
6818 /* Dialog was cancelled: Keep the old value without giving
6819 * an error message. */
6820 if (new_value_alloced)
6821 free_string_option(p_guifont);
6822 p_guifont = vim_strsave(oldval);
6823 new_value_alloced = TRUE;
6824 }
6825 else
6826# endif
6827 errmsg = (char_u *)N_("E596: Invalid font(s)");
6828 }
6829 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006830 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006831 }
6832# ifdef FEAT_XFONTSET
6833 else if (varp == &p_guifontset)
6834 {
6835 if (STRCMP(p_guifontset, "*") == 0)
6836 errmsg = (char_u *)N_("E597: can't select fontset");
6837 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6838 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006839 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006840 }
6841# endif
6842# ifdef FEAT_MBYTE
6843 else if (varp == &p_guifontwide)
6844 {
6845 if (STRCMP(p_guifontwide, "*") == 0)
6846 errmsg = (char_u *)N_("E533: can't select wide font");
6847 else if (gui_get_wide_font() == FAIL)
6848 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006849 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006850 }
6851# endif
6852#endif
6853
6854#ifdef CURSOR_SHAPE
6855 /* 'guicursor' */
6856 else if (varp == &p_guicursor)
6857 errmsg = parse_shape_opt(SHAPE_CURSOR);
6858#endif
6859
6860#ifdef FEAT_MOUSESHAPE
6861 /* 'mouseshape' */
6862 else if (varp == &p_mouseshape)
6863 {
6864 errmsg = parse_shape_opt(SHAPE_MOUSE);
6865 update_mouseshape(-1);
6866 }
6867#endif
6868
6869#ifdef FEAT_PRINTER
6870 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006871 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006872# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006873 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006874 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006875# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006876#endif
6877
6878#ifdef FEAT_LANGMAP
6879 /* 'langmap' */
6880 else if (varp == &p_langmap)
6881 langmap_set();
6882#endif
6883
6884#ifdef FEAT_LINEBREAK
6885 /* 'breakat' */
6886 else if (varp == &p_breakat)
6887 fill_breakat_flags();
6888#endif
6889
6890#ifdef FEAT_TITLE
6891 /* 'titlestring' and 'iconstring' */
6892 else if (varp == &p_titlestring || varp == &p_iconstring)
6893 {
6894# ifdef FEAT_STL_OPT
6895 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6896
6897 /* NULL => statusline syntax */
6898 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6899 stl_syntax |= flagval;
6900 else
6901 stl_syntax &= ~flagval;
6902# endif
6903 did_set_title(varp == &p_iconstring);
6904
6905 }
6906#endif
6907
6908#ifdef FEAT_GUI
6909 /* 'guioptions' */
6910 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006911 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006912 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006913 redraw_gui_only = TRUE;
6914 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006915#endif
6916
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006917#if defined(FEAT_GUI_TABLINE)
6918 /* 'guitablabel' */
6919 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006920 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006921 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006922 redraw_gui_only = TRUE;
6923 }
6924 /* 'guitabtooltip' */
6925 else if (varp == &p_gtt)
6926 {
6927 redraw_gui_only = TRUE;
6928 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006929#endif
6930
Bram Moolenaar071d4272004-06-13 20:20:40 +00006931#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6932 /* 'ttymouse' */
6933 else if (varp == &p_ttym)
6934 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006935 /* Switch the mouse off before changing the escape sequences used for
6936 * that. */
6937 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006938 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6939 errmsg = e_invarg;
6940 else
6941 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006942 if (termcap_active)
6943 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006944 }
6945#endif
6946
Bram Moolenaar071d4272004-06-13 20:20:40 +00006947 /* 'selection' */
6948 else if (varp == &p_sel)
6949 {
6950 if (*p_sel == NUL
6951 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6952 errmsg = e_invarg;
6953 }
6954
6955 /* 'selectmode' */
6956 else if (varp == &p_slm)
6957 {
6958 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6959 errmsg = e_invarg;
6960 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006961
6962#ifdef FEAT_BROWSE
6963 /* 'browsedir' */
6964 else if (varp == &p_bsdir)
6965 {
6966 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6967 && !mch_isdir(p_bsdir))
6968 errmsg = e_invarg;
6969 }
6970#endif
6971
Bram Moolenaar071d4272004-06-13 20:20:40 +00006972 /* 'keymodel' */
6973 else if (varp == &p_km)
6974 {
6975 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6976 errmsg = e_invarg;
6977 else
6978 {
6979 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6980 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6981 }
6982 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006983
6984 /* 'mousemodel' */
6985 else if (varp == &p_mousem)
6986 {
6987 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6988 errmsg = e_invarg;
6989#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6990 else if (*p_mousem != *oldval)
6991 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6992 * to create or delete the popup menus. */
6993 gui_motif_update_mousemodel(root_menu);
6994#endif
6995 }
6996
6997 /* 'switchbuf' */
6998 else if (varp == &p_swb)
6999 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007000 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007001 errmsg = e_invarg;
7002 }
7003
7004 /* 'debug' */
7005 else if (varp == &p_debug)
7006 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007007 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007008 errmsg = e_invarg;
7009 }
7010
7011 /* 'display' */
7012 else if (varp == &p_dy)
7013 {
7014 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7015 errmsg = e_invarg;
7016 else
7017 (void)init_chartab();
7018
7019 }
7020
Bram Moolenaar071d4272004-06-13 20:20:40 +00007021 /* 'eadirection' */
7022 else if (varp == &p_ead)
7023 {
7024 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7025 errmsg = e_invarg;
7026 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007027
7028#ifdef FEAT_CLIPBOARD
7029 /* 'clipboard' */
7030 else if (varp == &p_cb)
7031 errmsg = check_clipboard_option();
7032#endif
7033
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007034#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007035 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7036 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007037 else if (varp == &(curwin->w_s->b_p_spl)
7038 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007039 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007040 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007041 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007042 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007043 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007044 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007045 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007046 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007047 /* 'spellsuggest' */
7048 else if (varp == &p_sps)
7049 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007050 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007051 errmsg = e_invarg;
7052 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007053 /* 'mkspellmem' */
7054 else if (varp == &p_msm)
7055 {
7056 if (spell_check_msm() != OK)
7057 errmsg = e_invarg;
7058 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007059#endif
7060
Bram Moolenaar071d4272004-06-13 20:20:40 +00007061 /* When 'bufhidden' is set, check for valid value. */
7062 else if (gvarp == &p_bh)
7063 {
7064 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7065 errmsg = e_invarg;
7066 }
7067
7068 /* When 'buftype' is set, check for valid value. */
7069 else if (gvarp == &p_bt)
7070 {
7071 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7072 errmsg = e_invarg;
7073 else
7074 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007075 if (curwin->w_status_height)
7076 {
7077 curwin->w_redr_status = TRUE;
7078 redraw_later(VALID);
7079 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007080 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007081#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007082 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007083#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007084 }
7085 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007086
7087#ifdef FEAT_STL_OPT
7088 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007089 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007090 {
7091 int wid;
7092
7093 if (varp == &p_ruf) /* reset ru_wid first */
7094 ru_wid = 0;
7095 s = *varp;
7096 if (varp == &p_ruf && *s == '%')
7097 {
7098 /* set ru_wid if 'ruf' starts with "%99(" */
7099 if (*++s == '-') /* ignore a '-' */
7100 s++;
7101 wid = getdigits(&s);
7102 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7103 ru_wid = wid;
7104 else
7105 errmsg = check_stl_option(p_ruf);
7106 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007107 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007108 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007109 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007110 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007111 comp_col();
7112 }
7113#endif
7114
7115#ifdef FEAT_INS_EXPAND
7116 /* check if it is a valid value for 'complete' -- Acevedo */
7117 else if (gvarp == &p_cpt)
7118 {
7119 for (s = *varp; *s;)
7120 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007121 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007122 s++;
7123 if (!*s)
7124 break;
7125 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7126 {
7127 errmsg = illegal_char(errbuf, *s);
7128 break;
7129 }
7130 if (*++s != NUL && *s != ',' && *s != ' ')
7131 {
7132 if (s[-1] == 'k' || s[-1] == 's')
7133 {
7134 /* skip optional filename after 'k' and 's' */
7135 while (*s && *s != ',' && *s != ' ')
7136 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007137 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007138 ++s;
7139 ++s;
7140 }
7141 }
7142 else
7143 {
7144 if (errbuf != NULL)
7145 {
7146 sprintf((char *)errbuf,
7147 _("E535: Illegal character after <%c>"),
7148 *--s);
7149 errmsg = errbuf;
7150 }
7151 else
7152 errmsg = (char_u *)"";
7153 break;
7154 }
7155 }
7156 }
7157 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007158
7159 /* 'completeopt' */
7160 else if (varp == &p_cot)
7161 {
7162 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7163 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007164 else
7165 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007166 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007167#endif /* FEAT_INS_EXPAND */
7168
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007169#ifdef FEAT_SIGNS
7170 /* 'signcolumn' */
7171 else if (varp == &curwin->w_p_scl)
7172 {
7173 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7174 errmsg = e_invarg;
7175 }
7176#endif
7177
Bram Moolenaar071d4272004-06-13 20:20:40 +00007178
7179#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007180 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007181 else if (varp == &p_toolbar)
7182 {
7183 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7184 &toolbar_flags, TRUE) != OK)
7185 errmsg = e_invarg;
7186 else
7187 {
7188 out_flush();
7189 gui_mch_show_toolbar((toolbar_flags &
7190 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7191 }
7192 }
7193#endif
7194
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007195#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007196 /* 'toolbariconsize': GTK+ 2 only */
7197 else if (varp == &p_tbis)
7198 {
7199 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7200 errmsg = e_invarg;
7201 else
7202 {
7203 out_flush();
7204 gui_mch_show_toolbar((toolbar_flags &
7205 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7206 }
7207 }
7208#endif
7209
7210 /* 'pastetoggle': translate key codes like in a mapping */
7211 else if (varp == &p_pt)
7212 {
7213 if (*p_pt)
7214 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007215 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007216 if (p != NULL)
7217 {
7218 if (new_value_alloced)
7219 free_string_option(p_pt);
7220 p_pt = p;
7221 new_value_alloced = TRUE;
7222 }
7223 }
7224 }
7225
7226 /* 'backspace' */
7227 else if (varp == &p_bs)
7228 {
7229 if (VIM_ISDIGIT(*p_bs))
7230 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007231 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007232 errmsg = e_invarg;
7233 }
7234 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7235 errmsg = e_invarg;
7236 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007237 else if (varp == &p_bo)
7238 {
7239 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7240 errmsg = e_invarg;
7241 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007242
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007243 /* 'tagcase' */
7244 else if (gvarp == &p_tc)
7245 {
7246 unsigned int *flags;
7247
7248 if (opt_flags & OPT_LOCAL)
7249 {
7250 p = curbuf->b_p_tc;
7251 flags = &curbuf->b_tc_flags;
7252 }
7253 else
7254 {
7255 p = p_tc;
7256 flags = &tc_flags;
7257 }
7258
7259 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7260 /* make the local value empty: use the global value */
7261 *flags = 0;
7262 else if (*p == NUL
7263 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7264 errmsg = e_invarg;
7265 }
7266
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007267#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007268 /* 'casemap' */
7269 else if (varp == &p_cmp)
7270 {
7271 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7272 errmsg = e_invarg;
7273 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007274#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007275
7276#ifdef FEAT_DIFF
7277 /* 'diffopt' */
7278 else if (varp == &p_dip)
7279 {
7280 if (diffopt_changed() == FAIL)
7281 errmsg = e_invarg;
7282 }
7283#endif
7284
7285#ifdef FEAT_FOLDING
7286 /* 'foldmethod' */
7287 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7288 {
7289 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7290 || *curwin->w_p_fdm == NUL)
7291 errmsg = e_invarg;
7292 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007293 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007294 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007295 if (foldmethodIsDiff(curwin))
7296 newFoldLevel();
7297 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007298 }
7299# ifdef FEAT_EVAL
7300 /* 'foldexpr' */
7301 else if (varp == &curwin->w_p_fde)
7302 {
7303 if (foldmethodIsExpr(curwin))
7304 foldUpdateAll(curwin);
7305 }
7306# endif
7307 /* 'foldmarker' */
7308 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7309 {
7310 p = vim_strchr(*varp, ',');
7311 if (p == NULL)
7312 errmsg = (char_u *)N_("E536: comma required");
7313 else if (p == *varp || p[1] == NUL)
7314 errmsg = e_invarg;
7315 else if (foldmethodIsMarker(curwin))
7316 foldUpdateAll(curwin);
7317 }
7318 /* 'commentstring' */
7319 else if (gvarp == &p_cms)
7320 {
7321 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7322 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7323 }
7324 /* 'foldopen' */
7325 else if (varp == &p_fdo)
7326 {
7327 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7328 errmsg = e_invarg;
7329 }
7330 /* 'foldclose' */
7331 else if (varp == &p_fcl)
7332 {
7333 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7334 errmsg = e_invarg;
7335 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007336 /* 'foldignore' */
7337 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7338 {
7339 if (foldmethodIsIndent(curwin))
7340 foldUpdateAll(curwin);
7341 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007342#endif
7343
7344#ifdef FEAT_VIRTUALEDIT
7345 /* 'virtualedit' */
7346 else if (varp == &p_ve)
7347 {
7348 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7349 errmsg = e_invarg;
7350 else if (STRCMP(p_ve, oldval) != 0)
7351 {
7352 /* Recompute cursor position in case the new 've' setting
7353 * changes something. */
7354 validate_virtcol();
7355 coladvance(curwin->w_virtcol);
7356 }
7357 }
7358#endif
7359
7360#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7361 else if (varp == &p_csqf)
7362 {
7363 if (p_csqf != NULL)
7364 {
7365 p = p_csqf;
7366 while (*p != NUL)
7367 {
7368 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7369 || p[1] == NUL
7370 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7371 || (p[2] != NUL && p[2] != ','))
7372 {
7373 errmsg = e_invarg;
7374 break;
7375 }
7376 else if (p[2] == NUL)
7377 break;
7378 else
7379 p += 3;
7380 }
7381 }
7382 }
7383#endif
7384
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007385#ifdef FEAT_CINDENT
7386 /* 'cinoptions' */
7387 else if (gvarp == &p_cino)
7388 {
7389 /* TODO: recognize errors */
7390 parse_cino(curbuf);
7391 }
7392#endif
7393
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007394#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007395 /* 'renderoptions' */
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007396 else if (varp == &p_rop && gui.in_use)
7397 {
7398 if (!gui_mch_set_rendering_options(p_rop))
7399 errmsg = e_invarg;
7400 }
7401#endif
7402
Bram Moolenaard0b51382016-11-04 15:23:45 +01007403#ifdef FEAT_AUTOCMD
7404 else if (gvarp == &p_ft)
7405 {
7406 if (!valid_filetype(*varp))
7407 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007408 else
7409 ft_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaard0b51382016-11-04 15:23:45 +01007410 }
7411#endif
7412
7413#ifdef FEAT_SYN_HL
7414 else if (gvarp == &p_syn)
7415 {
7416 if (!valid_filetype(*varp))
7417 errmsg = e_invarg;
7418 }
7419#endif
7420
Bram Moolenaar825680f2017-07-22 17:04:02 +02007421#ifdef FEAT_TERMINAL
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007422 /* 'termkey' */
Bram Moolenaarc4f43bc2017-07-24 20:03:01 +02007423 else if (varp == &curwin->w_p_tk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007424 {
7425 if (*curwin->w_p_tk != NUL && string_to_key(curwin->w_p_tk, TRUE) == 0)
7426 errmsg = e_invarg;
7427 }
Bram Moolenaar825680f2017-07-22 17:04:02 +02007428 /* 'termsize' */
7429 else if (varp == &curwin->w_p_tms)
7430 {
7431 if (*curwin->w_p_tms != NUL)
7432 {
7433 p = skipdigits(curwin->w_p_tms);
7434 if (p == curwin->w_p_tms || *p != 'x' || *skipdigits(p + 1) != NUL)
7435 errmsg = e_invarg;
7436 }
7437 }
7438#endif
7439
Bram Moolenaar071d4272004-06-13 20:20:40 +00007440 /* Options that are a list of flags. */
7441 else
7442 {
7443 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007444 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007445 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007446 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007447 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007448 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007449 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007450 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007451 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007452#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007453 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007454 p = (char_u *)COCU_ALL;
7455#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007456 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007457 {
7458#ifdef FEAT_MOUSE
7459 p = (char_u *)MOUSE_ALL;
7460#else
7461 if (*p_mouse != NUL)
7462 errmsg = (char_u *)N_("E538: No mouse support");
7463#endif
7464 }
7465#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007466 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007467 p = (char_u *)GO_ALL;
7468#endif
7469 if (p != NULL)
7470 {
7471 for (s = *varp; *s; ++s)
7472 if (vim_strchr(p, *s) == NULL)
7473 {
7474 errmsg = illegal_char(errbuf, *s);
7475 break;
7476 }
7477 }
7478 }
7479
7480 /*
7481 * If error detected, restore the previous value.
7482 */
7483 if (errmsg != NULL)
7484 {
7485 if (new_value_alloced)
7486 free_string_option(*varp);
7487 *varp = oldval;
7488 /*
7489 * When resetting some values, need to act on it.
7490 */
7491 if (did_chartab)
7492 (void)init_chartab();
7493 if (varp == &p_hl)
7494 (void)highlight_changed();
7495 }
7496 else
7497 {
7498#ifdef FEAT_EVAL
7499 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007500 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007501#endif
7502 /*
7503 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007504 * Use "free_oldval", because recursiveness may change the flags under
7505 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007506 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007507 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007508 free_string_option(oldval);
7509 if (new_value_alloced)
7510 options[opt_idx].flags |= P_ALLOCED;
7511 else
7512 options[opt_idx].flags &= ~P_ALLOCED;
7513
7514 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007515 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007516 {
7517 /* global option with local value set to use global value; free
7518 * the local value and make it empty */
7519 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7520 free_string_option(*(char_u **)p);
7521 *(char_u **)p = empty_option;
7522 }
7523
7524 /* May set global value for local option. */
7525 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7526 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007527
7528#ifdef FEAT_AUTOCMD
7529 /*
7530 * Trigger the autocommand only after setting the flags.
7531 */
7532# ifdef FEAT_SYN_HL
7533 /* When 'syntax' is set, load the syntax of that name */
7534 if (varp == &(curbuf->b_p_syn))
7535 {
7536 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7537 curbuf->b_fname, TRUE, curbuf);
7538 }
7539# endif
7540 else if (varp == &(curbuf->b_p_ft))
7541 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007542 /* 'filetype' is set, trigger the FileType autocommand.
7543 * Skip this when called from a modeline and the filetype was
7544 * already set to this value. */
7545 if (!(opt_flags & OPT_MODELINE) || ft_changed)
7546 {
7547 did_filetype = TRUE;
7548 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007549 curbuf->b_fname, TRUE, curbuf);
Bram Moolenaar163095f2017-07-09 15:41:53 +02007550 /* Just in case the old "curbuf" is now invalid. */
7551 if (varp != &(curbuf->b_p_ft))
7552 varp = NULL;
Bram Moolenaar90492982017-06-22 14:16:31 +02007553 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007554 }
7555#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007556#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007557 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007558 {
7559 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007560 char_u *q = curwin->w_s->b_p_spl;
7561
7562 /* Skip the first name if it is "cjk". */
7563 if (STRNCMP(q, "cjk,", 4) == 0)
7564 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007565
7566 /*
7567 * Source the spell/LANG.vim in 'runtimepath'.
7568 * They could set 'spellcapcheck' depending on the language.
7569 * Use the first name in 'spelllang' up to '_region' or
7570 * '.encoding'.
7571 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007572 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007573 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7574 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007575 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007576 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007577 }
7578#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007579 }
7580
7581#ifdef FEAT_MOUSE
7582 if (varp == &p_mouse)
7583 {
7584# ifdef FEAT_MOUSE_TTY
7585 if (*p_mouse == NUL)
7586 mch_setmouse(FALSE); /* switch mouse off */
7587 else
7588# endif
7589 setmouse(); /* in case 'mouse' changed */
7590 }
7591#endif
7592
Bram Moolenaar913077c2012-03-28 19:59:04 +02007593 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007594 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007595 curwin->w_set_curswant = TRUE;
7596
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007597#ifdef FEAT_GUI
7598 /* check redraw when it's not a GUI option or the GUI is active. */
7599 if (!redraw_gui_only || gui.in_use)
7600#endif
7601 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007602
7603 return errmsg;
7604}
7605
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007606#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007607/*
7608 * Simple int comparison function for use with qsort()
7609 */
7610 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007611int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007612{
7613 return *(const int *)a - *(const int *)b;
7614}
7615
7616/*
7617 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7618 * Returns error message, NULL if it's OK.
7619 */
7620 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007621check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007622{
7623 char_u *s;
7624 int col;
7625 int count = 0;
7626 int color_cols[256];
7627 int i;
7628 int j = 0;
7629
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007630 if (wp->w_buffer == NULL)
7631 return NULL; /* buffer was closed */
7632
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007633 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007634 {
7635 if (*s == '-' || *s == '+')
7636 {
7637 /* -N and +N: add to 'textwidth' */
7638 col = (*s == '-') ? -1 : 1;
7639 ++s;
7640 if (!VIM_ISDIGIT(*s))
7641 return e_invarg;
7642 col = col * getdigits(&s);
7643 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007644 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007645 col += wp->w_buffer->b_p_tw;
7646 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007647 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007648 }
7649 else if (VIM_ISDIGIT(*s))
7650 col = getdigits(&s);
7651 else
7652 return e_invarg;
7653 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007654skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007655 if (*s == NUL)
7656 break;
7657 if (*s != ',')
7658 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007659 if (*++s == NUL)
7660 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007661 }
7662
7663 vim_free(wp->w_p_cc_cols);
7664 if (count == 0)
7665 wp->w_p_cc_cols = NULL;
7666 else
7667 {
7668 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7669 if (wp->w_p_cc_cols != NULL)
7670 {
7671 /* sort the columns for faster usage on screen redraw inside
7672 * win_line() */
7673 qsort(color_cols, count, sizeof(int), int_cmp);
7674
7675 for (i = 0; i < count; ++i)
7676 /* skip duplicates */
7677 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7678 wp->w_p_cc_cols[j++] = color_cols[i];
7679 wp->w_p_cc_cols[j] = -1; /* end marker */
7680 }
7681 }
7682
7683 return NULL; /* no error */
7684}
7685#endif
7686
Bram Moolenaar071d4272004-06-13 20:20:40 +00007687/*
7688 * Handle setting 'listchars' or 'fillchars'.
7689 * Returns error message, NULL if it's OK.
7690 */
7691 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007692set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007693{
7694 int round, i, len, entries;
7695 char_u *p, *s;
7696 int c1, c2 = 0;
7697 struct charstab
7698 {
7699 int *cp;
7700 char *name;
7701 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007702 static struct charstab filltab[] =
7703 {
7704 {&fill_stl, "stl"},
7705 {&fill_stlnc, "stlnc"},
7706 {&fill_vert, "vert"},
7707 {&fill_fold, "fold"},
7708 {&fill_diff, "diff"},
7709 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007710 static struct charstab lcstab[] =
7711 {
7712 {&lcs_eol, "eol"},
7713 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007714 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007715 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007716 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007717 {&lcs_tab2, "tab"},
7718 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007719#ifdef FEAT_CONCEAL
7720 {&lcs_conceal, "conceal"},
7721#else
7722 {NULL, "conceal"},
7723#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007724 };
7725 struct charstab *tab;
7726
Bram Moolenaar071d4272004-06-13 20:20:40 +00007727 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007728 {
7729 tab = lcstab;
7730 entries = sizeof(lcstab) / sizeof(struct charstab);
7731 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007732 else
7733 {
7734 tab = filltab;
7735 entries = sizeof(filltab) / sizeof(struct charstab);
7736 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007737
7738 /* first round: check for valid value, second round: assign values */
7739 for (round = 0; round <= 1; ++round)
7740 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007741 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007742 {
7743 /* After checking that the value is valid: set defaults: space for
7744 * 'fillchars', NUL for 'listchars' */
7745 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007746 if (tab[i].cp != NULL)
7747 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007748 if (varp == &p_lcs)
7749 lcs_tab1 = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007750 else
7751 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007752 }
7753 p = *varp;
7754 while (*p)
7755 {
7756 for (i = 0; i < entries; ++i)
7757 {
7758 len = (int)STRLEN(tab[i].name);
7759 if (STRNCMP(p, tab[i].name, len) == 0
7760 && p[len] == ':'
7761 && p[len + 1] != NUL)
7762 {
7763 s = p + len + 1;
7764#ifdef FEAT_MBYTE
7765 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007766 if (mb_char2cells(c1) > 1)
7767 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007768#else
7769 c1 = *s++;
7770#endif
7771 if (tab[i].cp == &lcs_tab2)
7772 {
7773 if (*s == NUL)
7774 continue;
7775#ifdef FEAT_MBYTE
7776 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007777 if (mb_char2cells(c2) > 1)
7778 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007779#else
7780 c2 = *s++;
7781#endif
7782 }
7783 if (*s == ',' || *s == NUL)
7784 {
7785 if (round)
7786 {
7787 if (tab[i].cp == &lcs_tab2)
7788 {
7789 lcs_tab1 = c1;
7790 lcs_tab2 = c2;
7791 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007792 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007793 *(tab[i].cp) = c1;
7794
7795 }
7796 p = s;
7797 break;
7798 }
7799 }
7800 }
7801
7802 if (i == entries)
7803 return e_invarg;
7804 if (*p == ',')
7805 ++p;
7806 }
7807 }
7808
7809 return NULL; /* no error */
7810}
7811
7812#ifdef FEAT_STL_OPT
7813/*
7814 * Check validity of options with the 'statusline' format.
7815 * Return error message or NULL.
7816 */
7817 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007818check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007819{
7820 int itemcnt = 0;
7821 int groupdepth = 0;
7822 static char_u errbuf[80];
7823
7824 while (*s && itemcnt < STL_MAX_ITEM)
7825 {
7826 /* Check for valid keys after % sequences */
7827 while (*s && *s != '%')
7828 s++;
7829 if (!*s)
7830 break;
7831 s++;
7832 if (*s != '%' && *s != ')')
7833 ++itemcnt;
7834 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7835 {
7836 s++;
7837 continue;
7838 }
7839 if (*s == ')')
7840 {
7841 s++;
7842 if (--groupdepth < 0)
7843 break;
7844 continue;
7845 }
7846 if (*s == '-')
7847 s++;
7848 while (VIM_ISDIGIT(*s))
7849 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007850 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007851 continue;
7852 if (*s == '.')
7853 {
7854 s++;
7855 while (*s && VIM_ISDIGIT(*s))
7856 s++;
7857 }
7858 if (*s == '(')
7859 {
7860 groupdepth++;
7861 continue;
7862 }
7863 if (vim_strchr(STL_ALL, *s) == NULL)
7864 {
7865 return illegal_char(errbuf, *s);
7866 }
7867 if (*s == '{')
7868 {
7869 s++;
7870 while (*s != '}' && *s)
7871 s++;
7872 if (*s != '}')
7873 return (char_u *)N_("E540: Unclosed expression sequence");
7874 }
7875 }
7876 if (itemcnt >= STL_MAX_ITEM)
7877 return (char_u *)N_("E541: too many items");
7878 if (groupdepth != 0)
7879 return (char_u *)N_("E542: unbalanced groups");
7880 return NULL;
7881}
7882#endif
7883
7884#ifdef FEAT_CLIPBOARD
7885/*
7886 * Extract the items in the 'clipboard' option and set global values.
7887 */
7888 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007889check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007890{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007891 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007892 int new_autoselect_star = FALSE;
7893 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007894 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007895 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007896 regprog_T *new_exclude_prog = NULL;
7897 char_u *errmsg = NULL;
7898 char_u *p;
7899
7900 for (p = p_cb; *p != NUL; )
7901 {
7902 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7903 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007904 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007905 p += 7;
7906 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007907 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007908 && (p[11] == ',' || p[11] == NUL))
7909 {
7910 new_unnamed |= CLIP_UNNAMED_PLUS;
7911 p += 11;
7912 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007913 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007914 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007915 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007916 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007917 p += 10;
7918 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007919 else if (STRNCMP(p, "autoselectplus", 14) == 0
7920 && (p[14] == ',' || p[14] == NUL))
7921 {
7922 new_autoselect_plus = TRUE;
7923 p += 14;
7924 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007925 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007926 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007927 {
7928 new_autoselectml = TRUE;
7929 p += 12;
7930 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007931 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7932 {
7933 new_html = TRUE;
7934 p += 4;
7935 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007936 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7937 {
7938 p += 8;
7939 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7940 if (new_exclude_prog == NULL)
7941 errmsg = e_invarg;
7942 break;
7943 }
7944 else
7945 {
7946 errmsg = e_invarg;
7947 break;
7948 }
7949 if (*p == ',')
7950 ++p;
7951 }
7952 if (errmsg == NULL)
7953 {
7954 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007955 clip_autoselect_star = new_autoselect_star;
7956 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007957 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007958 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007959 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007960 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007961#ifdef FEAT_GUI_GTK
7962 if (gui.in_use)
7963 {
7964 gui_gtk_set_selection_targets();
7965 gui_gtk_set_dnd_targets();
7966 }
7967#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007968 }
7969 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007970 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007971
7972 return errmsg;
7973}
7974#endif
7975
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007976#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007977 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007978did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007979{
7980 char_u *errmsg = NULL;
7981 win_T *wp;
7982 int l;
7983
7984 if (is_spellfile)
7985 {
7986 l = (int)STRLEN(curwin->w_s->b_p_spf);
7987 if (l > 0 && (l < 4
7988 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7989 errmsg = e_invarg;
7990 }
7991
7992 if (errmsg == NULL)
7993 {
7994 FOR_ALL_WINDOWS(wp)
7995 if (wp->w_buffer == curbuf && wp->w_p_spell)
7996 {
7997 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007998 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007999 }
8000 }
8001 return errmsg;
8002}
8003
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008004/*
8005 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8006 * Return error message when failed, NULL when OK.
8007 */
8008 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008009compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008010{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008011 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008012 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008013
Bram Moolenaar860cae12010-06-05 23:22:07 +02008014 if (*synblock->b_p_spc == NUL)
8015 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008016 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008017 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008018 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008019 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008020 if (re != NULL)
8021 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008022 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008023 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008024 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008025 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008026 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008027 return e_invarg;
8028 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008029 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008030 }
8031
Bram Moolenaar473de612013-06-08 18:19:48 +02008032 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008033 return NULL;
8034}
8035#endif
8036
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008037#if defined(FEAT_EVAL) || defined(PROTO)
8038/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008039 * Set the scriptID for an option, taking care of setting the buffer- or
8040 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008041 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008042 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008043set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008044{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008045 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8046 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008047
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008048 /* Remember where the option was set. For local options need to do that
8049 * in the buffer or window structure. */
8050 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008051 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008052 if (both || (opt_flags & OPT_LOCAL))
8053 {
8054 if (indir & PV_BUF)
8055 curbuf->b_p_scriptID[indir & PV_MASK] = id;
8056 else if (indir & PV_WIN)
8057 curwin->w_p_scriptID[indir & PV_MASK] = id;
8058 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008059}
8060#endif
8061
Bram Moolenaar071d4272004-06-13 20:20:40 +00008062/*
8063 * Set the value of a boolean option, and take care of side effects.
8064 * Returns NULL for success, or an error message for an error.
8065 */
8066 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008067set_bool_option(
8068 int opt_idx, /* index in options[] table */
8069 char_u *varp, /* pointer to the option variable */
8070 int value, /* new value */
8071 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008072{
8073 int old_value = *(int *)varp;
8074
Bram Moolenaar071d4272004-06-13 20:20:40 +00008075 /* Disallow changing some options from secure mode */
8076 if ((secure
8077#ifdef HAVE_SANDBOX
8078 || sandbox != 0
8079#endif
8080 ) && (options[opt_idx].flags & P_SECURE))
8081 return e_secure;
8082
8083 *(int *)varp = value; /* set the new value */
8084#ifdef FEAT_EVAL
8085 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008086 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008087#endif
8088
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008089#ifdef FEAT_GUI
8090 need_mouse_correct = TRUE;
8091#endif
8092
Bram Moolenaar071d4272004-06-13 20:20:40 +00008093 /* May set global value for local option. */
8094 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8095 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8096
8097 /*
8098 * Handle side effects of changing a bool option.
8099 */
8100
8101 /* 'compatible' */
8102 if ((int *)varp == &p_cp)
8103 {
8104 compatible_set();
8105 }
8106
Bram Moolenaar920694c2016-08-21 17:45:02 +02008107#ifdef FEAT_LANGMAP
8108 if ((int *)varp == &p_lrm)
8109 /* 'langremap' -> !'langnoremap' */
8110 p_lnr = !p_lrm;
8111 else if ((int *)varp == &p_lnr)
8112 /* 'langnoremap' -> !'langremap' */
8113 p_lrm = !p_lnr;
8114#endif
8115
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008116#ifdef FEAT_PERSISTENT_UNDO
8117 /* 'undofile' */
8118 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8119 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008120 /* Only take action when the option was set. When reset we do not
8121 * delete the undo file, the option may be set again without making
8122 * any changes in between. */
8123 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008124 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008125 char_u hash[UNDO_HASH_SIZE];
8126 buf_T *save_curbuf = curbuf;
8127
Bram Moolenaar29323592016-07-24 22:04:11 +02008128 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008129 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008130 /* When 'undofile' is set globally: for every buffer, otherwise
8131 * only for the current buffer: Try to read in the undofile,
8132 * if one exists, the buffer wasn't changed and the buffer was
8133 * loaded */
8134 if ((curbuf == save_curbuf
8135 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8136 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8137 {
8138 u_compute_hash(hash);
8139 u_read_undo(NULL, hash, curbuf->b_fname);
8140 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008141 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008142 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008143 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008144 }
8145#endif
8146
Bram Moolenaar071d4272004-06-13 20:20:40 +00008147 else if ((int *)varp == &curbuf->b_p_ro)
8148 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008149 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008150 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8151 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008152
8153 /* when 'readonly' is set may give W10 again */
8154 if (curbuf->b_p_ro)
8155 curbuf->b_did_warn = FALSE;
8156
Bram Moolenaar071d4272004-06-13 20:20:40 +00008157#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008158 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008159#endif
8160 }
8161
Bram Moolenaar9c449722010-07-20 18:44:27 +02008162#ifdef FEAT_GUI
8163 else if ((int *)varp == &p_mh)
8164 {
8165 if (!p_mh)
8166 gui_mch_mousehide(FALSE);
8167 }
8168#endif
8169
Bram Moolenaara539df02010-08-01 14:35:05 +02008170 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008171 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008172 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008173# ifdef FEAT_TERMINAL
8174 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaar6d819742017-08-06 14:57:49 +02008175 if (term_in_normal_mode()
Bram Moolenaar20e6cd02017-08-01 20:25:22 +02008176 || (bt_terminal(curbuf) && !term_is_finished(curbuf)))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008177 {
8178 curbuf->b_p_ma = FALSE;
8179 return (char_u *)N_("E946: Cannot make a terminal with running job modifiable");
8180 }
8181# endif
8182# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008183 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008184# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008185 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008186#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008187 /* when 'endofline' is changed, redraw the window title */
8188 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008189 {
8190 redraw_titles();
8191 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008192 /* when 'fixeol' is changed, redraw the window title */
8193 else if ((int *)varp == &curbuf->b_p_fixeol)
8194 {
8195 redraw_titles();
8196 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008197# ifdef FEAT_MBYTE
8198 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008199 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008200 {
8201 redraw_titles();
8202 }
8203# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008204#endif
8205
8206 /* when 'bin' is set also set some other options */
8207 else if ((int *)varp == &curbuf->b_p_bin)
8208 {
8209 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8210#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008211 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008212#endif
8213 }
8214
8215#ifdef FEAT_AUTOCMD
8216 /* when 'buflisted' changes, trigger autocommands */
8217 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8218 {
8219 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8220 NULL, NULL, TRUE, curbuf);
8221 }
8222#endif
8223
8224 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8225 else if ((int *)varp == &curbuf->b_p_swf)
8226 {
8227 if (curbuf->b_p_swf && p_uc)
8228 ml_open_file(curbuf); /* create the swap file */
8229 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008230 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8231 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008232 mf_close_file(curbuf, TRUE); /* remove the swap file */
8233 }
8234
8235 /* when 'terse' is set change 'shortmess' */
8236 else if ((int *)varp == &p_terse)
8237 {
8238 char_u *p;
8239
8240 p = vim_strchr(p_shm, SHM_SEARCH);
8241
8242 /* insert 's' in p_shm */
8243 if (p_terse && p == NULL)
8244 {
8245 STRCPY(IObuff, p_shm);
8246 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008247 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008248 }
8249 /* remove 's' from p_shm */
8250 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008251 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008252 }
8253
8254 /* when 'paste' is set or reset also change other options */
8255 else if ((int *)varp == &p_paste)
8256 {
8257 paste_option_changed();
8258 }
8259
8260 /* when 'insertmode' is set from an autocommand need to do work here */
8261 else if ((int *)varp == &p_im)
8262 {
8263 if (p_im)
8264 {
8265 if ((State & INSERT) == 0)
8266 need_start_insertmode = TRUE;
8267 stop_insert_mode = FALSE;
8268 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008269 /* only reset if it was set previously */
8270 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008271 {
8272 need_start_insertmode = FALSE;
8273 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008274 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008275 clear_cmdline = TRUE; /* remove "(insert)" */
8276 restart_edit = 0;
8277 }
8278 }
8279
8280 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8281 else if ((int *)varp == &p_ic && p_hls)
8282 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008283 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008284 }
8285
8286#ifdef FEAT_SEARCH_EXTRA
8287 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8288 else if ((int *)varp == &p_hls)
8289 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008290 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008291 }
8292#endif
8293
8294#ifdef FEAT_SCROLLBIND
8295 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8296 * at the end of normal_cmd() */
8297 else if ((int *)varp == &curwin->w_p_scb)
8298 {
8299 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008300 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008301 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008302 curwin->w_scbind_pos = curwin->w_topline;
8303 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008304 }
8305#endif
8306
Bram Moolenaar4033c552017-09-16 20:54:51 +02008307#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008308 /* There can be only one window with 'previewwindow' set. */
8309 else if ((int *)varp == &curwin->w_p_pvw)
8310 {
8311 if (curwin->w_p_pvw)
8312 {
8313 win_T *win;
8314
Bram Moolenaar29323592016-07-24 22:04:11 +02008315 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008316 if (win->w_p_pvw && win != curwin)
8317 {
8318 curwin->w_p_pvw = FALSE;
8319 return (char_u *)N_("E590: A preview window already exists");
8320 }
8321 }
8322 }
8323#endif
8324
8325 /* when 'textmode' is set or reset also change 'fileformat' */
8326 else if ((int *)varp == &curbuf->b_p_tx)
8327 {
8328 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8329 }
8330
8331 /* when 'textauto' is set or reset also change 'fileformats' */
8332 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008333 set_string_option_direct((char_u *)"ffs", -1,
8334 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008335 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008336
8337 /*
8338 * When 'lisp' option changes include/exclude '-' in
8339 * keyword characters.
8340 */
8341#ifdef FEAT_LISP
8342 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8343 {
8344 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8345 }
8346#endif
8347
8348#ifdef FEAT_TITLE
8349 /* when 'title' changed, may need to change the title; same for 'icon' */
8350 else if ((int *)varp == &p_title)
8351 {
8352 did_set_title(FALSE);
8353 }
8354
8355 else if ((int *)varp == &p_icon)
8356 {
8357 did_set_title(TRUE);
8358 }
8359#endif
8360
8361 else if ((int *)varp == &curbuf->b_changed)
8362 {
8363 if (!value)
8364 save_file_ff(curbuf); /* Buffer is unchanged */
8365#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008366 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008367#endif
8368#ifdef FEAT_AUTOCMD
8369 modified_was_set = value;
8370#endif
8371 }
8372
8373#ifdef BACKSLASH_IN_FILENAME
8374 else if ((int *)varp == &p_ssl)
8375 {
8376 if (p_ssl)
8377 {
8378 psepc = '/';
8379 psepcN = '\\';
8380 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008381 }
8382 else
8383 {
8384 psepc = '\\';
8385 psepcN = '/';
8386 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008387 }
8388
8389 /* need to adjust the file name arguments and buffer names. */
8390 buflist_slash_adjust();
8391 alist_slash_adjust();
8392# ifdef FEAT_EVAL
8393 scriptnames_slash_adjust();
8394# endif
8395 }
8396#endif
8397
8398 /* If 'wrap' is set, set w_leftcol to zero. */
8399 else if ((int *)varp == &curwin->w_p_wrap)
8400 {
8401 if (curwin->w_p_wrap)
8402 curwin->w_leftcol = 0;
8403 }
8404
Bram Moolenaar071d4272004-06-13 20:20:40 +00008405 else if ((int *)varp == &p_ea)
8406 {
8407 if (p_ea && !old_value)
8408 win_equal(curwin, FALSE, 0);
8409 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008410
8411 else if ((int *)varp == &p_wiv)
8412 {
8413 /*
8414 * When 'weirdinvert' changed, set/reset 't_xs'.
8415 * Then set 'weirdinvert' according to value of 't_xs'.
8416 */
8417 if (p_wiv && !old_value)
8418 T_XS = (char_u *)"y";
8419 else if (!p_wiv && old_value)
8420 T_XS = empty_option;
8421 p_wiv = (*T_XS != NUL);
8422 }
8423
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008424#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008425 else if ((int *)varp == &p_beval)
8426 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008427 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008428 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008429 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008430 gui_mch_disable_beval_area(balloonEval);
8431 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008432#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008433
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008434#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008435 else if ((int *)varp == &p_acd)
8436 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008437 /* Change directories when the 'acd' option is set now. */
8438 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008439 }
8440#endif
8441
8442#ifdef FEAT_DIFF
8443 /* 'diff' */
8444 else if ((int *)varp == &curwin->w_p_diff)
8445 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008446 /* May add or remove the buffer from the list of diff buffers. */
8447 diff_buf_adjust(curwin);
8448# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008449 if (foldmethodIsDiff(curwin))
8450 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008451# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008452 }
8453#endif
8454
8455#ifdef USE_IM_CONTROL
8456 /* 'imdisable' */
8457 else if ((int *)varp == &p_imdisable)
8458 {
8459 /* Only de-activate it here, it will be enabled when changing mode. */
8460 if (p_imdisable)
8461 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008462 else if (State & INSERT)
8463 /* When the option is set from an autocommand, it may need to take
8464 * effect right away. */
8465 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008466 }
8467#endif
8468
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008469#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008470 /* 'spell' */
8471 else if ((int *)varp == &curwin->w_p_spell)
8472 {
8473 if (curwin->w_p_spell)
8474 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008475 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008476 if (errmsg != NULL)
8477 EMSG(_(errmsg));
8478 }
8479 }
8480#endif
8481
Bram Moolenaar071d4272004-06-13 20:20:40 +00008482#ifdef FEAT_FKMAP
8483 else if ((int *)varp == &p_altkeymap)
8484 {
8485 if (old_value != p_altkeymap)
8486 {
8487 if (!p_altkeymap)
8488 {
8489 p_hkmap = p_fkmap;
8490 p_fkmap = 0;
8491 }
8492 else
8493 {
8494 p_fkmap = p_hkmap;
8495 p_hkmap = 0;
8496 }
8497 (void)init_chartab();
8498 }
8499 }
8500
8501 /*
8502 * In case some second language keymapping options have changed, check
8503 * and correct the setting in a consistent way.
8504 */
8505
8506 /*
8507 * If hkmap or fkmap are set, reset Arabic keymapping.
8508 */
8509 if ((p_hkmap || p_fkmap) && p_altkeymap)
8510 {
8511 p_altkeymap = p_fkmap;
8512# ifdef FEAT_ARABIC
8513 curwin->w_p_arab = FALSE;
8514# endif
8515 (void)init_chartab();
8516 }
8517
8518 /*
8519 * If hkmap set, reset Farsi keymapping.
8520 */
8521 if (p_hkmap && p_altkeymap)
8522 {
8523 p_altkeymap = 0;
8524 p_fkmap = 0;
8525# ifdef FEAT_ARABIC
8526 curwin->w_p_arab = FALSE;
8527# endif
8528 (void)init_chartab();
8529 }
8530
8531 /*
8532 * If fkmap set, reset Hebrew keymapping.
8533 */
8534 if (p_fkmap && !p_altkeymap)
8535 {
8536 p_altkeymap = 1;
8537 p_hkmap = 0;
8538# ifdef FEAT_ARABIC
8539 curwin->w_p_arab = FALSE;
8540# endif
8541 (void)init_chartab();
8542 }
8543#endif
8544
8545#ifdef FEAT_ARABIC
8546 if ((int *)varp == &curwin->w_p_arab)
8547 {
8548 if (curwin->w_p_arab)
8549 {
8550 /*
8551 * 'arabic' is set, handle various sub-settings.
8552 */
8553 if (!p_tbidi)
8554 {
8555 /* set rightleft mode */
8556 if (!curwin->w_p_rl)
8557 {
8558 curwin->w_p_rl = TRUE;
8559 changed_window_setting();
8560 }
8561
8562 /* Enable Arabic shaping (major part of what Arabic requires) */
8563 if (!p_arshape)
8564 {
8565 p_arshape = TRUE;
8566 redraw_later_clear();
8567 }
8568 }
8569
8570 /* Arabic requires a utf-8 encoding, inform the user if its not
8571 * set. */
8572 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008573 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008574 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8575
Bram Moolenaar8820b482017-03-16 17:23:31 +01008576 msg_source(HL_ATTR(HLF_W));
8577 MSG_ATTR(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008578#ifdef FEAT_EVAL
8579 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8580#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008581 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008582
8583# ifdef FEAT_MBYTE
8584 /* set 'delcombine' */
8585 p_deco = TRUE;
8586# endif
8587
8588# ifdef FEAT_KEYMAP
8589 /* Force-set the necessary keymap for arabic */
8590 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8591 OPT_LOCAL);
8592# endif
8593# ifdef FEAT_FKMAP
8594 p_altkeymap = 0;
8595 p_hkmap = 0;
8596 p_fkmap = 0;
8597 (void)init_chartab();
8598# endif
8599 }
8600 else
8601 {
8602 /*
8603 * 'arabic' is reset, handle various sub-settings.
8604 */
8605 if (!p_tbidi)
8606 {
8607 /* reset rightleft mode */
8608 if (curwin->w_p_rl)
8609 {
8610 curwin->w_p_rl = FALSE;
8611 changed_window_setting();
8612 }
8613
8614 /* 'arabicshape' isn't reset, it is a global option and
8615 * another window may still need it "on". */
8616 }
8617
8618 /* 'delcombine' isn't reset, it is a global option and another
8619 * window may still want it "on". */
8620
8621# ifdef FEAT_KEYMAP
8622 /* Revert to the default keymap */
8623 curbuf->b_p_iminsert = B_IMODE_NONE;
8624 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8625# endif
8626 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008627 }
8628
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008629#endif
8630
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008631#ifdef FEAT_TERMGUICOLORS
8632 /* 'termguicolors' */
8633 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008634 {
8635# ifdef FEAT_GUI
8636 if (!gui.in_use && !gui.starting)
8637# endif
8638 highlight_gui_started();
8639 }
8640#endif
8641
Bram Moolenaar071d4272004-06-13 20:20:40 +00008642 /*
8643 * End of handling side effects for bool options.
8644 */
8645
Bram Moolenaar53744302015-07-17 17:38:22 +02008646 /* after handling side effects, call autocommand */
8647
Bram Moolenaar071d4272004-06-13 20:20:40 +00008648 options[opt_idx].flags |= P_WAS_SET;
8649
Bram Moolenaar53744302015-07-17 17:38:22 +02008650#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8651 if (!starting)
8652 {
8653 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008654 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8655 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8656 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008657 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8658 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8659 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8660 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8661 reset_v_option_vars();
8662 }
8663#endif
8664
Bram Moolenaar071d4272004-06-13 20:20:40 +00008665 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008666 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008667 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008668 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008669 check_redraw(options[opt_idx].flags);
8670
8671 return NULL;
8672}
8673
8674/*
8675 * Set the value of a number option, and take care of side effects.
8676 * Returns NULL for success, or an error message for an error.
8677 */
8678 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008679set_num_option(
8680 int opt_idx, /* index in options[] table */
8681 char_u *varp, /* pointer to the option variable */
8682 long value, /* new value */
8683 char_u *errbuf, /* buffer for error messages */
8684 size_t errbuflen, /* length of "errbuf" */
8685 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008686 OPT_MODELINE */
8687{
8688 char_u *errmsg = NULL;
8689 long old_value = *(long *)varp;
8690 long old_Rows = Rows; /* remember old Rows */
8691 long old_Columns = Columns; /* remember old Columns */
8692 long *pp = (long *)varp;
8693
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008694 /* Disallow changing some options from secure mode. */
8695 if ((secure
8696#ifdef HAVE_SANDBOX
8697 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008698#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008699 ) && (options[opt_idx].flags & P_SECURE))
8700 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008701
8702 *pp = value;
8703#ifdef FEAT_EVAL
8704 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008705 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008706#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008707#ifdef FEAT_GUI
8708 need_mouse_correct = TRUE;
8709#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008710
Bram Moolenaar14f24742012-08-08 18:01:05 +02008711 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008712 {
8713 errmsg = e_positive;
8714 curbuf->b_p_sw = curbuf->b_p_ts;
8715 }
8716
8717 /*
8718 * Number options that need some action when changed
8719 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008720 if (pp == &p_wh || pp == &p_hh)
8721 {
8722 if (p_wh < 1)
8723 {
8724 errmsg = e_positive;
8725 p_wh = 1;
8726 }
8727 if (p_wmh > p_wh)
8728 {
8729 errmsg = e_winheight;
8730 p_wh = p_wmh;
8731 }
8732 if (p_hh < 0)
8733 {
8734 errmsg = e_positive;
8735 p_hh = 0;
8736 }
8737
8738 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008739 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008740 {
8741 if (pp == &p_wh && curwin->w_height < p_wh)
8742 win_setheight((int)p_wh);
8743 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8744 win_setheight((int)p_hh);
8745 }
8746 }
8747
8748 /* 'winminheight' */
8749 else if (pp == &p_wmh)
8750 {
8751 if (p_wmh < 0)
8752 {
8753 errmsg = e_positive;
8754 p_wmh = 0;
8755 }
8756 if (p_wmh > p_wh)
8757 {
8758 errmsg = e_winheight;
8759 p_wmh = p_wh;
8760 }
8761 win_setminheight();
8762 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008763 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008764 {
8765 if (p_wiw < 1)
8766 {
8767 errmsg = e_positive;
8768 p_wiw = 1;
8769 }
8770 if (p_wmw > p_wiw)
8771 {
8772 errmsg = e_winwidth;
8773 p_wiw = p_wmw;
8774 }
8775
8776 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008777 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008778 win_setwidth((int)p_wiw);
8779 }
8780
8781 /* 'winminwidth' */
8782 else if (pp == &p_wmw)
8783 {
8784 if (p_wmw < 0)
8785 {
8786 errmsg = e_positive;
8787 p_wmw = 0;
8788 }
8789 if (p_wmw > p_wiw)
8790 {
8791 errmsg = e_winwidth;
8792 p_wmw = p_wiw;
8793 }
8794 win_setminheight();
8795 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008796
Bram Moolenaar071d4272004-06-13 20:20:40 +00008797 /* (re)set last window status line */
8798 else if (pp == &p_ls)
8799 {
8800 last_status(FALSE);
8801 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008802
8803 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008804 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008805 {
8806 shell_new_rows(); /* recompute window positions and heights */
8807 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008808
8809#ifdef FEAT_GUI
8810 else if (pp == &p_linespace)
8811 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008812 /* Recompute gui.char_height and resize the Vim window to keep the
8813 * same number of lines. */
8814 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008815 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008816 }
8817#endif
8818
8819#ifdef FEAT_FOLDING
8820 /* 'foldlevel' */
8821 else if (pp == &curwin->w_p_fdl)
8822 {
8823 if (curwin->w_p_fdl < 0)
8824 curwin->w_p_fdl = 0;
8825 newFoldLevel();
8826 }
8827
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008828 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008829 else if (pp == &curwin->w_p_fml)
8830 {
8831 foldUpdateAll(curwin);
8832 }
8833
8834 /* 'foldnestmax' */
8835 else if (pp == &curwin->w_p_fdn)
8836 {
8837 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8838 foldUpdateAll(curwin);
8839 }
8840
8841 /* 'foldcolumn' */
8842 else if (pp == &curwin->w_p_fdc)
8843 {
8844 if (curwin->w_p_fdc < 0)
8845 {
8846 errmsg = e_positive;
8847 curwin->w_p_fdc = 0;
8848 }
8849 else if (curwin->w_p_fdc > 12)
8850 {
8851 errmsg = e_invarg;
8852 curwin->w_p_fdc = 12;
8853 }
8854 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008855#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008856
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008857#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008858 /* 'shiftwidth' or 'tabstop' */
8859 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8860 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008861# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008862 if (foldmethodIsIndent(curwin))
8863 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008864# endif
8865# ifdef FEAT_CINDENT
8866 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8867 * parse 'cinoptions'. */
8868 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8869 parse_cino(curbuf);
8870# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008871 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008872#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008873
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008874#ifdef FEAT_MBYTE
8875 /* 'maxcombine' */
8876 else if (pp == &p_mco)
8877 {
8878 if (p_mco > MAX_MCO)
8879 p_mco = MAX_MCO;
8880 else if (p_mco < 0)
8881 p_mco = 0;
8882 screenclear(); /* will re-allocate the screen */
8883 }
8884#endif
8885
Bram Moolenaar071d4272004-06-13 20:20:40 +00008886 else if (pp == &curbuf->b_p_iminsert)
8887 {
8888 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8889 {
8890 errmsg = e_invarg;
8891 curbuf->b_p_iminsert = B_IMODE_NONE;
8892 }
8893 p_iminsert = curbuf->b_p_iminsert;
8894 if (termcap_active) /* don't do this in the alternate screen */
8895 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02008896#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008897 /* Show/unshow value of 'keymap' in status lines. */
8898 status_redraw_curbuf();
8899#endif
8900 }
8901
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02008902#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
8903 /* 'imstyle' */
8904 else if (pp == &p_imst)
8905 {
8906 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
8907 errmsg = e_invarg;
8908 }
8909#endif
8910
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008911 else if (pp == &p_window)
8912 {
8913 if (p_window < 1)
8914 p_window = 1;
8915 else if (p_window >= Rows)
8916 p_window = Rows - 1;
8917 }
8918
Bram Moolenaar071d4272004-06-13 20:20:40 +00008919 else if (pp == &curbuf->b_p_imsearch)
8920 {
8921 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8922 {
8923 errmsg = e_invarg;
8924 curbuf->b_p_imsearch = B_IMODE_NONE;
8925 }
8926 p_imsearch = curbuf->b_p_imsearch;
8927 }
8928
8929#ifdef FEAT_TITLE
8930 /* if 'titlelen' has changed, redraw the title */
8931 else if (pp == &p_titlelen)
8932 {
8933 if (p_titlelen < 0)
8934 {
8935 errmsg = e_positive;
8936 p_titlelen = 85;
8937 }
8938 if (starting != NO_SCREEN && old_value != p_titlelen)
8939 need_maketitle = TRUE;
8940 }
8941#endif
8942
8943 /* if p_ch changed value, change the command line height */
8944 else if (pp == &p_ch)
8945 {
8946 if (p_ch < 1)
8947 {
8948 errmsg = e_positive;
8949 p_ch = 1;
8950 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008951 if (p_ch > Rows - min_rows() + 1)
8952 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008953
8954 /* Only compute the new window layout when startup has been
8955 * completed. Otherwise the frame sizes may be wrong. */
8956 if (p_ch != old_value && full_screen
8957#ifdef FEAT_GUI
8958 && !gui.starting
8959#endif
8960 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008961 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008962 }
8963
8964 /* when 'updatecount' changes from zero to non-zero, open swap files */
8965 else if (pp == &p_uc)
8966 {
8967 if (p_uc < 0)
8968 {
8969 errmsg = e_positive;
8970 p_uc = 100;
8971 }
8972 if (p_uc && !old_value)
8973 ml_open_files();
8974 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008975#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008976 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008977 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008978 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008979 {
8980 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008981 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008982 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008983 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008984 {
8985 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008986 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008987 }
8988 }
8989#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008990#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008991 else if (pp == &p_mzq)
8992 mzvim_reset_timer();
8993#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008994
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01008995#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
8996 /* 'pyxversion' */
8997 else if (pp == &p_pyx)
8998 {
8999 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9000 errmsg = e_invarg;
9001 }
9002#endif
9003
Bram Moolenaar071d4272004-06-13 20:20:40 +00009004 /* sync undo before 'undolevels' changes */
9005 else if (pp == &p_ul)
9006 {
9007 /* use the old value, otherwise u_sync() may not work properly */
9008 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009009 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009010 p_ul = value;
9011 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009012 else if (pp == &curbuf->b_p_ul)
9013 {
9014 /* use the old value, otherwise u_sync() may not work properly */
9015 curbuf->b_p_ul = old_value;
9016 u_sync(TRUE);
9017 curbuf->b_p_ul = value;
9018 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009019
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009020#ifdef FEAT_LINEBREAK
9021 /* 'numberwidth' must be positive */
9022 else if (pp == &curwin->w_p_nuw)
9023 {
9024 if (curwin->w_p_nuw < 1)
9025 {
9026 errmsg = e_positive;
9027 curwin->w_p_nuw = 1;
9028 }
9029 if (curwin->w_p_nuw > 10)
9030 {
9031 errmsg = e_invarg;
9032 curwin->w_p_nuw = 10;
9033 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009034 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009035 }
9036#endif
9037
Bram Moolenaar1a384422010-07-14 19:53:30 +02009038 else if (pp == &curbuf->b_p_tw)
9039 {
9040 if (curbuf->b_p_tw < 0)
9041 {
9042 errmsg = e_positive;
9043 curbuf->b_p_tw = 0;
9044 }
9045#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009046 {
9047 win_T *wp;
9048 tabpage_T *tp;
9049
9050 FOR_ALL_TAB_WINDOWS(tp, wp)
9051 check_colorcolumn(wp);
9052 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009053#endif
9054 }
9055
Bram Moolenaar071d4272004-06-13 20:20:40 +00009056 /*
9057 * Check the bounds for numeric options here
9058 */
9059 if (Rows < min_rows() && full_screen)
9060 {
9061 if (errbuf != NULL)
9062 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009063 vim_snprintf((char *)errbuf, errbuflen,
9064 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009065 errmsg = errbuf;
9066 }
9067 Rows = min_rows();
9068 }
9069 if (Columns < MIN_COLUMNS && full_screen)
9070 {
9071 if (errbuf != NULL)
9072 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009073 vim_snprintf((char *)errbuf, errbuflen,
9074 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009075 errmsg = errbuf;
9076 }
9077 Columns = MIN_COLUMNS;
9078 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009079 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009080
Bram Moolenaar071d4272004-06-13 20:20:40 +00009081 /*
9082 * If the screen (shell) height has been changed, assume it is the
9083 * physical screenheight.
9084 */
9085 if (old_Rows != Rows || old_Columns != Columns)
9086 {
9087 /* Changing the screen size is not allowed while updating the screen. */
9088 if (updating_screen)
9089 *pp = old_value;
9090 else if (full_screen
9091#ifdef FEAT_GUI
9092 && !gui.starting
9093#endif
9094 )
9095 set_shellsize((int)Columns, (int)Rows, TRUE);
9096 else
9097 {
9098 /* Postpone the resizing; check the size and cmdline position for
9099 * messages. */
9100 check_shellsize();
9101 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9102 cmdline_row = Rows - p_ch;
9103 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009104 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009105 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009106 }
9107
Bram Moolenaar071d4272004-06-13 20:20:40 +00009108 if (curbuf->b_p_ts <= 0)
9109 {
9110 errmsg = e_positive;
9111 curbuf->b_p_ts = 8;
9112 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009113 if (p_tm < 0)
9114 {
9115 errmsg = e_positive;
9116 p_tm = 0;
9117 }
9118 if ((curwin->w_p_scr <= 0
9119 || (curwin->w_p_scr > curwin->w_height
9120 && curwin->w_height > 0))
9121 && full_screen)
9122 {
9123 if (pp == &(curwin->w_p_scr))
9124 {
9125 if (curwin->w_p_scr != 0)
9126 errmsg = e_scroll;
9127 win_comp_scroll(curwin);
9128 }
9129 /* If 'scroll' became invalid because of a side effect silently adjust
9130 * it. */
9131 else if (curwin->w_p_scr <= 0)
9132 curwin->w_p_scr = 1;
9133 else /* curwin->w_p_scr > curwin->w_height */
9134 curwin->w_p_scr = curwin->w_height;
9135 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009136 if (p_hi < 0)
9137 {
9138 errmsg = e_positive;
9139 p_hi = 0;
9140 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009141 else if (p_hi > 10000)
9142 {
9143 errmsg = e_invarg;
9144 p_hi = 10000;
9145 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009146 if (p_re < 0 || p_re > 2)
9147 {
9148 errmsg = e_invarg;
9149 p_re = 0;
9150 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009151 if (p_report < 0)
9152 {
9153 errmsg = e_positive;
9154 p_report = 1;
9155 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009156 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009157 {
9158 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9159 p_sj = Rows / 2;
9160 else
9161 {
9162 errmsg = e_scroll;
9163 p_sj = 1;
9164 }
9165 }
9166 if (p_so < 0 && full_screen)
9167 {
9168 errmsg = e_scroll;
9169 p_so = 0;
9170 }
9171 if (p_siso < 0 && full_screen)
9172 {
9173 errmsg = e_positive;
9174 p_siso = 0;
9175 }
9176#ifdef FEAT_CMDWIN
9177 if (p_cwh < 1)
9178 {
9179 errmsg = e_positive;
9180 p_cwh = 1;
9181 }
9182#endif
9183 if (p_ut < 0)
9184 {
9185 errmsg = e_positive;
9186 p_ut = 2000;
9187 }
9188 if (p_ss < 0)
9189 {
9190 errmsg = e_positive;
9191 p_ss = 0;
9192 }
9193
9194 /* May set global value for local option. */
9195 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9196 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9197
9198 options[opt_idx].flags |= P_WAS_SET;
9199
Bram Moolenaar53744302015-07-17 17:38:22 +02009200#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
9201 if (!starting && errmsg == NULL)
9202 {
9203 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009204 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9205 vim_snprintf((char *)buf_new, 10, "%ld", value);
9206 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009207 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9208 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9209 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9210 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9211 reset_v_option_vars();
9212 }
9213#endif
9214
Bram Moolenaar071d4272004-06-13 20:20:40 +00009215 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009216 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009217 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009218 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009219 check_redraw(options[opt_idx].flags);
9220
9221 return errmsg;
9222}
9223
9224/*
9225 * Called after an option changed: check if something needs to be redrawn.
9226 */
9227 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009228check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009229{
9230 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009231 int doclear = (flags & P_RCLR) == P_RCLR;
9232 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009233
Bram Moolenaar071d4272004-06-13 20:20:40 +00009234 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9235 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009236
9237 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9238 changed_window_setting();
9239 if (flags & P_RBUF)
9240 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009241 if (flags & P_RWINONLY)
9242 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009243 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009244 redraw_all_later(CLEAR);
9245 else if (all)
9246 redraw_all_later(NOT_VALID);
9247}
9248
9249/*
9250 * Find index for option 'arg'.
9251 * Return -1 if not found.
9252 */
9253 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009254findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009255{
9256 int opt_idx;
9257 char *s, *p;
9258 static short quick_tab[27] = {0, 0}; /* quick access table */
9259 int is_term_opt;
9260
9261 /*
9262 * For first call: Initialize the quick-access table.
9263 * It contains the index for the first option that starts with a certain
9264 * letter. There are 26 letters, plus the first "t_" option.
9265 */
9266 if (quick_tab[1] == 0)
9267 {
9268 p = options[0].fullname;
9269 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9270 {
9271 if (s[0] != p[0])
9272 {
9273 if (s[0] == 't' && s[1] == '_')
9274 quick_tab[26] = opt_idx;
9275 else
9276 quick_tab[CharOrdLow(s[0])] = opt_idx;
9277 }
9278 p = s;
9279 }
9280 }
9281
9282 /*
9283 * Check for name starting with an illegal character.
9284 */
9285#ifdef EBCDIC
9286 if (!islower(arg[0]))
9287#else
9288 if (arg[0] < 'a' || arg[0] > 'z')
9289#endif
9290 return -1;
9291
9292 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9293 if (is_term_opt)
9294 opt_idx = quick_tab[26];
9295 else
9296 opt_idx = quick_tab[CharOrdLow(arg[0])];
9297 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9298 {
9299 if (STRCMP(arg, s) == 0) /* match full name */
9300 break;
9301 }
9302 if (s == NULL && !is_term_opt)
9303 {
9304 opt_idx = quick_tab[CharOrdLow(arg[0])];
9305 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9306 {
9307 s = options[opt_idx].shortname;
9308 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9309 break;
9310 s = NULL;
9311 }
9312 }
9313 if (s == NULL)
9314 opt_idx = -1;
9315 return opt_idx;
9316}
9317
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009318#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009319/*
9320 * Get the value for an option.
9321 *
9322 * Returns:
9323 * Number or Toggle option: 1, *numval gets value.
9324 * String option: 0, *stringval gets allocated string.
9325 * Hidden Number or Toggle option: -1.
9326 * hidden String option: -2.
9327 * unknown option: -3.
9328 */
9329 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009330get_option_value(
9331 char_u *name,
9332 long *numval,
9333 char_u **stringval, /* NULL when only checking existence */
9334 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009335{
9336 int opt_idx;
9337 char_u *varp;
9338
9339 opt_idx = findoption(name);
9340 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009341 {
9342 int key;
9343
9344 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9345 && (key = find_key_option(name)) != 0)
9346 {
9347 char_u key_name[2];
9348 char_u *p;
9349
9350 if (key < 0)
9351 {
9352 key_name[0] = KEY2TERMCAP0(key);
9353 key_name[1] = KEY2TERMCAP1(key);
9354 }
9355 else
9356 {
9357 key_name[0] = KS_KEY;
9358 key_name[1] = (key & 0xff);
9359 }
9360 p = find_termcode(key_name);
9361 if (p != NULL)
9362 {
9363 if (stringval != NULL)
9364 *stringval = vim_strsave(p);
9365 return 0;
9366 }
9367 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009368 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009369 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009370
9371 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9372
9373 if (options[opt_idx].flags & P_STRING)
9374 {
9375 if (varp == NULL) /* hidden option */
9376 return -2;
9377 if (stringval != NULL)
9378 {
9379#ifdef FEAT_CRYPT
9380 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009381 if ((char_u **)varp == &curbuf->b_p_key
9382 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009383 *stringval = vim_strsave((char_u *)"*****");
9384 else
9385#endif
9386 *stringval = vim_strsave(*(char_u **)(varp));
9387 }
9388 return 0;
9389 }
9390
9391 if (varp == NULL) /* hidden option */
9392 return -1;
9393 if (options[opt_idx].flags & P_NUM)
9394 *numval = *(long *)varp;
9395 else
9396 {
9397 /* Special case: 'modified' is b_changed, but we also want to consider
9398 * it set when 'ff' or 'fenc' changed. */
9399 if ((int *)varp == &curbuf->b_changed)
9400 *numval = curbufIsChanged();
9401 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009402 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009403 }
9404 return 1;
9405}
9406#endif
9407
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009408#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009409/*
9410 * Returns the option attributes and its value. Unlike the above function it
9411 * will return either global value or local value of the option depending on
9412 * what was requested, but it will never return global value if it was
9413 * requested to return local one and vice versa. Neither it will return
9414 * buffer-local value if it was requested to return window-local one.
9415 *
9416 * Pretends that option is absent if it is not present in the requested scope
9417 * (i.e. has no global, window-local or buffer-local value depending on
9418 * opt_type). Uses
9419 *
9420 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009421 * 0 hidden or unknown option, also option that does not have requested
9422 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009423 * see SOPT_* in vim.h for other flags
9424 *
9425 * Possible opt_type values: see SREQ_* in vim.h
9426 */
9427 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009428get_option_value_strict(
9429 char_u *name,
9430 long *numval,
9431 char_u **stringval, /* NULL when only obtaining attributes */
9432 int opt_type,
9433 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009434{
9435 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009436 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009437 struct vimoption *p;
9438 int r = 0;
9439
9440 opt_idx = findoption(name);
9441 if (opt_idx < 0)
9442 return 0;
9443
9444 p = &(options[opt_idx]);
9445
9446 /* Hidden option */
9447 if (p->var == NULL)
9448 return 0;
9449
9450 if (p->flags & P_BOOL)
9451 r |= SOPT_BOOL;
9452 else if (p->flags & P_NUM)
9453 r |= SOPT_NUM;
9454 else if (p->flags & P_STRING)
9455 r |= SOPT_STRING;
9456
9457 if (p->indir == PV_NONE)
9458 {
9459 if (opt_type == SREQ_GLOBAL)
9460 r |= SOPT_GLOBAL;
9461 else
9462 return 0; /* Did not request global-only option */
9463 }
9464 else
9465 {
9466 if (p->indir & PV_BOTH)
9467 r |= SOPT_GLOBAL;
9468 else if (opt_type == SREQ_GLOBAL)
9469 return 0; /* Requested global option */
9470
9471 if (p->indir & PV_WIN)
9472 {
9473 if (opt_type == SREQ_BUF)
9474 return 0; /* Did not request window-local option */
9475 else
9476 r |= SOPT_WIN;
9477 }
9478 else if (p->indir & PV_BUF)
9479 {
9480 if (opt_type == SREQ_WIN)
9481 return 0; /* Did not request buffer-local option */
9482 else
9483 r |= SOPT_BUF;
9484 }
9485 }
9486
9487 if (stringval == NULL)
9488 return r;
9489
9490 if (opt_type == SREQ_GLOBAL)
9491 varp = p->var;
9492 else
9493 {
9494 if (opt_type == SREQ_BUF)
9495 {
9496 /* Special case: 'modified' is b_changed, but we also want to
9497 * consider it set when 'ff' or 'fenc' changed. */
9498 if (p->indir == PV_MOD)
9499 {
9500 *numval = bufIsChanged((buf_T *) from);
9501 varp = NULL;
9502 }
9503#ifdef FEAT_CRYPT
9504 else if (p->indir == PV_KEY)
9505 {
9506 /* never return the value of the crypt key */
9507 *stringval = NULL;
9508 varp = NULL;
9509 }
9510#endif
9511 else
9512 {
9513 aco_save_T aco;
9514 aucmd_prepbuf(&aco, (buf_T *) from);
9515 varp = get_varp(p);
9516 aucmd_restbuf(&aco);
9517 }
9518 }
9519 else if (opt_type == SREQ_WIN)
9520 {
9521 win_T *save_curwin;
9522 save_curwin = curwin;
9523 curwin = (win_T *) from;
9524 curbuf = curwin->w_buffer;
9525 varp = get_varp(p);
9526 curwin = save_curwin;
9527 curbuf = curwin->w_buffer;
9528 }
9529 if (varp == p->var)
9530 return (r | SOPT_UNSET);
9531 }
9532
9533 if (varp != NULL)
9534 {
9535 if (p->flags & P_STRING)
9536 *stringval = vim_strsave(*(char_u **)(varp));
9537 else if (p->flags & P_NUM)
9538 *numval = *(long *) varp;
9539 else
9540 *numval = *(int *)varp;
9541 }
9542
9543 return r;
9544}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009545
9546/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009547 * Iterate over options. First argument is a pointer to a pointer to a
9548 * structure inside options[] array, second is option type like in the above
9549 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009550 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009551 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009552 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009553 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009554 * first argument to NULL.
9555 *
9556 * Returns full option name for current option on each call.
9557 */
9558 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009559option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009560{
9561 struct vimoption *ret = NULL;
9562 do
9563 {
9564 if (*option == NULL)
9565 *option = (void *) options;
9566 else if (((struct vimoption *) (*option))->fullname == NULL)
9567 {
9568 *option = NULL;
9569 return NULL;
9570 }
9571 else
9572 *option = (void *) (((struct vimoption *) (*option)) + 1);
9573
9574 ret = ((struct vimoption *) (*option));
9575
9576 /* Hidden option */
9577 if (ret->var == NULL)
9578 {
9579 ret = NULL;
9580 continue;
9581 }
9582
9583 switch (opt_type)
9584 {
9585 case SREQ_GLOBAL:
9586 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9587 ret = NULL;
9588 break;
9589 case SREQ_BUF:
9590 if (!(ret->indir & PV_BUF))
9591 ret = NULL;
9592 break;
9593 case SREQ_WIN:
9594 if (!(ret->indir & PV_WIN))
9595 ret = NULL;
9596 break;
9597 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009598 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009599 return NULL;
9600 }
9601 }
9602 while (ret == NULL);
9603
9604 return (char_u *)ret->fullname;
9605}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009606#endif
9607
Bram Moolenaar071d4272004-06-13 20:20:40 +00009608/*
9609 * Set the value of option "name".
9610 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009611 *
9612 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009613 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009614 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009615set_option_value(
9616 char_u *name,
9617 long number,
9618 char_u *string,
9619 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009620{
9621 int opt_idx;
9622 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009623 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009624
9625 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009626 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009627 {
9628 int key;
9629
9630 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9631 && (key = find_key_option(name)) != 0)
9632 {
9633 char_u key_name[2];
9634
9635 if (key < 0)
9636 {
9637 key_name[0] = KEY2TERMCAP0(key);
9638 key_name[1] = KEY2TERMCAP1(key);
9639 }
9640 else
9641 {
9642 key_name[0] = KS_KEY;
9643 key_name[1] = (key & 0xff);
9644 }
9645 add_termcode(key_name, string, FALSE);
9646 if (full_screen)
9647 ttest(FALSE);
9648 redraw_all_later(CLEAR);
9649 return NULL;
9650 }
9651
Bram Moolenaar071d4272004-06-13 20:20:40 +00009652 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009653 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009654 else
9655 {
9656 flags = options[opt_idx].flags;
9657#ifdef HAVE_SANDBOX
9658 /* Disallow changing some options in the sandbox */
9659 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009660 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009661 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009662 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009663 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009664#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009665 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009666 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009667 else
9668 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009669 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009670 if (varp != NULL) /* hidden option is not changed */
9671 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009672 if (number == 0 && string != NULL)
9673 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009674 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009675
9676 /* Either we are given a string or we are setting option
9677 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009678 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009679 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009680 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009681 {
9682 /* There's another character after zeros or the string
9683 * is empty. In both cases, we are trying to set a
9684 * num option using a string. */
9685 EMSG3(_("E521: Number required: &%s = '%s'"),
9686 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009687 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009688
9689 }
9690 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009691 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009692 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009693 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009694 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009695 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009696 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009697 }
9698 }
9699 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009700 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009701}
9702
9703/*
9704 * Get the terminal code for a terminal option.
9705 * Returns NULL when not found.
9706 */
9707 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009708get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009709{
9710 int opt_idx;
9711 char_u *varp;
9712
9713 if (tname[0] != 't' || tname[1] != '_' ||
9714 tname[2] == NUL || tname[3] == NUL)
9715 return NULL;
9716 if ((opt_idx = findoption(tname)) >= 0)
9717 {
9718 varp = get_varp(&(options[opt_idx]));
9719 if (varp != NULL)
9720 varp = *(char_u **)(varp);
9721 return varp;
9722 }
9723 return find_termcode(tname + 2);
9724}
9725
9726 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009727get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009728{
9729 int i;
9730
9731 i = findoption((char_u *)"hl");
9732 if (i >= 0)
9733 return options[i].def_val[VI_DEFAULT];
9734 return (char_u *)NULL;
9735}
9736
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009737#if defined(FEAT_MBYTE) || defined(PROTO)
9738 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009739get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009740{
9741 int i;
9742
9743 i = findoption((char_u *)"enc");
9744 if (i >= 0)
9745 return options[i].def_val[VI_DEFAULT];
9746 return (char_u *)NULL;
9747}
9748#endif
9749
Bram Moolenaar071d4272004-06-13 20:20:40 +00009750/*
9751 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9752 */
9753 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009754find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009755{
9756 int key;
9757 int modifiers;
9758
9759 /*
9760 * Don't use get_special_key_code() for t_xx, we don't want it to call
9761 * add_termcap_entry().
9762 */
9763 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9764 key = TERMCAP2KEY(arg[2], arg[3]);
9765 else
9766 {
9767 --arg; /* put arg at the '<' */
9768 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009769 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009770 if (modifiers) /* can't handle modifiers here */
9771 key = 0;
9772 }
9773 return key;
9774}
9775
9776/*
9777 * if 'all' == 0: show changed options
9778 * if 'all' == 1: show all normal options
9779 * if 'all' == 2: show all terminal options
9780 */
9781 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009782showoptions(
9783 int all,
9784 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009785{
9786 struct vimoption *p;
9787 int col;
9788 int isterm;
9789 char_u *varp;
9790 struct vimoption **items;
9791 int item_count;
9792 int run;
9793 int row, rows;
9794 int cols;
9795 int i;
9796 int len;
9797
9798#define INC 20
9799#define GAP 3
9800
9801 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9802 PARAM_COUNT));
9803 if (items == NULL)
9804 return;
9805
9806 /* Highlight title */
9807 if (all == 2)
9808 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9809 else if (opt_flags & OPT_GLOBAL)
9810 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9811 else if (opt_flags & OPT_LOCAL)
9812 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9813 else
9814 MSG_PUTS_TITLE(_("\n--- Options ---"));
9815
9816 /*
9817 * do the loop two times:
9818 * 1. display the short items
9819 * 2. display the long items (only strings and numbers)
9820 */
9821 for (run = 1; run <= 2 && !got_int; ++run)
9822 {
9823 /*
9824 * collect the items in items[]
9825 */
9826 item_count = 0;
9827 for (p = &options[0]; p->fullname != NULL; p++)
9828 {
9829 varp = NULL;
9830 isterm = istermoption(p);
9831 if (opt_flags != 0)
9832 {
9833 if (p->indir != PV_NONE && !isterm)
9834 varp = get_varp_scope(p, opt_flags);
9835 }
9836 else
9837 varp = get_varp(p);
9838 if (varp != NULL
9839 && ((all == 2 && isterm)
9840 || (all == 1 && !isterm)
9841 || (all == 0 && !optval_default(p, varp))))
9842 {
9843 if (p->flags & P_BOOL)
9844 len = 1; /* a toggle option fits always */
9845 else
9846 {
9847 option_value2string(p, opt_flags);
9848 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9849 }
9850 if ((len <= INC - GAP && run == 1) ||
9851 (len > INC - GAP && run == 2))
9852 items[item_count++] = p;
9853 }
9854 }
9855
9856 /*
9857 * display the items
9858 */
9859 if (run == 1)
9860 {
9861 cols = (Columns + GAP - 3) / INC;
9862 if (cols == 0)
9863 cols = 1;
9864 rows = (item_count + cols - 1) / cols;
9865 }
9866 else /* run == 2 */
9867 rows = item_count;
9868 for (row = 0; row < rows && !got_int; ++row)
9869 {
9870 msg_putchar('\n'); /* go to next line */
9871 if (got_int) /* 'q' typed in more */
9872 break;
9873 col = 0;
9874 for (i = row; i < item_count; i += rows)
9875 {
9876 msg_col = col; /* make columns */
9877 showoneopt(items[i], opt_flags);
9878 col += INC;
9879 }
9880 out_flush();
9881 ui_breakcheck();
9882 }
9883 }
9884 vim_free(items);
9885}
9886
9887/*
9888 * Return TRUE if option "p" has its default value.
9889 */
9890 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009891optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009892{
9893 int dvi;
9894
9895 if (varp == NULL)
9896 return TRUE; /* hidden option is always at default */
9897 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9898 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009899 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009900 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009901 /* the cast to long is required for Manx C, long_i is
9902 * needed for MSVC */
9903 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009904 /* P_STRING */
9905 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9906}
9907
9908/*
9909 * showoneopt: show the value of one option
9910 * must not be called with a hidden option!
9911 */
9912 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009913showoneopt(
9914 struct vimoption *p,
9915 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009916{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009917 char_u *varp;
9918 int save_silent = silent_mode;
9919
9920 silent_mode = FALSE;
9921 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009922
9923 varp = get_varp_scope(p, opt_flags);
9924
9925 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9926 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9927 ? !curbufIsChanged() : !*(int *)varp))
9928 MSG_PUTS("no");
9929 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9930 MSG_PUTS("--");
9931 else
9932 MSG_PUTS(" ");
9933 MSG_PUTS(p->fullname);
9934 if (!(p->flags & P_BOOL))
9935 {
9936 msg_putchar('=');
9937 /* put value string in NameBuff */
9938 option_value2string(p, opt_flags);
9939 msg_outtrans(NameBuff);
9940 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009941
9942 silent_mode = save_silent;
9943 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009944}
9945
9946/*
9947 * Write modified options as ":set" commands to a file.
9948 *
9949 * There are three values for "opt_flags":
9950 * OPT_GLOBAL: Write global option values and fresh values of
9951 * buffer-local options (used for start of a session
9952 * file).
9953 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9954 * curwin (used for a vimrc file).
9955 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9956 * and local values for window-local options of
9957 * curwin. Local values are also written when at the
9958 * default value, because a modeline or autocommand
9959 * may have set them when doing ":edit file" and the
9960 * user has set them back at the default or fresh
9961 * value.
9962 * When "local_only" is TRUE, don't write fresh
9963 * values, only local values (for ":mkview").
9964 * (fresh value = value used for a new buffer or window for a local option).
9965 *
9966 * Return FAIL on error, OK otherwise.
9967 */
9968 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009969makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009970{
9971 struct vimoption *p;
9972 char_u *varp; /* currently used value */
9973 char_u *varp_fresh; /* local value */
9974 char_u *varp_local = NULL; /* fresh value */
9975 char *cmd;
9976 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009977 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009978
9979 /*
9980 * The options that don't have a default (terminal name, columns, lines)
9981 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009982 * Do the loop over "options[]" twice: once for options with the
9983 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009984 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009985 for (pri = 1; pri >= 0; --pri)
9986 {
9987 for (p = &options[0]; !istermoption(p); p++)
9988 if (!(p->flags & P_NO_MKRC)
9989 && !istermoption(p)
9990 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009991 {
9992 /* skip global option when only doing locals */
9993 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9994 continue;
9995
9996 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9997 * file, they are always buffer-specific. */
9998 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9999 continue;
10000
10001 /* Global values are only written when not at the default value. */
10002 varp = get_varp_scope(p, opt_flags);
10003 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10004 continue;
10005
10006 round = 2;
10007 if (p->indir != PV_NONE)
10008 {
10009 if (p->var == VAR_WIN)
10010 {
10011 /* skip window-local option when only doing globals */
10012 if (!(opt_flags & OPT_LOCAL))
10013 continue;
10014 /* When fresh value of window-local option is not at the
10015 * default, need to write it too. */
10016 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10017 {
10018 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10019 if (!optval_default(p, varp_fresh))
10020 {
10021 round = 1;
10022 varp_local = varp;
10023 varp = varp_fresh;
10024 }
10025 }
10026 }
10027 }
10028
10029 /* Round 1: fresh value for window-local options.
10030 * Round 2: other values */
10031 for ( ; round <= 2; varp = varp_local, ++round)
10032 {
10033 if (round == 1 || (opt_flags & OPT_GLOBAL))
10034 cmd = "set";
10035 else
10036 cmd = "setlocal";
10037
10038 if (p->flags & P_BOOL)
10039 {
10040 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10041 return FAIL;
10042 }
10043 else if (p->flags & P_NUM)
10044 {
10045 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10046 return FAIL;
10047 }
10048 else /* P_STRING */
10049 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010050#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10051 int do_endif = FALSE;
10052
Bram Moolenaar071d4272004-06-13 20:20:40 +000010053 /* Don't set 'syntax' and 'filetype' again if the value is
10054 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010055 if (
10056# if defined(FEAT_SYN_HL)
10057 p->indir == PV_SYN
10058# if defined(FEAT_AUTOCMD)
10059 ||
10060# endif
10061# endif
10062# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010063 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010064# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010065 )
Bram Moolenaar071d4272004-06-13 20:20:40 +000010066 {
10067 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10068 *(char_u **)(varp)) < 0
10069 || put_eol(fd) < 0)
10070 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010071 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010072 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010073#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010074 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10075 (p->flags & P_EXPAND) != 0) == FAIL)
10076 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010077#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10078 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010079 {
10080 if (put_line(fd, "endif") == FAIL)
10081 return FAIL;
10082 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010083#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010084 }
10085 }
10086 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010087 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010088 return OK;
10089}
10090
10091#if defined(FEAT_FOLDING) || defined(PROTO)
10092/*
10093 * Generate set commands for the local fold options only. Used when
10094 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10095 */
10096 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010097makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010098{
10099 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10100# ifdef FEAT_EVAL
10101 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10102 == FAIL
10103# endif
10104 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10105 == FAIL
10106 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10107 == FAIL
10108 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10109 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10110 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10111 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10112 )
10113 return FAIL;
10114
10115 return OK;
10116}
10117#endif
10118
10119 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010120put_setstring(
10121 FILE *fd,
10122 char *cmd,
10123 char *name,
10124 char_u **valuep,
10125 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010126{
10127 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010128 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010129
10130 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10131 return FAIL;
10132 if (*valuep != NULL)
10133 {
10134 /* Output 'pastetoggle' as key names. For other
10135 * options some characters have to be escaped with
10136 * CTRL-V or backslash */
10137 if (valuep == &p_pt)
10138 {
10139 s = *valuep;
10140 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010141 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010142 return FAIL;
10143 }
10144 else if (expand)
10145 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010146 buf = alloc(MAXPATHL);
10147 if (buf == NULL)
10148 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010149 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10150 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010151 {
10152 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010153 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010154 }
10155 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010156 }
10157 else if (put_escstr(fd, *valuep, 2) == FAIL)
10158 return FAIL;
10159 }
10160 if (put_eol(fd) < 0)
10161 return FAIL;
10162 return OK;
10163}
10164
10165 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010166put_setnum(
10167 FILE *fd,
10168 char *cmd,
10169 char *name,
10170 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010171{
10172 long wc;
10173
10174 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10175 return FAIL;
10176 if (wc_use_keyname((char_u *)valuep, &wc))
10177 {
10178 /* print 'wildchar' and 'wildcharm' as a key name */
10179 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10180 return FAIL;
10181 }
10182 else if (fprintf(fd, "%ld", *valuep) < 0)
10183 return FAIL;
10184 if (put_eol(fd) < 0)
10185 return FAIL;
10186 return OK;
10187}
10188
10189 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010190put_setbool(
10191 FILE *fd,
10192 char *cmd,
10193 char *name,
10194 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010195{
Bram Moolenaar893de922007-10-02 18:40:57 +000010196 if (value < 0) /* global/local option using global value */
10197 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010198 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10199 || put_eol(fd) < 0)
10200 return FAIL;
10201 return OK;
10202}
10203
10204/*
10205 * Clear all the terminal options.
10206 * If the option has been allocated, free the memory.
10207 * Terminal options are never hidden or indirect.
10208 */
10209 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010210clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010211{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010212 /*
10213 * Reset a few things before clearing the old options. This may cause
10214 * outputting a few things that the terminal doesn't understand, but the
10215 * screen will be cleared later, so this is OK.
10216 */
10217#ifdef FEAT_MOUSE_TTY
10218 mch_setmouse(FALSE); /* switch mouse off */
10219#endif
10220#ifdef FEAT_TITLE
10221 mch_restore_title(3); /* restore window titles */
10222#endif
10223#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10224 /* When starting the GUI close the display opened for the clipboard.
10225 * After restoring the title, because that will need the display. */
10226 if (gui.starting)
10227 clear_xterm_clip();
10228#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010229 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010230
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010231 free_termoptions();
10232}
10233
10234 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010235free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010236{
10237 struct vimoption *p;
10238
Bram Moolenaar071d4272004-06-13 20:20:40 +000010239 for (p = &options[0]; p->fullname != NULL; p++)
10240 if (istermoption(p))
10241 {
10242 if (p->flags & P_ALLOCED)
10243 free_string_option(*(char_u **)(p->var));
10244 if (p->flags & P_DEF_ALLOCED)
10245 free_string_option(p->def_val[VI_DEFAULT]);
10246 *(char_u **)(p->var) = empty_option;
10247 p->def_val[VI_DEFAULT] = empty_option;
10248 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10249 }
10250 clear_termcodes();
10251}
10252
10253/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010254 * Free the string for one term option, if it was allocated.
10255 * Set the string to empty_option and clear allocated flag.
10256 * "var" points to the option value.
10257 */
10258 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010259free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010260{
10261 struct vimoption *p;
10262
10263 for (p = &options[0]; p->fullname != NULL; p++)
10264 if (p->var == var)
10265 {
10266 if (p->flags & P_ALLOCED)
10267 free_string_option(*(char_u **)(p->var));
10268 *(char_u **)(p->var) = empty_option;
10269 p->flags &= ~P_ALLOCED;
10270 break;
10271 }
10272}
10273
10274/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010275 * Set the terminal option defaults to the current value.
10276 * Used after setting the terminal name.
10277 */
10278 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010279set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010280{
10281 struct vimoption *p;
10282
10283 for (p = &options[0]; p->fullname != NULL; p++)
10284 {
10285 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10286 {
10287 if (p->flags & P_DEF_ALLOCED)
10288 {
10289 free_string_option(p->def_val[VI_DEFAULT]);
10290 p->flags &= ~P_DEF_ALLOCED;
10291 }
10292 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10293 if (p->flags & P_ALLOCED)
10294 {
10295 p->flags |= P_DEF_ALLOCED;
10296 p->flags &= ~P_ALLOCED; /* don't free the value now */
10297 }
10298 }
10299 }
10300}
10301
10302/*
10303 * return TRUE if 'p' starts with 't_'
10304 */
10305 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010306istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010307{
10308 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10309}
10310
10311/*
10312 * Compute columns for ruler and shown command. 'sc_col' is also used to
10313 * decide what the maximum length of a message on the status line can be.
10314 * If there is a status line for the last window, 'sc_col' is independent
10315 * of 'ru_col'.
10316 */
10317
10318#define COL_RULER 17 /* columns needed by standard ruler */
10319
10320 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010321comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010322{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010323#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010324 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010325
10326 sc_col = 0;
10327 ru_col = 0;
10328 if (p_ru)
10329 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010330# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010331 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010332# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010333 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010334# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010335 /* no last status line, adjust sc_col */
10336 if (!last_has_status)
10337 sc_col = ru_col;
10338 }
10339 if (p_sc)
10340 {
10341 sc_col += SHOWCMD_COLS;
10342 if (!p_ru || last_has_status) /* no need for separating space */
10343 ++sc_col;
10344 }
10345 sc_col = Columns - sc_col;
10346 ru_col = Columns - ru_col;
10347 if (sc_col <= 0) /* screen too narrow, will become a mess */
10348 sc_col = 1;
10349 if (ru_col <= 0)
10350 ru_col = 1;
10351#else
10352 sc_col = Columns;
10353 ru_col = Columns;
10354#endif
10355}
10356
10357/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010358 * Unset local option value, similar to ":set opt<".
10359 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010360 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010361unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010362{
10363 struct vimoption *p;
10364 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010365 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010366
10367 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010368 if (opt_idx < 0)
10369 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010370 p = &(options[opt_idx]);
10371
10372 switch ((int)p->indir)
10373 {
10374 /* global option with local value: use local value if it's been set */
10375 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010376 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010377 break;
10378 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010379 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010380 break;
10381 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010382 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010383 break;
10384 case PV_AR:
10385 buf->b_p_ar = -1;
10386 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010387 case PV_BKC:
10388 clear_string_option(&buf->b_p_bkc);
10389 buf->b_bkc_flags = 0;
10390 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010391 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010392 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010393 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010394 case PV_TC:
10395 clear_string_option(&buf->b_p_tc);
10396 buf->b_tc_flags = 0;
10397 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010398#ifdef FEAT_FIND_ID
10399 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010400 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010401 break;
10402 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010403 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010404 break;
10405#endif
10406#ifdef FEAT_INS_EXPAND
10407 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010408 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010409 break;
10410 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010411 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010412 break;
10413#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010414 case PV_FP:
10415 clear_string_option(&buf->b_p_fp);
10416 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010417#ifdef FEAT_QUICKFIX
10418 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010419 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010420 break;
10421 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010422 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010423 break;
10424 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010425 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010426 break;
10427#endif
10428#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10429 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010430 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010431 break;
10432#endif
10433#if defined(FEAT_CRYPT)
10434 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010435 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010436 break;
10437#endif
10438#ifdef FEAT_STL_OPT
10439 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010440 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010441 break;
10442#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010443 case PV_UL:
10444 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10445 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010446#ifdef FEAT_LISP
10447 case PV_LW:
10448 clear_string_option(&buf->b_p_lw);
10449 break;
10450#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010451#ifdef FEAT_MBYTE
10452 case PV_MENC:
10453 clear_string_option(&buf->b_p_menc);
10454 break;
10455#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010456 }
10457}
10458
10459/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010460 * Get pointer to option variable, depending on local or global scope.
10461 */
10462 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010463get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010464{
10465 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10466 {
10467 if (p->var == VAR_WIN)
10468 return (char_u *)GLOBAL_WO(get_varp(p));
10469 return p->var;
10470 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010471 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010472 {
10473 switch ((int)p->indir)
10474 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010475 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010476#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010477 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10478 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10479 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010480#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010481 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10482 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10483 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010484 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010485 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010486 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010487#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010488 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10489 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010490#endif
10491#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010492 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10493 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010494#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010495#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10496 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10497#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010498#if defined(FEAT_CRYPT)
10499 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10500#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010501#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010502 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010503#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010504 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010505#ifdef FEAT_LISP
10506 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10507#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010508 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010509#ifdef FEAT_MBYTE
10510 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10511#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010512 }
10513 return NULL; /* "cannot happen" */
10514 }
10515 return get_varp(p);
10516}
10517
10518/*
10519 * Get pointer to option variable.
10520 */
10521 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010522get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010523{
10524 /* hidden option, always return NULL */
10525 if (p->var == NULL)
10526 return NULL;
10527
10528 switch ((int)p->indir)
10529 {
10530 case PV_NONE: return p->var;
10531
10532 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010533 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010534 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010535 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010536 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010537 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010538 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010539 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010540 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010541 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010542 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010543 case PV_TC: return *curbuf->b_p_tc != NUL
10544 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010545 case PV_BKC: return *curbuf->b_p_bkc != NUL
10546 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010547#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010548 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010549 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010550 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010551 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10552#endif
10553#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010554 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010555 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010556 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010557 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10558#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010559 case PV_FP: return *curbuf->b_p_fp != NUL
10560 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010561#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010562 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010563 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010564 case PV_GP: return *curbuf->b_p_gp != NUL
10565 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10566 case PV_MP: return *curbuf->b_p_mp != NUL
10567 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010568#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010569#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10570 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10571 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10572#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010573#if defined(FEAT_CRYPT)
10574 case PV_CM: return *curbuf->b_p_cm != NUL
10575 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10576#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010577#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010578 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010579 ? (char_u *)&(curwin->w_p_stl) : p->var;
10580#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010581 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10582 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010583#ifdef FEAT_LISP
10584 case PV_LW: return *curbuf->b_p_lw != NUL
10585 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10586#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010587#ifdef FEAT_MBYTE
10588 case PV_MENC: return *curbuf->b_p_menc != NUL
10589 ? (char_u *)&(curbuf->b_p_menc) : p->var;
10590#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010591
10592#ifdef FEAT_ARABIC
10593 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10594#endif
10595 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010596#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010597 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10598#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010599#ifdef FEAT_SYN_HL
10600 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10601 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010602 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010603#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010604#ifdef FEAT_DIFF
10605 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10606#endif
10607#ifdef FEAT_FOLDING
10608 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10609 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10610 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10611 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10612 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10613 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10614 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10615# ifdef FEAT_EVAL
10616 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10617 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10618# endif
10619 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10620#endif
10621 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010622 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010623#ifdef FEAT_LINEBREAK
10624 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10625#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010626 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010627 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020010628#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010629 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10630#endif
10631#ifdef FEAT_RIGHTLEFT
10632 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10633 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10634#endif
10635 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10636 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10637#ifdef FEAT_LINEBREAK
10638 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010639 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10640 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010641#endif
10642#ifdef FEAT_SCROLLBIND
10643 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10644#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010645#ifdef FEAT_CURSORBIND
10646 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10647#endif
10648#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010649 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10650 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10651#endif
10652#ifdef FEAT_TERMINAL
Bram Moolenaar1b0675c2017-07-15 14:04:01 +020010653 case PV_TK: return (char_u *)&(curwin->w_p_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010654 case PV_TMS: return (char_u *)&(curwin->w_p_tms);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010655#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010656
10657 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10658 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10659#ifdef FEAT_MBYTE
10660 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10661#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010662 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10663 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010664 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10665 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10666#ifdef FEAT_CINDENT
10667 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10668 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10669 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10670#endif
10671#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10672 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10673#endif
10674#ifdef FEAT_COMMENTS
10675 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10676#endif
10677#ifdef FEAT_FOLDING
10678 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10679#endif
10680#ifdef FEAT_INS_EXPAND
10681 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10682#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010683#ifdef FEAT_COMPL_FUNC
10684 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010685 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010686#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010687 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010688 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010689 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10690#ifdef FEAT_MBYTE
10691 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10692#endif
10693 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10694#ifdef FEAT_AUTOCMD
10695 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10696#endif
10697 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010698 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010699 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10700 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10701 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10702 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10703#ifdef FEAT_FIND_ID
10704# ifdef FEAT_EVAL
10705 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10706# endif
10707#endif
10708#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10709 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10710 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10711#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010712#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010713 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10714#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010715#ifdef FEAT_CRYPT
10716 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10717#endif
10718#ifdef FEAT_LISP
10719 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10720#endif
10721 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10722 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10723 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10724 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10725 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010726 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010727#ifdef FEAT_TEXTOBJ
10728 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10729#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010730 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10731#ifdef FEAT_SMARTINDENT
10732 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10733#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010734 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010735 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10736#ifdef FEAT_SEARCHPATH
10737 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10738#endif
10739 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10740#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010741 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010742 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10743#endif
10744#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010745 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10746 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10747 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010748#endif
10749 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10750 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10751 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10752 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010753#ifdef FEAT_PERSISTENT_UNDO
10754 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10755#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010756 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10757#ifdef FEAT_KEYMAP
10758 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10759#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010760#ifdef FEAT_SIGNS
10761 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10762#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010763 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010764 }
10765 /* always return a valid pointer to avoid a crash! */
10766 return (char_u *)&(curbuf->b_p_wm);
10767}
10768
10769/*
10770 * Get the value of 'equalprg', either the buffer-local one or the global one.
10771 */
10772 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010773get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010774{
10775 if (*curbuf->b_p_ep == NUL)
10776 return p_ep;
10777 return curbuf->b_p_ep;
10778}
10779
Bram Moolenaar071d4272004-06-13 20:20:40 +000010780/*
10781 * Copy options from one window to another.
10782 * Used when splitting a window.
10783 */
10784 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010785win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010786{
10787 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10788 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10789# ifdef FEAT_RIGHTLEFT
10790# ifdef FEAT_FKMAP
10791 /* Is this right? */
10792 wp_to->w_farsi = wp_from->w_farsi;
10793# endif
10794# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010795#if defined(FEAT_LINEBREAK)
10796 briopt_check(wp_to);
10797#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010798}
Bram Moolenaar071d4272004-06-13 20:20:40 +000010799
10800/*
10801 * Copy the options from one winopt_T to another.
10802 * Doesn't free the old option values in "to", use clear_winopt() for that.
10803 * The 'scroll' option is not copied, because it depends on the window height.
10804 * The 'previewwindow' option is reset, there can be only one preview window.
10805 */
10806 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010807copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010808{
10809#ifdef FEAT_ARABIC
10810 to->wo_arab = from->wo_arab;
10811#endif
10812 to->wo_list = from->wo_list;
10813 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010814 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010815#ifdef FEAT_LINEBREAK
10816 to->wo_nuw = from->wo_nuw;
10817#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010818#ifdef FEAT_RIGHTLEFT
10819 to->wo_rl = from->wo_rl;
10820 to->wo_rlc = vim_strsave(from->wo_rlc);
10821#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010822#ifdef FEAT_STL_OPT
10823 to->wo_stl = vim_strsave(from->wo_stl);
10824#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010825 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010826#ifdef FEAT_DIFF
10827 to->wo_wrap_save = from->wo_wrap_save;
10828#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010829#ifdef FEAT_LINEBREAK
10830 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010831 to->wo_bri = from->wo_bri;
10832 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010833#endif
10834#ifdef FEAT_SCROLLBIND
10835 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010836 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010837#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010838#ifdef FEAT_CURSORBIND
10839 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010840 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010841#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010842#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010843 to->wo_spell = from->wo_spell;
10844#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010845#ifdef FEAT_SYN_HL
10846 to->wo_cuc = from->wo_cuc;
10847 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010848 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010849#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010850#ifdef FEAT_DIFF
10851 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010852 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010853#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010854#ifdef FEAT_CONCEAL
10855 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010856 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010857#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010858#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010859 to->wo_tk = vim_strsave(from->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010860 to->wo_tms = vim_strsave(from->wo_tms);
10861#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010862#ifdef FEAT_FOLDING
10863 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010864 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010865 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010866 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010867 to->wo_fdi = vim_strsave(from->wo_fdi);
10868 to->wo_fml = from->wo_fml;
10869 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010870 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010871 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010872 to->wo_fdm_save = from->wo_diff_saved
10873 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010874 to->wo_fdn = from->wo_fdn;
10875# ifdef FEAT_EVAL
10876 to->wo_fde = vim_strsave(from->wo_fde);
10877 to->wo_fdt = vim_strsave(from->wo_fdt);
10878# endif
10879 to->wo_fmr = vim_strsave(from->wo_fmr);
10880#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010881#ifdef FEAT_SIGNS
10882 to->wo_scl = vim_strsave(from->wo_scl);
10883#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010884 check_winopt(to); /* don't want NULL pointers */
10885}
10886
10887/*
10888 * Check string options in a window for a NULL value.
10889 */
10890 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010891check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010892{
10893 check_winopt(&win->w_onebuf_opt);
10894 check_winopt(&win->w_allbuf_opt);
10895}
10896
10897/*
10898 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10899 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010900 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010901check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010902{
10903#ifdef FEAT_FOLDING
10904 check_string_option(&wop->wo_fdi);
10905 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010906 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010907# ifdef FEAT_EVAL
10908 check_string_option(&wop->wo_fde);
10909 check_string_option(&wop->wo_fdt);
10910# endif
10911 check_string_option(&wop->wo_fmr);
10912#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010913#ifdef FEAT_SIGNS
10914 check_string_option(&wop->wo_scl);
10915#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010916#ifdef FEAT_RIGHTLEFT
10917 check_string_option(&wop->wo_rlc);
10918#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010919#ifdef FEAT_STL_OPT
10920 check_string_option(&wop->wo_stl);
10921#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010922#ifdef FEAT_SYN_HL
10923 check_string_option(&wop->wo_cc);
10924#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010925#ifdef FEAT_CONCEAL
10926 check_string_option(&wop->wo_cocu);
10927#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010928#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010929 check_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010930 check_string_option(&wop->wo_tms);
10931#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010932#ifdef FEAT_LINEBREAK
10933 check_string_option(&wop->wo_briopt);
10934#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010935}
10936
10937/*
10938 * Free the allocated memory inside a winopt_T.
10939 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010940 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010941clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010942{
10943#ifdef FEAT_FOLDING
10944 clear_string_option(&wop->wo_fdi);
10945 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010946 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010947# ifdef FEAT_EVAL
10948 clear_string_option(&wop->wo_fde);
10949 clear_string_option(&wop->wo_fdt);
10950# endif
10951 clear_string_option(&wop->wo_fmr);
10952#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010953#ifdef FEAT_SIGNS
10954 clear_string_option(&wop->wo_scl);
10955#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010956#ifdef FEAT_LINEBREAK
10957 clear_string_option(&wop->wo_briopt);
10958#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010959#ifdef FEAT_RIGHTLEFT
10960 clear_string_option(&wop->wo_rlc);
10961#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010962#ifdef FEAT_STL_OPT
10963 clear_string_option(&wop->wo_stl);
10964#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010965#ifdef FEAT_SYN_HL
10966 clear_string_option(&wop->wo_cc);
10967#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010968#ifdef FEAT_CONCEAL
10969 clear_string_option(&wop->wo_cocu);
10970#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010971#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010972 clear_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010973 clear_string_option(&wop->wo_tms);
10974#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010975}
10976
10977/*
10978 * Copy global option values to local options for one buffer.
10979 * Used when creating a new buffer and sometimes when entering a buffer.
10980 * flags:
10981 * BCO_ENTER We will enter the buf buffer.
10982 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10983 * appropriate.
10984 * BCO_NOHELP Don't copy the values to a help buffer.
10985 */
10986 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010987buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010988{
10989 int should_copy = TRUE;
10990 char_u *save_p_isk = NULL; /* init for GCC */
10991 int dont_do_help;
10992 int did_isk = FALSE;
10993
10994 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010995 * Skip this when the option defaults have not been set yet. Happens when
10996 * main() allocates the first buffer.
10997 */
10998 if (p_cpo != NULL)
10999 {
11000 /*
11001 * Always copy when entering and 'cpo' contains 'S'.
11002 * Don't copy when already initialized.
11003 * Don't copy when 'cpo' contains 's' and not entering.
11004 * 'S' BCO_ENTER initialized 's' should_copy
11005 * yes yes X X TRUE
11006 * yes no yes X FALSE
11007 * no X yes X FALSE
11008 * X no no yes FALSE
11009 * X no no no TRUE
11010 * no yes no X TRUE
11011 */
11012 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11013 && (buf->b_p_initialized
11014 || (!(flags & BCO_ENTER)
11015 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11016 should_copy = FALSE;
11017
11018 if (should_copy || (flags & BCO_ALWAYS))
11019 {
11020 /* Don't copy the options specific to a help buffer when
11021 * BCO_NOHELP is given or the options were initialized already
11022 * (jumping back to a help file with CTRL-T or CTRL-O) */
11023 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11024 || buf->b_p_initialized;
11025 if (dont_do_help) /* don't free b_p_isk */
11026 {
11027 save_p_isk = buf->b_p_isk;
11028 buf->b_p_isk = NULL;
11029 }
11030 /*
11031 * Always free the allocated strings.
11032 * If not already initialized, set 'readonly' and copy 'fileformat'.
11033 */
11034 if (!buf->b_p_initialized)
11035 {
11036 free_buf_options(buf, TRUE);
11037 buf->b_p_ro = FALSE; /* don't copy readonly */
11038 buf->b_p_tx = p_tx;
11039#ifdef FEAT_MBYTE
11040 buf->b_p_fenc = vim_strsave(p_fenc);
11041#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011042 switch (*p_ffs)
11043 {
11044 case 'm':
11045 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11046 case 'd':
11047 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11048 case 'u':
11049 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11050 default:
11051 buf->b_p_ff = vim_strsave(p_ff);
11052 }
11053 if (buf->b_p_ff != NULL)
11054 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011055 buf->b_p_bh = empty_option;
11056 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011057 }
11058 else
11059 free_buf_options(buf, FALSE);
11060
11061 buf->b_p_ai = p_ai;
11062 buf->b_p_ai_nopaste = p_ai_nopaste;
11063 buf->b_p_sw = p_sw;
11064 buf->b_p_tw = p_tw;
11065 buf->b_p_tw_nopaste = p_tw_nopaste;
11066 buf->b_p_tw_nobin = p_tw_nobin;
11067 buf->b_p_wm = p_wm;
11068 buf->b_p_wm_nopaste = p_wm_nopaste;
11069 buf->b_p_wm_nobin = p_wm_nobin;
11070 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011071#ifdef FEAT_MBYTE
11072 buf->b_p_bomb = p_bomb;
11073#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020011074 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011075 buf->b_p_et = p_et;
11076 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011077 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011078 buf->b_p_ml = p_ml;
11079 buf->b_p_ml_nobin = p_ml_nobin;
11080 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011081 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011082#ifdef FEAT_INS_EXPAND
11083 buf->b_p_cpt = vim_strsave(p_cpt);
11084#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011085#ifdef FEAT_COMPL_FUNC
11086 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011087 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011088#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011089 buf->b_p_sts = p_sts;
11090 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011091 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011092#ifdef FEAT_COMMENTS
11093 buf->b_p_com = vim_strsave(p_com);
11094#endif
11095#ifdef FEAT_FOLDING
11096 buf->b_p_cms = vim_strsave(p_cms);
11097#endif
11098 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011099 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011100 buf->b_p_nf = vim_strsave(p_nf);
11101 buf->b_p_mps = vim_strsave(p_mps);
11102#ifdef FEAT_SMARTINDENT
11103 buf->b_p_si = p_si;
11104#endif
11105 buf->b_p_ci = p_ci;
11106#ifdef FEAT_CINDENT
11107 buf->b_p_cin = p_cin;
11108 buf->b_p_cink = vim_strsave(p_cink);
11109 buf->b_p_cino = vim_strsave(p_cino);
11110#endif
11111#ifdef FEAT_AUTOCMD
11112 /* Don't copy 'filetype', it must be detected */
11113 buf->b_p_ft = empty_option;
11114#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011115 buf->b_p_pi = p_pi;
11116#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11117 buf->b_p_cinw = vim_strsave(p_cinw);
11118#endif
11119#ifdef FEAT_LISP
11120 buf->b_p_lisp = p_lisp;
11121#endif
11122#ifdef FEAT_SYN_HL
11123 /* Don't copy 'syntax', it must be set */
11124 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011125 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011126 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011127#endif
11128#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011129 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011130 (void)compile_cap_prog(&buf->b_s);
11131 buf->b_s.b_p_spf = vim_strsave(p_spf);
11132 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011133#endif
11134#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11135 buf->b_p_inde = vim_strsave(p_inde);
11136 buf->b_p_indk = vim_strsave(p_indk);
11137#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011138 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011139#if defined(FEAT_EVAL)
11140 buf->b_p_fex = vim_strsave(p_fex);
11141#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011142#ifdef FEAT_CRYPT
11143 buf->b_p_key = vim_strsave(p_key);
11144#endif
11145#ifdef FEAT_SEARCHPATH
11146 buf->b_p_sua = vim_strsave(p_sua);
11147#endif
11148#ifdef FEAT_KEYMAP
11149 buf->b_p_keymap = vim_strsave(p_keymap);
11150 buf->b_kmap_state |= KEYMAP_INIT;
11151#endif
11152 /* This isn't really an option, but copying the langmap and IME
11153 * state from the current buffer is better than resetting it. */
11154 buf->b_p_iminsert = p_iminsert;
11155 buf->b_p_imsearch = p_imsearch;
11156
11157 /* options that are normally global but also have a local value
11158 * are not copied, start using the global value */
11159 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011160 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011161 buf->b_p_bkc = empty_option;
11162 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011163#ifdef FEAT_QUICKFIX
11164 buf->b_p_gp = empty_option;
11165 buf->b_p_mp = empty_option;
11166 buf->b_p_efm = empty_option;
11167#endif
11168 buf->b_p_ep = empty_option;
11169 buf->b_p_kp = empty_option;
11170 buf->b_p_path = empty_option;
11171 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011172 buf->b_p_tc = empty_option;
11173 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011174#ifdef FEAT_FIND_ID
11175 buf->b_p_def = empty_option;
11176 buf->b_p_inc = empty_option;
11177# ifdef FEAT_EVAL
11178 buf->b_p_inex = vim_strsave(p_inex);
11179# endif
11180#endif
11181#ifdef FEAT_INS_EXPAND
11182 buf->b_p_dict = empty_option;
11183 buf->b_p_tsr = empty_option;
11184#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011185#ifdef FEAT_TEXTOBJ
11186 buf->b_p_qe = vim_strsave(p_qe);
11187#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011188#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11189 buf->b_p_bexpr = empty_option;
11190#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011191#if defined(FEAT_CRYPT)
11192 buf->b_p_cm = empty_option;
11193#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011194#ifdef FEAT_PERSISTENT_UNDO
11195 buf->b_p_udf = p_udf;
11196#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011197#ifdef FEAT_LISP
11198 buf->b_p_lw = empty_option;
11199#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011200#ifdef FEAT_MBYTE
11201 buf->b_p_menc = empty_option;
11202#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011203
11204 /*
11205 * Don't copy the options set by ex_help(), use the saved values,
11206 * when going from a help buffer to a non-help buffer.
11207 * Don't touch these at all when BCO_NOHELP is used and going from
11208 * or to a help buffer.
11209 */
11210 if (dont_do_help)
11211 buf->b_p_isk = save_p_isk;
11212 else
11213 {
11214 buf->b_p_isk = vim_strsave(p_isk);
11215 did_isk = TRUE;
11216 buf->b_p_ts = p_ts;
11217 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011218 if (buf->b_p_bt[0] == 'h')
11219 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011220 buf->b_p_ma = p_ma;
11221 }
11222 }
11223
11224 /*
11225 * When the options should be copied (ignoring BCO_ALWAYS), set the
11226 * flag that indicates that the options have been initialized.
11227 */
11228 if (should_copy)
11229 buf->b_p_initialized = TRUE;
11230 }
11231
11232 check_buf_options(buf); /* make sure we don't have NULLs */
11233 if (did_isk)
11234 (void)buf_init_chartab(buf, FALSE);
11235}
11236
11237/*
11238 * Reset the 'modifiable' option and its default value.
11239 */
11240 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011241reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011242{
11243 int opt_idx;
11244
11245 curbuf->b_p_ma = FALSE;
11246 p_ma = FALSE;
11247 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011248 if (opt_idx >= 0)
11249 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011250}
11251
11252/*
11253 * Set the global value for 'iminsert' to the local value.
11254 */
11255 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011256set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011257{
11258 p_iminsert = curbuf->b_p_iminsert;
11259}
11260
11261/*
11262 * Set the global value for 'imsearch' to the local value.
11263 */
11264 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011265set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011266{
11267 p_imsearch = curbuf->b_p_imsearch;
11268}
11269
11270#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11271static int expand_option_idx = -1;
11272static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11273static int expand_option_flags = 0;
11274
11275 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011276set_context_in_set_cmd(
11277 expand_T *xp,
11278 char_u *arg,
11279 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011280{
11281 int nextchar;
11282 long_u flags = 0; /* init for GCC */
11283 int opt_idx = 0; /* init for GCC */
11284 char_u *p;
11285 char_u *s;
11286 int is_term_option = FALSE;
11287 int key;
11288
11289 expand_option_flags = opt_flags;
11290
11291 xp->xp_context = EXPAND_SETTINGS;
11292 if (*arg == NUL)
11293 {
11294 xp->xp_pattern = arg;
11295 return;
11296 }
11297 p = arg + STRLEN(arg) - 1;
11298 if (*p == ' ' && *(p - 1) != '\\')
11299 {
11300 xp->xp_pattern = p + 1;
11301 return;
11302 }
11303 while (p > arg)
11304 {
11305 s = p;
11306 /* count number of backslashes before ' ' or ',' */
11307 if (*p == ' ' || *p == ',')
11308 {
11309 while (s > arg && *(s - 1) == '\\')
11310 --s;
11311 }
11312 /* break at a space with an even number of backslashes */
11313 if (*p == ' ' && ((p - s) & 1) == 0)
11314 {
11315 ++p;
11316 break;
11317 }
11318 --p;
11319 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011320 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011321 {
11322 xp->xp_context = EXPAND_BOOL_SETTINGS;
11323 p += 2;
11324 }
11325 if (STRNCMP(p, "inv", 3) == 0)
11326 {
11327 xp->xp_context = EXPAND_BOOL_SETTINGS;
11328 p += 3;
11329 }
11330 xp->xp_pattern = arg = p;
11331 if (*arg == '<')
11332 {
11333 while (*p != '>')
11334 if (*p++ == NUL) /* expand terminal option name */
11335 return;
11336 key = get_special_key_code(arg + 1);
11337 if (key == 0) /* unknown name */
11338 {
11339 xp->xp_context = EXPAND_NOTHING;
11340 return;
11341 }
11342 nextchar = *++p;
11343 is_term_option = TRUE;
11344 expand_option_name[2] = KEY2TERMCAP0(key);
11345 expand_option_name[3] = KEY2TERMCAP1(key);
11346 }
11347 else
11348 {
11349 if (p[0] == 't' && p[1] == '_')
11350 {
11351 p += 2;
11352 if (*p != NUL)
11353 ++p;
11354 if (*p == NUL)
11355 return; /* expand option name */
11356 nextchar = *++p;
11357 is_term_option = TRUE;
11358 expand_option_name[2] = p[-2];
11359 expand_option_name[3] = p[-1];
11360 }
11361 else
11362 {
11363 /* Allow * wildcard */
11364 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11365 p++;
11366 if (*p == NUL)
11367 return;
11368 nextchar = *p;
11369 *p = NUL;
11370 opt_idx = findoption(arg);
11371 *p = nextchar;
11372 if (opt_idx == -1 || options[opt_idx].var == NULL)
11373 {
11374 xp->xp_context = EXPAND_NOTHING;
11375 return;
11376 }
11377 flags = options[opt_idx].flags;
11378 if (flags & P_BOOL)
11379 {
11380 xp->xp_context = EXPAND_NOTHING;
11381 return;
11382 }
11383 }
11384 }
11385 /* handle "-=" and "+=" */
11386 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11387 {
11388 ++p;
11389 nextchar = '=';
11390 }
11391 if ((nextchar != '=' && nextchar != ':')
11392 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11393 {
11394 xp->xp_context = EXPAND_UNSUCCESSFUL;
11395 return;
11396 }
11397 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11398 {
11399 xp->xp_context = EXPAND_OLD_SETTING;
11400 if (is_term_option)
11401 expand_option_idx = -1;
11402 else
11403 expand_option_idx = opt_idx;
11404 xp->xp_pattern = p + 1;
11405 return;
11406 }
11407 xp->xp_context = EXPAND_NOTHING;
11408 if (is_term_option || (flags & P_NUM))
11409 return;
11410
11411 xp->xp_pattern = p + 1;
11412
11413 if (flags & P_EXPAND)
11414 {
11415 p = options[opt_idx].var;
11416 if (p == (char_u *)&p_bdir
11417 || p == (char_u *)&p_dir
11418 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011419 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011420 || p == (char_u *)&p_rtp
11421#ifdef FEAT_SEARCHPATH
11422 || p == (char_u *)&p_cdpath
11423#endif
11424#ifdef FEAT_SESSION
11425 || p == (char_u *)&p_vdir
11426#endif
11427 )
11428 {
11429 xp->xp_context = EXPAND_DIRECTORIES;
11430 if (p == (char_u *)&p_path
11431#ifdef FEAT_SEARCHPATH
11432 || p == (char_u *)&p_cdpath
11433#endif
11434 )
11435 xp->xp_backslash = XP_BS_THREE;
11436 else
11437 xp->xp_backslash = XP_BS_ONE;
11438 }
11439 else
11440 {
11441 xp->xp_context = EXPAND_FILES;
11442 /* for 'tags' need three backslashes for a space */
11443 if (p == (char_u *)&p_tags)
11444 xp->xp_backslash = XP_BS_THREE;
11445 else
11446 xp->xp_backslash = XP_BS_ONE;
11447 }
11448 }
11449
11450 /* For an option that is a list of file names, find the start of the
11451 * last file name. */
11452 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11453 {
11454 /* count number of backslashes before ' ' or ',' */
11455 if (*p == ' ' || *p == ',')
11456 {
11457 s = p;
11458 while (s > xp->xp_pattern && *(s - 1) == '\\')
11459 --s;
11460 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11461 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11462 {
11463 xp->xp_pattern = p + 1;
11464 break;
11465 }
11466 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011467
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011468#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011469 /* for 'spellsuggest' start at "file:" */
11470 if (options[opt_idx].var == (char_u *)&p_sps
11471 && STRNCMP(p, "file:", 5) == 0)
11472 {
11473 xp->xp_pattern = p + 5;
11474 break;
11475 }
11476#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011477 }
11478
11479 return;
11480}
11481
11482 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011483ExpandSettings(
11484 expand_T *xp,
11485 regmatch_T *regmatch,
11486 int *num_file,
11487 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011488{
11489 int num_normal = 0; /* Nr of matching non-term-code settings */
11490 int num_term = 0; /* Nr of matching terminal code settings */
11491 int opt_idx;
11492 int match;
11493 int count = 0;
11494 char_u *str;
11495 int loop;
11496 int is_term_opt;
11497 char_u name_buf[MAX_KEY_NAME_LEN];
11498 static char *(names[]) = {"all", "termcap"};
11499 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11500
11501 /* do this loop twice:
11502 * loop == 0: count the number of matching options
11503 * loop == 1: copy the matching options into allocated memory
11504 */
11505 for (loop = 0; loop <= 1; ++loop)
11506 {
11507 regmatch->rm_ic = ic;
11508 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11509 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011510 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11511 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011512 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11513 {
11514 if (loop == 0)
11515 num_normal++;
11516 else
11517 (*file)[count++] = vim_strsave((char_u *)names[match]);
11518 }
11519 }
11520 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11521 opt_idx++)
11522 {
11523 if (options[opt_idx].var == NULL)
11524 continue;
11525 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11526 && !(options[opt_idx].flags & P_BOOL))
11527 continue;
11528 is_term_opt = istermoption(&options[opt_idx]);
11529 if (is_term_opt && num_normal > 0)
11530 continue;
11531 match = FALSE;
11532 if (vim_regexec(regmatch, str, (colnr_T)0)
11533 || (options[opt_idx].shortname != NULL
11534 && vim_regexec(regmatch,
11535 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11536 match = TRUE;
11537 else if (is_term_opt)
11538 {
11539 name_buf[0] = '<';
11540 name_buf[1] = 't';
11541 name_buf[2] = '_';
11542 name_buf[3] = str[2];
11543 name_buf[4] = str[3];
11544 name_buf[5] = '>';
11545 name_buf[6] = NUL;
11546 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11547 {
11548 match = TRUE;
11549 str = name_buf;
11550 }
11551 }
11552 if (match)
11553 {
11554 if (loop == 0)
11555 {
11556 if (is_term_opt)
11557 num_term++;
11558 else
11559 num_normal++;
11560 }
11561 else
11562 (*file)[count++] = vim_strsave(str);
11563 }
11564 }
11565 /*
11566 * Check terminal key codes, these are not in the option table
11567 */
11568 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11569 {
11570 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11571 {
11572 if (!isprint(str[0]) || !isprint(str[1]))
11573 continue;
11574
11575 name_buf[0] = 't';
11576 name_buf[1] = '_';
11577 name_buf[2] = str[0];
11578 name_buf[3] = str[1];
11579 name_buf[4] = NUL;
11580
11581 match = FALSE;
11582 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11583 match = TRUE;
11584 else
11585 {
11586 name_buf[0] = '<';
11587 name_buf[1] = 't';
11588 name_buf[2] = '_';
11589 name_buf[3] = str[0];
11590 name_buf[4] = str[1];
11591 name_buf[5] = '>';
11592 name_buf[6] = NUL;
11593
11594 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11595 match = TRUE;
11596 }
11597 if (match)
11598 {
11599 if (loop == 0)
11600 num_term++;
11601 else
11602 (*file)[count++] = vim_strsave(name_buf);
11603 }
11604 }
11605
11606 /*
11607 * Check special key names.
11608 */
11609 regmatch->rm_ic = TRUE; /* ignore case here */
11610 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11611 {
11612 name_buf[0] = '<';
11613 STRCPY(name_buf + 1, str);
11614 STRCAT(name_buf, ">");
11615
11616 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11617 {
11618 if (loop == 0)
11619 num_term++;
11620 else
11621 (*file)[count++] = vim_strsave(name_buf);
11622 }
11623 }
11624 }
11625 if (loop == 0)
11626 {
11627 if (num_normal > 0)
11628 *num_file = num_normal;
11629 else if (num_term > 0)
11630 *num_file = num_term;
11631 else
11632 return OK;
11633 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11634 if (*file == NULL)
11635 {
11636 *file = (char_u **)"";
11637 return FAIL;
11638 }
11639 }
11640 }
11641 return OK;
11642}
11643
11644 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011645ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011646{
11647 char_u *var = NULL; /* init for GCC */
11648 char_u *buf;
11649
11650 *num_file = 0;
11651 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11652 if (*file == NULL)
11653 return FAIL;
11654
11655 /*
11656 * For a terminal key code expand_option_idx is < 0.
11657 */
11658 if (expand_option_idx < 0)
11659 {
11660 var = find_termcode(expand_option_name + 2);
11661 if (var == NULL)
11662 expand_option_idx = findoption(expand_option_name);
11663 }
11664
11665 if (expand_option_idx >= 0)
11666 {
11667 /* put string of option value in NameBuff */
11668 option_value2string(&options[expand_option_idx], expand_option_flags);
11669 var = NameBuff;
11670 }
11671 else if (var == NULL)
11672 var = (char_u *)"";
11673
11674 /* A backslash is required before some characters. This is the reverse of
11675 * what happens in do_set(). */
11676 buf = vim_strsave_escaped(var, escape_chars);
11677
11678 if (buf == NULL)
11679 {
11680 vim_free(*file);
11681 *file = NULL;
11682 return FAIL;
11683 }
11684
11685#ifdef BACKSLASH_IN_FILENAME
11686 /* For MS-Windows et al. we don't double backslashes at the start and
11687 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011688 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011689 if (var[0] == '\\' && var[1] == '\\'
11690 && expand_option_idx >= 0
11691 && (options[expand_option_idx].flags & P_EXPAND)
11692 && vim_isfilec(var[2])
11693 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011694 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011695#endif
11696
11697 *file[0] = buf;
11698 *num_file = 1;
11699 return OK;
11700}
11701#endif
11702
11703/*
11704 * Get the value for the numeric or string option *opp in a nice format into
11705 * NameBuff[]. Must not be called with a hidden option!
11706 */
11707 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011708option_value2string(
11709 struct vimoption *opp,
11710 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011711{
11712 char_u *varp;
11713
11714 varp = get_varp_scope(opp, opt_flags);
11715
11716 if (opp->flags & P_NUM)
11717 {
11718 long wc = 0;
11719
11720 if (wc_use_keyname(varp, &wc))
11721 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11722 else if (wc != 0)
11723 STRCPY(NameBuff, transchar((int)wc));
11724 else
11725 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11726 }
11727 else /* P_STRING */
11728 {
11729 varp = *(char_u **)(varp);
11730 if (varp == NULL) /* just in case */
11731 NameBuff[0] = NUL;
11732#ifdef FEAT_CRYPT
11733 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011734 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011735 STRCPY(NameBuff, "*****");
11736#endif
11737 else if (opp->flags & P_EXPAND)
11738 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11739 /* Translate 'pastetoggle' into special key names */
11740 else if ((char_u **)opp->var == &p_pt)
11741 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11742 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011743 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011744 }
11745}
11746
11747/*
11748 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11749 * printed as a keyname.
11750 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11751 */
11752 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011753wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011754{
11755 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11756 {
11757 *wcp = *(long *)varp;
11758 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11759 return TRUE;
11760 }
11761 return FALSE;
11762}
11763
Bram Moolenaar01615492015-02-03 13:00:38 +010011764#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011765/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011766 * Any character has an equivalent 'langmap' character. This is used for
11767 * keyboards that have a special language mode that sends characters above
11768 * 128 (although other characters can be translated too). The "to" field is a
11769 * Vim command character. This avoids having to switch the keyboard back to
11770 * ASCII mode when leaving Insert mode.
11771 *
11772 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11773 * commands.
11774 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11775 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11776 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011777 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011778# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011779/*
11780 * With multi-byte support use growarray for 'langmap' chars >= 256
11781 */
11782typedef struct
11783{
11784 int from;
11785 int to;
11786} langmap_entry_T;
11787
11788static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011789static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011790
11791/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011792 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11793 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011794 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011795 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011796langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011797{
11798 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011799 int a = 0;
11800 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011801
11802 /* Do a binary search for an existing entry. */
11803 while (a != b)
11804 {
11805 int i = (a + b) / 2;
11806 int d = entries[i].from - from;
11807
11808 if (d == 0)
11809 {
11810 entries[i].to = to;
11811 return;
11812 }
11813 if (d < 0)
11814 a = i + 1;
11815 else
11816 b = i;
11817 }
11818
11819 if (ga_grow(&langmap_mapga, 1) != OK)
11820 return; /* out of memory */
11821
11822 /* insert new entry at position "a" */
11823 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11824 mch_memmove(entries + 1, entries,
11825 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11826 ++langmap_mapga.ga_len;
11827 entries[0].from = from;
11828 entries[0].to = to;
11829}
11830
11831/*
11832 * Apply 'langmap' to multi-byte character "c" and return the result.
11833 */
11834 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011835langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011836{
11837 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11838 int a = 0;
11839 int b = langmap_mapga.ga_len;
11840
11841 while (a != b)
11842 {
11843 int i = (a + b) / 2;
11844 int d = entries[i].from - c;
11845
11846 if (d == 0)
11847 return entries[i].to; /* found matching entry */
11848 if (d < 0)
11849 a = i + 1;
11850 else
11851 b = i;
11852 }
11853 return c; /* no entry found, return "c" unmodified */
11854}
11855# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011856
11857 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011858langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011859{
11860 int i;
11861
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011862 for (i = 0; i < 256; i++)
11863 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11864# ifdef FEAT_MBYTE
11865 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11866# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011867}
11868
11869/*
11870 * Called when langmap option is set; the language map can be
11871 * changed at any time!
11872 */
11873 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011874langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011875{
11876 char_u *p;
11877 char_u *p2;
11878 int from, to;
11879
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011880#ifdef FEAT_MBYTE
11881 ga_clear(&langmap_mapga); /* clear the previous map first */
11882#endif
11883 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011884
11885 for (p = p_langmap; p[0] != NUL; )
11886 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011887 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011888 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011889 {
11890 if (p2[0] == '\\' && p2[1] != NUL)
11891 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011892 }
11893 if (p2[0] == ';')
11894 ++p2; /* abcd;ABCD form, p2 points to A */
11895 else
11896 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11897 while (p[0])
11898 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011899 if (p[0] == ',')
11900 {
11901 ++p;
11902 break;
11903 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011904 if (p[0] == '\\' && p[1] != NUL)
11905 ++p;
11906#ifdef FEAT_MBYTE
11907 from = (*mb_ptr2char)(p);
11908#else
11909 from = p[0];
11910#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011911 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011912 if (p2 == NULL)
11913 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011914 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011915 if (p[0] != ',')
11916 {
11917 if (p[0] == '\\')
11918 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011919#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011920 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011921#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011922 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011923#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011924 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011925 }
11926 else
11927 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011928 if (p2[0] != ',')
11929 {
11930 if (p2[0] == '\\')
11931 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011932#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011933 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011934#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011935 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011936#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011937 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011938 }
11939 if (to == NUL)
11940 {
11941 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11942 transchar(from));
11943 return;
11944 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011945
11946#ifdef FEAT_MBYTE
11947 if (from >= 256)
11948 langmap_set_entry(from, to);
11949 else
11950#endif
11951 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011952
11953 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011954 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011955 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011956 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011957 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011958 if (*p == ';')
11959 {
11960 p = p2;
11961 if (p[0] != NUL)
11962 {
11963 if (p[0] != ',')
11964 {
11965 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11966 return;
11967 }
11968 ++p;
11969 }
11970 break;
11971 }
11972 }
11973 }
11974 }
11975}
11976#endif
11977
11978/*
11979 * Return TRUE if format option 'x' is in effect.
11980 * Take care of no formatting when 'paste' is set.
11981 */
11982 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011983has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011984{
11985 if (p_paste)
11986 return FALSE;
11987 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11988}
11989
11990/*
11991 * Return TRUE if "x" is present in 'shortmess' option, or
11992 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11993 */
11994 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011995shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011996{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011997 return p_shm != NULL &&
11998 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011999 || (vim_strchr(p_shm, 'a') != NULL
12000 && vim_strchr((char_u *)SHM_A, x) != NULL));
12001}
12002
12003/*
12004 * paste_option_changed() - Called after p_paste was set or reset.
12005 */
12006 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012007paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012008{
12009 static int old_p_paste = FALSE;
12010 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012011 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012012#ifdef FEAT_CMDL_INFO
12013 static int save_ru = 0;
12014#endif
12015#ifdef FEAT_RIGHTLEFT
12016 static int save_ri = 0;
12017 static int save_hkmap = 0;
12018#endif
12019 buf_T *buf;
12020
12021 if (p_paste)
12022 {
12023 /*
12024 * Paste switched from off to on.
12025 * Save the current values, so they can be restored later.
12026 */
12027 if (!old_p_paste)
12028 {
12029 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012030 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012031 {
12032 buf->b_p_tw_nopaste = buf->b_p_tw;
12033 buf->b_p_wm_nopaste = buf->b_p_wm;
12034 buf->b_p_sts_nopaste = buf->b_p_sts;
12035 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012036 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012037 }
12038
12039 /* save global options */
12040 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012041 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012042#ifdef FEAT_CMDL_INFO
12043 save_ru = p_ru;
12044#endif
12045#ifdef FEAT_RIGHTLEFT
12046 save_ri = p_ri;
12047 save_hkmap = p_hkmap;
12048#endif
12049 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012050 p_ai_nopaste = p_ai;
12051 p_et_nopaste = p_et;
12052 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012053 p_tw_nopaste = p_tw;
12054 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012055 }
12056
12057 /*
12058 * Always set the option values, also when 'paste' is set when it is
12059 * already on.
12060 */
12061 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012062 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012063 {
12064 buf->b_p_tw = 0; /* textwidth is 0 */
12065 buf->b_p_wm = 0; /* wrapmargin is 0 */
12066 buf->b_p_sts = 0; /* softtabstop is 0 */
12067 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012068 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012069 }
12070
12071 /* set global options */
12072 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012073 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012074#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012075 if (p_ru)
12076 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012077 p_ru = 0; /* no ruler */
12078#endif
12079#ifdef FEAT_RIGHTLEFT
12080 p_ri = 0; /* no reverse insert */
12081 p_hkmap = 0; /* no Hebrew keyboard */
12082#endif
12083 /* set global values for local buffer options */
12084 p_tw = 0;
12085 p_wm = 0;
12086 p_sts = 0;
12087 p_ai = 0;
12088 }
12089
12090 /*
12091 * Paste switched from on to off: Restore saved values.
12092 */
12093 else if (old_p_paste)
12094 {
12095 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012096 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012097 {
12098 buf->b_p_tw = buf->b_p_tw_nopaste;
12099 buf->b_p_wm = buf->b_p_wm_nopaste;
12100 buf->b_p_sts = buf->b_p_sts_nopaste;
12101 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012102 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012103 }
12104
12105 /* restore global options */
12106 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012107 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012108#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012109 if (p_ru != save_ru)
12110 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012111 p_ru = save_ru;
12112#endif
12113#ifdef FEAT_RIGHTLEFT
12114 p_ri = save_ri;
12115 p_hkmap = save_hkmap;
12116#endif
12117 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012118 p_ai = p_ai_nopaste;
12119 p_et = p_et_nopaste;
12120 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012121 p_tw = p_tw_nopaste;
12122 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012123 }
12124
12125 old_p_paste = p_paste;
12126}
12127
12128/*
12129 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12130 *
12131 * Reset 'compatible' and set the values for options that didn't get set yet
12132 * to the Vim defaults.
12133 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012134 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012135 */
12136 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012137vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012138{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012139 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012140 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012141 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012142
12143 if (!option_was_set((char_u *)"cp"))
12144 {
12145 p_cp = FALSE;
12146 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12147 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12148 set_option_default(opt_idx, OPT_FREE, FALSE);
12149 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012150 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012151 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012152
12153 if (fname != NULL)
12154 {
12155 p = vim_getenv(envname, &dofree);
12156 if (p == NULL)
12157 {
12158 /* Set $MYVIMRC to the first vimrc file found. */
12159 p = FullName_save(fname, FALSE);
12160 if (p != NULL)
12161 {
12162 vim_setenv(envname, p);
12163 vim_free(p);
12164 }
12165 }
12166 else if (dofree)
12167 vim_free(p);
12168 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012169}
12170
12171/*
12172 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12173 */
12174 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012175change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012176{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012177 int opt_idx;
12178
Bram Moolenaar071d4272004-06-13 20:20:40 +000012179 if (p_cp != on)
12180 {
12181 p_cp = on;
12182 compatible_set();
12183 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012184 opt_idx = findoption((char_u *)"cp");
12185 if (opt_idx >= 0)
12186 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012187}
12188
12189/*
12190 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012191 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012192 */
12193 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012194option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012195{
12196 int idx;
12197
12198 idx = findoption(name);
12199 if (idx < 0) /* unknown option */
12200 return FALSE;
12201 if (options[idx].flags & P_WAS_SET)
12202 return TRUE;
12203 return FALSE;
12204}
12205
12206/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012207 * Reset the flag indicating option "name" was set.
12208 */
12209 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012210reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012211{
12212 int idx = findoption(name);
12213
12214 if (idx >= 0)
12215 options[idx].flags &= ~P_WAS_SET;
12216}
12217
12218/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012219 * compatible_set() - Called when 'compatible' has been set or unset.
12220 *
12221 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12222 * flag) to a Vi compatible value.
12223 * When 'compatible' is unset: Set all options that have a different default
12224 * for Vim (without the P_VI_DEF flag) to that default.
12225 */
12226 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012227compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012228{
12229 int opt_idx;
12230
12231 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12232 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12233 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12234 set_option_default(opt_idx, OPT_FREE, p_cp);
12235 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012236 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012237}
12238
12239#ifdef FEAT_LINEBREAK
12240
12241# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12242 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012243 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012244# endif
12245
12246/*
12247 * fill_breakat_flags() -- called when 'breakat' changes value.
12248 */
12249 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012250fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012251{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012252 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012253 int i;
12254
12255 for (i = 0; i < 256; i++)
12256 breakat_flags[i] = FALSE;
12257
12258 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012259 for (p = p_breakat; *p; p++)
12260 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012261}
12262
12263# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012264 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012265# endif
12266
12267#endif
12268
12269/*
12270 * Check an option that can be a range of string values.
12271 *
12272 * Return OK for correct value, FAIL otherwise.
12273 * Empty is always OK.
12274 */
12275 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012276check_opt_strings(
12277 char_u *val,
12278 char **values,
12279 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012280{
12281 return opt_strings_flags(val, values, NULL, list);
12282}
12283
12284/*
12285 * Handle an option that can be a range of string values.
12286 * Set a flag in "*flagp" for each string present.
12287 *
12288 * Return OK for correct value, FAIL otherwise.
12289 * Empty is always OK.
12290 */
12291 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012292opt_strings_flags(
12293 char_u *val, /* new value */
12294 char **values, /* array of valid string values */
12295 unsigned *flagp,
12296 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012297{
12298 int i;
12299 int len;
12300 unsigned new_flags = 0;
12301
12302 while (*val)
12303 {
12304 for (i = 0; ; ++i)
12305 {
12306 if (values[i] == NULL) /* val not found in values[] */
12307 return FAIL;
12308
12309 len = (int)STRLEN(values[i]);
12310 if (STRNCMP(values[i], val, len) == 0
12311 && ((list && val[len] == ',') || val[len] == NUL))
12312 {
12313 val += len + (val[len] == ',');
12314 new_flags |= (1 << i);
12315 break; /* check next item in val list */
12316 }
12317 }
12318 }
12319 if (flagp != NULL)
12320 *flagp = new_flags;
12321
12322 return OK;
12323}
12324
12325/*
12326 * Read the 'wildmode' option, fill wim_flags[].
12327 */
12328 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012329check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012330{
12331 char_u new_wim_flags[4];
12332 char_u *p;
12333 int i;
12334 int idx = 0;
12335
12336 for (i = 0; i < 4; ++i)
12337 new_wim_flags[i] = 0;
12338
12339 for (p = p_wim; *p; ++p)
12340 {
12341 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12342 ;
12343 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12344 return FAIL;
12345 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12346 new_wim_flags[idx] |= WIM_LONGEST;
12347 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12348 new_wim_flags[idx] |= WIM_FULL;
12349 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12350 new_wim_flags[idx] |= WIM_LIST;
12351 else
12352 return FAIL;
12353 p += i;
12354 if (*p == NUL)
12355 break;
12356 if (*p == ',')
12357 {
12358 if (idx == 3)
12359 return FAIL;
12360 ++idx;
12361 }
12362 }
12363
12364 /* fill remaining entries with last flag */
12365 while (idx < 3)
12366 {
12367 new_wim_flags[idx + 1] = new_wim_flags[idx];
12368 ++idx;
12369 }
12370
12371 /* only when there are no errors, wim_flags[] is changed */
12372 for (i = 0; i < 4; ++i)
12373 wim_flags[i] = new_wim_flags[i];
12374 return OK;
12375}
12376
12377/*
12378 * Check if backspacing over something is allowed.
12379 */
12380 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012381can_bs(
12382 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012383{
12384 switch (*p_bs)
12385 {
12386 case '2': return TRUE;
12387 case '1': return (what != BS_START);
12388 case '0': return FALSE;
12389 }
12390 return vim_strchr(p_bs, what) != NULL;
12391}
12392
12393/*
12394 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12395 * the file must be considered changed when the value is different.
12396 */
12397 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012398save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012399{
12400 buf->b_start_ffc = *buf->b_p_ff;
12401 buf->b_start_eol = buf->b_p_eol;
12402#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012403 buf->b_start_bomb = buf->b_p_bomb;
12404
Bram Moolenaar071d4272004-06-13 20:20:40 +000012405 /* Only use free/alloc when necessary, they take time. */
12406 if (buf->b_start_fenc == NULL
12407 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12408 {
12409 vim_free(buf->b_start_fenc);
12410 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12411 }
12412#endif
12413}
12414
12415/*
12416 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12417 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012418 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12419 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012420 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012421 * When "ignore_empty" is true don't consider a new, empty buffer to be
12422 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012423 */
12424 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012425file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012426{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012427 /* In a buffer that was never loaded the options are not valid. */
12428 if (buf->b_flags & BF_NEVERLOADED)
12429 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012430 if (ignore_empty
12431 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012432 && buf->b_ml.ml_line_count == 1
12433 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12434 return FALSE;
12435 if (buf->b_start_ffc != *buf->b_p_ff)
12436 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012437 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012438 return TRUE;
12439#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012440 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12441 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012442 if (buf->b_start_fenc == NULL)
12443 return (*buf->b_p_fenc != NUL);
12444 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12445#else
12446 return FALSE;
12447#endif
12448}
12449
12450/*
12451 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12452 */
12453 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012454check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012455{
12456 return check_opt_strings(p, p_ff_values, FALSE);
12457}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012458
12459/*
12460 * Return the effective shiftwidth value for current buffer, using the
12461 * 'tabstop' value when 'shiftwidth' is zero.
12462 */
12463 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012464get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012465{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012466 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012467}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012468
12469/*
12470 * Return the effective softtabstop value for the current buffer, using the
12471 * 'tabstop' value when 'softtabstop' is negative.
12472 */
12473 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012474get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012475{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012476 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012477}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012478
12479/*
12480 * Check matchpairs option for "*initc".
12481 * If there is a match set "*initc" to the matching character and "*findc" to
12482 * the opposite character. Set "*backwards" to the direction.
12483 * When "switchit" is TRUE swap the direction.
12484 */
12485 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012486find_mps_values(
12487 int *initc,
12488 int *findc,
12489 int *backwards,
12490 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012491{
12492 char_u *ptr;
12493
12494 ptr = curbuf->b_p_mps;
12495 while (*ptr != NUL)
12496 {
12497#ifdef FEAT_MBYTE
12498 if (has_mbyte)
12499 {
12500 char_u *prev;
12501
12502 if (mb_ptr2char(ptr) == *initc)
12503 {
12504 if (switchit)
12505 {
12506 *findc = *initc;
12507 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12508 *backwards = TRUE;
12509 }
12510 else
12511 {
12512 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12513 *backwards = FALSE;
12514 }
12515 return;
12516 }
12517 prev = ptr;
12518 ptr += mb_ptr2len(ptr) + 1;
12519 if (mb_ptr2char(ptr) == *initc)
12520 {
12521 if (switchit)
12522 {
12523 *findc = *initc;
12524 *initc = mb_ptr2char(prev);
12525 *backwards = FALSE;
12526 }
12527 else
12528 {
12529 *findc = mb_ptr2char(prev);
12530 *backwards = TRUE;
12531 }
12532 return;
12533 }
12534 ptr += mb_ptr2len(ptr);
12535 }
12536 else
12537#endif
12538 {
12539 if (*ptr == *initc)
12540 {
12541 if (switchit)
12542 {
12543 *backwards = TRUE;
12544 *findc = *initc;
12545 *initc = ptr[2];
12546 }
12547 else
12548 {
12549 *backwards = FALSE;
12550 *findc = ptr[2];
12551 }
12552 return;
12553 }
12554 ptr += 2;
12555 if (*ptr == *initc)
12556 {
12557 if (switchit)
12558 {
12559 *backwards = FALSE;
12560 *findc = *initc;
12561 *initc = ptr[-2];
12562 }
12563 else
12564 {
12565 *backwards = TRUE;
12566 *findc = ptr[-2];
12567 }
12568 return;
12569 }
12570 ++ptr;
12571 }
12572 if (*ptr == ',')
12573 ++ptr;
12574 }
12575}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012576
12577#if defined(FEAT_LINEBREAK) || defined(PROTO)
12578/*
12579 * This is called when 'breakindentopt' is changed and when a window is
12580 * initialized.
12581 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012582 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012583briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012584{
12585 char_u *p;
12586 int bri_shift = 0;
12587 long bri_min = 20;
12588 int bri_sbr = FALSE;
12589
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012590 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012591 while (*p != NUL)
12592 {
12593 if (STRNCMP(p, "shift:", 6) == 0
12594 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12595 {
12596 p += 6;
12597 bri_shift = getdigits(&p);
12598 }
12599 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12600 {
12601 p += 4;
12602 bri_min = getdigits(&p);
12603 }
12604 else if (STRNCMP(p, "sbr", 3) == 0)
12605 {
12606 p += 3;
12607 bri_sbr = TRUE;
12608 }
12609 if (*p != ',' && *p != NUL)
12610 return FAIL;
12611 if (*p == ',')
12612 ++p;
12613 }
12614
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012615 wp->w_p_brishift = bri_shift;
12616 wp->w_p_brimin = bri_min;
12617 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012618
12619 return OK;
12620}
12621#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012622
12623/*
12624 * Get the local or global value of 'backupcopy'.
12625 */
12626 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012627get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012628{
12629 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12630}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012631
12632#if defined(FEAT_SIGNS) || defined(PROTO)
12633/*
12634 * Return TRUE when window "wp" has a column to draw signs in.
12635 */
12636 int
12637signcolumn_on(win_T *wp)
12638{
12639 if (*wp->w_p_scl == 'n')
12640 return FALSE;
12641 if (*wp->w_p_scl == 'y')
12642 return TRUE;
12643 return (wp->w_buffer->b_signlist != NULL
12644# ifdef FEAT_NETBEANS_INTG
12645 || wp->w_buffer->b_has_sign_column
12646# endif
12647 );
12648}
12649#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012650
12651#if defined(FEAT_EVAL) || defined(PROTO)
12652/*
12653 * Get window or buffer local options.
12654 */
12655 dict_T *
12656get_winbuf_options(int bufopt)
12657{
12658 dict_T *d;
12659 int opt_idx;
12660
12661 d = dict_alloc();
12662 if (d == NULL)
12663 return NULL;
12664
12665 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12666 {
12667 struct vimoption *opt = &options[opt_idx];
12668
12669 if ((bufopt && (opt->indir & PV_BUF))
12670 || (!bufopt && (opt->indir & PV_WIN)))
12671 {
12672 char_u *varp = get_varp(opt);
12673
12674 if (varp != NULL)
12675 {
12676 if (opt->flags & P_STRING)
12677 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012678 else if (opt->flags & P_NUM)
12679 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012680 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012681 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012682 }
12683 }
12684 }
12685
12686 return d;
12687}
12688#endif