blob: 08fb789dad19b7c12330415ccc9ea7bd2bd25215 [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,
Bram Moolenaard0573012017-10-28 21:11:06 +0200513#if defined(FEAT_GUI_MAC)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000514 (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,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100637#ifdef FEAT_BEVAL_GUI
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100638 (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},
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100645 {"balloonevalterm", "bevalterm",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100646#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100647 (char_u *)&p_bevalterm, PV_NONE,
648 {(char_u *)FALSE, (char_u *)0L}
649#else
650 (char_u *)NULL, PV_NONE,
651 {(char_u *)0L, (char_u *)0L}
652#endif
653 SCRIPTID_INIT},
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100654 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
655#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
656 (char_u *)&p_bexpr, PV_BEXPR,
657 {(char_u *)"", (char_u *)0L}
658#else
659 (char_u *)NULL, PV_NONE,
660 {(char_u *)0L, (char_u *)0L}
661#endif
662 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000663 {"beautify", "bf", P_BOOL|P_VI_DEF,
664 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000665 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200666 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
667 (char_u *)&p_bo, PV_NONE,
668 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000669 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
670 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000671 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000672 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000673 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000674 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000675 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
676#ifdef FEAT_MBYTE
677 (char_u *)&p_bomb, PV_BOMB,
678#else
679 (char_u *)NULL, PV_NONE,
680#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000681 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000682 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
683#ifdef FEAT_LINEBREAK
684 (char_u *)&p_breakat, PV_NONE,
685 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
686#else
687 (char_u *)NULL, PV_NONE,
688 {(char_u *)0L, (char_u *)0L}
689#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000690 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200691 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
692#ifdef FEAT_LINEBREAK
693 (char_u *)VAR_WIN, PV_BRI,
694 {(char_u *)FALSE, (char_u *)0L}
695#else
696 (char_u *)NULL, PV_NONE,
697 {(char_u *)0L, (char_u *)0L}
698#endif
699 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200700 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
701 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200702#ifdef FEAT_LINEBREAK
703 (char_u *)VAR_WIN, PV_BRIOPT,
704 {(char_u *)"", (char_u *)NULL}
705#else
706 (char_u *)NULL, PV_NONE,
707 {(char_u *)"", (char_u *)NULL}
708#endif
709 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000710 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
711#ifdef FEAT_BROWSE
712 (char_u *)&p_bsdir, PV_NONE,
713 {(char_u *)"last", (char_u *)0L}
714#else
715 (char_u *)NULL, PV_NONE,
716 {(char_u *)0L, (char_u *)0L}
717#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000718 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000719 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000720 (char_u *)&p_bh, PV_BH,
721 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000722 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000723 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
724 (char_u *)&p_bl, PV_BL,
725 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000726 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000727 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000728 (char_u *)&p_bt, PV_BT,
729 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000730 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200731 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000732#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000733 (char_u *)&p_cmp, PV_NONE,
734 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000735#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 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
741#ifdef FEAT_SEARCHPATH
742 (char_u *)&p_cdpath, PV_NONE,
743 {(char_u *)",,", (char_u *)0L}
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 {"cedit", NULL, P_STRING,
750#ifdef FEAT_CMDWIN
751 (char_u *)&p_cedit, PV_NONE,
752 {(char_u *)"", (char_u *)CTRL_F_STR}
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 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
759#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
760 (char_u *)&p_ccv, PV_NONE,
761 {(char_u *)"", (char_u *)0L}
762#else
763 (char_u *)NULL, PV_NONE,
764 {(char_u *)0L, (char_u *)0L}
765#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000766 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000767 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
768#ifdef FEAT_CINDENT
769 (char_u *)&p_cin, PV_CIN,
770#else
771 (char_u *)NULL, PV_NONE,
772#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000773 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200774 {"cinkeys", "cink", 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_cink, PV_CINK,
777 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
778#else
779 (char_u *)NULL, PV_NONE,
780 {(char_u *)0L, (char_u *)0L}
781#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000782 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200783 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000784#ifdef FEAT_CINDENT
785 (char_u *)&p_cino, PV_CINO,
786#else
787 (char_u *)NULL, PV_NONE,
788#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000789 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200790 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000791#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
792 (char_u *)&p_cinw, PV_CINW,
793 {(char_u *)"if,else,while,do,for,switch",
794 (char_u *)0L}
795#else
796 (char_u *)NULL, PV_NONE,
797 {(char_u *)0L, (char_u *)0L}
798#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000799 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200800 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000801#ifdef FEAT_CLIPBOARD
802 (char_u *)&p_cb, PV_NONE,
803# ifdef FEAT_XCLIPBOARD
804 {(char_u *)"autoselect,exclude:cons\\|linux",
805 (char_u *)0L}
806# else
807 {(char_u *)"", (char_u *)0L}
808# endif
809#else
810 (char_u *)NULL, PV_NONE,
811 {(char_u *)"", (char_u *)0L}
812#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000813 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000814 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
815 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000816 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000817 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
818#ifdef FEAT_CMDWIN
819 (char_u *)&p_cwh, PV_NONE,
820#else
821 (char_u *)NULL, PV_NONE,
822#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000823 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200824 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200825#ifdef FEAT_SYN_HL
826 (char_u *)VAR_WIN, PV_CC,
827#else
828 (char_u *)NULL, PV_NONE,
829#endif
830 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000831 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
832 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000833 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200834 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
835 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000836#ifdef FEAT_COMMENTS
837 (char_u *)&p_com, PV_COM,
838 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
839 (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 Moolenaar913077c2012-03-28 19:59:04 +0200845 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000846#ifdef FEAT_FOLDING
847 (char_u *)&p_cms, PV_CMS,
848 {(char_u *)"/*%s*/", (char_u *)0L}
849#else
850 (char_u *)NULL, PV_NONE,
851 {(char_u *)0L, (char_u *)0L}
852#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000853 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000854 /* P_PRI_MKRC isn't needed here, optval_default()
855 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000856 {"compatible", "cp", P_BOOL|P_RALL,
857 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000858 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200859 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000860#ifdef FEAT_INS_EXPAND
861 (char_u *)&p_cpt, PV_CPT,
862 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
863#else
864 (char_u *)NULL, PV_NONE,
865 {(char_u *)0L, (char_u *)0L}
866#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000867 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200868 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200869#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200870 (char_u *)VAR_WIN, PV_COCU,
871 {(char_u *)"", (char_u *)NULL}
872#else
873 (char_u *)NULL, PV_NONE,
874 {(char_u *)NULL, (char_u *)0L}
875#endif
876 SCRIPTID_INIT},
877 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
878#ifdef FEAT_CONCEAL
879 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200880#else
881 (char_u *)NULL, PV_NONE,
882#endif
883 {(char_u *)0L, (char_u *)0L}
884 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000885 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
886#ifdef FEAT_COMPL_FUNC
887 (char_u *)&p_cfu, PV_CFU,
888 {(char_u *)"", (char_u *)0L}
889#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 Moolenaar0e7c4b92015-06-20 15:30:03 +0200894 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000895#ifdef FEAT_INS_EXPAND
896 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000897 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000898#else
899 (char_u *)NULL, PV_NONE,
900 {(char_u *)0L, (char_u *)0L}
901#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000902 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000903 {"confirm", "cf", P_BOOL|P_VI_DEF,
904#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
905 (char_u *)&p_confirm, PV_NONE,
906#else
907 (char_u *)NULL, PV_NONE,
908#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000909 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000910 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000911 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000912 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000913 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
914 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000915 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000916 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
917 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000918 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
919 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200920 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200921#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200922 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200923 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200924#else
925 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200926 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200927#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200928 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000929 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
930#ifdef FEAT_CSCOPE
931 (char_u *)&p_cspc, PV_NONE,
932#else
933 (char_u *)NULL, PV_NONE,
934#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000935 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000936 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
937#ifdef FEAT_CSCOPE
938 (char_u *)&p_csprg, PV_NONE,
939 {(char_u *)"cscope", (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 Moolenaar0e7c4b92015-06-20 15:30:03 +0200945 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000946#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
947 (char_u *)&p_csqf, PV_NONE,
948 {(char_u *)"", (char_u *)0L}
949#else
950 (char_u *)NULL, PV_NONE,
951 {(char_u *)0L, (char_u *)0L}
952#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000953 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200954 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
955#ifdef FEAT_CSCOPE
956 (char_u *)&p_csre, PV_NONE,
957#else
958 (char_u *)NULL, PV_NONE,
959#endif
960 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000961 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
962#ifdef FEAT_CSCOPE
963 (char_u *)&p_cst, PV_NONE,
964#else
965 (char_u *)NULL, PV_NONE,
966#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000967 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000968 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
969#ifdef FEAT_CSCOPE
970 (char_u *)&p_csto, PV_NONE,
971#else
972 (char_u *)NULL, PV_NONE,
973#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000974 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000975 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
976#ifdef FEAT_CSCOPE
977 (char_u *)&p_csverbose, PV_NONE,
978#else
979 (char_u *)NULL, PV_NONE,
980#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000981 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200982 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
983#ifdef FEAT_CURSORBIND
984 (char_u *)VAR_WIN, PV_CRBIND,
985#else
986 (char_u *)NULL, PV_NONE,
987#endif
988 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000989 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
990#ifdef FEAT_SYN_HL
991 (char_u *)VAR_WIN, PV_CUC,
992#else
993 (char_u *)NULL, PV_NONE,
994#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000995 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100996 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000997#ifdef FEAT_SYN_HL
998 (char_u *)VAR_WIN, PV_CUL,
999#else
1000 (char_u *)NULL, PV_NONE,
1001#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001002 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001003 {"debug", NULL, P_STRING|P_VI_DEF,
1004 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001005 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001006 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001007#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001008 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001009 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001010#else
1011 (char_u *)NULL, PV_NONE,
1012 {(char_u *)NULL, (char_u *)0L}
1013#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001014 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001015 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
1016#ifdef FEAT_MBYTE
1017 (char_u *)&p_deco, PV_NONE,
1018#else
1019 (char_u *)NULL, PV_NONE,
1020#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001021 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001022 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001023#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001024 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001025#else
1026 (char_u *)NULL, PV_NONE,
1027#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001028 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001029 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1030#ifdef FEAT_DIFF
1031 (char_u *)VAR_WIN, PV_DIFF,
1032#else
1033 (char_u *)NULL, PV_NONE,
1034#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001035 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001036 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001037#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1038 (char_u *)&p_dex, PV_NONE,
1039 {(char_u *)"", (char_u *)0L}
1040#else
1041 (char_u *)NULL, PV_NONE,
1042 {(char_u *)0L, (char_u *)0L}
1043#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001044 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001045 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1046 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001047#ifdef FEAT_DIFF
1048 (char_u *)&p_dip, PV_NONE,
1049 {(char_u *)"filler", (char_u *)NULL}
1050#else
1051 (char_u *)NULL, PV_NONE,
1052 {(char_u *)"", (char_u *)NULL}
1053#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001054 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001055 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1056#ifdef FEAT_DIGRAPHS
1057 (char_u *)&p_dg, PV_NONE,
1058#else
1059 (char_u *)NULL, PV_NONE,
1060#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001061 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001062 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1063 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001064 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001065 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001066 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001067 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001068 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001069 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001070 (char_u *)&p_ead, PV_NONE,
1071 {(char_u *)"both", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001072 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001073 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1074 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001075 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001076 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
1077#if defined(FEAT_MBYTE)
1078 (char_u *)&p_emoji, PV_NONE,
1079 {(char_u *)TRUE, (char_u *)0L}
1080#else
1081 (char_u *)NULL, PV_NONE,
1082 {(char_u *)0L, (char_u *)0L}
1083#endif
1084 SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001085 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001086#ifdef FEAT_MBYTE
1087 (char_u *)&p_enc, PV_NONE,
1088 {(char_u *)ENC_DFLT, (char_u *)0L}
1089#else
1090 (char_u *)NULL, PV_NONE,
1091 {(char_u *)0L, (char_u *)0L}
1092#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001093 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001094 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1095 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001096 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001097 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1098 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001099 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001100 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001101 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001102 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001103 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1104 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001105 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001106 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1107#ifdef FEAT_QUICKFIX
1108 (char_u *)&p_ef, PV_NONE,
1109 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1110#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 Moolenaar0e7c4b92015-06-20 15:30:03 +02001115 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001116#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001117 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001118 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001119#else
1120 (char_u *)NULL, PV_NONE,
1121 {(char_u *)NULL, (char_u *)0L}
1122#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001123 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001124 {"esckeys", "ek", P_BOOL|P_VIM,
1125 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001126 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001127 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001128#ifdef FEAT_AUTOCMD
1129 (char_u *)&p_ei, PV_NONE,
1130#else
1131 (char_u *)NULL, PV_NONE,
1132#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001133 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001134 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1135 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001136 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001137 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1138 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001139 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001140 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1141 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001142#ifdef FEAT_MBYTE
1143 (char_u *)&p_fenc, PV_FENC,
1144 {(char_u *)"", (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 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001151#ifdef FEAT_MBYTE
1152 (char_u *)&p_fencs, PV_NONE,
1153 {(char_u *)"ucs-bom", (char_u *)0L}
1154#else
1155 (char_u *)NULL, PV_NONE,
1156 {(char_u *)0L, (char_u *)0L}
1157#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001158 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001159 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1160 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001161 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001162 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001163 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001164 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001165 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1166 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001167 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1168 (char_u *)&p_fic, PV_NONE,
1169 {
1170#ifdef CASE_INSENSITIVE_FILENAME
1171 (char_u *)TRUE,
1172#else
1173 (char_u *)FALSE,
1174#endif
1175 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001176 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001177#ifdef FEAT_AUTOCMD
1178 (char_u *)&p_ft, PV_FT,
1179 {(char_u *)"", (char_u *)0L}
1180#else
1181 (char_u *)NULL, PV_NONE,
1182 {(char_u *)0L, (char_u *)0L}
1183#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001184 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001185 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001186 (char_u *)&p_fcs, PV_NONE,
1187 {(char_u *)"vert:|,fold:-", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001188 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001189 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1190 (char_u *)&p_fixeol, PV_FIXEOL,
1191 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001192 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1193#ifdef FEAT_FKMAP
1194 (char_u *)&p_fkmap, PV_NONE,
1195#else
1196 (char_u *)NULL, PV_NONE,
1197#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001198 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001199 {"flash", "fl", P_BOOL|P_VI_DEF,
1200 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001201 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001202 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001203#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001204 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001205 {(char_u *)"", (char_u *)0L}
1206#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001207 (char_u *)NULL, PV_NONE,
1208 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001209#endif
1210 SCRIPTID_INIT},
1211 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1212#ifdef FEAT_FOLDING
1213 (char_u *)VAR_WIN, PV_FDC,
1214 {(char_u *)FALSE, (char_u *)0L}
1215#else
1216 (char_u *)NULL, PV_NONE,
1217 {(char_u *)NULL, (char_u *)0L}
1218#endif
1219 SCRIPTID_INIT},
1220 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1221#ifdef FEAT_FOLDING
1222 (char_u *)VAR_WIN, PV_FEN,
1223 {(char_u *)TRUE, (char_u *)0L}
1224#else
1225 (char_u *)NULL, PV_NONE,
1226 {(char_u *)NULL, (char_u *)0L}
1227#endif
1228 SCRIPTID_INIT},
1229 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1230#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1231 (char_u *)VAR_WIN, PV_FDE,
1232 {(char_u *)"0", (char_u *)NULL}
1233#else
1234 (char_u *)NULL, PV_NONE,
1235 {(char_u *)NULL, (char_u *)0L}
1236#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001237 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001238 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|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_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001241 {(char_u *)"#", (char_u *)NULL}
1242#else
1243 (char_u *)NULL, PV_NONE,
1244 {(char_u *)NULL, (char_u *)0L}
1245#endif
1246 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001247 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001248#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001249 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001250 {(char_u *)0L, (char_u *)0L}
1251#else
1252 (char_u *)NULL, PV_NONE,
1253 {(char_u *)NULL, (char_u *)0L}
1254#endif
1255 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001256 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001257#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001258 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001259 {(char_u *)-1L, (char_u *)0L}
1260#else
1261 (char_u *)NULL, PV_NONE,
1262 {(char_u *)NULL, (char_u *)0L}
1263#endif
1264 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001265 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001266 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001267#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001268 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001269 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001270#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001271 (char_u *)NULL, PV_NONE,
1272 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001273#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001274 SCRIPTID_INIT},
1275 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1276#ifdef FEAT_FOLDING
1277 (char_u *)VAR_WIN, PV_FDM,
1278 {(char_u *)"manual", (char_u *)NULL}
1279#else
1280 (char_u *)NULL, PV_NONE,
1281 {(char_u *)NULL, (char_u *)0L}
1282#endif
1283 SCRIPTID_INIT},
1284 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1285#ifdef FEAT_FOLDING
1286 (char_u *)VAR_WIN, PV_FML,
1287 {(char_u *)1L, (char_u *)0L}
1288#else
1289 (char_u *)NULL, PV_NONE,
1290 {(char_u *)NULL, (char_u *)0L}
1291#endif
1292 SCRIPTID_INIT},
1293 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1294#ifdef FEAT_FOLDING
1295 (char_u *)VAR_WIN, PV_FDN,
1296 {(char_u *)20L, (char_u *)0L}
1297#else
1298 (char_u *)NULL, PV_NONE,
1299 {(char_u *)NULL, (char_u *)0L}
1300#endif
1301 SCRIPTID_INIT},
1302 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1303#ifdef FEAT_FOLDING
1304 (char_u *)&p_fdo, PV_NONE,
1305 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1306 (char_u *)0L}
1307#else
1308 (char_u *)NULL, PV_NONE,
1309 {(char_u *)NULL, (char_u *)0L}
1310#endif
1311 SCRIPTID_INIT},
1312 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1313#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1314 (char_u *)VAR_WIN, PV_FDT,
1315 {(char_u *)"foldtext()", (char_u *)NULL}
1316#else
1317 (char_u *)NULL, PV_NONE,
1318 {(char_u *)NULL, (char_u *)0L}
1319#endif
1320 SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001321 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001322#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001323 (char_u *)&p_fex, PV_FEX,
1324 {(char_u *)"", (char_u *)0L}
1325#else
1326 (char_u *)NULL, PV_NONE,
1327 {(char_u *)0L, (char_u *)0L}
1328#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001329 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001330 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1331 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001332 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1333 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001334 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1335 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001336 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1337 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001338 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001339 (char_u *)&p_fp, PV_FP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001340 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001341 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1342#ifdef HAVE_FSYNC
1343 (char_u *)&p_fs, PV_NONE,
1344 {(char_u *)TRUE, (char_u *)0L}
1345#else
1346 (char_u *)NULL, PV_NONE,
1347 {(char_u *)FALSE, (char_u *)0L}
1348#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001349 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001350 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1351 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001352 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001353 {"graphic", "gr", P_BOOL|P_VI_DEF,
1354 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001355 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001356 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001357#ifdef FEAT_QUICKFIX
1358 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001359 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001360#else
1361 (char_u *)NULL, PV_NONE,
1362 {(char_u *)NULL, (char_u *)0L}
1363#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001364 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001365 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1366#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001367 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001368 {
1369# ifdef WIN3264
1370 /* may be changed to "grep -n" in os_win32.c */
1371 (char_u *)"findstr /n",
1372# else
1373# ifdef UNIX
1374 /* Add an extra file name so that grep will always
1375 * insert a file name in the match line. */
1376 (char_u *)"grep -n $* /dev/null",
1377# else
1378# ifdef VMS
1379 (char_u *)"SEARCH/NUMBERS ",
1380# else
1381 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001382# endif
1383# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001384# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001385 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001386#else
1387 (char_u *)NULL, PV_NONE,
1388 {(char_u *)NULL, (char_u *)0L}
1389#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001390 SCRIPTID_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001391 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001392#ifdef CURSOR_SHAPE
1393 (char_u *)&p_guicursor, PV_NONE,
1394 {
1395# ifdef FEAT_GUI
1396 (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 +01001397# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001398 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1399# endif
1400 (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 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001407#ifdef FEAT_GUI
1408 (char_u *)&p_guifont, 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 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001416#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1417 (char_u *)&p_guifontset, 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 Moolenaar0e7c4b92015-06-20 15:30:03 +02001424 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001425#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1426 (char_u *)&p_guifontwide, PV_NONE,
1427 {(char_u *)"", (char_u *)0L}
1428#else
1429 (char_u *)NULL, PV_NONE,
1430 {(char_u *)NULL, (char_u *)0L}
1431#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001432 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001433 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001434#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001435 (char_u *)&p_ghr, PV_NONE,
1436#else
1437 (char_u *)NULL, PV_NONE,
1438#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001439 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001440 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001441#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001442 (char_u *)&p_go, PV_NONE,
Bram Moolenaard0573012017-10-28 21:11:06 +02001443# if defined(UNIX) && !defined(FEAT_GUI_MAC)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001444 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001445# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001446 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001447# endif
1448#else
1449 (char_u *)NULL, PV_NONE,
1450 {(char_u *)NULL, (char_u *)0L}
1451#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001452 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001453 {"guipty", NULL, P_BOOL|P_VI_DEF,
1454#if defined(FEAT_GUI)
1455 (char_u *)&p_guipty, PV_NONE,
1456#else
1457 (char_u *)NULL, PV_NONE,
1458#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001459 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001460 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001461#if defined(FEAT_GUI_TABLINE)
1462 (char_u *)&p_gtl, 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 Moolenaarf9393ef2006-04-24 19:47:27 +00001469 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001470#if defined(FEAT_GUI_TABLINE)
1471 (char_u *)&p_gtt, PV_NONE,
1472 {(char_u *)"", (char_u *)0L}
1473#else
1474 (char_u *)NULL, PV_NONE,
1475 {(char_u *)NULL, (char_u *)0L}
1476#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001477 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001478 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1479 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001480 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001481 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1482 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001483 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1484 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001485 {"helpheight", "hh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001486 (char_u *)&p_hh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001487 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001488 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001489#ifdef FEAT_MULTI_LANG
1490 (char_u *)&p_hlg, PV_NONE,
1491 {(char_u *)"", (char_u *)0L}
1492#else
1493 (char_u *)NULL, PV_NONE,
1494 {(char_u *)0L, (char_u *)0L}
1495#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001496 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001497 {"hidden", "hid", P_BOOL|P_VI_DEF,
1498 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001499 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001500 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001501 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001502 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1503 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001504 {"history", "hi", P_NUM|P_VIM,
1505 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001506 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001507 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1508#ifdef FEAT_RIGHTLEFT
1509 (char_u *)&p_hkmap, PV_NONE,
1510#else
1511 (char_u *)NULL, PV_NONE,
1512#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001513 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001514 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1515#ifdef FEAT_RIGHTLEFT
1516 (char_u *)&p_hkmapp, PV_NONE,
1517#else
1518 (char_u *)NULL, PV_NONE,
1519#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001520 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001521 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1522 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001523 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001524 {"icon", NULL, P_BOOL|P_VI_DEF,
1525#ifdef FEAT_TITLE
1526 (char_u *)&p_icon, PV_NONE,
1527#else
1528 (char_u *)NULL, PV_NONE,
1529#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001530 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001531 {"iconstring", NULL, P_STRING|P_VI_DEF,
1532#ifdef FEAT_TITLE
1533 (char_u *)&p_iconstring, PV_NONE,
1534#else
1535 (char_u *)NULL, PV_NONE,
1536#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001537 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001538 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1539 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001540 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001541 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar819edbe2017-11-25 17:14:33 +01001542#if defined(FEAT_EVAL) && defined(FEAT_MBYTE)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001543 (char_u *)&p_imaf, PV_NONE,
1544 {(char_u *)"", (char_u *)NULL}
1545# else
1546 (char_u *)NULL, PV_NONE,
1547 {(char_u *)NULL, (char_u *)0L}
1548# endif
1549 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001550 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001551#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001552 (char_u *)&p_imak, PV_NONE,
1553#else
1554 (char_u *)NULL, PV_NONE,
1555#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001556 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001557 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
Bram Moolenaar819edbe2017-11-25 17:14:33 +01001558#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00001559 (char_u *)&p_imcmdline, PV_NONE,
1560#else
1561 (char_u *)NULL, PV_NONE,
1562#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001563 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001564 {"imdisable", "imd", P_BOOL|P_VI_DEF,
Bram Moolenaar819edbe2017-11-25 17:14:33 +01001565#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00001566 (char_u *)&p_imdisable, PV_NONE,
1567#else
1568 (char_u *)NULL, PV_NONE,
1569#endif
1570#ifdef __sgi
1571 {(char_u *)TRUE, (char_u *)0L}
1572#else
1573 {(char_u *)FALSE, (char_u *)0L}
1574#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001575 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001576 {"iminsert", "imi", P_NUM|P_VI_DEF,
1577 (char_u *)&p_iminsert, PV_IMI,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001578 {(char_u *)B_IMODE_NONE, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001579 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001580 {"imsearch", "ims", P_NUM|P_VI_DEF,
1581 (char_u *)&p_imsearch, PV_IMS,
Bram Moolenaar4cf56bb2017-09-16 15:50:32 +02001582 {(char_u *)B_IMODE_USE_INSERT, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001583 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001584 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar819edbe2017-11-25 17:14:33 +01001585#if defined(FEAT_EVAL) && defined(FEAT_MBYTE)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001586 (char_u *)&p_imsf, PV_NONE,
1587 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001588#else
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001589 (char_u *)NULL, PV_NONE,
1590 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001591#endif
1592 SCRIPTID_INIT},
1593 {"imstyle", "imst", P_NUM|P_VI_DEF|P_SECURE,
1594#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1595 (char_u *)&p_imst, PV_NONE,
1596 {(char_u *)IM_OVER_THE_SPOT, (char_u *)0L}
1597#else
1598 (char_u *)NULL, PV_NONE,
1599 {(char_u *)0L, (char_u *)0L}
1600#endif
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001601 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001602 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1603#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001604 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001605 {(char_u *)"^\\s*#\\s*include", (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 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1612#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1613 (char_u *)&p_inex, PV_INEX,
1614 {(char_u *)"", (char_u *)0L}
1615#else
1616 (char_u *)NULL, PV_NONE,
1617 {(char_u *)0L, (char_u *)0L}
1618#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001619 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001620 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1621 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001622 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001623 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1624#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1625 (char_u *)&p_inde, PV_INDE,
1626 {(char_u *)"", (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 Moolenaar0e7c4b92015-06-20 15:30:03 +02001632 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001633#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1634 (char_u *)&p_indk, PV_INDK,
1635 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1636#else
1637 (char_u *)NULL, PV_NONE,
1638 {(char_u *)0L, (char_u *)0L}
1639#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001640 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001641 {"infercase", "inf", P_BOOL|P_VI_DEF,
1642 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001643 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001644 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1645 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001646 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001647 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1648 (char_u *)&p_isf, PV_NONE,
1649 {
1650#ifdef BACKSLASH_IN_FILENAME
1651 /* Excluded are: & and ^ are special in cmd.exe
1652 * ( and ) are used in text separating fnames */
1653 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1654#else
1655# ifdef AMIGA
1656 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1657# else
1658# ifdef VMS
1659 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1660# else /* UNIX et al. */
1661# ifdef EBCDIC
1662 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1663# else
1664 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1665# endif
1666# endif
1667# endif
1668#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001669 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001670 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1671 (char_u *)&p_isi, PV_NONE,
1672 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001673#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001674 (char_u *)"@,48-57,_,128-167,224-235",
1675#else
1676# ifdef EBCDIC
1677 /* TODO: EBCDIC Check this! @ == isalpha()*/
1678 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1679 "112-120,128,140-142,156,158,172,"
1680 "174,186,191,203-207,219-225,235-239,"
1681 "251-254",
1682# else
1683 (char_u *)"@,48-57,_,192-255",
1684# endif
1685#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001686 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001687 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1688 (char_u *)&p_isk, PV_ISK,
1689 {
1690#ifdef EBCDIC
1691 (char_u *)"@,240-249,_",
1692 /* TODO: EBCDIC Check this! @ == isalpha()*/
1693 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1694 "112-120,128,140-142,156,158,172,"
1695 "174,186,191,203-207,219-225,235-239,"
1696 "251-254",
1697#else
1698 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001699# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001700 (char_u *)"@,48-57,_,128-167,224-235"
1701# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001702 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001703# endif
1704#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001705 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001706 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1707 (char_u *)&p_isp, PV_NONE,
1708 {
Bram Moolenaard0573012017-10-28 21:11:06 +02001709#if defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001710 (char_u *)"@,~-255",
1711#else
1712# ifdef EBCDIC
1713 /* all chars above 63 are printable */
1714 (char_u *)"63-255",
1715# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001716 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001717# endif
1718#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001719 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001720 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1721 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001722 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001723 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1724#ifdef FEAT_CRYPT
1725 (char_u *)&p_key, PV_KEY,
1726 {(char_u *)"", (char_u *)0L}
1727#else
1728 (char_u *)NULL, PV_NONE,
1729 {(char_u *)0L, (char_u *)0L}
1730#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001731 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001732 {"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 +00001733#ifdef FEAT_KEYMAP
1734 (char_u *)&p_keymap, PV_KMAP,
1735 {(char_u *)"", (char_u *)0L}
1736#else
1737 (char_u *)NULL, PV_NONE,
1738 {(char_u *)"", (char_u *)0L}
1739#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001740 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001741 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001742 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001743 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001744 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001745 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001746 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001747#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001748 (char_u *)":help",
1749#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001750# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001751 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001752# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001753# ifdef USEMAN_S
1754 (char_u *)"man -s",
1755# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001756 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001757# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001758# endif
1759#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001760 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001761 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001762#ifdef FEAT_LANGMAP
1763 (char_u *)&p_langmap, PV_NONE,
1764 {(char_u *)"", /* unmatched } */
1765#else
1766 (char_u *)NULL, PV_NONE,
1767 {(char_u *)NULL,
1768#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001769 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001770 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001771#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1772 (char_u *)&p_lm, PV_NONE,
1773#else
1774 (char_u *)NULL, PV_NONE,
1775#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001776 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001777 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1778#ifdef FEAT_LANGMAP
1779 (char_u *)&p_lnr, PV_NONE,
1780#else
1781 (char_u *)NULL, PV_NONE,
1782#endif
1783 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001784 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1785#ifdef FEAT_LANGMAP
1786 (char_u *)&p_lrm, PV_NONE,
1787#else
1788 (char_u *)NULL, PV_NONE,
1789#endif
Bram Moolenaarda9ce2c2016-09-02 19:34:10 +02001790 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001791 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001792 (char_u *)&p_ls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001793 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001794 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1795 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001796 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001797 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1798#ifdef FEAT_LINEBREAK
1799 (char_u *)VAR_WIN, PV_LBR,
1800#else
1801 (char_u *)NULL, PV_NONE,
1802#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001803 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001804 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1805 (char_u *)&Rows, PV_NONE,
1806 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001807#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001808 (char_u *)25L,
1809#else
1810 (char_u *)24L,
1811#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001812 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001813 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1814#ifdef FEAT_GUI
1815 (char_u *)&p_linespace, PV_NONE,
1816#else
1817 (char_u *)NULL, PV_NONE,
1818#endif
1819#ifdef FEAT_GUI_W32
1820 {(char_u *)1L, (char_u *)0L}
1821#else
1822 {(char_u *)0L, (char_u *)0L}
1823#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001824 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001825 {"lisp", NULL, P_BOOL|P_VI_DEF,
1826#ifdef FEAT_LISP
1827 (char_u *)&p_lisp, PV_LISP,
1828#else
1829 (char_u *)NULL, PV_NONE,
1830#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001831 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001832 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001833#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001834 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001835 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1836#else
1837 (char_u *)NULL, PV_NONE,
1838 {(char_u *)"", (char_u *)0L}
1839#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001840 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001841 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1842 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001843 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001844 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001845 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001846 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001847 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1848 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001849 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001850 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001851#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001852 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001853 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001854#else
1855 (char_u *)NULL, PV_NONE,
1856 {(char_u *)"", (char_u *)0L}
1857#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001858 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001859 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001860#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001861 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001862 {(char_u *)TRUE, (char_u *)0L}
1863#else
1864 (char_u *)NULL, PV_NONE,
1865 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001866#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001867 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001868 {"magic", NULL, P_BOOL|P_VI_DEF,
1869 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001870 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001871 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001872#ifdef FEAT_QUICKFIX
1873 (char_u *)&p_mef, PV_NONE,
1874 {(char_u *)"", (char_u *)0L}
1875#else
1876 (char_u *)NULL, PV_NONE,
1877 {(char_u *)NULL, (char_u *)0L}
1878#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001879 SCRIPTID_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001880 {"makeencoding","menc", P_STRING|P_VI_DEF,
1881#ifdef FEAT_MBYTE
1882 (char_u *)&p_menc, PV_MENC,
1883 {(char_u *)"", (char_u *)0L}
1884#else
1885 (char_u *)NULL, PV_NONE,
1886 {(char_u *)0L, (char_u *)0L}
1887#endif
1888 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001889 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1890#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001891 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001892# ifdef VMS
1893 {(char_u *)"MMS", (char_u *)0L}
1894# else
1895 {(char_u *)"make", (char_u *)0L}
1896# endif
1897#else
1898 (char_u *)NULL, PV_NONE,
1899 {(char_u *)NULL, (char_u *)0L}
1900#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001901 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001902 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001903 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001904 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1905 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001906 {"matchtime", "mat", P_NUM|P_VI_DEF,
1907 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001908 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001909 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001910#ifdef FEAT_MBYTE
1911 (char_u *)&p_mco, PV_NONE,
1912#else
1913 (char_u *)NULL, PV_NONE,
1914#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001915 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001916 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1917#ifdef FEAT_EVAL
1918 (char_u *)&p_mfd, PV_NONE,
1919#else
1920 (char_u *)NULL, PV_NONE,
1921#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001922 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001923 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1924 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001925 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001926 {"maxmem", "mm", P_NUM|P_VI_DEF,
1927 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001928 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1929 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001930 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1931 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001932 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001933 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1934 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001935 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1936 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001937 {"menuitems", "mis", P_NUM|P_VI_DEF,
1938#ifdef FEAT_MENU
1939 (char_u *)&p_mis, PV_NONE,
1940#else
1941 (char_u *)NULL, PV_NONE,
1942#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001943 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001944 {"mesg", NULL, P_BOOL|P_VI_DEF,
1945 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001946 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001947 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001948#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001949 (char_u *)&p_msm, PV_NONE,
1950 {(char_u *)"460000,2000,500", (char_u *)0L}
1951#else
1952 (char_u *)NULL, PV_NONE,
1953 {(char_u *)0L, (char_u *)0L}
1954#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001955 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001956 {"modeline", "ml", P_BOOL|P_VIM,
1957 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001958 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001959 {"modelines", "mls", P_NUM|P_VI_DEF,
1960 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001961 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001962 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1963 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001964 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001965 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1966 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001967 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001968 {"more", NULL, P_BOOL|P_VIM,
1969 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001970 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001971 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1972 (char_u *)&p_mouse, PV_NONE,
1973 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001974#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001975 (char_u *)"a",
1976#else
1977 (char_u *)"",
1978#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001979 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001980 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1981#ifdef FEAT_GUI
1982 (char_u *)&p_mousef, PV_NONE,
1983#else
1984 (char_u *)NULL, PV_NONE,
1985#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001986 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001987 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1988#ifdef FEAT_GUI
1989 (char_u *)&p_mh, PV_NONE,
1990#else
1991 (char_u *)NULL, PV_NONE,
1992#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001993 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001994 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1995 (char_u *)&p_mousem, PV_NONE,
1996 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001997#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001998 (char_u *)"popup",
1999#else
Bram Moolenaard0573012017-10-28 21:11:06 +02002000# if defined(MACOS_X)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002001 (char_u *)"popup_setpos",
2002# else
2003 (char_u *)"extend",
2004# endif
2005#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002006 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002007 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002008#ifdef FEAT_MOUSESHAPE
2009 (char_u *)&p_mouseshape, PV_NONE,
2010 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
2011#else
2012 (char_u *)NULL, PV_NONE,
2013 {(char_u *)NULL, (char_u *)0L}
2014#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002015 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002016 {"mousetime", "mouset", P_NUM|P_VI_DEF,
2017 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002018 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02002019 {"mzschemedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2020#if defined(DYNAMIC_MZSCHEME)
2021 (char_u *)&p_mzschemedll, PV_NONE,
2022 {(char_u *)DYNAMIC_MZSCH_DLL, (char_u *)0L}
2023#else
2024 (char_u *)NULL, PV_NONE,
2025 {(char_u *)"", (char_u *)0L}
2026#endif
2027 SCRIPTID_INIT},
2028 {"mzschemegcdll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2029#if defined(DYNAMIC_MZSCHEME)
2030 (char_u *)&p_mzschemegcdll, PV_NONE,
2031 {(char_u *)DYNAMIC_MZGC_DLL, (char_u *)0L}
2032#else
2033 (char_u *)NULL, PV_NONE,
2034 {(char_u *)"", (char_u *)0L}
2035#endif
2036 SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00002037 {"mzquantum", "mzq", P_NUM,
2038#ifdef FEAT_MZSCHEME
2039 (char_u *)&p_mzq, PV_NONE,
2040#else
2041 (char_u *)NULL, PV_NONE,
2042#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002043 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002044 {"novice", NULL, P_BOOL|P_VI_DEF,
2045 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002046 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002047 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002048 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01002049 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002050 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002051 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
2052 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002053 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002054 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
2055#ifdef FEAT_LINEBREAK
2056 (char_u *)VAR_WIN, PV_NUW,
2057#else
2058 (char_u *)NULL, PV_NONE,
2059#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002060 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00002061 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00002062#ifdef FEAT_COMPL_FUNC
2063 (char_u *)&p_ofu, PV_OFU,
2064 {(char_u *)"", (char_u *)0L}
2065#else
2066 (char_u *)NULL, PV_NONE,
2067 {(char_u *)0L, (char_u *)0L}
2068#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002069 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002070 {"open", NULL, P_BOOL|P_VI_DEF,
2071 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002072 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002073 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002074#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002075 (char_u *)&p_odev, PV_NONE,
2076#else
2077 (char_u *)NULL, PV_NONE,
2078#endif
2079 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002080 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002081 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2082 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002083 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002084 {"optimize", "opt", P_BOOL|P_VI_DEF,
2085 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002086 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002087 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002088 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02002089 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002090 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2091 |P_SECURE,
2092 (char_u *)&p_pp, PV_NONE,
2093 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2094 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002095 {"paragraphs", "para", P_STRING|P_VI_DEF,
2096 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002097 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002098 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002099 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002100 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002101 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002102 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2103 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002104 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002105 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2106#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2107 (char_u *)&p_pex, PV_NONE,
2108 {(char_u *)"", (char_u *)0L}
2109#else
2110 (char_u *)NULL, PV_NONE,
2111 {(char_u *)0L, (char_u *)0L}
2112#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002113 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002114 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002115 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002116 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002117 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002118 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002119 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002120#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002121 (char_u *)".,,",
2122#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002123 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002124#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002125 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002126 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002127#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002128 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002129 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002130#else
2131 (char_u *)NULL, PV_NONE,
2132 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002133#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002134 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002135 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2136 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002137 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002138 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002139#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002140 (char_u *)&p_pvh, PV_NONE,
2141#else
2142 (char_u *)NULL, PV_NONE,
2143#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002144 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002145 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002146#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002147 (char_u *)VAR_WIN, PV_PVW,
2148#else
2149 (char_u *)NULL, PV_NONE,
2150#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002151 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002152 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002153#ifdef FEAT_PRINTER
2154 (char_u *)&p_pdev, PV_NONE,
2155 {(char_u *)"", (char_u *)0L}
2156#else
2157 (char_u *)NULL, PV_NONE,
2158 {(char_u *)NULL, (char_u *)0L}
2159#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002160 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002161 {"printencoding", "penc", P_STRING|P_VI_DEF,
2162#ifdef FEAT_POSTSCRIPT
2163 (char_u *)&p_penc, PV_NONE,
2164 {(char_u *)"", (char_u *)0L}
2165#else
2166 (char_u *)NULL, PV_NONE,
2167 {(char_u *)NULL, (char_u *)0L}
2168#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002169 SCRIPTID_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002170 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002171#ifdef FEAT_POSTSCRIPT
2172 (char_u *)&p_pexpr, PV_NONE,
2173 {(char_u *)"", (char_u *)0L}
2174#else
2175 (char_u *)NULL, PV_NONE,
2176 {(char_u *)NULL, (char_u *)0L}
2177#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002178 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002179 {"printfont", "pfn", P_STRING|P_VI_DEF,
2180#ifdef FEAT_PRINTER
2181 (char_u *)&p_pfn, PV_NONE,
2182 {
2183# ifdef MSWIN
2184 (char_u *)"Courier_New:h10",
2185# else
2186 (char_u *)"courier",
2187# endif
2188 (char_u *)0L}
2189#else
2190 (char_u *)NULL, PV_NONE,
2191 {(char_u *)NULL, (char_u *)0L}
2192#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002193 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002194 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2195#ifdef FEAT_PRINTER
2196 (char_u *)&p_header, PV_NONE,
Bram Moolenaar0903d562017-08-26 22:30:15 +02002197 /* untranslated to avoid problems when 'encoding'
2198 * is changed */
2199 {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002200#else
2201 (char_u *)NULL, PV_NONE,
2202 {(char_u *)NULL, (char_u *)0L}
2203#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002204 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002205 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2206#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2207 (char_u *)&p_pmcs, PV_NONE,
2208 {(char_u *)"", (char_u *)0L}
2209#else
2210 (char_u *)NULL, PV_NONE,
2211 {(char_u *)NULL, (char_u *)0L}
2212#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002213 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002214 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2215#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2216 (char_u *)&p_pmfn, PV_NONE,
2217 {(char_u *)"", (char_u *)0L}
2218#else
2219 (char_u *)NULL, PV_NONE,
2220 {(char_u *)NULL, (char_u *)0L}
2221#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002222 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002223 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002224#ifdef FEAT_PRINTER
2225 (char_u *)&p_popt, PV_NONE,
2226 {(char_u *)"", (char_u *)0L}
2227#else
2228 (char_u *)NULL, PV_NONE,
2229 {(char_u *)NULL, (char_u *)0L}
2230#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002231 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002232 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002233 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002234 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002235 {"pumheight", "ph", P_NUM|P_VI_DEF,
2236#ifdef FEAT_INS_EXPAND
2237 (char_u *)&p_ph, PV_NONE,
2238#else
2239 (char_u *)NULL, PV_NONE,
2240#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002241 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002242 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002243#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002244 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002245 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002246#else
2247 (char_u *)NULL, PV_NONE,
2248 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002249#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002250 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002251 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002252#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002253 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002254 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002255#else
2256 (char_u *)NULL, PV_NONE,
2257 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002258#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002259 SCRIPTID_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002260 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2261#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2262 (char_u *)&p_pyx, PV_NONE,
2263#else
2264 (char_u *)NULL, PV_NONE,
2265#endif
2266 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
2267 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002268 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2269#ifdef FEAT_TEXTOBJ
2270 (char_u *)&p_qe, PV_QE,
2271 {(char_u *)"\\", (char_u *)0L}
2272#else
2273 (char_u *)NULL, PV_NONE,
2274 {(char_u *)NULL, (char_u *)0L}
2275#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002276 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002277 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2278 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002279 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002280 {"redraw", NULL, P_BOOL|P_VI_DEF,
2281 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002282 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002283 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2284#ifdef FEAT_RELTIME
2285 (char_u *)&p_rdt, PV_NONE,
2286#else
2287 (char_u *)NULL, PV_NONE,
2288#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002289 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002290 {"regexpengine", "re", P_NUM|P_VI_DEF,
2291 (char_u *)&p_re, PV_NONE,
2292 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002293 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2294 (char_u *)VAR_WIN, PV_RNU,
2295 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002296 {"remap", NULL, P_BOOL|P_VI_DEF,
2297 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002298 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002299 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002300#ifdef FEAT_RENDER_OPTIONS
2301 (char_u *)&p_rop, PV_NONE,
2302 {(char_u *)"", (char_u *)0L}
2303#else
2304 (char_u *)NULL, PV_NONE,
2305 {(char_u *)NULL, (char_u *)0L}
2306#endif
2307 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002308 {"report", NULL, P_NUM|P_VI_DEF,
2309 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002310 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002311 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2312#ifdef WIN3264
2313 (char_u *)&p_rs, PV_NONE,
2314#else
2315 (char_u *)NULL, PV_NONE,
2316#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002317 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002318 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2319#ifdef FEAT_RIGHTLEFT
2320 (char_u *)&p_ri, PV_NONE,
2321#else
2322 (char_u *)NULL, PV_NONE,
2323#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002324 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002325 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2326#ifdef FEAT_RIGHTLEFT
2327 (char_u *)VAR_WIN, PV_RL,
2328#else
2329 (char_u *)NULL, PV_NONE,
2330#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002331 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002332 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2333#ifdef FEAT_RIGHTLEFT
2334 (char_u *)VAR_WIN, PV_RLC,
2335 {(char_u *)"search", (char_u *)NULL}
2336#else
2337 (char_u *)NULL, PV_NONE,
2338 {(char_u *)NULL, (char_u *)0L}
2339#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002340 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002341 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002342#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002343 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002344 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002345#else
2346 (char_u *)NULL, PV_NONE,
2347 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002348#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002349 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002350 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2351#ifdef FEAT_CMDL_INFO
2352 (char_u *)&p_ru, PV_NONE,
2353#else
2354 (char_u *)NULL, PV_NONE,
2355#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002356 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002357 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2358#ifdef FEAT_STL_OPT
2359 (char_u *)&p_ruf, PV_NONE,
2360#else
2361 (char_u *)NULL, PV_NONE,
2362#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002363 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002364 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2365 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002366 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002367 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2368 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002369 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2370 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01002371 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002372 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2373#ifdef FEAT_SCROLLBIND
2374 (char_u *)VAR_WIN, PV_SCBIND,
2375#else
2376 (char_u *)NULL, PV_NONE,
2377#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002378 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002379 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2380 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002381 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002382 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2383 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002384 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002385 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002386#ifdef FEAT_SCROLLBIND
2387 (char_u *)&p_sbo, PV_NONE,
2388 {(char_u *)"ver,jump", (char_u *)0L}
2389#else
2390 (char_u *)NULL, PV_NONE,
2391 {(char_u *)0L, (char_u *)0L}
2392#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002393 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002394 {"sections", "sect", P_STRING|P_VI_DEF,
2395 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002396 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2397 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002398 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2399 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002400 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002401 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002402 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002403 {(char_u *)"inclusive", (char_u *)0L}
2404 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002405 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002406 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002407 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002408 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002409#ifdef FEAT_SESSION
2410 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002411 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002412 (char_u *)0L}
2413#else
2414 (char_u *)NULL, PV_NONE,
2415 {(char_u *)0L, (char_u *)0L}
2416#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002417 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002418 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2419 (char_u *)&p_sh, PV_NONE,
2420 {
2421#ifdef VMS
2422 (char_u *)"-",
2423#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002424# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002425 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002426# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002427 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002428# endif
2429#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002430 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002431 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2432 (char_u *)&p_shcf, PV_NONE,
2433 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002434#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002435 (char_u *)"/c",
2436#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002437 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002438#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002439 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002440 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2441#ifdef FEAT_QUICKFIX
2442 (char_u *)&p_sp, PV_NONE,
2443 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002444#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002445 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002446#else
2447 (char_u *)">",
2448#endif
2449 (char_u *)0L}
2450#else
2451 (char_u *)NULL, PV_NONE,
2452 {(char_u *)0L, (char_u *)0L}
2453#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002454 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002455 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2456 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002457 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002458 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2459 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002460 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002461 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2462#ifdef BACKSLASH_IN_FILENAME
2463 (char_u *)&p_ssl, PV_NONE,
2464#else
2465 (char_u *)NULL, PV_NONE,
2466#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002467 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002468 {"shelltemp", "stmp", P_BOOL,
2469 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002470 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002471 {"shelltype", "st", P_NUM|P_VI_DEF,
2472#ifdef AMIGA
2473 (char_u *)&p_st, PV_NONE,
2474#else
2475 (char_u *)NULL, PV_NONE,
2476#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002477 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002478 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2479 (char_u *)&p_sxq, PV_NONE,
2480 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002481#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002482 (char_u *)"\"",
2483#else
2484 (char_u *)"",
2485#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002486 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002487 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2488 (char_u *)&p_sxe, PV_NONE,
2489 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002490#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002491 (char_u *)"\"&|<>()@^",
2492#else
2493 (char_u *)"",
2494#endif
2495 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002496 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2497 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002498 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002499 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2500 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002501 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002502 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2503 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002504 {(char_u *)"", (char_u *)"filnxtToO"}
2505 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002506 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002507 (char_u *)&p_sn, PV_SN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002508 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002509 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2510#ifdef FEAT_LINEBREAK
2511 (char_u *)&p_sbr, PV_NONE,
2512#else
2513 (char_u *)NULL, PV_NONE,
2514#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002515 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002516 {"showcmd", "sc", P_BOOL|P_VIM,
2517#ifdef FEAT_CMDL_INFO
2518 (char_u *)&p_sc, PV_NONE,
2519#else
2520 (char_u *)NULL, PV_NONE,
2521#endif
2522 {(char_u *)FALSE,
2523#ifdef UNIX
2524 (char_u *)FALSE
2525#else
2526 (char_u *)TRUE
2527#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002528 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002529 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2530 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002531 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002532 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2533 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002534 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002535 {"showmode", "smd", P_BOOL|P_VIM,
2536 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002537 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002538 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002539 (char_u *)&p_stal, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002540 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002541 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2542 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002543 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002544 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2545 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002546 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002547 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2548#ifdef FEAT_SIGNS
2549 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002550 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002551#else
2552 (char_u *)NULL, PV_NONE,
2553 {(char_u *)NULL, (char_u *)0L}
2554#endif
Bram Moolenaarb3384832016-08-12 18:51:58 +02002555 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002556 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2557 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002558 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002559 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2560 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002561 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002562 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2563#ifdef FEAT_SMARTINDENT
2564 (char_u *)&p_si, PV_SI,
2565#else
2566 (char_u *)NULL, PV_NONE,
2567#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002568 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002569 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2570 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002571 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002572 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2573 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002574 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002575 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2576 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002577 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002578 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002579#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002580 (char_u *)VAR_WIN, PV_SPELL,
2581#else
2582 (char_u *)NULL, PV_NONE,
2583#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002584 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002585 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002586#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002587 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002588 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002589#else
2590 (char_u *)NULL, PV_NONE,
2591 {(char_u *)0L, (char_u *)0L}
2592#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002593 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002594 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2595 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002596#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002597 (char_u *)&p_spf, PV_SPF,
2598 {(char_u *)"", (char_u *)0L}
2599#else
2600 (char_u *)NULL, PV_NONE,
2601 {(char_u *)0L, (char_u *)0L}
2602#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002603 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002604 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2605 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002606#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002607 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002608 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002609#else
2610 (char_u *)NULL, PV_NONE,
2611 {(char_u *)0L, (char_u *)0L}
2612#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002613 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002614 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002615#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002616 (char_u *)&p_sps, PV_NONE,
2617 {(char_u *)"best", (char_u *)0L}
2618#else
2619 (char_u *)NULL, PV_NONE,
2620 {(char_u *)0L, (char_u *)0L}
2621#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002622 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002623 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002624 (char_u *)&p_sb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002625 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002626 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002627 (char_u *)&p_spr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002628 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002629 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2630 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002631 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002632 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2633#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002634 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002635#else
2636 (char_u *)NULL, PV_NONE,
2637#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002638 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002639 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002640 (char_u *)&p_su, PV_NONE,
2641 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002642 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002643 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002644#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002645 (char_u *)&p_sua, PV_SUA,
2646 {(char_u *)"", (char_u *)0L}
2647#else
2648 (char_u *)NULL, PV_NONE,
2649 {(char_u *)0L, (char_u *)0L}
2650#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002651 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002652 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2653 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002654 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002655 {"swapsync", "sws", P_STRING|P_VI_DEF,
2656 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002657 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002658 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002659 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002660 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002661 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2662#ifdef FEAT_SYN_HL
2663 (char_u *)&p_smc, PV_SMC,
2664 {(char_u *)3000L, (char_u *)0L}
2665#else
2666 (char_u *)NULL, PV_NONE,
2667 {(char_u *)0L, (char_u *)0L}
2668#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002669 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002670 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002671#ifdef FEAT_SYN_HL
2672 (char_u *)&p_syn, PV_SYN,
2673 {(char_u *)"", (char_u *)0L}
2674#else
2675 (char_u *)NULL, PV_NONE,
2676 {(char_u *)0L, (char_u *)0L}
2677#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002678 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002679 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2680#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002681 (char_u *)&p_tal, PV_NONE,
2682#else
2683 (char_u *)NULL, PV_NONE,
2684#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002685 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002686 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002687 (char_u *)&p_tpm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002688 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002689 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2690 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002691 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002692 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2693 (char_u *)&p_tbs, PV_NONE,
2694#ifdef VMS /* binary searching doesn't appear to work on VMS */
2695 {(char_u *)0L, (char_u *)0L}
2696#else
2697 {(char_u *)TRUE, (char_u *)0L}
2698#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002699 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002700 {"tagcase", "tc", P_STRING|P_VIM,
2701 (char_u *)&p_tc, PV_TC,
2702 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002703 {"taglength", "tl", P_NUM|P_VI_DEF,
2704 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002705 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002706 {"tagrelative", "tr", P_BOOL|P_VIM,
2707 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002708 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002709 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002710 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002711 {
2712#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2713 (char_u *)"./tags,./TAGS,tags,TAGS",
2714#else
2715 (char_u *)"./tags,tags",
2716#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002717 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002718 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2719 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002720 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002721 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002722#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002723 (char_u *)&p_tcldll, PV_NONE,
2724 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002725#else
2726 (char_u *)NULL, PV_NONE,
2727 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002728#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002729 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002730 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2731 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002732 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002733 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2734#ifdef FEAT_ARABIC
2735 (char_u *)&p_tbidi, PV_NONE,
2736#else
2737 (char_u *)NULL, PV_NONE,
2738#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002739 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002740 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2741#ifdef FEAT_MBYTE
2742 (char_u *)&p_tenc, PV_NONE,
2743 {(char_u *)"", (char_u *)0L}
2744#else
2745 (char_u *)NULL, PV_NONE,
2746 {(char_u *)0L, (char_u *)0L}
2747#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002748 SCRIPTID_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002749 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2750#ifdef FEAT_TERMGUICOLORS
2751 (char_u *)&p_tgc, PV_NONE,
2752 {(char_u *)FALSE, (char_u *)FALSE}
2753#else
2754 (char_u*)NULL, PV_NONE,
2755 {(char_u *)FALSE, (char_u *)FALSE}
2756#endif
2757 SCRIPTID_INIT},
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002758 {"termkey", "tk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2759#ifdef FEAT_TERMINAL
2760 (char_u *)VAR_WIN, PV_TK,
Bram Moolenaar1f28b4c2017-07-28 13:48:34 +02002761 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002762#else
2763 (char_u *)NULL, PV_NONE,
2764 {(char_u *)NULL, (char_u *)0L}
2765#endif
2766 SCRIPTID_INIT},
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002767 {"termsize", "tms", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2768#ifdef FEAT_TERMINAL
2769 (char_u *)VAR_WIN, PV_TMS,
2770 {(char_u *)"", (char_u *)NULL}
2771#else
2772 (char_u *)NULL, PV_NONE,
2773 {(char_u *)NULL, (char_u *)0L}
2774#endif
2775 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002776 {"terse", NULL, P_BOOL|P_VI_DEF,
2777 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002778 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002779 {"textauto", "ta", P_BOOL|P_VIM,
2780 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002781 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2782 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002783 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2784 (char_u *)&p_tx, PV_TX,
2785 {
2786#ifdef USE_CRNL
2787 (char_u *)TRUE,
2788#else
2789 (char_u *)FALSE,
2790#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002791 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002792 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002793 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002794 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002795 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002796#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002797 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002798#else
2799 (char_u *)NULL, PV_NONE,
2800#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002801 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002802 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2803 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002804 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002805 {"timeout", "to", P_BOOL|P_VI_DEF,
2806 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002807 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002808 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2809 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002810 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002811 {"title", NULL, P_BOOL|P_VI_DEF,
2812#ifdef FEAT_TITLE
2813 (char_u *)&p_title, PV_NONE,
2814#else
2815 (char_u *)NULL, PV_NONE,
2816#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002817 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002818 {"titlelen", NULL, P_NUM|P_VI_DEF,
2819#ifdef FEAT_TITLE
2820 (char_u *)&p_titlelen, PV_NONE,
2821#else
2822 (char_u *)NULL, PV_NONE,
2823#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002824 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002825 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002826#ifdef FEAT_TITLE
2827 (char_u *)&p_titleold, PV_NONE,
2828 {(char_u *)N_("Thanks for flying Vim"),
2829 (char_u *)0L}
2830#else
2831 (char_u *)NULL, PV_NONE,
2832 {(char_u *)0L, (char_u *)0L}
2833#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002834 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002835 {"titlestring", NULL, P_STRING|P_VI_DEF,
2836#ifdef FEAT_TITLE
2837 (char_u *)&p_titlestring, PV_NONE,
2838#else
2839 (char_u *)NULL, PV_NONE,
2840#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002841 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002842 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002843#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002844 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002845 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002846#else
2847 (char_u *)NULL, PV_NONE,
2848 {(char_u *)0L, (char_u *)0L}
2849#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002850 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002851 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002852#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002853 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002854 {(char_u *)"small", (char_u *)0L}
2855#else
2856 (char_u *)NULL, PV_NONE,
2857 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002858#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002859 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002860 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2861 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002862 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002863 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2864 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002865 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002866 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2867 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002868 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002869 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2870 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002871 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002872 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2873#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2874 (char_u *)&p_ttym, PV_NONE,
2875#else
2876 (char_u *)NULL, PV_NONE,
2877#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002878 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002879 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2880 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002881 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002882 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2883 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002884 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002885 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2886 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002887#ifdef FEAT_PERSISTENT_UNDO
2888 (char_u *)&p_udir, PV_NONE,
2889 {(char_u *)".", (char_u *)0L}
2890#else
2891 (char_u *)NULL, PV_NONE,
2892 {(char_u *)0L, (char_u *)0L}
2893#endif
2894 SCRIPTID_INIT},
2895 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2896#ifdef FEAT_PERSISTENT_UNDO
2897 (char_u *)&p_udf, PV_UDF,
2898#else
2899 (char_u *)NULL, PV_NONE,
2900#endif
2901 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002902 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002903 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002904 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002905#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002906 (char_u *)1000L,
2907#else
2908 (char_u *)100L,
2909#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002910 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002911 {"undoreload", "ur", P_NUM|P_VI_DEF,
2912 (char_u *)&p_ur, PV_NONE,
2913 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002914 {"updatecount", "uc", P_NUM|P_VI_DEF,
2915 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002916 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002917 {"updatetime", "ut", P_NUM|P_VI_DEF,
2918 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002919 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002920 {"verbose", "vbs", P_NUM|P_VI_DEF,
2921 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002922 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002923 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2924 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002925 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002926 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2927#ifdef FEAT_SESSION
2928 (char_u *)&p_vdir, PV_NONE,
2929 {(char_u *)DFLT_VDIR, (char_u *)0L}
2930#else
2931 (char_u *)NULL, PV_NONE,
2932 {(char_u *)0L, (char_u *)0L}
2933#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002934 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002935 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002936#ifdef FEAT_SESSION
2937 (char_u *)&p_vop, PV_NONE,
Bram Moolenaar13e90412017-11-11 18:16:48 +01002938 {(char_u *)"folds,options,cursor,curdir",
2939 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002940#else
2941 (char_u *)NULL, PV_NONE,
2942 {(char_u *)0L, (char_u *)0L}
2943#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002944 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002945 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002946#ifdef FEAT_VIMINFO
2947 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002948#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002949 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002950#else
2951# ifdef AMIGA
2952 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002953 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002954# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002955 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002956# endif
2957#endif
2958#else
2959 (char_u *)NULL, PV_NONE,
2960 {(char_u *)0L, (char_u *)0L}
2961#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002962 SCRIPTID_INIT},
Bram Moolenaarc4da1132017-07-15 19:39:43 +02002963 {"viminfofile", "vif", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE|P_VI_DEF,
2964#ifdef FEAT_VIMINFO
2965 (char_u *)&p_viminfofile, PV_NONE,
2966 {(char_u *)"", (char_u *)0L}
2967#else
2968 (char_u *)NULL, PV_NONE,
2969 {(char_u *)0L, (char_u *)0L}
2970#endif
2971 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002972 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2973 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002974#ifdef FEAT_VIRTUALEDIT
2975 (char_u *)&p_ve, PV_NONE,
2976 {(char_u *)"", (char_u *)""}
2977#else
2978 (char_u *)NULL, PV_NONE,
2979 {(char_u *)0L, (char_u *)0L}
2980#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002981 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002982 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2983 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002984 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002985 {"w300", NULL, P_NUM|P_VI_DEF,
2986 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002987 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002988 {"w1200", NULL, P_NUM|P_VI_DEF,
2989 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002990 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002991 {"w9600", NULL, P_NUM|P_VI_DEF,
2992 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002993 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002994 {"warn", NULL, P_BOOL|P_VI_DEF,
2995 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002996 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002997 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2998 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002999 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003000 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003001 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003002 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003003 {"wildchar", "wc", P_NUM|P_VIM,
3004 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003005 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
3006 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003007 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003008 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003009 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003010 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003011#ifdef FEAT_WILDIGN
3012 (char_u *)&p_wig, PV_NONE,
3013#else
3014 (char_u *)NULL, PV_NONE,
3015#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003016 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003017 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3018 (char_u *)&p_wic, PV_NONE,
3019 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003020 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
3021#ifdef FEAT_WILDMENU
3022 (char_u *)&p_wmnu, PV_NONE,
3023#else
3024 (char_u *)NULL, PV_NONE,
3025#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003026 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003027 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003028 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003029 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003030 {"wildoptions", "wop", P_STRING|P_VI_DEF,
3031#ifdef FEAT_CMDL_COMPL
3032 (char_u *)&p_wop, PV_NONE,
3033 {(char_u *)"", (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 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3040#ifdef FEAT_WAK
3041 (char_u *)&p_wak, PV_NONE,
3042 {(char_u *)"menu", (char_u *)0L}
3043#else
3044 (char_u *)NULL, PV_NONE,
3045 {(char_u *)NULL, (char_u *)0L}
3046#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003047 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003048 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003049 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003050 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003051 {"winheight", "wh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003052 (char_u *)&p_wh, 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 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003055 (char_u *)VAR_WIN, PV_WFH,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003056 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003057 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003058 (char_u *)VAR_WIN, PV_WFW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003059 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003060 {"winminheight", "wmh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003061 (char_u *)&p_wmh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003062 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003063 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003064 (char_u *)&p_wmw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003065 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003066 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar84ed4ad2017-08-17 11:33:42 +02003067#if defined(WIN3264) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003068 (char_u *)&p_winptydll, PV_NONE, {
3069# ifdef _WIN64
3070 (char_u *)"winpty64.dll",
3071# else
3072 (char_u *)"winpty32.dll",
3073# endif
3074 (char_u *)0L}
3075#else
3076 (char_u *)NULL, PV_NONE,
3077 {(char_u *)0L, (char_u *)0L}
3078#endif
3079 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003080 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003081 (char_u *)&p_wiw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003082 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003083 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3084 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003085 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003086 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3087 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003088 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003089 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3090 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003091 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003092 {"write", NULL, P_BOOL|P_VI_DEF,
3093 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003094 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003095 {"writeany", "wa", P_BOOL|P_VI_DEF,
3096 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003097 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003098 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3099 (char_u *)&p_wb, PV_NONE,
3100 {
3101#ifdef FEAT_WRITEBACKUP
3102 (char_u *)TRUE,
3103#else
3104 (char_u *)FALSE,
3105#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003106 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003107 {"writedelay", "wd", P_NUM|P_VI_DEF,
3108 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003109 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003110
3111/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003112#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003113 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003114 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003115
3116 p_term("t_AB", T_CAB)
3117 p_term("t_AF", T_CAF)
3118 p_term("t_AL", T_CAL)
3119 p_term("t_al", T_AL)
3120 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003121 p_term("t_BE", T_BE)
3122 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003123 p_term("t_cd", T_CD)
3124 p_term("t_ce", T_CE)
3125 p_term("t_cl", T_CL)
3126 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003127 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003128 p_term("t_Co", T_CCO)
3129 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003130 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003131 p_term("t_cs", T_CS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003132 p_term("t_CV", T_CSV)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003133 p_term("t_da", T_DA)
3134 p_term("t_db", T_DB)
3135 p_term("t_DL", T_CDL)
3136 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003137 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003138 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003139 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003140 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003141 p_term("t_IE", T_CIE)
3142 p_term("t_IS", T_CIS)
3143 p_term("t_ke", T_KE)
3144 p_term("t_ks", T_KS)
3145 p_term("t_le", T_LE)
3146 p_term("t_mb", T_MB)
3147 p_term("t_md", T_MD)
3148 p_term("t_me", T_ME)
3149 p_term("t_mr", T_MR)
3150 p_term("t_ms", T_MS)
3151 p_term("t_nd", T_ND)
3152 p_term("t_op", T_OP)
Bram Moolenaara20f83d2017-10-15 13:35:01 +02003153 p_term("t_RF", T_RFG)
Bram Moolenaare5401222015-06-25 19:16:56 +02003154 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003155 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003156 p_term("t_RI", T_CRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003157 p_term("t_RS", T_CRS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003158 p_term("t_RV", T_CRV)
3159 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003160 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003161 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003162 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003163 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003164 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003165 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003166 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003167 p_term("t_sr", T_SR)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003168 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003169 p_term("t_te", T_TE)
3170 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003171 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003172 p_term("t_ts", T_TS)
3173 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003174 p_term("t_ue", T_UE)
3175 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003176 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003177 p_term("t_vb", T_VB)
3178 p_term("t_ve", T_VE)
3179 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003180 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003181 p_term("t_vs", T_VS)
3182 p_term("t_WP", T_CWP)
3183 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003184 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003185 p_term("t_xs", T_XS)
3186 p_term("t_ZH", T_CZH)
3187 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003188 p_term("t_8f", T_8F)
3189 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003190
3191/* terminal key codes are not in here */
3192
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003193 /* end marker */
3194 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003195};
3196
3197#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3198
3199#ifdef FEAT_MBYTE
3200static char *(p_ambw_values[]) = {"single", "double", NULL};
3201#endif
3202static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003203static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003204static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003205#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003206static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003207#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003208#ifdef FEAT_CMDL_COMPL
3209static char *(p_wop_values[]) = {"tagfile", NULL};
3210#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003211#ifdef FEAT_WAK
3212static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3213#endif
3214static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003215static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3216static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003217static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003218#ifdef FEAT_BROWSE
3219static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3220#endif
3221#ifdef FEAT_SCROLLBIND
3222static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3223#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003224static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003225static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003226#ifdef FEAT_AUTOCMD
3227static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", NULL};
3228#else
3229static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003230#endif
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003231static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003232static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3233#ifdef FEAT_FOLDING
3234static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003235# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003236 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003237# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003238 NULL};
3239static char *(p_fcl_values[]) = {"all", NULL};
3240#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003241#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003242static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003243#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003244#ifdef FEAT_SIGNS
3245static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3246#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003247
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003248static void set_option_default(int, int opt_flags, int compatible);
3249static void set_options_default(int opt_flags);
3250static char_u *term_bg_default(void);
3251static void did_set_option(int opt_idx, int opt_flags, int new_value);
3252static char_u *illegal_char(char_u *, int);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003253#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003254static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003255#endif
3256#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003257static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003258#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003259static char_u *option_expand(int opt_idx, char_u *val);
3260static void didset_options(void);
3261static void didset_options2(void);
3262static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003263#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003264static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003265#else
3266# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3267#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003268static void set_string_option_global(int opt_idx, char_u **varp);
3269static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3270static 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);
3271static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003272#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003273static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003274#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003275#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003276static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003277#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003278#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003279static char_u *did_set_spell_option(int is_spellfile);
3280static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003281#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003282#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003283static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003284#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003285static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3286static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3287static void check_redraw(long_u flags);
3288static int findoption(char_u *);
3289static int find_key_option(char_u *);
3290static void showoptions(int all, int opt_flags);
3291static int optval_default(struct vimoption *, char_u *varp);
3292static void showoneopt(struct vimoption *, int opt_flags);
3293static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3294static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3295static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3296static int istermoption(struct vimoption *);
3297static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3298static char_u *get_varp(struct vimoption *);
3299static void option_value2string(struct vimoption *, int opt_flags);
3300static void check_winopt(winopt_T *wop);
3301static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003302#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003303static void langmap_init(void);
3304static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003305#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003306static void paste_option_changed(void);
3307static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003308#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003309static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003310#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003311static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3312static int check_opt_strings(char_u *val, char **values, int);
3313static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003314#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003315static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003316#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003317
3318/*
3319 * Initialize the options, first part.
3320 *
3321 * Called only once from main(), just after creating the first buffer.
3322 */
3323 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003324set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003325{
3326 char_u *p;
3327 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003328 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003329
3330#ifdef FEAT_LANGMAP
3331 langmap_init();
3332#endif
3333
3334 /* Be Vi compatible by default */
3335 p_cp = TRUE;
3336
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003337 /* Use POSIX compatibility when $VIM_POSIX is set. */
3338 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003339 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003340 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003341 set_string_default("shm", (char_u *)"A");
3342 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003343
Bram Moolenaar071d4272004-06-13 20:20:40 +00003344 /*
3345 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003346 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003347 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003348 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003349#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003350 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003351# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003352 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003353# endif
3354#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003355 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003356 set_string_default("sh", p);
3357
3358#ifdef FEAT_WILDIGN
3359 /*
3360 * Set the default for 'backupskip' to include environment variables for
3361 * temp files.
3362 */
3363 {
3364# ifdef UNIX
3365 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3366# else
3367 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3368# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003369 int len;
3370 garray_T ga;
3371 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003372
3373 ga_init2(&ga, 1, 100);
3374 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3375 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003376 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003377# ifdef UNIX
3378 if (*names[n] == NUL)
3379 p = (char_u *)"/tmp";
3380 else
3381# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003382 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003383 if (p != NULL && *p != NUL)
3384 {
3385 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003386 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003387 if (ga_grow(&ga, len) == OK)
3388 {
3389 if (ga.ga_len > 0)
3390 STRCAT(ga.ga_data, ",");
3391 STRCAT(ga.ga_data, p);
3392 add_pathsep(ga.ga_data);
3393 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003394 ga.ga_len += len;
3395 }
3396 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003397 if (mustfree)
3398 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003399 }
3400 if (ga.ga_data != NULL)
3401 {
3402 set_string_default("bsk", ga.ga_data);
3403 vim_free(ga.ga_data);
3404 }
3405 }
3406#endif
3407
3408 /*
3409 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3410 */
3411 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003412 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003413 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003414#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3415 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3416#endif
3417 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003418#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003419 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003420 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003421#else
3422# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003423 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003424 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003425# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003426 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003427# endif
3428#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003429 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003430 opt_idx = findoption((char_u *)"maxmem");
3431 if (opt_idx >= 0)
3432 {
3433#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003434 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3435 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003436#endif
3437 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3438 }
3439 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003440 }
3441
Bram Moolenaar071d4272004-06-13 20:20:40 +00003442#ifdef FEAT_SEARCHPATH
3443 {
3444 char_u *cdpath;
3445 char_u *buf;
3446 int i;
3447 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003448 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003449
3450 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003451 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003452 if (cdpath != NULL)
3453 {
3454 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3455 if (buf != NULL)
3456 {
3457 buf[0] = ','; /* start with ",", current dir first */
3458 j = 1;
3459 for (i = 0; cdpath[i] != NUL; ++i)
3460 {
3461 if (vim_ispathlistsep(cdpath[i]))
3462 buf[j++] = ',';
3463 else
3464 {
3465 if (cdpath[i] == ' ' || cdpath[i] == ',')
3466 buf[j++] = '\\';
3467 buf[j++] = cdpath[i];
3468 }
3469 }
3470 buf[j] = NUL;
3471 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003472 if (opt_idx >= 0)
3473 {
3474 options[opt_idx].def_val[VI_DEFAULT] = buf;
3475 options[opt_idx].flags |= P_DEF_ALLOCED;
3476 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003477 else
3478 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003479 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003480 if (mustfree)
3481 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003482 }
3483 }
3484#endif
3485
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003486#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003487 /* Set print encoding on platforms that don't default to latin1 */
3488 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003489# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003490 (char_u *)"cp1252"
3491# else
3492# ifdef VMS
3493 (char_u *)"dec-mcs"
3494# else
3495# ifdef EBCDIC
3496 (char_u *)"ebcdic-uk"
3497# else
3498# ifdef MAC
3499 (char_u *)"mac-roman"
3500# else /* HPUX */
3501 (char_u *)"hp-roman8"
3502# endif
3503# endif
3504# endif
3505# endif
3506 );
3507#endif
3508
3509#ifdef FEAT_POSTSCRIPT
3510 /* 'printexpr' must be allocated to be able to evaluate it. */
3511 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003512# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003513 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003514# else
3515# ifdef VMS
3516 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3517
3518# else
3519 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3520# endif
3521# endif
3522 );
3523#endif
3524
3525 /*
3526 * Set all the options (except the terminal options) to their default
3527 * value. Also set the global value for local options.
3528 */
3529 set_options_default(0);
3530
3531#ifdef FEAT_GUI
3532 if (found_reverse_arg)
3533 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3534#endif
3535
3536 curbuf->b_p_initialized = TRUE;
3537 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003538 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003539 check_buf_options(curbuf);
3540 check_win_options(curwin);
3541 check_options();
3542
3543 /* Must be before option_expand(), because that one needs vim_isIDc() */
3544 didset_options();
3545
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003546#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003547 /* Use the current chartab for the generic chartab. This is not in
3548 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003549 init_spell_chartab();
3550#endif
3551
Bram Moolenaar071d4272004-06-13 20:20:40 +00003552 /*
3553 * Expand environment variables and things like "~" for the defaults.
3554 * If option_expand() returns non-NULL the variable is expanded. This can
3555 * only happen for non-indirect options.
3556 * Also set the default to the expanded value, so ":set" does not list
3557 * them.
3558 * Don't set the P_ALLOCED flag, because we don't want to free the
3559 * default.
3560 */
3561 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3562 {
3563 if ((options[opt_idx].flags & P_GETTEXT)
3564 && options[opt_idx].var != NULL)
3565 p = (char_u *)_(*(char **)options[opt_idx].var);
3566 else
3567 p = option_expand(opt_idx, NULL);
3568 if (p != NULL && (p = vim_strsave(p)) != NULL)
3569 {
3570 *(char_u **)options[opt_idx].var = p;
3571 /* VIMEXP
3572 * Defaults for all expanded options are currently the same for Vi
3573 * and Vim. When this changes, add some code here! Also need to
3574 * split P_DEF_ALLOCED in two.
3575 */
3576 if (options[opt_idx].flags & P_DEF_ALLOCED)
3577 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3578 options[opt_idx].def_val[VI_DEFAULT] = p;
3579 options[opt_idx].flags |= P_DEF_ALLOCED;
3580 }
3581 }
3582
Bram Moolenaar071d4272004-06-13 20:20:40 +00003583 save_file_ff(curbuf); /* Buffer is unchanged */
3584
Bram Moolenaar071d4272004-06-13 20:20:40 +00003585#if defined(FEAT_ARABIC)
3586 /* Detect use of mlterm.
3587 * Mlterm is a terminal emulator akin to xterm that has some special
3588 * abilities (bidi namely).
3589 * NOTE: mlterm's author is being asked to 'set' a variable
3590 * instead of an environment variable due to inheritance.
3591 */
3592 if (mch_getenv((char_u *)"MLTERM") != NULL)
3593 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3594#endif
3595
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003596 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003597
3598#ifdef FEAT_MBYTE
3599# if defined(WIN3264) && defined(FEAT_GETTEXT)
3600 /*
3601 * If $LANG isn't set, try to get a good value for it. This makes the
3602 * right language be used automatically. Don't do this for English.
3603 */
3604 if (mch_getenv((char_u *)"LANG") == NULL)
3605 {
3606 char buf[20];
3607
3608 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3609 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3610 * only the first two. */
3611 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3612 (LPTSTR)buf, 20);
3613 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3614 {
3615 /* There are a few exceptions (probably more) */
3616 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3617 STRCPY(buf, "zh_TW");
3618 else if (STRNICMP(buf, "chs", 3) == 0
3619 || STRNICMP(buf, "zhc", 3) == 0)
3620 STRCPY(buf, "zh_CN");
3621 else if (STRNICMP(buf, "jp", 2) == 0)
3622 STRCPY(buf, "ja");
3623 else
3624 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003625 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003626 }
3627 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003628# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003629# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003630 /* Moved to os_mac_conv.c to avoid dependency problems. */
3631 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003632# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003633# endif
3634
3635 /* enc_locale() will try to find the encoding of the current locale. */
3636 p = enc_locale();
3637 if (p != NULL)
3638 {
3639 char_u *save_enc;
3640
3641 /* Try setting 'encoding' and check if the value is valid.
3642 * If not, go back to the default "latin1". */
3643 save_enc = p_enc;
3644 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003645 if (STRCMP(p_enc, "gb18030") == 0)
3646 {
3647 /* We don't support "gb18030", but "cp936" is a good substitute
3648 * for practical purposes, thus use that. It's not an alias to
3649 * still support conversion between gb18030 and utf-8. */
3650 p_enc = vim_strsave((char_u *)"cp936");
3651 vim_free(p);
3652 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003653 if (mb_init() == NULL)
3654 {
3655 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003656 if (opt_idx >= 0)
3657 {
3658 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3659 options[opt_idx].flags |= P_DEF_ALLOCED;
3660 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003661
Bram Moolenaard0573012017-10-28 21:11:06 +02003662#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003663 if (STRCMP(p_enc, "latin1") == 0
3664# ifdef FEAT_MBYTE
3665 || enc_utf8
3666# endif
3667 )
3668 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003669 /* Adjust the default for 'isprint' and 'iskeyword' to match
3670 * latin1. Also set the defaults for when 'nocompatible' is
3671 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003672 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003673 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003674 set_string_option_direct((char_u *)"isk", -1,
3675 ISK_LATIN1, OPT_FREE, SID_NONE);
3676 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003677 if (opt_idx >= 0)
3678 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003679 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003680 if (opt_idx >= 0)
3681 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003682 (void)init_chartab();
3683 }
3684#endif
3685
Bram Moolenaar071d4272004-06-13 20:20:40 +00003686# if defined(WIN3264) && !defined(FEAT_GUI)
3687 /* Win32 console: When GetACP() returns a different value from
3688 * GetConsoleCP() set 'termencoding'. */
3689 if (GetACP() != GetConsoleCP())
3690 {
3691 char buf[50];
3692
3693 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3694 p_tenc = vim_strsave((char_u *)buf);
3695 if (p_tenc != NULL)
3696 {
3697 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003698 if (opt_idx >= 0)
3699 {
3700 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3701 options[opt_idx].flags |= P_DEF_ALLOCED;
3702 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003703 convert_setup(&input_conv, p_tenc, p_enc);
3704 convert_setup(&output_conv, p_enc, p_tenc);
3705 }
3706 else
3707 p_tenc = empty_option;
3708 }
3709# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003710# if defined(WIN3264) && defined(FEAT_MBYTE)
3711 /* $HOME may have characters in active code page. */
3712 init_homedir();
3713# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003714 }
3715 else
3716 {
3717 vim_free(p_enc);
3718 p_enc = save_enc;
3719 }
3720 }
3721#endif
3722
3723#ifdef FEAT_MULTI_LANG
3724 /* Set the default for 'helplang'. */
3725 set_helplang_default(get_mess_lang());
3726#endif
3727}
3728
3729/*
3730 * Set an option to its default value.
3731 * This does not take care of side effects!
3732 */
3733 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003734set_option_default(
3735 int opt_idx,
3736 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3737 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003738{
3739 char_u *varp; /* pointer to variable for current option */
3740 int dvi; /* index in def_val[] */
3741 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003742 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003743 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3744
3745 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3746 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003747 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003748 {
3749 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3750 if (flags & P_STRING)
3751 {
3752 /* Use set_string_option_direct() for local options to handle
3753 * freeing and allocating the value. */
3754 if (options[opt_idx].indir != PV_NONE)
3755 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003756 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003757 else
3758 {
3759 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3760 free_string_option(*(char_u **)(varp));
3761 *(char_u **)varp = options[opt_idx].def_val[dvi];
3762 options[opt_idx].flags &= ~P_ALLOCED;
3763 }
3764 }
3765 else if (flags & P_NUM)
3766 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003767 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003768 win_comp_scroll(curwin);
3769 else
3770 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003771 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003772 /* May also set global value for local option. */
3773 if (both)
3774 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3775 *(long *)varp;
3776 }
3777 }
3778 else /* P_BOOL */
3779 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003780 /* the cast to long is required for Manx C, long_i is needed for
3781 * MSVC */
3782 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003783#ifdef UNIX
3784 /* 'modeline' defaults to off for root */
3785 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3786 *(int *)varp = FALSE;
3787#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003788 /* May also set global value for local option. */
3789 if (both)
3790 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3791 *(int *)varp;
3792 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003793
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003794 /* The default value is not insecure. */
3795 flagsp = insecure_flag(opt_idx, opt_flags);
3796 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003797 }
3798
3799#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003800 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003801#endif
3802}
3803
3804/*
3805 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003806 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003807 */
3808 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003809set_options_default(
3810 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003811{
3812 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003813 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003814 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003815
3816 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003817 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003818#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003819 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003820 || (TRUE
3821# if defined(FEAT_MBYTE)
3822 && options[i].var != (char_u *)&p_enc
3823# endif
3824# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003825 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003826 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003827# endif
3828 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003829#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003830 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003831 set_option_default(i, opt_flags, p_cp);
3832
Bram Moolenaar071d4272004-06-13 20:20:40 +00003833 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003834 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003835 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003836#ifdef FEAT_CINDENT
3837 parse_cino(curbuf);
3838#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003839}
3840
3841/*
3842 * Set the Vi-default value of a string option.
3843 * Used for 'sh', 'backupskip' and 'term'.
3844 */
3845 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003846set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003847{
3848 char_u *p;
3849 int opt_idx;
3850
3851 p = vim_strsave(val);
3852 if (p != NULL) /* we don't want a NULL */
3853 {
3854 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003855 if (opt_idx >= 0)
3856 {
3857 if (options[opt_idx].flags & P_DEF_ALLOCED)
3858 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3859 options[opt_idx].def_val[VI_DEFAULT] = p;
3860 options[opt_idx].flags |= P_DEF_ALLOCED;
3861 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003862 }
3863}
3864
3865/*
3866 * Set the Vi-default value of a number option.
3867 * Used for 'lines' and 'columns'.
3868 */
3869 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003870set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003871{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003872 int opt_idx;
3873
3874 opt_idx = findoption((char_u *)name);
3875 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003876 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003877}
3878
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003879#if defined(EXITFREE) || defined(PROTO)
3880/*
3881 * Free all options.
3882 */
3883 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003884free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003885{
3886 int i;
3887
3888 for (i = 0; !istermoption(&options[i]); i++)
3889 {
3890 if (options[i].indir == PV_NONE)
3891 {
3892 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003893 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003894 free_string_option(*(char_u **)options[i].var);
3895 if (options[i].flags & P_DEF_ALLOCED)
3896 free_string_option(options[i].def_val[VI_DEFAULT]);
3897 }
3898 else if (options[i].var != VAR_WIN
3899 && (options[i].flags & P_STRING))
3900 /* buffer-local option: free global value */
3901 free_string_option(*(char_u **)options[i].var);
3902 }
3903}
3904#endif
3905
3906
Bram Moolenaar071d4272004-06-13 20:20:40 +00003907/*
3908 * Initialize the options, part two: After getting Rows and Columns and
3909 * setting 'term'.
3910 */
3911 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003912set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003913{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003914 int idx;
3915
Bram Moolenaar071d4272004-06-13 20:20:40 +00003916 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003917 * 'scroll' defaults to half the window height. The stored default is zero,
3918 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003919 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003920 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003921 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003922 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003923 comp_col();
3924
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003925 /*
3926 * 'window' is only for backwards compatibility with Vi.
3927 * Default is Rows - 1.
3928 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003929 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003930 p_window = Rows - 1;
3931 set_number_default("window", Rows - 1);
3932
Bram Moolenaarf740b292006-02-16 22:11:02 +00003933 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003934#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003935 /*
3936 * If 'background' wasn't set by the user, try guessing the value,
3937 * depending on the terminal name. Only need to check for terminals
3938 * with a dark background, that can handle color.
3939 */
3940 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003941 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3942 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003943 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003944 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003945 /* don't mark it as set, when starting the GUI it may be
3946 * changed again */
3947 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003948 }
3949#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003950
3951#ifdef CURSOR_SHAPE
3952 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3953#endif
3954#ifdef FEAT_MOUSESHAPE
3955 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3956#endif
3957#ifdef FEAT_PRINTER
3958 (void)parse_printoptions(); /* parse 'printoptions' default value */
3959#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003960}
3961
3962/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003963 * Return "dark" or "light" depending on the kind of terminal.
3964 * This is just guessing! Recognized are:
3965 * "linux" Linux console
3966 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003967 * "cygwin.*" Cygwin shell
3968 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00003969 * We also check the COLORFGBG environment variable, which is set by
3970 * rxvt and derivatives. This variable contains either two or three
3971 * values separated by semicolons; we want the last value in either
3972 * case. If this value is 0-6 or 8, our background is dark.
3973 */
3974 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003975term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003976{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003977#if defined(WIN3264)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003978 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003979 return (char_u *)"dark";
3980#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003981 char_u *p;
3982
Bram Moolenaarf740b292006-02-16 22:11:02 +00003983 if (STRCMP(T_NAME, "linux") == 0
3984 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003985 || STRNCMP(T_NAME, "cygwin", 6) == 0
3986 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00003987 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3988 && (p = vim_strrchr(p, ';')) != NULL
3989 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3990 && p[2] == NUL))
3991 return (char_u *)"dark";
3992 return (char_u *)"light";
3993#endif
3994}
3995
3996/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003997 * Initialize the options, part three: After reading the .vimrc
3998 */
3999 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004000set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004001{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004002#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004003/*
4004 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4005 * This is done after other initializations, where 'shell' might have been
4006 * set, but only if they have not been set before.
4007 */
4008 char_u *p;
4009 int idx_srr;
4010 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004011# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004012 int idx_sp;
4013 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004014# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004015
4016 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004017 if (idx_srr < 0)
4018 do_srr = FALSE;
4019 else
4020 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004021# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004022 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004023 if (idx_sp < 0)
4024 do_sp = FALSE;
4025 else
4026 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004027# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004028 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004029 if (p != NULL)
4030 {
4031 /*
4032 * Default for p_sp is "| tee", for p_srr is ">".
4033 * For known shells it is changed here to include stderr.
4034 */
4035 if ( fnamecmp(p, "csh") == 0
4036 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004037# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004038 || fnamecmp(p, "csh.exe") == 0
4039 || fnamecmp(p, "tcsh.exe") == 0
4040# endif
4041 )
4042 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004043# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004044 if (do_sp)
4045 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004046# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004047 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004048# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004049 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004050# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004051 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4052 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004053# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004054 if (do_srr)
4055 {
4056 p_srr = (char_u *)">&";
4057 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4058 }
4059 }
4060 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004061 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004062 if ( fnamecmp(p, "sh") == 0
4063 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004064 || fnamecmp(p, "mksh") == 0
4065 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004066 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004067 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004068 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004069 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004070# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004071 || fnamecmp(p, "cmd") == 0
4072 || fnamecmp(p, "sh.exe") == 0
4073 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004074 || fnamecmp(p, "mksh.exe") == 0
4075 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004076 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004077 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004078 || fnamecmp(p, "bash.exe") == 0
4079 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004080# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004081 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004082 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004083# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004084 if (do_sp)
4085 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004086# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004087 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004088# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004089 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004090# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004091 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4092 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004093# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004094 if (do_srr)
4095 {
4096 p_srr = (char_u *)">%s 2>&1";
4097 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4098 }
4099 }
4100 vim_free(p);
4101 }
4102#endif
4103
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004104#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004105 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004106 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4107 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004108 * This is done after other initializations, where 'shell' might have been
4109 * set, but only if they have not been set before. Default for p_shcf is
4110 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004111 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004112 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004113 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004114 {
4115 int idx3;
4116
4117 idx3 = findoption((char_u *)"shcf");
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_shcf = (char_u *)"-c";
4121 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4122 }
4123
Bram Moolenaar071d4272004-06-13 20:20:40 +00004124 /* Somehow Win32 requires the quotes around the redirection too */
4125 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004126 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004127 {
4128 p_sxq = (char_u *)"\"";
4129 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4130 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004131 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004132 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4133 {
4134 int idx3;
4135
4136 /*
4137 * cmd.exe on Windows will strip the first and last double quote given
4138 * on the command line, e.g. most of the time things like:
4139 * cmd /c "my path/to/echo" "my args to echo"
4140 * become:
4141 * my path/to/echo" "my args to echo
4142 * when executed.
4143 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004144 * To avoid this, set shellxquote to surround the command in
4145 * parenthesis. This appears to make most commands work, without
4146 * breaking commands that worked previously, such as
4147 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004148 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004149 idx3 = findoption((char_u *)"sxq");
4150 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4151 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004152 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004153 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4154 }
4155
Bram Moolenaara64ba222012-02-12 23:23:31 +01004156 idx3 = findoption((char_u *)"shcf");
4157 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4158 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004159 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004160 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4161 }
4162 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004163#endif
4164
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004165 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004166 {
4167 int idx_ffs = findoption((char_u *)"ffs");
4168
4169 /* Apply the first entry of 'fileformats' to the initial buffer. */
4170 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4171 set_fileformat(default_fileformat(), OPT_LOCAL);
4172 }
4173
Bram Moolenaar071d4272004-06-13 20:20:40 +00004174#ifdef FEAT_TITLE
4175 set_title_defaults();
4176#endif
4177}
4178
4179#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4180/*
4181 * When 'helplang' is still at its default value, set it to "lang".
4182 * Only the first two characters of "lang" are used.
4183 */
4184 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004185set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004186{
4187 int idx;
4188
4189 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4190 return;
4191 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004192 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004193 {
4194 if (options[idx].flags & P_ALLOCED)
4195 free_string_option(p_hlg);
4196 p_hlg = vim_strsave(lang);
4197 if (p_hlg == NULL)
4198 p_hlg = empty_option;
4199 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004200 {
4201 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4202 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4203 {
4204 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4205 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4206 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004207 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004208 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004209 options[idx].flags |= P_ALLOCED;
4210 }
4211}
4212#endif
4213
4214#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004215static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004216
4217 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004218gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004219{
4220 if (gui_get_lightness(gui.back_pixel) < 127)
4221 return (char_u *)"dark";
4222 return (char_u *)"light";
4223}
4224
4225/*
4226 * Option initializations that can only be done after opening the GUI window.
4227 */
4228 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004229init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004230{
4231 /* Set the 'background' option according to the lightness of the
4232 * background color, unless the user has set it already. */
4233 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4234 {
4235 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4236 highlight_changed();
4237 }
4238}
4239#endif
4240
4241#ifdef FEAT_TITLE
4242/*
4243 * 'title' and 'icon' only default to true if they have not been set or reset
4244 * in .vimrc and we can read the old value.
4245 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4246 * they can be reset. This reduces startup time when using X on a remote
4247 * machine.
4248 */
4249 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004250set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004251{
4252 int idx1;
4253 long val;
4254
4255 /*
4256 * If GUI is (going to be) used, we can always set the window title and
4257 * icon name. Saves a bit of time, because the X11 display server does
4258 * not need to be contacted.
4259 */
4260 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004261 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004262 {
4263#ifdef FEAT_GUI
4264 if (gui.starting || gui.in_use)
4265 val = TRUE;
4266 else
4267#endif
4268 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004269 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004270 p_title = val;
4271 }
4272 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004273 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004274 {
4275#ifdef FEAT_GUI
4276 if (gui.starting || gui.in_use)
4277 val = TRUE;
4278 else
4279#endif
4280 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004281 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004282 p_icon = val;
4283 }
4284}
4285#endif
4286
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004287#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4288 static void
4289trigger_optionsset_string(
4290 int opt_idx,
4291 int opt_flags,
4292 char_u *oldval,
4293 char_u *newval)
4294{
4295 if (oldval != NULL && newval != NULL)
4296 {
4297 char_u buf_type[7];
4298
4299 sprintf((char *)buf_type, "%s",
4300 (opt_flags & OPT_LOCAL) ? "local" : "global");
4301 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4302 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4303 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4304 apply_autocmds(EVENT_OPTIONSET,
4305 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4306 reset_v_option_vars();
4307 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004308}
4309#endif
4310
Bram Moolenaar071d4272004-06-13 20:20:40 +00004311/*
4312 * Parse 'arg' for option settings.
4313 *
4314 * 'arg' may be IObuff, but only when no errors can be present and option
4315 * does not need to be expanded with option_expand().
4316 * "opt_flags":
4317 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004318 * OPT_GLOBAL for ":setglobal"
4319 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004320 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004321 * OPT_WINONLY to only set window-local options
4322 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004323 *
4324 * returns FAIL if an error is detected, OK otherwise
4325 */
4326 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004327do_set(
4328 char_u *arg, /* option string (may be written to!) */
4329 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004330{
4331 int opt_idx;
4332 char_u *errmsg;
4333 char_u errbuf[80];
4334 char_u *startarg;
4335 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4336 int nextchar; /* next non-white char after option name */
4337 int afterchar; /* character just after option name */
4338 int len;
4339 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004340 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004341 int key;
4342 long_u flags; /* flags for current option */
4343 char_u *varp = NULL; /* pointer to variable for current option */
4344 int did_show = FALSE; /* already showed one value */
4345 int adding; /* "opt+=arg" */
4346 int prepending; /* "opt^=arg" */
4347 int removing; /* "opt-=arg" */
4348 int cp_val = 0;
4349 char_u key_name[2];
4350
4351 if (*arg == NUL)
4352 {
4353 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004354 did_show = TRUE;
4355 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004356 }
4357
4358 while (*arg != NUL) /* loop to process all options */
4359 {
4360 errmsg = NULL;
4361 startarg = arg; /* remember for error message */
4362
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004363 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4364 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004365 {
4366 /*
4367 * ":set all" show all options.
4368 * ":set all&" set all options to their default value.
4369 */
4370 arg += 3;
4371 if (*arg == '&')
4372 {
4373 ++arg;
4374 /* Only for :set command set global value of local options. */
4375 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004376 didset_options();
4377 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004378 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004379 }
4380 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004381 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004382 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004383 did_show = TRUE;
4384 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004385 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004386 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004387 {
4388 showoptions(2, opt_flags);
4389 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004390 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004391 arg += 7;
4392 }
4393 else
4394 {
4395 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004396 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004397 {
4398 prefix = 0;
4399 arg += 2;
4400 }
4401 else if (STRNCMP(arg, "inv", 3) == 0)
4402 {
4403 prefix = 2;
4404 arg += 3;
4405 }
4406
4407 /* find end of name */
4408 key = 0;
4409 if (*arg == '<')
4410 {
4411 nextchar = 0;
4412 opt_idx = -1;
4413 /* look out for <t_>;> */
4414 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4415 len = 5;
4416 else
4417 {
4418 len = 1;
4419 while (arg[len] != NUL && arg[len] != '>')
4420 ++len;
4421 }
4422 if (arg[len] != '>')
4423 {
4424 errmsg = e_invarg;
4425 goto skip;
4426 }
4427 arg[len] = NUL; /* put NUL after name */
4428 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4429 opt_idx = findoption(arg + 1);
4430 arg[len++] = '>'; /* restore '>' */
4431 if (opt_idx == -1)
4432 key = find_key_option(arg + 1);
4433 }
4434 else
4435 {
4436 len = 0;
4437 /*
4438 * The two characters after "t_" may not be alphanumeric.
4439 */
4440 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4441 len = 4;
4442 else
4443 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4444 ++len;
4445 nextchar = arg[len];
4446 arg[len] = NUL; /* put NUL after name */
4447 opt_idx = findoption(arg);
4448 arg[len] = nextchar; /* restore nextchar */
4449 if (opt_idx == -1)
4450 key = find_key_option(arg);
4451 }
4452
4453 /* remember character after option name */
4454 afterchar = arg[len];
4455
4456 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004457 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004458 ++len;
4459
4460 adding = FALSE;
4461 prepending = FALSE;
4462 removing = FALSE;
4463 if (arg[len] != NUL && arg[len + 1] == '=')
4464 {
4465 if (arg[len] == '+')
4466 {
4467 adding = TRUE; /* "+=" */
4468 ++len;
4469 }
4470 else if (arg[len] == '^')
4471 {
4472 prepending = TRUE; /* "^=" */
4473 ++len;
4474 }
4475 else if (arg[len] == '-')
4476 {
4477 removing = TRUE; /* "-=" */
4478 ++len;
4479 }
4480 }
4481 nextchar = arg[len];
4482
4483 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4484 {
4485 errmsg = (char_u *)N_("E518: Unknown option");
4486 goto skip;
4487 }
4488
4489 if (opt_idx >= 0)
4490 {
4491 if (options[opt_idx].var == NULL) /* hidden option: skip */
4492 {
4493 /* Only give an error message when requesting the value of
4494 * a hidden option, ignore setting it. */
4495 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4496 && (!(options[opt_idx].flags & P_BOOL)
4497 || nextchar == '?'))
4498 errmsg = (char_u *)N_("E519: Option not supported");
4499 goto skip;
4500 }
4501
4502 flags = options[opt_idx].flags;
4503 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4504 }
4505 else
4506 {
4507 flags = P_STRING;
4508 if (key < 0)
4509 {
4510 key_name[0] = KEY2TERMCAP0(key);
4511 key_name[1] = KEY2TERMCAP1(key);
4512 }
4513 else
4514 {
4515 key_name[0] = KS_KEY;
4516 key_name[1] = (key & 0xff);
4517 }
4518 }
4519
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004520 /* Skip all options that are not window-local (used when showing
4521 * an already loaded buffer in a window). */
4522 if ((opt_flags & OPT_WINONLY)
4523 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4524 goto skip;
4525
Bram Moolenaara3227e22006-03-08 21:32:40 +00004526 /* Skip all options that are window-local (used for :vimgrep). */
4527 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4528 && options[opt_idx].var == VAR_WIN)
4529 goto skip;
4530
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004531 /* Disallow changing some options from modelines. */
4532 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004533 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004534 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004535 {
4536 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4537 goto skip;
4538 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004539#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004540 /* In diff mode some options are overruled. This avoids that
4541 * 'foldmethod' becomes "marker" instead of "diff" and that
4542 * "wrap" gets set. */
4543 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004544 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004545 && (
4546#ifdef FEAT_FOLDING
4547 options[opt_idx].indir == PV_FDM ||
4548#endif
4549 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004550 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004551#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004552 }
4553
4554#ifdef HAVE_SANDBOX
4555 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004556 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004557 {
4558 errmsg = (char_u *)_(e_sandbox);
4559 goto skip;
4560 }
4561#endif
4562
4563 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4564 {
4565 arg += len;
4566 cp_val = p_cp;
4567 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4568 {
4569 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4570 {
4571 cp_val = FALSE;
4572 arg += 3;
4573 }
4574 else /* "opt&vi": set to Vi default */
4575 {
4576 cp_val = TRUE;
4577 arg += 2;
4578 }
4579 }
4580 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004581 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004582 {
4583 errmsg = e_trailing;
4584 goto skip;
4585 }
4586 }
4587
4588 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004589 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4590 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004591 */
4592 if (nextchar == '?'
4593 || (prefix == 1
4594 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4595 && !(flags & P_BOOL)))
4596 {
4597 /*
4598 * print value
4599 */
4600 if (did_show)
4601 msg_putchar('\n'); /* cursor below last one */
4602 else
4603 {
4604 gotocmdline(TRUE); /* cursor at status line */
4605 did_show = TRUE; /* remember that we did a line */
4606 }
4607 if (opt_idx >= 0)
4608 {
4609 showoneopt(&options[opt_idx], opt_flags);
4610#ifdef FEAT_EVAL
4611 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004612 {
4613 /* Mention where the option was last set. */
4614 if (varp == options[opt_idx].var)
4615 last_set_msg(options[opt_idx].scriptID);
4616 else if ((int)options[opt_idx].indir & PV_WIN)
4617 last_set_msg(curwin->w_p_scriptID[
4618 (int)options[opt_idx].indir & PV_MASK]);
4619 else if ((int)options[opt_idx].indir & PV_BUF)
4620 last_set_msg(curbuf->b_p_scriptID[
4621 (int)options[opt_idx].indir & PV_MASK]);
4622 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004623#endif
4624 }
4625 else
4626 {
4627 char_u *p;
4628
4629 p = find_termcode(key_name);
4630 if (p == NULL)
4631 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004632 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004633 goto skip;
4634 }
4635 else
4636 (void)show_one_termcode(key_name, p, TRUE);
4637 }
4638 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004639 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004640 errmsg = e_trailing;
4641 }
4642 else
4643 {
4644 if (flags & P_BOOL) /* boolean */
4645 {
4646 if (nextchar == '=' || nextchar == ':')
4647 {
4648 errmsg = e_invarg;
4649 goto skip;
4650 }
4651
4652 /*
4653 * ":set opt!": invert
4654 * ":set opt&": reset to default value
4655 * ":set opt<": reset to global value
4656 */
4657 if (nextchar == '!')
4658 value = *(int *)(varp) ^ 1;
4659 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004660 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004661 ((flags & P_VI_DEF) || cp_val)
4662 ? VI_DEFAULT : VIM_DEFAULT];
4663 else if (nextchar == '<')
4664 {
4665 /* For 'autoread' -1 means to use global value. */
4666 if ((int *)varp == &curbuf->b_p_ar
4667 && opt_flags == OPT_LOCAL)
4668 value = -1;
4669 else
4670 value = *(int *)get_varp_scope(&(options[opt_idx]),
4671 OPT_GLOBAL);
4672 }
4673 else
4674 {
4675 /*
4676 * ":set invopt": invert
4677 * ":set opt" or ":set noopt": set or reset
4678 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004679 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004680 {
4681 errmsg = e_trailing;
4682 goto skip;
4683 }
4684 if (prefix == 2) /* inv */
4685 value = *(int *)(varp) ^ 1;
4686 else
4687 value = prefix;
4688 }
4689
4690 errmsg = set_bool_option(opt_idx, varp, (int)value,
4691 opt_flags);
4692 }
4693 else /* numeric or string */
4694 {
4695 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4696 || prefix != 1)
4697 {
4698 errmsg = e_invarg;
4699 goto skip;
4700 }
4701
4702 if (flags & P_NUM) /* numeric */
4703 {
4704 /*
4705 * Different ways to set a number option:
4706 * & set to default value
4707 * < set to global value
4708 * <xx> accept special key codes for 'wildchar'
4709 * c accept any non-digit for 'wildchar'
4710 * [-]0-9 set number
4711 * other error
4712 */
4713 ++arg;
4714 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004715 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004716 ((flags & P_VI_DEF) || cp_val)
4717 ? VI_DEFAULT : VIM_DEFAULT];
4718 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004719 {
4720 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4721 * use the global value. */
4722 if ((long *)varp == &curbuf->b_p_ul
4723 && opt_flags == OPT_LOCAL)
4724 value = NO_LOCAL_UNDOLEVEL;
4725 else
4726 value = *(long *)get_varp_scope(
4727 &(options[opt_idx]), OPT_GLOBAL);
4728 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004729 else if (((long *)varp == &p_wc
4730 || (long *)varp == &p_wcm)
4731 && (*arg == '<'
4732 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004733 || (*arg != NUL
4734 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004735 && !VIM_ISDIGIT(*arg))))
4736 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004737 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004738 if (value == 0 && (long *)varp != &p_wcm)
4739 {
4740 errmsg = e_invarg;
4741 goto skip;
4742 }
4743 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004744 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4745 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004746 /* Allow negative (for 'undolevels'), octal and
4747 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004748 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4749 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004750 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004751 {
4752 errmsg = e_invarg;
4753 goto skip;
4754 }
4755 }
4756 else
4757 {
4758 errmsg = (char_u *)N_("E521: Number required after =");
4759 goto skip;
4760 }
4761
4762 if (adding)
4763 value = *(long *)varp + value;
4764 if (prepending)
4765 value = *(long *)varp * value;
4766 if (removing)
4767 value = *(long *)varp - value;
4768 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004769 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004770 }
4771 else if (opt_idx >= 0) /* string */
4772 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004773 char_u *save_arg = NULL;
4774 char_u *s = NULL;
4775 char_u *oldval = NULL; /* previous value if *varp */
4776 char_u *newval;
4777 char_u *origval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004778#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004779 char_u *saved_origval = NULL;
4780 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004781#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004782 unsigned newlen;
4783 int comma;
4784 int bs;
4785 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004786 was allocated */
4787
4788 /* When using ":set opt=val" for a global option
4789 * with a local value the local value will be
4790 * reset, use the global value here. */
4791 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004792 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004793 varp = options[opt_idx].var;
4794
4795 /* The old value is kept until we are sure that the
4796 * new value is valid. */
4797 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004798
4799 /* When setting the local value of a global
4800 * option, the old value may be the global value. */
4801 if (((int)options[opt_idx].indir & PV_BOTH)
4802 && (opt_flags & OPT_LOCAL))
4803 origval = *(char_u **)get_varp(
4804 &options[opt_idx]);
4805 else
4806 origval = oldval;
4807
Bram Moolenaar071d4272004-06-13 20:20:40 +00004808 if (nextchar == '&') /* set to default val */
4809 {
4810 newval = options[opt_idx].def_val[
4811 ((flags & P_VI_DEF) || cp_val)
4812 ? VI_DEFAULT : VIM_DEFAULT];
4813 if ((char_u **)varp == &p_bg)
4814 {
4815 /* guess the value of 'background' */
4816#ifdef FEAT_GUI
4817 if (gui.in_use)
4818 newval = gui_bg_default();
4819 else
4820#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004821 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004822 }
4823
4824 /* expand environment variables and ~ (since the
4825 * default value was already expanded, only
4826 * required when an environment variable was set
4827 * later */
4828 if (newval == NULL)
4829 newval = empty_option;
4830 else
4831 {
4832 s = option_expand(opt_idx, newval);
4833 if (s == NULL)
4834 s = newval;
4835 newval = vim_strsave(s);
4836 }
4837 new_value_alloced = TRUE;
4838 }
4839 else if (nextchar == '<') /* set to global val */
4840 {
4841 newval = vim_strsave(*(char_u **)get_varp_scope(
4842 &(options[opt_idx]), OPT_GLOBAL));
4843 new_value_alloced = TRUE;
4844 }
4845 else
4846 {
4847 ++arg; /* jump to after the '=' or ':' */
4848
4849 /*
4850 * Set 'keywordprg' to ":help" if an empty
4851 * value was passed to :set by the user.
4852 * Misuse errbuf[] for the resulting string.
4853 */
4854 if (varp == (char_u *)&p_kp
4855 && (*arg == NUL || *arg == ' '))
4856 {
4857 STRCPY(errbuf, ":help");
4858 save_arg = arg;
4859 arg = errbuf;
4860 }
4861 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004862 * Convert 'backspace' number to string, for
4863 * adding, prepending and removing string.
4864 */
4865 else if (varp == (char_u *)&p_bs
4866 && VIM_ISDIGIT(**(char_u **)varp))
4867 {
4868 i = getdigits((char_u **)varp);
4869 switch (i)
4870 {
4871 case 0:
4872 *(char_u **)varp = empty_option;
4873 break;
4874 case 1:
4875 *(char_u **)varp = vim_strsave(
4876 (char_u *)"indent,eol");
4877 break;
4878 case 2:
4879 *(char_u **)varp = vim_strsave(
4880 (char_u *)"indent,eol,start");
4881 break;
4882 }
4883 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004884 if (origval == oldval)
4885 origval = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004886 oldval = *(char_u **)varp;
4887 }
4888 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004889 * Convert 'whichwrap' number to string, for
4890 * backwards compatibility with Vim 3.0.
4891 * Misuse errbuf[] for the resulting string.
4892 */
4893 else if (varp == (char_u *)&p_ww
4894 && VIM_ISDIGIT(*arg))
4895 {
4896 *errbuf = NUL;
4897 i = getdigits(&arg);
4898 if (i & 1)
4899 STRCAT(errbuf, "b,");
4900 if (i & 2)
4901 STRCAT(errbuf, "s,");
4902 if (i & 4)
4903 STRCAT(errbuf, "h,l,");
4904 if (i & 8)
4905 STRCAT(errbuf, "<,>,");
4906 if (i & 16)
4907 STRCAT(errbuf, "[,],");
4908 if (*errbuf != NUL) /* remove trailing , */
4909 errbuf[STRLEN(errbuf) - 1] = NUL;
4910 save_arg = arg;
4911 arg = errbuf;
4912 }
4913 /*
4914 * Remove '>' before 'dir' and 'bdir', for
4915 * backwards compatibility with version 3.0
4916 */
4917 else if ( *arg == '>'
4918 && (varp == (char_u *)&p_dir
4919 || varp == (char_u *)&p_bdir))
4920 {
4921 ++arg;
4922 }
4923
Bram Moolenaar071d4272004-06-13 20:20:40 +00004924 /*
4925 * Copy the new string into allocated memory.
4926 * Can't use set_string_option_direct(), because
4927 * we need to remove the backslashes.
4928 */
4929 /* get a bit too much */
4930 newlen = (unsigned)STRLEN(arg) + 1;
4931 if (adding || prepending || removing)
4932 newlen += (unsigned)STRLEN(origval) + 1;
4933 newval = alloc(newlen);
4934 if (newval == NULL) /* out of mem, don't change */
4935 break;
4936 s = newval;
4937
4938 /*
4939 * Copy the string, skip over escaped chars.
4940 * For MS-DOS and WIN32 backslashes before normal
4941 * file name characters are not removed, and keep
4942 * backslash at start, for "\\machine\path", but
4943 * do remove it for "\\\\machine\\path".
4944 * The reverse is found in ExpandOldSetting().
4945 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004946 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004947 {
4948 if (*arg == '\\' && arg[1] != NUL
4949#ifdef BACKSLASH_IN_FILENAME
4950 && !((flags & P_EXPAND)
4951 && vim_isfilec(arg[1])
4952 && (arg[1] != '\\'
4953 || (s == newval
4954 && arg[2] != '\\')))
4955#endif
4956 )
4957 ++arg; /* remove backslash */
4958#ifdef FEAT_MBYTE
4959 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004960 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004961 {
4962 /* copy multibyte char */
4963 mch_memmove(s, arg, (size_t)i);
4964 arg += i;
4965 s += i;
4966 }
4967 else
4968#endif
4969 *s++ = *arg++;
4970 }
4971 *s = NUL;
4972
4973 /*
4974 * Expand environment variables and ~.
4975 * Don't do it when adding without inserting a
4976 * comma.
4977 */
4978 if (!(adding || prepending || removing)
4979 || (flags & P_COMMA))
4980 {
4981 s = option_expand(opt_idx, newval);
4982 if (s != NULL)
4983 {
4984 vim_free(newval);
4985 newlen = (unsigned)STRLEN(s) + 1;
4986 if (adding || prepending || removing)
4987 newlen += (unsigned)STRLEN(origval) + 1;
4988 newval = alloc(newlen);
4989 if (newval == NULL)
4990 break;
4991 STRCPY(newval, s);
4992 }
4993 }
4994
4995 /* locate newval[] in origval[] when removing it
4996 * and when adding to avoid duplicates */
4997 i = 0; /* init for GCC */
4998 if (removing || (flags & P_NODUP))
4999 {
5000 i = (int)STRLEN(newval);
5001 bs = 0;
5002 for (s = origval; *s; ++s)
5003 {
5004 if ((!(flags & P_COMMA)
5005 || s == origval
5006 || (s[-1] == ',' && !(bs & 1)))
5007 && STRNCMP(s, newval, i) == 0
5008 && (!(flags & P_COMMA)
5009 || s[i] == ','
5010 || s[i] == NUL))
5011 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005012 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005013 * even number of backslashes or a single
5014 * backslash preceded by a comma before it
5015 * is recognized as a separator */
5016 if ((s > origval + 1
5017 && s[-1] == '\\'
5018 && s[-2] != ',')
5019 || (s == origval + 1
5020 && s[-1] == '\\'))
5021
Bram Moolenaar071d4272004-06-13 20:20:40 +00005022 ++bs;
5023 else
5024 bs = 0;
5025 }
5026
5027 /* do not add if already there */
5028 if ((adding || prepending) && *s)
5029 {
5030 prepending = FALSE;
5031 adding = FALSE;
5032 STRCPY(newval, origval);
5033 }
5034 }
5035
5036 /* concatenate the two strings; add a ',' if
5037 * needed */
5038 if (adding || prepending)
5039 {
5040 comma = ((flags & P_COMMA) && *origval != NUL
5041 && *newval != NUL);
5042 if (adding)
5043 {
5044 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005045 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005046 if (comma && i > 1
5047 && (flags & P_ONECOMMA) == P_ONECOMMA
5048 && origval[i - 1] == ','
5049 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005050 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005051 mch_memmove(newval + i + comma, newval,
5052 STRLEN(newval) + 1);
5053 mch_memmove(newval, origval, (size_t)i);
5054 }
5055 else
5056 {
5057 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005058 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005059 }
5060 if (comma)
5061 newval[i] = ',';
5062 }
5063
5064 /* Remove newval[] from origval[]. (Note: "i" has
5065 * been set above and is used here). */
5066 if (removing)
5067 {
5068 STRCPY(newval, origval);
5069 if (*s)
5070 {
5071 /* may need to remove a comma */
5072 if (flags & P_COMMA)
5073 {
5074 if (s == origval)
5075 {
5076 /* include comma after string */
5077 if (s[i] == ',')
5078 ++i;
5079 }
5080 else
5081 {
5082 /* include comma before string */
5083 --s;
5084 ++i;
5085 }
5086 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005087 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005088 }
5089 }
5090
5091 if (flags & P_FLAGLIST)
5092 {
5093 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005094 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005095 {
5096 /* if options have P_FLAGLIST and
5097 * P_ONECOMMA such as 'whichwrap' */
5098 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005099 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005100 if (*s != ',' && *(s + 1) == ','
5101 && vim_strchr(s + 2, *s) != NULL)
5102 {
5103 /* Remove the duplicated value and
5104 * the next comma. */
5105 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005106 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005107 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005108 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005109 else
5110 {
5111 if ((!(flags & P_COMMA) || *s != ',')
5112 && vim_strchr(s + 1, *s) != NULL)
5113 {
5114 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005115 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005116 }
5117 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005118 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005119 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005120 }
5121
5122 if (save_arg != NULL) /* number for 'whichwrap' */
5123 arg = save_arg;
5124 new_value_alloced = TRUE;
5125 }
5126
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005127 /*
5128 * Set the new value.
5129 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005130 *(char_u **)(varp) = newval;
5131
Bram Moolenaar53744302015-07-17 17:38:22 +02005132#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005133 if (!starting
5134# ifdef FEAT_CRYPT
5135 && options[opt_idx].indir != PV_KEY
5136# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005137 && origval != NULL && newval != NULL)
5138 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005139 /* origval may be freed by
5140 * did_set_string_option(), make a copy. */
5141 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005142 /* newval (and varp) may become invalid if the
5143 * buffer is closed by autocommands. */
5144 saved_newval = vim_strsave(newval);
5145 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005146#endif
5147
Bram Moolenaar071d4272004-06-13 20:20:40 +00005148 /* Handle side effects, and set the global value for
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005149 * ":set" on local options. Note: when setting 'syntax'
5150 * or 'filetype' autocommands may be triggered that can
5151 * cause havoc. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005152 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5153 new_value_alloced, oldval, errbuf, opt_flags);
5154
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005155#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5156 if (errmsg == NULL)
5157 trigger_optionsset_string(opt_idx, opt_flags,
5158 saved_origval, saved_newval);
5159 vim_free(saved_origval);
5160 vim_free(saved_newval);
5161#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005162 /* If error detected, print the error message. */
5163 if (errmsg != NULL)
5164 goto skip;
5165 }
5166 else /* key code option */
5167 {
5168 char_u *p;
5169
5170 if (nextchar == '&')
5171 {
5172 if (add_termcap_entry(key_name, TRUE) == FAIL)
5173 errmsg = (char_u *)N_("E522: Not found in termcap");
5174 }
5175 else
5176 {
5177 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005178 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005179 if (*p == '\\' && p[1] != NUL)
5180 ++p;
5181 nextchar = *p;
5182 *p = NUL;
5183 add_termcode(key_name, arg, FALSE);
5184 *p = nextchar;
5185 }
5186 if (full_screen)
5187 ttest(FALSE);
5188 redraw_all_later(CLEAR);
5189 }
5190 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005191
Bram Moolenaar071d4272004-06-13 20:20:40 +00005192 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005193 did_set_option(opt_idx, opt_flags,
5194 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005195 }
5196
5197skip:
5198 /*
5199 * Advance to next argument.
5200 * - skip until a blank found, taking care of backslashes
5201 * - skip blanks
5202 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5203 */
5204 for (i = 0; i < 2 ; ++i)
5205 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005206 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005207 if (*arg++ == '\\' && *arg != NUL)
5208 ++arg;
5209 arg = skipwhite(arg);
5210 if (*arg != '=')
5211 break;
5212 }
5213 }
5214
5215 if (errmsg != NULL)
5216 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005217 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005218 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005219 if (i + (arg - startarg) < IOSIZE)
5220 {
5221 /* append the argument with the error */
5222 STRCAT(IObuff, ": ");
5223 mch_memmove(IObuff + i, startarg, (arg - startarg));
5224 IObuff[i + (arg - startarg)] = NUL;
5225 }
5226 /* make sure all characters are printable */
5227 trans_characters(IObuff, IOSIZE);
5228
5229 ++no_wait_return; /* wait_return done later */
5230 emsg(IObuff); /* show error highlighted */
5231 --no_wait_return;
5232
5233 return FAIL;
5234 }
5235
5236 arg = skipwhite(arg);
5237 }
5238
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005239theend:
5240 if (silent_mode && did_show)
5241 {
5242 /* After displaying option values in silent mode. */
5243 silent_mode = FALSE;
5244 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5245 msg_putchar('\n');
5246 cursor_on(); /* msg_start() switches it off */
5247 out_flush();
5248 silent_mode = TRUE;
5249 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5250 }
5251
Bram Moolenaar071d4272004-06-13 20:20:40 +00005252 return OK;
5253}
5254
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005255/*
5256 * Call this when an option has been given a new value through a user command.
5257 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5258 */
5259 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005260did_set_option(
5261 int opt_idx,
5262 int opt_flags, /* possibly with OPT_MODELINE */
5263 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005264{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005265 long_u *p;
5266
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005267 options[opt_idx].flags |= P_WAS_SET;
5268
5269 /* When an option is set in the sandbox, from a modeline or in secure mode
5270 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005271 * flag. */
5272 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005273 if (secure
5274#ifdef HAVE_SANDBOX
5275 || sandbox != 0
5276#endif
5277 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005278 *p = *p | P_INSECURE;
5279 else if (new_value)
5280 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005281}
5282
Bram Moolenaar071d4272004-06-13 20:20:40 +00005283 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005284illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005285{
5286 if (errbuf == NULL)
5287 return (char_u *)"";
5288 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005289 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005290 return errbuf;
5291}
5292
5293/*
5294 * Convert a key name or string into a key value.
5295 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005296 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005297 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005298 int
5299string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005300{
5301 if (*arg == '<')
5302 return find_key_option(arg + 1);
5303 if (*arg == '^')
5304 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005305 if (multi_byte)
5306 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005307 return *arg;
5308}
5309
5310#ifdef FEAT_CMDWIN
5311/*
5312 * Check value of 'cedit' and set cedit_key.
5313 * Returns NULL if value is OK, error message otherwise.
5314 */
5315 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005316check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005317{
5318 int n;
5319
5320 if (*p_cedit == NUL)
5321 cedit_key = -1;
5322 else
5323 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005324 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005325 if (vim_isprintc(n))
5326 return e_invarg;
5327 cedit_key = n;
5328 }
5329 return NULL;
5330}
5331#endif
5332
5333#ifdef FEAT_TITLE
5334/*
5335 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5336 * maketitle() to create and display it.
5337 * When switching the title or icon off, call mch_restore_title() to get
5338 * the old value back.
5339 */
5340 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005341did_set_title(
5342 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005343{
5344 if (starting != NO_SCREEN
5345#ifdef FEAT_GUI
5346 && !gui.starting
5347#endif
5348 )
5349 {
5350 maketitle();
5351 if (icon)
5352 {
5353 if (!p_icon)
5354 mch_restore_title(2);
5355 }
5356 else
5357 {
5358 if (!p_title)
5359 mch_restore_title(1);
5360 }
5361 }
5362}
5363#endif
5364
5365/*
5366 * set_options_bin - called when 'bin' changes value.
5367 */
5368 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005369set_options_bin(
5370 int oldval,
5371 int newval,
5372 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005373{
5374 /*
5375 * The option values that are changed when 'bin' changes are
5376 * copied when 'bin is set and restored when 'bin' is reset.
5377 */
5378 if (newval)
5379 {
5380 if (!oldval) /* switched on */
5381 {
5382 if (!(opt_flags & OPT_GLOBAL))
5383 {
5384 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5385 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5386 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5387 curbuf->b_p_et_nobin = curbuf->b_p_et;
5388 }
5389 if (!(opt_flags & OPT_LOCAL))
5390 {
5391 p_tw_nobin = p_tw;
5392 p_wm_nobin = p_wm;
5393 p_ml_nobin = p_ml;
5394 p_et_nobin = p_et;
5395 }
5396 }
5397
5398 if (!(opt_flags & OPT_GLOBAL))
5399 {
5400 curbuf->b_p_tw = 0; /* no automatic line wrap */
5401 curbuf->b_p_wm = 0; /* no automatic line wrap */
5402 curbuf->b_p_ml = 0; /* no modelines */
5403 curbuf->b_p_et = 0; /* no expandtab */
5404 }
5405 if (!(opt_flags & OPT_LOCAL))
5406 {
5407 p_tw = 0;
5408 p_wm = 0;
5409 p_ml = FALSE;
5410 p_et = FALSE;
5411 p_bin = TRUE; /* needed when called for the "-b" argument */
5412 }
5413 }
5414 else if (oldval) /* switched off */
5415 {
5416 if (!(opt_flags & OPT_GLOBAL))
5417 {
5418 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5419 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5420 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5421 curbuf->b_p_et = curbuf->b_p_et_nobin;
5422 }
5423 if (!(opt_flags & OPT_LOCAL))
5424 {
5425 p_tw = p_tw_nobin;
5426 p_wm = p_wm_nobin;
5427 p_ml = p_ml_nobin;
5428 p_et = p_et_nobin;
5429 }
5430 }
5431}
5432
5433#ifdef FEAT_VIMINFO
5434/*
5435 * Find the parameter represented by the given character (eg ', :, ", or /),
5436 * and return its associated value in the 'viminfo' string.
5437 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005438 * If the parameter is not specified in the string or there is no following
5439 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005440 */
5441 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005442get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005443{
5444 char_u *p;
5445
5446 p = find_viminfo_parameter(type);
5447 if (p != NULL && VIM_ISDIGIT(*p))
5448 return atoi((char *)p);
5449 return -1;
5450}
5451
5452/*
5453 * Find the parameter represented by the given character (eg ''', ':', '"', or
5454 * '/') in the 'viminfo' option and return a pointer to the string after it.
5455 * Return NULL if the parameter is not specified in the string.
5456 */
5457 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005458find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005459{
5460 char_u *p;
5461
5462 for (p = p_viminfo; *p; ++p)
5463 {
5464 if (*p == type)
5465 return p + 1;
5466 if (*p == 'n') /* 'n' is always the last one */
5467 break;
5468 p = vim_strchr(p, ','); /* skip until next ',' */
5469 if (p == NULL) /* hit the end without finding parameter */
5470 break;
5471 }
5472 return NULL;
5473}
5474#endif
5475
5476/*
5477 * Expand environment variables for some string options.
5478 * These string options cannot be indirect!
5479 * If "val" is NULL expand the current value of the option.
5480 * Return pointer to NameBuff, or NULL when not expanded.
5481 */
5482 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005483option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005484{
5485 /* if option doesn't need expansion nothing to do */
5486 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5487 return NULL;
5488
5489 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5490 * expand_env() would truncate the string. */
5491 if (val != NULL && STRLEN(val) > MAXPATHL)
5492 return NULL;
5493
5494 if (val == NULL)
5495 val = *(char_u **)options[opt_idx].var;
5496
5497 /*
5498 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5499 * Escape spaces when expanding 'tags', they are used to separate file
5500 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005501 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005502 */
5503 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005504 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005505#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005506 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5507#endif
5508 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005509 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5510 return NULL;
5511
5512 return NameBuff;
5513}
5514
5515/*
5516 * After setting various option values: recompute variables that depend on
5517 * option values.
5518 */
5519 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005520didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005521{
5522 /* initialize the table for 'iskeyword' et.al. */
5523 (void)init_chartab();
5524
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005525#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005526 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005527#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005528 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005529 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005530#ifdef FEAT_SESSION
5531 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5532 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5533#endif
5534#ifdef FEAT_FOLDING
5535 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5536#endif
5537 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005538 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005539#ifdef FEAT_VIRTUALEDIT
5540 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5541#endif
5542#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5543 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5544#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005545#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005546 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005547 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005548 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005549 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005550#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005551#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5552 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5553#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005554#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005555 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5556#endif
5557#ifdef FEAT_CMDWIN
5558 /* set cedit_key */
5559 (void)check_cedit();
5560#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005561#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005562 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005563#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005564#ifdef FEAT_LINEBREAK
5565 /* initialize the table for 'breakat'. */
5566 fill_breakat_flags();
5567#endif
5568
5569}
5570
5571/*
5572 * More side effects of setting options.
5573 */
5574 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005575didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005576{
5577 /* Initialize the highlight_attr[] table. */
5578 (void)highlight_changed();
5579
5580 /* Parse default for 'wildmode' */
5581 check_opt_wim();
5582
5583 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005584 /* Parse default for 'fillchars'. */
5585 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005586
5587#ifdef FEAT_CLIPBOARD
5588 /* Parse default for 'clipboard' */
5589 (void)check_clipboard_option();
5590#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005591}
5592
5593/*
5594 * Check for string options that are NULL (normally only termcap options).
5595 */
5596 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005597check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005598{
5599 int opt_idx;
5600
5601 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5602 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5603 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5604}
5605
5606/*
5607 * Check string options in a buffer for NULL value.
5608 */
5609 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005610check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005611{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005612 check_string_option(&buf->b_p_bh);
5613 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005614#ifdef FEAT_MBYTE
5615 check_string_option(&buf->b_p_fenc);
5616#endif
5617 check_string_option(&buf->b_p_ff);
5618#ifdef FEAT_FIND_ID
5619 check_string_option(&buf->b_p_def);
5620 check_string_option(&buf->b_p_inc);
5621# ifdef FEAT_EVAL
5622 check_string_option(&buf->b_p_inex);
5623# endif
5624#endif
5625#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5626 check_string_option(&buf->b_p_inde);
5627 check_string_option(&buf->b_p_indk);
5628#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005629#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5630 check_string_option(&buf->b_p_bexpr);
5631#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005632#if defined(FEAT_CRYPT)
5633 check_string_option(&buf->b_p_cm);
5634#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005635 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005636#if defined(FEAT_EVAL)
5637 check_string_option(&buf->b_p_fex);
5638#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005639#ifdef FEAT_CRYPT
5640 check_string_option(&buf->b_p_key);
5641#endif
5642 check_string_option(&buf->b_p_kp);
5643 check_string_option(&buf->b_p_mps);
5644 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005645 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005646 check_string_option(&buf->b_p_isk);
5647#ifdef FEAT_COMMENTS
5648 check_string_option(&buf->b_p_com);
5649#endif
5650#ifdef FEAT_FOLDING
5651 check_string_option(&buf->b_p_cms);
5652#endif
5653 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005654#ifdef FEAT_TEXTOBJ
5655 check_string_option(&buf->b_p_qe);
5656#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005657#ifdef FEAT_SYN_HL
5658 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005659 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005660#endif
5661#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005662 check_string_option(&buf->b_s.b_p_spc);
5663 check_string_option(&buf->b_s.b_p_spf);
5664 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005665#endif
5666#ifdef FEAT_SEARCHPATH
5667 check_string_option(&buf->b_p_sua);
5668#endif
5669#ifdef FEAT_CINDENT
5670 check_string_option(&buf->b_p_cink);
5671 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005672 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005673#endif
5674#ifdef FEAT_AUTOCMD
5675 check_string_option(&buf->b_p_ft);
5676#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005677#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5678 check_string_option(&buf->b_p_cinw);
5679#endif
5680#ifdef FEAT_INS_EXPAND
5681 check_string_option(&buf->b_p_cpt);
5682#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005683#ifdef FEAT_COMPL_FUNC
5684 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005685 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005686#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005687#ifdef FEAT_KEYMAP
5688 check_string_option(&buf->b_p_keymap);
5689#endif
5690#ifdef FEAT_QUICKFIX
5691 check_string_option(&buf->b_p_gp);
5692 check_string_option(&buf->b_p_mp);
5693 check_string_option(&buf->b_p_efm);
5694#endif
5695 check_string_option(&buf->b_p_ep);
5696 check_string_option(&buf->b_p_path);
5697 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005698 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005699#ifdef FEAT_INS_EXPAND
5700 check_string_option(&buf->b_p_dict);
5701 check_string_option(&buf->b_p_tsr);
5702#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005703#ifdef FEAT_LISP
5704 check_string_option(&buf->b_p_lw);
5705#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005706 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005707#ifdef FEAT_MBYTE
5708 check_string_option(&buf->b_p_menc);
5709#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005710}
5711
5712/*
5713 * Free the string allocated for an option.
5714 * Checks for the string being empty_option. This may happen if we're out of
5715 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5716 * check_options().
5717 * Does NOT check for P_ALLOCED flag!
5718 */
5719 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005720free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005721{
5722 if (p != empty_option)
5723 vim_free(p);
5724}
5725
5726 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005727clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005728{
5729 if (*pp != empty_option)
5730 vim_free(*pp);
5731 *pp = empty_option;
5732}
5733
5734 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005735check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005736{
5737 if (*pp == NULL)
5738 *pp = empty_option;
5739}
5740
5741/*
5742 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5743 */
5744 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005745set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005746{
5747 int opt_idx;
5748
5749 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5750 if (options[opt_idx].var == (char_u *)p)
5751 {
5752 options[opt_idx].flags |= P_ALLOCED;
5753 return;
5754 }
5755 return; /* cannot happen: didn't find it! */
5756}
5757
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005758#if defined(FEAT_EVAL) || defined(PROTO)
5759/*
5760 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5761 * Return FALSE when it wasn't.
5762 * Return -1 for an unknown option.
5763 */
5764 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005765was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005766{
5767 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005768 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005769
5770 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005771 {
5772 flagp = insecure_flag(idx, opt_flags);
5773 return (*flagp & P_INSECURE) != 0;
5774 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005775 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005776 return -1;
5777}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005778
5779/*
5780 * Get a pointer to the flags used for the P_INSECURE flag of option
5781 * "opt_idx". For some local options a local flags field is used.
5782 */
5783 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005784insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005785{
5786 if (opt_flags & OPT_LOCAL)
5787 switch ((int)options[opt_idx].indir)
5788 {
5789#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005790 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005791#endif
5792#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005793# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005794 case PV_FDE: return &curwin->w_p_fde_flags;
5795 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005796# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005797# ifdef FEAT_BEVAL
5798 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5799# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005800# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005801 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005802# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005803 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005804# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005805 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005806# endif
5807#endif
5808 }
5809
5810 /* Nothing special, return global flags field. */
5811 return &options[opt_idx].flags;
5812}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005813#endif
5814
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005815#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005816static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005817
5818/*
5819 * Redraw the window title and/or tab page text later.
5820 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005821static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005822{
5823 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005824 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005825}
5826#endif
5827
Bram Moolenaar071d4272004-06-13 20:20:40 +00005828/*
5829 * Set a string option to a new value (without checking the effect).
5830 * The string is copied into allocated memory.
5831 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005832 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005833 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005834 */
5835 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005836set_string_option_direct(
5837 char_u *name,
5838 int opt_idx,
5839 char_u *val,
5840 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5841 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005842{
5843 char_u *s;
5844 char_u **varp;
5845 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005846 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005847
Bram Moolenaar89d40322006-08-29 15:30:07 +00005848 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005849 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005850 idx = findoption(name);
5851 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005852 {
5853 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005854 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005855 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005856 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005857 }
5858
Bram Moolenaar89d40322006-08-29 15:30:07 +00005859 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005860 return;
5861
5862 s = vim_strsave(val);
5863 if (s != NULL)
5864 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005865 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005866 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005867 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005868 free_string_option(*varp);
5869 *varp = s;
5870
5871 /* For buffer/window local option may also set the global value. */
5872 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005873 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005874
Bram Moolenaar89d40322006-08-29 15:30:07 +00005875 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005876
5877 /* When setting both values of a global option with a local value,
5878 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005879 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005880 {
5881 free_string_option(*varp);
5882 *varp = empty_option;
5883 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005884# ifdef FEAT_EVAL
5885 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005886 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005887 set_sid == 0 ? current_SID : set_sid);
5888# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005889 }
5890}
5891
5892/*
5893 * Set global value for string option when it's a local option.
5894 */
5895 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005896set_string_option_global(
5897 int opt_idx, /* option index */
5898 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005899{
5900 char_u **p, *s;
5901
5902 /* the global value is always allocated */
5903 if (options[opt_idx].var == VAR_WIN)
5904 p = (char_u **)GLOBAL_WO(varp);
5905 else
5906 p = (char_u **)options[opt_idx].var;
5907 if (options[opt_idx].indir != PV_NONE
5908 && p != varp
5909 && (s = vim_strsave(*varp)) != NULL)
5910 {
5911 free_string_option(*p);
5912 *p = s;
5913 }
5914}
5915
5916/*
5917 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005918 *
5919 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005920 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005921 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005922set_string_option(
5923 int opt_idx,
5924 char_u *value,
5925 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005926{
5927 char_u *s;
5928 char_u **varp;
5929 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005930#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5931 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005932 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02005933#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005934 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005935
5936 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005937 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005938
5939 s = vim_strsave(value);
5940 if (s != NULL)
5941 {
5942 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5943 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005944 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005945 ? OPT_GLOBAL : OPT_LOCAL)
5946 : opt_flags);
5947 oldval = *varp;
5948 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005949
5950#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005951 if (!starting
5952# ifdef FEAT_CRYPT
5953 && options[opt_idx].indir != PV_KEY
5954# endif
5955 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005956 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005957 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005958 saved_newval = vim_strsave(s);
5959 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005960#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005961 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5962 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005963 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005964
Bram Moolenaar53744302015-07-17 17:38:22 +02005965#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005966 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005967 if (r == NULL)
5968 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005969 saved_oldval, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005970 vim_free(saved_oldval);
5971 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02005972#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005973 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005974 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005975}
5976
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005977#if defined(FEAT_KEYMAP) || defined(FEAT_AUTOCMD) || defined(FEAT_SYN_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005978/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01005979 * Return TRUE if "val" is a valid 'filetype' name.
5980 * Also used for 'syntax' and 'keymap'.
5981 */
5982 static int
5983valid_filetype(char_u *val)
5984{
5985 char_u *s;
5986
5987 for (s = val; *s != NUL; ++s)
5988 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
5989 return FALSE;
5990 return TRUE;
5991}
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005992#endif
Bram Moolenaard0b51382016-11-04 15:23:45 +01005993
5994/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00005995 * Handle string options that need some action to perform when changed.
5996 * Returns NULL for success, or an error message for an error.
5997 */
5998 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005999did_set_string_option(
6000 int opt_idx, /* index in options[] table */
6001 char_u **varp, /* pointer to the option variable */
6002 int new_value_alloced, /* new value was allocated */
6003 char_u *oldval, /* previous value of the option */
6004 char_u *errbuf, /* buffer for errors, or NULL */
6005 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006006{
6007 char_u *errmsg = NULL;
6008 char_u *s, *p;
6009 int did_chartab = FALSE;
6010 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006011 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006012#ifdef FEAT_GUI
6013 /* set when changing an option that only requires a redraw in the GUI */
6014 int redraw_gui_only = FALSE;
6015#endif
Bram Moolenaar90492982017-06-22 14:16:31 +02006016#ifdef FEAT_AUTOCMD
6017 int ft_changed = FALSE;
6018#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006019
6020 /* Get the global option to compare with, otherwise we would have to check
6021 * two values for all local options. */
6022 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6023
6024 /* Disallow changing some options from secure mode */
6025 if ((secure
6026#ifdef HAVE_SANDBOX
6027 || sandbox != 0
6028#endif
6029 ) && (options[opt_idx].flags & P_SECURE))
6030 {
6031 errmsg = e_secure;
6032 }
6033
Bram Moolenaar7554da42016-11-25 22:04:13 +01006034 /* Check for a "normal" directory or file name in some options. Disallow a
6035 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006036 * are often illegal in a file name. Be more permissive if "secure" is off.
6037 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01006038 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006039 && vim_strpbrk(*varp, (char_u *)(secure
6040 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006041 || ((options[opt_idx].flags & P_NDNAME)
6042 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006043 {
6044 errmsg = e_invarg;
6045 }
6046
Bram Moolenaar071d4272004-06-13 20:20:40 +00006047 /* 'term' */
6048 else if (varp == &T_NAME)
6049 {
6050 if (T_NAME[0] == NUL)
6051 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
6052#ifdef FEAT_GUI
6053 if (gui.in_use)
6054 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
6055 else if (term_is_gui(T_NAME))
6056 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
6057#endif
6058 else if (set_termname(T_NAME) == FAIL)
6059 errmsg = (char_u *)N_("E522: Not found in termcap");
6060 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006061 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006062 /* Screen colors may have changed. */
6063 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006064
6065 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6066 * P_ALLOCED flag on 'term'. */
6067 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006068 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006069 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006070 }
6071
6072 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006073 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006074 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006075 char_u *bkc = p_bkc;
6076 unsigned int *flags = &bkc_flags;
6077
6078 if (opt_flags & OPT_LOCAL)
6079 {
6080 bkc = curbuf->b_p_bkc;
6081 flags = &curbuf->b_bkc_flags;
6082 }
6083
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006084 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6085 /* make the local value empty: use the global value */
6086 *flags = 0;
6087 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006088 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006089 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6090 errmsg = e_invarg;
6091 if ((((int)*flags & BKC_AUTO) != 0)
6092 + (((int)*flags & BKC_YES) != 0)
6093 + (((int)*flags & BKC_NO) != 0) != 1)
6094 {
6095 /* Must have exactly one of "auto", "yes" and "no". */
6096 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6097 errmsg = e_invarg;
6098 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006099 }
6100 }
6101
6102 /* 'backupext' and 'patchmode' */
6103 else if (varp == &p_bex || varp == &p_pm)
6104 {
6105 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6106 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6107 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
6108 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006109#ifdef FEAT_LINEBREAK
6110 /* 'breakindentopt' */
6111 else if (varp == &curwin->w_p_briopt)
6112 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006113 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006114 errmsg = e_invarg;
6115 }
6116#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006117
6118 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006119 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006120 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006121 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006122 */
6123 else if ( varp == &p_isi
6124 || varp == &(curbuf->b_p_isk)
6125 || varp == &p_isp
6126 || varp == &p_isf)
6127 {
6128 if (init_chartab() == FAIL)
6129 {
6130 did_chartab = TRUE; /* need to restore it below */
6131 errmsg = e_invarg; /* error in value */
6132 }
6133 }
6134
6135 /* 'helpfile' */
6136 else if (varp == &p_hf)
6137 {
6138 /* May compute new values for $VIM and $VIMRUNTIME */
6139 if (didset_vim)
6140 {
6141 vim_setenv((char_u *)"VIM", (char_u *)"");
6142 didset_vim = FALSE;
6143 }
6144 if (didset_vimruntime)
6145 {
6146 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6147 didset_vimruntime = FALSE;
6148 }
6149 }
6150
Bram Moolenaar1a384422010-07-14 19:53:30 +02006151#ifdef FEAT_SYN_HL
6152 /* 'colorcolumn' */
6153 else if (varp == &curwin->w_p_cc)
6154 errmsg = check_colorcolumn(curwin);
6155#endif
6156
Bram Moolenaar071d4272004-06-13 20:20:40 +00006157#ifdef FEAT_MULTI_LANG
6158 /* 'helplang' */
6159 else if (varp == &p_hlg)
6160 {
6161 /* Check for "", "ab", "ab,cd", etc. */
6162 for (s = p_hlg; *s != NUL; s += 3)
6163 {
6164 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6165 {
6166 errmsg = e_invarg;
6167 break;
6168 }
6169 if (s[2] == NUL)
6170 break;
6171 }
6172 }
6173#endif
6174
6175 /* 'highlight' */
6176 else if (varp == &p_hl)
6177 {
6178 if (highlight_changed() == FAIL)
6179 errmsg = e_invarg; /* invalid flags */
6180 }
6181
6182 /* 'nrformats' */
6183 else if (gvarp == &p_nf)
6184 {
6185 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6186 errmsg = e_invarg;
6187 }
6188
6189#ifdef FEAT_SESSION
6190 /* 'sessionoptions' */
6191 else if (varp == &p_ssop)
6192 {
6193 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6194 errmsg = e_invarg;
6195 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6196 {
6197 /* Don't allow both "sesdir" and "curdir". */
6198 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6199 errmsg = e_invarg;
6200 }
6201 }
6202 /* 'viewoptions' */
6203 else if (varp == &p_vop)
6204 {
6205 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6206 errmsg = e_invarg;
6207 }
6208#endif
6209
6210 /* 'scrollopt' */
6211#ifdef FEAT_SCROLLBIND
6212 else if (varp == &p_sbo)
6213 {
6214 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6215 errmsg = e_invarg;
6216 }
6217#endif
6218
6219 /* 'ambiwidth' */
6220#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006221 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006222 {
6223 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6224 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006225 else if (set_chars_option(&p_lcs) != NULL)
6226 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006227 else if (set_chars_option(&p_fcs) != NULL)
6228 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006229 }
6230#endif
6231
6232 /* 'background' */
6233 else if (varp == &p_bg)
6234 {
6235 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6236 {
6237#ifdef FEAT_EVAL
6238 int dark = (*p_bg == 'd');
6239#endif
6240
6241 init_highlight(FALSE, FALSE);
6242
6243#ifdef FEAT_EVAL
6244 if (dark != (*p_bg == 'd')
6245 && get_var_value((char_u *)"g:colors_name") != NULL)
6246 {
6247 /* The color scheme must have set 'background' back to another
6248 * value, that's not what we want here. Disable the color
6249 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006250 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006251 free_string_option(p_bg);
6252 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6253 check_string_option(&p_bg);
6254 init_highlight(FALSE, FALSE);
6255 }
6256#endif
6257 }
6258 else
6259 errmsg = e_invarg;
6260 }
6261
6262 /* 'wildmode' */
6263 else if (varp == &p_wim)
6264 {
6265 if (check_opt_wim() == FAIL)
6266 errmsg = e_invarg;
6267 }
6268
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006269#ifdef FEAT_CMDL_COMPL
6270 /* 'wildoptions' */
6271 else if (varp == &p_wop)
6272 {
6273 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6274 errmsg = e_invarg;
6275 }
6276#endif
6277
Bram Moolenaar071d4272004-06-13 20:20:40 +00006278#ifdef FEAT_WAK
6279 /* 'winaltkeys' */
6280 else if (varp == &p_wak)
6281 {
6282 if (*p_wak == NUL
6283 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6284 errmsg = e_invarg;
6285# ifdef FEAT_MENU
6286# ifdef FEAT_GUI_MOTIF
6287 else if (gui.in_use)
6288 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6289# else
6290# ifdef FEAT_GUI_GTK
6291 else if (gui.in_use)
6292 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6293# endif
6294# endif
6295# endif
6296 }
6297#endif
6298
6299#ifdef FEAT_AUTOCMD
6300 /* 'eventignore' */
6301 else if (varp == &p_ei)
6302 {
6303 if (check_ei() == FAIL)
6304 errmsg = e_invarg;
6305 }
6306#endif
6307
6308#ifdef FEAT_MBYTE
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006309 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6310 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6311 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006312 {
6313 if (gvarp == &p_fenc)
6314 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006315 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006316 errmsg = e_modifiable;
6317 else if (vim_strchr(*varp, ',') != NULL)
6318 /* No comma allowed in 'fileencoding'; catches confusing it
6319 * with 'fileencodings'. */
6320 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006321 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006322 {
6323# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006324 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006325 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006326# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006327 /* Add 'fileencoding' to the swap file. */
6328 ml_setflags(curbuf);
6329 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006330 }
6331 if (errmsg == NULL)
6332 {
6333 /* canonize the value, so that STRCMP() can be used on it */
6334 p = enc_canonize(*varp);
6335 if (p != NULL)
6336 {
6337 vim_free(*varp);
6338 *varp = p;
6339 }
6340 if (varp == &p_enc)
6341 {
6342 errmsg = mb_init();
6343# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006344 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006345# endif
6346 }
6347 }
6348
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006349# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006350 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6351 {
6352 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6353 if (STRCMP(p_tenc, "utf-8") != 0)
6354 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6355 }
6356# endif
6357
6358 if (errmsg == NULL)
6359 {
6360# ifdef FEAT_KEYMAP
6361 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6362 * (with another encoding). */
6363 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6364 (void)keymap_init();
6365# endif
6366
6367 /* When 'termencoding' is not empty and 'encoding' changes or when
6368 * 'termencoding' changes, need to setup for keyboard input and
6369 * display output conversion. */
6370 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6371 {
Bram Moolenaar17471e82017-11-26 23:47:18 +01006372 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6373 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6374 {
6375 EMSG3(_("E950: Cannot convert between %s and %s"),
6376 p_tenc, p_enc);
6377 errmsg = e_invarg;
6378 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006379 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006380
6381# if defined(WIN3264) && defined(FEAT_MBYTE)
6382 /* $HOME may have characters in active code page. */
6383 if (varp == &p_enc)
6384 init_homedir();
6385# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006386 }
6387 }
6388#endif
6389
6390#if defined(FEAT_POSTSCRIPT)
6391 else if (varp == &p_penc)
6392 {
6393 /* Canonize printencoding if VIM standard one */
6394 p = enc_canonize(p_penc);
6395 if (p != NULL)
6396 {
6397 vim_free(p_penc);
6398 p_penc = p;
6399 }
6400 else
6401 {
6402 /* Ensure lower case and '-' for '_' */
6403 for (s = p_penc; *s != NUL; s++)
6404 {
6405 if (*s == '_')
6406 *s = '-';
6407 else
6408 *s = TOLOWER_ASC(*s);
6409 }
6410 }
6411 }
6412#endif
6413
Bram Moolenaar9372a112005-12-06 19:59:18 +00006414#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006415 else if (varp == &p_imak)
6416 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006417 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006418 errmsg = e_invarg;
6419 }
6420#endif
6421
6422#ifdef FEAT_KEYMAP
6423 else if (varp == &curbuf->b_p_keymap)
6424 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006425 if (!valid_filetype(*varp))
6426 errmsg = e_invarg;
6427 else
6428 /* load or unload key mapping tables */
6429 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006430
Bram Moolenaarfab06232009-03-04 03:13:35 +00006431 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006432 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006433 if (*curbuf->b_p_keymap != NUL)
6434 {
6435 /* Installed a new keymap, switch on using it. */
6436 curbuf->b_p_iminsert = B_IMODE_LMAP;
6437 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6438 curbuf->b_p_imsearch = B_IMODE_LMAP;
6439 }
6440 else
6441 {
6442 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6443 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6444 curbuf->b_p_iminsert = B_IMODE_NONE;
6445 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6446 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6447 }
6448 if ((opt_flags & OPT_LOCAL) == 0)
6449 {
6450 set_iminsert_global();
6451 set_imsearch_global();
6452 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006453 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006454 }
6455 }
6456#endif
6457
6458 /* 'fileformat' */
6459 else if (gvarp == &p_ff)
6460 {
6461 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6462 errmsg = e_modifiable;
6463 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6464 errmsg = e_invarg;
6465 else
6466 {
6467 /* may also change 'textmode' */
6468 if (get_fileformat(curbuf) == EOL_DOS)
6469 curbuf->b_p_tx = TRUE;
6470 else
6471 curbuf->b_p_tx = FALSE;
6472#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006473 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006474#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006475 /* update flag in swap file */
6476 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006477 /* Redraw needed when switching to/from "mac": a CR in the text
6478 * will be displayed differently. */
6479 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6480 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006481 }
6482 }
6483
6484 /* 'fileformats' */
6485 else if (varp == &p_ffs)
6486 {
6487 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6488 errmsg = e_invarg;
6489 else
6490 {
6491 /* also change 'textauto' */
6492 if (*p_ffs == NUL)
6493 p_ta = FALSE;
6494 else
6495 p_ta = TRUE;
6496 }
6497 }
6498
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006499#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006500 /* 'cryptkey' */
6501 else if (gvarp == &p_key)
6502 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006503# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006504 /* Make sure the ":set" command doesn't show the new value in the
6505 * history. */
6506 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006507# endif
6508 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6509 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006510 ml_set_crypt_key(curbuf, oldval,
6511 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006512 }
6513
6514 else if (gvarp == &p_cm)
6515 {
6516 if (opt_flags & OPT_LOCAL)
6517 p = curbuf->b_p_cm;
6518 else
6519 p = p_cm;
6520 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6521 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006522 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006523 errmsg = e_invarg;
6524 else
6525 {
6526 /* When setting the global value to empty, make it "zip". */
6527 if (*p_cm == NUL)
6528 {
6529 if (new_value_alloced)
6530 free_string_option(p_cm);
6531 p_cm = vim_strsave((char_u *)"zip");
6532 new_value_alloced = TRUE;
6533 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006534 /* When using ":set cm=name" the local value is going to be empty.
6535 * Do that here, otherwise the crypt functions will still use the
6536 * local value. */
6537 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6538 {
6539 free_string_option(curbuf->b_p_cm);
6540 curbuf->b_p_cm = empty_option;
6541 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006542
6543 /* Need to update the swapfile when the effective method changed.
6544 * Set "s" to the effective old value, "p" to the effective new
6545 * method and compare. */
6546 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6547 s = p_cm; /* was previously using the global value */
6548 else
6549 s = oldval;
6550 if (*curbuf->b_p_cm == NUL)
6551 p = p_cm; /* is now using the global value */
6552 else
6553 p = curbuf->b_p_cm;
6554 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006555 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006556
6557 /* If the global value changes need to update the swapfile for all
6558 * buffers using that value. */
6559 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6560 {
6561 buf_T *buf;
6562
Bram Moolenaar29323592016-07-24 22:04:11 +02006563 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006564 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006565 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006566 }
6567 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006568 }
6569#endif
6570
6571 /* 'matchpairs' */
6572 else if (gvarp == &p_mps)
6573 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006574#ifdef FEAT_MBYTE
6575 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006576 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006577 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006578 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006579 int x2 = -1;
6580 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006581
6582 if (*p != NUL)
6583 p += mb_ptr2len(p);
6584 if (*p != NUL)
6585 x2 = *p++;
6586 if (*p != NUL)
6587 {
6588 x3 = mb_ptr2char(p);
6589 p += mb_ptr2len(p);
6590 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006591 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006592 {
6593 errmsg = e_invarg;
6594 break;
6595 }
6596 if (*p == NUL)
6597 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006598 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006599 }
6600 else
6601#endif
6602 {
6603 /* Check for "x:y,x:y" */
6604 for (p = *varp; *p != NUL; p += 4)
6605 {
6606 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6607 {
6608 errmsg = e_invarg;
6609 break;
6610 }
6611 if (p[3] == NUL)
6612 break;
6613 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006614 }
6615 }
6616
6617#ifdef FEAT_COMMENTS
6618 /* 'comments' */
6619 else if (gvarp == &p_com)
6620 {
6621 for (s = *varp; *s; )
6622 {
6623 while (*s && *s != ':')
6624 {
6625 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6626 && !VIM_ISDIGIT(*s) && *s != '-')
6627 {
6628 errmsg = illegal_char(errbuf, *s);
6629 break;
6630 }
6631 ++s;
6632 }
6633 if (*s++ == NUL)
6634 errmsg = (char_u *)N_("E524: Missing colon");
6635 else if (*s == ',' || *s == NUL)
6636 errmsg = (char_u *)N_("E525: Zero length string");
6637 if (errmsg != NULL)
6638 break;
6639 while (*s && *s != ',')
6640 {
6641 if (*s == '\\' && s[1] != NUL)
6642 ++s;
6643 ++s;
6644 }
6645 s = skip_to_option_part(s);
6646 }
6647 }
6648#endif
6649
6650 /* 'listchars' */
6651 else if (varp == &p_lcs)
6652 {
6653 errmsg = set_chars_option(varp);
6654 }
6655
Bram Moolenaar071d4272004-06-13 20:20:40 +00006656 /* 'fillchars' */
6657 else if (varp == &p_fcs)
6658 {
6659 errmsg = set_chars_option(varp);
6660 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006661
6662#ifdef FEAT_CMDWIN
6663 /* 'cedit' */
6664 else if (varp == &p_cedit)
6665 {
6666 errmsg = check_cedit();
6667 }
6668#endif
6669
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006670 /* 'verbosefile' */
6671 else if (varp == &p_vfile)
6672 {
6673 verbose_stop();
6674 if (*p_vfile != NUL && verbose_open() == FAIL)
6675 errmsg = e_invarg;
6676 }
6677
Bram Moolenaar071d4272004-06-13 20:20:40 +00006678#ifdef FEAT_VIMINFO
6679 /* 'viminfo' */
6680 else if (varp == &p_viminfo)
6681 {
6682 for (s = p_viminfo; *s;)
6683 {
6684 /* Check it's a valid character */
6685 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6686 {
6687 errmsg = illegal_char(errbuf, *s);
6688 break;
6689 }
6690 if (*s == 'n') /* name is always last one */
6691 {
6692 break;
6693 }
6694 else if (*s == 'r') /* skip until next ',' */
6695 {
6696 while (*++s && *s != ',')
6697 ;
6698 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006699 else if (*s == '%')
6700 {
6701 /* optional number */
6702 while (vim_isdigit(*++s))
6703 ;
6704 }
6705 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006706 ++s; /* no extra chars */
6707 else /* must have a number */
6708 {
6709 while (vim_isdigit(*++s))
6710 ;
6711
6712 if (!VIM_ISDIGIT(*(s - 1)))
6713 {
6714 if (errbuf != NULL)
6715 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006716 sprintf((char *)errbuf,
6717 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006718 transchar_byte(*(s - 1)));
6719 errmsg = errbuf;
6720 }
6721 else
6722 errmsg = (char_u *)"";
6723 break;
6724 }
6725 }
6726 if (*s == ',')
6727 ++s;
6728 else if (*s)
6729 {
6730 if (errbuf != NULL)
6731 errmsg = (char_u *)N_("E527: Missing comma");
6732 else
6733 errmsg = (char_u *)"";
6734 break;
6735 }
6736 }
6737 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6738 errmsg = (char_u *)N_("E528: Must specify a ' value");
6739 }
6740#endif /* FEAT_VIMINFO */
6741
6742 /* terminal options */
6743 else if (istermoption(&options[opt_idx]) && full_screen)
6744 {
6745 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6746 if (varp == &T_CCO)
6747 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006748 int colors = atoi((char *)T_CCO);
6749
6750 /* Only reinitialize colors if t_Co value has really changed to
6751 * avoid expensive reload of colorscheme if t_Co is set to the
6752 * same value multiple times. */
6753 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006754 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006755 t_colors = colors;
6756 if (t_colors <= 1)
6757 {
6758 if (new_value_alloced)
6759 vim_free(T_CCO);
6760 T_CCO = empty_option;
6761 }
6762 /* We now have a different color setup, initialize it again. */
6763 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006764 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006765 }
6766 ttest(FALSE);
6767 if (varp == &T_ME)
6768 {
6769 out_str(T_ME);
6770 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006771#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006772 /* Since t_me has been set, this probably means that the user
6773 * wants to use this as default colors. Need to reset default
6774 * background/foreground colors. */
6775 mch_set_normal_colors();
6776#endif
6777 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006778 if (varp == &T_BE && termcap_active)
6779 {
6780 if (*T_BE == NUL)
6781 /* When clearing t_BE we assume the user no longer wants
6782 * bracketed paste, thus disable it by writing t_BD. */
6783 out_str(T_BD);
6784 else
6785 out_str(T_BE);
6786 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006787 }
6788
6789#ifdef FEAT_LINEBREAK
6790 /* 'showbreak' */
6791 else if (varp == &p_sbr)
6792 {
6793 for (s = p_sbr; *s; )
6794 {
6795 if (ptr2cells(s) != 1)
6796 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006797 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006798 }
6799 }
6800#endif
6801
6802#ifdef FEAT_GUI
6803 /* 'guifont' */
6804 else if (varp == &p_guifont)
6805 {
6806 if (gui.in_use)
6807 {
6808 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006809# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006810 /*
6811 * Put up a font dialog and let the user select a new value.
6812 * If this is cancelled go back to the old value but don't
6813 * give an error message.
6814 */
6815 if (STRCMP(p, "*") == 0)
6816 {
6817 p = gui_mch_font_dialog(oldval);
6818
6819 if (new_value_alloced)
6820 free_string_option(p_guifont);
6821
6822 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6823 new_value_alloced = TRUE;
6824 }
6825# endif
6826 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6827 {
6828# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6829 if (STRCMP(p_guifont, "*") == 0)
6830 {
6831 /* Dialog was cancelled: Keep the old value without giving
6832 * an error message. */
6833 if (new_value_alloced)
6834 free_string_option(p_guifont);
6835 p_guifont = vim_strsave(oldval);
6836 new_value_alloced = TRUE;
6837 }
6838 else
6839# endif
6840 errmsg = (char_u *)N_("E596: Invalid font(s)");
6841 }
6842 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006843 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006844 }
6845# ifdef FEAT_XFONTSET
6846 else if (varp == &p_guifontset)
6847 {
6848 if (STRCMP(p_guifontset, "*") == 0)
6849 errmsg = (char_u *)N_("E597: can't select fontset");
6850 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6851 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006852 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006853 }
6854# endif
6855# ifdef FEAT_MBYTE
6856 else if (varp == &p_guifontwide)
6857 {
6858 if (STRCMP(p_guifontwide, "*") == 0)
6859 errmsg = (char_u *)N_("E533: can't select wide font");
6860 else if (gui_get_wide_font() == FAIL)
6861 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006862 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006863 }
6864# endif
6865#endif
6866
6867#ifdef CURSOR_SHAPE
6868 /* 'guicursor' */
6869 else if (varp == &p_guicursor)
6870 errmsg = parse_shape_opt(SHAPE_CURSOR);
6871#endif
6872
6873#ifdef FEAT_MOUSESHAPE
6874 /* 'mouseshape' */
6875 else if (varp == &p_mouseshape)
6876 {
6877 errmsg = parse_shape_opt(SHAPE_MOUSE);
6878 update_mouseshape(-1);
6879 }
6880#endif
6881
6882#ifdef FEAT_PRINTER
6883 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006884 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006885# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006886 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006887 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006888# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006889#endif
6890
6891#ifdef FEAT_LANGMAP
6892 /* 'langmap' */
6893 else if (varp == &p_langmap)
6894 langmap_set();
6895#endif
6896
6897#ifdef FEAT_LINEBREAK
6898 /* 'breakat' */
6899 else if (varp == &p_breakat)
6900 fill_breakat_flags();
6901#endif
6902
6903#ifdef FEAT_TITLE
6904 /* 'titlestring' and 'iconstring' */
6905 else if (varp == &p_titlestring || varp == &p_iconstring)
6906 {
6907# ifdef FEAT_STL_OPT
6908 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6909
6910 /* NULL => statusline syntax */
6911 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6912 stl_syntax |= flagval;
6913 else
6914 stl_syntax &= ~flagval;
6915# endif
6916 did_set_title(varp == &p_iconstring);
6917
6918 }
6919#endif
6920
6921#ifdef FEAT_GUI
6922 /* 'guioptions' */
6923 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006924 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006925 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006926 redraw_gui_only = TRUE;
6927 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006928#endif
6929
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006930#if defined(FEAT_GUI_TABLINE)
6931 /* 'guitablabel' */
6932 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006933 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006934 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006935 redraw_gui_only = TRUE;
6936 }
6937 /* 'guitabtooltip' */
6938 else if (varp == &p_gtt)
6939 {
6940 redraw_gui_only = TRUE;
6941 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006942#endif
6943
Bram Moolenaar071d4272004-06-13 20:20:40 +00006944#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6945 /* 'ttymouse' */
6946 else if (varp == &p_ttym)
6947 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006948 /* Switch the mouse off before changing the escape sequences used for
6949 * that. */
6950 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006951 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6952 errmsg = e_invarg;
6953 else
6954 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006955 if (termcap_active)
6956 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006957 }
6958#endif
6959
Bram Moolenaar071d4272004-06-13 20:20:40 +00006960 /* 'selection' */
6961 else if (varp == &p_sel)
6962 {
6963 if (*p_sel == NUL
6964 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6965 errmsg = e_invarg;
6966 }
6967
6968 /* 'selectmode' */
6969 else if (varp == &p_slm)
6970 {
6971 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6972 errmsg = e_invarg;
6973 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006974
6975#ifdef FEAT_BROWSE
6976 /* 'browsedir' */
6977 else if (varp == &p_bsdir)
6978 {
6979 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6980 && !mch_isdir(p_bsdir))
6981 errmsg = e_invarg;
6982 }
6983#endif
6984
Bram Moolenaar071d4272004-06-13 20:20:40 +00006985 /* 'keymodel' */
6986 else if (varp == &p_km)
6987 {
6988 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6989 errmsg = e_invarg;
6990 else
6991 {
6992 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6993 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6994 }
6995 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006996
6997 /* 'mousemodel' */
6998 else if (varp == &p_mousem)
6999 {
7000 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7001 errmsg = e_invarg;
7002#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7003 else if (*p_mousem != *oldval)
7004 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7005 * to create or delete the popup menus. */
7006 gui_motif_update_mousemodel(root_menu);
7007#endif
7008 }
7009
7010 /* 'switchbuf' */
7011 else if (varp == &p_swb)
7012 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007013 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007014 errmsg = e_invarg;
7015 }
7016
7017 /* 'debug' */
7018 else if (varp == &p_debug)
7019 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007020 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007021 errmsg = e_invarg;
7022 }
7023
7024 /* 'display' */
7025 else if (varp == &p_dy)
7026 {
7027 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7028 errmsg = e_invarg;
7029 else
7030 (void)init_chartab();
7031
7032 }
7033
Bram Moolenaar071d4272004-06-13 20:20:40 +00007034 /* 'eadirection' */
7035 else if (varp == &p_ead)
7036 {
7037 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7038 errmsg = e_invarg;
7039 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007040
7041#ifdef FEAT_CLIPBOARD
7042 /* 'clipboard' */
7043 else if (varp == &p_cb)
7044 errmsg = check_clipboard_option();
7045#endif
7046
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007047#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007048 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7049 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007050 else if (varp == &(curwin->w_s->b_p_spl)
7051 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007052 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007053 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007054 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007055 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007056 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007057 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007058 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007059 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007060 /* 'spellsuggest' */
7061 else if (varp == &p_sps)
7062 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007063 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007064 errmsg = e_invarg;
7065 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007066 /* 'mkspellmem' */
7067 else if (varp == &p_msm)
7068 {
7069 if (spell_check_msm() != OK)
7070 errmsg = e_invarg;
7071 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007072#endif
7073
Bram Moolenaar071d4272004-06-13 20:20:40 +00007074 /* When 'bufhidden' is set, check for valid value. */
7075 else if (gvarp == &p_bh)
7076 {
7077 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7078 errmsg = e_invarg;
7079 }
7080
7081 /* When 'buftype' is set, check for valid value. */
7082 else if (gvarp == &p_bt)
7083 {
7084 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7085 errmsg = e_invarg;
7086 else
7087 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007088 if (curwin->w_status_height)
7089 {
7090 curwin->w_redr_status = TRUE;
7091 redraw_later(VALID);
7092 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007093 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007094#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007095 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007096#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007097 }
7098 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007099
7100#ifdef FEAT_STL_OPT
7101 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007102 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007103 {
7104 int wid;
7105
7106 if (varp == &p_ruf) /* reset ru_wid first */
7107 ru_wid = 0;
7108 s = *varp;
7109 if (varp == &p_ruf && *s == '%')
7110 {
7111 /* set ru_wid if 'ruf' starts with "%99(" */
7112 if (*++s == '-') /* ignore a '-' */
7113 s++;
7114 wid = getdigits(&s);
7115 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7116 ru_wid = wid;
7117 else
7118 errmsg = check_stl_option(p_ruf);
7119 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007120 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007121 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007122 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007123 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007124 comp_col();
7125 }
7126#endif
7127
7128#ifdef FEAT_INS_EXPAND
7129 /* check if it is a valid value for 'complete' -- Acevedo */
7130 else if (gvarp == &p_cpt)
7131 {
7132 for (s = *varp; *s;)
7133 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007134 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007135 s++;
7136 if (!*s)
7137 break;
7138 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7139 {
7140 errmsg = illegal_char(errbuf, *s);
7141 break;
7142 }
7143 if (*++s != NUL && *s != ',' && *s != ' ')
7144 {
7145 if (s[-1] == 'k' || s[-1] == 's')
7146 {
7147 /* skip optional filename after 'k' and 's' */
7148 while (*s && *s != ',' && *s != ' ')
7149 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007150 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007151 ++s;
7152 ++s;
7153 }
7154 }
7155 else
7156 {
7157 if (errbuf != NULL)
7158 {
7159 sprintf((char *)errbuf,
7160 _("E535: Illegal character after <%c>"),
7161 *--s);
7162 errmsg = errbuf;
7163 }
7164 else
7165 errmsg = (char_u *)"";
7166 break;
7167 }
7168 }
7169 }
7170 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007171
7172 /* 'completeopt' */
7173 else if (varp == &p_cot)
7174 {
7175 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7176 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007177 else
7178 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007179 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007180#endif /* FEAT_INS_EXPAND */
7181
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007182#ifdef FEAT_SIGNS
7183 /* 'signcolumn' */
7184 else if (varp == &curwin->w_p_scl)
7185 {
7186 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7187 errmsg = e_invarg;
7188 }
7189#endif
7190
Bram Moolenaar071d4272004-06-13 20:20:40 +00007191
7192#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007193 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007194 else if (varp == &p_toolbar)
7195 {
7196 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7197 &toolbar_flags, TRUE) != OK)
7198 errmsg = e_invarg;
7199 else
7200 {
7201 out_flush();
7202 gui_mch_show_toolbar((toolbar_flags &
7203 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7204 }
7205 }
7206#endif
7207
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007208#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007209 /* 'toolbariconsize': GTK+ 2 only */
7210 else if (varp == &p_tbis)
7211 {
7212 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7213 errmsg = e_invarg;
7214 else
7215 {
7216 out_flush();
7217 gui_mch_show_toolbar((toolbar_flags &
7218 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7219 }
7220 }
7221#endif
7222
7223 /* 'pastetoggle': translate key codes like in a mapping */
7224 else if (varp == &p_pt)
7225 {
7226 if (*p_pt)
7227 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007228 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007229 if (p != NULL)
7230 {
7231 if (new_value_alloced)
7232 free_string_option(p_pt);
7233 p_pt = p;
7234 new_value_alloced = TRUE;
7235 }
7236 }
7237 }
7238
7239 /* 'backspace' */
7240 else if (varp == &p_bs)
7241 {
7242 if (VIM_ISDIGIT(*p_bs))
7243 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007244 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007245 errmsg = e_invarg;
7246 }
7247 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7248 errmsg = e_invarg;
7249 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007250 else if (varp == &p_bo)
7251 {
7252 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7253 errmsg = e_invarg;
7254 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007255
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007256 /* 'tagcase' */
7257 else if (gvarp == &p_tc)
7258 {
7259 unsigned int *flags;
7260
7261 if (opt_flags & OPT_LOCAL)
7262 {
7263 p = curbuf->b_p_tc;
7264 flags = &curbuf->b_tc_flags;
7265 }
7266 else
7267 {
7268 p = p_tc;
7269 flags = &tc_flags;
7270 }
7271
7272 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7273 /* make the local value empty: use the global value */
7274 *flags = 0;
7275 else if (*p == NUL
7276 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7277 errmsg = e_invarg;
7278 }
7279
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007280#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007281 /* 'casemap' */
7282 else if (varp == &p_cmp)
7283 {
7284 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7285 errmsg = e_invarg;
7286 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007287#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007288
7289#ifdef FEAT_DIFF
7290 /* 'diffopt' */
7291 else if (varp == &p_dip)
7292 {
7293 if (diffopt_changed() == FAIL)
7294 errmsg = e_invarg;
7295 }
7296#endif
7297
7298#ifdef FEAT_FOLDING
7299 /* 'foldmethod' */
7300 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7301 {
7302 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7303 || *curwin->w_p_fdm == NUL)
7304 errmsg = e_invarg;
7305 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007306 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007307 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007308 if (foldmethodIsDiff(curwin))
7309 newFoldLevel();
7310 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007311 }
7312# ifdef FEAT_EVAL
7313 /* 'foldexpr' */
7314 else if (varp == &curwin->w_p_fde)
7315 {
7316 if (foldmethodIsExpr(curwin))
7317 foldUpdateAll(curwin);
7318 }
7319# endif
7320 /* 'foldmarker' */
7321 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7322 {
7323 p = vim_strchr(*varp, ',');
7324 if (p == NULL)
7325 errmsg = (char_u *)N_("E536: comma required");
7326 else if (p == *varp || p[1] == NUL)
7327 errmsg = e_invarg;
7328 else if (foldmethodIsMarker(curwin))
7329 foldUpdateAll(curwin);
7330 }
7331 /* 'commentstring' */
7332 else if (gvarp == &p_cms)
7333 {
7334 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7335 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7336 }
7337 /* 'foldopen' */
7338 else if (varp == &p_fdo)
7339 {
7340 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7341 errmsg = e_invarg;
7342 }
7343 /* 'foldclose' */
7344 else if (varp == &p_fcl)
7345 {
7346 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7347 errmsg = e_invarg;
7348 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007349 /* 'foldignore' */
7350 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7351 {
7352 if (foldmethodIsIndent(curwin))
7353 foldUpdateAll(curwin);
7354 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007355#endif
7356
7357#ifdef FEAT_VIRTUALEDIT
7358 /* 'virtualedit' */
7359 else if (varp == &p_ve)
7360 {
7361 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7362 errmsg = e_invarg;
7363 else if (STRCMP(p_ve, oldval) != 0)
7364 {
7365 /* Recompute cursor position in case the new 've' setting
7366 * changes something. */
7367 validate_virtcol();
7368 coladvance(curwin->w_virtcol);
7369 }
7370 }
7371#endif
7372
7373#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7374 else if (varp == &p_csqf)
7375 {
7376 if (p_csqf != NULL)
7377 {
7378 p = p_csqf;
7379 while (*p != NUL)
7380 {
7381 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7382 || p[1] == NUL
7383 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7384 || (p[2] != NUL && p[2] != ','))
7385 {
7386 errmsg = e_invarg;
7387 break;
7388 }
7389 else if (p[2] == NUL)
7390 break;
7391 else
7392 p += 3;
7393 }
7394 }
7395 }
7396#endif
7397
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007398#ifdef FEAT_CINDENT
7399 /* 'cinoptions' */
7400 else if (gvarp == &p_cino)
7401 {
7402 /* TODO: recognize errors */
7403 parse_cino(curbuf);
7404 }
7405#endif
7406
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007407#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007408 /* 'renderoptions' */
Bram Moolenaar3767c6e2017-12-05 16:57:56 +01007409 else if (varp == &p_rop)
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007410 {
7411 if (!gui_mch_set_rendering_options(p_rop))
7412 errmsg = e_invarg;
7413 }
7414#endif
7415
Bram Moolenaard0b51382016-11-04 15:23:45 +01007416#ifdef FEAT_AUTOCMD
7417 else if (gvarp == &p_ft)
7418 {
7419 if (!valid_filetype(*varp))
7420 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007421 else
7422 ft_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaard0b51382016-11-04 15:23:45 +01007423 }
7424#endif
7425
7426#ifdef FEAT_SYN_HL
7427 else if (gvarp == &p_syn)
7428 {
7429 if (!valid_filetype(*varp))
7430 errmsg = e_invarg;
7431 }
7432#endif
7433
Bram Moolenaar825680f2017-07-22 17:04:02 +02007434#ifdef FEAT_TERMINAL
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007435 /* 'termkey' */
Bram Moolenaarc4f43bc2017-07-24 20:03:01 +02007436 else if (varp == &curwin->w_p_tk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007437 {
7438 if (*curwin->w_p_tk != NUL && string_to_key(curwin->w_p_tk, TRUE) == 0)
7439 errmsg = e_invarg;
7440 }
Bram Moolenaar825680f2017-07-22 17:04:02 +02007441 /* 'termsize' */
7442 else if (varp == &curwin->w_p_tms)
7443 {
7444 if (*curwin->w_p_tms != NUL)
7445 {
7446 p = skipdigits(curwin->w_p_tms);
7447 if (p == curwin->w_p_tms || *p != 'x' || *skipdigits(p + 1) != NUL)
7448 errmsg = e_invarg;
7449 }
7450 }
7451#endif
7452
Bram Moolenaar071d4272004-06-13 20:20:40 +00007453 /* Options that are a list of flags. */
7454 else
7455 {
7456 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007457 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007458 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007459 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007460 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007461 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007462 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007463 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007464 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007465#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007466 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007467 p = (char_u *)COCU_ALL;
7468#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007469 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007470 {
7471#ifdef FEAT_MOUSE
7472 p = (char_u *)MOUSE_ALL;
7473#else
7474 if (*p_mouse != NUL)
7475 errmsg = (char_u *)N_("E538: No mouse support");
7476#endif
7477 }
7478#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007479 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007480 p = (char_u *)GO_ALL;
7481#endif
7482 if (p != NULL)
7483 {
7484 for (s = *varp; *s; ++s)
7485 if (vim_strchr(p, *s) == NULL)
7486 {
7487 errmsg = illegal_char(errbuf, *s);
7488 break;
7489 }
7490 }
7491 }
7492
7493 /*
7494 * If error detected, restore the previous value.
7495 */
7496 if (errmsg != NULL)
7497 {
7498 if (new_value_alloced)
7499 free_string_option(*varp);
7500 *varp = oldval;
7501 /*
7502 * When resetting some values, need to act on it.
7503 */
7504 if (did_chartab)
7505 (void)init_chartab();
7506 if (varp == &p_hl)
7507 (void)highlight_changed();
7508 }
7509 else
7510 {
7511#ifdef FEAT_EVAL
7512 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007513 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007514#endif
7515 /*
7516 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007517 * Use "free_oldval", because recursiveness may change the flags under
7518 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007519 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007520 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007521 free_string_option(oldval);
7522 if (new_value_alloced)
7523 options[opt_idx].flags |= P_ALLOCED;
7524 else
7525 options[opt_idx].flags &= ~P_ALLOCED;
7526
7527 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007528 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007529 {
7530 /* global option with local value set to use global value; free
7531 * the local value and make it empty */
7532 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7533 free_string_option(*(char_u **)p);
7534 *(char_u **)p = empty_option;
7535 }
7536
7537 /* May set global value for local option. */
7538 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7539 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007540
7541#ifdef FEAT_AUTOCMD
7542 /*
7543 * Trigger the autocommand only after setting the flags.
7544 */
7545# ifdef FEAT_SYN_HL
7546 /* When 'syntax' is set, load the syntax of that name */
7547 if (varp == &(curbuf->b_p_syn))
7548 {
7549 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7550 curbuf->b_fname, TRUE, curbuf);
7551 }
7552# endif
7553 else if (varp == &(curbuf->b_p_ft))
7554 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007555 /* 'filetype' is set, trigger the FileType autocommand.
7556 * Skip this when called from a modeline and the filetype was
7557 * already set to this value. */
7558 if (!(opt_flags & OPT_MODELINE) || ft_changed)
7559 {
7560 did_filetype = TRUE;
7561 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007562 curbuf->b_fname, TRUE, curbuf);
Bram Moolenaar163095f2017-07-09 15:41:53 +02007563 /* Just in case the old "curbuf" is now invalid. */
7564 if (varp != &(curbuf->b_p_ft))
7565 varp = NULL;
Bram Moolenaar90492982017-06-22 14:16:31 +02007566 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007567 }
7568#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007569#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007570 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007571 {
7572 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007573 char_u *q = curwin->w_s->b_p_spl;
7574
7575 /* Skip the first name if it is "cjk". */
7576 if (STRNCMP(q, "cjk,", 4) == 0)
7577 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007578
7579 /*
7580 * Source the spell/LANG.vim in 'runtimepath'.
7581 * They could set 'spellcapcheck' depending on the language.
7582 * Use the first name in 'spelllang' up to '_region' or
7583 * '.encoding'.
7584 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007585 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007586 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7587 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007588 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007589 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007590 }
7591#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007592 }
7593
7594#ifdef FEAT_MOUSE
7595 if (varp == &p_mouse)
7596 {
7597# ifdef FEAT_MOUSE_TTY
7598 if (*p_mouse == NUL)
7599 mch_setmouse(FALSE); /* switch mouse off */
7600 else
7601# endif
7602 setmouse(); /* in case 'mouse' changed */
7603 }
7604#endif
7605
Bram Moolenaar913077c2012-03-28 19:59:04 +02007606 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007607 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007608 curwin->w_set_curswant = TRUE;
7609
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007610#ifdef FEAT_GUI
7611 /* check redraw when it's not a GUI option or the GUI is active. */
7612 if (!redraw_gui_only || gui.in_use)
7613#endif
7614 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007615
7616 return errmsg;
7617}
7618
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007619#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007620/*
7621 * Simple int comparison function for use with qsort()
7622 */
7623 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007624int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007625{
7626 return *(const int *)a - *(const int *)b;
7627}
7628
7629/*
7630 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7631 * Returns error message, NULL if it's OK.
7632 */
7633 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007634check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007635{
7636 char_u *s;
7637 int col;
7638 int count = 0;
7639 int color_cols[256];
7640 int i;
7641 int j = 0;
7642
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007643 if (wp->w_buffer == NULL)
7644 return NULL; /* buffer was closed */
7645
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007646 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007647 {
7648 if (*s == '-' || *s == '+')
7649 {
7650 /* -N and +N: add to 'textwidth' */
7651 col = (*s == '-') ? -1 : 1;
7652 ++s;
7653 if (!VIM_ISDIGIT(*s))
7654 return e_invarg;
7655 col = col * getdigits(&s);
7656 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007657 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007658 col += wp->w_buffer->b_p_tw;
7659 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007660 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007661 }
7662 else if (VIM_ISDIGIT(*s))
7663 col = getdigits(&s);
7664 else
7665 return e_invarg;
7666 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007667skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007668 if (*s == NUL)
7669 break;
7670 if (*s != ',')
7671 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007672 if (*++s == NUL)
7673 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007674 }
7675
7676 vim_free(wp->w_p_cc_cols);
7677 if (count == 0)
7678 wp->w_p_cc_cols = NULL;
7679 else
7680 {
7681 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7682 if (wp->w_p_cc_cols != NULL)
7683 {
7684 /* sort the columns for faster usage on screen redraw inside
7685 * win_line() */
7686 qsort(color_cols, count, sizeof(int), int_cmp);
7687
7688 for (i = 0; i < count; ++i)
7689 /* skip duplicates */
7690 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7691 wp->w_p_cc_cols[j++] = color_cols[i];
7692 wp->w_p_cc_cols[j] = -1; /* end marker */
7693 }
7694 }
7695
7696 return NULL; /* no error */
7697}
7698#endif
7699
Bram Moolenaar071d4272004-06-13 20:20:40 +00007700/*
7701 * Handle setting 'listchars' or 'fillchars'.
7702 * Returns error message, NULL if it's OK.
7703 */
7704 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007705set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007706{
7707 int round, i, len, entries;
7708 char_u *p, *s;
7709 int c1, c2 = 0;
7710 struct charstab
7711 {
7712 int *cp;
7713 char *name;
7714 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007715 static struct charstab filltab[] =
7716 {
7717 {&fill_stl, "stl"},
7718 {&fill_stlnc, "stlnc"},
7719 {&fill_vert, "vert"},
7720 {&fill_fold, "fold"},
7721 {&fill_diff, "diff"},
7722 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007723 static struct charstab lcstab[] =
7724 {
7725 {&lcs_eol, "eol"},
7726 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007727 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007728 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007729 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007730 {&lcs_tab2, "tab"},
7731 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007732#ifdef FEAT_CONCEAL
7733 {&lcs_conceal, "conceal"},
7734#else
7735 {NULL, "conceal"},
7736#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007737 };
7738 struct charstab *tab;
7739
Bram Moolenaar071d4272004-06-13 20:20:40 +00007740 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007741 {
7742 tab = lcstab;
7743 entries = sizeof(lcstab) / sizeof(struct charstab);
7744 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007745 else
7746 {
7747 tab = filltab;
7748 entries = sizeof(filltab) / sizeof(struct charstab);
7749 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007750
7751 /* first round: check for valid value, second round: assign values */
7752 for (round = 0; round <= 1; ++round)
7753 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007754 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007755 {
7756 /* After checking that the value is valid: set defaults: space for
7757 * 'fillchars', NUL for 'listchars' */
7758 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007759 if (tab[i].cp != NULL)
7760 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007761 if (varp == &p_lcs)
7762 lcs_tab1 = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007763 else
7764 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007765 }
7766 p = *varp;
7767 while (*p)
7768 {
7769 for (i = 0; i < entries; ++i)
7770 {
7771 len = (int)STRLEN(tab[i].name);
7772 if (STRNCMP(p, tab[i].name, len) == 0
7773 && p[len] == ':'
7774 && p[len + 1] != NUL)
7775 {
7776 s = p + len + 1;
7777#ifdef FEAT_MBYTE
7778 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007779 if (mb_char2cells(c1) > 1)
7780 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007781#else
7782 c1 = *s++;
7783#endif
7784 if (tab[i].cp == &lcs_tab2)
7785 {
7786 if (*s == NUL)
7787 continue;
7788#ifdef FEAT_MBYTE
7789 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007790 if (mb_char2cells(c2) > 1)
7791 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007792#else
7793 c2 = *s++;
7794#endif
7795 }
7796 if (*s == ',' || *s == NUL)
7797 {
7798 if (round)
7799 {
7800 if (tab[i].cp == &lcs_tab2)
7801 {
7802 lcs_tab1 = c1;
7803 lcs_tab2 = c2;
7804 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007805 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007806 *(tab[i].cp) = c1;
7807
7808 }
7809 p = s;
7810 break;
7811 }
7812 }
7813 }
7814
7815 if (i == entries)
7816 return e_invarg;
7817 if (*p == ',')
7818 ++p;
7819 }
7820 }
7821
7822 return NULL; /* no error */
7823}
7824
7825#ifdef FEAT_STL_OPT
7826/*
7827 * Check validity of options with the 'statusline' format.
7828 * Return error message or NULL.
7829 */
7830 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007831check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007832{
7833 int itemcnt = 0;
7834 int groupdepth = 0;
7835 static char_u errbuf[80];
7836
7837 while (*s && itemcnt < STL_MAX_ITEM)
7838 {
7839 /* Check for valid keys after % sequences */
7840 while (*s && *s != '%')
7841 s++;
7842 if (!*s)
7843 break;
7844 s++;
7845 if (*s != '%' && *s != ')')
7846 ++itemcnt;
7847 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7848 {
7849 s++;
7850 continue;
7851 }
7852 if (*s == ')')
7853 {
7854 s++;
7855 if (--groupdepth < 0)
7856 break;
7857 continue;
7858 }
7859 if (*s == '-')
7860 s++;
7861 while (VIM_ISDIGIT(*s))
7862 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007863 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007864 continue;
7865 if (*s == '.')
7866 {
7867 s++;
7868 while (*s && VIM_ISDIGIT(*s))
7869 s++;
7870 }
7871 if (*s == '(')
7872 {
7873 groupdepth++;
7874 continue;
7875 }
7876 if (vim_strchr(STL_ALL, *s) == NULL)
7877 {
7878 return illegal_char(errbuf, *s);
7879 }
7880 if (*s == '{')
7881 {
7882 s++;
7883 while (*s != '}' && *s)
7884 s++;
7885 if (*s != '}')
7886 return (char_u *)N_("E540: Unclosed expression sequence");
7887 }
7888 }
7889 if (itemcnt >= STL_MAX_ITEM)
7890 return (char_u *)N_("E541: too many items");
7891 if (groupdepth != 0)
7892 return (char_u *)N_("E542: unbalanced groups");
7893 return NULL;
7894}
7895#endif
7896
7897#ifdef FEAT_CLIPBOARD
7898/*
7899 * Extract the items in the 'clipboard' option and set global values.
7900 */
7901 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007902check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007903{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007904 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007905 int new_autoselect_star = FALSE;
7906 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007907 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007908 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007909 regprog_T *new_exclude_prog = NULL;
7910 char_u *errmsg = NULL;
7911 char_u *p;
7912
7913 for (p = p_cb; *p != NUL; )
7914 {
7915 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7916 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007917 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007918 p += 7;
7919 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007920 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007921 && (p[11] == ',' || p[11] == NUL))
7922 {
7923 new_unnamed |= CLIP_UNNAMED_PLUS;
7924 p += 11;
7925 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007926 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007927 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007928 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007929 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007930 p += 10;
7931 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007932 else if (STRNCMP(p, "autoselectplus", 14) == 0
7933 && (p[14] == ',' || p[14] == NUL))
7934 {
7935 new_autoselect_plus = TRUE;
7936 p += 14;
7937 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007938 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007939 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007940 {
7941 new_autoselectml = TRUE;
7942 p += 12;
7943 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007944 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7945 {
7946 new_html = TRUE;
7947 p += 4;
7948 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007949 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7950 {
7951 p += 8;
7952 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7953 if (new_exclude_prog == NULL)
7954 errmsg = e_invarg;
7955 break;
7956 }
7957 else
7958 {
7959 errmsg = e_invarg;
7960 break;
7961 }
7962 if (*p == ',')
7963 ++p;
7964 }
7965 if (errmsg == NULL)
7966 {
7967 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007968 clip_autoselect_star = new_autoselect_star;
7969 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007970 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007971 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007972 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007973 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007974#ifdef FEAT_GUI_GTK
7975 if (gui.in_use)
7976 {
7977 gui_gtk_set_selection_targets();
7978 gui_gtk_set_dnd_targets();
7979 }
7980#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007981 }
7982 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007983 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007984
7985 return errmsg;
7986}
7987#endif
7988
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007989#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007990 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007991did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007992{
7993 char_u *errmsg = NULL;
7994 win_T *wp;
7995 int l;
7996
7997 if (is_spellfile)
7998 {
7999 l = (int)STRLEN(curwin->w_s->b_p_spf);
8000 if (l > 0 && (l < 4
8001 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8002 errmsg = e_invarg;
8003 }
8004
8005 if (errmsg == NULL)
8006 {
8007 FOR_ALL_WINDOWS(wp)
8008 if (wp->w_buffer == curbuf && wp->w_p_spell)
8009 {
8010 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008011 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008012 }
8013 }
8014 return errmsg;
8015}
8016
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008017/*
8018 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8019 * Return error message when failed, NULL when OK.
8020 */
8021 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008022compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008023{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008024 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008025 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008026
Bram Moolenaar860cae12010-06-05 23:22:07 +02008027 if (*synblock->b_p_spc == NUL)
8028 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008029 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008030 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008031 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008032 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008033 if (re != NULL)
8034 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008035 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008036 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008037 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008038 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008039 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008040 return e_invarg;
8041 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008042 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008043 }
8044
Bram Moolenaar473de612013-06-08 18:19:48 +02008045 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008046 return NULL;
8047}
8048#endif
8049
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008050#if defined(FEAT_EVAL) || defined(PROTO)
8051/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008052 * Set the scriptID for an option, taking care of setting the buffer- or
8053 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008054 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008055 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008056set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008057{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008058 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8059 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008060
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008061 /* Remember where the option was set. For local options need to do that
8062 * in the buffer or window structure. */
8063 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008064 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008065 if (both || (opt_flags & OPT_LOCAL))
8066 {
8067 if (indir & PV_BUF)
8068 curbuf->b_p_scriptID[indir & PV_MASK] = id;
8069 else if (indir & PV_WIN)
8070 curwin->w_p_scriptID[indir & PV_MASK] = id;
8071 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008072}
8073#endif
8074
Bram Moolenaar071d4272004-06-13 20:20:40 +00008075/*
8076 * Set the value of a boolean option, and take care of side effects.
8077 * Returns NULL for success, or an error message for an error.
8078 */
8079 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008080set_bool_option(
8081 int opt_idx, /* index in options[] table */
8082 char_u *varp, /* pointer to the option variable */
8083 int value, /* new value */
8084 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008085{
8086 int old_value = *(int *)varp;
8087
Bram Moolenaar071d4272004-06-13 20:20:40 +00008088 /* Disallow changing some options from secure mode */
8089 if ((secure
8090#ifdef HAVE_SANDBOX
8091 || sandbox != 0
8092#endif
8093 ) && (options[opt_idx].flags & P_SECURE))
8094 return e_secure;
8095
8096 *(int *)varp = value; /* set the new value */
8097#ifdef FEAT_EVAL
8098 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008099 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008100#endif
8101
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008102#ifdef FEAT_GUI
8103 need_mouse_correct = TRUE;
8104#endif
8105
Bram Moolenaar071d4272004-06-13 20:20:40 +00008106 /* May set global value for local option. */
8107 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8108 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8109
8110 /*
8111 * Handle side effects of changing a bool option.
8112 */
8113
8114 /* 'compatible' */
8115 if ((int *)varp == &p_cp)
8116 {
8117 compatible_set();
8118 }
8119
Bram Moolenaar920694c2016-08-21 17:45:02 +02008120#ifdef FEAT_LANGMAP
8121 if ((int *)varp == &p_lrm)
8122 /* 'langremap' -> !'langnoremap' */
8123 p_lnr = !p_lrm;
8124 else if ((int *)varp == &p_lnr)
8125 /* 'langnoremap' -> !'langremap' */
8126 p_lrm = !p_lnr;
8127#endif
8128
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008129#ifdef FEAT_PERSISTENT_UNDO
8130 /* 'undofile' */
8131 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8132 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008133 /* Only take action when the option was set. When reset we do not
8134 * delete the undo file, the option may be set again without making
8135 * any changes in between. */
8136 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008137 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008138 char_u hash[UNDO_HASH_SIZE];
8139 buf_T *save_curbuf = curbuf;
8140
Bram Moolenaar29323592016-07-24 22:04:11 +02008141 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008142 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008143 /* When 'undofile' is set globally: for every buffer, otherwise
8144 * only for the current buffer: Try to read in the undofile,
8145 * if one exists, the buffer wasn't changed and the buffer was
8146 * loaded */
8147 if ((curbuf == save_curbuf
8148 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8149 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8150 {
8151 u_compute_hash(hash);
8152 u_read_undo(NULL, hash, curbuf->b_fname);
8153 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008154 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008155 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008156 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008157 }
8158#endif
8159
Bram Moolenaar071d4272004-06-13 20:20:40 +00008160 else if ((int *)varp == &curbuf->b_p_ro)
8161 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008162 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008163 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8164 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008165
8166 /* when 'readonly' is set may give W10 again */
8167 if (curbuf->b_p_ro)
8168 curbuf->b_did_warn = FALSE;
8169
Bram Moolenaar071d4272004-06-13 20:20:40 +00008170#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008171 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008172#endif
8173 }
8174
Bram Moolenaar9c449722010-07-20 18:44:27 +02008175#ifdef FEAT_GUI
8176 else if ((int *)varp == &p_mh)
8177 {
8178 if (!p_mh)
8179 gui_mch_mousehide(FALSE);
8180 }
8181#endif
8182
Bram Moolenaara539df02010-08-01 14:35:05 +02008183 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008184 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008185 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008186# ifdef FEAT_TERMINAL
8187 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaar6d819742017-08-06 14:57:49 +02008188 if (term_in_normal_mode()
Bram Moolenaar20e6cd02017-08-01 20:25:22 +02008189 || (bt_terminal(curbuf) && !term_is_finished(curbuf)))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008190 {
8191 curbuf->b_p_ma = FALSE;
8192 return (char_u *)N_("E946: Cannot make a terminal with running job modifiable");
8193 }
8194# endif
8195# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008196 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008197# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008198 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008199#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008200 /* when 'endofline' is changed, redraw the window title */
8201 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008202 {
8203 redraw_titles();
8204 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008205 /* when 'fixeol' is changed, redraw the window title */
8206 else if ((int *)varp == &curbuf->b_p_fixeol)
8207 {
8208 redraw_titles();
8209 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008210# ifdef FEAT_MBYTE
8211 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008212 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008213 {
8214 redraw_titles();
8215 }
8216# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008217#endif
8218
8219 /* when 'bin' is set also set some other options */
8220 else if ((int *)varp == &curbuf->b_p_bin)
8221 {
8222 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8223#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008224 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008225#endif
8226 }
8227
8228#ifdef FEAT_AUTOCMD
8229 /* when 'buflisted' changes, trigger autocommands */
8230 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8231 {
8232 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8233 NULL, NULL, TRUE, curbuf);
8234 }
8235#endif
8236
8237 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8238 else if ((int *)varp == &curbuf->b_p_swf)
8239 {
8240 if (curbuf->b_p_swf && p_uc)
8241 ml_open_file(curbuf); /* create the swap file */
8242 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008243 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8244 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008245 mf_close_file(curbuf, TRUE); /* remove the swap file */
8246 }
8247
8248 /* when 'terse' is set change 'shortmess' */
8249 else if ((int *)varp == &p_terse)
8250 {
8251 char_u *p;
8252
8253 p = vim_strchr(p_shm, SHM_SEARCH);
8254
8255 /* insert 's' in p_shm */
8256 if (p_terse && p == NULL)
8257 {
8258 STRCPY(IObuff, p_shm);
8259 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008260 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008261 }
8262 /* remove 's' from p_shm */
8263 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008264 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008265 }
8266
8267 /* when 'paste' is set or reset also change other options */
8268 else if ((int *)varp == &p_paste)
8269 {
8270 paste_option_changed();
8271 }
8272
8273 /* when 'insertmode' is set from an autocommand need to do work here */
8274 else if ((int *)varp == &p_im)
8275 {
8276 if (p_im)
8277 {
8278 if ((State & INSERT) == 0)
8279 need_start_insertmode = TRUE;
8280 stop_insert_mode = FALSE;
8281 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008282 /* only reset if it was set previously */
8283 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008284 {
8285 need_start_insertmode = FALSE;
8286 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008287 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008288 clear_cmdline = TRUE; /* remove "(insert)" */
8289 restart_edit = 0;
8290 }
8291 }
8292
8293 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8294 else if ((int *)varp == &p_ic && p_hls)
8295 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008296 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008297 }
8298
8299#ifdef FEAT_SEARCH_EXTRA
8300 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8301 else if ((int *)varp == &p_hls)
8302 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008303 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008304 }
8305#endif
8306
8307#ifdef FEAT_SCROLLBIND
8308 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8309 * at the end of normal_cmd() */
8310 else if ((int *)varp == &curwin->w_p_scb)
8311 {
8312 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008313 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008314 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008315 curwin->w_scbind_pos = curwin->w_topline;
8316 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008317 }
8318#endif
8319
Bram Moolenaar4033c552017-09-16 20:54:51 +02008320#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008321 /* There can be only one window with 'previewwindow' set. */
8322 else if ((int *)varp == &curwin->w_p_pvw)
8323 {
8324 if (curwin->w_p_pvw)
8325 {
8326 win_T *win;
8327
Bram Moolenaar29323592016-07-24 22:04:11 +02008328 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008329 if (win->w_p_pvw && win != curwin)
8330 {
8331 curwin->w_p_pvw = FALSE;
8332 return (char_u *)N_("E590: A preview window already exists");
8333 }
8334 }
8335 }
8336#endif
8337
8338 /* when 'textmode' is set or reset also change 'fileformat' */
8339 else if ((int *)varp == &curbuf->b_p_tx)
8340 {
8341 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8342 }
8343
8344 /* when 'textauto' is set or reset also change 'fileformats' */
8345 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008346 set_string_option_direct((char_u *)"ffs", -1,
8347 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008348 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008349
8350 /*
8351 * When 'lisp' option changes include/exclude '-' in
8352 * keyword characters.
8353 */
8354#ifdef FEAT_LISP
8355 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8356 {
8357 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8358 }
8359#endif
8360
8361#ifdef FEAT_TITLE
8362 /* when 'title' changed, may need to change the title; same for 'icon' */
8363 else if ((int *)varp == &p_title)
8364 {
8365 did_set_title(FALSE);
8366 }
8367
8368 else if ((int *)varp == &p_icon)
8369 {
8370 did_set_title(TRUE);
8371 }
8372#endif
8373
8374 else if ((int *)varp == &curbuf->b_changed)
8375 {
8376 if (!value)
8377 save_file_ff(curbuf); /* Buffer is unchanged */
8378#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008379 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008380#endif
8381#ifdef FEAT_AUTOCMD
8382 modified_was_set = value;
8383#endif
8384 }
8385
8386#ifdef BACKSLASH_IN_FILENAME
8387 else if ((int *)varp == &p_ssl)
8388 {
8389 if (p_ssl)
8390 {
8391 psepc = '/';
8392 psepcN = '\\';
8393 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008394 }
8395 else
8396 {
8397 psepc = '\\';
8398 psepcN = '/';
8399 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008400 }
8401
8402 /* need to adjust the file name arguments and buffer names. */
8403 buflist_slash_adjust();
8404 alist_slash_adjust();
8405# ifdef FEAT_EVAL
8406 scriptnames_slash_adjust();
8407# endif
8408 }
8409#endif
8410
8411 /* If 'wrap' is set, set w_leftcol to zero. */
8412 else if ((int *)varp == &curwin->w_p_wrap)
8413 {
8414 if (curwin->w_p_wrap)
8415 curwin->w_leftcol = 0;
8416 }
8417
Bram Moolenaar071d4272004-06-13 20:20:40 +00008418 else if ((int *)varp == &p_ea)
8419 {
8420 if (p_ea && !old_value)
8421 win_equal(curwin, FALSE, 0);
8422 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008423
8424 else if ((int *)varp == &p_wiv)
8425 {
8426 /*
8427 * When 'weirdinvert' changed, set/reset 't_xs'.
8428 * Then set 'weirdinvert' according to value of 't_xs'.
8429 */
8430 if (p_wiv && !old_value)
8431 T_XS = (char_u *)"y";
8432 else if (!p_wiv && old_value)
8433 T_XS = empty_option;
8434 p_wiv = (*T_XS != NUL);
8435 }
8436
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008437#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008438 else if ((int *)varp == &p_beval)
8439 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008440 if (!balloonEvalForTerm)
8441 {
8442 if (p_beval && !old_value)
8443 gui_mch_enable_beval_area(balloonEval);
8444 else if (!p_beval && old_value)
8445 gui_mch_disable_beval_area(balloonEval);
8446 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008447 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008448#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008449#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008450 else if ((int *)varp == &p_bevalterm)
8451 {
8452 mch_bevalterm_changed();
8453 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008454#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008455
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008456#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008457 else if ((int *)varp == &p_acd)
8458 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008459 /* Change directories when the 'acd' option is set now. */
8460 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008461 }
8462#endif
8463
8464#ifdef FEAT_DIFF
8465 /* 'diff' */
8466 else if ((int *)varp == &curwin->w_p_diff)
8467 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008468 /* May add or remove the buffer from the list of diff buffers. */
8469 diff_buf_adjust(curwin);
8470# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008471 if (foldmethodIsDiff(curwin))
8472 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008473# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008474 }
8475#endif
8476
Bram Moolenaar819edbe2017-11-25 17:14:33 +01008477#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008478 /* 'imdisable' */
8479 else if ((int *)varp == &p_imdisable)
8480 {
8481 /* Only de-activate it here, it will be enabled when changing mode. */
8482 if (p_imdisable)
8483 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008484 else if (State & INSERT)
8485 /* When the option is set from an autocommand, it may need to take
8486 * effect right away. */
8487 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008488 }
8489#endif
8490
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008491#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008492 /* 'spell' */
8493 else if ((int *)varp == &curwin->w_p_spell)
8494 {
8495 if (curwin->w_p_spell)
8496 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008497 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008498 if (errmsg != NULL)
8499 EMSG(_(errmsg));
8500 }
8501 }
8502#endif
8503
Bram Moolenaar071d4272004-06-13 20:20:40 +00008504#ifdef FEAT_FKMAP
8505 else if ((int *)varp == &p_altkeymap)
8506 {
8507 if (old_value != p_altkeymap)
8508 {
8509 if (!p_altkeymap)
8510 {
8511 p_hkmap = p_fkmap;
8512 p_fkmap = 0;
8513 }
8514 else
8515 {
8516 p_fkmap = p_hkmap;
8517 p_hkmap = 0;
8518 }
8519 (void)init_chartab();
8520 }
8521 }
8522
8523 /*
8524 * In case some second language keymapping options have changed, check
8525 * and correct the setting in a consistent way.
8526 */
8527
8528 /*
8529 * If hkmap or fkmap are set, reset Arabic keymapping.
8530 */
8531 if ((p_hkmap || p_fkmap) && p_altkeymap)
8532 {
8533 p_altkeymap = p_fkmap;
8534# ifdef FEAT_ARABIC
8535 curwin->w_p_arab = FALSE;
8536# endif
8537 (void)init_chartab();
8538 }
8539
8540 /*
8541 * If hkmap set, reset Farsi keymapping.
8542 */
8543 if (p_hkmap && p_altkeymap)
8544 {
8545 p_altkeymap = 0;
8546 p_fkmap = 0;
8547# ifdef FEAT_ARABIC
8548 curwin->w_p_arab = FALSE;
8549# endif
8550 (void)init_chartab();
8551 }
8552
8553 /*
8554 * If fkmap set, reset Hebrew keymapping.
8555 */
8556 if (p_fkmap && !p_altkeymap)
8557 {
8558 p_altkeymap = 1;
8559 p_hkmap = 0;
8560# ifdef FEAT_ARABIC
8561 curwin->w_p_arab = FALSE;
8562# endif
8563 (void)init_chartab();
8564 }
8565#endif
8566
8567#ifdef FEAT_ARABIC
8568 if ((int *)varp == &curwin->w_p_arab)
8569 {
8570 if (curwin->w_p_arab)
8571 {
8572 /*
8573 * 'arabic' is set, handle various sub-settings.
8574 */
8575 if (!p_tbidi)
8576 {
8577 /* set rightleft mode */
8578 if (!curwin->w_p_rl)
8579 {
8580 curwin->w_p_rl = TRUE;
8581 changed_window_setting();
8582 }
8583
8584 /* Enable Arabic shaping (major part of what Arabic requires) */
8585 if (!p_arshape)
8586 {
8587 p_arshape = TRUE;
8588 redraw_later_clear();
8589 }
8590 }
8591
8592 /* Arabic requires a utf-8 encoding, inform the user if its not
8593 * set. */
8594 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008595 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008596 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8597
Bram Moolenaar8820b482017-03-16 17:23:31 +01008598 msg_source(HL_ATTR(HLF_W));
8599 MSG_ATTR(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008600#ifdef FEAT_EVAL
8601 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8602#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008603 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008604
8605# ifdef FEAT_MBYTE
8606 /* set 'delcombine' */
8607 p_deco = TRUE;
8608# endif
8609
8610# ifdef FEAT_KEYMAP
8611 /* Force-set the necessary keymap for arabic */
8612 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8613 OPT_LOCAL);
8614# endif
8615# ifdef FEAT_FKMAP
8616 p_altkeymap = 0;
8617 p_hkmap = 0;
8618 p_fkmap = 0;
8619 (void)init_chartab();
8620# endif
8621 }
8622 else
8623 {
8624 /*
8625 * 'arabic' is reset, handle various sub-settings.
8626 */
8627 if (!p_tbidi)
8628 {
8629 /* reset rightleft mode */
8630 if (curwin->w_p_rl)
8631 {
8632 curwin->w_p_rl = FALSE;
8633 changed_window_setting();
8634 }
8635
8636 /* 'arabicshape' isn't reset, it is a global option and
8637 * another window may still need it "on". */
8638 }
8639
8640 /* 'delcombine' isn't reset, it is a global option and another
8641 * window may still want it "on". */
8642
8643# ifdef FEAT_KEYMAP
8644 /* Revert to the default keymap */
8645 curbuf->b_p_iminsert = B_IMODE_NONE;
8646 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8647# endif
8648 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008649 }
8650
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008651#endif
8652
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008653#ifdef FEAT_TERMGUICOLORS
8654 /* 'termguicolors' */
8655 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008656 {
8657# ifdef FEAT_GUI
8658 if (!gui.in_use && !gui.starting)
8659# endif
8660 highlight_gui_started();
8661 }
8662#endif
8663
Bram Moolenaar071d4272004-06-13 20:20:40 +00008664 /*
8665 * End of handling side effects for bool options.
8666 */
8667
Bram Moolenaar53744302015-07-17 17:38:22 +02008668 /* after handling side effects, call autocommand */
8669
Bram Moolenaar071d4272004-06-13 20:20:40 +00008670 options[opt_idx].flags |= P_WAS_SET;
8671
Bram Moolenaar53744302015-07-17 17:38:22 +02008672#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8673 if (!starting)
8674 {
8675 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008676 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8677 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8678 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008679 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8680 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8681 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8682 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8683 reset_v_option_vars();
8684 }
8685#endif
8686
Bram Moolenaar071d4272004-06-13 20:20:40 +00008687 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008688 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008689 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008690 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008691 check_redraw(options[opt_idx].flags);
8692
8693 return NULL;
8694}
8695
8696/*
8697 * Set the value of a number option, and take care of side effects.
8698 * Returns NULL for success, or an error message for an error.
8699 */
8700 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008701set_num_option(
8702 int opt_idx, /* index in options[] table */
8703 char_u *varp, /* pointer to the option variable */
8704 long value, /* new value */
8705 char_u *errbuf, /* buffer for error messages */
8706 size_t errbuflen, /* length of "errbuf" */
8707 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008708 OPT_MODELINE */
8709{
8710 char_u *errmsg = NULL;
8711 long old_value = *(long *)varp;
8712 long old_Rows = Rows; /* remember old Rows */
8713 long old_Columns = Columns; /* remember old Columns */
8714 long *pp = (long *)varp;
8715
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008716 /* Disallow changing some options from secure mode. */
8717 if ((secure
8718#ifdef HAVE_SANDBOX
8719 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008720#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008721 ) && (options[opt_idx].flags & P_SECURE))
8722 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008723
8724 *pp = value;
8725#ifdef FEAT_EVAL
8726 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008727 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008728#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008729#ifdef FEAT_GUI
8730 need_mouse_correct = TRUE;
8731#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008732
Bram Moolenaar14f24742012-08-08 18:01:05 +02008733 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008734 {
8735 errmsg = e_positive;
8736 curbuf->b_p_sw = curbuf->b_p_ts;
8737 }
8738
8739 /*
8740 * Number options that need some action when changed
8741 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008742 if (pp == &p_wh || pp == &p_hh)
8743 {
8744 if (p_wh < 1)
8745 {
8746 errmsg = e_positive;
8747 p_wh = 1;
8748 }
8749 if (p_wmh > p_wh)
8750 {
8751 errmsg = e_winheight;
8752 p_wh = p_wmh;
8753 }
8754 if (p_hh < 0)
8755 {
8756 errmsg = e_positive;
8757 p_hh = 0;
8758 }
8759
8760 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008761 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008762 {
8763 if (pp == &p_wh && curwin->w_height < p_wh)
8764 win_setheight((int)p_wh);
8765 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8766 win_setheight((int)p_hh);
8767 }
8768 }
8769
8770 /* 'winminheight' */
8771 else if (pp == &p_wmh)
8772 {
8773 if (p_wmh < 0)
8774 {
8775 errmsg = e_positive;
8776 p_wmh = 0;
8777 }
8778 if (p_wmh > p_wh)
8779 {
8780 errmsg = e_winheight;
8781 p_wmh = p_wh;
8782 }
8783 win_setminheight();
8784 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008785 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008786 {
8787 if (p_wiw < 1)
8788 {
8789 errmsg = e_positive;
8790 p_wiw = 1;
8791 }
8792 if (p_wmw > p_wiw)
8793 {
8794 errmsg = e_winwidth;
8795 p_wiw = p_wmw;
8796 }
8797
8798 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008799 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008800 win_setwidth((int)p_wiw);
8801 }
8802
8803 /* 'winminwidth' */
8804 else if (pp == &p_wmw)
8805 {
8806 if (p_wmw < 0)
8807 {
8808 errmsg = e_positive;
8809 p_wmw = 0;
8810 }
8811 if (p_wmw > p_wiw)
8812 {
8813 errmsg = e_winwidth;
8814 p_wmw = p_wiw;
8815 }
8816 win_setminheight();
8817 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008818
Bram Moolenaar071d4272004-06-13 20:20:40 +00008819 /* (re)set last window status line */
8820 else if (pp == &p_ls)
8821 {
8822 last_status(FALSE);
8823 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008824
8825 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008826 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008827 {
8828 shell_new_rows(); /* recompute window positions and heights */
8829 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008830
8831#ifdef FEAT_GUI
8832 else if (pp == &p_linespace)
8833 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008834 /* Recompute gui.char_height and resize the Vim window to keep the
8835 * same number of lines. */
8836 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008837 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008838 }
8839#endif
8840
8841#ifdef FEAT_FOLDING
8842 /* 'foldlevel' */
8843 else if (pp == &curwin->w_p_fdl)
8844 {
8845 if (curwin->w_p_fdl < 0)
8846 curwin->w_p_fdl = 0;
8847 newFoldLevel();
8848 }
8849
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008850 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008851 else if (pp == &curwin->w_p_fml)
8852 {
8853 foldUpdateAll(curwin);
8854 }
8855
8856 /* 'foldnestmax' */
8857 else if (pp == &curwin->w_p_fdn)
8858 {
8859 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8860 foldUpdateAll(curwin);
8861 }
8862
8863 /* 'foldcolumn' */
8864 else if (pp == &curwin->w_p_fdc)
8865 {
8866 if (curwin->w_p_fdc < 0)
8867 {
8868 errmsg = e_positive;
8869 curwin->w_p_fdc = 0;
8870 }
8871 else if (curwin->w_p_fdc > 12)
8872 {
8873 errmsg = e_invarg;
8874 curwin->w_p_fdc = 12;
8875 }
8876 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008877#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008878
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008879#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008880 /* 'shiftwidth' or 'tabstop' */
8881 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8882 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008883# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008884 if (foldmethodIsIndent(curwin))
8885 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008886# endif
8887# ifdef FEAT_CINDENT
8888 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8889 * parse 'cinoptions'. */
8890 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8891 parse_cino(curbuf);
8892# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008893 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008894#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008895
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008896#ifdef FEAT_MBYTE
8897 /* 'maxcombine' */
8898 else if (pp == &p_mco)
8899 {
8900 if (p_mco > MAX_MCO)
8901 p_mco = MAX_MCO;
8902 else if (p_mco < 0)
8903 p_mco = 0;
8904 screenclear(); /* will re-allocate the screen */
8905 }
8906#endif
8907
Bram Moolenaar071d4272004-06-13 20:20:40 +00008908 else if (pp == &curbuf->b_p_iminsert)
8909 {
8910 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8911 {
8912 errmsg = e_invarg;
8913 curbuf->b_p_iminsert = B_IMODE_NONE;
8914 }
8915 p_iminsert = curbuf->b_p_iminsert;
8916 if (termcap_active) /* don't do this in the alternate screen */
8917 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02008918#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008919 /* Show/unshow value of 'keymap' in status lines. */
8920 status_redraw_curbuf();
8921#endif
8922 }
8923
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02008924#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
8925 /* 'imstyle' */
8926 else if (pp == &p_imst)
8927 {
8928 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
8929 errmsg = e_invarg;
8930 }
8931#endif
8932
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008933 else if (pp == &p_window)
8934 {
8935 if (p_window < 1)
8936 p_window = 1;
8937 else if (p_window >= Rows)
8938 p_window = Rows - 1;
8939 }
8940
Bram Moolenaar071d4272004-06-13 20:20:40 +00008941 else if (pp == &curbuf->b_p_imsearch)
8942 {
8943 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8944 {
8945 errmsg = e_invarg;
8946 curbuf->b_p_imsearch = B_IMODE_NONE;
8947 }
8948 p_imsearch = curbuf->b_p_imsearch;
8949 }
8950
8951#ifdef FEAT_TITLE
8952 /* if 'titlelen' has changed, redraw the title */
8953 else if (pp == &p_titlelen)
8954 {
8955 if (p_titlelen < 0)
8956 {
8957 errmsg = e_positive;
8958 p_titlelen = 85;
8959 }
8960 if (starting != NO_SCREEN && old_value != p_titlelen)
8961 need_maketitle = TRUE;
8962 }
8963#endif
8964
8965 /* if p_ch changed value, change the command line height */
8966 else if (pp == &p_ch)
8967 {
8968 if (p_ch < 1)
8969 {
8970 errmsg = e_positive;
8971 p_ch = 1;
8972 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008973 if (p_ch > Rows - min_rows() + 1)
8974 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008975
8976 /* Only compute the new window layout when startup has been
8977 * completed. Otherwise the frame sizes may be wrong. */
8978 if (p_ch != old_value && full_screen
8979#ifdef FEAT_GUI
8980 && !gui.starting
8981#endif
8982 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008983 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008984 }
8985
8986 /* when 'updatecount' changes from zero to non-zero, open swap files */
8987 else if (pp == &p_uc)
8988 {
8989 if (p_uc < 0)
8990 {
8991 errmsg = e_positive;
8992 p_uc = 100;
8993 }
8994 if (p_uc && !old_value)
8995 ml_open_files();
8996 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008997#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008998 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008999 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009000 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009001 {
9002 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009003 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009004 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009005 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009006 {
9007 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009008 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009009 }
9010 }
9011#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009012#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009013 else if (pp == &p_mzq)
9014 mzvim_reset_timer();
9015#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009016
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009017#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9018 /* 'pyxversion' */
9019 else if (pp == &p_pyx)
9020 {
9021 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9022 errmsg = e_invarg;
9023 }
9024#endif
9025
Bram Moolenaar071d4272004-06-13 20:20:40 +00009026 /* sync undo before 'undolevels' changes */
9027 else if (pp == &p_ul)
9028 {
9029 /* use the old value, otherwise u_sync() may not work properly */
9030 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009031 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009032 p_ul = value;
9033 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009034 else if (pp == &curbuf->b_p_ul)
9035 {
9036 /* use the old value, otherwise u_sync() may not work properly */
9037 curbuf->b_p_ul = old_value;
9038 u_sync(TRUE);
9039 curbuf->b_p_ul = value;
9040 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009041
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009042#ifdef FEAT_LINEBREAK
9043 /* 'numberwidth' must be positive */
9044 else if (pp == &curwin->w_p_nuw)
9045 {
9046 if (curwin->w_p_nuw < 1)
9047 {
9048 errmsg = e_positive;
9049 curwin->w_p_nuw = 1;
9050 }
9051 if (curwin->w_p_nuw > 10)
9052 {
9053 errmsg = e_invarg;
9054 curwin->w_p_nuw = 10;
9055 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009056 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009057 }
9058#endif
9059
Bram Moolenaar1a384422010-07-14 19:53:30 +02009060 else if (pp == &curbuf->b_p_tw)
9061 {
9062 if (curbuf->b_p_tw < 0)
9063 {
9064 errmsg = e_positive;
9065 curbuf->b_p_tw = 0;
9066 }
9067#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009068 {
9069 win_T *wp;
9070 tabpage_T *tp;
9071
9072 FOR_ALL_TAB_WINDOWS(tp, wp)
9073 check_colorcolumn(wp);
9074 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009075#endif
9076 }
9077
Bram Moolenaar071d4272004-06-13 20:20:40 +00009078 /*
9079 * Check the bounds for numeric options here
9080 */
9081 if (Rows < min_rows() && full_screen)
9082 {
9083 if (errbuf != NULL)
9084 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009085 vim_snprintf((char *)errbuf, errbuflen,
9086 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009087 errmsg = errbuf;
9088 }
9089 Rows = min_rows();
9090 }
9091 if (Columns < MIN_COLUMNS && full_screen)
9092 {
9093 if (errbuf != NULL)
9094 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009095 vim_snprintf((char *)errbuf, errbuflen,
9096 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009097 errmsg = errbuf;
9098 }
9099 Columns = MIN_COLUMNS;
9100 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009101 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009102
Bram Moolenaar071d4272004-06-13 20:20:40 +00009103 /*
9104 * If the screen (shell) height has been changed, assume it is the
9105 * physical screenheight.
9106 */
9107 if (old_Rows != Rows || old_Columns != Columns)
9108 {
9109 /* Changing the screen size is not allowed while updating the screen. */
9110 if (updating_screen)
9111 *pp = old_value;
9112 else if (full_screen
9113#ifdef FEAT_GUI
9114 && !gui.starting
9115#endif
9116 )
9117 set_shellsize((int)Columns, (int)Rows, TRUE);
9118 else
9119 {
9120 /* Postpone the resizing; check the size and cmdline position for
9121 * messages. */
9122 check_shellsize();
9123 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9124 cmdline_row = Rows - p_ch;
9125 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009126 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009127 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009128 }
9129
Bram Moolenaar071d4272004-06-13 20:20:40 +00009130 if (curbuf->b_p_ts <= 0)
9131 {
9132 errmsg = e_positive;
9133 curbuf->b_p_ts = 8;
9134 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009135 if (p_tm < 0)
9136 {
9137 errmsg = e_positive;
9138 p_tm = 0;
9139 }
9140 if ((curwin->w_p_scr <= 0
9141 || (curwin->w_p_scr > curwin->w_height
9142 && curwin->w_height > 0))
9143 && full_screen)
9144 {
9145 if (pp == &(curwin->w_p_scr))
9146 {
9147 if (curwin->w_p_scr != 0)
9148 errmsg = e_scroll;
9149 win_comp_scroll(curwin);
9150 }
9151 /* If 'scroll' became invalid because of a side effect silently adjust
9152 * it. */
9153 else if (curwin->w_p_scr <= 0)
9154 curwin->w_p_scr = 1;
9155 else /* curwin->w_p_scr > curwin->w_height */
9156 curwin->w_p_scr = curwin->w_height;
9157 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009158 if (p_hi < 0)
9159 {
9160 errmsg = e_positive;
9161 p_hi = 0;
9162 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009163 else if (p_hi > 10000)
9164 {
9165 errmsg = e_invarg;
9166 p_hi = 10000;
9167 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009168 if (p_re < 0 || p_re > 2)
9169 {
9170 errmsg = e_invarg;
9171 p_re = 0;
9172 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009173 if (p_report < 0)
9174 {
9175 errmsg = e_positive;
9176 p_report = 1;
9177 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009178 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009179 {
9180 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9181 p_sj = Rows / 2;
9182 else
9183 {
9184 errmsg = e_scroll;
9185 p_sj = 1;
9186 }
9187 }
9188 if (p_so < 0 && full_screen)
9189 {
9190 errmsg = e_scroll;
9191 p_so = 0;
9192 }
9193 if (p_siso < 0 && full_screen)
9194 {
9195 errmsg = e_positive;
9196 p_siso = 0;
9197 }
9198#ifdef FEAT_CMDWIN
9199 if (p_cwh < 1)
9200 {
9201 errmsg = e_positive;
9202 p_cwh = 1;
9203 }
9204#endif
9205 if (p_ut < 0)
9206 {
9207 errmsg = e_positive;
9208 p_ut = 2000;
9209 }
9210 if (p_ss < 0)
9211 {
9212 errmsg = e_positive;
9213 p_ss = 0;
9214 }
9215
9216 /* May set global value for local option. */
9217 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9218 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9219
9220 options[opt_idx].flags |= P_WAS_SET;
9221
Bram Moolenaar53744302015-07-17 17:38:22 +02009222#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
9223 if (!starting && errmsg == NULL)
9224 {
9225 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009226 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9227 vim_snprintf((char *)buf_new, 10, "%ld", value);
9228 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009229 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9230 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9231 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9232 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9233 reset_v_option_vars();
9234 }
9235#endif
9236
Bram Moolenaar071d4272004-06-13 20:20:40 +00009237 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009238 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009239 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009240 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009241 check_redraw(options[opt_idx].flags);
9242
9243 return errmsg;
9244}
9245
9246/*
9247 * Called after an option changed: check if something needs to be redrawn.
9248 */
9249 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009250check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009251{
9252 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009253 int doclear = (flags & P_RCLR) == P_RCLR;
9254 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009255
Bram Moolenaar071d4272004-06-13 20:20:40 +00009256 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9257 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009258
9259 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9260 changed_window_setting();
9261 if (flags & P_RBUF)
9262 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009263 if (flags & P_RWINONLY)
9264 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009265 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009266 redraw_all_later(CLEAR);
9267 else if (all)
9268 redraw_all_later(NOT_VALID);
9269}
9270
9271/*
9272 * Find index for option 'arg'.
9273 * Return -1 if not found.
9274 */
9275 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009276findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009277{
9278 int opt_idx;
9279 char *s, *p;
9280 static short quick_tab[27] = {0, 0}; /* quick access table */
9281 int is_term_opt;
9282
9283 /*
9284 * For first call: Initialize the quick-access table.
9285 * It contains the index for the first option that starts with a certain
9286 * letter. There are 26 letters, plus the first "t_" option.
9287 */
9288 if (quick_tab[1] == 0)
9289 {
9290 p = options[0].fullname;
9291 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9292 {
9293 if (s[0] != p[0])
9294 {
9295 if (s[0] == 't' && s[1] == '_')
9296 quick_tab[26] = opt_idx;
9297 else
9298 quick_tab[CharOrdLow(s[0])] = opt_idx;
9299 }
9300 p = s;
9301 }
9302 }
9303
9304 /*
9305 * Check for name starting with an illegal character.
9306 */
9307#ifdef EBCDIC
9308 if (!islower(arg[0]))
9309#else
9310 if (arg[0] < 'a' || arg[0] > 'z')
9311#endif
9312 return -1;
9313
9314 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9315 if (is_term_opt)
9316 opt_idx = quick_tab[26];
9317 else
9318 opt_idx = quick_tab[CharOrdLow(arg[0])];
9319 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9320 {
9321 if (STRCMP(arg, s) == 0) /* match full name */
9322 break;
9323 }
9324 if (s == NULL && !is_term_opt)
9325 {
9326 opt_idx = quick_tab[CharOrdLow(arg[0])];
9327 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9328 {
9329 s = options[opt_idx].shortname;
9330 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9331 break;
9332 s = NULL;
9333 }
9334 }
9335 if (s == NULL)
9336 opt_idx = -1;
9337 return opt_idx;
9338}
9339
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009340#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009341/*
9342 * Get the value for an option.
9343 *
9344 * Returns:
9345 * Number or Toggle option: 1, *numval gets value.
9346 * String option: 0, *stringval gets allocated string.
9347 * Hidden Number or Toggle option: -1.
9348 * hidden String option: -2.
9349 * unknown option: -3.
9350 */
9351 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009352get_option_value(
9353 char_u *name,
9354 long *numval,
9355 char_u **stringval, /* NULL when only checking existence */
9356 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009357{
9358 int opt_idx;
9359 char_u *varp;
9360
9361 opt_idx = findoption(name);
9362 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009363 {
9364 int key;
9365
9366 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9367 && (key = find_key_option(name)) != 0)
9368 {
9369 char_u key_name[2];
9370 char_u *p;
9371
9372 if (key < 0)
9373 {
9374 key_name[0] = KEY2TERMCAP0(key);
9375 key_name[1] = KEY2TERMCAP1(key);
9376 }
9377 else
9378 {
9379 key_name[0] = KS_KEY;
9380 key_name[1] = (key & 0xff);
9381 }
9382 p = find_termcode(key_name);
9383 if (p != NULL)
9384 {
9385 if (stringval != NULL)
9386 *stringval = vim_strsave(p);
9387 return 0;
9388 }
9389 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009390 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009391 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009392
9393 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9394
9395 if (options[opt_idx].flags & P_STRING)
9396 {
9397 if (varp == NULL) /* hidden option */
9398 return -2;
9399 if (stringval != NULL)
9400 {
9401#ifdef FEAT_CRYPT
9402 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009403 if ((char_u **)varp == &curbuf->b_p_key
9404 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009405 *stringval = vim_strsave((char_u *)"*****");
9406 else
9407#endif
9408 *stringval = vim_strsave(*(char_u **)(varp));
9409 }
9410 return 0;
9411 }
9412
9413 if (varp == NULL) /* hidden option */
9414 return -1;
9415 if (options[opt_idx].flags & P_NUM)
9416 *numval = *(long *)varp;
9417 else
9418 {
9419 /* Special case: 'modified' is b_changed, but we also want to consider
9420 * it set when 'ff' or 'fenc' changed. */
9421 if ((int *)varp == &curbuf->b_changed)
9422 *numval = curbufIsChanged();
9423 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009424 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009425 }
9426 return 1;
9427}
9428#endif
9429
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009430#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009431/*
9432 * Returns the option attributes and its value. Unlike the above function it
9433 * will return either global value or local value of the option depending on
9434 * what was requested, but it will never return global value if it was
9435 * requested to return local one and vice versa. Neither it will return
9436 * buffer-local value if it was requested to return window-local one.
9437 *
9438 * Pretends that option is absent if it is not present in the requested scope
9439 * (i.e. has no global, window-local or buffer-local value depending on
9440 * opt_type). Uses
9441 *
9442 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009443 * 0 hidden or unknown option, also option that does not have requested
9444 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009445 * see SOPT_* in vim.h for other flags
9446 *
9447 * Possible opt_type values: see SREQ_* in vim.h
9448 */
9449 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009450get_option_value_strict(
9451 char_u *name,
9452 long *numval,
9453 char_u **stringval, /* NULL when only obtaining attributes */
9454 int opt_type,
9455 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009456{
9457 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009458 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009459 struct vimoption *p;
9460 int r = 0;
9461
9462 opt_idx = findoption(name);
9463 if (opt_idx < 0)
9464 return 0;
9465
9466 p = &(options[opt_idx]);
9467
9468 /* Hidden option */
9469 if (p->var == NULL)
9470 return 0;
9471
9472 if (p->flags & P_BOOL)
9473 r |= SOPT_BOOL;
9474 else if (p->flags & P_NUM)
9475 r |= SOPT_NUM;
9476 else if (p->flags & P_STRING)
9477 r |= SOPT_STRING;
9478
9479 if (p->indir == PV_NONE)
9480 {
9481 if (opt_type == SREQ_GLOBAL)
9482 r |= SOPT_GLOBAL;
9483 else
9484 return 0; /* Did not request global-only option */
9485 }
9486 else
9487 {
9488 if (p->indir & PV_BOTH)
9489 r |= SOPT_GLOBAL;
9490 else if (opt_type == SREQ_GLOBAL)
9491 return 0; /* Requested global option */
9492
9493 if (p->indir & PV_WIN)
9494 {
9495 if (opt_type == SREQ_BUF)
9496 return 0; /* Did not request window-local option */
9497 else
9498 r |= SOPT_WIN;
9499 }
9500 else if (p->indir & PV_BUF)
9501 {
9502 if (opt_type == SREQ_WIN)
9503 return 0; /* Did not request buffer-local option */
9504 else
9505 r |= SOPT_BUF;
9506 }
9507 }
9508
9509 if (stringval == NULL)
9510 return r;
9511
9512 if (opt_type == SREQ_GLOBAL)
9513 varp = p->var;
9514 else
9515 {
9516 if (opt_type == SREQ_BUF)
9517 {
9518 /* Special case: 'modified' is b_changed, but we also want to
9519 * consider it set when 'ff' or 'fenc' changed. */
9520 if (p->indir == PV_MOD)
9521 {
9522 *numval = bufIsChanged((buf_T *) from);
9523 varp = NULL;
9524 }
9525#ifdef FEAT_CRYPT
9526 else if (p->indir == PV_KEY)
9527 {
9528 /* never return the value of the crypt key */
9529 *stringval = NULL;
9530 varp = NULL;
9531 }
9532#endif
9533 else
9534 {
9535 aco_save_T aco;
9536 aucmd_prepbuf(&aco, (buf_T *) from);
9537 varp = get_varp(p);
9538 aucmd_restbuf(&aco);
9539 }
9540 }
9541 else if (opt_type == SREQ_WIN)
9542 {
9543 win_T *save_curwin;
9544 save_curwin = curwin;
9545 curwin = (win_T *) from;
9546 curbuf = curwin->w_buffer;
9547 varp = get_varp(p);
9548 curwin = save_curwin;
9549 curbuf = curwin->w_buffer;
9550 }
9551 if (varp == p->var)
9552 return (r | SOPT_UNSET);
9553 }
9554
9555 if (varp != NULL)
9556 {
9557 if (p->flags & P_STRING)
9558 *stringval = vim_strsave(*(char_u **)(varp));
9559 else if (p->flags & P_NUM)
9560 *numval = *(long *) varp;
9561 else
9562 *numval = *(int *)varp;
9563 }
9564
9565 return r;
9566}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009567
9568/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009569 * Iterate over options. First argument is a pointer to a pointer to a
9570 * structure inside options[] array, second is option type like in the above
9571 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009572 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009573 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009574 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009575 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009576 * first argument to NULL.
9577 *
9578 * Returns full option name for current option on each call.
9579 */
9580 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009581option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009582{
9583 struct vimoption *ret = NULL;
9584 do
9585 {
9586 if (*option == NULL)
9587 *option = (void *) options;
9588 else if (((struct vimoption *) (*option))->fullname == NULL)
9589 {
9590 *option = NULL;
9591 return NULL;
9592 }
9593 else
9594 *option = (void *) (((struct vimoption *) (*option)) + 1);
9595
9596 ret = ((struct vimoption *) (*option));
9597
9598 /* Hidden option */
9599 if (ret->var == NULL)
9600 {
9601 ret = NULL;
9602 continue;
9603 }
9604
9605 switch (opt_type)
9606 {
9607 case SREQ_GLOBAL:
9608 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9609 ret = NULL;
9610 break;
9611 case SREQ_BUF:
9612 if (!(ret->indir & PV_BUF))
9613 ret = NULL;
9614 break;
9615 case SREQ_WIN:
9616 if (!(ret->indir & PV_WIN))
9617 ret = NULL;
9618 break;
9619 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009620 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009621 return NULL;
9622 }
9623 }
9624 while (ret == NULL);
9625
9626 return (char_u *)ret->fullname;
9627}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009628#endif
9629
Bram Moolenaar071d4272004-06-13 20:20:40 +00009630/*
9631 * Set the value of option "name".
9632 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009633 *
9634 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009635 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009636 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009637set_option_value(
9638 char_u *name,
9639 long number,
9640 char_u *string,
9641 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009642{
9643 int opt_idx;
9644 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009645 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009646
9647 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009648 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009649 {
9650 int key;
9651
9652 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9653 && (key = find_key_option(name)) != 0)
9654 {
9655 char_u key_name[2];
9656
9657 if (key < 0)
9658 {
9659 key_name[0] = KEY2TERMCAP0(key);
9660 key_name[1] = KEY2TERMCAP1(key);
9661 }
9662 else
9663 {
9664 key_name[0] = KS_KEY;
9665 key_name[1] = (key & 0xff);
9666 }
9667 add_termcode(key_name, string, FALSE);
9668 if (full_screen)
9669 ttest(FALSE);
9670 redraw_all_later(CLEAR);
9671 return NULL;
9672 }
9673
Bram Moolenaar071d4272004-06-13 20:20:40 +00009674 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009675 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009676 else
9677 {
9678 flags = options[opt_idx].flags;
9679#ifdef HAVE_SANDBOX
9680 /* Disallow changing some options in the sandbox */
9681 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009682 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009683 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009684 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009685 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009686#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009687 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009688 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009689 else
9690 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009691 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009692 if (varp != NULL) /* hidden option is not changed */
9693 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009694 if (number == 0 && string != NULL)
9695 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009696 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009697
9698 /* Either we are given a string or we are setting option
9699 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009700 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009701 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009702 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009703 {
9704 /* There's another character after zeros or the string
9705 * is empty. In both cases, we are trying to set a
9706 * num option using a string. */
9707 EMSG3(_("E521: Number required: &%s = '%s'"),
9708 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009709 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009710
9711 }
9712 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009713 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009714 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009715 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009716 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009717 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009718 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009719 }
9720 }
9721 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009722 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009723}
9724
9725/*
9726 * Get the terminal code for a terminal option.
9727 * Returns NULL when not found.
9728 */
9729 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009730get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009731{
9732 int opt_idx;
9733 char_u *varp;
9734
9735 if (tname[0] != 't' || tname[1] != '_' ||
9736 tname[2] == NUL || tname[3] == NUL)
9737 return NULL;
9738 if ((opt_idx = findoption(tname)) >= 0)
9739 {
9740 varp = get_varp(&(options[opt_idx]));
9741 if (varp != NULL)
9742 varp = *(char_u **)(varp);
9743 return varp;
9744 }
9745 return find_termcode(tname + 2);
9746}
9747
9748 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009749get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009750{
9751 int i;
9752
9753 i = findoption((char_u *)"hl");
9754 if (i >= 0)
9755 return options[i].def_val[VI_DEFAULT];
9756 return (char_u *)NULL;
9757}
9758
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009759#if defined(FEAT_MBYTE) || defined(PROTO)
9760 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009761get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009762{
9763 int i;
9764
9765 i = findoption((char_u *)"enc");
9766 if (i >= 0)
9767 return options[i].def_val[VI_DEFAULT];
9768 return (char_u *)NULL;
9769}
9770#endif
9771
Bram Moolenaar071d4272004-06-13 20:20:40 +00009772/*
9773 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9774 */
9775 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009776find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009777{
9778 int key;
9779 int modifiers;
9780
9781 /*
9782 * Don't use get_special_key_code() for t_xx, we don't want it to call
9783 * add_termcap_entry().
9784 */
9785 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9786 key = TERMCAP2KEY(arg[2], arg[3]);
9787 else
9788 {
9789 --arg; /* put arg at the '<' */
9790 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009791 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009792 if (modifiers) /* can't handle modifiers here */
9793 key = 0;
9794 }
9795 return key;
9796}
9797
9798/*
9799 * if 'all' == 0: show changed options
9800 * if 'all' == 1: show all normal options
9801 * if 'all' == 2: show all terminal options
9802 */
9803 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009804showoptions(
9805 int all,
9806 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009807{
9808 struct vimoption *p;
9809 int col;
9810 int isterm;
9811 char_u *varp;
9812 struct vimoption **items;
9813 int item_count;
9814 int run;
9815 int row, rows;
9816 int cols;
9817 int i;
9818 int len;
9819
9820#define INC 20
9821#define GAP 3
9822
9823 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9824 PARAM_COUNT));
9825 if (items == NULL)
9826 return;
9827
9828 /* Highlight title */
9829 if (all == 2)
9830 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9831 else if (opt_flags & OPT_GLOBAL)
9832 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9833 else if (opt_flags & OPT_LOCAL)
9834 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9835 else
9836 MSG_PUTS_TITLE(_("\n--- Options ---"));
9837
9838 /*
9839 * do the loop two times:
9840 * 1. display the short items
9841 * 2. display the long items (only strings and numbers)
9842 */
9843 for (run = 1; run <= 2 && !got_int; ++run)
9844 {
9845 /*
9846 * collect the items in items[]
9847 */
9848 item_count = 0;
9849 for (p = &options[0]; p->fullname != NULL; p++)
9850 {
9851 varp = NULL;
9852 isterm = istermoption(p);
9853 if (opt_flags != 0)
9854 {
9855 if (p->indir != PV_NONE && !isterm)
9856 varp = get_varp_scope(p, opt_flags);
9857 }
9858 else
9859 varp = get_varp(p);
9860 if (varp != NULL
9861 && ((all == 2 && isterm)
9862 || (all == 1 && !isterm)
9863 || (all == 0 && !optval_default(p, varp))))
9864 {
9865 if (p->flags & P_BOOL)
9866 len = 1; /* a toggle option fits always */
9867 else
9868 {
9869 option_value2string(p, opt_flags);
9870 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9871 }
9872 if ((len <= INC - GAP && run == 1) ||
9873 (len > INC - GAP && run == 2))
9874 items[item_count++] = p;
9875 }
9876 }
9877
9878 /*
9879 * display the items
9880 */
9881 if (run == 1)
9882 {
9883 cols = (Columns + GAP - 3) / INC;
9884 if (cols == 0)
9885 cols = 1;
9886 rows = (item_count + cols - 1) / cols;
9887 }
9888 else /* run == 2 */
9889 rows = item_count;
9890 for (row = 0; row < rows && !got_int; ++row)
9891 {
9892 msg_putchar('\n'); /* go to next line */
9893 if (got_int) /* 'q' typed in more */
9894 break;
9895 col = 0;
9896 for (i = row; i < item_count; i += rows)
9897 {
9898 msg_col = col; /* make columns */
9899 showoneopt(items[i], opt_flags);
9900 col += INC;
9901 }
9902 out_flush();
9903 ui_breakcheck();
9904 }
9905 }
9906 vim_free(items);
9907}
9908
9909/*
9910 * Return TRUE if option "p" has its default value.
9911 */
9912 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009913optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009914{
9915 int dvi;
9916
9917 if (varp == NULL)
9918 return TRUE; /* hidden option is always at default */
9919 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9920 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009921 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009922 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009923 /* the cast to long is required for Manx C, long_i is
9924 * needed for MSVC */
9925 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009926 /* P_STRING */
9927 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9928}
9929
9930/*
9931 * showoneopt: show the value of one option
9932 * must not be called with a hidden option!
9933 */
9934 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009935showoneopt(
9936 struct vimoption *p,
9937 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009938{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009939 char_u *varp;
9940 int save_silent = silent_mode;
9941
9942 silent_mode = FALSE;
9943 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009944
9945 varp = get_varp_scope(p, opt_flags);
9946
9947 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9948 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9949 ? !curbufIsChanged() : !*(int *)varp))
9950 MSG_PUTS("no");
9951 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9952 MSG_PUTS("--");
9953 else
9954 MSG_PUTS(" ");
9955 MSG_PUTS(p->fullname);
9956 if (!(p->flags & P_BOOL))
9957 {
9958 msg_putchar('=');
9959 /* put value string in NameBuff */
9960 option_value2string(p, opt_flags);
9961 msg_outtrans(NameBuff);
9962 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009963
9964 silent_mode = save_silent;
9965 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009966}
9967
9968/*
9969 * Write modified options as ":set" commands to a file.
9970 *
9971 * There are three values for "opt_flags":
9972 * OPT_GLOBAL: Write global option values and fresh values of
9973 * buffer-local options (used for start of a session
9974 * file).
9975 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9976 * curwin (used for a vimrc file).
9977 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9978 * and local values for window-local options of
9979 * curwin. Local values are also written when at the
9980 * default value, because a modeline or autocommand
9981 * may have set them when doing ":edit file" and the
9982 * user has set them back at the default or fresh
9983 * value.
9984 * When "local_only" is TRUE, don't write fresh
9985 * values, only local values (for ":mkview").
9986 * (fresh value = value used for a new buffer or window for a local option).
9987 *
9988 * Return FAIL on error, OK otherwise.
9989 */
9990 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009991makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009992{
9993 struct vimoption *p;
9994 char_u *varp; /* currently used value */
9995 char_u *varp_fresh; /* local value */
9996 char_u *varp_local = NULL; /* fresh value */
9997 char *cmd;
9998 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009999 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010000
10001 /*
10002 * The options that don't have a default (terminal name, columns, lines)
10003 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010004 * Do the loop over "options[]" twice: once for options with the
10005 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010006 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010007 for (pri = 1; pri >= 0; --pri)
10008 {
10009 for (p = &options[0]; !istermoption(p); p++)
10010 if (!(p->flags & P_NO_MKRC)
10011 && !istermoption(p)
10012 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010013 {
10014 /* skip global option when only doing locals */
10015 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10016 continue;
10017
10018 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10019 * file, they are always buffer-specific. */
10020 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10021 continue;
10022
10023 /* Global values are only written when not at the default value. */
10024 varp = get_varp_scope(p, opt_flags);
10025 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10026 continue;
10027
10028 round = 2;
10029 if (p->indir != PV_NONE)
10030 {
10031 if (p->var == VAR_WIN)
10032 {
10033 /* skip window-local option when only doing globals */
10034 if (!(opt_flags & OPT_LOCAL))
10035 continue;
10036 /* When fresh value of window-local option is not at the
10037 * default, need to write it too. */
10038 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10039 {
10040 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10041 if (!optval_default(p, varp_fresh))
10042 {
10043 round = 1;
10044 varp_local = varp;
10045 varp = varp_fresh;
10046 }
10047 }
10048 }
10049 }
10050
10051 /* Round 1: fresh value for window-local options.
10052 * Round 2: other values */
10053 for ( ; round <= 2; varp = varp_local, ++round)
10054 {
10055 if (round == 1 || (opt_flags & OPT_GLOBAL))
10056 cmd = "set";
10057 else
10058 cmd = "setlocal";
10059
10060 if (p->flags & P_BOOL)
10061 {
10062 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10063 return FAIL;
10064 }
10065 else if (p->flags & P_NUM)
10066 {
10067 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10068 return FAIL;
10069 }
10070 else /* P_STRING */
10071 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010072#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10073 int do_endif = FALSE;
10074
Bram Moolenaar071d4272004-06-13 20:20:40 +000010075 /* Don't set 'syntax' and 'filetype' again if the value is
10076 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010077 if (
10078# if defined(FEAT_SYN_HL)
10079 p->indir == PV_SYN
10080# if defined(FEAT_AUTOCMD)
10081 ||
10082# endif
10083# endif
10084# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010085 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010086# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010087 )
Bram Moolenaar071d4272004-06-13 20:20:40 +000010088 {
10089 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10090 *(char_u **)(varp)) < 0
10091 || put_eol(fd) < 0)
10092 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010093 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010094 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010095#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010096 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10097 (p->flags & P_EXPAND) != 0) == FAIL)
10098 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010099#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10100 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010101 {
10102 if (put_line(fd, "endif") == FAIL)
10103 return FAIL;
10104 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010105#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010106 }
10107 }
10108 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010109 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010110 return OK;
10111}
10112
10113#if defined(FEAT_FOLDING) || defined(PROTO)
10114/*
10115 * Generate set commands for the local fold options only. Used when
10116 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10117 */
10118 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010119makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010120{
10121 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10122# ifdef FEAT_EVAL
10123 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10124 == FAIL
10125# endif
10126 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10127 == FAIL
10128 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10129 == FAIL
10130 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10131 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10132 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10133 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10134 )
10135 return FAIL;
10136
10137 return OK;
10138}
10139#endif
10140
10141 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010142put_setstring(
10143 FILE *fd,
10144 char *cmd,
10145 char *name,
10146 char_u **valuep,
10147 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010148{
10149 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010150 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010151
10152 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10153 return FAIL;
10154 if (*valuep != NULL)
10155 {
10156 /* Output 'pastetoggle' as key names. For other
10157 * options some characters have to be escaped with
10158 * CTRL-V or backslash */
10159 if (valuep == &p_pt)
10160 {
10161 s = *valuep;
10162 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010163 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010164 return FAIL;
10165 }
10166 else if (expand)
10167 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010168 buf = alloc(MAXPATHL);
10169 if (buf == NULL)
10170 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010171 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10172 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010173 {
10174 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010175 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010176 }
10177 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010178 }
10179 else if (put_escstr(fd, *valuep, 2) == FAIL)
10180 return FAIL;
10181 }
10182 if (put_eol(fd) < 0)
10183 return FAIL;
10184 return OK;
10185}
10186
10187 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010188put_setnum(
10189 FILE *fd,
10190 char *cmd,
10191 char *name,
10192 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010193{
10194 long wc;
10195
10196 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10197 return FAIL;
10198 if (wc_use_keyname((char_u *)valuep, &wc))
10199 {
10200 /* print 'wildchar' and 'wildcharm' as a key name */
10201 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10202 return FAIL;
10203 }
10204 else if (fprintf(fd, "%ld", *valuep) < 0)
10205 return FAIL;
10206 if (put_eol(fd) < 0)
10207 return FAIL;
10208 return OK;
10209}
10210
10211 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010212put_setbool(
10213 FILE *fd,
10214 char *cmd,
10215 char *name,
10216 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010217{
Bram Moolenaar893de922007-10-02 18:40:57 +000010218 if (value < 0) /* global/local option using global value */
10219 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010220 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10221 || put_eol(fd) < 0)
10222 return FAIL;
10223 return OK;
10224}
10225
10226/*
10227 * Clear all the terminal options.
10228 * If the option has been allocated, free the memory.
10229 * Terminal options are never hidden or indirect.
10230 */
10231 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010232clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010233{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010234 /*
10235 * Reset a few things before clearing the old options. This may cause
10236 * outputting a few things that the terminal doesn't understand, but the
10237 * screen will be cleared later, so this is OK.
10238 */
10239#ifdef FEAT_MOUSE_TTY
10240 mch_setmouse(FALSE); /* switch mouse off */
10241#endif
10242#ifdef FEAT_TITLE
10243 mch_restore_title(3); /* restore window titles */
10244#endif
10245#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10246 /* When starting the GUI close the display opened for the clipboard.
10247 * After restoring the title, because that will need the display. */
10248 if (gui.starting)
10249 clear_xterm_clip();
10250#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010251 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010252
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010253 free_termoptions();
10254}
10255
10256 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010257free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010258{
10259 struct vimoption *p;
10260
Bram Moolenaar071d4272004-06-13 20:20:40 +000010261 for (p = &options[0]; p->fullname != NULL; p++)
10262 if (istermoption(p))
10263 {
10264 if (p->flags & P_ALLOCED)
10265 free_string_option(*(char_u **)(p->var));
10266 if (p->flags & P_DEF_ALLOCED)
10267 free_string_option(p->def_val[VI_DEFAULT]);
10268 *(char_u **)(p->var) = empty_option;
10269 p->def_val[VI_DEFAULT] = empty_option;
10270 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10271 }
10272 clear_termcodes();
10273}
10274
10275/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010276 * Free the string for one term option, if it was allocated.
10277 * Set the string to empty_option and clear allocated flag.
10278 * "var" points to the option value.
10279 */
10280 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010281free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010282{
10283 struct vimoption *p;
10284
10285 for (p = &options[0]; p->fullname != NULL; p++)
10286 if (p->var == var)
10287 {
10288 if (p->flags & P_ALLOCED)
10289 free_string_option(*(char_u **)(p->var));
10290 *(char_u **)(p->var) = empty_option;
10291 p->flags &= ~P_ALLOCED;
10292 break;
10293 }
10294}
10295
10296/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010297 * Set the terminal option defaults to the current value.
10298 * Used after setting the terminal name.
10299 */
10300 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010301set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010302{
10303 struct vimoption *p;
10304
10305 for (p = &options[0]; p->fullname != NULL; p++)
10306 {
10307 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10308 {
10309 if (p->flags & P_DEF_ALLOCED)
10310 {
10311 free_string_option(p->def_val[VI_DEFAULT]);
10312 p->flags &= ~P_DEF_ALLOCED;
10313 }
10314 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10315 if (p->flags & P_ALLOCED)
10316 {
10317 p->flags |= P_DEF_ALLOCED;
10318 p->flags &= ~P_ALLOCED; /* don't free the value now */
10319 }
10320 }
10321 }
10322}
10323
10324/*
10325 * return TRUE if 'p' starts with 't_'
10326 */
10327 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010328istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010329{
10330 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10331}
10332
10333/*
10334 * Compute columns for ruler and shown command. 'sc_col' is also used to
10335 * decide what the maximum length of a message on the status line can be.
10336 * If there is a status line for the last window, 'sc_col' is independent
10337 * of 'ru_col'.
10338 */
10339
10340#define COL_RULER 17 /* columns needed by standard ruler */
10341
10342 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010343comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010344{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010345#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010346 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010347
10348 sc_col = 0;
10349 ru_col = 0;
10350 if (p_ru)
10351 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010352# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010353 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010354# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010355 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010356# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010357 /* no last status line, adjust sc_col */
10358 if (!last_has_status)
10359 sc_col = ru_col;
10360 }
10361 if (p_sc)
10362 {
10363 sc_col += SHOWCMD_COLS;
10364 if (!p_ru || last_has_status) /* no need for separating space */
10365 ++sc_col;
10366 }
10367 sc_col = Columns - sc_col;
10368 ru_col = Columns - ru_col;
10369 if (sc_col <= 0) /* screen too narrow, will become a mess */
10370 sc_col = 1;
10371 if (ru_col <= 0)
10372 ru_col = 1;
10373#else
10374 sc_col = Columns;
10375 ru_col = Columns;
10376#endif
10377}
10378
10379/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010380 * Unset local option value, similar to ":set opt<".
10381 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010382 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010383unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010384{
10385 struct vimoption *p;
10386 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010387 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010388
10389 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010390 if (opt_idx < 0)
10391 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010392 p = &(options[opt_idx]);
10393
10394 switch ((int)p->indir)
10395 {
10396 /* global option with local value: use local value if it's been set */
10397 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010398 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010399 break;
10400 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010401 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010402 break;
10403 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010404 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010405 break;
10406 case PV_AR:
10407 buf->b_p_ar = -1;
10408 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010409 case PV_BKC:
10410 clear_string_option(&buf->b_p_bkc);
10411 buf->b_bkc_flags = 0;
10412 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010413 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010414 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010415 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010416 case PV_TC:
10417 clear_string_option(&buf->b_p_tc);
10418 buf->b_tc_flags = 0;
10419 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010420#ifdef FEAT_FIND_ID
10421 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010422 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010423 break;
10424 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010425 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010426 break;
10427#endif
10428#ifdef FEAT_INS_EXPAND
10429 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010430 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010431 break;
10432 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010433 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010434 break;
10435#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010436 case PV_FP:
10437 clear_string_option(&buf->b_p_fp);
10438 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010439#ifdef FEAT_QUICKFIX
10440 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010441 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010442 break;
10443 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010444 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010445 break;
10446 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010447 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010448 break;
10449#endif
10450#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10451 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010452 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010453 break;
10454#endif
10455#if defined(FEAT_CRYPT)
10456 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010457 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010458 break;
10459#endif
10460#ifdef FEAT_STL_OPT
10461 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010462 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010463 break;
10464#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010465 case PV_UL:
10466 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10467 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010468#ifdef FEAT_LISP
10469 case PV_LW:
10470 clear_string_option(&buf->b_p_lw);
10471 break;
10472#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010473#ifdef FEAT_MBYTE
10474 case PV_MENC:
10475 clear_string_option(&buf->b_p_menc);
10476 break;
10477#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010478 }
10479}
10480
10481/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010482 * Get pointer to option variable, depending on local or global scope.
10483 */
10484 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010485get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010486{
10487 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10488 {
10489 if (p->var == VAR_WIN)
10490 return (char_u *)GLOBAL_WO(get_varp(p));
10491 return p->var;
10492 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010493 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010494 {
10495 switch ((int)p->indir)
10496 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010497 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010498#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010499 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10500 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10501 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010502#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010503 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10504 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10505 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010506 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010507 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010508 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010509#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010510 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10511 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010512#endif
10513#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010514 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10515 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010516#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010517#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10518 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10519#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010520#if defined(FEAT_CRYPT)
10521 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10522#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010523#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010524 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010525#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010526 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010527#ifdef FEAT_LISP
10528 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10529#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010530 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010531#ifdef FEAT_MBYTE
10532 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10533#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010534 }
10535 return NULL; /* "cannot happen" */
10536 }
10537 return get_varp(p);
10538}
10539
10540/*
10541 * Get pointer to option variable.
10542 */
10543 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010544get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010545{
10546 /* hidden option, always return NULL */
10547 if (p->var == NULL)
10548 return NULL;
10549
10550 switch ((int)p->indir)
10551 {
10552 case PV_NONE: return p->var;
10553
10554 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010555 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010556 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010557 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010558 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010559 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010560 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010561 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010562 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010563 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010564 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010565 case PV_TC: return *curbuf->b_p_tc != NUL
10566 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010567 case PV_BKC: return *curbuf->b_p_bkc != NUL
10568 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010569#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010570 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010571 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010572 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010573 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10574#endif
10575#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010576 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010577 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010578 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010579 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10580#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010581 case PV_FP: return *curbuf->b_p_fp != NUL
10582 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010583#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010584 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010585 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010586 case PV_GP: return *curbuf->b_p_gp != NUL
10587 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10588 case PV_MP: return *curbuf->b_p_mp != NUL
10589 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010590#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010591#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10592 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10593 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10594#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010595#if defined(FEAT_CRYPT)
10596 case PV_CM: return *curbuf->b_p_cm != NUL
10597 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10598#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010599#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010600 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010601 ? (char_u *)&(curwin->w_p_stl) : p->var;
10602#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010603 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10604 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010605#ifdef FEAT_LISP
10606 case PV_LW: return *curbuf->b_p_lw != NUL
10607 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10608#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010609#ifdef FEAT_MBYTE
10610 case PV_MENC: return *curbuf->b_p_menc != NUL
10611 ? (char_u *)&(curbuf->b_p_menc) : p->var;
10612#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010613
10614#ifdef FEAT_ARABIC
10615 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10616#endif
10617 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010618#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010619 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10620#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010621#ifdef FEAT_SYN_HL
10622 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10623 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010624 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010625#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010626#ifdef FEAT_DIFF
10627 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10628#endif
10629#ifdef FEAT_FOLDING
10630 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10631 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10632 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10633 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10634 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10635 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10636 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10637# ifdef FEAT_EVAL
10638 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10639 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10640# endif
10641 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10642#endif
10643 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010644 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010645#ifdef FEAT_LINEBREAK
10646 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10647#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010648 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010649 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020010650#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010651 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10652#endif
10653#ifdef FEAT_RIGHTLEFT
10654 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10655 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10656#endif
10657 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10658 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10659#ifdef FEAT_LINEBREAK
10660 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010661 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10662 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010663#endif
10664#ifdef FEAT_SCROLLBIND
10665 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10666#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010667#ifdef FEAT_CURSORBIND
10668 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10669#endif
10670#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010671 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10672 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10673#endif
10674#ifdef FEAT_TERMINAL
Bram Moolenaar1b0675c2017-07-15 14:04:01 +020010675 case PV_TK: return (char_u *)&(curwin->w_p_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010676 case PV_TMS: return (char_u *)&(curwin->w_p_tms);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010677#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010678
10679 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10680 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10681#ifdef FEAT_MBYTE
10682 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10683#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010684 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10685 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010686 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10687 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10688#ifdef FEAT_CINDENT
10689 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10690 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10691 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10692#endif
10693#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10694 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10695#endif
10696#ifdef FEAT_COMMENTS
10697 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10698#endif
10699#ifdef FEAT_FOLDING
10700 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10701#endif
10702#ifdef FEAT_INS_EXPAND
10703 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10704#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010705#ifdef FEAT_COMPL_FUNC
10706 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010707 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010708#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010709 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010710 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010711 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10712#ifdef FEAT_MBYTE
10713 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10714#endif
10715 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10716#ifdef FEAT_AUTOCMD
10717 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10718#endif
10719 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010720 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010721 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10722 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10723 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10724 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10725#ifdef FEAT_FIND_ID
10726# ifdef FEAT_EVAL
10727 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10728# endif
10729#endif
10730#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10731 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10732 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10733#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010734#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010735 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10736#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010737#ifdef FEAT_CRYPT
10738 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10739#endif
10740#ifdef FEAT_LISP
10741 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10742#endif
10743 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10744 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10745 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10746 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10747 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010748 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010749#ifdef FEAT_TEXTOBJ
10750 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10751#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010752 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10753#ifdef FEAT_SMARTINDENT
10754 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10755#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010756 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010757 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10758#ifdef FEAT_SEARCHPATH
10759 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10760#endif
10761 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10762#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010763 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010764 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10765#endif
10766#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010767 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10768 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10769 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010770#endif
10771 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10772 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10773 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10774 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010775#ifdef FEAT_PERSISTENT_UNDO
10776 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10777#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010778 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10779#ifdef FEAT_KEYMAP
10780 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10781#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010782#ifdef FEAT_SIGNS
10783 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10784#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010785 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010786 }
10787 /* always return a valid pointer to avoid a crash! */
10788 return (char_u *)&(curbuf->b_p_wm);
10789}
10790
10791/*
10792 * Get the value of 'equalprg', either the buffer-local one or the global one.
10793 */
10794 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010795get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010796{
10797 if (*curbuf->b_p_ep == NUL)
10798 return p_ep;
10799 return curbuf->b_p_ep;
10800}
10801
Bram Moolenaar071d4272004-06-13 20:20:40 +000010802/*
10803 * Copy options from one window to another.
10804 * Used when splitting a window.
10805 */
10806 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010807win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010808{
10809 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10810 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10811# ifdef FEAT_RIGHTLEFT
10812# ifdef FEAT_FKMAP
10813 /* Is this right? */
10814 wp_to->w_farsi = wp_from->w_farsi;
10815# endif
10816# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010817#if defined(FEAT_LINEBREAK)
10818 briopt_check(wp_to);
10819#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010820}
Bram Moolenaar071d4272004-06-13 20:20:40 +000010821
10822/*
10823 * Copy the options from one winopt_T to another.
10824 * Doesn't free the old option values in "to", use clear_winopt() for that.
10825 * The 'scroll' option is not copied, because it depends on the window height.
10826 * The 'previewwindow' option is reset, there can be only one preview window.
10827 */
10828 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010829copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010830{
10831#ifdef FEAT_ARABIC
10832 to->wo_arab = from->wo_arab;
10833#endif
10834 to->wo_list = from->wo_list;
10835 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010836 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010837#ifdef FEAT_LINEBREAK
10838 to->wo_nuw = from->wo_nuw;
10839#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010840#ifdef FEAT_RIGHTLEFT
10841 to->wo_rl = from->wo_rl;
10842 to->wo_rlc = vim_strsave(from->wo_rlc);
10843#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010844#ifdef FEAT_STL_OPT
10845 to->wo_stl = vim_strsave(from->wo_stl);
10846#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010847 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010848#ifdef FEAT_DIFF
10849 to->wo_wrap_save = from->wo_wrap_save;
10850#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010851#ifdef FEAT_LINEBREAK
10852 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010853 to->wo_bri = from->wo_bri;
10854 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010855#endif
10856#ifdef FEAT_SCROLLBIND
10857 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010858 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010859#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010860#ifdef FEAT_CURSORBIND
10861 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010862 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010863#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010864#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010865 to->wo_spell = from->wo_spell;
10866#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010867#ifdef FEAT_SYN_HL
10868 to->wo_cuc = from->wo_cuc;
10869 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010870 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010871#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010872#ifdef FEAT_DIFF
10873 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010874 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010875#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010876#ifdef FEAT_CONCEAL
10877 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010878 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010879#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010880#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010881 to->wo_tk = vim_strsave(from->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010882 to->wo_tms = vim_strsave(from->wo_tms);
10883#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010884#ifdef FEAT_FOLDING
10885 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010886 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010887 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010888 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010889 to->wo_fdi = vim_strsave(from->wo_fdi);
10890 to->wo_fml = from->wo_fml;
10891 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010892 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010893 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010894 to->wo_fdm_save = from->wo_diff_saved
10895 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010896 to->wo_fdn = from->wo_fdn;
10897# ifdef FEAT_EVAL
10898 to->wo_fde = vim_strsave(from->wo_fde);
10899 to->wo_fdt = vim_strsave(from->wo_fdt);
10900# endif
10901 to->wo_fmr = vim_strsave(from->wo_fmr);
10902#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010903#ifdef FEAT_SIGNS
10904 to->wo_scl = vim_strsave(from->wo_scl);
10905#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010906 check_winopt(to); /* don't want NULL pointers */
10907}
10908
10909/*
10910 * Check string options in a window for a NULL value.
10911 */
10912 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010913check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010914{
10915 check_winopt(&win->w_onebuf_opt);
10916 check_winopt(&win->w_allbuf_opt);
10917}
10918
10919/*
10920 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10921 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010922 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010923check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010924{
10925#ifdef FEAT_FOLDING
10926 check_string_option(&wop->wo_fdi);
10927 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010928 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010929# ifdef FEAT_EVAL
10930 check_string_option(&wop->wo_fde);
10931 check_string_option(&wop->wo_fdt);
10932# endif
10933 check_string_option(&wop->wo_fmr);
10934#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010935#ifdef FEAT_SIGNS
10936 check_string_option(&wop->wo_scl);
10937#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010938#ifdef FEAT_RIGHTLEFT
10939 check_string_option(&wop->wo_rlc);
10940#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010941#ifdef FEAT_STL_OPT
10942 check_string_option(&wop->wo_stl);
10943#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010944#ifdef FEAT_SYN_HL
10945 check_string_option(&wop->wo_cc);
10946#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010947#ifdef FEAT_CONCEAL
10948 check_string_option(&wop->wo_cocu);
10949#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010950#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010951 check_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010952 check_string_option(&wop->wo_tms);
10953#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010954#ifdef FEAT_LINEBREAK
10955 check_string_option(&wop->wo_briopt);
10956#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010957}
10958
10959/*
10960 * Free the allocated memory inside a winopt_T.
10961 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010962 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010963clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010964{
10965#ifdef FEAT_FOLDING
10966 clear_string_option(&wop->wo_fdi);
10967 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010968 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010969# ifdef FEAT_EVAL
10970 clear_string_option(&wop->wo_fde);
10971 clear_string_option(&wop->wo_fdt);
10972# endif
10973 clear_string_option(&wop->wo_fmr);
10974#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010975#ifdef FEAT_SIGNS
10976 clear_string_option(&wop->wo_scl);
10977#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010978#ifdef FEAT_LINEBREAK
10979 clear_string_option(&wop->wo_briopt);
10980#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010981#ifdef FEAT_RIGHTLEFT
10982 clear_string_option(&wop->wo_rlc);
10983#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010984#ifdef FEAT_STL_OPT
10985 clear_string_option(&wop->wo_stl);
10986#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010987#ifdef FEAT_SYN_HL
10988 clear_string_option(&wop->wo_cc);
10989#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010990#ifdef FEAT_CONCEAL
10991 clear_string_option(&wop->wo_cocu);
10992#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010993#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010994 clear_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010995 clear_string_option(&wop->wo_tms);
10996#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010997}
10998
10999/*
11000 * Copy global option values to local options for one buffer.
11001 * Used when creating a new buffer and sometimes when entering a buffer.
11002 * flags:
11003 * BCO_ENTER We will enter the buf buffer.
11004 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11005 * appropriate.
11006 * BCO_NOHELP Don't copy the values to a help buffer.
11007 */
11008 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011009buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011010{
11011 int should_copy = TRUE;
11012 char_u *save_p_isk = NULL; /* init for GCC */
11013 int dont_do_help;
11014 int did_isk = FALSE;
11015
11016 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011017 * Skip this when the option defaults have not been set yet. Happens when
11018 * main() allocates the first buffer.
11019 */
11020 if (p_cpo != NULL)
11021 {
11022 /*
11023 * Always copy when entering and 'cpo' contains 'S'.
11024 * Don't copy when already initialized.
11025 * Don't copy when 'cpo' contains 's' and not entering.
11026 * 'S' BCO_ENTER initialized 's' should_copy
11027 * yes yes X X TRUE
11028 * yes no yes X FALSE
11029 * no X yes X FALSE
11030 * X no no yes FALSE
11031 * X no no no TRUE
11032 * no yes no X TRUE
11033 */
11034 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11035 && (buf->b_p_initialized
11036 || (!(flags & BCO_ENTER)
11037 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11038 should_copy = FALSE;
11039
11040 if (should_copy || (flags & BCO_ALWAYS))
11041 {
11042 /* Don't copy the options specific to a help buffer when
11043 * BCO_NOHELP is given or the options were initialized already
11044 * (jumping back to a help file with CTRL-T or CTRL-O) */
11045 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11046 || buf->b_p_initialized;
11047 if (dont_do_help) /* don't free b_p_isk */
11048 {
11049 save_p_isk = buf->b_p_isk;
11050 buf->b_p_isk = NULL;
11051 }
11052 /*
11053 * Always free the allocated strings.
11054 * If not already initialized, set 'readonly' and copy 'fileformat'.
11055 */
11056 if (!buf->b_p_initialized)
11057 {
11058 free_buf_options(buf, TRUE);
11059 buf->b_p_ro = FALSE; /* don't copy readonly */
11060 buf->b_p_tx = p_tx;
11061#ifdef FEAT_MBYTE
11062 buf->b_p_fenc = vim_strsave(p_fenc);
11063#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011064 switch (*p_ffs)
11065 {
11066 case 'm':
11067 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11068 case 'd':
11069 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11070 case 'u':
11071 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11072 default:
11073 buf->b_p_ff = vim_strsave(p_ff);
11074 }
11075 if (buf->b_p_ff != NULL)
11076 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011077 buf->b_p_bh = empty_option;
11078 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011079 }
11080 else
11081 free_buf_options(buf, FALSE);
11082
11083 buf->b_p_ai = p_ai;
11084 buf->b_p_ai_nopaste = p_ai_nopaste;
11085 buf->b_p_sw = p_sw;
11086 buf->b_p_tw = p_tw;
11087 buf->b_p_tw_nopaste = p_tw_nopaste;
11088 buf->b_p_tw_nobin = p_tw_nobin;
11089 buf->b_p_wm = p_wm;
11090 buf->b_p_wm_nopaste = p_wm_nopaste;
11091 buf->b_p_wm_nobin = p_wm_nobin;
11092 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011093#ifdef FEAT_MBYTE
11094 buf->b_p_bomb = p_bomb;
11095#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020011096 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011097 buf->b_p_et = p_et;
11098 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011099 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011100 buf->b_p_ml = p_ml;
11101 buf->b_p_ml_nobin = p_ml_nobin;
11102 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011103 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011104#ifdef FEAT_INS_EXPAND
11105 buf->b_p_cpt = vim_strsave(p_cpt);
11106#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011107#ifdef FEAT_COMPL_FUNC
11108 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011109 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011110#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011111 buf->b_p_sts = p_sts;
11112 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011113 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011114#ifdef FEAT_COMMENTS
11115 buf->b_p_com = vim_strsave(p_com);
11116#endif
11117#ifdef FEAT_FOLDING
11118 buf->b_p_cms = vim_strsave(p_cms);
11119#endif
11120 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011121 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011122 buf->b_p_nf = vim_strsave(p_nf);
11123 buf->b_p_mps = vim_strsave(p_mps);
11124#ifdef FEAT_SMARTINDENT
11125 buf->b_p_si = p_si;
11126#endif
11127 buf->b_p_ci = p_ci;
11128#ifdef FEAT_CINDENT
11129 buf->b_p_cin = p_cin;
11130 buf->b_p_cink = vim_strsave(p_cink);
11131 buf->b_p_cino = vim_strsave(p_cino);
11132#endif
11133#ifdef FEAT_AUTOCMD
11134 /* Don't copy 'filetype', it must be detected */
11135 buf->b_p_ft = empty_option;
11136#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011137 buf->b_p_pi = p_pi;
11138#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11139 buf->b_p_cinw = vim_strsave(p_cinw);
11140#endif
11141#ifdef FEAT_LISP
11142 buf->b_p_lisp = p_lisp;
11143#endif
11144#ifdef FEAT_SYN_HL
11145 /* Don't copy 'syntax', it must be set */
11146 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011147 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011148 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011149#endif
11150#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011151 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011152 (void)compile_cap_prog(&buf->b_s);
11153 buf->b_s.b_p_spf = vim_strsave(p_spf);
11154 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011155#endif
11156#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11157 buf->b_p_inde = vim_strsave(p_inde);
11158 buf->b_p_indk = vim_strsave(p_indk);
11159#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011160 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011161#if defined(FEAT_EVAL)
11162 buf->b_p_fex = vim_strsave(p_fex);
11163#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011164#ifdef FEAT_CRYPT
11165 buf->b_p_key = vim_strsave(p_key);
11166#endif
11167#ifdef FEAT_SEARCHPATH
11168 buf->b_p_sua = vim_strsave(p_sua);
11169#endif
11170#ifdef FEAT_KEYMAP
11171 buf->b_p_keymap = vim_strsave(p_keymap);
11172 buf->b_kmap_state |= KEYMAP_INIT;
11173#endif
11174 /* This isn't really an option, but copying the langmap and IME
11175 * state from the current buffer is better than resetting it. */
11176 buf->b_p_iminsert = p_iminsert;
11177 buf->b_p_imsearch = p_imsearch;
11178
11179 /* options that are normally global but also have a local value
11180 * are not copied, start using the global value */
11181 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011182 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011183 buf->b_p_bkc = empty_option;
11184 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011185#ifdef FEAT_QUICKFIX
11186 buf->b_p_gp = empty_option;
11187 buf->b_p_mp = empty_option;
11188 buf->b_p_efm = empty_option;
11189#endif
11190 buf->b_p_ep = empty_option;
11191 buf->b_p_kp = empty_option;
11192 buf->b_p_path = empty_option;
11193 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011194 buf->b_p_tc = empty_option;
11195 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011196#ifdef FEAT_FIND_ID
11197 buf->b_p_def = empty_option;
11198 buf->b_p_inc = empty_option;
11199# ifdef FEAT_EVAL
11200 buf->b_p_inex = vim_strsave(p_inex);
11201# endif
11202#endif
11203#ifdef FEAT_INS_EXPAND
11204 buf->b_p_dict = empty_option;
11205 buf->b_p_tsr = empty_option;
11206#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011207#ifdef FEAT_TEXTOBJ
11208 buf->b_p_qe = vim_strsave(p_qe);
11209#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011210#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11211 buf->b_p_bexpr = empty_option;
11212#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011213#if defined(FEAT_CRYPT)
11214 buf->b_p_cm = empty_option;
11215#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011216#ifdef FEAT_PERSISTENT_UNDO
11217 buf->b_p_udf = p_udf;
11218#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011219#ifdef FEAT_LISP
11220 buf->b_p_lw = empty_option;
11221#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011222#ifdef FEAT_MBYTE
11223 buf->b_p_menc = empty_option;
11224#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011225
11226 /*
11227 * Don't copy the options set by ex_help(), use the saved values,
11228 * when going from a help buffer to a non-help buffer.
11229 * Don't touch these at all when BCO_NOHELP is used and going from
11230 * or to a help buffer.
11231 */
11232 if (dont_do_help)
11233 buf->b_p_isk = save_p_isk;
11234 else
11235 {
11236 buf->b_p_isk = vim_strsave(p_isk);
11237 did_isk = TRUE;
11238 buf->b_p_ts = p_ts;
11239 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011240 if (buf->b_p_bt[0] == 'h')
11241 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011242 buf->b_p_ma = p_ma;
11243 }
11244 }
11245
11246 /*
11247 * When the options should be copied (ignoring BCO_ALWAYS), set the
11248 * flag that indicates that the options have been initialized.
11249 */
11250 if (should_copy)
11251 buf->b_p_initialized = TRUE;
11252 }
11253
11254 check_buf_options(buf); /* make sure we don't have NULLs */
11255 if (did_isk)
11256 (void)buf_init_chartab(buf, FALSE);
11257}
11258
11259/*
11260 * Reset the 'modifiable' option and its default value.
11261 */
11262 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011263reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011264{
11265 int opt_idx;
11266
11267 curbuf->b_p_ma = FALSE;
11268 p_ma = FALSE;
11269 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011270 if (opt_idx >= 0)
11271 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011272}
11273
11274/*
11275 * Set the global value for 'iminsert' to the local value.
11276 */
11277 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011278set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011279{
11280 p_iminsert = curbuf->b_p_iminsert;
11281}
11282
11283/*
11284 * Set the global value for 'imsearch' to the local value.
11285 */
11286 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011287set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011288{
11289 p_imsearch = curbuf->b_p_imsearch;
11290}
11291
11292#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11293static int expand_option_idx = -1;
11294static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11295static int expand_option_flags = 0;
11296
11297 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011298set_context_in_set_cmd(
11299 expand_T *xp,
11300 char_u *arg,
11301 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011302{
11303 int nextchar;
11304 long_u flags = 0; /* init for GCC */
11305 int opt_idx = 0; /* init for GCC */
11306 char_u *p;
11307 char_u *s;
11308 int is_term_option = FALSE;
11309 int key;
11310
11311 expand_option_flags = opt_flags;
11312
11313 xp->xp_context = EXPAND_SETTINGS;
11314 if (*arg == NUL)
11315 {
11316 xp->xp_pattern = arg;
11317 return;
11318 }
11319 p = arg + STRLEN(arg) - 1;
11320 if (*p == ' ' && *(p - 1) != '\\')
11321 {
11322 xp->xp_pattern = p + 1;
11323 return;
11324 }
11325 while (p > arg)
11326 {
11327 s = p;
11328 /* count number of backslashes before ' ' or ',' */
11329 if (*p == ' ' || *p == ',')
11330 {
11331 while (s > arg && *(s - 1) == '\\')
11332 --s;
11333 }
11334 /* break at a space with an even number of backslashes */
11335 if (*p == ' ' && ((p - s) & 1) == 0)
11336 {
11337 ++p;
11338 break;
11339 }
11340 --p;
11341 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011342 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011343 {
11344 xp->xp_context = EXPAND_BOOL_SETTINGS;
11345 p += 2;
11346 }
11347 if (STRNCMP(p, "inv", 3) == 0)
11348 {
11349 xp->xp_context = EXPAND_BOOL_SETTINGS;
11350 p += 3;
11351 }
11352 xp->xp_pattern = arg = p;
11353 if (*arg == '<')
11354 {
11355 while (*p != '>')
11356 if (*p++ == NUL) /* expand terminal option name */
11357 return;
11358 key = get_special_key_code(arg + 1);
11359 if (key == 0) /* unknown name */
11360 {
11361 xp->xp_context = EXPAND_NOTHING;
11362 return;
11363 }
11364 nextchar = *++p;
11365 is_term_option = TRUE;
11366 expand_option_name[2] = KEY2TERMCAP0(key);
11367 expand_option_name[3] = KEY2TERMCAP1(key);
11368 }
11369 else
11370 {
11371 if (p[0] == 't' && p[1] == '_')
11372 {
11373 p += 2;
11374 if (*p != NUL)
11375 ++p;
11376 if (*p == NUL)
11377 return; /* expand option name */
11378 nextchar = *++p;
11379 is_term_option = TRUE;
11380 expand_option_name[2] = p[-2];
11381 expand_option_name[3] = p[-1];
11382 }
11383 else
11384 {
11385 /* Allow * wildcard */
11386 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11387 p++;
11388 if (*p == NUL)
11389 return;
11390 nextchar = *p;
11391 *p = NUL;
11392 opt_idx = findoption(arg);
11393 *p = nextchar;
11394 if (opt_idx == -1 || options[opt_idx].var == NULL)
11395 {
11396 xp->xp_context = EXPAND_NOTHING;
11397 return;
11398 }
11399 flags = options[opt_idx].flags;
11400 if (flags & P_BOOL)
11401 {
11402 xp->xp_context = EXPAND_NOTHING;
11403 return;
11404 }
11405 }
11406 }
11407 /* handle "-=" and "+=" */
11408 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11409 {
11410 ++p;
11411 nextchar = '=';
11412 }
11413 if ((nextchar != '=' && nextchar != ':')
11414 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11415 {
11416 xp->xp_context = EXPAND_UNSUCCESSFUL;
11417 return;
11418 }
11419 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11420 {
11421 xp->xp_context = EXPAND_OLD_SETTING;
11422 if (is_term_option)
11423 expand_option_idx = -1;
11424 else
11425 expand_option_idx = opt_idx;
11426 xp->xp_pattern = p + 1;
11427 return;
11428 }
11429 xp->xp_context = EXPAND_NOTHING;
11430 if (is_term_option || (flags & P_NUM))
11431 return;
11432
11433 xp->xp_pattern = p + 1;
11434
11435 if (flags & P_EXPAND)
11436 {
11437 p = options[opt_idx].var;
11438 if (p == (char_u *)&p_bdir
11439 || p == (char_u *)&p_dir
11440 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011441 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011442 || p == (char_u *)&p_rtp
11443#ifdef FEAT_SEARCHPATH
11444 || p == (char_u *)&p_cdpath
11445#endif
11446#ifdef FEAT_SESSION
11447 || p == (char_u *)&p_vdir
11448#endif
11449 )
11450 {
11451 xp->xp_context = EXPAND_DIRECTORIES;
11452 if (p == (char_u *)&p_path
11453#ifdef FEAT_SEARCHPATH
11454 || p == (char_u *)&p_cdpath
11455#endif
11456 )
11457 xp->xp_backslash = XP_BS_THREE;
11458 else
11459 xp->xp_backslash = XP_BS_ONE;
11460 }
11461 else
11462 {
11463 xp->xp_context = EXPAND_FILES;
11464 /* for 'tags' need three backslashes for a space */
11465 if (p == (char_u *)&p_tags)
11466 xp->xp_backslash = XP_BS_THREE;
11467 else
11468 xp->xp_backslash = XP_BS_ONE;
11469 }
11470 }
11471
11472 /* For an option that is a list of file names, find the start of the
11473 * last file name. */
11474 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11475 {
11476 /* count number of backslashes before ' ' or ',' */
11477 if (*p == ' ' || *p == ',')
11478 {
11479 s = p;
11480 while (s > xp->xp_pattern && *(s - 1) == '\\')
11481 --s;
11482 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11483 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11484 {
11485 xp->xp_pattern = p + 1;
11486 break;
11487 }
11488 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011489
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011490#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011491 /* for 'spellsuggest' start at "file:" */
11492 if (options[opt_idx].var == (char_u *)&p_sps
11493 && STRNCMP(p, "file:", 5) == 0)
11494 {
11495 xp->xp_pattern = p + 5;
11496 break;
11497 }
11498#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011499 }
11500
11501 return;
11502}
11503
11504 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011505ExpandSettings(
11506 expand_T *xp,
11507 regmatch_T *regmatch,
11508 int *num_file,
11509 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011510{
11511 int num_normal = 0; /* Nr of matching non-term-code settings */
11512 int num_term = 0; /* Nr of matching terminal code settings */
11513 int opt_idx;
11514 int match;
11515 int count = 0;
11516 char_u *str;
11517 int loop;
11518 int is_term_opt;
11519 char_u name_buf[MAX_KEY_NAME_LEN];
11520 static char *(names[]) = {"all", "termcap"};
11521 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11522
11523 /* do this loop twice:
11524 * loop == 0: count the number of matching options
11525 * loop == 1: copy the matching options into allocated memory
11526 */
11527 for (loop = 0; loop <= 1; ++loop)
11528 {
11529 regmatch->rm_ic = ic;
11530 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11531 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011532 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11533 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011534 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11535 {
11536 if (loop == 0)
11537 num_normal++;
11538 else
11539 (*file)[count++] = vim_strsave((char_u *)names[match]);
11540 }
11541 }
11542 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11543 opt_idx++)
11544 {
11545 if (options[opt_idx].var == NULL)
11546 continue;
11547 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11548 && !(options[opt_idx].flags & P_BOOL))
11549 continue;
11550 is_term_opt = istermoption(&options[opt_idx]);
11551 if (is_term_opt && num_normal > 0)
11552 continue;
11553 match = FALSE;
11554 if (vim_regexec(regmatch, str, (colnr_T)0)
11555 || (options[opt_idx].shortname != NULL
11556 && vim_regexec(regmatch,
11557 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11558 match = TRUE;
11559 else if (is_term_opt)
11560 {
11561 name_buf[0] = '<';
11562 name_buf[1] = 't';
11563 name_buf[2] = '_';
11564 name_buf[3] = str[2];
11565 name_buf[4] = str[3];
11566 name_buf[5] = '>';
11567 name_buf[6] = NUL;
11568 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11569 {
11570 match = TRUE;
11571 str = name_buf;
11572 }
11573 }
11574 if (match)
11575 {
11576 if (loop == 0)
11577 {
11578 if (is_term_opt)
11579 num_term++;
11580 else
11581 num_normal++;
11582 }
11583 else
11584 (*file)[count++] = vim_strsave(str);
11585 }
11586 }
11587 /*
11588 * Check terminal key codes, these are not in the option table
11589 */
11590 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11591 {
11592 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11593 {
11594 if (!isprint(str[0]) || !isprint(str[1]))
11595 continue;
11596
11597 name_buf[0] = 't';
11598 name_buf[1] = '_';
11599 name_buf[2] = str[0];
11600 name_buf[3] = str[1];
11601 name_buf[4] = NUL;
11602
11603 match = FALSE;
11604 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11605 match = TRUE;
11606 else
11607 {
11608 name_buf[0] = '<';
11609 name_buf[1] = 't';
11610 name_buf[2] = '_';
11611 name_buf[3] = str[0];
11612 name_buf[4] = str[1];
11613 name_buf[5] = '>';
11614 name_buf[6] = NUL;
11615
11616 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11617 match = TRUE;
11618 }
11619 if (match)
11620 {
11621 if (loop == 0)
11622 num_term++;
11623 else
11624 (*file)[count++] = vim_strsave(name_buf);
11625 }
11626 }
11627
11628 /*
11629 * Check special key names.
11630 */
11631 regmatch->rm_ic = TRUE; /* ignore case here */
11632 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11633 {
11634 name_buf[0] = '<';
11635 STRCPY(name_buf + 1, str);
11636 STRCAT(name_buf, ">");
11637
11638 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11639 {
11640 if (loop == 0)
11641 num_term++;
11642 else
11643 (*file)[count++] = vim_strsave(name_buf);
11644 }
11645 }
11646 }
11647 if (loop == 0)
11648 {
11649 if (num_normal > 0)
11650 *num_file = num_normal;
11651 else if (num_term > 0)
11652 *num_file = num_term;
11653 else
11654 return OK;
11655 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11656 if (*file == NULL)
11657 {
11658 *file = (char_u **)"";
11659 return FAIL;
11660 }
11661 }
11662 }
11663 return OK;
11664}
11665
11666 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011667ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011668{
11669 char_u *var = NULL; /* init for GCC */
11670 char_u *buf;
11671
11672 *num_file = 0;
11673 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11674 if (*file == NULL)
11675 return FAIL;
11676
11677 /*
11678 * For a terminal key code expand_option_idx is < 0.
11679 */
11680 if (expand_option_idx < 0)
11681 {
11682 var = find_termcode(expand_option_name + 2);
11683 if (var == NULL)
11684 expand_option_idx = findoption(expand_option_name);
11685 }
11686
11687 if (expand_option_idx >= 0)
11688 {
11689 /* put string of option value in NameBuff */
11690 option_value2string(&options[expand_option_idx], expand_option_flags);
11691 var = NameBuff;
11692 }
11693 else if (var == NULL)
11694 var = (char_u *)"";
11695
11696 /* A backslash is required before some characters. This is the reverse of
11697 * what happens in do_set(). */
11698 buf = vim_strsave_escaped(var, escape_chars);
11699
11700 if (buf == NULL)
11701 {
11702 vim_free(*file);
11703 *file = NULL;
11704 return FAIL;
11705 }
11706
11707#ifdef BACKSLASH_IN_FILENAME
11708 /* For MS-Windows et al. we don't double backslashes at the start and
11709 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011710 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011711 if (var[0] == '\\' && var[1] == '\\'
11712 && expand_option_idx >= 0
11713 && (options[expand_option_idx].flags & P_EXPAND)
11714 && vim_isfilec(var[2])
11715 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011716 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011717#endif
11718
11719 *file[0] = buf;
11720 *num_file = 1;
11721 return OK;
11722}
11723#endif
11724
11725/*
11726 * Get the value for the numeric or string option *opp in a nice format into
11727 * NameBuff[]. Must not be called with a hidden option!
11728 */
11729 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011730option_value2string(
11731 struct vimoption *opp,
11732 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011733{
11734 char_u *varp;
11735
11736 varp = get_varp_scope(opp, opt_flags);
11737
11738 if (opp->flags & P_NUM)
11739 {
11740 long wc = 0;
11741
11742 if (wc_use_keyname(varp, &wc))
11743 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11744 else if (wc != 0)
11745 STRCPY(NameBuff, transchar((int)wc));
11746 else
11747 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11748 }
11749 else /* P_STRING */
11750 {
11751 varp = *(char_u **)(varp);
11752 if (varp == NULL) /* just in case */
11753 NameBuff[0] = NUL;
11754#ifdef FEAT_CRYPT
11755 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011756 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011757 STRCPY(NameBuff, "*****");
11758#endif
11759 else if (opp->flags & P_EXPAND)
11760 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11761 /* Translate 'pastetoggle' into special key names */
11762 else if ((char_u **)opp->var == &p_pt)
11763 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11764 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011765 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011766 }
11767}
11768
11769/*
11770 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11771 * printed as a keyname.
11772 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11773 */
11774 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011775wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011776{
11777 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11778 {
11779 *wcp = *(long *)varp;
11780 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11781 return TRUE;
11782 }
11783 return FALSE;
11784}
11785
Bram Moolenaar01615492015-02-03 13:00:38 +010011786#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011787/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011788 * Any character has an equivalent 'langmap' character. This is used for
11789 * keyboards that have a special language mode that sends characters above
11790 * 128 (although other characters can be translated too). The "to" field is a
11791 * Vim command character. This avoids having to switch the keyboard back to
11792 * ASCII mode when leaving Insert mode.
11793 *
11794 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11795 * commands.
11796 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11797 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11798 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011799 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011800# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011801/*
11802 * With multi-byte support use growarray for 'langmap' chars >= 256
11803 */
11804typedef struct
11805{
11806 int from;
11807 int to;
11808} langmap_entry_T;
11809
11810static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011811static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011812
11813/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011814 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11815 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011816 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011817 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011818langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011819{
11820 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011821 int a = 0;
11822 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011823
11824 /* Do a binary search for an existing entry. */
11825 while (a != b)
11826 {
11827 int i = (a + b) / 2;
11828 int d = entries[i].from - from;
11829
11830 if (d == 0)
11831 {
11832 entries[i].to = to;
11833 return;
11834 }
11835 if (d < 0)
11836 a = i + 1;
11837 else
11838 b = i;
11839 }
11840
11841 if (ga_grow(&langmap_mapga, 1) != OK)
11842 return; /* out of memory */
11843
11844 /* insert new entry at position "a" */
11845 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11846 mch_memmove(entries + 1, entries,
11847 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11848 ++langmap_mapga.ga_len;
11849 entries[0].from = from;
11850 entries[0].to = to;
11851}
11852
11853/*
11854 * Apply 'langmap' to multi-byte character "c" and return the result.
11855 */
11856 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011857langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011858{
11859 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11860 int a = 0;
11861 int b = langmap_mapga.ga_len;
11862
11863 while (a != b)
11864 {
11865 int i = (a + b) / 2;
11866 int d = entries[i].from - c;
11867
11868 if (d == 0)
11869 return entries[i].to; /* found matching entry */
11870 if (d < 0)
11871 a = i + 1;
11872 else
11873 b = i;
11874 }
11875 return c; /* no entry found, return "c" unmodified */
11876}
11877# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011878
11879 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011880langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011881{
11882 int i;
11883
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011884 for (i = 0; i < 256; i++)
11885 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11886# ifdef FEAT_MBYTE
11887 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11888# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011889}
11890
11891/*
11892 * Called when langmap option is set; the language map can be
11893 * changed at any time!
11894 */
11895 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011896langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011897{
11898 char_u *p;
11899 char_u *p2;
11900 int from, to;
11901
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011902#ifdef FEAT_MBYTE
11903 ga_clear(&langmap_mapga); /* clear the previous map first */
11904#endif
11905 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011906
11907 for (p = p_langmap; p[0] != NUL; )
11908 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011909 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011910 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011911 {
11912 if (p2[0] == '\\' && p2[1] != NUL)
11913 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011914 }
11915 if (p2[0] == ';')
11916 ++p2; /* abcd;ABCD form, p2 points to A */
11917 else
11918 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11919 while (p[0])
11920 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011921 if (p[0] == ',')
11922 {
11923 ++p;
11924 break;
11925 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011926 if (p[0] == '\\' && p[1] != NUL)
11927 ++p;
11928#ifdef FEAT_MBYTE
11929 from = (*mb_ptr2char)(p);
11930#else
11931 from = p[0];
11932#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011933 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011934 if (p2 == NULL)
11935 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011936 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011937 if (p[0] != ',')
11938 {
11939 if (p[0] == '\\')
11940 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011941#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011942 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011943#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011944 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011945#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011946 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011947 }
11948 else
11949 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011950 if (p2[0] != ',')
11951 {
11952 if (p2[0] == '\\')
11953 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011954#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011955 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011956#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011957 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011958#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011959 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011960 }
11961 if (to == NUL)
11962 {
11963 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11964 transchar(from));
11965 return;
11966 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011967
11968#ifdef FEAT_MBYTE
11969 if (from >= 256)
11970 langmap_set_entry(from, to);
11971 else
11972#endif
11973 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011974
11975 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011976 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011977 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011978 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011979 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011980 if (*p == ';')
11981 {
11982 p = p2;
11983 if (p[0] != NUL)
11984 {
11985 if (p[0] != ',')
11986 {
11987 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11988 return;
11989 }
11990 ++p;
11991 }
11992 break;
11993 }
11994 }
11995 }
11996 }
11997}
11998#endif
11999
12000/*
12001 * Return TRUE if format option 'x' is in effect.
12002 * Take care of no formatting when 'paste' is set.
12003 */
12004 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012005has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012006{
12007 if (p_paste)
12008 return FALSE;
12009 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12010}
12011
12012/*
12013 * Return TRUE if "x" is present in 'shortmess' option, or
12014 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12015 */
12016 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012017shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012018{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012019 return p_shm != NULL &&
12020 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012021 || (vim_strchr(p_shm, 'a') != NULL
12022 && vim_strchr((char_u *)SHM_A, x) != NULL));
12023}
12024
12025/*
12026 * paste_option_changed() - Called after p_paste was set or reset.
12027 */
12028 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012029paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012030{
12031 static int old_p_paste = FALSE;
12032 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012033 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012034#ifdef FEAT_CMDL_INFO
12035 static int save_ru = 0;
12036#endif
12037#ifdef FEAT_RIGHTLEFT
12038 static int save_ri = 0;
12039 static int save_hkmap = 0;
12040#endif
12041 buf_T *buf;
12042
12043 if (p_paste)
12044 {
12045 /*
12046 * Paste switched from off to on.
12047 * Save the current values, so they can be restored later.
12048 */
12049 if (!old_p_paste)
12050 {
12051 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012052 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012053 {
12054 buf->b_p_tw_nopaste = buf->b_p_tw;
12055 buf->b_p_wm_nopaste = buf->b_p_wm;
12056 buf->b_p_sts_nopaste = buf->b_p_sts;
12057 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012058 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012059 }
12060
12061 /* save global options */
12062 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012063 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012064#ifdef FEAT_CMDL_INFO
12065 save_ru = p_ru;
12066#endif
12067#ifdef FEAT_RIGHTLEFT
12068 save_ri = p_ri;
12069 save_hkmap = p_hkmap;
12070#endif
12071 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012072 p_ai_nopaste = p_ai;
12073 p_et_nopaste = p_et;
12074 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012075 p_tw_nopaste = p_tw;
12076 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012077 }
12078
12079 /*
12080 * Always set the option values, also when 'paste' is set when it is
12081 * already on.
12082 */
12083 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012084 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012085 {
12086 buf->b_p_tw = 0; /* textwidth is 0 */
12087 buf->b_p_wm = 0; /* wrapmargin is 0 */
12088 buf->b_p_sts = 0; /* softtabstop is 0 */
12089 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012090 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012091 }
12092
12093 /* set global options */
12094 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012095 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012096#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012097 if (p_ru)
12098 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012099 p_ru = 0; /* no ruler */
12100#endif
12101#ifdef FEAT_RIGHTLEFT
12102 p_ri = 0; /* no reverse insert */
12103 p_hkmap = 0; /* no Hebrew keyboard */
12104#endif
12105 /* set global values for local buffer options */
12106 p_tw = 0;
12107 p_wm = 0;
12108 p_sts = 0;
12109 p_ai = 0;
12110 }
12111
12112 /*
12113 * Paste switched from on to off: Restore saved values.
12114 */
12115 else if (old_p_paste)
12116 {
12117 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012118 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012119 {
12120 buf->b_p_tw = buf->b_p_tw_nopaste;
12121 buf->b_p_wm = buf->b_p_wm_nopaste;
12122 buf->b_p_sts = buf->b_p_sts_nopaste;
12123 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012124 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012125 }
12126
12127 /* restore global options */
12128 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012129 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012130#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012131 if (p_ru != save_ru)
12132 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012133 p_ru = save_ru;
12134#endif
12135#ifdef FEAT_RIGHTLEFT
12136 p_ri = save_ri;
12137 p_hkmap = save_hkmap;
12138#endif
12139 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012140 p_ai = p_ai_nopaste;
12141 p_et = p_et_nopaste;
12142 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012143 p_tw = p_tw_nopaste;
12144 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012145 }
12146
12147 old_p_paste = p_paste;
12148}
12149
12150/*
12151 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12152 *
12153 * Reset 'compatible' and set the values for options that didn't get set yet
12154 * to the Vim defaults.
12155 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012156 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012157 */
12158 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012159vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012160{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012161 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012162 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012163 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012164
12165 if (!option_was_set((char_u *)"cp"))
12166 {
12167 p_cp = FALSE;
12168 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12169 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12170 set_option_default(opt_idx, OPT_FREE, FALSE);
12171 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012172 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012173 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012174
12175 if (fname != NULL)
12176 {
12177 p = vim_getenv(envname, &dofree);
12178 if (p == NULL)
12179 {
12180 /* Set $MYVIMRC to the first vimrc file found. */
12181 p = FullName_save(fname, FALSE);
12182 if (p != NULL)
12183 {
12184 vim_setenv(envname, p);
12185 vim_free(p);
12186 }
12187 }
12188 else if (dofree)
12189 vim_free(p);
12190 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012191}
12192
12193/*
12194 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12195 */
12196 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012197change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012198{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012199 int opt_idx;
12200
Bram Moolenaar071d4272004-06-13 20:20:40 +000012201 if (p_cp != on)
12202 {
12203 p_cp = on;
12204 compatible_set();
12205 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012206 opt_idx = findoption((char_u *)"cp");
12207 if (opt_idx >= 0)
12208 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012209}
12210
12211/*
12212 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012213 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012214 */
12215 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012216option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012217{
12218 int idx;
12219
12220 idx = findoption(name);
12221 if (idx < 0) /* unknown option */
12222 return FALSE;
12223 if (options[idx].flags & P_WAS_SET)
12224 return TRUE;
12225 return FALSE;
12226}
12227
12228/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012229 * Reset the flag indicating option "name" was set.
12230 */
12231 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012232reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012233{
12234 int idx = findoption(name);
12235
12236 if (idx >= 0)
12237 options[idx].flags &= ~P_WAS_SET;
12238}
12239
12240/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012241 * compatible_set() - Called when 'compatible' has been set or unset.
12242 *
12243 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12244 * flag) to a Vi compatible value.
12245 * When 'compatible' is unset: Set all options that have a different default
12246 * for Vim (without the P_VI_DEF flag) to that default.
12247 */
12248 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012249compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012250{
12251 int opt_idx;
12252
12253 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12254 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12255 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12256 set_option_default(opt_idx, OPT_FREE, p_cp);
12257 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012258 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012259}
12260
12261#ifdef FEAT_LINEBREAK
12262
12263# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12264 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012265 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012266# endif
12267
12268/*
12269 * fill_breakat_flags() -- called when 'breakat' changes value.
12270 */
12271 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012272fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012273{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012274 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012275 int i;
12276
12277 for (i = 0; i < 256; i++)
12278 breakat_flags[i] = FALSE;
12279
12280 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012281 for (p = p_breakat; *p; p++)
12282 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012283}
12284
12285# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012286 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012287# endif
12288
12289#endif
12290
12291/*
12292 * Check an option that can be a range of string values.
12293 *
12294 * Return OK for correct value, FAIL otherwise.
12295 * Empty is always OK.
12296 */
12297 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012298check_opt_strings(
12299 char_u *val,
12300 char **values,
12301 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012302{
12303 return opt_strings_flags(val, values, NULL, list);
12304}
12305
12306/*
12307 * Handle an option that can be a range of string values.
12308 * Set a flag in "*flagp" for each string present.
12309 *
12310 * Return OK for correct value, FAIL otherwise.
12311 * Empty is always OK.
12312 */
12313 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012314opt_strings_flags(
12315 char_u *val, /* new value */
12316 char **values, /* array of valid string values */
12317 unsigned *flagp,
12318 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012319{
12320 int i;
12321 int len;
12322 unsigned new_flags = 0;
12323
12324 while (*val)
12325 {
12326 for (i = 0; ; ++i)
12327 {
12328 if (values[i] == NULL) /* val not found in values[] */
12329 return FAIL;
12330
12331 len = (int)STRLEN(values[i]);
12332 if (STRNCMP(values[i], val, len) == 0
12333 && ((list && val[len] == ',') || val[len] == NUL))
12334 {
12335 val += len + (val[len] == ',');
12336 new_flags |= (1 << i);
12337 break; /* check next item in val list */
12338 }
12339 }
12340 }
12341 if (flagp != NULL)
12342 *flagp = new_flags;
12343
12344 return OK;
12345}
12346
12347/*
12348 * Read the 'wildmode' option, fill wim_flags[].
12349 */
12350 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012351check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012352{
12353 char_u new_wim_flags[4];
12354 char_u *p;
12355 int i;
12356 int idx = 0;
12357
12358 for (i = 0; i < 4; ++i)
12359 new_wim_flags[i] = 0;
12360
12361 for (p = p_wim; *p; ++p)
12362 {
12363 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12364 ;
12365 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12366 return FAIL;
12367 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12368 new_wim_flags[idx] |= WIM_LONGEST;
12369 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12370 new_wim_flags[idx] |= WIM_FULL;
12371 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12372 new_wim_flags[idx] |= WIM_LIST;
12373 else
12374 return FAIL;
12375 p += i;
12376 if (*p == NUL)
12377 break;
12378 if (*p == ',')
12379 {
12380 if (idx == 3)
12381 return FAIL;
12382 ++idx;
12383 }
12384 }
12385
12386 /* fill remaining entries with last flag */
12387 while (idx < 3)
12388 {
12389 new_wim_flags[idx + 1] = new_wim_flags[idx];
12390 ++idx;
12391 }
12392
12393 /* only when there are no errors, wim_flags[] is changed */
12394 for (i = 0; i < 4; ++i)
12395 wim_flags[i] = new_wim_flags[i];
12396 return OK;
12397}
12398
12399/*
12400 * Check if backspacing over something is allowed.
12401 */
12402 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012403can_bs(
12404 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012405{
12406 switch (*p_bs)
12407 {
12408 case '2': return TRUE;
12409 case '1': return (what != BS_START);
12410 case '0': return FALSE;
12411 }
12412 return vim_strchr(p_bs, what) != NULL;
12413}
12414
12415/*
12416 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12417 * the file must be considered changed when the value is different.
12418 */
12419 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012420save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012421{
12422 buf->b_start_ffc = *buf->b_p_ff;
12423 buf->b_start_eol = buf->b_p_eol;
12424#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012425 buf->b_start_bomb = buf->b_p_bomb;
12426
Bram Moolenaar071d4272004-06-13 20:20:40 +000012427 /* Only use free/alloc when necessary, they take time. */
12428 if (buf->b_start_fenc == NULL
12429 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12430 {
12431 vim_free(buf->b_start_fenc);
12432 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12433 }
12434#endif
12435}
12436
12437/*
12438 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12439 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012440 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12441 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012442 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012443 * When "ignore_empty" is true don't consider a new, empty buffer to be
12444 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012445 */
12446 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012447file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012448{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012449 /* In a buffer that was never loaded the options are not valid. */
12450 if (buf->b_flags & BF_NEVERLOADED)
12451 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012452 if (ignore_empty
12453 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012454 && buf->b_ml.ml_line_count == 1
12455 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12456 return FALSE;
12457 if (buf->b_start_ffc != *buf->b_p_ff)
12458 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012459 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012460 return TRUE;
12461#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012462 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12463 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012464 if (buf->b_start_fenc == NULL)
12465 return (*buf->b_p_fenc != NUL);
12466 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12467#else
12468 return FALSE;
12469#endif
12470}
12471
12472/*
12473 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12474 */
12475 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012476check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012477{
12478 return check_opt_strings(p, p_ff_values, FALSE);
12479}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012480
12481/*
12482 * Return the effective shiftwidth value for current buffer, using the
12483 * 'tabstop' value when 'shiftwidth' is zero.
12484 */
12485 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012486get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012487{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012488 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012489}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012490
12491/*
12492 * Return the effective softtabstop value for the current buffer, using the
12493 * 'tabstop' value when 'softtabstop' is negative.
12494 */
12495 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012496get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012497{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012498 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012499}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012500
12501/*
12502 * Check matchpairs option for "*initc".
12503 * If there is a match set "*initc" to the matching character and "*findc" to
12504 * the opposite character. Set "*backwards" to the direction.
12505 * When "switchit" is TRUE swap the direction.
12506 */
12507 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012508find_mps_values(
12509 int *initc,
12510 int *findc,
12511 int *backwards,
12512 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012513{
12514 char_u *ptr;
12515
12516 ptr = curbuf->b_p_mps;
12517 while (*ptr != NUL)
12518 {
12519#ifdef FEAT_MBYTE
12520 if (has_mbyte)
12521 {
12522 char_u *prev;
12523
12524 if (mb_ptr2char(ptr) == *initc)
12525 {
12526 if (switchit)
12527 {
12528 *findc = *initc;
12529 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12530 *backwards = TRUE;
12531 }
12532 else
12533 {
12534 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12535 *backwards = FALSE;
12536 }
12537 return;
12538 }
12539 prev = ptr;
12540 ptr += mb_ptr2len(ptr) + 1;
12541 if (mb_ptr2char(ptr) == *initc)
12542 {
12543 if (switchit)
12544 {
12545 *findc = *initc;
12546 *initc = mb_ptr2char(prev);
12547 *backwards = FALSE;
12548 }
12549 else
12550 {
12551 *findc = mb_ptr2char(prev);
12552 *backwards = TRUE;
12553 }
12554 return;
12555 }
12556 ptr += mb_ptr2len(ptr);
12557 }
12558 else
12559#endif
12560 {
12561 if (*ptr == *initc)
12562 {
12563 if (switchit)
12564 {
12565 *backwards = TRUE;
12566 *findc = *initc;
12567 *initc = ptr[2];
12568 }
12569 else
12570 {
12571 *backwards = FALSE;
12572 *findc = ptr[2];
12573 }
12574 return;
12575 }
12576 ptr += 2;
12577 if (*ptr == *initc)
12578 {
12579 if (switchit)
12580 {
12581 *backwards = FALSE;
12582 *findc = *initc;
12583 *initc = ptr[-2];
12584 }
12585 else
12586 {
12587 *backwards = TRUE;
12588 *findc = ptr[-2];
12589 }
12590 return;
12591 }
12592 ++ptr;
12593 }
12594 if (*ptr == ',')
12595 ++ptr;
12596 }
12597}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012598
12599#if defined(FEAT_LINEBREAK) || defined(PROTO)
12600/*
12601 * This is called when 'breakindentopt' is changed and when a window is
12602 * initialized.
12603 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012604 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012605briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012606{
12607 char_u *p;
12608 int bri_shift = 0;
12609 long bri_min = 20;
12610 int bri_sbr = FALSE;
12611
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012612 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012613 while (*p != NUL)
12614 {
12615 if (STRNCMP(p, "shift:", 6) == 0
12616 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12617 {
12618 p += 6;
12619 bri_shift = getdigits(&p);
12620 }
12621 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12622 {
12623 p += 4;
12624 bri_min = getdigits(&p);
12625 }
12626 else if (STRNCMP(p, "sbr", 3) == 0)
12627 {
12628 p += 3;
12629 bri_sbr = TRUE;
12630 }
12631 if (*p != ',' && *p != NUL)
12632 return FAIL;
12633 if (*p == ',')
12634 ++p;
12635 }
12636
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012637 wp->w_p_brishift = bri_shift;
12638 wp->w_p_brimin = bri_min;
12639 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012640
12641 return OK;
12642}
12643#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012644
12645/*
12646 * Get the local or global value of 'backupcopy'.
12647 */
12648 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012649get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012650{
12651 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12652}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012653
12654#if defined(FEAT_SIGNS) || defined(PROTO)
12655/*
12656 * Return TRUE when window "wp" has a column to draw signs in.
12657 */
12658 int
12659signcolumn_on(win_T *wp)
12660{
12661 if (*wp->w_p_scl == 'n')
12662 return FALSE;
12663 if (*wp->w_p_scl == 'y')
12664 return TRUE;
12665 return (wp->w_buffer->b_signlist != NULL
12666# ifdef FEAT_NETBEANS_INTG
12667 || wp->w_buffer->b_has_sign_column
12668# endif
12669 );
12670}
12671#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012672
12673#if defined(FEAT_EVAL) || defined(PROTO)
12674/*
12675 * Get window or buffer local options.
12676 */
12677 dict_T *
12678get_winbuf_options(int bufopt)
12679{
12680 dict_T *d;
12681 int opt_idx;
12682
12683 d = dict_alloc();
12684 if (d == NULL)
12685 return NULL;
12686
12687 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12688 {
12689 struct vimoption *opt = &options[opt_idx];
12690
12691 if ((bufopt && (opt->indir & PV_BUF))
12692 || (!bufopt && (opt->indir & PV_WIN)))
12693 {
12694 char_u *varp = get_varp(opt);
12695
12696 if (varp != NULL)
12697 {
12698 if (opt->flags & P_STRING)
12699 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012700 else if (opt->flags & P_NUM)
12701 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012702 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012703 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012704 }
12705 }
12706 }
12707
12708 return d;
12709}
12710#endif