blob: 4e2b929693fe7494f081e2644317e9bb041dd5c3 [file] [log] [blame]
Bram Moolenaaredf3f972016-08-29 22:49:24 +02001/* vi:set ts=8 sts=4 sw=4 noet:
Bram Moolenaar071d4272004-06-13 20:20:40 +00002 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * Code to handle user-settable options. This is all pretty much table-
12 * driven. Checklist for adding a new option:
13 * - Put it in the options array below (copy an existing entry).
14 * - For a global option: Add a variable for it in option.h.
15 * - For a buffer or window local option:
16 * - Add a PV_XX entry to the enum below.
17 * - Add a variable to the window or buffer struct in structs.h.
18 * - For a window option, add some code to copy_winopt().
19 * - For a buffer option, add some code to buf_copy_options().
20 * - For a buffer string option, add code to check_buf_options().
21 * - If it's a numeric option, add any necessary bounds checks to do_set().
22 * - If it's a list of flags, add some code in do_set(), search for WW_ALL.
23 * - When adding an option with expansion (P_EXPAND), but with a different
24 * default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP.
Bram Moolenaarcea912a2016-10-12 14:20:24 +020025 * - Add documentation! One line in doc/quickref.txt, full description in
Bram Moolenaar071d4272004-06-13 20:20:40 +000026 * options.txt, and any other related places.
27 * - Add an entry in runtime/optwin.vim.
28 * When making changes:
29 * - Adjust the help for the option in doc/option.txt.
30 * - When an entry has the P_VIM flag, or is lacking the P_VI_DEF flag, add a
31 * comment at the help for the 'compatible' option.
32 */
33
34#define IN_OPTION_C
35#include "vim.h"
36
37/*
38 * The options that are local to a window or buffer have "indir" set to one of
39 * these values. Special values:
40 * PV_NONE: global option.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000041 * PV_WIN is added: window-local option
42 * PV_BUF is added: buffer-local option
Bram Moolenaar071d4272004-06-13 20:20:40 +000043 * PV_BOTH is added: global option which also has a local value.
44 */
45#define PV_BOTH 0x1000
Bram Moolenaara23ccb82006-02-27 00:08:02 +000046#define PV_WIN 0x2000
47#define PV_BUF 0x4000
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000048#define PV_MASK 0x0fff
Bram Moolenaara23ccb82006-02-27 00:08:02 +000049#define OPT_WIN(x) (idopt_T)(PV_WIN + (int)(x))
50#define OPT_BUF(x) (idopt_T)(PV_BUF + (int)(x))
Bram Moolenaar071d4272004-06-13 20:20:40 +000051#define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
52
Bram Moolenaara23ccb82006-02-27 00:08:02 +000053/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000054 * Definition of the PV_ values for buffer-local options.
55 * The BV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000056 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +000057#define PV_AI OPT_BUF(BV_AI)
58#define PV_AR OPT_BOTH(OPT_BUF(BV_AR))
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020059#define PV_BKC OPT_BOTH(OPT_BUF(BV_BKC))
Bram Moolenaar81bdd6a2017-07-23 22:57:00 +020060#define PV_BH OPT_BUF(BV_BH)
61#define PV_BT OPT_BUF(BV_BT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000062#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000063# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
64# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
65# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000066#endif
67#define PV_BIN OPT_BUF(BV_BIN)
68#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000069#ifdef FEAT_MBYTE
70# define PV_BOMB OPT_BUF(BV_BOMB)
71#endif
72#define PV_CI OPT_BUF(BV_CI)
73#ifdef FEAT_CINDENT
74# define PV_CIN OPT_BUF(BV_CIN)
75# define PV_CINK OPT_BUF(BV_CINK)
76# define PV_CINO OPT_BUF(BV_CINO)
77#endif
78#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
79# define PV_CINW OPT_BUF(BV_CINW)
80#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020081#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000082#ifdef FEAT_FOLDING
83# define PV_CMS OPT_BUF(BV_CMS)
84#endif
85#ifdef FEAT_COMMENTS
86# define PV_COM OPT_BUF(BV_COM)
87#endif
88#ifdef FEAT_INS_EXPAND
89# define PV_CPT OPT_BUF(BV_CPT)
90# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
91# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
92#endif
93#ifdef FEAT_COMPL_FUNC
94# define PV_CFU OPT_BUF(BV_CFU)
95#endif
96#ifdef FEAT_FIND_ID
97# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
98# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
99#endif
100#define PV_EOL OPT_BUF(BV_EOL)
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200101#define PV_FIXEOL OPT_BUF(BV_FIXEOL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000102#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
103#define PV_ET OPT_BUF(BV_ET)
104#ifdef FEAT_MBYTE
105# define PV_FENC OPT_BUF(BV_FENC)
106#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000107#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
108# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
109#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100110#define PV_FP OPT_BOTH(OPT_BUF(BV_FP))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000111#ifdef FEAT_EVAL
112# define PV_FEX OPT_BUF(BV_FEX)
113#endif
114#define PV_FF OPT_BUF(BV_FF)
115#define PV_FLP OPT_BUF(BV_FLP)
116#define PV_FO OPT_BUF(BV_FO)
117#ifdef FEAT_AUTOCMD
118# define PV_FT OPT_BUF(BV_FT)
119#endif
120#define PV_IMI OPT_BUF(BV_IMI)
121#define PV_IMS OPT_BUF(BV_IMS)
122#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
123# define PV_INDE OPT_BUF(BV_INDE)
124# define PV_INDK OPT_BUF(BV_INDK)
125#endif
126#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
127# define PV_INEX OPT_BUF(BV_INEX)
128#endif
129#define PV_INF OPT_BUF(BV_INF)
130#define PV_ISK OPT_BUF(BV_ISK)
131#ifdef FEAT_CRYPT
132# define PV_KEY OPT_BUF(BV_KEY)
133#endif
134#ifdef FEAT_KEYMAP
135# define PV_KMAP OPT_BUF(BV_KMAP)
136#endif
137#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
138#ifdef FEAT_LISP
139# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100140# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000141#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +0100142#ifdef FEAT_MBYTE
143# define PV_MENC OPT_BOTH(OPT_BUF(BV_MENC))
144#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000145#define PV_MA OPT_BUF(BV_MA)
146#define PV_ML OPT_BUF(BV_ML)
147#define PV_MOD OPT_BUF(BV_MOD)
148#define PV_MPS OPT_BUF(BV_MPS)
149#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000150#ifdef FEAT_COMPL_FUNC
151# define PV_OFU OPT_BUF(BV_OFU)
152#endif
153#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
154#define PV_PI OPT_BUF(BV_PI)
155#ifdef FEAT_TEXTOBJ
156# define PV_QE OPT_BUF(BV_QE)
157#endif
158#define PV_RO OPT_BUF(BV_RO)
159#ifdef FEAT_SMARTINDENT
160# define PV_SI OPT_BUF(BV_SI)
161#endif
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100162#define PV_SN OPT_BUF(BV_SN)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000163#ifdef FEAT_SYN_HL
164# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000165# define PV_SYN OPT_BUF(BV_SYN)
166#endif
167#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000168# define PV_SPC OPT_BUF(BV_SPC)
169# define PV_SPF OPT_BUF(BV_SPF)
170# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000171#endif
172#define PV_STS OPT_BUF(BV_STS)
173#ifdef FEAT_SEARCHPATH
174# define PV_SUA OPT_BUF(BV_SUA)
175#endif
176#define PV_SW OPT_BUF(BV_SW)
177#define PV_SWF OPT_BUF(BV_SWF)
178#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
Bram Moolenaar0f6562e2015-11-24 18:48:14 +0100179#define PV_TC OPT_BOTH(OPT_BUF(BV_TC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000180#define PV_TS OPT_BUF(BV_TS)
181#define PV_TW OPT_BUF(BV_TW)
182#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200183#ifdef FEAT_PERSISTENT_UNDO
184# define PV_UDF OPT_BUF(BV_UDF)
185#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000186#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000187
188/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000189 * Definition of the PV_ values for window-local options.
190 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000191 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000192#define PV_LIST OPT_WIN(WV_LIST)
193#ifdef FEAT_ARABIC
194# define PV_ARAB OPT_WIN(WV_ARAB)
195#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200196#ifdef FEAT_LINEBREAK
197# define PV_BRI OPT_WIN(WV_BRI)
198# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
199#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000200#ifdef FEAT_DIFF
201# define PV_DIFF OPT_WIN(WV_DIFF)
202#endif
203#ifdef FEAT_FOLDING
204# define PV_FDC OPT_WIN(WV_FDC)
205# define PV_FEN OPT_WIN(WV_FEN)
206# define PV_FDI OPT_WIN(WV_FDI)
207# define PV_FDL OPT_WIN(WV_FDL)
208# define PV_FDM OPT_WIN(WV_FDM)
209# define PV_FML OPT_WIN(WV_FML)
210# define PV_FDN OPT_WIN(WV_FDN)
211# ifdef FEAT_EVAL
212# define PV_FDE OPT_WIN(WV_FDE)
213# define PV_FDT OPT_WIN(WV_FDT)
214# endif
215# define PV_FMR OPT_WIN(WV_FMR)
216#endif
217#ifdef FEAT_LINEBREAK
218# define PV_LBR OPT_WIN(WV_LBR)
219#endif
220#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200221#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000222#ifdef FEAT_LINEBREAK
223# define PV_NUW OPT_WIN(WV_NUW)
224#endif
Bram Moolenaar4033c552017-09-16 20:54:51 +0200225#if defined(FEAT_QUICKFIX)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000226# define PV_PVW OPT_WIN(WV_PVW)
227#endif
228#ifdef FEAT_RIGHTLEFT
229# define PV_RL OPT_WIN(WV_RL)
230# define PV_RLC OPT_WIN(WV_RLC)
231#endif
232#ifdef FEAT_SCROLLBIND
233# define PV_SCBIND OPT_WIN(WV_SCBIND)
234#endif
235#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000236#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000237# define PV_SPELL OPT_WIN(WV_SPELL)
238#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000239#ifdef FEAT_SYN_HL
240# define PV_CUC OPT_WIN(WV_CUC)
241# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200242# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000243#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000244#ifdef FEAT_STL_OPT
245# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
246#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100247#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000248# define PV_WFH OPT_WIN(WV_WFH)
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000249# define PV_WFW OPT_WIN(WV_WFW)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000250#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200251#ifdef FEAT_CURSORBIND
252# define PV_CRBIND OPT_WIN(WV_CRBIND)
253#endif
254#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200255# define PV_COCU OPT_WIN(WV_COCU)
256# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200257#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200258#ifdef FEAT_TERMINAL
Bram Moolenaar1b0675c2017-07-15 14:04:01 +0200259# define PV_TK OPT_WIN(WV_TK)
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200260# define PV_TMS OPT_WIN(WV_TMS)
261#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200262#ifdef FEAT_SIGNS
263# define PV_SCL OPT_WIN(WV_SCL)
264#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000265
266/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000267typedef enum
268{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000269 PV_NONE = 0,
270 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000271} idopt_T;
272
273/*
274 * Options local to a window have a value local to a buffer and global to all
275 * buffers. Indicate this by setting "var" to VAR_WIN.
276 */
277#define VAR_WIN ((char_u *)-1)
278
279/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000280 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000281 * Only to be used in option.c!
282 */
283static int p_ai;
284static int p_bin;
285#ifdef FEAT_MBYTE
286static int p_bomb;
287#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000288static char_u *p_bh;
289static char_u *p_bt;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000290static int p_bl;
291static int p_ci;
292#ifdef FEAT_CINDENT
293static int p_cin;
294static char_u *p_cink;
295static char_u *p_cino;
296#endif
297#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
298static char_u *p_cinw;
299#endif
300#ifdef FEAT_COMMENTS
301static char_u *p_com;
302#endif
303#ifdef FEAT_FOLDING
304static char_u *p_cms;
305#endif
306#ifdef FEAT_INS_EXPAND
307static char_u *p_cpt;
308#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000309#ifdef FEAT_COMPL_FUNC
310static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000311static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000312#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000313static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200314static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000315static int p_et;
316#ifdef FEAT_MBYTE
317static char_u *p_fenc;
318#endif
319static char_u *p_ff;
320static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000321static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000322#ifdef FEAT_AUTOCMD
323static char_u *p_ft;
324#endif
325static long p_iminsert;
326static long p_imsearch;
327#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
328static char_u *p_inex;
329#endif
330#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
331static char_u *p_inde;
332static char_u *p_indk;
333#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000334#if defined(FEAT_EVAL)
335static char_u *p_fex;
336#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000337static int p_inf;
338static char_u *p_isk;
339#ifdef FEAT_CRYPT
340static char_u *p_key;
341#endif
342#ifdef FEAT_LISP
343static int p_lisp;
344#endif
345static int p_ml;
346static int p_ma;
347static int p_mod;
348static char_u *p_mps;
349static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000350static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000351#ifdef FEAT_TEXTOBJ
352static char_u *p_qe;
353#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000354static int p_ro;
355#ifdef FEAT_SMARTINDENT
356static int p_si;
357#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000358static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000359static long p_sts;
360#if defined(FEAT_SEARCHPATH)
361static char_u *p_sua;
362#endif
363static long p_sw;
364static int p_swf;
365#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000366static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000367static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000368#endif
369#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000370static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000371static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000372static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000373#endif
374static long p_ts;
375static long p_tw;
376static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200377#ifdef FEAT_PERSISTENT_UNDO
378static int p_udf;
379#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000380static long p_wm;
381#ifdef FEAT_KEYMAP
382static char_u *p_keymap;
383#endif
384
385/* Saved values for when 'bin' is set. */
386static int p_et_nobin;
387static int p_ml_nobin;
388static long p_tw_nobin;
389static long p_wm_nobin;
390
391/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200392static int p_ai_nopaste;
393static int p_et_nopaste;
394static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000395static long p_tw_nopaste;
396static long p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000397
398struct vimoption
399{
400 char *fullname; /* full option name */
401 char *shortname; /* permissible abbreviation */
402 long_u flags; /* see below */
403 char_u *var; /* global option: pointer to variable;
404 * window-local option: VAR_WIN;
405 * buffer-local option: global value */
406 idopt_T indir; /* global option: PV_NONE;
407 * local option: indirect option index */
408 char_u *def_val[2]; /* default values for variable (vi and vim) */
409#ifdef FEAT_EVAL
410 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000411# define SCRIPTID_INIT , 0
412#else
413# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000414#endif
415};
416
417#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
418#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
419
420/*
421 * Flags
422 */
423#define P_BOOL 0x01 /* the option is boolean */
424#define P_NUM 0x02 /* the option is numeric */
425#define P_STRING 0x04 /* the option is a string */
426#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000427 must use free_string_option() when
428 assigning new value. Not set if default is
429 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000430#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
431 never be used for local or hidden options! */
432#define P_NODEFAULT 0x40 /* don't set to default value */
433#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
434 use vim_free() when assigning new value */
435#define P_WAS_SET 0x100 /* option has been set/reset */
436#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
437#define P_VI_DEF 0x400 /* Use Vi default for Vim */
438#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
439
440 /* when option changed, what to display: */
441#define P_RSTAT 0x1000 /* redraw status lines */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100442#define P_RWIN 0x2000 /* redraw current window and recompute text */
443#define P_RBUF 0x4000 /* redraw current buffer and recompute text */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000444#define P_RALL 0x6000 /* redraw all windows */
445#define P_RCLR 0x7000 /* clear and redraw all */
446
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200447#define P_COMMA 0x8000 /* comma separated list */
448#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
449 * commas */
450#define P_NODUP 0x20000L /* don't allow duplicate strings */
451#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000452
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200453#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
454#define P_GETTEXT 0x100000L /* expand default value with _() */
455#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
456#define P_NFNAME 0x400000L /* only normal file name chars allowed */
457#define P_INSECURE 0x800000L /* option was set from a modeline */
458#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7554da42016-11-25 22:04:13 +0100459 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200460#define P_NO_ML 0x2000000L /* not allowed in modeline */
461#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200462 * there is a redraw flag */
Bram Moolenaar7554da42016-11-25 22:04:13 +0100463#define P_NDNAME 0x8000000L /* only normal dir name chars allowed */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100464#define P_RWINONLY 0x10000000L /* only redraw current window */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000465
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000466#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
467
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000468/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
469 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100470#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000471# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000472#else
473# define ISP_LATIN1 (char_u *)"@,161-255"
474#endif
475
Bram Moolenaar05fbfdc2017-08-14 22:35:08 +0200476# define HIGHLIGHT_INIT "8:SpecialKey,~:EndOfBuffer,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn,q:QuickFixLine,z:StatusLineTerm,Z:StatusLineTermNC"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000477
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +0100478/* Default python version for pyx* commands */
479#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
480# define DEFAULT_PYTHON_VER 0
481#elif defined(FEAT_PYTHON3)
482# define DEFAULT_PYTHON_VER 3
483#elif defined(FEAT_PYTHON)
484# define DEFAULT_PYTHON_VER 2
485#else
486# define DEFAULT_PYTHON_VER 0
487#endif
488
Bram Moolenaar071d4272004-06-13 20:20:40 +0000489/*
490 * options[] is initialized here.
491 * The order of the options MUST be alphabetic for ":set all" and findoption().
492 * All option names MUST start with a lowercase letter (for findoption()).
493 * Exception: "t_" options are at the end.
494 * The options with a NULL variable are 'hidden': a set command for them is
495 * ignored and they are not printed.
496 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100497static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000498{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200499 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000500#ifdef FEAT_RIGHTLEFT
501 (char_u *)&p_aleph, PV_NONE,
502#else
503 (char_u *)NULL, PV_NONE,
504#endif
505 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100506#if (defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000507 (char_u *)128L,
508#else
509 (char_u *)224L,
510#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000511 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000512 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
513#if defined(FEAT_GUI) && defined(MACOS_X)
514 (char_u *)&p_antialias, PV_NONE,
515 {(char_u *)FALSE, (char_u *)FALSE}
516#else
517 (char_u *)NULL, PV_NONE,
518 {(char_u *)FALSE, (char_u *)FALSE}
519#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000520 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200521 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000522#ifdef FEAT_ARABIC
523 (char_u *)VAR_WIN, PV_ARAB,
524#else
525 (char_u *)NULL, PV_NONE,
526#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000527 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000528 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
529#ifdef FEAT_ARABIC
530 (char_u *)&p_arshape, PV_NONE,
531#else
532 (char_u *)NULL, PV_NONE,
533#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000534 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000535 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
536#ifdef FEAT_RIGHTLEFT
537 (char_u *)&p_ari, PV_NONE,
538#else
539 (char_u *)NULL, PV_NONE,
540#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000541 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000542 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
543#ifdef FEAT_FKMAP
544 (char_u *)&p_altkeymap, PV_NONE,
545#else
546 (char_u *)NULL, PV_NONE,
547#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000548 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000549 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
550#if defined(FEAT_MBYTE)
551 (char_u *)&p_ambw, PV_NONE,
552 {(char_u *)"single", (char_u *)0L}
553#else
554 (char_u *)NULL, PV_NONE,
555 {(char_u *)0L, (char_u *)0L}
556#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000557 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000558 {"autochdir", "acd", P_BOOL|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100559#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000560 (char_u *)&p_acd, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100561 {(char_u *)FALSE, (char_u *)0L}
562#else
563 (char_u *)NULL, PV_NONE,
564 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000565#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +0100566 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000567 {"autoindent", "ai", P_BOOL|P_VI_DEF,
568 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000569 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000570 {"autoprint", "ap", P_BOOL|P_VI_DEF,
571 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000572 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000573 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000574 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000575 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000576 {"autowrite", "aw", P_BOOL|P_VI_DEF,
577 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000578 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000579 {"autowriteall","awa", P_BOOL|P_VI_DEF,
580 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000581 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000582 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
583 (char_u *)&p_bg, PV_NONE,
584 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100585#if (defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000586 (char_u *)"dark",
587#else
588 (char_u *)"light",
589#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000590 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200591 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000592 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000593 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000594 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
595 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000596 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200597 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200598 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000599#ifdef UNIX
600 {(char_u *)"yes", (char_u *)"auto"}
601#else
602 {(char_u *)"auto", (char_u *)"auto"}
603#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000604 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200605 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
606 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000607 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000608 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000609 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000610 (char_u *)&p_bex, PV_NONE,
611 {
612#ifdef VMS
613 (char_u *)"_",
614#else
615 (char_u *)"~",
616#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000617 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200618 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000619#ifdef FEAT_WILDIGN
620 (char_u *)&p_bsk, PV_NONE,
621 {(char_u *)"", (char_u *)0L}
622#else
623 (char_u *)NULL, PV_NONE,
624 {(char_u *)0L, (char_u *)0L}
625#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000626 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000627 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100628#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000629 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100630 {(char_u *)600L, (char_u *)0L}
631#else
632 (char_u *)NULL, PV_NONE,
633 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000634#endif
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100635 SCRIPTID_INIT},
636 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
637#ifdef FEAT_BEVAL
638 (char_u *)&p_beval, PV_NONE,
639 {(char_u *)FALSE, (char_u *)0L}
640#else
641 (char_u *)NULL, PV_NONE,
642 {(char_u *)0L, (char_u *)0L}
643#endif
644 SCRIPTID_INIT},
645 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
646#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
647 (char_u *)&p_bexpr, PV_BEXPR,
648 {(char_u *)"", (char_u *)0L}
649#else
650 (char_u *)NULL, PV_NONE,
651 {(char_u *)0L, (char_u *)0L}
652#endif
653 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000654 {"beautify", "bf", P_BOOL|P_VI_DEF,
655 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000656 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200657 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
658 (char_u *)&p_bo, PV_NONE,
659 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000660 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
661 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000662 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000663 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000664 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000665 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000666 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
667#ifdef FEAT_MBYTE
668 (char_u *)&p_bomb, PV_BOMB,
669#else
670 (char_u *)NULL, PV_NONE,
671#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000672 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000673 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
674#ifdef FEAT_LINEBREAK
675 (char_u *)&p_breakat, PV_NONE,
676 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
677#else
678 (char_u *)NULL, PV_NONE,
679 {(char_u *)0L, (char_u *)0L}
680#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000681 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200682 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
683#ifdef FEAT_LINEBREAK
684 (char_u *)VAR_WIN, PV_BRI,
685 {(char_u *)FALSE, (char_u *)0L}
686#else
687 (char_u *)NULL, PV_NONE,
688 {(char_u *)0L, (char_u *)0L}
689#endif
690 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200691 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
692 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200693#ifdef FEAT_LINEBREAK
694 (char_u *)VAR_WIN, PV_BRIOPT,
695 {(char_u *)"", (char_u *)NULL}
696#else
697 (char_u *)NULL, PV_NONE,
698 {(char_u *)"", (char_u *)NULL}
699#endif
700 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000701 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
702#ifdef FEAT_BROWSE
703 (char_u *)&p_bsdir, PV_NONE,
704 {(char_u *)"last", (char_u *)0L}
705#else
706 (char_u *)NULL, PV_NONE,
707 {(char_u *)0L, (char_u *)0L}
708#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000709 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000710 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000711 (char_u *)&p_bh, PV_BH,
712 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000713 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000714 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
715 (char_u *)&p_bl, PV_BL,
716 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000717 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000718 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000719 (char_u *)&p_bt, PV_BT,
720 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000721 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200722 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000723#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000724 (char_u *)&p_cmp, PV_NONE,
725 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000726#else
727 (char_u *)NULL, PV_NONE,
728 {(char_u *)0L, (char_u *)0L}
729#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000730 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000731 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
732#ifdef FEAT_SEARCHPATH
733 (char_u *)&p_cdpath, PV_NONE,
734 {(char_u *)",,", (char_u *)0L}
735#else
736 (char_u *)NULL, PV_NONE,
737 {(char_u *)0L, (char_u *)0L}
738#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000739 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000740 {"cedit", NULL, P_STRING,
741#ifdef FEAT_CMDWIN
742 (char_u *)&p_cedit, PV_NONE,
743 {(char_u *)"", (char_u *)CTRL_F_STR}
744#else
745 (char_u *)NULL, PV_NONE,
746 {(char_u *)0L, (char_u *)0L}
747#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000748 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000749 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
750#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
751 (char_u *)&p_ccv, PV_NONE,
752 {(char_u *)"", (char_u *)0L}
753#else
754 (char_u *)NULL, PV_NONE,
755 {(char_u *)0L, (char_u *)0L}
756#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000757 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000758 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
759#ifdef FEAT_CINDENT
760 (char_u *)&p_cin, PV_CIN,
761#else
762 (char_u *)NULL, PV_NONE,
763#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000764 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200765 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000766#ifdef FEAT_CINDENT
767 (char_u *)&p_cink, PV_CINK,
768 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
769#else
770 (char_u *)NULL, PV_NONE,
771 {(char_u *)0L, (char_u *)0L}
772#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000773 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200774 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000775#ifdef FEAT_CINDENT
776 (char_u *)&p_cino, PV_CINO,
777#else
778 (char_u *)NULL, PV_NONE,
779#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000780 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200781 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000782#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
783 (char_u *)&p_cinw, PV_CINW,
784 {(char_u *)"if,else,while,do,for,switch",
785 (char_u *)0L}
786#else
787 (char_u *)NULL, PV_NONE,
788 {(char_u *)0L, (char_u *)0L}
789#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000790 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200791 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000792#ifdef FEAT_CLIPBOARD
793 (char_u *)&p_cb, PV_NONE,
794# ifdef FEAT_XCLIPBOARD
795 {(char_u *)"autoselect,exclude:cons\\|linux",
796 (char_u *)0L}
797# else
798 {(char_u *)"", (char_u *)0L}
799# endif
800#else
801 (char_u *)NULL, PV_NONE,
802 {(char_u *)"", (char_u *)0L}
803#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000804 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000805 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
806 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000807 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000808 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
809#ifdef FEAT_CMDWIN
810 (char_u *)&p_cwh, PV_NONE,
811#else
812 (char_u *)NULL, PV_NONE,
813#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000814 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200815 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200816#ifdef FEAT_SYN_HL
817 (char_u *)VAR_WIN, PV_CC,
818#else
819 (char_u *)NULL, PV_NONE,
820#endif
821 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000822 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
823 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000824 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200825 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
826 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000827#ifdef FEAT_COMMENTS
828 (char_u *)&p_com, PV_COM,
829 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
830 (char_u *)0L}
831#else
832 (char_u *)NULL, PV_NONE,
833 {(char_u *)0L, (char_u *)0L}
834#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000835 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200836 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000837#ifdef FEAT_FOLDING
838 (char_u *)&p_cms, PV_CMS,
839 {(char_u *)"/*%s*/", (char_u *)0L}
840#else
841 (char_u *)NULL, PV_NONE,
842 {(char_u *)0L, (char_u *)0L}
843#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000844 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000845 /* P_PRI_MKRC isn't needed here, optval_default()
846 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000847 {"compatible", "cp", P_BOOL|P_RALL,
848 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000849 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200850 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000851#ifdef FEAT_INS_EXPAND
852 (char_u *)&p_cpt, PV_CPT,
853 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
854#else
855 (char_u *)NULL, PV_NONE,
856 {(char_u *)0L, (char_u *)0L}
857#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000858 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200859 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200860#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200861 (char_u *)VAR_WIN, PV_COCU,
862 {(char_u *)"", (char_u *)NULL}
863#else
864 (char_u *)NULL, PV_NONE,
865 {(char_u *)NULL, (char_u *)0L}
866#endif
867 SCRIPTID_INIT},
868 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
869#ifdef FEAT_CONCEAL
870 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200871#else
872 (char_u *)NULL, PV_NONE,
873#endif
874 {(char_u *)0L, (char_u *)0L}
875 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000876 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
877#ifdef FEAT_COMPL_FUNC
878 (char_u *)&p_cfu, PV_CFU,
879 {(char_u *)"", (char_u *)0L}
880#else
881 (char_u *)NULL, PV_NONE,
882 {(char_u *)0L, (char_u *)0L}
883#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000884 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200885 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000886#ifdef FEAT_INS_EXPAND
887 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000888 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000889#else
890 (char_u *)NULL, PV_NONE,
891 {(char_u *)0L, (char_u *)0L}
892#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000893 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000894 {"confirm", "cf", P_BOOL|P_VI_DEF,
895#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
896 (char_u *)&p_confirm, PV_NONE,
897#else
898 (char_u *)NULL, PV_NONE,
899#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000900 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000901 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000902 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000903 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000904 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
905 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000906 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000907 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
908 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000909 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
910 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200911 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200912#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200913 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200914 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200915#else
916 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200917 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200918#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200919 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000920 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
921#ifdef FEAT_CSCOPE
922 (char_u *)&p_cspc, PV_NONE,
923#else
924 (char_u *)NULL, PV_NONE,
925#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000926 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000927 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
928#ifdef FEAT_CSCOPE
929 (char_u *)&p_csprg, PV_NONE,
930 {(char_u *)"cscope", (char_u *)0L}
931#else
932 (char_u *)NULL, PV_NONE,
933 {(char_u *)0L, (char_u *)0L}
934#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000935 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200936 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000937#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
938 (char_u *)&p_csqf, PV_NONE,
939 {(char_u *)"", (char_u *)0L}
940#else
941 (char_u *)NULL, PV_NONE,
942 {(char_u *)0L, (char_u *)0L}
943#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000944 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200945 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
946#ifdef FEAT_CSCOPE
947 (char_u *)&p_csre, PV_NONE,
948#else
949 (char_u *)NULL, PV_NONE,
950#endif
951 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000952 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
953#ifdef FEAT_CSCOPE
954 (char_u *)&p_cst, PV_NONE,
955#else
956 (char_u *)NULL, PV_NONE,
957#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000958 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000959 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
960#ifdef FEAT_CSCOPE
961 (char_u *)&p_csto, PV_NONE,
962#else
963 (char_u *)NULL, PV_NONE,
964#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000965 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000966 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
967#ifdef FEAT_CSCOPE
968 (char_u *)&p_csverbose, PV_NONE,
969#else
970 (char_u *)NULL, PV_NONE,
971#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000972 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200973 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
974#ifdef FEAT_CURSORBIND
975 (char_u *)VAR_WIN, PV_CRBIND,
976#else
977 (char_u *)NULL, PV_NONE,
978#endif
979 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000980 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
981#ifdef FEAT_SYN_HL
982 (char_u *)VAR_WIN, PV_CUC,
983#else
984 (char_u *)NULL, PV_NONE,
985#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000986 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100987 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000988#ifdef FEAT_SYN_HL
989 (char_u *)VAR_WIN, PV_CUL,
990#else
991 (char_u *)NULL, PV_NONE,
992#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000993 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000994 {"debug", NULL, P_STRING|P_VI_DEF,
995 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000996 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200997 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000998#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000999 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001000 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001001#else
1002 (char_u *)NULL, PV_NONE,
1003 {(char_u *)NULL, (char_u *)0L}
1004#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001005 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001006 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
1007#ifdef FEAT_MBYTE
1008 (char_u *)&p_deco, PV_NONE,
1009#else
1010 (char_u *)NULL, PV_NONE,
1011#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001012 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001013 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001014#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001015 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001016#else
1017 (char_u *)NULL, PV_NONE,
1018#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001019 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001020 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1021#ifdef FEAT_DIFF
1022 (char_u *)VAR_WIN, PV_DIFF,
1023#else
1024 (char_u *)NULL, PV_NONE,
1025#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001026 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001027 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001028#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1029 (char_u *)&p_dex, PV_NONE,
1030 {(char_u *)"", (char_u *)0L}
1031#else
1032 (char_u *)NULL, PV_NONE,
1033 {(char_u *)0L, (char_u *)0L}
1034#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001035 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001036 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1037 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001038#ifdef FEAT_DIFF
1039 (char_u *)&p_dip, PV_NONE,
1040 {(char_u *)"filler", (char_u *)NULL}
1041#else
1042 (char_u *)NULL, PV_NONE,
1043 {(char_u *)"", (char_u *)NULL}
1044#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001045 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001046 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1047#ifdef FEAT_DIGRAPHS
1048 (char_u *)&p_dg, PV_NONE,
1049#else
1050 (char_u *)NULL, PV_NONE,
1051#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001052 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001053 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1054 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001055 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001056 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001057 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001058 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001059 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001060 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001061 (char_u *)&p_ead, PV_NONE,
1062 {(char_u *)"both", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001063 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001064 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1065 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001066 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001067 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
1068#if defined(FEAT_MBYTE)
1069 (char_u *)&p_emoji, PV_NONE,
1070 {(char_u *)TRUE, (char_u *)0L}
1071#else
1072 (char_u *)NULL, PV_NONE,
1073 {(char_u *)0L, (char_u *)0L}
1074#endif
1075 SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001076 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001077#ifdef FEAT_MBYTE
1078 (char_u *)&p_enc, PV_NONE,
1079 {(char_u *)ENC_DFLT, (char_u *)0L}
1080#else
1081 (char_u *)NULL, PV_NONE,
1082 {(char_u *)0L, (char_u *)0L}
1083#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001084 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001085 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1086 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001087 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001088 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1089 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001090 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001091 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001092 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001093 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001094 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1095 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001096 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001097 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1098#ifdef FEAT_QUICKFIX
1099 (char_u *)&p_ef, PV_NONE,
1100 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1101#else
1102 (char_u *)NULL, PV_NONE,
1103 {(char_u *)NULL, (char_u *)0L}
1104#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001105 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001106 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001107#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001108 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001109 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001110#else
1111 (char_u *)NULL, PV_NONE,
1112 {(char_u *)NULL, (char_u *)0L}
1113#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001114 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001115 {"esckeys", "ek", P_BOOL|P_VIM,
1116 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001117 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001118 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001119#ifdef FEAT_AUTOCMD
1120 (char_u *)&p_ei, PV_NONE,
1121#else
1122 (char_u *)NULL, PV_NONE,
1123#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001124 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001125 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1126 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001127 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001128 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1129 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001130 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001131 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1132 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001133#ifdef FEAT_MBYTE
1134 (char_u *)&p_fenc, PV_FENC,
1135 {(char_u *)"", (char_u *)0L}
1136#else
1137 (char_u *)NULL, PV_NONE,
1138 {(char_u *)0L, (char_u *)0L}
1139#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001140 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001141 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001142#ifdef FEAT_MBYTE
1143 (char_u *)&p_fencs, PV_NONE,
1144 {(char_u *)"ucs-bom", (char_u *)0L}
1145#else
1146 (char_u *)NULL, PV_NONE,
1147 {(char_u *)0L, (char_u *)0L}
1148#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001149 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001150 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1151 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001152 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001153 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001154 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001155 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001156 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1157 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001158 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1159 (char_u *)&p_fic, PV_NONE,
1160 {
1161#ifdef CASE_INSENSITIVE_FILENAME
1162 (char_u *)TRUE,
1163#else
1164 (char_u *)FALSE,
1165#endif
1166 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001167 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001168#ifdef FEAT_AUTOCMD
1169 (char_u *)&p_ft, PV_FT,
1170 {(char_u *)"", (char_u *)0L}
1171#else
1172 (char_u *)NULL, PV_NONE,
1173 {(char_u *)0L, (char_u *)0L}
1174#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001175 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001176 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001177 (char_u *)&p_fcs, PV_NONE,
1178 {(char_u *)"vert:|,fold:-", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001179 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001180 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1181 (char_u *)&p_fixeol, PV_FIXEOL,
1182 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001183 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1184#ifdef FEAT_FKMAP
1185 (char_u *)&p_fkmap, PV_NONE,
1186#else
1187 (char_u *)NULL, PV_NONE,
1188#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001189 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001190 {"flash", "fl", P_BOOL|P_VI_DEF,
1191 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001192 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001193 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001194#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001195 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001196 {(char_u *)"", (char_u *)0L}
1197#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001198 (char_u *)NULL, PV_NONE,
1199 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001200#endif
1201 SCRIPTID_INIT},
1202 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1203#ifdef FEAT_FOLDING
1204 (char_u *)VAR_WIN, PV_FDC,
1205 {(char_u *)FALSE, (char_u *)0L}
1206#else
1207 (char_u *)NULL, PV_NONE,
1208 {(char_u *)NULL, (char_u *)0L}
1209#endif
1210 SCRIPTID_INIT},
1211 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1212#ifdef FEAT_FOLDING
1213 (char_u *)VAR_WIN, PV_FEN,
1214 {(char_u *)TRUE, (char_u *)0L}
1215#else
1216 (char_u *)NULL, PV_NONE,
1217 {(char_u *)NULL, (char_u *)0L}
1218#endif
1219 SCRIPTID_INIT},
1220 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1221#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1222 (char_u *)VAR_WIN, PV_FDE,
1223 {(char_u *)"0", (char_u *)NULL}
1224#else
1225 (char_u *)NULL, PV_NONE,
1226 {(char_u *)NULL, (char_u *)0L}
1227#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001228 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001229 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001230#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001231 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001232 {(char_u *)"#", (char_u *)NULL}
1233#else
1234 (char_u *)NULL, PV_NONE,
1235 {(char_u *)NULL, (char_u *)0L}
1236#endif
1237 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001238 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001239#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001240 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001241 {(char_u *)0L, (char_u *)0L}
1242#else
1243 (char_u *)NULL, PV_NONE,
1244 {(char_u *)NULL, (char_u *)0L}
1245#endif
1246 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001247 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001248#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001249 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001250 {(char_u *)-1L, (char_u *)0L}
1251#else
1252 (char_u *)NULL, PV_NONE,
1253 {(char_u *)NULL, (char_u *)0L}
1254#endif
1255 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001256 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001257 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001258#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001259 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001260 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001261#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001262 (char_u *)NULL, PV_NONE,
1263 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001264#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001265 SCRIPTID_INIT},
1266 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1267#ifdef FEAT_FOLDING
1268 (char_u *)VAR_WIN, PV_FDM,
1269 {(char_u *)"manual", (char_u *)NULL}
1270#else
1271 (char_u *)NULL, PV_NONE,
1272 {(char_u *)NULL, (char_u *)0L}
1273#endif
1274 SCRIPTID_INIT},
1275 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1276#ifdef FEAT_FOLDING
1277 (char_u *)VAR_WIN, PV_FML,
1278 {(char_u *)1L, (char_u *)0L}
1279#else
1280 (char_u *)NULL, PV_NONE,
1281 {(char_u *)NULL, (char_u *)0L}
1282#endif
1283 SCRIPTID_INIT},
1284 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1285#ifdef FEAT_FOLDING
1286 (char_u *)VAR_WIN, PV_FDN,
1287 {(char_u *)20L, (char_u *)0L}
1288#else
1289 (char_u *)NULL, PV_NONE,
1290 {(char_u *)NULL, (char_u *)0L}
1291#endif
1292 SCRIPTID_INIT},
1293 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1294#ifdef FEAT_FOLDING
1295 (char_u *)&p_fdo, PV_NONE,
1296 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1297 (char_u *)0L}
1298#else
1299 (char_u *)NULL, PV_NONE,
1300 {(char_u *)NULL, (char_u *)0L}
1301#endif
1302 SCRIPTID_INIT},
1303 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1304#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1305 (char_u *)VAR_WIN, PV_FDT,
1306 {(char_u *)"foldtext()", (char_u *)NULL}
1307#else
1308 (char_u *)NULL, PV_NONE,
1309 {(char_u *)NULL, (char_u *)0L}
1310#endif
1311 SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001312 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001313#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001314 (char_u *)&p_fex, PV_FEX,
1315 {(char_u *)"", (char_u *)0L}
1316#else
1317 (char_u *)NULL, PV_NONE,
1318 {(char_u *)0L, (char_u *)0L}
1319#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001320 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001321 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1322 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001323 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1324 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001325 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1326 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001327 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1328 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001329 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001330 (char_u *)&p_fp, PV_FP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001331 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001332 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1333#ifdef HAVE_FSYNC
1334 (char_u *)&p_fs, PV_NONE,
1335 {(char_u *)TRUE, (char_u *)0L}
1336#else
1337 (char_u *)NULL, PV_NONE,
1338 {(char_u *)FALSE, (char_u *)0L}
1339#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001340 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001341 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1342 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001343 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001344 {"graphic", "gr", P_BOOL|P_VI_DEF,
1345 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001346 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001347 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001348#ifdef FEAT_QUICKFIX
1349 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001350 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001351#else
1352 (char_u *)NULL, PV_NONE,
1353 {(char_u *)NULL, (char_u *)0L}
1354#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001355 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001356 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1357#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001358 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001359 {
1360# ifdef WIN3264
1361 /* may be changed to "grep -n" in os_win32.c */
1362 (char_u *)"findstr /n",
1363# else
1364# ifdef UNIX
1365 /* Add an extra file name so that grep will always
1366 * insert a file name in the match line. */
1367 (char_u *)"grep -n $* /dev/null",
1368# else
1369# ifdef VMS
1370 (char_u *)"SEARCH/NUMBERS ",
1371# else
1372 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001373# endif
1374# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001375# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001376 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001377#else
1378 (char_u *)NULL, PV_NONE,
1379 {(char_u *)NULL, (char_u *)0L}
1380#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001381 SCRIPTID_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001382 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001383#ifdef CURSOR_SHAPE
1384 (char_u *)&p_guicursor, PV_NONE,
1385 {
1386# ifdef FEAT_GUI
1387 (char_u *)"n-v-c:block-Cursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001388# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001389 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1390# endif
1391 (char_u *)0L}
1392#else
1393 (char_u *)NULL, PV_NONE,
1394 {(char_u *)NULL, (char_u *)0L}
1395#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001396 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001397 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001398#ifdef FEAT_GUI
1399 (char_u *)&p_guifont, PV_NONE,
1400 {(char_u *)"", (char_u *)0L}
1401#else
1402 (char_u *)NULL, PV_NONE,
1403 {(char_u *)NULL, (char_u *)0L}
1404#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001405 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001406 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001407#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1408 (char_u *)&p_guifontset, PV_NONE,
1409 {(char_u *)"", (char_u *)0L}
1410#else
1411 (char_u *)NULL, PV_NONE,
1412 {(char_u *)NULL, (char_u *)0L}
1413#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001414 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001415 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001416#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1417 (char_u *)&p_guifontwide, PV_NONE,
1418 {(char_u *)"", (char_u *)0L}
1419#else
1420 (char_u *)NULL, PV_NONE,
1421 {(char_u *)NULL, (char_u *)0L}
1422#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001423 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001424 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001425#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001426 (char_u *)&p_ghr, PV_NONE,
1427#else
1428 (char_u *)NULL, PV_NONE,
1429#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001430 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001431 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001432#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001433 (char_u *)&p_go, PV_NONE,
1434# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001435 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001436# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001437 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001438# endif
1439#else
1440 (char_u *)NULL, PV_NONE,
1441 {(char_u *)NULL, (char_u *)0L}
1442#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001443 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001444 {"guipty", NULL, P_BOOL|P_VI_DEF,
1445#if defined(FEAT_GUI)
1446 (char_u *)&p_guipty, PV_NONE,
1447#else
1448 (char_u *)NULL, PV_NONE,
1449#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001450 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001451 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001452#if defined(FEAT_GUI_TABLINE)
1453 (char_u *)&p_gtl, PV_NONE,
1454 {(char_u *)"", (char_u *)0L}
1455#else
1456 (char_u *)NULL, PV_NONE,
1457 {(char_u *)NULL, (char_u *)0L}
1458#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001459 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001460 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001461#if defined(FEAT_GUI_TABLINE)
1462 (char_u *)&p_gtt, PV_NONE,
1463 {(char_u *)"", (char_u *)0L}
1464#else
1465 (char_u *)NULL, PV_NONE,
1466 {(char_u *)NULL, (char_u *)0L}
1467#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001468 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001469 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1470 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001471 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001472 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1473 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001474 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1475 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001476 {"helpheight", "hh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001477 (char_u *)&p_hh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001478 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001479 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001480#ifdef FEAT_MULTI_LANG
1481 (char_u *)&p_hlg, PV_NONE,
1482 {(char_u *)"", (char_u *)0L}
1483#else
1484 (char_u *)NULL, PV_NONE,
1485 {(char_u *)0L, (char_u *)0L}
1486#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001487 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001488 {"hidden", "hid", P_BOOL|P_VI_DEF,
1489 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001490 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001491 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001492 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001493 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1494 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001495 {"history", "hi", P_NUM|P_VIM,
1496 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001497 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001498 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1499#ifdef FEAT_RIGHTLEFT
1500 (char_u *)&p_hkmap, PV_NONE,
1501#else
1502 (char_u *)NULL, PV_NONE,
1503#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001504 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001505 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1506#ifdef FEAT_RIGHTLEFT
1507 (char_u *)&p_hkmapp, PV_NONE,
1508#else
1509 (char_u *)NULL, PV_NONE,
1510#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001511 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001512 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1513 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001514 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001515 {"icon", NULL, P_BOOL|P_VI_DEF,
1516#ifdef FEAT_TITLE
1517 (char_u *)&p_icon, PV_NONE,
1518#else
1519 (char_u *)NULL, PV_NONE,
1520#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001521 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001522 {"iconstring", NULL, P_STRING|P_VI_DEF,
1523#ifdef FEAT_TITLE
1524 (char_u *)&p_iconstring, PV_NONE,
1525#else
1526 (char_u *)NULL, PV_NONE,
1527#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001528 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001529 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1530 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001531 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001532 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1533# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1534 (char_u *)&p_imaf, PV_NONE,
1535 {(char_u *)"", (char_u *)NULL}
1536# else
1537 (char_u *)NULL, PV_NONE,
1538 {(char_u *)NULL, (char_u *)0L}
1539# endif
1540 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001541 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001542#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001543 (char_u *)&p_imak, PV_NONE,
1544#else
1545 (char_u *)NULL, PV_NONE,
1546#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001547 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001548 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1549#ifdef USE_IM_CONTROL
1550 (char_u *)&p_imcmdline, PV_NONE,
1551#else
1552 (char_u *)NULL, PV_NONE,
1553#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001554 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001555 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1556#ifdef USE_IM_CONTROL
1557 (char_u *)&p_imdisable, PV_NONE,
1558#else
1559 (char_u *)NULL, PV_NONE,
1560#endif
1561#ifdef __sgi
1562 {(char_u *)TRUE, (char_u *)0L}
1563#else
1564 {(char_u *)FALSE, (char_u *)0L}
1565#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001566 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001567 {"iminsert", "imi", P_NUM|P_VI_DEF,
1568 (char_u *)&p_iminsert, PV_IMI,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001569 {(char_u *)B_IMODE_NONE, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001570 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001571 {"imsearch", "ims", P_NUM|P_VI_DEF,
1572 (char_u *)&p_imsearch, PV_IMS,
Bram Moolenaar4cf56bb2017-09-16 15:50:32 +02001573 {(char_u *)B_IMODE_USE_INSERT, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001574 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001575 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001576#if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001577 (char_u *)&p_imsf, PV_NONE,
1578 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001579#else
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001580 (char_u *)NULL, PV_NONE,
1581 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001582#endif
1583 SCRIPTID_INIT},
1584 {"imstyle", "imst", P_NUM|P_VI_DEF|P_SECURE,
1585#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1586 (char_u *)&p_imst, PV_NONE,
1587 {(char_u *)IM_OVER_THE_SPOT, (char_u *)0L}
1588#else
1589 (char_u *)NULL, PV_NONE,
1590 {(char_u *)0L, (char_u *)0L}
1591#endif
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001592 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001593 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1594#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001595 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001596 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1597#else
1598 (char_u *)NULL, PV_NONE,
1599 {(char_u *)0L, (char_u *)0L}
1600#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001601 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001602 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1603#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1604 (char_u *)&p_inex, PV_INEX,
1605 {(char_u *)"", (char_u *)0L}
1606#else
1607 (char_u *)NULL, PV_NONE,
1608 {(char_u *)0L, (char_u *)0L}
1609#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001610 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001611 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1612 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001613 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001614 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1615#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1616 (char_u *)&p_inde, PV_INDE,
1617 {(char_u *)"", (char_u *)0L}
1618#else
1619 (char_u *)NULL, PV_NONE,
1620 {(char_u *)0L, (char_u *)0L}
1621#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001622 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001623 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001624#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1625 (char_u *)&p_indk, PV_INDK,
1626 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1627#else
1628 (char_u *)NULL, PV_NONE,
1629 {(char_u *)0L, (char_u *)0L}
1630#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001631 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001632 {"infercase", "inf", P_BOOL|P_VI_DEF,
1633 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001634 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001635 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1636 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001637 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001638 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1639 (char_u *)&p_isf, PV_NONE,
1640 {
1641#ifdef BACKSLASH_IN_FILENAME
1642 /* Excluded are: & and ^ are special in cmd.exe
1643 * ( and ) are used in text separating fnames */
1644 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1645#else
1646# ifdef AMIGA
1647 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1648# else
1649# ifdef VMS
1650 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1651# else /* UNIX et al. */
1652# ifdef EBCDIC
1653 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1654# else
1655 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1656# endif
1657# endif
1658# endif
1659#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001660 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001661 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1662 (char_u *)&p_isi, PV_NONE,
1663 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001664#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001665 (char_u *)"@,48-57,_,128-167,224-235",
1666#else
1667# ifdef EBCDIC
1668 /* TODO: EBCDIC Check this! @ == isalpha()*/
1669 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1670 "112-120,128,140-142,156,158,172,"
1671 "174,186,191,203-207,219-225,235-239,"
1672 "251-254",
1673# else
1674 (char_u *)"@,48-57,_,192-255",
1675# endif
1676#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001677 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001678 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1679 (char_u *)&p_isk, PV_ISK,
1680 {
1681#ifdef EBCDIC
1682 (char_u *)"@,240-249,_",
1683 /* TODO: EBCDIC Check this! @ == isalpha()*/
1684 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1685 "112-120,128,140-142,156,158,172,"
1686 "174,186,191,203-207,219-225,235-239,"
1687 "251-254",
1688#else
1689 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001690# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001691 (char_u *)"@,48-57,_,128-167,224-235"
1692# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001693 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001694# endif
1695#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001696 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001697 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1698 (char_u *)&p_isp, PV_NONE,
1699 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001700#if defined(MSWIN) || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001701 || defined(VMS)
1702 (char_u *)"@,~-255",
1703#else
1704# ifdef EBCDIC
1705 /* all chars above 63 are printable */
1706 (char_u *)"63-255",
1707# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001708 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001709# endif
1710#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001711 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001712 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1713 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001714 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001715 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1716#ifdef FEAT_CRYPT
1717 (char_u *)&p_key, PV_KEY,
1718 {(char_u *)"", (char_u *)0L}
1719#else
1720 (char_u *)NULL, PV_NONE,
1721 {(char_u *)0L, (char_u *)0L}
1722#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001723 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001724 {"keymap", "kmp", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_RSTAT|P_NFNAME|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001725#ifdef FEAT_KEYMAP
1726 (char_u *)&p_keymap, PV_KMAP,
1727 {(char_u *)"", (char_u *)0L}
1728#else
1729 (char_u *)NULL, PV_NONE,
1730 {(char_u *)"", (char_u *)0L}
1731#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001732 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001733 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001734 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001735 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001736 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001737 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001738 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001739#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001740 (char_u *)":help",
1741#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001742# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001743 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001744# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001745# ifdef USEMAN_S
1746 (char_u *)"man -s",
1747# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001748 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001749# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001750# endif
1751#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001752 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001753 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001754#ifdef FEAT_LANGMAP
1755 (char_u *)&p_langmap, PV_NONE,
1756 {(char_u *)"", /* unmatched } */
1757#else
1758 (char_u *)NULL, PV_NONE,
1759 {(char_u *)NULL,
1760#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001761 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001762 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001763#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1764 (char_u *)&p_lm, PV_NONE,
1765#else
1766 (char_u *)NULL, PV_NONE,
1767#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001768 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001769 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1770#ifdef FEAT_LANGMAP
1771 (char_u *)&p_lnr, PV_NONE,
1772#else
1773 (char_u *)NULL, PV_NONE,
1774#endif
1775 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001776 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1777#ifdef FEAT_LANGMAP
1778 (char_u *)&p_lrm, PV_NONE,
1779#else
1780 (char_u *)NULL, PV_NONE,
1781#endif
Bram Moolenaarda9ce2c2016-09-02 19:34:10 +02001782 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001783 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001784 (char_u *)&p_ls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001785 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001786 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1787 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001788 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001789 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1790#ifdef FEAT_LINEBREAK
1791 (char_u *)VAR_WIN, PV_LBR,
1792#else
1793 (char_u *)NULL, PV_NONE,
1794#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001795 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001796 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1797 (char_u *)&Rows, PV_NONE,
1798 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001799#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001800 (char_u *)25L,
1801#else
1802 (char_u *)24L,
1803#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001804 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001805 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1806#ifdef FEAT_GUI
1807 (char_u *)&p_linespace, PV_NONE,
1808#else
1809 (char_u *)NULL, PV_NONE,
1810#endif
1811#ifdef FEAT_GUI_W32
1812 {(char_u *)1L, (char_u *)0L}
1813#else
1814 {(char_u *)0L, (char_u *)0L}
1815#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001816 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001817 {"lisp", NULL, P_BOOL|P_VI_DEF,
1818#ifdef FEAT_LISP
1819 (char_u *)&p_lisp, PV_LISP,
1820#else
1821 (char_u *)NULL, PV_NONE,
1822#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001823 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001824 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001825#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001826 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001827 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1828#else
1829 (char_u *)NULL, PV_NONE,
1830 {(char_u *)"", (char_u *)0L}
1831#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001832 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001833 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1834 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001835 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001836 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001837 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001838 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001839 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1840 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001841 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001842 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001843#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001844 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001845 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001846#else
1847 (char_u *)NULL, PV_NONE,
1848 {(char_u *)"", (char_u *)0L}
1849#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001850 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001851 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001852#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001853 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001854 {(char_u *)TRUE, (char_u *)0L}
1855#else
1856 (char_u *)NULL, PV_NONE,
1857 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001858#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001859 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001860 {"magic", NULL, P_BOOL|P_VI_DEF,
1861 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001862 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001863 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001864#ifdef FEAT_QUICKFIX
1865 (char_u *)&p_mef, PV_NONE,
1866 {(char_u *)"", (char_u *)0L}
1867#else
1868 (char_u *)NULL, PV_NONE,
1869 {(char_u *)NULL, (char_u *)0L}
1870#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001871 SCRIPTID_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001872 {"makeencoding","menc", P_STRING|P_VI_DEF,
1873#ifdef FEAT_MBYTE
1874 (char_u *)&p_menc, PV_MENC,
1875 {(char_u *)"", (char_u *)0L}
1876#else
1877 (char_u *)NULL, PV_NONE,
1878 {(char_u *)0L, (char_u *)0L}
1879#endif
1880 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001881 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1882#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001883 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001884# ifdef VMS
1885 {(char_u *)"MMS", (char_u *)0L}
1886# else
1887 {(char_u *)"make", (char_u *)0L}
1888# endif
1889#else
1890 (char_u *)NULL, PV_NONE,
1891 {(char_u *)NULL, (char_u *)0L}
1892#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001893 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001894 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001895 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001896 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1897 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001898 {"matchtime", "mat", P_NUM|P_VI_DEF,
1899 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001900 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001901 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001902#ifdef FEAT_MBYTE
1903 (char_u *)&p_mco, PV_NONE,
1904#else
1905 (char_u *)NULL, PV_NONE,
1906#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001907 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001908 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1909#ifdef FEAT_EVAL
1910 (char_u *)&p_mfd, PV_NONE,
1911#else
1912 (char_u *)NULL, PV_NONE,
1913#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001914 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001915 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1916 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001917 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001918 {"maxmem", "mm", P_NUM|P_VI_DEF,
1919 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001920 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1921 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001922 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1923 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001924 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001925 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1926 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001927 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1928 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001929 {"menuitems", "mis", P_NUM|P_VI_DEF,
1930#ifdef FEAT_MENU
1931 (char_u *)&p_mis, PV_NONE,
1932#else
1933 (char_u *)NULL, PV_NONE,
1934#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001935 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001936 {"mesg", NULL, P_BOOL|P_VI_DEF,
1937 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001938 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001939 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001940#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001941 (char_u *)&p_msm, PV_NONE,
1942 {(char_u *)"460000,2000,500", (char_u *)0L}
1943#else
1944 (char_u *)NULL, PV_NONE,
1945 {(char_u *)0L, (char_u *)0L}
1946#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001947 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001948 {"modeline", "ml", P_BOOL|P_VIM,
1949 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001950 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001951 {"modelines", "mls", P_NUM|P_VI_DEF,
1952 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001953 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001954 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1955 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001956 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001957 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1958 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001959 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001960 {"more", NULL, P_BOOL|P_VIM,
1961 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001962 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001963 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1964 (char_u *)&p_mouse, PV_NONE,
1965 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001966#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001967 (char_u *)"a",
1968#else
1969 (char_u *)"",
1970#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001971 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001972 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1973#ifdef FEAT_GUI
1974 (char_u *)&p_mousef, PV_NONE,
1975#else
1976 (char_u *)NULL, PV_NONE,
1977#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001978 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001979 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1980#ifdef FEAT_GUI
1981 (char_u *)&p_mh, PV_NONE,
1982#else
1983 (char_u *)NULL, PV_NONE,
1984#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001985 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001986 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1987 (char_u *)&p_mousem, PV_NONE,
1988 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001989#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001990 (char_u *)"popup",
1991#else
1992# if defined(MACOS)
1993 (char_u *)"popup_setpos",
1994# else
1995 (char_u *)"extend",
1996# endif
1997#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001998 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001999 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002000#ifdef FEAT_MOUSESHAPE
2001 (char_u *)&p_mouseshape, PV_NONE,
2002 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
2003#else
2004 (char_u *)NULL, PV_NONE,
2005 {(char_u *)NULL, (char_u *)0L}
2006#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002007 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002008 {"mousetime", "mouset", P_NUM|P_VI_DEF,
2009 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002010 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00002011 {"mzquantum", "mzq", P_NUM,
2012#ifdef FEAT_MZSCHEME
2013 (char_u *)&p_mzq, PV_NONE,
2014#else
2015 (char_u *)NULL, PV_NONE,
2016#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002017 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002018 {"novice", NULL, P_BOOL|P_VI_DEF,
2019 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002020 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002021 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002022 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01002023 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002024 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002025 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
2026 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002027 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002028 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
2029#ifdef FEAT_LINEBREAK
2030 (char_u *)VAR_WIN, PV_NUW,
2031#else
2032 (char_u *)NULL, PV_NONE,
2033#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002034 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00002035 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00002036#ifdef FEAT_COMPL_FUNC
2037 (char_u *)&p_ofu, PV_OFU,
2038 {(char_u *)"", (char_u *)0L}
2039#else
2040 (char_u *)NULL, PV_NONE,
2041 {(char_u *)0L, (char_u *)0L}
2042#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002043 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002044 {"open", 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 Moolenaar043545e2006-10-10 16:44:07 +00002047 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002048#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002049 (char_u *)&p_odev, PV_NONE,
2050#else
2051 (char_u *)NULL, PV_NONE,
2052#endif
2053 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002054 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002055 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2056 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002057 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002058 {"optimize", "opt", P_BOOL|P_VI_DEF,
2059 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002060 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002061 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002062 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02002063 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002064 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2065 |P_SECURE,
2066 (char_u *)&p_pp, PV_NONE,
2067 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2068 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002069 {"paragraphs", "para", P_STRING|P_VI_DEF,
2070 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002071 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002072 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002073 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002074 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002075 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002076 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2077 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002078 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002079 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2080#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2081 (char_u *)&p_pex, PV_NONE,
2082 {(char_u *)"", (char_u *)0L}
2083#else
2084 (char_u *)NULL, PV_NONE,
2085 {(char_u *)0L, (char_u *)0L}
2086#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002087 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002088 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002089 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002090 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002091 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002092 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002093 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002094#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002095 (char_u *)".,,",
2096#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002097 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002098#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002099 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002100 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002101#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002102 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002103 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002104#else
2105 (char_u *)NULL, PV_NONE,
2106 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002107#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002108 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002109 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2110 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002111 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002112 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002113#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002114 (char_u *)&p_pvh, PV_NONE,
2115#else
2116 (char_u *)NULL, PV_NONE,
2117#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002118 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002119 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002120#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002121 (char_u *)VAR_WIN, PV_PVW,
2122#else
2123 (char_u *)NULL, PV_NONE,
2124#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002125 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002126 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002127#ifdef FEAT_PRINTER
2128 (char_u *)&p_pdev, PV_NONE,
2129 {(char_u *)"", (char_u *)0L}
2130#else
2131 (char_u *)NULL, PV_NONE,
2132 {(char_u *)NULL, (char_u *)0L}
2133#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002134 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002135 {"printencoding", "penc", P_STRING|P_VI_DEF,
2136#ifdef FEAT_POSTSCRIPT
2137 (char_u *)&p_penc, PV_NONE,
2138 {(char_u *)"", (char_u *)0L}
2139#else
2140 (char_u *)NULL, PV_NONE,
2141 {(char_u *)NULL, (char_u *)0L}
2142#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002143 SCRIPTID_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002144 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002145#ifdef FEAT_POSTSCRIPT
2146 (char_u *)&p_pexpr, PV_NONE,
2147 {(char_u *)"", (char_u *)0L}
2148#else
2149 (char_u *)NULL, PV_NONE,
2150 {(char_u *)NULL, (char_u *)0L}
2151#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002152 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002153 {"printfont", "pfn", P_STRING|P_VI_DEF,
2154#ifdef FEAT_PRINTER
2155 (char_u *)&p_pfn, PV_NONE,
2156 {
2157# ifdef MSWIN
2158 (char_u *)"Courier_New:h10",
2159# else
2160 (char_u *)"courier",
2161# endif
2162 (char_u *)0L}
2163#else
2164 (char_u *)NULL, PV_NONE,
2165 {(char_u *)NULL, (char_u *)0L}
2166#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002167 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002168 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2169#ifdef FEAT_PRINTER
2170 (char_u *)&p_header, PV_NONE,
Bram Moolenaar0903d562017-08-26 22:30:15 +02002171 /* untranslated to avoid problems when 'encoding'
2172 * is changed */
2173 {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002174#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 Moolenaar8299df92004-07-10 09:47:34 +00002179 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2180#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2181 (char_u *)&p_pmcs, PV_NONE,
2182 {(char_u *)"", (char_u *)0L}
2183#else
2184 (char_u *)NULL, PV_NONE,
2185 {(char_u *)NULL, (char_u *)0L}
2186#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002187 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002188 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2189#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2190 (char_u *)&p_pmfn, PV_NONE,
2191 {(char_u *)"", (char_u *)0L}
2192#else
2193 (char_u *)NULL, PV_NONE,
2194 {(char_u *)NULL, (char_u *)0L}
2195#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002196 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002197 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002198#ifdef FEAT_PRINTER
2199 (char_u *)&p_popt, PV_NONE,
2200 {(char_u *)"", (char_u *)0L}
2201#else
2202 (char_u *)NULL, PV_NONE,
2203 {(char_u *)NULL, (char_u *)0L}
2204#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002205 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002206 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002207 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002208 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002209 {"pumheight", "ph", P_NUM|P_VI_DEF,
2210#ifdef FEAT_INS_EXPAND
2211 (char_u *)&p_ph, PV_NONE,
2212#else
2213 (char_u *)NULL, PV_NONE,
2214#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002215 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002216 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002217#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002218 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002219 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002220#else
2221 (char_u *)NULL, PV_NONE,
2222 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002223#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002224 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002225 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002226#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002227 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002228 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002229#else
2230 (char_u *)NULL, PV_NONE,
2231 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002232#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002233 SCRIPTID_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002234 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2235#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2236 (char_u *)&p_pyx, PV_NONE,
2237#else
2238 (char_u *)NULL, PV_NONE,
2239#endif
2240 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
2241 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002242 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2243#ifdef FEAT_TEXTOBJ
2244 (char_u *)&p_qe, PV_QE,
2245 {(char_u *)"\\", (char_u *)0L}
2246#else
2247 (char_u *)NULL, PV_NONE,
2248 {(char_u *)NULL, (char_u *)0L}
2249#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002250 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002251 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2252 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002253 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002254 {"redraw", NULL, P_BOOL|P_VI_DEF,
2255 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002256 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002257 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2258#ifdef FEAT_RELTIME
2259 (char_u *)&p_rdt, PV_NONE,
2260#else
2261 (char_u *)NULL, PV_NONE,
2262#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002263 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002264 {"regexpengine", "re", P_NUM|P_VI_DEF,
2265 (char_u *)&p_re, PV_NONE,
2266 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002267 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2268 (char_u *)VAR_WIN, PV_RNU,
2269 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002270 {"remap", NULL, P_BOOL|P_VI_DEF,
2271 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002272 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002273 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002274#ifdef FEAT_RENDER_OPTIONS
2275 (char_u *)&p_rop, PV_NONE,
2276 {(char_u *)"", (char_u *)0L}
2277#else
2278 (char_u *)NULL, PV_NONE,
2279 {(char_u *)NULL, (char_u *)0L}
2280#endif
2281 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002282 {"report", NULL, P_NUM|P_VI_DEF,
2283 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002284 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002285 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2286#ifdef WIN3264
2287 (char_u *)&p_rs, PV_NONE,
2288#else
2289 (char_u *)NULL, PV_NONE,
2290#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002291 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002292 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2293#ifdef FEAT_RIGHTLEFT
2294 (char_u *)&p_ri, PV_NONE,
2295#else
2296 (char_u *)NULL, PV_NONE,
2297#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002298 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002299 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2300#ifdef FEAT_RIGHTLEFT
2301 (char_u *)VAR_WIN, PV_RL,
2302#else
2303 (char_u *)NULL, PV_NONE,
2304#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002305 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002306 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2307#ifdef FEAT_RIGHTLEFT
2308 (char_u *)VAR_WIN, PV_RLC,
2309 {(char_u *)"search", (char_u *)NULL}
2310#else
2311 (char_u *)NULL, PV_NONE,
2312 {(char_u *)NULL, (char_u *)0L}
2313#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002314 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002315 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002316#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002317 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002318 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002319#else
2320 (char_u *)NULL, PV_NONE,
2321 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002322#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002323 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002324 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2325#ifdef FEAT_CMDL_INFO
2326 (char_u *)&p_ru, PV_NONE,
2327#else
2328 (char_u *)NULL, PV_NONE,
2329#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002330 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002331 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2332#ifdef FEAT_STL_OPT
2333 (char_u *)&p_ruf, PV_NONE,
2334#else
2335 (char_u *)NULL, PV_NONE,
2336#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002337 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002338 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2339 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002340 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002341 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2342 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002343 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2344 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002345 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002346 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2347#ifdef FEAT_SCROLLBIND
2348 (char_u *)VAR_WIN, PV_SCBIND,
2349#else
2350 (char_u *)NULL, PV_NONE,
2351#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002352 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002353 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2354 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002355 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002356 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2357 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002358 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002359 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002360#ifdef FEAT_SCROLLBIND
2361 (char_u *)&p_sbo, PV_NONE,
2362 {(char_u *)"ver,jump", (char_u *)0L}
2363#else
2364 (char_u *)NULL, PV_NONE,
2365 {(char_u *)0L, (char_u *)0L}
2366#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002367 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002368 {"sections", "sect", P_STRING|P_VI_DEF,
2369 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002370 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2371 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002372 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2373 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002374 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002375 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002376 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002377 {(char_u *)"inclusive", (char_u *)0L}
2378 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002379 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002380 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002381 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002382 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002383#ifdef FEAT_SESSION
2384 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002385 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002386 (char_u *)0L}
2387#else
2388 (char_u *)NULL, PV_NONE,
2389 {(char_u *)0L, (char_u *)0L}
2390#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002391 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002392 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2393 (char_u *)&p_sh, PV_NONE,
2394 {
2395#ifdef VMS
2396 (char_u *)"-",
2397#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002398# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002399 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002400# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002401 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002402# endif
2403#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002404 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002405 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2406 (char_u *)&p_shcf, PV_NONE,
2407 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002408#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002409 (char_u *)"/c",
2410#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002411 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002412#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002413 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002414 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2415#ifdef FEAT_QUICKFIX
2416 (char_u *)&p_sp, PV_NONE,
2417 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002418#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002419 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002420#else
2421 (char_u *)">",
2422#endif
2423 (char_u *)0L}
2424#else
2425 (char_u *)NULL, PV_NONE,
2426 {(char_u *)0L, (char_u *)0L}
2427#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002428 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002429 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2430 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002431 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002432 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2433 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002434 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002435 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2436#ifdef BACKSLASH_IN_FILENAME
2437 (char_u *)&p_ssl, PV_NONE,
2438#else
2439 (char_u *)NULL, PV_NONE,
2440#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002441 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002442 {"shelltemp", "stmp", P_BOOL,
2443 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002444 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002445 {"shelltype", "st", P_NUM|P_VI_DEF,
2446#ifdef AMIGA
2447 (char_u *)&p_st, PV_NONE,
2448#else
2449 (char_u *)NULL, PV_NONE,
2450#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002451 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002452 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2453 (char_u *)&p_sxq, PV_NONE,
2454 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002455#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002456 (char_u *)"\"",
2457#else
2458 (char_u *)"",
2459#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002460 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002461 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2462 (char_u *)&p_sxe, PV_NONE,
2463 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002464#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002465 (char_u *)"\"&|<>()@^",
2466#else
2467 (char_u *)"",
2468#endif
2469 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002470 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2471 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002472 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002473 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2474 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002475 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002476 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2477 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002478 {(char_u *)"", (char_u *)"filnxtToO"}
2479 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002480 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002481 (char_u *)&p_sn, PV_SN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002482 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002483 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2484#ifdef FEAT_LINEBREAK
2485 (char_u *)&p_sbr, PV_NONE,
2486#else
2487 (char_u *)NULL, PV_NONE,
2488#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002489 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002490 {"showcmd", "sc", P_BOOL|P_VIM,
2491#ifdef FEAT_CMDL_INFO
2492 (char_u *)&p_sc, PV_NONE,
2493#else
2494 (char_u *)NULL, PV_NONE,
2495#endif
2496 {(char_u *)FALSE,
2497#ifdef UNIX
2498 (char_u *)FALSE
2499#else
2500 (char_u *)TRUE
2501#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002502 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002503 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2504 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002505 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002506 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2507 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002508 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002509 {"showmode", "smd", P_BOOL|P_VIM,
2510 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002511 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002512 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002513 (char_u *)&p_stal, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002514 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002515 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2516 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002517 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002518 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2519 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002520 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002521 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2522#ifdef FEAT_SIGNS
2523 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002524 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002525#else
2526 (char_u *)NULL, PV_NONE,
2527 {(char_u *)NULL, (char_u *)0L}
2528#endif
Bram Moolenaarb3384832016-08-12 18:51:58 +02002529 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002530 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2531 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002532 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002533 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2534 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002535 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002536 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2537#ifdef FEAT_SMARTINDENT
2538 (char_u *)&p_si, PV_SI,
2539#else
2540 (char_u *)NULL, PV_NONE,
2541#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002542 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002543 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2544 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002545 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002546 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2547 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002548 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002549 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2550 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002551 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002552 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002553#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002554 (char_u *)VAR_WIN, PV_SPELL,
2555#else
2556 (char_u *)NULL, PV_NONE,
2557#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002558 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002559 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002560#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002561 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002562 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002563#else
2564 (char_u *)NULL, PV_NONE,
2565 {(char_u *)0L, (char_u *)0L}
2566#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002567 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002568 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2569 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002570#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002571 (char_u *)&p_spf, PV_SPF,
2572 {(char_u *)"", (char_u *)0L}
2573#else
2574 (char_u *)NULL, PV_NONE,
2575 {(char_u *)0L, (char_u *)0L}
2576#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002577 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002578 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2579 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002580#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002581 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002582 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002583#else
2584 (char_u *)NULL, PV_NONE,
2585 {(char_u *)0L, (char_u *)0L}
2586#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002587 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002588 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002589#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002590 (char_u *)&p_sps, PV_NONE,
2591 {(char_u *)"best", (char_u *)0L}
2592#else
2593 (char_u *)NULL, PV_NONE,
2594 {(char_u *)0L, (char_u *)0L}
2595#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002596 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002597 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002598 (char_u *)&p_sb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002599 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002600 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002601 (char_u *)&p_spr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002602 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002603 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2604 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002605 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002606 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2607#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002608 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002609#else
2610 (char_u *)NULL, PV_NONE,
2611#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002612 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002613 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002614 (char_u *)&p_su, PV_NONE,
2615 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002616 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002617 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002618#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002619 (char_u *)&p_sua, PV_SUA,
2620 {(char_u *)"", (char_u *)0L}
2621#else
2622 (char_u *)NULL, PV_NONE,
2623 {(char_u *)0L, (char_u *)0L}
2624#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002625 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002626 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2627 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002628 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002629 {"swapsync", "sws", P_STRING|P_VI_DEF,
2630 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002631 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002632 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002633 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002634 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002635 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2636#ifdef FEAT_SYN_HL
2637 (char_u *)&p_smc, PV_SMC,
2638 {(char_u *)3000L, (char_u *)0L}
2639#else
2640 (char_u *)NULL, PV_NONE,
2641 {(char_u *)0L, (char_u *)0L}
2642#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002643 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002644 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002645#ifdef FEAT_SYN_HL
2646 (char_u *)&p_syn, PV_SYN,
2647 {(char_u *)"", (char_u *)0L}
2648#else
2649 (char_u *)NULL, PV_NONE,
2650 {(char_u *)0L, (char_u *)0L}
2651#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002652 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002653 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2654#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002655 (char_u *)&p_tal, PV_NONE,
2656#else
2657 (char_u *)NULL, PV_NONE,
2658#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002659 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002660 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002661 (char_u *)&p_tpm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002662 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002663 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2664 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002665 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002666 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2667 (char_u *)&p_tbs, PV_NONE,
2668#ifdef VMS /* binary searching doesn't appear to work on VMS */
2669 {(char_u *)0L, (char_u *)0L}
2670#else
2671 {(char_u *)TRUE, (char_u *)0L}
2672#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002673 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002674 {"tagcase", "tc", P_STRING|P_VIM,
2675 (char_u *)&p_tc, PV_TC,
2676 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002677 {"taglength", "tl", P_NUM|P_VI_DEF,
2678 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002679 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002680 {"tagrelative", "tr", P_BOOL|P_VIM,
2681 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002682 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002683 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002684 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002685 {
2686#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2687 (char_u *)"./tags,./TAGS,tags,TAGS",
2688#else
2689 (char_u *)"./tags,tags",
2690#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002691 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002692 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2693 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002694 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002695 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002696#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002697 (char_u *)&p_tcldll, PV_NONE,
2698 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002699#else
2700 (char_u *)NULL, PV_NONE,
2701 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002702#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002703 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002704 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2705 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002706 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002707 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2708#ifdef FEAT_ARABIC
2709 (char_u *)&p_tbidi, PV_NONE,
2710#else
2711 (char_u *)NULL, PV_NONE,
2712#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002713 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002714 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2715#ifdef FEAT_MBYTE
2716 (char_u *)&p_tenc, PV_NONE,
2717 {(char_u *)"", (char_u *)0L}
2718#else
2719 (char_u *)NULL, PV_NONE,
2720 {(char_u *)0L, (char_u *)0L}
2721#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002722 SCRIPTID_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002723 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2724#ifdef FEAT_TERMGUICOLORS
2725 (char_u *)&p_tgc, PV_NONE,
2726 {(char_u *)FALSE, (char_u *)FALSE}
2727#else
2728 (char_u*)NULL, PV_NONE,
2729 {(char_u *)FALSE, (char_u *)FALSE}
2730#endif
2731 SCRIPTID_INIT},
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002732 {"termkey", "tk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2733#ifdef FEAT_TERMINAL
2734 (char_u *)VAR_WIN, PV_TK,
Bram Moolenaar1f28b4c2017-07-28 13:48:34 +02002735 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002736#else
2737 (char_u *)NULL, PV_NONE,
2738 {(char_u *)NULL, (char_u *)0L}
2739#endif
2740 SCRIPTID_INIT},
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002741 {"termsize", "tms", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2742#ifdef FEAT_TERMINAL
2743 (char_u *)VAR_WIN, PV_TMS,
2744 {(char_u *)"", (char_u *)NULL}
2745#else
2746 (char_u *)NULL, PV_NONE,
2747 {(char_u *)NULL, (char_u *)0L}
2748#endif
2749 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002750 {"terse", NULL, P_BOOL|P_VI_DEF,
2751 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002752 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002753 {"textauto", "ta", P_BOOL|P_VIM,
2754 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002755 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2756 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002757 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2758 (char_u *)&p_tx, PV_TX,
2759 {
2760#ifdef USE_CRNL
2761 (char_u *)TRUE,
2762#else
2763 (char_u *)FALSE,
2764#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002765 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002766 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002767 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002768 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002769 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002770#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002771 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002772#else
2773 (char_u *)NULL, PV_NONE,
2774#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002775 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002776 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2777 (char_u *)&p_to, 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 {"timeout", "to", P_BOOL|P_VI_DEF,
2780 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002781 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002782 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2783 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002784 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002785 {"title", NULL, P_BOOL|P_VI_DEF,
2786#ifdef FEAT_TITLE
2787 (char_u *)&p_title, PV_NONE,
2788#else
2789 (char_u *)NULL, PV_NONE,
2790#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002791 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002792 {"titlelen", NULL, P_NUM|P_VI_DEF,
2793#ifdef FEAT_TITLE
2794 (char_u *)&p_titlelen, PV_NONE,
2795#else
2796 (char_u *)NULL, PV_NONE,
2797#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002798 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002799 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002800#ifdef FEAT_TITLE
2801 (char_u *)&p_titleold, PV_NONE,
2802 {(char_u *)N_("Thanks for flying Vim"),
2803 (char_u *)0L}
2804#else
2805 (char_u *)NULL, PV_NONE,
2806 {(char_u *)0L, (char_u *)0L}
2807#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002808 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002809 {"titlestring", NULL, P_STRING|P_VI_DEF,
2810#ifdef FEAT_TITLE
2811 (char_u *)&p_titlestring, PV_NONE,
2812#else
2813 (char_u *)NULL, PV_NONE,
2814#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002815 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002816 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002817#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002818 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002819 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002820#else
2821 (char_u *)NULL, PV_NONE,
2822 {(char_u *)0L, (char_u *)0L}
2823#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002824 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002825 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002826#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002827 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002828 {(char_u *)"small", (char_u *)0L}
2829#else
2830 (char_u *)NULL, PV_NONE,
2831 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002832#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002833 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002834 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2835 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002836 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002837 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2838 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002839 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002840 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2841 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002842 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002843 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2844 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002845 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002846 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2847#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2848 (char_u *)&p_ttym, PV_NONE,
2849#else
2850 (char_u *)NULL, PV_NONE,
2851#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002852 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002853 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2854 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002855 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002856 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2857 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002858 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002859 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2860 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002861#ifdef FEAT_PERSISTENT_UNDO
2862 (char_u *)&p_udir, PV_NONE,
2863 {(char_u *)".", (char_u *)0L}
2864#else
2865 (char_u *)NULL, PV_NONE,
2866 {(char_u *)0L, (char_u *)0L}
2867#endif
2868 SCRIPTID_INIT},
2869 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2870#ifdef FEAT_PERSISTENT_UNDO
2871 (char_u *)&p_udf, PV_UDF,
2872#else
2873 (char_u *)NULL, PV_NONE,
2874#endif
2875 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002876 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002877 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002878 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002879#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002880 (char_u *)1000L,
2881#else
2882 (char_u *)100L,
2883#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002884 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002885 {"undoreload", "ur", P_NUM|P_VI_DEF,
2886 (char_u *)&p_ur, PV_NONE,
2887 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002888 {"updatecount", "uc", P_NUM|P_VI_DEF,
2889 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002890 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002891 {"updatetime", "ut", P_NUM|P_VI_DEF,
2892 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002893 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002894 {"verbose", "vbs", P_NUM|P_VI_DEF,
2895 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002896 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002897 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2898 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002899 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002900 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2901#ifdef FEAT_SESSION
2902 (char_u *)&p_vdir, PV_NONE,
2903 {(char_u *)DFLT_VDIR, (char_u *)0L}
2904#else
2905 (char_u *)NULL, PV_NONE,
2906 {(char_u *)0L, (char_u *)0L}
2907#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002908 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002909 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002910#ifdef FEAT_SESSION
2911 (char_u *)&p_vop, PV_NONE,
2912 {(char_u *)"folds,options,cursor", (char_u *)0L}
2913#else
2914 (char_u *)NULL, PV_NONE,
2915 {(char_u *)0L, (char_u *)0L}
2916#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002917 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002918 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002919#ifdef FEAT_VIMINFO
2920 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002921#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002922 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002923#else
2924# ifdef AMIGA
2925 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002926 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002927# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002928 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002929# endif
2930#endif
2931#else
2932 (char_u *)NULL, PV_NONE,
2933 {(char_u *)0L, (char_u *)0L}
2934#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002935 SCRIPTID_INIT},
Bram Moolenaarc4da1132017-07-15 19:39:43 +02002936 {"viminfofile", "vif", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE|P_VI_DEF,
2937#ifdef FEAT_VIMINFO
2938 (char_u *)&p_viminfofile, PV_NONE,
2939 {(char_u *)"", (char_u *)0L}
2940#else
2941 (char_u *)NULL, PV_NONE,
2942 {(char_u *)0L, (char_u *)0L}
2943#endif
2944 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002945 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2946 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002947#ifdef FEAT_VIRTUALEDIT
2948 (char_u *)&p_ve, PV_NONE,
2949 {(char_u *)"", (char_u *)""}
2950#else
2951 (char_u *)NULL, PV_NONE,
2952 {(char_u *)0L, (char_u *)0L}
2953#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002954 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002955 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2956 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002957 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002958 {"w300", NULL, P_NUM|P_VI_DEF,
2959 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002960 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002961 {"w1200", NULL, P_NUM|P_VI_DEF,
2962 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002963 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002964 {"w9600", NULL, P_NUM|P_VI_DEF,
2965 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002966 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002967 {"warn", NULL, P_BOOL|P_VI_DEF,
2968 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002969 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002970 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2971 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002972 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002973 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002974 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002975 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002976 {"wildchar", "wc", P_NUM|P_VIM,
2977 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002978 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2979 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002980 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002981 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002982 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002983 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002984#ifdef FEAT_WILDIGN
2985 (char_u *)&p_wig, PV_NONE,
2986#else
2987 (char_u *)NULL, PV_NONE,
2988#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002989 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002990 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2991 (char_u *)&p_wic, PV_NONE,
2992 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002993 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2994#ifdef FEAT_WILDMENU
2995 (char_u *)&p_wmnu, PV_NONE,
2996#else
2997 (char_u *)NULL, PV_NONE,
2998#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002999 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003000 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003001 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003002 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003003 {"wildoptions", "wop", P_STRING|P_VI_DEF,
3004#ifdef FEAT_CMDL_COMPL
3005 (char_u *)&p_wop, PV_NONE,
3006 {(char_u *)"", (char_u *)0L}
3007#else
3008 (char_u *)NULL, PV_NONE,
3009 {(char_u *)NULL, (char_u *)0L}
3010#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003011 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003012 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3013#ifdef FEAT_WAK
3014 (char_u *)&p_wak, PV_NONE,
3015 {(char_u *)"menu", (char_u *)0L}
3016#else
3017 (char_u *)NULL, PV_NONE,
3018 {(char_u *)NULL, (char_u *)0L}
3019#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003020 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003021 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003022 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003023 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003024 {"winheight", "wh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003025 (char_u *)&p_wh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003026 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003027 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003028 (char_u *)VAR_WIN, PV_WFH,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003029 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003030 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003031 (char_u *)VAR_WIN, PV_WFW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003032 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003033 {"winminheight", "wmh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003034 (char_u *)&p_wmh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003035 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003036 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003037 (char_u *)&p_wmw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003038 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003039 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar84ed4ad2017-08-17 11:33:42 +02003040#if defined(WIN3264) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003041 (char_u *)&p_winptydll, PV_NONE, {
3042# ifdef _WIN64
3043 (char_u *)"winpty64.dll",
3044# else
3045 (char_u *)"winpty32.dll",
3046# endif
3047 (char_u *)0L}
3048#else
3049 (char_u *)NULL, PV_NONE,
3050 {(char_u *)0L, (char_u *)0L}
3051#endif
3052 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003053 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003054 (char_u *)&p_wiw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003055 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003056 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3057 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003058 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003059 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3060 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003061 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003062 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3063 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003064 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003065 {"write", NULL, P_BOOL|P_VI_DEF,
3066 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003067 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003068 {"writeany", "wa", P_BOOL|P_VI_DEF,
3069 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003070 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003071 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3072 (char_u *)&p_wb, PV_NONE,
3073 {
3074#ifdef FEAT_WRITEBACKUP
3075 (char_u *)TRUE,
3076#else
3077 (char_u *)FALSE,
3078#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003079 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003080 {"writedelay", "wd", P_NUM|P_VI_DEF,
3081 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003082 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003083
3084/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003085#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003086 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003087 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003088
3089 p_term("t_AB", T_CAB)
3090 p_term("t_AF", T_CAF)
3091 p_term("t_AL", T_CAL)
3092 p_term("t_al", T_AL)
3093 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003094 p_term("t_BE", T_BE)
3095 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003096 p_term("t_cd", T_CD)
3097 p_term("t_ce", T_CE)
3098 p_term("t_cl", T_CL)
3099 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003100 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003101 p_term("t_Co", T_CCO)
3102 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003103 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003104 p_term("t_cs", T_CS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003105 p_term("t_CV", T_CSV)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003106 p_term("t_da", T_DA)
3107 p_term("t_db", T_DB)
3108 p_term("t_DL", T_CDL)
3109 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003110 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003111 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003112 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003113 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003114 p_term("t_IE", T_CIE)
3115 p_term("t_IS", T_CIS)
3116 p_term("t_ke", T_KE)
3117 p_term("t_ks", T_KS)
3118 p_term("t_le", T_LE)
3119 p_term("t_mb", T_MB)
3120 p_term("t_md", T_MD)
3121 p_term("t_me", T_ME)
3122 p_term("t_mr", T_MR)
3123 p_term("t_ms", T_MS)
3124 p_term("t_nd", T_ND)
3125 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02003126 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003127 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003128 p_term("t_RI", T_CRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003129 p_term("t_RS", T_CRS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003130 p_term("t_RV", T_CRV)
3131 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003132 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003133 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003134 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003135 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003136 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003137 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003138 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003139 p_term("t_sr", T_SR)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003140 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003141 p_term("t_te", T_TE)
3142 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003143 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003144 p_term("t_ts", T_TS)
3145 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003146 p_term("t_ue", T_UE)
3147 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003148 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003149 p_term("t_vb", T_VB)
3150 p_term("t_ve", T_VE)
3151 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003152 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003153 p_term("t_vs", T_VS)
3154 p_term("t_WP", T_CWP)
3155 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003156 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003157 p_term("t_xs", T_XS)
3158 p_term("t_ZH", T_CZH)
3159 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003160 p_term("t_8f", T_8F)
3161 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003162
3163/* terminal key codes are not in here */
3164
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003165 /* end marker */
3166 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003167};
3168
3169#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3170
3171#ifdef FEAT_MBYTE
3172static char *(p_ambw_values[]) = {"single", "double", NULL};
3173#endif
3174static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003175static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003176static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003177#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003178static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003179#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003180#ifdef FEAT_CMDL_COMPL
3181static char *(p_wop_values[]) = {"tagfile", NULL};
3182#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003183#ifdef FEAT_WAK
3184static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3185#endif
3186static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003187static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3188static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003189static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003190#ifdef FEAT_BROWSE
3191static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3192#endif
3193#ifdef FEAT_SCROLLBIND
3194static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3195#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003196static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003197static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003198#ifdef FEAT_AUTOCMD
3199static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", NULL};
3200#else
3201static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003202#endif
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003203static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003204static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3205#ifdef FEAT_FOLDING
3206static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003207# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003208 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003209# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003210 NULL};
3211static char *(p_fcl_values[]) = {"all", NULL};
3212#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003213#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003214static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003215#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003216#ifdef FEAT_SIGNS
3217static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3218#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003219
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003220static void set_option_default(int, int opt_flags, int compatible);
3221static void set_options_default(int opt_flags);
3222static char_u *term_bg_default(void);
3223static void did_set_option(int opt_idx, int opt_flags, int new_value);
3224static char_u *illegal_char(char_u *, int);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003225#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003226static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003227#endif
3228#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003229static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003230#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003231static char_u *option_expand(int opt_idx, char_u *val);
3232static void didset_options(void);
3233static void didset_options2(void);
3234static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003235#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003236static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003237#else
3238# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3239#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003240static void set_string_option_global(int opt_idx, char_u **varp);
3241static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3242static 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);
3243static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003244#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003245static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003246#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003247#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003248static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003249#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003250#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003251static char_u *did_set_spell_option(int is_spellfile);
3252static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003253#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003254#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003255static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003256#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003257static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3258static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3259static void check_redraw(long_u flags);
3260static int findoption(char_u *);
3261static int find_key_option(char_u *);
3262static void showoptions(int all, int opt_flags);
3263static int optval_default(struct vimoption *, char_u *varp);
3264static void showoneopt(struct vimoption *, int opt_flags);
3265static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3266static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3267static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3268static int istermoption(struct vimoption *);
3269static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3270static char_u *get_varp(struct vimoption *);
3271static void option_value2string(struct vimoption *, int opt_flags);
3272static void check_winopt(winopt_T *wop);
3273static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003274#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003275static void langmap_init(void);
3276static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003277#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003278static void paste_option_changed(void);
3279static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003280#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003281static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003282#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003283static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3284static int check_opt_strings(char_u *val, char **values, int);
3285static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003286#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003287static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003288#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003289
3290/*
3291 * Initialize the options, first part.
3292 *
3293 * Called only once from main(), just after creating the first buffer.
3294 */
3295 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003296set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003297{
3298 char_u *p;
3299 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003300 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003301
3302#ifdef FEAT_LANGMAP
3303 langmap_init();
3304#endif
3305
3306 /* Be Vi compatible by default */
3307 p_cp = TRUE;
3308
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003309 /* Use POSIX compatibility when $VIM_POSIX is set. */
3310 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003311 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003312 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003313 set_string_default("shm", (char_u *)"A");
3314 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003315
Bram Moolenaar071d4272004-06-13 20:20:40 +00003316 /*
3317 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003318 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003319 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003320 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003321#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003322 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003323# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003324 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003325# endif
3326#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003327 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003328 set_string_default("sh", p);
3329
3330#ifdef FEAT_WILDIGN
3331 /*
3332 * Set the default for 'backupskip' to include environment variables for
3333 * temp files.
3334 */
3335 {
3336# ifdef UNIX
3337 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3338# else
3339 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3340# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003341 int len;
3342 garray_T ga;
3343 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003344
3345 ga_init2(&ga, 1, 100);
3346 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3347 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003348 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003349# ifdef UNIX
3350 if (*names[n] == NUL)
3351 p = (char_u *)"/tmp";
3352 else
3353# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003354 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003355 if (p != NULL && *p != NUL)
3356 {
3357 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003358 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003359 if (ga_grow(&ga, len) == OK)
3360 {
3361 if (ga.ga_len > 0)
3362 STRCAT(ga.ga_data, ",");
3363 STRCAT(ga.ga_data, p);
3364 add_pathsep(ga.ga_data);
3365 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003366 ga.ga_len += len;
3367 }
3368 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003369 if (mustfree)
3370 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003371 }
3372 if (ga.ga_data != NULL)
3373 {
3374 set_string_default("bsk", ga.ga_data);
3375 vim_free(ga.ga_data);
3376 }
3377 }
3378#endif
3379
3380 /*
3381 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3382 */
3383 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003384 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003385 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003386#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3387 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3388#endif
3389 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003390#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003391 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003392 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003393#else
3394# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003395 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003396 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003397# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003398 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003399# endif
3400#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003401 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003402 opt_idx = findoption((char_u *)"maxmem");
3403 if (opt_idx >= 0)
3404 {
3405#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003406 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3407 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003408#endif
3409 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3410 }
3411 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003412 }
3413
Bram Moolenaar071d4272004-06-13 20:20:40 +00003414#ifdef FEAT_SEARCHPATH
3415 {
3416 char_u *cdpath;
3417 char_u *buf;
3418 int i;
3419 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003420 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003421
3422 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003423 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003424 if (cdpath != NULL)
3425 {
3426 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3427 if (buf != NULL)
3428 {
3429 buf[0] = ','; /* start with ",", current dir first */
3430 j = 1;
3431 for (i = 0; cdpath[i] != NUL; ++i)
3432 {
3433 if (vim_ispathlistsep(cdpath[i]))
3434 buf[j++] = ',';
3435 else
3436 {
3437 if (cdpath[i] == ' ' || cdpath[i] == ',')
3438 buf[j++] = '\\';
3439 buf[j++] = cdpath[i];
3440 }
3441 }
3442 buf[j] = NUL;
3443 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003444 if (opt_idx >= 0)
3445 {
3446 options[opt_idx].def_val[VI_DEFAULT] = buf;
3447 options[opt_idx].flags |= P_DEF_ALLOCED;
3448 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003449 else
3450 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003451 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003452 if (mustfree)
3453 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003454 }
3455 }
3456#endif
3457
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003458#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003459 /* Set print encoding on platforms that don't default to latin1 */
3460 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003461# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003462 (char_u *)"cp1252"
3463# else
3464# ifdef VMS
3465 (char_u *)"dec-mcs"
3466# else
3467# ifdef EBCDIC
3468 (char_u *)"ebcdic-uk"
3469# else
3470# ifdef MAC
3471 (char_u *)"mac-roman"
3472# else /* HPUX */
3473 (char_u *)"hp-roman8"
3474# endif
3475# endif
3476# endif
3477# endif
3478 );
3479#endif
3480
3481#ifdef FEAT_POSTSCRIPT
3482 /* 'printexpr' must be allocated to be able to evaluate it. */
3483 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003484# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003485 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003486# else
3487# ifdef VMS
3488 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3489
3490# else
3491 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3492# endif
3493# endif
3494 );
3495#endif
3496
3497 /*
3498 * Set all the options (except the terminal options) to their default
3499 * value. Also set the global value for local options.
3500 */
3501 set_options_default(0);
3502
3503#ifdef FEAT_GUI
3504 if (found_reverse_arg)
3505 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3506#endif
3507
3508 curbuf->b_p_initialized = TRUE;
3509 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003510 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003511 check_buf_options(curbuf);
3512 check_win_options(curwin);
3513 check_options();
3514
3515 /* Must be before option_expand(), because that one needs vim_isIDc() */
3516 didset_options();
3517
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003518#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003519 /* Use the current chartab for the generic chartab. This is not in
3520 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003521 init_spell_chartab();
3522#endif
3523
Bram Moolenaar071d4272004-06-13 20:20:40 +00003524 /*
3525 * Expand environment variables and things like "~" for the defaults.
3526 * If option_expand() returns non-NULL the variable is expanded. This can
3527 * only happen for non-indirect options.
3528 * Also set the default to the expanded value, so ":set" does not list
3529 * them.
3530 * Don't set the P_ALLOCED flag, because we don't want to free the
3531 * default.
3532 */
3533 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3534 {
3535 if ((options[opt_idx].flags & P_GETTEXT)
3536 && options[opt_idx].var != NULL)
3537 p = (char_u *)_(*(char **)options[opt_idx].var);
3538 else
3539 p = option_expand(opt_idx, NULL);
3540 if (p != NULL && (p = vim_strsave(p)) != NULL)
3541 {
3542 *(char_u **)options[opt_idx].var = p;
3543 /* VIMEXP
3544 * Defaults for all expanded options are currently the same for Vi
3545 * and Vim. When this changes, add some code here! Also need to
3546 * split P_DEF_ALLOCED in two.
3547 */
3548 if (options[opt_idx].flags & P_DEF_ALLOCED)
3549 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3550 options[opt_idx].def_val[VI_DEFAULT] = p;
3551 options[opt_idx].flags |= P_DEF_ALLOCED;
3552 }
3553 }
3554
Bram Moolenaar071d4272004-06-13 20:20:40 +00003555 save_file_ff(curbuf); /* Buffer is unchanged */
3556
Bram Moolenaar071d4272004-06-13 20:20:40 +00003557#if defined(FEAT_ARABIC)
3558 /* Detect use of mlterm.
3559 * Mlterm is a terminal emulator akin to xterm that has some special
3560 * abilities (bidi namely).
3561 * NOTE: mlterm's author is being asked to 'set' a variable
3562 * instead of an environment variable due to inheritance.
3563 */
3564 if (mch_getenv((char_u *)"MLTERM") != NULL)
3565 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3566#endif
3567
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003568 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003569
3570#ifdef FEAT_MBYTE
3571# if defined(WIN3264) && defined(FEAT_GETTEXT)
3572 /*
3573 * If $LANG isn't set, try to get a good value for it. This makes the
3574 * right language be used automatically. Don't do this for English.
3575 */
3576 if (mch_getenv((char_u *)"LANG") == NULL)
3577 {
3578 char buf[20];
3579
3580 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3581 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3582 * only the first two. */
3583 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3584 (LPTSTR)buf, 20);
3585 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3586 {
3587 /* There are a few exceptions (probably more) */
3588 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3589 STRCPY(buf, "zh_TW");
3590 else if (STRNICMP(buf, "chs", 3) == 0
3591 || STRNICMP(buf, "zhc", 3) == 0)
3592 STRCPY(buf, "zh_CN");
3593 else if (STRNICMP(buf, "jp", 2) == 0)
3594 STRCPY(buf, "ja");
3595 else
3596 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003597 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003598 }
3599 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003600# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003601# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003602 /* Moved to os_mac_conv.c to avoid dependency problems. */
3603 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003604# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003605# endif
3606
3607 /* enc_locale() will try to find the encoding of the current locale. */
3608 p = enc_locale();
3609 if (p != NULL)
3610 {
3611 char_u *save_enc;
3612
3613 /* Try setting 'encoding' and check if the value is valid.
3614 * If not, go back to the default "latin1". */
3615 save_enc = p_enc;
3616 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003617 if (STRCMP(p_enc, "gb18030") == 0)
3618 {
3619 /* We don't support "gb18030", but "cp936" is a good substitute
3620 * for practical purposes, thus use that. It's not an alias to
3621 * still support conversion between gb18030 and utf-8. */
3622 p_enc = vim_strsave((char_u *)"cp936");
3623 vim_free(p);
3624 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003625 if (mb_init() == NULL)
3626 {
3627 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003628 if (opt_idx >= 0)
3629 {
3630 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3631 options[opt_idx].flags |= P_DEF_ALLOCED;
3632 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003633
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003634#if defined(MSWIN) || defined(MACOS) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003635 if (STRCMP(p_enc, "latin1") == 0
3636# ifdef FEAT_MBYTE
3637 || enc_utf8
3638# endif
3639 )
3640 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003641 /* Adjust the default for 'isprint' and 'iskeyword' to match
3642 * latin1. Also set the defaults for when 'nocompatible' is
3643 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003644 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003645 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003646 set_string_option_direct((char_u *)"isk", -1,
3647 ISK_LATIN1, OPT_FREE, SID_NONE);
3648 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003649 if (opt_idx >= 0)
3650 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003651 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003652 if (opt_idx >= 0)
3653 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003654 (void)init_chartab();
3655 }
3656#endif
3657
Bram Moolenaar071d4272004-06-13 20:20:40 +00003658# if defined(WIN3264) && !defined(FEAT_GUI)
3659 /* Win32 console: When GetACP() returns a different value from
3660 * GetConsoleCP() set 'termencoding'. */
3661 if (GetACP() != GetConsoleCP())
3662 {
3663 char buf[50];
3664
3665 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3666 p_tenc = vim_strsave((char_u *)buf);
3667 if (p_tenc != NULL)
3668 {
3669 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003670 if (opt_idx >= 0)
3671 {
3672 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3673 options[opt_idx].flags |= P_DEF_ALLOCED;
3674 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003675 convert_setup(&input_conv, p_tenc, p_enc);
3676 convert_setup(&output_conv, p_enc, p_tenc);
3677 }
3678 else
3679 p_tenc = empty_option;
3680 }
3681# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003682# if defined(WIN3264) && defined(FEAT_MBYTE)
3683 /* $HOME may have characters in active code page. */
3684 init_homedir();
3685# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003686 }
3687 else
3688 {
3689 vim_free(p_enc);
3690 p_enc = save_enc;
3691 }
3692 }
3693#endif
3694
3695#ifdef FEAT_MULTI_LANG
3696 /* Set the default for 'helplang'. */
3697 set_helplang_default(get_mess_lang());
3698#endif
3699}
3700
3701/*
3702 * Set an option to its default value.
3703 * This does not take care of side effects!
3704 */
3705 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003706set_option_default(
3707 int opt_idx,
3708 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3709 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003710{
3711 char_u *varp; /* pointer to variable for current option */
3712 int dvi; /* index in def_val[] */
3713 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003714 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003715 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3716
3717 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3718 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003719 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003720 {
3721 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3722 if (flags & P_STRING)
3723 {
3724 /* Use set_string_option_direct() for local options to handle
3725 * freeing and allocating the value. */
3726 if (options[opt_idx].indir != PV_NONE)
3727 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003728 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003729 else
3730 {
3731 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3732 free_string_option(*(char_u **)(varp));
3733 *(char_u **)varp = options[opt_idx].def_val[dvi];
3734 options[opt_idx].flags &= ~P_ALLOCED;
3735 }
3736 }
3737 else if (flags & P_NUM)
3738 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003739 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003740 win_comp_scroll(curwin);
3741 else
3742 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003743 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003744 /* May also set global value for local option. */
3745 if (both)
3746 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3747 *(long *)varp;
3748 }
3749 }
3750 else /* P_BOOL */
3751 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003752 /* the cast to long is required for Manx C, long_i is needed for
3753 * MSVC */
3754 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003755#ifdef UNIX
3756 /* 'modeline' defaults to off for root */
3757 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3758 *(int *)varp = FALSE;
3759#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003760 /* May also set global value for local option. */
3761 if (both)
3762 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3763 *(int *)varp;
3764 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003765
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003766 /* The default value is not insecure. */
3767 flagsp = insecure_flag(opt_idx, opt_flags);
3768 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003769 }
3770
3771#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003772 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003773#endif
3774}
3775
3776/*
3777 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003778 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003779 */
3780 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003781set_options_default(
3782 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003783{
3784 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003785 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003786 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003787
3788 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003789 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003790#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003791 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003792 || (TRUE
3793# if defined(FEAT_MBYTE)
3794 && options[i].var != (char_u *)&p_enc
3795# endif
3796# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003797 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003798 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003799# endif
3800 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003801#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003802 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003803 set_option_default(i, opt_flags, p_cp);
3804
Bram Moolenaar071d4272004-06-13 20:20:40 +00003805 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003806 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003807 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003808#ifdef FEAT_CINDENT
3809 parse_cino(curbuf);
3810#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003811}
3812
3813/*
3814 * Set the Vi-default value of a string option.
3815 * Used for 'sh', 'backupskip' and 'term'.
3816 */
3817 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003818set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003819{
3820 char_u *p;
3821 int opt_idx;
3822
3823 p = vim_strsave(val);
3824 if (p != NULL) /* we don't want a NULL */
3825 {
3826 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003827 if (opt_idx >= 0)
3828 {
3829 if (options[opt_idx].flags & P_DEF_ALLOCED)
3830 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3831 options[opt_idx].def_val[VI_DEFAULT] = p;
3832 options[opt_idx].flags |= P_DEF_ALLOCED;
3833 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003834 }
3835}
3836
3837/*
3838 * Set the Vi-default value of a number option.
3839 * Used for 'lines' and 'columns'.
3840 */
3841 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003842set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003843{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003844 int opt_idx;
3845
3846 opt_idx = findoption((char_u *)name);
3847 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003848 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003849}
3850
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003851#if defined(EXITFREE) || defined(PROTO)
3852/*
3853 * Free all options.
3854 */
3855 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003856free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003857{
3858 int i;
3859
3860 for (i = 0; !istermoption(&options[i]); i++)
3861 {
3862 if (options[i].indir == PV_NONE)
3863 {
3864 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003865 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003866 free_string_option(*(char_u **)options[i].var);
3867 if (options[i].flags & P_DEF_ALLOCED)
3868 free_string_option(options[i].def_val[VI_DEFAULT]);
3869 }
3870 else if (options[i].var != VAR_WIN
3871 && (options[i].flags & P_STRING))
3872 /* buffer-local option: free global value */
3873 free_string_option(*(char_u **)options[i].var);
3874 }
3875}
3876#endif
3877
3878
Bram Moolenaar071d4272004-06-13 20:20:40 +00003879/*
3880 * Initialize the options, part two: After getting Rows and Columns and
3881 * setting 'term'.
3882 */
3883 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003884set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003885{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003886 int idx;
3887
Bram Moolenaar071d4272004-06-13 20:20:40 +00003888 /*
3889 * 'scroll' defaults to half the window height. Note that this default is
3890 * wrong when the window height changes.
3891 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003892 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003893 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003894 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003895 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003896 comp_col();
3897
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003898 /*
3899 * 'window' is only for backwards compatibility with Vi.
3900 * Default is Rows - 1.
3901 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003902 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003903 p_window = Rows - 1;
3904 set_number_default("window", Rows - 1);
3905
Bram Moolenaarf740b292006-02-16 22:11:02 +00003906 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003907#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003908 /*
3909 * If 'background' wasn't set by the user, try guessing the value,
3910 * depending on the terminal name. Only need to check for terminals
3911 * with a dark background, that can handle color.
3912 */
3913 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003914 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3915 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003916 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003917 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003918 /* don't mark it as set, when starting the GUI it may be
3919 * changed again */
3920 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003921 }
3922#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003923
3924#ifdef CURSOR_SHAPE
3925 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3926#endif
3927#ifdef FEAT_MOUSESHAPE
3928 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3929#endif
3930#ifdef FEAT_PRINTER
3931 (void)parse_printoptions(); /* parse 'printoptions' default value */
3932#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003933}
3934
3935/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003936 * Return "dark" or "light" depending on the kind of terminal.
3937 * This is just guessing! Recognized are:
3938 * "linux" Linux console
3939 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003940 * "cygwin.*" Cygwin shell
3941 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00003942 * We also check the COLORFGBG environment variable, which is set by
3943 * rxvt and derivatives. This variable contains either two or three
3944 * values separated by semicolons; we want the last value in either
3945 * case. If this value is 0-6 or 8, our background is dark.
3946 */
3947 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003948term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003949{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003950#if defined(WIN3264)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003951 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003952 return (char_u *)"dark";
3953#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003954 char_u *p;
3955
Bram Moolenaarf740b292006-02-16 22:11:02 +00003956 if (STRCMP(T_NAME, "linux") == 0
3957 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003958 || STRNCMP(T_NAME, "cygwin", 6) == 0
3959 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00003960 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3961 && (p = vim_strrchr(p, ';')) != NULL
3962 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3963 && p[2] == NUL))
3964 return (char_u *)"dark";
3965 return (char_u *)"light";
3966#endif
3967}
3968
3969/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003970 * Initialize the options, part three: After reading the .vimrc
3971 */
3972 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003973set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003974{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003975#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003976/*
3977 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3978 * This is done after other initializations, where 'shell' might have been
3979 * set, but only if they have not been set before.
3980 */
3981 char_u *p;
3982 int idx_srr;
3983 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003984# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003985 int idx_sp;
3986 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003987# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003988
3989 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003990 if (idx_srr < 0)
3991 do_srr = FALSE;
3992 else
3993 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003994# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003995 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003996 if (idx_sp < 0)
3997 do_sp = FALSE;
3998 else
3999 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004000# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004001 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004002 if (p != NULL)
4003 {
4004 /*
4005 * Default for p_sp is "| tee", for p_srr is ">".
4006 * For known shells it is changed here to include stderr.
4007 */
4008 if ( fnamecmp(p, "csh") == 0
4009 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004010# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004011 || fnamecmp(p, "csh.exe") == 0
4012 || fnamecmp(p, "tcsh.exe") == 0
4013# endif
4014 )
4015 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004016# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004017 if (do_sp)
4018 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004019# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004020 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004021# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004022 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004023# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004024 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4025 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004026# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004027 if (do_srr)
4028 {
4029 p_srr = (char_u *)">&";
4030 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4031 }
4032 }
4033 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004034 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004035 if ( fnamecmp(p, "sh") == 0
4036 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004037 || fnamecmp(p, "mksh") == 0
4038 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004039 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004040 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004041 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004042 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004043# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004044 || fnamecmp(p, "cmd") == 0
4045 || fnamecmp(p, "sh.exe") == 0
4046 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004047 || fnamecmp(p, "mksh.exe") == 0
4048 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004049 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004050 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004051 || fnamecmp(p, "bash.exe") == 0
4052 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004053# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004054 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004055 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004056# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004057 if (do_sp)
4058 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004059# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004060 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004061# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004062 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004063# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004064 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4065 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004066# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004067 if (do_srr)
4068 {
4069 p_srr = (char_u *)">%s 2>&1";
4070 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4071 }
4072 }
4073 vim_free(p);
4074 }
4075#endif
4076
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004077#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004078 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004079 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4080 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004081 * This is done after other initializations, where 'shell' might have been
4082 * set, but only if they have not been set before. Default for p_shcf is
4083 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004084 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004085 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004086 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004087 {
4088 int idx3;
4089
4090 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004091 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004092 {
4093 p_shcf = (char_u *)"-c";
4094 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4095 }
4096
Bram Moolenaar071d4272004-06-13 20:20:40 +00004097 /* Somehow Win32 requires the quotes around the redirection too */
4098 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004099 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004100 {
4101 p_sxq = (char_u *)"\"";
4102 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4103 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004104 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004105 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4106 {
4107 int idx3;
4108
4109 /*
4110 * cmd.exe on Windows will strip the first and last double quote given
4111 * on the command line, e.g. most of the time things like:
4112 * cmd /c "my path/to/echo" "my args to echo"
4113 * become:
4114 * my path/to/echo" "my args to echo
4115 * when executed.
4116 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004117 * To avoid this, set shellxquote to surround the command in
4118 * parenthesis. This appears to make most commands work, without
4119 * breaking commands that worked previously, such as
4120 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004121 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004122 idx3 = findoption((char_u *)"sxq");
4123 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4124 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004125 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004126 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4127 }
4128
Bram Moolenaara64ba222012-02-12 23:23:31 +01004129 idx3 = findoption((char_u *)"shcf");
4130 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4131 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004132 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004133 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4134 }
4135 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004136#endif
4137
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004138 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004139 {
4140 int idx_ffs = findoption((char_u *)"ffs");
4141
4142 /* Apply the first entry of 'fileformats' to the initial buffer. */
4143 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4144 set_fileformat(default_fileformat(), OPT_LOCAL);
4145 }
4146
Bram Moolenaar071d4272004-06-13 20:20:40 +00004147#ifdef FEAT_TITLE
4148 set_title_defaults();
4149#endif
4150}
4151
4152#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4153/*
4154 * When 'helplang' is still at its default value, set it to "lang".
4155 * Only the first two characters of "lang" are used.
4156 */
4157 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004158set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004159{
4160 int idx;
4161
4162 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4163 return;
4164 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004165 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004166 {
4167 if (options[idx].flags & P_ALLOCED)
4168 free_string_option(p_hlg);
4169 p_hlg = vim_strsave(lang);
4170 if (p_hlg == NULL)
4171 p_hlg = empty_option;
4172 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004173 {
4174 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4175 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4176 {
4177 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4178 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4179 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004180 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004181 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004182 options[idx].flags |= P_ALLOCED;
4183 }
4184}
4185#endif
4186
4187#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004188static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004189
4190 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004191gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004192{
4193 if (gui_get_lightness(gui.back_pixel) < 127)
4194 return (char_u *)"dark";
4195 return (char_u *)"light";
4196}
4197
4198/*
4199 * Option initializations that can only be done after opening the GUI window.
4200 */
4201 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004202init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004203{
4204 /* Set the 'background' option according to the lightness of the
4205 * background color, unless the user has set it already. */
4206 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4207 {
4208 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4209 highlight_changed();
4210 }
4211}
4212#endif
4213
4214#ifdef FEAT_TITLE
4215/*
4216 * 'title' and 'icon' only default to true if they have not been set or reset
4217 * in .vimrc and we can read the old value.
4218 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4219 * they can be reset. This reduces startup time when using X on a remote
4220 * machine.
4221 */
4222 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004223set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004224{
4225 int idx1;
4226 long val;
4227
4228 /*
4229 * If GUI is (going to be) used, we can always set the window title and
4230 * icon name. Saves a bit of time, because the X11 display server does
4231 * not need to be contacted.
4232 */
4233 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004234 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004235 {
4236#ifdef FEAT_GUI
4237 if (gui.starting || gui.in_use)
4238 val = TRUE;
4239 else
4240#endif
4241 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004242 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004243 p_title = val;
4244 }
4245 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004246 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004247 {
4248#ifdef FEAT_GUI
4249 if (gui.starting || gui.in_use)
4250 val = TRUE;
4251 else
4252#endif
4253 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004254 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004255 p_icon = val;
4256 }
4257}
4258#endif
4259
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004260#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4261 static void
4262trigger_optionsset_string(
4263 int opt_idx,
4264 int opt_flags,
4265 char_u *oldval,
4266 char_u *newval)
4267{
4268 if (oldval != NULL && newval != NULL)
4269 {
4270 char_u buf_type[7];
4271
4272 sprintf((char *)buf_type, "%s",
4273 (opt_flags & OPT_LOCAL) ? "local" : "global");
4274 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4275 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4276 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4277 apply_autocmds(EVENT_OPTIONSET,
4278 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4279 reset_v_option_vars();
4280 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004281}
4282#endif
4283
Bram Moolenaar071d4272004-06-13 20:20:40 +00004284/*
4285 * Parse 'arg' for option settings.
4286 *
4287 * 'arg' may be IObuff, but only when no errors can be present and option
4288 * does not need to be expanded with option_expand().
4289 * "opt_flags":
4290 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004291 * OPT_GLOBAL for ":setglobal"
4292 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004293 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004294 * OPT_WINONLY to only set window-local options
4295 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004296 *
4297 * returns FAIL if an error is detected, OK otherwise
4298 */
4299 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004300do_set(
4301 char_u *arg, /* option string (may be written to!) */
4302 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004303{
4304 int opt_idx;
4305 char_u *errmsg;
4306 char_u errbuf[80];
4307 char_u *startarg;
4308 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4309 int nextchar; /* next non-white char after option name */
4310 int afterchar; /* character just after option name */
4311 int len;
4312 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004313 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004314 int key;
4315 long_u flags; /* flags for current option */
4316 char_u *varp = NULL; /* pointer to variable for current option */
4317 int did_show = FALSE; /* already showed one value */
4318 int adding; /* "opt+=arg" */
4319 int prepending; /* "opt^=arg" */
4320 int removing; /* "opt-=arg" */
4321 int cp_val = 0;
4322 char_u key_name[2];
4323
4324 if (*arg == NUL)
4325 {
4326 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004327 did_show = TRUE;
4328 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004329 }
4330
4331 while (*arg != NUL) /* loop to process all options */
4332 {
4333 errmsg = NULL;
4334 startarg = arg; /* remember for error message */
4335
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004336 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4337 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004338 {
4339 /*
4340 * ":set all" show all options.
4341 * ":set all&" set all options to their default value.
4342 */
4343 arg += 3;
4344 if (*arg == '&')
4345 {
4346 ++arg;
4347 /* Only for :set command set global value of local options. */
4348 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004349 didset_options();
4350 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004351 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004352 }
4353 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004354 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004355 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004356 did_show = TRUE;
4357 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004358 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004359 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004360 {
4361 showoptions(2, opt_flags);
4362 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004363 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004364 arg += 7;
4365 }
4366 else
4367 {
4368 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004369 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004370 {
4371 prefix = 0;
4372 arg += 2;
4373 }
4374 else if (STRNCMP(arg, "inv", 3) == 0)
4375 {
4376 prefix = 2;
4377 arg += 3;
4378 }
4379
4380 /* find end of name */
4381 key = 0;
4382 if (*arg == '<')
4383 {
4384 nextchar = 0;
4385 opt_idx = -1;
4386 /* look out for <t_>;> */
4387 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4388 len = 5;
4389 else
4390 {
4391 len = 1;
4392 while (arg[len] != NUL && arg[len] != '>')
4393 ++len;
4394 }
4395 if (arg[len] != '>')
4396 {
4397 errmsg = e_invarg;
4398 goto skip;
4399 }
4400 arg[len] = NUL; /* put NUL after name */
4401 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4402 opt_idx = findoption(arg + 1);
4403 arg[len++] = '>'; /* restore '>' */
4404 if (opt_idx == -1)
4405 key = find_key_option(arg + 1);
4406 }
4407 else
4408 {
4409 len = 0;
4410 /*
4411 * The two characters after "t_" may not be alphanumeric.
4412 */
4413 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4414 len = 4;
4415 else
4416 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4417 ++len;
4418 nextchar = arg[len];
4419 arg[len] = NUL; /* put NUL after name */
4420 opt_idx = findoption(arg);
4421 arg[len] = nextchar; /* restore nextchar */
4422 if (opt_idx == -1)
4423 key = find_key_option(arg);
4424 }
4425
4426 /* remember character after option name */
4427 afterchar = arg[len];
4428
4429 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004430 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004431 ++len;
4432
4433 adding = FALSE;
4434 prepending = FALSE;
4435 removing = FALSE;
4436 if (arg[len] != NUL && arg[len + 1] == '=')
4437 {
4438 if (arg[len] == '+')
4439 {
4440 adding = TRUE; /* "+=" */
4441 ++len;
4442 }
4443 else if (arg[len] == '^')
4444 {
4445 prepending = TRUE; /* "^=" */
4446 ++len;
4447 }
4448 else if (arg[len] == '-')
4449 {
4450 removing = TRUE; /* "-=" */
4451 ++len;
4452 }
4453 }
4454 nextchar = arg[len];
4455
4456 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4457 {
4458 errmsg = (char_u *)N_("E518: Unknown option");
4459 goto skip;
4460 }
4461
4462 if (opt_idx >= 0)
4463 {
4464 if (options[opt_idx].var == NULL) /* hidden option: skip */
4465 {
4466 /* Only give an error message when requesting the value of
4467 * a hidden option, ignore setting it. */
4468 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4469 && (!(options[opt_idx].flags & P_BOOL)
4470 || nextchar == '?'))
4471 errmsg = (char_u *)N_("E519: Option not supported");
4472 goto skip;
4473 }
4474
4475 flags = options[opt_idx].flags;
4476 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4477 }
4478 else
4479 {
4480 flags = P_STRING;
4481 if (key < 0)
4482 {
4483 key_name[0] = KEY2TERMCAP0(key);
4484 key_name[1] = KEY2TERMCAP1(key);
4485 }
4486 else
4487 {
4488 key_name[0] = KS_KEY;
4489 key_name[1] = (key & 0xff);
4490 }
4491 }
4492
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004493 /* Skip all options that are not window-local (used when showing
4494 * an already loaded buffer in a window). */
4495 if ((opt_flags & OPT_WINONLY)
4496 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4497 goto skip;
4498
Bram Moolenaara3227e22006-03-08 21:32:40 +00004499 /* Skip all options that are window-local (used for :vimgrep). */
4500 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4501 && options[opt_idx].var == VAR_WIN)
4502 goto skip;
4503
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004504 /* Disallow changing some options from modelines. */
4505 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004506 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004507 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004508 {
4509 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4510 goto skip;
4511 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004512#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004513 /* In diff mode some options are overruled. This avoids that
4514 * 'foldmethod' becomes "marker" instead of "diff" and that
4515 * "wrap" gets set. */
4516 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004517 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004518 && (
4519#ifdef FEAT_FOLDING
4520 options[opt_idx].indir == PV_FDM ||
4521#endif
4522 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004523 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004524#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004525 }
4526
4527#ifdef HAVE_SANDBOX
4528 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004529 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004530 {
4531 errmsg = (char_u *)_(e_sandbox);
4532 goto skip;
4533 }
4534#endif
4535
4536 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4537 {
4538 arg += len;
4539 cp_val = p_cp;
4540 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4541 {
4542 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4543 {
4544 cp_val = FALSE;
4545 arg += 3;
4546 }
4547 else /* "opt&vi": set to Vi default */
4548 {
4549 cp_val = TRUE;
4550 arg += 2;
4551 }
4552 }
4553 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004554 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004555 {
4556 errmsg = e_trailing;
4557 goto skip;
4558 }
4559 }
4560
4561 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004562 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4563 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004564 */
4565 if (nextchar == '?'
4566 || (prefix == 1
4567 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4568 && !(flags & P_BOOL)))
4569 {
4570 /*
4571 * print value
4572 */
4573 if (did_show)
4574 msg_putchar('\n'); /* cursor below last one */
4575 else
4576 {
4577 gotocmdline(TRUE); /* cursor at status line */
4578 did_show = TRUE; /* remember that we did a line */
4579 }
4580 if (opt_idx >= 0)
4581 {
4582 showoneopt(&options[opt_idx], opt_flags);
4583#ifdef FEAT_EVAL
4584 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004585 {
4586 /* Mention where the option was last set. */
4587 if (varp == options[opt_idx].var)
4588 last_set_msg(options[opt_idx].scriptID);
4589 else if ((int)options[opt_idx].indir & PV_WIN)
4590 last_set_msg(curwin->w_p_scriptID[
4591 (int)options[opt_idx].indir & PV_MASK]);
4592 else if ((int)options[opt_idx].indir & PV_BUF)
4593 last_set_msg(curbuf->b_p_scriptID[
4594 (int)options[opt_idx].indir & PV_MASK]);
4595 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004596#endif
4597 }
4598 else
4599 {
4600 char_u *p;
4601
4602 p = find_termcode(key_name);
4603 if (p == NULL)
4604 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004605 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004606 goto skip;
4607 }
4608 else
4609 (void)show_one_termcode(key_name, p, TRUE);
4610 }
4611 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004612 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004613 errmsg = e_trailing;
4614 }
4615 else
4616 {
4617 if (flags & P_BOOL) /* boolean */
4618 {
4619 if (nextchar == '=' || nextchar == ':')
4620 {
4621 errmsg = e_invarg;
4622 goto skip;
4623 }
4624
4625 /*
4626 * ":set opt!": invert
4627 * ":set opt&": reset to default value
4628 * ":set opt<": reset to global value
4629 */
4630 if (nextchar == '!')
4631 value = *(int *)(varp) ^ 1;
4632 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004633 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004634 ((flags & P_VI_DEF) || cp_val)
4635 ? VI_DEFAULT : VIM_DEFAULT];
4636 else if (nextchar == '<')
4637 {
4638 /* For 'autoread' -1 means to use global value. */
4639 if ((int *)varp == &curbuf->b_p_ar
4640 && opt_flags == OPT_LOCAL)
4641 value = -1;
4642 else
4643 value = *(int *)get_varp_scope(&(options[opt_idx]),
4644 OPT_GLOBAL);
4645 }
4646 else
4647 {
4648 /*
4649 * ":set invopt": invert
4650 * ":set opt" or ":set noopt": set or reset
4651 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004652 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004653 {
4654 errmsg = e_trailing;
4655 goto skip;
4656 }
4657 if (prefix == 2) /* inv */
4658 value = *(int *)(varp) ^ 1;
4659 else
4660 value = prefix;
4661 }
4662
4663 errmsg = set_bool_option(opt_idx, varp, (int)value,
4664 opt_flags);
4665 }
4666 else /* numeric or string */
4667 {
4668 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4669 || prefix != 1)
4670 {
4671 errmsg = e_invarg;
4672 goto skip;
4673 }
4674
4675 if (flags & P_NUM) /* numeric */
4676 {
4677 /*
4678 * Different ways to set a number option:
4679 * & set to default value
4680 * < set to global value
4681 * <xx> accept special key codes for 'wildchar'
4682 * c accept any non-digit for 'wildchar'
4683 * [-]0-9 set number
4684 * other error
4685 */
4686 ++arg;
4687 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004688 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004689 ((flags & P_VI_DEF) || cp_val)
4690 ? VI_DEFAULT : VIM_DEFAULT];
4691 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004692 {
4693 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4694 * use the global value. */
4695 if ((long *)varp == &curbuf->b_p_ul
4696 && opt_flags == OPT_LOCAL)
4697 value = NO_LOCAL_UNDOLEVEL;
4698 else
4699 value = *(long *)get_varp_scope(
4700 &(options[opt_idx]), OPT_GLOBAL);
4701 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004702 else if (((long *)varp == &p_wc
4703 || (long *)varp == &p_wcm)
4704 && (*arg == '<'
4705 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004706 || (*arg != NUL
4707 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004708 && !VIM_ISDIGIT(*arg))))
4709 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004710 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004711 if (value == 0 && (long *)varp != &p_wcm)
4712 {
4713 errmsg = e_invarg;
4714 goto skip;
4715 }
4716 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004717 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4718 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004719 /* Allow negative (for 'undolevels'), octal and
4720 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004721 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4722 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004723 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004724 {
4725 errmsg = e_invarg;
4726 goto skip;
4727 }
4728 }
4729 else
4730 {
4731 errmsg = (char_u *)N_("E521: Number required after =");
4732 goto skip;
4733 }
4734
4735 if (adding)
4736 value = *(long *)varp + value;
4737 if (prepending)
4738 value = *(long *)varp * value;
4739 if (removing)
4740 value = *(long *)varp - value;
4741 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004742 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004743 }
4744 else if (opt_idx >= 0) /* string */
4745 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004746 char_u *save_arg = NULL;
4747 char_u *s = NULL;
4748 char_u *oldval = NULL; /* previous value if *varp */
4749 char_u *newval;
4750 char_u *origval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004751#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004752 char_u *saved_origval = NULL;
4753 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004754#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004755 unsigned newlen;
4756 int comma;
4757 int bs;
4758 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004759 was allocated */
4760
4761 /* When using ":set opt=val" for a global option
4762 * with a local value the local value will be
4763 * reset, use the global value here. */
4764 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004765 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004766 varp = options[opt_idx].var;
4767
4768 /* The old value is kept until we are sure that the
4769 * new value is valid. */
4770 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004771
4772 /* When setting the local value of a global
4773 * option, the old value may be the global value. */
4774 if (((int)options[opt_idx].indir & PV_BOTH)
4775 && (opt_flags & OPT_LOCAL))
4776 origval = *(char_u **)get_varp(
4777 &options[opt_idx]);
4778 else
4779 origval = oldval;
4780
Bram Moolenaar071d4272004-06-13 20:20:40 +00004781 if (nextchar == '&') /* set to default val */
4782 {
4783 newval = options[opt_idx].def_val[
4784 ((flags & P_VI_DEF) || cp_val)
4785 ? VI_DEFAULT : VIM_DEFAULT];
4786 if ((char_u **)varp == &p_bg)
4787 {
4788 /* guess the value of 'background' */
4789#ifdef FEAT_GUI
4790 if (gui.in_use)
4791 newval = gui_bg_default();
4792 else
4793#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004794 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004795 }
4796
4797 /* expand environment variables and ~ (since the
4798 * default value was already expanded, only
4799 * required when an environment variable was set
4800 * later */
4801 if (newval == NULL)
4802 newval = empty_option;
4803 else
4804 {
4805 s = option_expand(opt_idx, newval);
4806 if (s == NULL)
4807 s = newval;
4808 newval = vim_strsave(s);
4809 }
4810 new_value_alloced = TRUE;
4811 }
4812 else if (nextchar == '<') /* set to global val */
4813 {
4814 newval = vim_strsave(*(char_u **)get_varp_scope(
4815 &(options[opt_idx]), OPT_GLOBAL));
4816 new_value_alloced = TRUE;
4817 }
4818 else
4819 {
4820 ++arg; /* jump to after the '=' or ':' */
4821
4822 /*
4823 * Set 'keywordprg' to ":help" if an empty
4824 * value was passed to :set by the user.
4825 * Misuse errbuf[] for the resulting string.
4826 */
4827 if (varp == (char_u *)&p_kp
4828 && (*arg == NUL || *arg == ' '))
4829 {
4830 STRCPY(errbuf, ":help");
4831 save_arg = arg;
4832 arg = errbuf;
4833 }
4834 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004835 * Convert 'backspace' number to string, for
4836 * adding, prepending and removing string.
4837 */
4838 else if (varp == (char_u *)&p_bs
4839 && VIM_ISDIGIT(**(char_u **)varp))
4840 {
4841 i = getdigits((char_u **)varp);
4842 switch (i)
4843 {
4844 case 0:
4845 *(char_u **)varp = empty_option;
4846 break;
4847 case 1:
4848 *(char_u **)varp = vim_strsave(
4849 (char_u *)"indent,eol");
4850 break;
4851 case 2:
4852 *(char_u **)varp = vim_strsave(
4853 (char_u *)"indent,eol,start");
4854 break;
4855 }
4856 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004857 if (origval == oldval)
4858 origval = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004859 oldval = *(char_u **)varp;
4860 }
4861 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004862 * Convert 'whichwrap' number to string, for
4863 * backwards compatibility with Vim 3.0.
4864 * Misuse errbuf[] for the resulting string.
4865 */
4866 else if (varp == (char_u *)&p_ww
4867 && VIM_ISDIGIT(*arg))
4868 {
4869 *errbuf = NUL;
4870 i = getdigits(&arg);
4871 if (i & 1)
4872 STRCAT(errbuf, "b,");
4873 if (i & 2)
4874 STRCAT(errbuf, "s,");
4875 if (i & 4)
4876 STRCAT(errbuf, "h,l,");
4877 if (i & 8)
4878 STRCAT(errbuf, "<,>,");
4879 if (i & 16)
4880 STRCAT(errbuf, "[,],");
4881 if (*errbuf != NUL) /* remove trailing , */
4882 errbuf[STRLEN(errbuf) - 1] = NUL;
4883 save_arg = arg;
4884 arg = errbuf;
4885 }
4886 /*
4887 * Remove '>' before 'dir' and 'bdir', for
4888 * backwards compatibility with version 3.0
4889 */
4890 else if ( *arg == '>'
4891 && (varp == (char_u *)&p_dir
4892 || varp == (char_u *)&p_bdir))
4893 {
4894 ++arg;
4895 }
4896
Bram Moolenaar071d4272004-06-13 20:20:40 +00004897 /*
4898 * Copy the new string into allocated memory.
4899 * Can't use set_string_option_direct(), because
4900 * we need to remove the backslashes.
4901 */
4902 /* get a bit too much */
4903 newlen = (unsigned)STRLEN(arg) + 1;
4904 if (adding || prepending || removing)
4905 newlen += (unsigned)STRLEN(origval) + 1;
4906 newval = alloc(newlen);
4907 if (newval == NULL) /* out of mem, don't change */
4908 break;
4909 s = newval;
4910
4911 /*
4912 * Copy the string, skip over escaped chars.
4913 * For MS-DOS and WIN32 backslashes before normal
4914 * file name characters are not removed, and keep
4915 * backslash at start, for "\\machine\path", but
4916 * do remove it for "\\\\machine\\path".
4917 * The reverse is found in ExpandOldSetting().
4918 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004919 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004920 {
4921 if (*arg == '\\' && arg[1] != NUL
4922#ifdef BACKSLASH_IN_FILENAME
4923 && !((flags & P_EXPAND)
4924 && vim_isfilec(arg[1])
4925 && (arg[1] != '\\'
4926 || (s == newval
4927 && arg[2] != '\\')))
4928#endif
4929 )
4930 ++arg; /* remove backslash */
4931#ifdef FEAT_MBYTE
4932 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004933 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004934 {
4935 /* copy multibyte char */
4936 mch_memmove(s, arg, (size_t)i);
4937 arg += i;
4938 s += i;
4939 }
4940 else
4941#endif
4942 *s++ = *arg++;
4943 }
4944 *s = NUL;
4945
4946 /*
4947 * Expand environment variables and ~.
4948 * Don't do it when adding without inserting a
4949 * comma.
4950 */
4951 if (!(adding || prepending || removing)
4952 || (flags & P_COMMA))
4953 {
4954 s = option_expand(opt_idx, newval);
4955 if (s != NULL)
4956 {
4957 vim_free(newval);
4958 newlen = (unsigned)STRLEN(s) + 1;
4959 if (adding || prepending || removing)
4960 newlen += (unsigned)STRLEN(origval) + 1;
4961 newval = alloc(newlen);
4962 if (newval == NULL)
4963 break;
4964 STRCPY(newval, s);
4965 }
4966 }
4967
4968 /* locate newval[] in origval[] when removing it
4969 * and when adding to avoid duplicates */
4970 i = 0; /* init for GCC */
4971 if (removing || (flags & P_NODUP))
4972 {
4973 i = (int)STRLEN(newval);
4974 bs = 0;
4975 for (s = origval; *s; ++s)
4976 {
4977 if ((!(flags & P_COMMA)
4978 || s == origval
4979 || (s[-1] == ',' && !(bs & 1)))
4980 && STRNCMP(s, newval, i) == 0
4981 && (!(flags & P_COMMA)
4982 || s[i] == ','
4983 || s[i] == NUL))
4984 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004985 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01004986 * even number of backslashes or a single
4987 * backslash preceded by a comma before it
4988 * is recognized as a separator */
4989 if ((s > origval + 1
4990 && s[-1] == '\\'
4991 && s[-2] != ',')
4992 || (s == origval + 1
4993 && s[-1] == '\\'))
4994
Bram Moolenaar071d4272004-06-13 20:20:40 +00004995 ++bs;
4996 else
4997 bs = 0;
4998 }
4999
5000 /* do not add if already there */
5001 if ((adding || prepending) && *s)
5002 {
5003 prepending = FALSE;
5004 adding = FALSE;
5005 STRCPY(newval, origval);
5006 }
5007 }
5008
5009 /* concatenate the two strings; add a ',' if
5010 * needed */
5011 if (adding || prepending)
5012 {
5013 comma = ((flags & P_COMMA) && *origval != NUL
5014 && *newval != NUL);
5015 if (adding)
5016 {
5017 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005018 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005019 if (comma && i > 1
5020 && (flags & P_ONECOMMA) == P_ONECOMMA
5021 && origval[i - 1] == ','
5022 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005023 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005024 mch_memmove(newval + i + comma, newval,
5025 STRLEN(newval) + 1);
5026 mch_memmove(newval, origval, (size_t)i);
5027 }
5028 else
5029 {
5030 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005031 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005032 }
5033 if (comma)
5034 newval[i] = ',';
5035 }
5036
5037 /* Remove newval[] from origval[]. (Note: "i" has
5038 * been set above and is used here). */
5039 if (removing)
5040 {
5041 STRCPY(newval, origval);
5042 if (*s)
5043 {
5044 /* may need to remove a comma */
5045 if (flags & P_COMMA)
5046 {
5047 if (s == origval)
5048 {
5049 /* include comma after string */
5050 if (s[i] == ',')
5051 ++i;
5052 }
5053 else
5054 {
5055 /* include comma before string */
5056 --s;
5057 ++i;
5058 }
5059 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005060 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005061 }
5062 }
5063
5064 if (flags & P_FLAGLIST)
5065 {
5066 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005067 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005068 {
5069 /* if options have P_FLAGLIST and
5070 * P_ONECOMMA such as 'whichwrap' */
5071 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005072 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005073 if (*s != ',' && *(s + 1) == ','
5074 && vim_strchr(s + 2, *s) != NULL)
5075 {
5076 /* Remove the duplicated value and
5077 * the next comma. */
5078 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005079 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005080 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005081 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005082 else
5083 {
5084 if ((!(flags & P_COMMA) || *s != ',')
5085 && vim_strchr(s + 1, *s) != NULL)
5086 {
5087 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005088 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005089 }
5090 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005091 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005092 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005093 }
5094
5095 if (save_arg != NULL) /* number for 'whichwrap' */
5096 arg = save_arg;
5097 new_value_alloced = TRUE;
5098 }
5099
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005100 /*
5101 * Set the new value.
5102 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005103 *(char_u **)(varp) = newval;
5104
Bram Moolenaar53744302015-07-17 17:38:22 +02005105#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005106 if (!starting
5107# ifdef FEAT_CRYPT
5108 && options[opt_idx].indir != PV_KEY
5109# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005110 && origval != NULL && newval != NULL)
5111 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005112 /* origval may be freed by
5113 * did_set_string_option(), make a copy. */
5114 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005115 /* newval (and varp) may become invalid if the
5116 * buffer is closed by autocommands. */
5117 saved_newval = vim_strsave(newval);
5118 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005119#endif
5120
Bram Moolenaar071d4272004-06-13 20:20:40 +00005121 /* Handle side effects, and set the global value for
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005122 * ":set" on local options. Note: when setting 'syntax'
5123 * or 'filetype' autocommands may be triggered that can
5124 * cause havoc. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005125 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5126 new_value_alloced, oldval, errbuf, opt_flags);
5127
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005128#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5129 if (errmsg == NULL)
5130 trigger_optionsset_string(opt_idx, opt_flags,
5131 saved_origval, saved_newval);
5132 vim_free(saved_origval);
5133 vim_free(saved_newval);
5134#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005135 /* If error detected, print the error message. */
5136 if (errmsg != NULL)
5137 goto skip;
5138 }
5139 else /* key code option */
5140 {
5141 char_u *p;
5142
5143 if (nextchar == '&')
5144 {
5145 if (add_termcap_entry(key_name, TRUE) == FAIL)
5146 errmsg = (char_u *)N_("E522: Not found in termcap");
5147 }
5148 else
5149 {
5150 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005151 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005152 if (*p == '\\' && p[1] != NUL)
5153 ++p;
5154 nextchar = *p;
5155 *p = NUL;
5156 add_termcode(key_name, arg, FALSE);
5157 *p = nextchar;
5158 }
5159 if (full_screen)
5160 ttest(FALSE);
5161 redraw_all_later(CLEAR);
5162 }
5163 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005164
Bram Moolenaar071d4272004-06-13 20:20:40 +00005165 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005166 did_set_option(opt_idx, opt_flags,
5167 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005168 }
5169
5170skip:
5171 /*
5172 * Advance to next argument.
5173 * - skip until a blank found, taking care of backslashes
5174 * - skip blanks
5175 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5176 */
5177 for (i = 0; i < 2 ; ++i)
5178 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005179 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005180 if (*arg++ == '\\' && *arg != NUL)
5181 ++arg;
5182 arg = skipwhite(arg);
5183 if (*arg != '=')
5184 break;
5185 }
5186 }
5187
5188 if (errmsg != NULL)
5189 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005190 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005191 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005192 if (i + (arg - startarg) < IOSIZE)
5193 {
5194 /* append the argument with the error */
5195 STRCAT(IObuff, ": ");
5196 mch_memmove(IObuff + i, startarg, (arg - startarg));
5197 IObuff[i + (arg - startarg)] = NUL;
5198 }
5199 /* make sure all characters are printable */
5200 trans_characters(IObuff, IOSIZE);
5201
5202 ++no_wait_return; /* wait_return done later */
5203 emsg(IObuff); /* show error highlighted */
5204 --no_wait_return;
5205
5206 return FAIL;
5207 }
5208
5209 arg = skipwhite(arg);
5210 }
5211
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005212theend:
5213 if (silent_mode && did_show)
5214 {
5215 /* After displaying option values in silent mode. */
5216 silent_mode = FALSE;
5217 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5218 msg_putchar('\n');
5219 cursor_on(); /* msg_start() switches it off */
5220 out_flush();
5221 silent_mode = TRUE;
5222 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5223 }
5224
Bram Moolenaar071d4272004-06-13 20:20:40 +00005225 return OK;
5226}
5227
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005228/*
5229 * Call this when an option has been given a new value through a user command.
5230 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5231 */
5232 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005233did_set_option(
5234 int opt_idx,
5235 int opt_flags, /* possibly with OPT_MODELINE */
5236 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005237{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005238 long_u *p;
5239
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005240 options[opt_idx].flags |= P_WAS_SET;
5241
5242 /* When an option is set in the sandbox, from a modeline or in secure mode
5243 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005244 * flag. */
5245 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005246 if (secure
5247#ifdef HAVE_SANDBOX
5248 || sandbox != 0
5249#endif
5250 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005251 *p = *p | P_INSECURE;
5252 else if (new_value)
5253 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005254}
5255
Bram Moolenaar071d4272004-06-13 20:20:40 +00005256 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005257illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005258{
5259 if (errbuf == NULL)
5260 return (char_u *)"";
5261 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005262 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005263 return errbuf;
5264}
5265
5266/*
5267 * Convert a key name or string into a key value.
5268 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005269 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005270 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005271 int
5272string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005273{
5274 if (*arg == '<')
5275 return find_key_option(arg + 1);
5276 if (*arg == '^')
5277 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005278 if (multi_byte)
5279 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005280 return *arg;
5281}
5282
5283#ifdef FEAT_CMDWIN
5284/*
5285 * Check value of 'cedit' and set cedit_key.
5286 * Returns NULL if value is OK, error message otherwise.
5287 */
5288 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005289check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005290{
5291 int n;
5292
5293 if (*p_cedit == NUL)
5294 cedit_key = -1;
5295 else
5296 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005297 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005298 if (vim_isprintc(n))
5299 return e_invarg;
5300 cedit_key = n;
5301 }
5302 return NULL;
5303}
5304#endif
5305
5306#ifdef FEAT_TITLE
5307/*
5308 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5309 * maketitle() to create and display it.
5310 * When switching the title or icon off, call mch_restore_title() to get
5311 * the old value back.
5312 */
5313 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005314did_set_title(
5315 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005316{
5317 if (starting != NO_SCREEN
5318#ifdef FEAT_GUI
5319 && !gui.starting
5320#endif
5321 )
5322 {
5323 maketitle();
5324 if (icon)
5325 {
5326 if (!p_icon)
5327 mch_restore_title(2);
5328 }
5329 else
5330 {
5331 if (!p_title)
5332 mch_restore_title(1);
5333 }
5334 }
5335}
5336#endif
5337
5338/*
5339 * set_options_bin - called when 'bin' changes value.
5340 */
5341 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005342set_options_bin(
5343 int oldval,
5344 int newval,
5345 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005346{
5347 /*
5348 * The option values that are changed when 'bin' changes are
5349 * copied when 'bin is set and restored when 'bin' is reset.
5350 */
5351 if (newval)
5352 {
5353 if (!oldval) /* switched on */
5354 {
5355 if (!(opt_flags & OPT_GLOBAL))
5356 {
5357 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5358 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5359 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5360 curbuf->b_p_et_nobin = curbuf->b_p_et;
5361 }
5362 if (!(opt_flags & OPT_LOCAL))
5363 {
5364 p_tw_nobin = p_tw;
5365 p_wm_nobin = p_wm;
5366 p_ml_nobin = p_ml;
5367 p_et_nobin = p_et;
5368 }
5369 }
5370
5371 if (!(opt_flags & OPT_GLOBAL))
5372 {
5373 curbuf->b_p_tw = 0; /* no automatic line wrap */
5374 curbuf->b_p_wm = 0; /* no automatic line wrap */
5375 curbuf->b_p_ml = 0; /* no modelines */
5376 curbuf->b_p_et = 0; /* no expandtab */
5377 }
5378 if (!(opt_flags & OPT_LOCAL))
5379 {
5380 p_tw = 0;
5381 p_wm = 0;
5382 p_ml = FALSE;
5383 p_et = FALSE;
5384 p_bin = TRUE; /* needed when called for the "-b" argument */
5385 }
5386 }
5387 else if (oldval) /* switched off */
5388 {
5389 if (!(opt_flags & OPT_GLOBAL))
5390 {
5391 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5392 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5393 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5394 curbuf->b_p_et = curbuf->b_p_et_nobin;
5395 }
5396 if (!(opt_flags & OPT_LOCAL))
5397 {
5398 p_tw = p_tw_nobin;
5399 p_wm = p_wm_nobin;
5400 p_ml = p_ml_nobin;
5401 p_et = p_et_nobin;
5402 }
5403 }
5404}
5405
5406#ifdef FEAT_VIMINFO
5407/*
5408 * Find the parameter represented by the given character (eg ', :, ", or /),
5409 * and return its associated value in the 'viminfo' string.
5410 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005411 * If the parameter is not specified in the string or there is no following
5412 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005413 */
5414 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005415get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005416{
5417 char_u *p;
5418
5419 p = find_viminfo_parameter(type);
5420 if (p != NULL && VIM_ISDIGIT(*p))
5421 return atoi((char *)p);
5422 return -1;
5423}
5424
5425/*
5426 * Find the parameter represented by the given character (eg ''', ':', '"', or
5427 * '/') in the 'viminfo' option and return a pointer to the string after it.
5428 * Return NULL if the parameter is not specified in the string.
5429 */
5430 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005431find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005432{
5433 char_u *p;
5434
5435 for (p = p_viminfo; *p; ++p)
5436 {
5437 if (*p == type)
5438 return p + 1;
5439 if (*p == 'n') /* 'n' is always the last one */
5440 break;
5441 p = vim_strchr(p, ','); /* skip until next ',' */
5442 if (p == NULL) /* hit the end without finding parameter */
5443 break;
5444 }
5445 return NULL;
5446}
5447#endif
5448
5449/*
5450 * Expand environment variables for some string options.
5451 * These string options cannot be indirect!
5452 * If "val" is NULL expand the current value of the option.
5453 * Return pointer to NameBuff, or NULL when not expanded.
5454 */
5455 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005456option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005457{
5458 /* if option doesn't need expansion nothing to do */
5459 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5460 return NULL;
5461
5462 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5463 * expand_env() would truncate the string. */
5464 if (val != NULL && STRLEN(val) > MAXPATHL)
5465 return NULL;
5466
5467 if (val == NULL)
5468 val = *(char_u **)options[opt_idx].var;
5469
5470 /*
5471 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5472 * Escape spaces when expanding 'tags', they are used to separate file
5473 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005474 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005475 */
5476 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005477 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005478#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005479 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5480#endif
5481 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005482 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5483 return NULL;
5484
5485 return NameBuff;
5486}
5487
5488/*
5489 * After setting various option values: recompute variables that depend on
5490 * option values.
5491 */
5492 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005493didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005494{
5495 /* initialize the table for 'iskeyword' et.al. */
5496 (void)init_chartab();
5497
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005498#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005499 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005500#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005501 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005502 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005503#ifdef FEAT_SESSION
5504 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5505 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5506#endif
5507#ifdef FEAT_FOLDING
5508 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5509#endif
5510 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005511 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005512#ifdef FEAT_VIRTUALEDIT
5513 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5514#endif
5515#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5516 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5517#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005518#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005519 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005520 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005521 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005522 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005523#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005524#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5525 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5526#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005527#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005528 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5529#endif
5530#ifdef FEAT_CMDWIN
5531 /* set cedit_key */
5532 (void)check_cedit();
5533#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005534#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005535 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005536#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005537#ifdef FEAT_LINEBREAK
5538 /* initialize the table for 'breakat'. */
5539 fill_breakat_flags();
5540#endif
5541
5542}
5543
5544/*
5545 * More side effects of setting options.
5546 */
5547 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005548didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005549{
5550 /* Initialize the highlight_attr[] table. */
5551 (void)highlight_changed();
5552
5553 /* Parse default for 'wildmode' */
5554 check_opt_wim();
5555
5556 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005557 /* Parse default for 'fillchars'. */
5558 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005559
5560#ifdef FEAT_CLIPBOARD
5561 /* Parse default for 'clipboard' */
5562 (void)check_clipboard_option();
5563#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005564}
5565
5566/*
5567 * Check for string options that are NULL (normally only termcap options).
5568 */
5569 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005570check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005571{
5572 int opt_idx;
5573
5574 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5575 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5576 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5577}
5578
5579/*
5580 * Check string options in a buffer for NULL value.
5581 */
5582 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005583check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005584{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005585 check_string_option(&buf->b_p_bh);
5586 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005587#ifdef FEAT_MBYTE
5588 check_string_option(&buf->b_p_fenc);
5589#endif
5590 check_string_option(&buf->b_p_ff);
5591#ifdef FEAT_FIND_ID
5592 check_string_option(&buf->b_p_def);
5593 check_string_option(&buf->b_p_inc);
5594# ifdef FEAT_EVAL
5595 check_string_option(&buf->b_p_inex);
5596# endif
5597#endif
5598#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5599 check_string_option(&buf->b_p_inde);
5600 check_string_option(&buf->b_p_indk);
5601#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005602#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5603 check_string_option(&buf->b_p_bexpr);
5604#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005605#if defined(FEAT_CRYPT)
5606 check_string_option(&buf->b_p_cm);
5607#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005608 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005609#if defined(FEAT_EVAL)
5610 check_string_option(&buf->b_p_fex);
5611#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005612#ifdef FEAT_CRYPT
5613 check_string_option(&buf->b_p_key);
5614#endif
5615 check_string_option(&buf->b_p_kp);
5616 check_string_option(&buf->b_p_mps);
5617 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005618 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005619 check_string_option(&buf->b_p_isk);
5620#ifdef FEAT_COMMENTS
5621 check_string_option(&buf->b_p_com);
5622#endif
5623#ifdef FEAT_FOLDING
5624 check_string_option(&buf->b_p_cms);
5625#endif
5626 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005627#ifdef FEAT_TEXTOBJ
5628 check_string_option(&buf->b_p_qe);
5629#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005630#ifdef FEAT_SYN_HL
5631 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005632 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005633#endif
5634#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005635 check_string_option(&buf->b_s.b_p_spc);
5636 check_string_option(&buf->b_s.b_p_spf);
5637 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005638#endif
5639#ifdef FEAT_SEARCHPATH
5640 check_string_option(&buf->b_p_sua);
5641#endif
5642#ifdef FEAT_CINDENT
5643 check_string_option(&buf->b_p_cink);
5644 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005645 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005646#endif
5647#ifdef FEAT_AUTOCMD
5648 check_string_option(&buf->b_p_ft);
5649#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005650#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5651 check_string_option(&buf->b_p_cinw);
5652#endif
5653#ifdef FEAT_INS_EXPAND
5654 check_string_option(&buf->b_p_cpt);
5655#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005656#ifdef FEAT_COMPL_FUNC
5657 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005658 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005659#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005660#ifdef FEAT_KEYMAP
5661 check_string_option(&buf->b_p_keymap);
5662#endif
5663#ifdef FEAT_QUICKFIX
5664 check_string_option(&buf->b_p_gp);
5665 check_string_option(&buf->b_p_mp);
5666 check_string_option(&buf->b_p_efm);
5667#endif
5668 check_string_option(&buf->b_p_ep);
5669 check_string_option(&buf->b_p_path);
5670 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005671 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005672#ifdef FEAT_INS_EXPAND
5673 check_string_option(&buf->b_p_dict);
5674 check_string_option(&buf->b_p_tsr);
5675#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005676#ifdef FEAT_LISP
5677 check_string_option(&buf->b_p_lw);
5678#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005679 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005680#ifdef FEAT_MBYTE
5681 check_string_option(&buf->b_p_menc);
5682#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005683}
5684
5685/*
5686 * Free the string allocated for an option.
5687 * Checks for the string being empty_option. This may happen if we're out of
5688 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5689 * check_options().
5690 * Does NOT check for P_ALLOCED flag!
5691 */
5692 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005693free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005694{
5695 if (p != empty_option)
5696 vim_free(p);
5697}
5698
5699 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005700clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005701{
5702 if (*pp != empty_option)
5703 vim_free(*pp);
5704 *pp = empty_option;
5705}
5706
5707 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005708check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005709{
5710 if (*pp == NULL)
5711 *pp = empty_option;
5712}
5713
5714/*
5715 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5716 */
5717 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005718set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005719{
5720 int opt_idx;
5721
5722 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5723 if (options[opt_idx].var == (char_u *)p)
5724 {
5725 options[opt_idx].flags |= P_ALLOCED;
5726 return;
5727 }
5728 return; /* cannot happen: didn't find it! */
5729}
5730
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005731#if defined(FEAT_EVAL) || defined(PROTO)
5732/*
5733 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5734 * Return FALSE when it wasn't.
5735 * Return -1 for an unknown option.
5736 */
5737 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005738was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005739{
5740 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005741 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005742
5743 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005744 {
5745 flagp = insecure_flag(idx, opt_flags);
5746 return (*flagp & P_INSECURE) != 0;
5747 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005748 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005749 return -1;
5750}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005751
5752/*
5753 * Get a pointer to the flags used for the P_INSECURE flag of option
5754 * "opt_idx". For some local options a local flags field is used.
5755 */
5756 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005757insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005758{
5759 if (opt_flags & OPT_LOCAL)
5760 switch ((int)options[opt_idx].indir)
5761 {
5762#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005763 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005764#endif
5765#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005766# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005767 case PV_FDE: return &curwin->w_p_fde_flags;
5768 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005769# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005770# ifdef FEAT_BEVAL
5771 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5772# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005773# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005774 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005775# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005776 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005777# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005778 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005779# endif
5780#endif
5781 }
5782
5783 /* Nothing special, return global flags field. */
5784 return &options[opt_idx].flags;
5785}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005786#endif
5787
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005788#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005789static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005790
5791/*
5792 * Redraw the window title and/or tab page text later.
5793 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005794static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005795{
5796 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005797 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005798}
5799#endif
5800
Bram Moolenaar071d4272004-06-13 20:20:40 +00005801/*
5802 * Set a string option to a new value (without checking the effect).
5803 * The string is copied into allocated memory.
5804 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005805 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005806 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005807 */
5808 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005809set_string_option_direct(
5810 char_u *name,
5811 int opt_idx,
5812 char_u *val,
5813 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5814 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005815{
5816 char_u *s;
5817 char_u **varp;
5818 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005819 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005820
Bram Moolenaar89d40322006-08-29 15:30:07 +00005821 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005822 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005823 idx = findoption(name);
5824 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005825 {
5826 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005827 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005828 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005829 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005830 }
5831
Bram Moolenaar89d40322006-08-29 15:30:07 +00005832 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005833 return;
5834
5835 s = vim_strsave(val);
5836 if (s != NULL)
5837 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005838 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005839 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005840 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005841 free_string_option(*varp);
5842 *varp = s;
5843
5844 /* For buffer/window local option may also set the global value. */
5845 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005846 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005847
Bram Moolenaar89d40322006-08-29 15:30:07 +00005848 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005849
5850 /* When setting both values of a global option with a local value,
5851 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005852 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005853 {
5854 free_string_option(*varp);
5855 *varp = empty_option;
5856 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005857# ifdef FEAT_EVAL
5858 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005859 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005860 set_sid == 0 ? current_SID : set_sid);
5861# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005862 }
5863}
5864
5865/*
5866 * Set global value for string option when it's a local option.
5867 */
5868 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005869set_string_option_global(
5870 int opt_idx, /* option index */
5871 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005872{
5873 char_u **p, *s;
5874
5875 /* the global value is always allocated */
5876 if (options[opt_idx].var == VAR_WIN)
5877 p = (char_u **)GLOBAL_WO(varp);
5878 else
5879 p = (char_u **)options[opt_idx].var;
5880 if (options[opt_idx].indir != PV_NONE
5881 && p != varp
5882 && (s = vim_strsave(*varp)) != NULL)
5883 {
5884 free_string_option(*p);
5885 *p = s;
5886 }
5887}
5888
5889/*
5890 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005891 *
5892 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005893 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005894 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005895set_string_option(
5896 int opt_idx,
5897 char_u *value,
5898 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005899{
5900 char_u *s;
5901 char_u **varp;
5902 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005903#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5904 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005905 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02005906#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005907 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005908
5909 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005910 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005911
5912 s = vim_strsave(value);
5913 if (s != NULL)
5914 {
5915 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5916 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005917 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005918 ? OPT_GLOBAL : OPT_LOCAL)
5919 : opt_flags);
5920 oldval = *varp;
5921 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005922
5923#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005924 if (!starting
5925# ifdef FEAT_CRYPT
5926 && options[opt_idx].indir != PV_KEY
5927# endif
5928 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005929 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005930 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005931 saved_newval = vim_strsave(s);
5932 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005933#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005934 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5935 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005936 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005937
Bram Moolenaar53744302015-07-17 17:38:22 +02005938#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005939 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005940 if (r == NULL)
5941 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005942 saved_oldval, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005943 vim_free(saved_oldval);
5944 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02005945#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005946 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005947 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005948}
5949
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005950#if defined(FEAT_KEYMAP) || defined(FEAT_AUTOCMD) || defined(FEAT_SYN_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005951/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01005952 * Return TRUE if "val" is a valid 'filetype' name.
5953 * Also used for 'syntax' and 'keymap'.
5954 */
5955 static int
5956valid_filetype(char_u *val)
5957{
5958 char_u *s;
5959
5960 for (s = val; *s != NUL; ++s)
5961 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
5962 return FALSE;
5963 return TRUE;
5964}
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005965#endif
Bram Moolenaard0b51382016-11-04 15:23:45 +01005966
5967/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00005968 * Handle string options that need some action to perform when changed.
5969 * Returns NULL for success, or an error message for an error.
5970 */
5971 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005972did_set_string_option(
5973 int opt_idx, /* index in options[] table */
5974 char_u **varp, /* pointer to the option variable */
5975 int new_value_alloced, /* new value was allocated */
5976 char_u *oldval, /* previous value of the option */
5977 char_u *errbuf, /* buffer for errors, or NULL */
5978 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005979{
5980 char_u *errmsg = NULL;
5981 char_u *s, *p;
5982 int did_chartab = FALSE;
5983 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005984 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005985#ifdef FEAT_GUI
5986 /* set when changing an option that only requires a redraw in the GUI */
5987 int redraw_gui_only = FALSE;
5988#endif
Bram Moolenaar90492982017-06-22 14:16:31 +02005989#ifdef FEAT_AUTOCMD
5990 int ft_changed = FALSE;
5991#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005992
5993 /* Get the global option to compare with, otherwise we would have to check
5994 * two values for all local options. */
5995 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5996
5997 /* Disallow changing some options from secure mode */
5998 if ((secure
5999#ifdef HAVE_SANDBOX
6000 || sandbox != 0
6001#endif
6002 ) && (options[opt_idx].flags & P_SECURE))
6003 {
6004 errmsg = e_secure;
6005 }
6006
Bram Moolenaar7554da42016-11-25 22:04:13 +01006007 /* Check for a "normal" directory or file name in some options. Disallow a
6008 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006009 * are often illegal in a file name. Be more permissive if "secure" is off.
6010 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01006011 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006012 && vim_strpbrk(*varp, (char_u *)(secure
6013 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006014 || ((options[opt_idx].flags & P_NDNAME)
6015 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006016 {
6017 errmsg = e_invarg;
6018 }
6019
Bram Moolenaar071d4272004-06-13 20:20:40 +00006020 /* 'term' */
6021 else if (varp == &T_NAME)
6022 {
6023 if (T_NAME[0] == NUL)
6024 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
6025#ifdef FEAT_GUI
6026 if (gui.in_use)
6027 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
6028 else if (term_is_gui(T_NAME))
6029 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
6030#endif
6031 else if (set_termname(T_NAME) == FAIL)
6032 errmsg = (char_u *)N_("E522: Not found in termcap");
6033 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006034 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006035 /* Screen colors may have changed. */
6036 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006037
6038 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6039 * P_ALLOCED flag on 'term'. */
6040 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006041 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006042 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006043 }
6044
6045 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006046 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006047 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006048 char_u *bkc = p_bkc;
6049 unsigned int *flags = &bkc_flags;
6050
6051 if (opt_flags & OPT_LOCAL)
6052 {
6053 bkc = curbuf->b_p_bkc;
6054 flags = &curbuf->b_bkc_flags;
6055 }
6056
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006057 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6058 /* make the local value empty: use the global value */
6059 *flags = 0;
6060 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006061 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006062 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6063 errmsg = e_invarg;
6064 if ((((int)*flags & BKC_AUTO) != 0)
6065 + (((int)*flags & BKC_YES) != 0)
6066 + (((int)*flags & BKC_NO) != 0) != 1)
6067 {
6068 /* Must have exactly one of "auto", "yes" and "no". */
6069 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6070 errmsg = e_invarg;
6071 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006072 }
6073 }
6074
6075 /* 'backupext' and 'patchmode' */
6076 else if (varp == &p_bex || varp == &p_pm)
6077 {
6078 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6079 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6080 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
6081 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006082#ifdef FEAT_LINEBREAK
6083 /* 'breakindentopt' */
6084 else if (varp == &curwin->w_p_briopt)
6085 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006086 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006087 errmsg = e_invarg;
6088 }
6089#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006090
6091 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006092 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006093 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006094 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006095 */
6096 else if ( varp == &p_isi
6097 || varp == &(curbuf->b_p_isk)
6098 || varp == &p_isp
6099 || varp == &p_isf)
6100 {
6101 if (init_chartab() == FAIL)
6102 {
6103 did_chartab = TRUE; /* need to restore it below */
6104 errmsg = e_invarg; /* error in value */
6105 }
6106 }
6107
6108 /* 'helpfile' */
6109 else if (varp == &p_hf)
6110 {
6111 /* May compute new values for $VIM and $VIMRUNTIME */
6112 if (didset_vim)
6113 {
6114 vim_setenv((char_u *)"VIM", (char_u *)"");
6115 didset_vim = FALSE;
6116 }
6117 if (didset_vimruntime)
6118 {
6119 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6120 didset_vimruntime = FALSE;
6121 }
6122 }
6123
Bram Moolenaar1a384422010-07-14 19:53:30 +02006124#ifdef FEAT_SYN_HL
6125 /* 'colorcolumn' */
6126 else if (varp == &curwin->w_p_cc)
6127 errmsg = check_colorcolumn(curwin);
6128#endif
6129
Bram Moolenaar071d4272004-06-13 20:20:40 +00006130#ifdef FEAT_MULTI_LANG
6131 /* 'helplang' */
6132 else if (varp == &p_hlg)
6133 {
6134 /* Check for "", "ab", "ab,cd", etc. */
6135 for (s = p_hlg; *s != NUL; s += 3)
6136 {
6137 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6138 {
6139 errmsg = e_invarg;
6140 break;
6141 }
6142 if (s[2] == NUL)
6143 break;
6144 }
6145 }
6146#endif
6147
6148 /* 'highlight' */
6149 else if (varp == &p_hl)
6150 {
6151 if (highlight_changed() == FAIL)
6152 errmsg = e_invarg; /* invalid flags */
6153 }
6154
6155 /* 'nrformats' */
6156 else if (gvarp == &p_nf)
6157 {
6158 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6159 errmsg = e_invarg;
6160 }
6161
6162#ifdef FEAT_SESSION
6163 /* 'sessionoptions' */
6164 else if (varp == &p_ssop)
6165 {
6166 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6167 errmsg = e_invarg;
6168 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6169 {
6170 /* Don't allow both "sesdir" and "curdir". */
6171 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6172 errmsg = e_invarg;
6173 }
6174 }
6175 /* 'viewoptions' */
6176 else if (varp == &p_vop)
6177 {
6178 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6179 errmsg = e_invarg;
6180 }
6181#endif
6182
6183 /* 'scrollopt' */
6184#ifdef FEAT_SCROLLBIND
6185 else if (varp == &p_sbo)
6186 {
6187 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6188 errmsg = e_invarg;
6189 }
6190#endif
6191
6192 /* 'ambiwidth' */
6193#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006194 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006195 {
6196 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6197 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006198 else if (set_chars_option(&p_lcs) != NULL)
6199 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006200 else if (set_chars_option(&p_fcs) != NULL)
6201 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006202 }
6203#endif
6204
6205 /* 'background' */
6206 else if (varp == &p_bg)
6207 {
6208 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6209 {
6210#ifdef FEAT_EVAL
6211 int dark = (*p_bg == 'd');
6212#endif
6213
6214 init_highlight(FALSE, FALSE);
6215
6216#ifdef FEAT_EVAL
6217 if (dark != (*p_bg == 'd')
6218 && get_var_value((char_u *)"g:colors_name") != NULL)
6219 {
6220 /* The color scheme must have set 'background' back to another
6221 * value, that's not what we want here. Disable the color
6222 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006223 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006224 free_string_option(p_bg);
6225 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6226 check_string_option(&p_bg);
6227 init_highlight(FALSE, FALSE);
6228 }
6229#endif
6230 }
6231 else
6232 errmsg = e_invarg;
6233 }
6234
6235 /* 'wildmode' */
6236 else if (varp == &p_wim)
6237 {
6238 if (check_opt_wim() == FAIL)
6239 errmsg = e_invarg;
6240 }
6241
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006242#ifdef FEAT_CMDL_COMPL
6243 /* 'wildoptions' */
6244 else if (varp == &p_wop)
6245 {
6246 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6247 errmsg = e_invarg;
6248 }
6249#endif
6250
Bram Moolenaar071d4272004-06-13 20:20:40 +00006251#ifdef FEAT_WAK
6252 /* 'winaltkeys' */
6253 else if (varp == &p_wak)
6254 {
6255 if (*p_wak == NUL
6256 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6257 errmsg = e_invarg;
6258# ifdef FEAT_MENU
6259# ifdef FEAT_GUI_MOTIF
6260 else if (gui.in_use)
6261 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6262# else
6263# ifdef FEAT_GUI_GTK
6264 else if (gui.in_use)
6265 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6266# endif
6267# endif
6268# endif
6269 }
6270#endif
6271
6272#ifdef FEAT_AUTOCMD
6273 /* 'eventignore' */
6274 else if (varp == &p_ei)
6275 {
6276 if (check_ei() == FAIL)
6277 errmsg = e_invarg;
6278 }
6279#endif
6280
6281#ifdef FEAT_MBYTE
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006282 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6283 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6284 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006285 {
6286 if (gvarp == &p_fenc)
6287 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006288 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006289 errmsg = e_modifiable;
6290 else if (vim_strchr(*varp, ',') != NULL)
6291 /* No comma allowed in 'fileencoding'; catches confusing it
6292 * with 'fileencodings'. */
6293 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006294 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006295 {
6296# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006297 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006298 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006299# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006300 /* Add 'fileencoding' to the swap file. */
6301 ml_setflags(curbuf);
6302 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006303 }
6304 if (errmsg == NULL)
6305 {
6306 /* canonize the value, so that STRCMP() can be used on it */
6307 p = enc_canonize(*varp);
6308 if (p != NULL)
6309 {
6310 vim_free(*varp);
6311 *varp = p;
6312 }
6313 if (varp == &p_enc)
6314 {
6315 errmsg = mb_init();
6316# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006317 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006318# endif
6319 }
6320 }
6321
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006322# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006323 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6324 {
6325 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6326 if (STRCMP(p_tenc, "utf-8") != 0)
6327 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6328 }
6329# endif
6330
6331 if (errmsg == NULL)
6332 {
6333# ifdef FEAT_KEYMAP
6334 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6335 * (with another encoding). */
6336 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6337 (void)keymap_init();
6338# endif
6339
6340 /* When 'termencoding' is not empty and 'encoding' changes or when
6341 * 'termencoding' changes, need to setup for keyboard input and
6342 * display output conversion. */
6343 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6344 {
6345 convert_setup(&input_conv, p_tenc, p_enc);
6346 convert_setup(&output_conv, p_enc, p_tenc);
6347 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006348
6349# if defined(WIN3264) && defined(FEAT_MBYTE)
6350 /* $HOME may have characters in active code page. */
6351 if (varp == &p_enc)
6352 init_homedir();
6353# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006354 }
6355 }
6356#endif
6357
6358#if defined(FEAT_POSTSCRIPT)
6359 else if (varp == &p_penc)
6360 {
6361 /* Canonize printencoding if VIM standard one */
6362 p = enc_canonize(p_penc);
6363 if (p != NULL)
6364 {
6365 vim_free(p_penc);
6366 p_penc = p;
6367 }
6368 else
6369 {
6370 /* Ensure lower case and '-' for '_' */
6371 for (s = p_penc; *s != NUL; s++)
6372 {
6373 if (*s == '_')
6374 *s = '-';
6375 else
6376 *s = TOLOWER_ASC(*s);
6377 }
6378 }
6379 }
6380#endif
6381
Bram Moolenaar9372a112005-12-06 19:59:18 +00006382#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006383 else if (varp == &p_imak)
6384 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006385 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006386 errmsg = e_invarg;
6387 }
6388#endif
6389
6390#ifdef FEAT_KEYMAP
6391 else if (varp == &curbuf->b_p_keymap)
6392 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006393 if (!valid_filetype(*varp))
6394 errmsg = e_invarg;
6395 else
6396 /* load or unload key mapping tables */
6397 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006398
Bram Moolenaarfab06232009-03-04 03:13:35 +00006399 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006400 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006401 if (*curbuf->b_p_keymap != NUL)
6402 {
6403 /* Installed a new keymap, switch on using it. */
6404 curbuf->b_p_iminsert = B_IMODE_LMAP;
6405 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6406 curbuf->b_p_imsearch = B_IMODE_LMAP;
6407 }
6408 else
6409 {
6410 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6411 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6412 curbuf->b_p_iminsert = B_IMODE_NONE;
6413 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6414 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6415 }
6416 if ((opt_flags & OPT_LOCAL) == 0)
6417 {
6418 set_iminsert_global();
6419 set_imsearch_global();
6420 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006421 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006422 }
6423 }
6424#endif
6425
6426 /* 'fileformat' */
6427 else if (gvarp == &p_ff)
6428 {
6429 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6430 errmsg = e_modifiable;
6431 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6432 errmsg = e_invarg;
6433 else
6434 {
6435 /* may also change 'textmode' */
6436 if (get_fileformat(curbuf) == EOL_DOS)
6437 curbuf->b_p_tx = TRUE;
6438 else
6439 curbuf->b_p_tx = FALSE;
6440#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006441 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006442#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006443 /* update flag in swap file */
6444 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006445 /* Redraw needed when switching to/from "mac": a CR in the text
6446 * will be displayed differently. */
6447 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6448 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006449 }
6450 }
6451
6452 /* 'fileformats' */
6453 else if (varp == &p_ffs)
6454 {
6455 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6456 errmsg = e_invarg;
6457 else
6458 {
6459 /* also change 'textauto' */
6460 if (*p_ffs == NUL)
6461 p_ta = FALSE;
6462 else
6463 p_ta = TRUE;
6464 }
6465 }
6466
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006467#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006468 /* 'cryptkey' */
6469 else if (gvarp == &p_key)
6470 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006471# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006472 /* Make sure the ":set" command doesn't show the new value in the
6473 * history. */
6474 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006475# endif
6476 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6477 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006478 ml_set_crypt_key(curbuf, oldval,
6479 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006480 }
6481
6482 else if (gvarp == &p_cm)
6483 {
6484 if (opt_flags & OPT_LOCAL)
6485 p = curbuf->b_p_cm;
6486 else
6487 p = p_cm;
6488 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6489 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006490 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006491 errmsg = e_invarg;
6492 else
6493 {
6494 /* When setting the global value to empty, make it "zip". */
6495 if (*p_cm == NUL)
6496 {
6497 if (new_value_alloced)
6498 free_string_option(p_cm);
6499 p_cm = vim_strsave((char_u *)"zip");
6500 new_value_alloced = TRUE;
6501 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006502 /* When using ":set cm=name" the local value is going to be empty.
6503 * Do that here, otherwise the crypt functions will still use the
6504 * local value. */
6505 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6506 {
6507 free_string_option(curbuf->b_p_cm);
6508 curbuf->b_p_cm = empty_option;
6509 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006510
6511 /* Need to update the swapfile when the effective method changed.
6512 * Set "s" to the effective old value, "p" to the effective new
6513 * method and compare. */
6514 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6515 s = p_cm; /* was previously using the global value */
6516 else
6517 s = oldval;
6518 if (*curbuf->b_p_cm == NUL)
6519 p = p_cm; /* is now using the global value */
6520 else
6521 p = curbuf->b_p_cm;
6522 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006523 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006524
6525 /* If the global value changes need to update the swapfile for all
6526 * buffers using that value. */
6527 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6528 {
6529 buf_T *buf;
6530
Bram Moolenaar29323592016-07-24 22:04:11 +02006531 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006532 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006533 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006534 }
6535 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006536 }
6537#endif
6538
6539 /* 'matchpairs' */
6540 else if (gvarp == &p_mps)
6541 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006542#ifdef FEAT_MBYTE
6543 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006544 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006545 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006546 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006547 int x2 = -1;
6548 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006549
6550 if (*p != NUL)
6551 p += mb_ptr2len(p);
6552 if (*p != NUL)
6553 x2 = *p++;
6554 if (*p != NUL)
6555 {
6556 x3 = mb_ptr2char(p);
6557 p += mb_ptr2len(p);
6558 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006559 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006560 {
6561 errmsg = e_invarg;
6562 break;
6563 }
6564 if (*p == NUL)
6565 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006566 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006567 }
6568 else
6569#endif
6570 {
6571 /* Check for "x:y,x:y" */
6572 for (p = *varp; *p != NUL; p += 4)
6573 {
6574 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6575 {
6576 errmsg = e_invarg;
6577 break;
6578 }
6579 if (p[3] == NUL)
6580 break;
6581 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006582 }
6583 }
6584
6585#ifdef FEAT_COMMENTS
6586 /* 'comments' */
6587 else if (gvarp == &p_com)
6588 {
6589 for (s = *varp; *s; )
6590 {
6591 while (*s && *s != ':')
6592 {
6593 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6594 && !VIM_ISDIGIT(*s) && *s != '-')
6595 {
6596 errmsg = illegal_char(errbuf, *s);
6597 break;
6598 }
6599 ++s;
6600 }
6601 if (*s++ == NUL)
6602 errmsg = (char_u *)N_("E524: Missing colon");
6603 else if (*s == ',' || *s == NUL)
6604 errmsg = (char_u *)N_("E525: Zero length string");
6605 if (errmsg != NULL)
6606 break;
6607 while (*s && *s != ',')
6608 {
6609 if (*s == '\\' && s[1] != NUL)
6610 ++s;
6611 ++s;
6612 }
6613 s = skip_to_option_part(s);
6614 }
6615 }
6616#endif
6617
6618 /* 'listchars' */
6619 else if (varp == &p_lcs)
6620 {
6621 errmsg = set_chars_option(varp);
6622 }
6623
Bram Moolenaar071d4272004-06-13 20:20:40 +00006624 /* 'fillchars' */
6625 else if (varp == &p_fcs)
6626 {
6627 errmsg = set_chars_option(varp);
6628 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006629
6630#ifdef FEAT_CMDWIN
6631 /* 'cedit' */
6632 else if (varp == &p_cedit)
6633 {
6634 errmsg = check_cedit();
6635 }
6636#endif
6637
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006638 /* 'verbosefile' */
6639 else if (varp == &p_vfile)
6640 {
6641 verbose_stop();
6642 if (*p_vfile != NUL && verbose_open() == FAIL)
6643 errmsg = e_invarg;
6644 }
6645
Bram Moolenaar071d4272004-06-13 20:20:40 +00006646#ifdef FEAT_VIMINFO
6647 /* 'viminfo' */
6648 else if (varp == &p_viminfo)
6649 {
6650 for (s = p_viminfo; *s;)
6651 {
6652 /* Check it's a valid character */
6653 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6654 {
6655 errmsg = illegal_char(errbuf, *s);
6656 break;
6657 }
6658 if (*s == 'n') /* name is always last one */
6659 {
6660 break;
6661 }
6662 else if (*s == 'r') /* skip until next ',' */
6663 {
6664 while (*++s && *s != ',')
6665 ;
6666 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006667 else if (*s == '%')
6668 {
6669 /* optional number */
6670 while (vim_isdigit(*++s))
6671 ;
6672 }
6673 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006674 ++s; /* no extra chars */
6675 else /* must have a number */
6676 {
6677 while (vim_isdigit(*++s))
6678 ;
6679
6680 if (!VIM_ISDIGIT(*(s - 1)))
6681 {
6682 if (errbuf != NULL)
6683 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006684 sprintf((char *)errbuf,
6685 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006686 transchar_byte(*(s - 1)));
6687 errmsg = errbuf;
6688 }
6689 else
6690 errmsg = (char_u *)"";
6691 break;
6692 }
6693 }
6694 if (*s == ',')
6695 ++s;
6696 else if (*s)
6697 {
6698 if (errbuf != NULL)
6699 errmsg = (char_u *)N_("E527: Missing comma");
6700 else
6701 errmsg = (char_u *)"";
6702 break;
6703 }
6704 }
6705 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6706 errmsg = (char_u *)N_("E528: Must specify a ' value");
6707 }
6708#endif /* FEAT_VIMINFO */
6709
6710 /* terminal options */
6711 else if (istermoption(&options[opt_idx]) && full_screen)
6712 {
6713 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6714 if (varp == &T_CCO)
6715 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006716 int colors = atoi((char *)T_CCO);
6717
6718 /* Only reinitialize colors if t_Co value has really changed to
6719 * avoid expensive reload of colorscheme if t_Co is set to the
6720 * same value multiple times. */
6721 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006722 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006723 t_colors = colors;
6724 if (t_colors <= 1)
6725 {
6726 if (new_value_alloced)
6727 vim_free(T_CCO);
6728 T_CCO = empty_option;
6729 }
6730 /* We now have a different color setup, initialize it again. */
6731 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006732 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006733 }
6734 ttest(FALSE);
6735 if (varp == &T_ME)
6736 {
6737 out_str(T_ME);
6738 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006739#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006740 /* Since t_me has been set, this probably means that the user
6741 * wants to use this as default colors. Need to reset default
6742 * background/foreground colors. */
6743 mch_set_normal_colors();
6744#endif
6745 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006746 if (varp == &T_BE && termcap_active)
6747 {
6748 if (*T_BE == NUL)
6749 /* When clearing t_BE we assume the user no longer wants
6750 * bracketed paste, thus disable it by writing t_BD. */
6751 out_str(T_BD);
6752 else
6753 out_str(T_BE);
6754 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006755 }
6756
6757#ifdef FEAT_LINEBREAK
6758 /* 'showbreak' */
6759 else if (varp == &p_sbr)
6760 {
6761 for (s = p_sbr; *s; )
6762 {
6763 if (ptr2cells(s) != 1)
6764 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006765 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006766 }
6767 }
6768#endif
6769
6770#ifdef FEAT_GUI
6771 /* 'guifont' */
6772 else if (varp == &p_guifont)
6773 {
6774 if (gui.in_use)
6775 {
6776 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006777# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006778 /*
6779 * Put up a font dialog and let the user select a new value.
6780 * If this is cancelled go back to the old value but don't
6781 * give an error message.
6782 */
6783 if (STRCMP(p, "*") == 0)
6784 {
6785 p = gui_mch_font_dialog(oldval);
6786
6787 if (new_value_alloced)
6788 free_string_option(p_guifont);
6789
6790 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6791 new_value_alloced = TRUE;
6792 }
6793# endif
6794 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6795 {
6796# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6797 if (STRCMP(p_guifont, "*") == 0)
6798 {
6799 /* Dialog was cancelled: Keep the old value without giving
6800 * an error message. */
6801 if (new_value_alloced)
6802 free_string_option(p_guifont);
6803 p_guifont = vim_strsave(oldval);
6804 new_value_alloced = TRUE;
6805 }
6806 else
6807# endif
6808 errmsg = (char_u *)N_("E596: Invalid font(s)");
6809 }
6810 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006811 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006812 }
6813# ifdef FEAT_XFONTSET
6814 else if (varp == &p_guifontset)
6815 {
6816 if (STRCMP(p_guifontset, "*") == 0)
6817 errmsg = (char_u *)N_("E597: can't select fontset");
6818 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6819 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006820 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006821 }
6822# endif
6823# ifdef FEAT_MBYTE
6824 else if (varp == &p_guifontwide)
6825 {
6826 if (STRCMP(p_guifontwide, "*") == 0)
6827 errmsg = (char_u *)N_("E533: can't select wide font");
6828 else if (gui_get_wide_font() == FAIL)
6829 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006830 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006831 }
6832# endif
6833#endif
6834
6835#ifdef CURSOR_SHAPE
6836 /* 'guicursor' */
6837 else if (varp == &p_guicursor)
6838 errmsg = parse_shape_opt(SHAPE_CURSOR);
6839#endif
6840
6841#ifdef FEAT_MOUSESHAPE
6842 /* 'mouseshape' */
6843 else if (varp == &p_mouseshape)
6844 {
6845 errmsg = parse_shape_opt(SHAPE_MOUSE);
6846 update_mouseshape(-1);
6847 }
6848#endif
6849
6850#ifdef FEAT_PRINTER
6851 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006852 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006853# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006854 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006855 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006856# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006857#endif
6858
6859#ifdef FEAT_LANGMAP
6860 /* 'langmap' */
6861 else if (varp == &p_langmap)
6862 langmap_set();
6863#endif
6864
6865#ifdef FEAT_LINEBREAK
6866 /* 'breakat' */
6867 else if (varp == &p_breakat)
6868 fill_breakat_flags();
6869#endif
6870
6871#ifdef FEAT_TITLE
6872 /* 'titlestring' and 'iconstring' */
6873 else if (varp == &p_titlestring || varp == &p_iconstring)
6874 {
6875# ifdef FEAT_STL_OPT
6876 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6877
6878 /* NULL => statusline syntax */
6879 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6880 stl_syntax |= flagval;
6881 else
6882 stl_syntax &= ~flagval;
6883# endif
6884 did_set_title(varp == &p_iconstring);
6885
6886 }
6887#endif
6888
6889#ifdef FEAT_GUI
6890 /* 'guioptions' */
6891 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006892 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006893 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006894 redraw_gui_only = TRUE;
6895 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006896#endif
6897
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006898#if defined(FEAT_GUI_TABLINE)
6899 /* 'guitablabel' */
6900 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006901 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006902 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006903 redraw_gui_only = TRUE;
6904 }
6905 /* 'guitabtooltip' */
6906 else if (varp == &p_gtt)
6907 {
6908 redraw_gui_only = TRUE;
6909 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006910#endif
6911
Bram Moolenaar071d4272004-06-13 20:20:40 +00006912#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6913 /* 'ttymouse' */
6914 else if (varp == &p_ttym)
6915 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006916 /* Switch the mouse off before changing the escape sequences used for
6917 * that. */
6918 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006919 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6920 errmsg = e_invarg;
6921 else
6922 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006923 if (termcap_active)
6924 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006925 }
6926#endif
6927
Bram Moolenaar071d4272004-06-13 20:20:40 +00006928 /* 'selection' */
6929 else if (varp == &p_sel)
6930 {
6931 if (*p_sel == NUL
6932 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6933 errmsg = e_invarg;
6934 }
6935
6936 /* 'selectmode' */
6937 else if (varp == &p_slm)
6938 {
6939 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6940 errmsg = e_invarg;
6941 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006942
6943#ifdef FEAT_BROWSE
6944 /* 'browsedir' */
6945 else if (varp == &p_bsdir)
6946 {
6947 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6948 && !mch_isdir(p_bsdir))
6949 errmsg = e_invarg;
6950 }
6951#endif
6952
Bram Moolenaar071d4272004-06-13 20:20:40 +00006953 /* 'keymodel' */
6954 else if (varp == &p_km)
6955 {
6956 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6957 errmsg = e_invarg;
6958 else
6959 {
6960 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6961 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6962 }
6963 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006964
6965 /* 'mousemodel' */
6966 else if (varp == &p_mousem)
6967 {
6968 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6969 errmsg = e_invarg;
6970#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6971 else if (*p_mousem != *oldval)
6972 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6973 * to create or delete the popup menus. */
6974 gui_motif_update_mousemodel(root_menu);
6975#endif
6976 }
6977
6978 /* 'switchbuf' */
6979 else if (varp == &p_swb)
6980 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006981 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006982 errmsg = e_invarg;
6983 }
6984
6985 /* 'debug' */
6986 else if (varp == &p_debug)
6987 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006988 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006989 errmsg = e_invarg;
6990 }
6991
6992 /* 'display' */
6993 else if (varp == &p_dy)
6994 {
6995 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6996 errmsg = e_invarg;
6997 else
6998 (void)init_chartab();
6999
7000 }
7001
Bram Moolenaar071d4272004-06-13 20:20:40 +00007002 /* 'eadirection' */
7003 else if (varp == &p_ead)
7004 {
7005 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7006 errmsg = e_invarg;
7007 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007008
7009#ifdef FEAT_CLIPBOARD
7010 /* 'clipboard' */
7011 else if (varp == &p_cb)
7012 errmsg = check_clipboard_option();
7013#endif
7014
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007015#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007016 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7017 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007018 else if (varp == &(curwin->w_s->b_p_spl)
7019 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007020 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007021 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007022 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007023 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007024 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007025 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007026 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007027 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007028 /* 'spellsuggest' */
7029 else if (varp == &p_sps)
7030 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007031 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007032 errmsg = e_invarg;
7033 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007034 /* 'mkspellmem' */
7035 else if (varp == &p_msm)
7036 {
7037 if (spell_check_msm() != OK)
7038 errmsg = e_invarg;
7039 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007040#endif
7041
Bram Moolenaar071d4272004-06-13 20:20:40 +00007042 /* When 'bufhidden' is set, check for valid value. */
7043 else if (gvarp == &p_bh)
7044 {
7045 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7046 errmsg = e_invarg;
7047 }
7048
7049 /* When 'buftype' is set, check for valid value. */
7050 else if (gvarp == &p_bt)
7051 {
7052 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7053 errmsg = e_invarg;
7054 else
7055 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007056 if (curwin->w_status_height)
7057 {
7058 curwin->w_redr_status = TRUE;
7059 redraw_later(VALID);
7060 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007061 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007062#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007063 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007064#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007065 }
7066 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007067
7068#ifdef FEAT_STL_OPT
7069 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007070 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007071 {
7072 int wid;
7073
7074 if (varp == &p_ruf) /* reset ru_wid first */
7075 ru_wid = 0;
7076 s = *varp;
7077 if (varp == &p_ruf && *s == '%')
7078 {
7079 /* set ru_wid if 'ruf' starts with "%99(" */
7080 if (*++s == '-') /* ignore a '-' */
7081 s++;
7082 wid = getdigits(&s);
7083 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7084 ru_wid = wid;
7085 else
7086 errmsg = check_stl_option(p_ruf);
7087 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007088 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007089 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007090 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007091 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007092 comp_col();
7093 }
7094#endif
7095
7096#ifdef FEAT_INS_EXPAND
7097 /* check if it is a valid value for 'complete' -- Acevedo */
7098 else if (gvarp == &p_cpt)
7099 {
7100 for (s = *varp; *s;)
7101 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007102 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007103 s++;
7104 if (!*s)
7105 break;
7106 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7107 {
7108 errmsg = illegal_char(errbuf, *s);
7109 break;
7110 }
7111 if (*++s != NUL && *s != ',' && *s != ' ')
7112 {
7113 if (s[-1] == 'k' || s[-1] == 's')
7114 {
7115 /* skip optional filename after 'k' and 's' */
7116 while (*s && *s != ',' && *s != ' ')
7117 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007118 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007119 ++s;
7120 ++s;
7121 }
7122 }
7123 else
7124 {
7125 if (errbuf != NULL)
7126 {
7127 sprintf((char *)errbuf,
7128 _("E535: Illegal character after <%c>"),
7129 *--s);
7130 errmsg = errbuf;
7131 }
7132 else
7133 errmsg = (char_u *)"";
7134 break;
7135 }
7136 }
7137 }
7138 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007139
7140 /* 'completeopt' */
7141 else if (varp == &p_cot)
7142 {
7143 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7144 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007145 else
7146 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007147 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007148#endif /* FEAT_INS_EXPAND */
7149
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007150#ifdef FEAT_SIGNS
7151 /* 'signcolumn' */
7152 else if (varp == &curwin->w_p_scl)
7153 {
7154 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7155 errmsg = e_invarg;
7156 }
7157#endif
7158
Bram Moolenaar071d4272004-06-13 20:20:40 +00007159
7160#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007161 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007162 else if (varp == &p_toolbar)
7163 {
7164 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7165 &toolbar_flags, TRUE) != OK)
7166 errmsg = e_invarg;
7167 else
7168 {
7169 out_flush();
7170 gui_mch_show_toolbar((toolbar_flags &
7171 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7172 }
7173 }
7174#endif
7175
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007176#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007177 /* 'toolbariconsize': GTK+ 2 only */
7178 else if (varp == &p_tbis)
7179 {
7180 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7181 errmsg = e_invarg;
7182 else
7183 {
7184 out_flush();
7185 gui_mch_show_toolbar((toolbar_flags &
7186 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7187 }
7188 }
7189#endif
7190
7191 /* 'pastetoggle': translate key codes like in a mapping */
7192 else if (varp == &p_pt)
7193 {
7194 if (*p_pt)
7195 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007196 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007197 if (p != NULL)
7198 {
7199 if (new_value_alloced)
7200 free_string_option(p_pt);
7201 p_pt = p;
7202 new_value_alloced = TRUE;
7203 }
7204 }
7205 }
7206
7207 /* 'backspace' */
7208 else if (varp == &p_bs)
7209 {
7210 if (VIM_ISDIGIT(*p_bs))
7211 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007212 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007213 errmsg = e_invarg;
7214 }
7215 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7216 errmsg = e_invarg;
7217 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007218 else if (varp == &p_bo)
7219 {
7220 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7221 errmsg = e_invarg;
7222 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007223
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007224 /* 'tagcase' */
7225 else if (gvarp == &p_tc)
7226 {
7227 unsigned int *flags;
7228
7229 if (opt_flags & OPT_LOCAL)
7230 {
7231 p = curbuf->b_p_tc;
7232 flags = &curbuf->b_tc_flags;
7233 }
7234 else
7235 {
7236 p = p_tc;
7237 flags = &tc_flags;
7238 }
7239
7240 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7241 /* make the local value empty: use the global value */
7242 *flags = 0;
7243 else if (*p == NUL
7244 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7245 errmsg = e_invarg;
7246 }
7247
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007248#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007249 /* 'casemap' */
7250 else if (varp == &p_cmp)
7251 {
7252 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7253 errmsg = e_invarg;
7254 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007255#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007256
7257#ifdef FEAT_DIFF
7258 /* 'diffopt' */
7259 else if (varp == &p_dip)
7260 {
7261 if (diffopt_changed() == FAIL)
7262 errmsg = e_invarg;
7263 }
7264#endif
7265
7266#ifdef FEAT_FOLDING
7267 /* 'foldmethod' */
7268 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7269 {
7270 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7271 || *curwin->w_p_fdm == NUL)
7272 errmsg = e_invarg;
7273 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007274 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007275 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007276 if (foldmethodIsDiff(curwin))
7277 newFoldLevel();
7278 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007279 }
7280# ifdef FEAT_EVAL
7281 /* 'foldexpr' */
7282 else if (varp == &curwin->w_p_fde)
7283 {
7284 if (foldmethodIsExpr(curwin))
7285 foldUpdateAll(curwin);
7286 }
7287# endif
7288 /* 'foldmarker' */
7289 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7290 {
7291 p = vim_strchr(*varp, ',');
7292 if (p == NULL)
7293 errmsg = (char_u *)N_("E536: comma required");
7294 else if (p == *varp || p[1] == NUL)
7295 errmsg = e_invarg;
7296 else if (foldmethodIsMarker(curwin))
7297 foldUpdateAll(curwin);
7298 }
7299 /* 'commentstring' */
7300 else if (gvarp == &p_cms)
7301 {
7302 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7303 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7304 }
7305 /* 'foldopen' */
7306 else if (varp == &p_fdo)
7307 {
7308 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7309 errmsg = e_invarg;
7310 }
7311 /* 'foldclose' */
7312 else if (varp == &p_fcl)
7313 {
7314 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7315 errmsg = e_invarg;
7316 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007317 /* 'foldignore' */
7318 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7319 {
7320 if (foldmethodIsIndent(curwin))
7321 foldUpdateAll(curwin);
7322 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007323#endif
7324
7325#ifdef FEAT_VIRTUALEDIT
7326 /* 'virtualedit' */
7327 else if (varp == &p_ve)
7328 {
7329 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7330 errmsg = e_invarg;
7331 else if (STRCMP(p_ve, oldval) != 0)
7332 {
7333 /* Recompute cursor position in case the new 've' setting
7334 * changes something. */
7335 validate_virtcol();
7336 coladvance(curwin->w_virtcol);
7337 }
7338 }
7339#endif
7340
7341#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7342 else if (varp == &p_csqf)
7343 {
7344 if (p_csqf != NULL)
7345 {
7346 p = p_csqf;
7347 while (*p != NUL)
7348 {
7349 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7350 || p[1] == NUL
7351 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7352 || (p[2] != NUL && p[2] != ','))
7353 {
7354 errmsg = e_invarg;
7355 break;
7356 }
7357 else if (p[2] == NUL)
7358 break;
7359 else
7360 p += 3;
7361 }
7362 }
7363 }
7364#endif
7365
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007366#ifdef FEAT_CINDENT
7367 /* 'cinoptions' */
7368 else if (gvarp == &p_cino)
7369 {
7370 /* TODO: recognize errors */
7371 parse_cino(curbuf);
7372 }
7373#endif
7374
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007375#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007376 /* 'renderoptions' */
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007377 else if (varp == &p_rop && gui.in_use)
7378 {
7379 if (!gui_mch_set_rendering_options(p_rop))
7380 errmsg = e_invarg;
7381 }
7382#endif
7383
Bram Moolenaard0b51382016-11-04 15:23:45 +01007384#ifdef FEAT_AUTOCMD
7385 else if (gvarp == &p_ft)
7386 {
7387 if (!valid_filetype(*varp))
7388 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007389 else
7390 ft_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaard0b51382016-11-04 15:23:45 +01007391 }
7392#endif
7393
7394#ifdef FEAT_SYN_HL
7395 else if (gvarp == &p_syn)
7396 {
7397 if (!valid_filetype(*varp))
7398 errmsg = e_invarg;
7399 }
7400#endif
7401
Bram Moolenaar825680f2017-07-22 17:04:02 +02007402#ifdef FEAT_TERMINAL
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007403 /* 'termkey' */
Bram Moolenaarc4f43bc2017-07-24 20:03:01 +02007404 else if (varp == &curwin->w_p_tk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007405 {
7406 if (*curwin->w_p_tk != NUL && string_to_key(curwin->w_p_tk, TRUE) == 0)
7407 errmsg = e_invarg;
7408 }
Bram Moolenaar825680f2017-07-22 17:04:02 +02007409 /* 'termsize' */
7410 else if (varp == &curwin->w_p_tms)
7411 {
7412 if (*curwin->w_p_tms != NUL)
7413 {
7414 p = skipdigits(curwin->w_p_tms);
7415 if (p == curwin->w_p_tms || *p != 'x' || *skipdigits(p + 1) != NUL)
7416 errmsg = e_invarg;
7417 }
7418 }
7419#endif
7420
Bram Moolenaar071d4272004-06-13 20:20:40 +00007421 /* Options that are a list of flags. */
7422 else
7423 {
7424 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007425 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007426 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007427 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007428 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007429 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007430 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007431 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007432 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007433#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007434 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007435 p = (char_u *)COCU_ALL;
7436#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007437 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007438 {
7439#ifdef FEAT_MOUSE
7440 p = (char_u *)MOUSE_ALL;
7441#else
7442 if (*p_mouse != NUL)
7443 errmsg = (char_u *)N_("E538: No mouse support");
7444#endif
7445 }
7446#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007447 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007448 p = (char_u *)GO_ALL;
7449#endif
7450 if (p != NULL)
7451 {
7452 for (s = *varp; *s; ++s)
7453 if (vim_strchr(p, *s) == NULL)
7454 {
7455 errmsg = illegal_char(errbuf, *s);
7456 break;
7457 }
7458 }
7459 }
7460
7461 /*
7462 * If error detected, restore the previous value.
7463 */
7464 if (errmsg != NULL)
7465 {
7466 if (new_value_alloced)
7467 free_string_option(*varp);
7468 *varp = oldval;
7469 /*
7470 * When resetting some values, need to act on it.
7471 */
7472 if (did_chartab)
7473 (void)init_chartab();
7474 if (varp == &p_hl)
7475 (void)highlight_changed();
7476 }
7477 else
7478 {
7479#ifdef FEAT_EVAL
7480 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007481 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007482#endif
7483 /*
7484 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007485 * Use "free_oldval", because recursiveness may change the flags under
7486 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007487 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007488 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007489 free_string_option(oldval);
7490 if (new_value_alloced)
7491 options[opt_idx].flags |= P_ALLOCED;
7492 else
7493 options[opt_idx].flags &= ~P_ALLOCED;
7494
7495 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007496 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007497 {
7498 /* global option with local value set to use global value; free
7499 * the local value and make it empty */
7500 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7501 free_string_option(*(char_u **)p);
7502 *(char_u **)p = empty_option;
7503 }
7504
7505 /* May set global value for local option. */
7506 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7507 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007508
7509#ifdef FEAT_AUTOCMD
7510 /*
7511 * Trigger the autocommand only after setting the flags.
7512 */
7513# ifdef FEAT_SYN_HL
7514 /* When 'syntax' is set, load the syntax of that name */
7515 if (varp == &(curbuf->b_p_syn))
7516 {
7517 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7518 curbuf->b_fname, TRUE, curbuf);
7519 }
7520# endif
7521 else if (varp == &(curbuf->b_p_ft))
7522 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007523 /* 'filetype' is set, trigger the FileType autocommand.
7524 * Skip this when called from a modeline and the filetype was
7525 * already set to this value. */
7526 if (!(opt_flags & OPT_MODELINE) || ft_changed)
7527 {
7528 did_filetype = TRUE;
7529 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007530 curbuf->b_fname, TRUE, curbuf);
Bram Moolenaar163095f2017-07-09 15:41:53 +02007531 /* Just in case the old "curbuf" is now invalid. */
7532 if (varp != &(curbuf->b_p_ft))
7533 varp = NULL;
Bram Moolenaar90492982017-06-22 14:16:31 +02007534 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007535 }
7536#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007537#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007538 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007539 {
7540 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007541 char_u *q = curwin->w_s->b_p_spl;
7542
7543 /* Skip the first name if it is "cjk". */
7544 if (STRNCMP(q, "cjk,", 4) == 0)
7545 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007546
7547 /*
7548 * Source the spell/LANG.vim in 'runtimepath'.
7549 * They could set 'spellcapcheck' depending on the language.
7550 * Use the first name in 'spelllang' up to '_region' or
7551 * '.encoding'.
7552 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007553 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007554 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7555 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007556 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007557 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007558 }
7559#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007560 }
7561
7562#ifdef FEAT_MOUSE
7563 if (varp == &p_mouse)
7564 {
7565# ifdef FEAT_MOUSE_TTY
7566 if (*p_mouse == NUL)
7567 mch_setmouse(FALSE); /* switch mouse off */
7568 else
7569# endif
7570 setmouse(); /* in case 'mouse' changed */
7571 }
7572#endif
7573
Bram Moolenaar913077c2012-03-28 19:59:04 +02007574 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007575 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007576 curwin->w_set_curswant = TRUE;
7577
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007578#ifdef FEAT_GUI
7579 /* check redraw when it's not a GUI option or the GUI is active. */
7580 if (!redraw_gui_only || gui.in_use)
7581#endif
7582 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007583
7584 return errmsg;
7585}
7586
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007587#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007588/*
7589 * Simple int comparison function for use with qsort()
7590 */
7591 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007592int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007593{
7594 return *(const int *)a - *(const int *)b;
7595}
7596
7597/*
7598 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7599 * Returns error message, NULL if it's OK.
7600 */
7601 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007602check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007603{
7604 char_u *s;
7605 int col;
7606 int count = 0;
7607 int color_cols[256];
7608 int i;
7609 int j = 0;
7610
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007611 if (wp->w_buffer == NULL)
7612 return NULL; /* buffer was closed */
7613
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007614 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007615 {
7616 if (*s == '-' || *s == '+')
7617 {
7618 /* -N and +N: add to 'textwidth' */
7619 col = (*s == '-') ? -1 : 1;
7620 ++s;
7621 if (!VIM_ISDIGIT(*s))
7622 return e_invarg;
7623 col = col * getdigits(&s);
7624 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007625 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007626 col += wp->w_buffer->b_p_tw;
7627 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007628 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007629 }
7630 else if (VIM_ISDIGIT(*s))
7631 col = getdigits(&s);
7632 else
7633 return e_invarg;
7634 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007635skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007636 if (*s == NUL)
7637 break;
7638 if (*s != ',')
7639 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007640 if (*++s == NUL)
7641 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007642 }
7643
7644 vim_free(wp->w_p_cc_cols);
7645 if (count == 0)
7646 wp->w_p_cc_cols = NULL;
7647 else
7648 {
7649 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7650 if (wp->w_p_cc_cols != NULL)
7651 {
7652 /* sort the columns for faster usage on screen redraw inside
7653 * win_line() */
7654 qsort(color_cols, count, sizeof(int), int_cmp);
7655
7656 for (i = 0; i < count; ++i)
7657 /* skip duplicates */
7658 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7659 wp->w_p_cc_cols[j++] = color_cols[i];
7660 wp->w_p_cc_cols[j] = -1; /* end marker */
7661 }
7662 }
7663
7664 return NULL; /* no error */
7665}
7666#endif
7667
Bram Moolenaar071d4272004-06-13 20:20:40 +00007668/*
7669 * Handle setting 'listchars' or 'fillchars'.
7670 * Returns error message, NULL if it's OK.
7671 */
7672 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007673set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007674{
7675 int round, i, len, entries;
7676 char_u *p, *s;
7677 int c1, c2 = 0;
7678 struct charstab
7679 {
7680 int *cp;
7681 char *name;
7682 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007683 static struct charstab filltab[] =
7684 {
7685 {&fill_stl, "stl"},
7686 {&fill_stlnc, "stlnc"},
7687 {&fill_vert, "vert"},
7688 {&fill_fold, "fold"},
7689 {&fill_diff, "diff"},
7690 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007691 static struct charstab lcstab[] =
7692 {
7693 {&lcs_eol, "eol"},
7694 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007695 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007696 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007697 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007698 {&lcs_tab2, "tab"},
7699 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007700#ifdef FEAT_CONCEAL
7701 {&lcs_conceal, "conceal"},
7702#else
7703 {NULL, "conceal"},
7704#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007705 };
7706 struct charstab *tab;
7707
Bram Moolenaar071d4272004-06-13 20:20:40 +00007708 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007709 {
7710 tab = lcstab;
7711 entries = sizeof(lcstab) / sizeof(struct charstab);
7712 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007713 else
7714 {
7715 tab = filltab;
7716 entries = sizeof(filltab) / sizeof(struct charstab);
7717 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007718
7719 /* first round: check for valid value, second round: assign values */
7720 for (round = 0; round <= 1; ++round)
7721 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007722 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007723 {
7724 /* After checking that the value is valid: set defaults: space for
7725 * 'fillchars', NUL for 'listchars' */
7726 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007727 if (tab[i].cp != NULL)
7728 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007729 if (varp == &p_lcs)
7730 lcs_tab1 = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007731 else
7732 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007733 }
7734 p = *varp;
7735 while (*p)
7736 {
7737 for (i = 0; i < entries; ++i)
7738 {
7739 len = (int)STRLEN(tab[i].name);
7740 if (STRNCMP(p, tab[i].name, len) == 0
7741 && p[len] == ':'
7742 && p[len + 1] != NUL)
7743 {
7744 s = p + len + 1;
7745#ifdef FEAT_MBYTE
7746 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007747 if (mb_char2cells(c1) > 1)
7748 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007749#else
7750 c1 = *s++;
7751#endif
7752 if (tab[i].cp == &lcs_tab2)
7753 {
7754 if (*s == NUL)
7755 continue;
7756#ifdef FEAT_MBYTE
7757 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007758 if (mb_char2cells(c2) > 1)
7759 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007760#else
7761 c2 = *s++;
7762#endif
7763 }
7764 if (*s == ',' || *s == NUL)
7765 {
7766 if (round)
7767 {
7768 if (tab[i].cp == &lcs_tab2)
7769 {
7770 lcs_tab1 = c1;
7771 lcs_tab2 = c2;
7772 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007773 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007774 *(tab[i].cp) = c1;
7775
7776 }
7777 p = s;
7778 break;
7779 }
7780 }
7781 }
7782
7783 if (i == entries)
7784 return e_invarg;
7785 if (*p == ',')
7786 ++p;
7787 }
7788 }
7789
7790 return NULL; /* no error */
7791}
7792
7793#ifdef FEAT_STL_OPT
7794/*
7795 * Check validity of options with the 'statusline' format.
7796 * Return error message or NULL.
7797 */
7798 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007799check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007800{
7801 int itemcnt = 0;
7802 int groupdepth = 0;
7803 static char_u errbuf[80];
7804
7805 while (*s && itemcnt < STL_MAX_ITEM)
7806 {
7807 /* Check for valid keys after % sequences */
7808 while (*s && *s != '%')
7809 s++;
7810 if (!*s)
7811 break;
7812 s++;
7813 if (*s != '%' && *s != ')')
7814 ++itemcnt;
7815 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7816 {
7817 s++;
7818 continue;
7819 }
7820 if (*s == ')')
7821 {
7822 s++;
7823 if (--groupdepth < 0)
7824 break;
7825 continue;
7826 }
7827 if (*s == '-')
7828 s++;
7829 while (VIM_ISDIGIT(*s))
7830 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007831 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007832 continue;
7833 if (*s == '.')
7834 {
7835 s++;
7836 while (*s && VIM_ISDIGIT(*s))
7837 s++;
7838 }
7839 if (*s == '(')
7840 {
7841 groupdepth++;
7842 continue;
7843 }
7844 if (vim_strchr(STL_ALL, *s) == NULL)
7845 {
7846 return illegal_char(errbuf, *s);
7847 }
7848 if (*s == '{')
7849 {
7850 s++;
7851 while (*s != '}' && *s)
7852 s++;
7853 if (*s != '}')
7854 return (char_u *)N_("E540: Unclosed expression sequence");
7855 }
7856 }
7857 if (itemcnt >= STL_MAX_ITEM)
7858 return (char_u *)N_("E541: too many items");
7859 if (groupdepth != 0)
7860 return (char_u *)N_("E542: unbalanced groups");
7861 return NULL;
7862}
7863#endif
7864
7865#ifdef FEAT_CLIPBOARD
7866/*
7867 * Extract the items in the 'clipboard' option and set global values.
7868 */
7869 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007870check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007871{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007872 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007873 int new_autoselect_star = FALSE;
7874 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007875 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007876 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007877 regprog_T *new_exclude_prog = NULL;
7878 char_u *errmsg = NULL;
7879 char_u *p;
7880
7881 for (p = p_cb; *p != NUL; )
7882 {
7883 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7884 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007885 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007886 p += 7;
7887 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007888 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007889 && (p[11] == ',' || p[11] == NUL))
7890 {
7891 new_unnamed |= CLIP_UNNAMED_PLUS;
7892 p += 11;
7893 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007894 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007895 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007896 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007897 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007898 p += 10;
7899 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007900 else if (STRNCMP(p, "autoselectplus", 14) == 0
7901 && (p[14] == ',' || p[14] == NUL))
7902 {
7903 new_autoselect_plus = TRUE;
7904 p += 14;
7905 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007906 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007907 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007908 {
7909 new_autoselectml = TRUE;
7910 p += 12;
7911 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007912 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7913 {
7914 new_html = TRUE;
7915 p += 4;
7916 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007917 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7918 {
7919 p += 8;
7920 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7921 if (new_exclude_prog == NULL)
7922 errmsg = e_invarg;
7923 break;
7924 }
7925 else
7926 {
7927 errmsg = e_invarg;
7928 break;
7929 }
7930 if (*p == ',')
7931 ++p;
7932 }
7933 if (errmsg == NULL)
7934 {
7935 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007936 clip_autoselect_star = new_autoselect_star;
7937 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007938 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007939 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007940 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007941 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007942#ifdef FEAT_GUI_GTK
7943 if (gui.in_use)
7944 {
7945 gui_gtk_set_selection_targets();
7946 gui_gtk_set_dnd_targets();
7947 }
7948#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007949 }
7950 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007951 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007952
7953 return errmsg;
7954}
7955#endif
7956
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007957#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007958 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007959did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007960{
7961 char_u *errmsg = NULL;
7962 win_T *wp;
7963 int l;
7964
7965 if (is_spellfile)
7966 {
7967 l = (int)STRLEN(curwin->w_s->b_p_spf);
7968 if (l > 0 && (l < 4
7969 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7970 errmsg = e_invarg;
7971 }
7972
7973 if (errmsg == NULL)
7974 {
7975 FOR_ALL_WINDOWS(wp)
7976 if (wp->w_buffer == curbuf && wp->w_p_spell)
7977 {
7978 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007979 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007980 }
7981 }
7982 return errmsg;
7983}
7984
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007985/*
7986 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7987 * Return error message when failed, NULL when OK.
7988 */
7989 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007990compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007991{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007992 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007993 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007994
Bram Moolenaar860cae12010-06-05 23:22:07 +02007995 if (*synblock->b_p_spc == NUL)
7996 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007997 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007998 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007999 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008000 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008001 if (re != NULL)
8002 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008003 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008004 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008005 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008006 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008007 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008008 return e_invarg;
8009 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008010 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008011 }
8012
Bram Moolenaar473de612013-06-08 18:19:48 +02008013 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008014 return NULL;
8015}
8016#endif
8017
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008018#if defined(FEAT_EVAL) || defined(PROTO)
8019/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008020 * Set the scriptID for an option, taking care of setting the buffer- or
8021 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008022 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008023 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008024set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008025{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008026 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8027 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008028
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008029 /* Remember where the option was set. For local options need to do that
8030 * in the buffer or window structure. */
8031 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008032 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008033 if (both || (opt_flags & OPT_LOCAL))
8034 {
8035 if (indir & PV_BUF)
8036 curbuf->b_p_scriptID[indir & PV_MASK] = id;
8037 else if (indir & PV_WIN)
8038 curwin->w_p_scriptID[indir & PV_MASK] = id;
8039 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008040}
8041#endif
8042
Bram Moolenaar071d4272004-06-13 20:20:40 +00008043/*
8044 * Set the value of a boolean option, and take care of side effects.
8045 * Returns NULL for success, or an error message for an error.
8046 */
8047 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008048set_bool_option(
8049 int opt_idx, /* index in options[] table */
8050 char_u *varp, /* pointer to the option variable */
8051 int value, /* new value */
8052 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008053{
8054 int old_value = *(int *)varp;
8055
Bram Moolenaar071d4272004-06-13 20:20:40 +00008056 /* Disallow changing some options from secure mode */
8057 if ((secure
8058#ifdef HAVE_SANDBOX
8059 || sandbox != 0
8060#endif
8061 ) && (options[opt_idx].flags & P_SECURE))
8062 return e_secure;
8063
8064 *(int *)varp = value; /* set the new value */
8065#ifdef FEAT_EVAL
8066 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008067 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008068#endif
8069
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008070#ifdef FEAT_GUI
8071 need_mouse_correct = TRUE;
8072#endif
8073
Bram Moolenaar071d4272004-06-13 20:20:40 +00008074 /* May set global value for local option. */
8075 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8076 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8077
8078 /*
8079 * Handle side effects of changing a bool option.
8080 */
8081
8082 /* 'compatible' */
8083 if ((int *)varp == &p_cp)
8084 {
8085 compatible_set();
8086 }
8087
Bram Moolenaar920694c2016-08-21 17:45:02 +02008088#ifdef FEAT_LANGMAP
8089 if ((int *)varp == &p_lrm)
8090 /* 'langremap' -> !'langnoremap' */
8091 p_lnr = !p_lrm;
8092 else if ((int *)varp == &p_lnr)
8093 /* 'langnoremap' -> !'langremap' */
8094 p_lrm = !p_lnr;
8095#endif
8096
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008097#ifdef FEAT_PERSISTENT_UNDO
8098 /* 'undofile' */
8099 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8100 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008101 /* Only take action when the option was set. When reset we do not
8102 * delete the undo file, the option may be set again without making
8103 * any changes in between. */
8104 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008105 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008106 char_u hash[UNDO_HASH_SIZE];
8107 buf_T *save_curbuf = curbuf;
8108
Bram Moolenaar29323592016-07-24 22:04:11 +02008109 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008110 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008111 /* When 'undofile' is set globally: for every buffer, otherwise
8112 * only for the current buffer: Try to read in the undofile,
8113 * if one exists, the buffer wasn't changed and the buffer was
8114 * loaded */
8115 if ((curbuf == save_curbuf
8116 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8117 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8118 {
8119 u_compute_hash(hash);
8120 u_read_undo(NULL, hash, curbuf->b_fname);
8121 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008122 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008123 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008124 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008125 }
8126#endif
8127
Bram Moolenaar071d4272004-06-13 20:20:40 +00008128 else if ((int *)varp == &curbuf->b_p_ro)
8129 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008130 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008131 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8132 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008133
8134 /* when 'readonly' is set may give W10 again */
8135 if (curbuf->b_p_ro)
8136 curbuf->b_did_warn = FALSE;
8137
Bram Moolenaar071d4272004-06-13 20:20:40 +00008138#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008139 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008140#endif
8141 }
8142
Bram Moolenaar9c449722010-07-20 18:44:27 +02008143#ifdef FEAT_GUI
8144 else if ((int *)varp == &p_mh)
8145 {
8146 if (!p_mh)
8147 gui_mch_mousehide(FALSE);
8148 }
8149#endif
8150
Bram Moolenaara539df02010-08-01 14:35:05 +02008151 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008152 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008153 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008154# ifdef FEAT_TERMINAL
8155 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaar6d819742017-08-06 14:57:49 +02008156 if (term_in_normal_mode()
Bram Moolenaar20e6cd02017-08-01 20:25:22 +02008157 || (bt_terminal(curbuf) && !term_is_finished(curbuf)))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008158 {
8159 curbuf->b_p_ma = FALSE;
8160 return (char_u *)N_("E946: Cannot make a terminal with running job modifiable");
8161 }
8162# endif
8163# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008164 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008165# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008166 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008167#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008168 /* when 'endofline' is changed, redraw the window title */
8169 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008170 {
8171 redraw_titles();
8172 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008173 /* when 'fixeol' is changed, redraw the window title */
8174 else if ((int *)varp == &curbuf->b_p_fixeol)
8175 {
8176 redraw_titles();
8177 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008178# ifdef FEAT_MBYTE
8179 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008180 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008181 {
8182 redraw_titles();
8183 }
8184# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008185#endif
8186
8187 /* when 'bin' is set also set some other options */
8188 else if ((int *)varp == &curbuf->b_p_bin)
8189 {
8190 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8191#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008192 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008193#endif
8194 }
8195
8196#ifdef FEAT_AUTOCMD
8197 /* when 'buflisted' changes, trigger autocommands */
8198 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8199 {
8200 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8201 NULL, NULL, TRUE, curbuf);
8202 }
8203#endif
8204
8205 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8206 else if ((int *)varp == &curbuf->b_p_swf)
8207 {
8208 if (curbuf->b_p_swf && p_uc)
8209 ml_open_file(curbuf); /* create the swap file */
8210 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008211 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8212 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008213 mf_close_file(curbuf, TRUE); /* remove the swap file */
8214 }
8215
8216 /* when 'terse' is set change 'shortmess' */
8217 else if ((int *)varp == &p_terse)
8218 {
8219 char_u *p;
8220
8221 p = vim_strchr(p_shm, SHM_SEARCH);
8222
8223 /* insert 's' in p_shm */
8224 if (p_terse && p == NULL)
8225 {
8226 STRCPY(IObuff, p_shm);
8227 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008228 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008229 }
8230 /* remove 's' from p_shm */
8231 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008232 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008233 }
8234
8235 /* when 'paste' is set or reset also change other options */
8236 else if ((int *)varp == &p_paste)
8237 {
8238 paste_option_changed();
8239 }
8240
8241 /* when 'insertmode' is set from an autocommand need to do work here */
8242 else if ((int *)varp == &p_im)
8243 {
8244 if (p_im)
8245 {
8246 if ((State & INSERT) == 0)
8247 need_start_insertmode = TRUE;
8248 stop_insert_mode = FALSE;
8249 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008250 /* only reset if it was set previously */
8251 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008252 {
8253 need_start_insertmode = FALSE;
8254 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008255 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008256 clear_cmdline = TRUE; /* remove "(insert)" */
8257 restart_edit = 0;
8258 }
8259 }
8260
8261 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8262 else if ((int *)varp == &p_ic && p_hls)
8263 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008264 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008265 }
8266
8267#ifdef FEAT_SEARCH_EXTRA
8268 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8269 else if ((int *)varp == &p_hls)
8270 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008271 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008272 }
8273#endif
8274
8275#ifdef FEAT_SCROLLBIND
8276 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8277 * at the end of normal_cmd() */
8278 else if ((int *)varp == &curwin->w_p_scb)
8279 {
8280 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008281 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008282 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008283 curwin->w_scbind_pos = curwin->w_topline;
8284 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008285 }
8286#endif
8287
Bram Moolenaar4033c552017-09-16 20:54:51 +02008288#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008289 /* There can be only one window with 'previewwindow' set. */
8290 else if ((int *)varp == &curwin->w_p_pvw)
8291 {
8292 if (curwin->w_p_pvw)
8293 {
8294 win_T *win;
8295
Bram Moolenaar29323592016-07-24 22:04:11 +02008296 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008297 if (win->w_p_pvw && win != curwin)
8298 {
8299 curwin->w_p_pvw = FALSE;
8300 return (char_u *)N_("E590: A preview window already exists");
8301 }
8302 }
8303 }
8304#endif
8305
8306 /* when 'textmode' is set or reset also change 'fileformat' */
8307 else if ((int *)varp == &curbuf->b_p_tx)
8308 {
8309 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8310 }
8311
8312 /* when 'textauto' is set or reset also change 'fileformats' */
8313 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008314 set_string_option_direct((char_u *)"ffs", -1,
8315 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008316 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008317
8318 /*
8319 * When 'lisp' option changes include/exclude '-' in
8320 * keyword characters.
8321 */
8322#ifdef FEAT_LISP
8323 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8324 {
8325 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8326 }
8327#endif
8328
8329#ifdef FEAT_TITLE
8330 /* when 'title' changed, may need to change the title; same for 'icon' */
8331 else if ((int *)varp == &p_title)
8332 {
8333 did_set_title(FALSE);
8334 }
8335
8336 else if ((int *)varp == &p_icon)
8337 {
8338 did_set_title(TRUE);
8339 }
8340#endif
8341
8342 else if ((int *)varp == &curbuf->b_changed)
8343 {
8344 if (!value)
8345 save_file_ff(curbuf); /* Buffer is unchanged */
8346#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008347 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008348#endif
8349#ifdef FEAT_AUTOCMD
8350 modified_was_set = value;
8351#endif
8352 }
8353
8354#ifdef BACKSLASH_IN_FILENAME
8355 else if ((int *)varp == &p_ssl)
8356 {
8357 if (p_ssl)
8358 {
8359 psepc = '/';
8360 psepcN = '\\';
8361 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008362 }
8363 else
8364 {
8365 psepc = '\\';
8366 psepcN = '/';
8367 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008368 }
8369
8370 /* need to adjust the file name arguments and buffer names. */
8371 buflist_slash_adjust();
8372 alist_slash_adjust();
8373# ifdef FEAT_EVAL
8374 scriptnames_slash_adjust();
8375# endif
8376 }
8377#endif
8378
8379 /* If 'wrap' is set, set w_leftcol to zero. */
8380 else if ((int *)varp == &curwin->w_p_wrap)
8381 {
8382 if (curwin->w_p_wrap)
8383 curwin->w_leftcol = 0;
8384 }
8385
Bram Moolenaar071d4272004-06-13 20:20:40 +00008386 else if ((int *)varp == &p_ea)
8387 {
8388 if (p_ea && !old_value)
8389 win_equal(curwin, FALSE, 0);
8390 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008391
8392 else if ((int *)varp == &p_wiv)
8393 {
8394 /*
8395 * When 'weirdinvert' changed, set/reset 't_xs'.
8396 * Then set 'weirdinvert' according to value of 't_xs'.
8397 */
8398 if (p_wiv && !old_value)
8399 T_XS = (char_u *)"y";
8400 else if (!p_wiv && old_value)
8401 T_XS = empty_option;
8402 p_wiv = (*T_XS != NUL);
8403 }
8404
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008405#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008406 else if ((int *)varp == &p_beval)
8407 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008408 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008409 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008410 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008411 gui_mch_disable_beval_area(balloonEval);
8412 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008413#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008414
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008415#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008416 else if ((int *)varp == &p_acd)
8417 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008418 /* Change directories when the 'acd' option is set now. */
8419 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008420 }
8421#endif
8422
8423#ifdef FEAT_DIFF
8424 /* 'diff' */
8425 else if ((int *)varp == &curwin->w_p_diff)
8426 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008427 /* May add or remove the buffer from the list of diff buffers. */
8428 diff_buf_adjust(curwin);
8429# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008430 if (foldmethodIsDiff(curwin))
8431 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008432# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008433 }
8434#endif
8435
8436#ifdef USE_IM_CONTROL
8437 /* 'imdisable' */
8438 else if ((int *)varp == &p_imdisable)
8439 {
8440 /* Only de-activate it here, it will be enabled when changing mode. */
8441 if (p_imdisable)
8442 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008443 else if (State & INSERT)
8444 /* When the option is set from an autocommand, it may need to take
8445 * effect right away. */
8446 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008447 }
8448#endif
8449
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008450#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008451 /* 'spell' */
8452 else if ((int *)varp == &curwin->w_p_spell)
8453 {
8454 if (curwin->w_p_spell)
8455 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008456 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008457 if (errmsg != NULL)
8458 EMSG(_(errmsg));
8459 }
8460 }
8461#endif
8462
Bram Moolenaar071d4272004-06-13 20:20:40 +00008463#ifdef FEAT_FKMAP
8464 else if ((int *)varp == &p_altkeymap)
8465 {
8466 if (old_value != p_altkeymap)
8467 {
8468 if (!p_altkeymap)
8469 {
8470 p_hkmap = p_fkmap;
8471 p_fkmap = 0;
8472 }
8473 else
8474 {
8475 p_fkmap = p_hkmap;
8476 p_hkmap = 0;
8477 }
8478 (void)init_chartab();
8479 }
8480 }
8481
8482 /*
8483 * In case some second language keymapping options have changed, check
8484 * and correct the setting in a consistent way.
8485 */
8486
8487 /*
8488 * If hkmap or fkmap are set, reset Arabic keymapping.
8489 */
8490 if ((p_hkmap || p_fkmap) && p_altkeymap)
8491 {
8492 p_altkeymap = p_fkmap;
8493# ifdef FEAT_ARABIC
8494 curwin->w_p_arab = FALSE;
8495# endif
8496 (void)init_chartab();
8497 }
8498
8499 /*
8500 * If hkmap set, reset Farsi keymapping.
8501 */
8502 if (p_hkmap && p_altkeymap)
8503 {
8504 p_altkeymap = 0;
8505 p_fkmap = 0;
8506# ifdef FEAT_ARABIC
8507 curwin->w_p_arab = FALSE;
8508# endif
8509 (void)init_chartab();
8510 }
8511
8512 /*
8513 * If fkmap set, reset Hebrew keymapping.
8514 */
8515 if (p_fkmap && !p_altkeymap)
8516 {
8517 p_altkeymap = 1;
8518 p_hkmap = 0;
8519# ifdef FEAT_ARABIC
8520 curwin->w_p_arab = FALSE;
8521# endif
8522 (void)init_chartab();
8523 }
8524#endif
8525
8526#ifdef FEAT_ARABIC
8527 if ((int *)varp == &curwin->w_p_arab)
8528 {
8529 if (curwin->w_p_arab)
8530 {
8531 /*
8532 * 'arabic' is set, handle various sub-settings.
8533 */
8534 if (!p_tbidi)
8535 {
8536 /* set rightleft mode */
8537 if (!curwin->w_p_rl)
8538 {
8539 curwin->w_p_rl = TRUE;
8540 changed_window_setting();
8541 }
8542
8543 /* Enable Arabic shaping (major part of what Arabic requires) */
8544 if (!p_arshape)
8545 {
8546 p_arshape = TRUE;
8547 redraw_later_clear();
8548 }
8549 }
8550
8551 /* Arabic requires a utf-8 encoding, inform the user if its not
8552 * set. */
8553 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008554 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008555 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8556
Bram Moolenaar8820b482017-03-16 17:23:31 +01008557 msg_source(HL_ATTR(HLF_W));
8558 MSG_ATTR(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008559#ifdef FEAT_EVAL
8560 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8561#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008562 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008563
8564# ifdef FEAT_MBYTE
8565 /* set 'delcombine' */
8566 p_deco = TRUE;
8567# endif
8568
8569# ifdef FEAT_KEYMAP
8570 /* Force-set the necessary keymap for arabic */
8571 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8572 OPT_LOCAL);
8573# endif
8574# ifdef FEAT_FKMAP
8575 p_altkeymap = 0;
8576 p_hkmap = 0;
8577 p_fkmap = 0;
8578 (void)init_chartab();
8579# endif
8580 }
8581 else
8582 {
8583 /*
8584 * 'arabic' is reset, handle various sub-settings.
8585 */
8586 if (!p_tbidi)
8587 {
8588 /* reset rightleft mode */
8589 if (curwin->w_p_rl)
8590 {
8591 curwin->w_p_rl = FALSE;
8592 changed_window_setting();
8593 }
8594
8595 /* 'arabicshape' isn't reset, it is a global option and
8596 * another window may still need it "on". */
8597 }
8598
8599 /* 'delcombine' isn't reset, it is a global option and another
8600 * window may still want it "on". */
8601
8602# ifdef FEAT_KEYMAP
8603 /* Revert to the default keymap */
8604 curbuf->b_p_iminsert = B_IMODE_NONE;
8605 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8606# endif
8607 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008608 }
8609
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008610#endif
8611
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008612#ifdef FEAT_TERMGUICOLORS
8613 /* 'termguicolors' */
8614 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008615 {
8616# ifdef FEAT_GUI
8617 if (!gui.in_use && !gui.starting)
8618# endif
8619 highlight_gui_started();
8620 }
8621#endif
8622
Bram Moolenaar071d4272004-06-13 20:20:40 +00008623 /*
8624 * End of handling side effects for bool options.
8625 */
8626
Bram Moolenaar53744302015-07-17 17:38:22 +02008627 /* after handling side effects, call autocommand */
8628
Bram Moolenaar071d4272004-06-13 20:20:40 +00008629 options[opt_idx].flags |= P_WAS_SET;
8630
Bram Moolenaar53744302015-07-17 17:38:22 +02008631#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8632 if (!starting)
8633 {
8634 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008635 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8636 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8637 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008638 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8639 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8640 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8641 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8642 reset_v_option_vars();
8643 }
8644#endif
8645
Bram Moolenaar071d4272004-06-13 20:20:40 +00008646 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008647 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008648 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008649 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008650 check_redraw(options[opt_idx].flags);
8651
8652 return NULL;
8653}
8654
8655/*
8656 * Set the value of a number option, and take care of side effects.
8657 * Returns NULL for success, or an error message for an error.
8658 */
8659 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008660set_num_option(
8661 int opt_idx, /* index in options[] table */
8662 char_u *varp, /* pointer to the option variable */
8663 long value, /* new value */
8664 char_u *errbuf, /* buffer for error messages */
8665 size_t errbuflen, /* length of "errbuf" */
8666 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008667 OPT_MODELINE */
8668{
8669 char_u *errmsg = NULL;
8670 long old_value = *(long *)varp;
8671 long old_Rows = Rows; /* remember old Rows */
8672 long old_Columns = Columns; /* remember old Columns */
8673 long *pp = (long *)varp;
8674
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008675 /* Disallow changing some options from secure mode. */
8676 if ((secure
8677#ifdef HAVE_SANDBOX
8678 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008679#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008680 ) && (options[opt_idx].flags & P_SECURE))
8681 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008682
8683 *pp = value;
8684#ifdef FEAT_EVAL
8685 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008686 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008687#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008688#ifdef FEAT_GUI
8689 need_mouse_correct = TRUE;
8690#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008691
Bram Moolenaar14f24742012-08-08 18:01:05 +02008692 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008693 {
8694 errmsg = e_positive;
8695 curbuf->b_p_sw = curbuf->b_p_ts;
8696 }
8697
8698 /*
8699 * Number options that need some action when changed
8700 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008701 if (pp == &p_wh || pp == &p_hh)
8702 {
8703 if (p_wh < 1)
8704 {
8705 errmsg = e_positive;
8706 p_wh = 1;
8707 }
8708 if (p_wmh > p_wh)
8709 {
8710 errmsg = e_winheight;
8711 p_wh = p_wmh;
8712 }
8713 if (p_hh < 0)
8714 {
8715 errmsg = e_positive;
8716 p_hh = 0;
8717 }
8718
8719 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008720 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008721 {
8722 if (pp == &p_wh && curwin->w_height < p_wh)
8723 win_setheight((int)p_wh);
8724 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8725 win_setheight((int)p_hh);
8726 }
8727 }
8728
8729 /* 'winminheight' */
8730 else if (pp == &p_wmh)
8731 {
8732 if (p_wmh < 0)
8733 {
8734 errmsg = e_positive;
8735 p_wmh = 0;
8736 }
8737 if (p_wmh > p_wh)
8738 {
8739 errmsg = e_winheight;
8740 p_wmh = p_wh;
8741 }
8742 win_setminheight();
8743 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008744 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008745 {
8746 if (p_wiw < 1)
8747 {
8748 errmsg = e_positive;
8749 p_wiw = 1;
8750 }
8751 if (p_wmw > p_wiw)
8752 {
8753 errmsg = e_winwidth;
8754 p_wiw = p_wmw;
8755 }
8756
8757 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008758 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008759 win_setwidth((int)p_wiw);
8760 }
8761
8762 /* 'winminwidth' */
8763 else if (pp == &p_wmw)
8764 {
8765 if (p_wmw < 0)
8766 {
8767 errmsg = e_positive;
8768 p_wmw = 0;
8769 }
8770 if (p_wmw > p_wiw)
8771 {
8772 errmsg = e_winwidth;
8773 p_wmw = p_wiw;
8774 }
8775 win_setminheight();
8776 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008777
Bram Moolenaar071d4272004-06-13 20:20:40 +00008778 /* (re)set last window status line */
8779 else if (pp == &p_ls)
8780 {
8781 last_status(FALSE);
8782 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008783
8784 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008785 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008786 {
8787 shell_new_rows(); /* recompute window positions and heights */
8788 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008789
8790#ifdef FEAT_GUI
8791 else if (pp == &p_linespace)
8792 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008793 /* Recompute gui.char_height and resize the Vim window to keep the
8794 * same number of lines. */
8795 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008796 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008797 }
8798#endif
8799
8800#ifdef FEAT_FOLDING
8801 /* 'foldlevel' */
8802 else if (pp == &curwin->w_p_fdl)
8803 {
8804 if (curwin->w_p_fdl < 0)
8805 curwin->w_p_fdl = 0;
8806 newFoldLevel();
8807 }
8808
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008809 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008810 else if (pp == &curwin->w_p_fml)
8811 {
8812 foldUpdateAll(curwin);
8813 }
8814
8815 /* 'foldnestmax' */
8816 else if (pp == &curwin->w_p_fdn)
8817 {
8818 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8819 foldUpdateAll(curwin);
8820 }
8821
8822 /* 'foldcolumn' */
8823 else if (pp == &curwin->w_p_fdc)
8824 {
8825 if (curwin->w_p_fdc < 0)
8826 {
8827 errmsg = e_positive;
8828 curwin->w_p_fdc = 0;
8829 }
8830 else if (curwin->w_p_fdc > 12)
8831 {
8832 errmsg = e_invarg;
8833 curwin->w_p_fdc = 12;
8834 }
8835 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008836#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008837
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008838#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008839 /* 'shiftwidth' or 'tabstop' */
8840 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8841 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008842# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008843 if (foldmethodIsIndent(curwin))
8844 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008845# endif
8846# ifdef FEAT_CINDENT
8847 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8848 * parse 'cinoptions'. */
8849 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8850 parse_cino(curbuf);
8851# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008852 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008853#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008854
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008855#ifdef FEAT_MBYTE
8856 /* 'maxcombine' */
8857 else if (pp == &p_mco)
8858 {
8859 if (p_mco > MAX_MCO)
8860 p_mco = MAX_MCO;
8861 else if (p_mco < 0)
8862 p_mco = 0;
8863 screenclear(); /* will re-allocate the screen */
8864 }
8865#endif
8866
Bram Moolenaar071d4272004-06-13 20:20:40 +00008867 else if (pp == &curbuf->b_p_iminsert)
8868 {
8869 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8870 {
8871 errmsg = e_invarg;
8872 curbuf->b_p_iminsert = B_IMODE_NONE;
8873 }
8874 p_iminsert = curbuf->b_p_iminsert;
8875 if (termcap_active) /* don't do this in the alternate screen */
8876 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02008877#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008878 /* Show/unshow value of 'keymap' in status lines. */
8879 status_redraw_curbuf();
8880#endif
8881 }
8882
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02008883#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
8884 /* 'imstyle' */
8885 else if (pp == &p_imst)
8886 {
8887 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
8888 errmsg = e_invarg;
8889 }
8890#endif
8891
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008892 else if (pp == &p_window)
8893 {
8894 if (p_window < 1)
8895 p_window = 1;
8896 else if (p_window >= Rows)
8897 p_window = Rows - 1;
8898 }
8899
Bram Moolenaar071d4272004-06-13 20:20:40 +00008900 else if (pp == &curbuf->b_p_imsearch)
8901 {
8902 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8903 {
8904 errmsg = e_invarg;
8905 curbuf->b_p_imsearch = B_IMODE_NONE;
8906 }
8907 p_imsearch = curbuf->b_p_imsearch;
8908 }
8909
8910#ifdef FEAT_TITLE
8911 /* if 'titlelen' has changed, redraw the title */
8912 else if (pp == &p_titlelen)
8913 {
8914 if (p_titlelen < 0)
8915 {
8916 errmsg = e_positive;
8917 p_titlelen = 85;
8918 }
8919 if (starting != NO_SCREEN && old_value != p_titlelen)
8920 need_maketitle = TRUE;
8921 }
8922#endif
8923
8924 /* if p_ch changed value, change the command line height */
8925 else if (pp == &p_ch)
8926 {
8927 if (p_ch < 1)
8928 {
8929 errmsg = e_positive;
8930 p_ch = 1;
8931 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008932 if (p_ch > Rows - min_rows() + 1)
8933 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008934
8935 /* Only compute the new window layout when startup has been
8936 * completed. Otherwise the frame sizes may be wrong. */
8937 if (p_ch != old_value && full_screen
8938#ifdef FEAT_GUI
8939 && !gui.starting
8940#endif
8941 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008942 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008943 }
8944
8945 /* when 'updatecount' changes from zero to non-zero, open swap files */
8946 else if (pp == &p_uc)
8947 {
8948 if (p_uc < 0)
8949 {
8950 errmsg = e_positive;
8951 p_uc = 100;
8952 }
8953 if (p_uc && !old_value)
8954 ml_open_files();
8955 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008956#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008957 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008958 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008959 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008960 {
8961 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008962 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008963 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008964 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008965 {
8966 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008967 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008968 }
8969 }
8970#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008971#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008972 else if (pp == &p_mzq)
8973 mzvim_reset_timer();
8974#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008975
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01008976#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
8977 /* 'pyxversion' */
8978 else if (pp == &p_pyx)
8979 {
8980 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
8981 errmsg = e_invarg;
8982 }
8983#endif
8984
Bram Moolenaar071d4272004-06-13 20:20:40 +00008985 /* sync undo before 'undolevels' changes */
8986 else if (pp == &p_ul)
8987 {
8988 /* use the old value, otherwise u_sync() may not work properly */
8989 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008990 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008991 p_ul = value;
8992 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008993 else if (pp == &curbuf->b_p_ul)
8994 {
8995 /* use the old value, otherwise u_sync() may not work properly */
8996 curbuf->b_p_ul = old_value;
8997 u_sync(TRUE);
8998 curbuf->b_p_ul = value;
8999 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009000
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009001#ifdef FEAT_LINEBREAK
9002 /* 'numberwidth' must be positive */
9003 else if (pp == &curwin->w_p_nuw)
9004 {
9005 if (curwin->w_p_nuw < 1)
9006 {
9007 errmsg = e_positive;
9008 curwin->w_p_nuw = 1;
9009 }
9010 if (curwin->w_p_nuw > 10)
9011 {
9012 errmsg = e_invarg;
9013 curwin->w_p_nuw = 10;
9014 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009015 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009016 }
9017#endif
9018
Bram Moolenaar1a384422010-07-14 19:53:30 +02009019 else if (pp == &curbuf->b_p_tw)
9020 {
9021 if (curbuf->b_p_tw < 0)
9022 {
9023 errmsg = e_positive;
9024 curbuf->b_p_tw = 0;
9025 }
9026#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009027 {
9028 win_T *wp;
9029 tabpage_T *tp;
9030
9031 FOR_ALL_TAB_WINDOWS(tp, wp)
9032 check_colorcolumn(wp);
9033 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009034#endif
9035 }
9036
Bram Moolenaar071d4272004-06-13 20:20:40 +00009037 /*
9038 * Check the bounds for numeric options here
9039 */
9040 if (Rows < min_rows() && full_screen)
9041 {
9042 if (errbuf != NULL)
9043 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009044 vim_snprintf((char *)errbuf, errbuflen,
9045 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009046 errmsg = errbuf;
9047 }
9048 Rows = min_rows();
9049 }
9050 if (Columns < MIN_COLUMNS && full_screen)
9051 {
9052 if (errbuf != NULL)
9053 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009054 vim_snprintf((char *)errbuf, errbuflen,
9055 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009056 errmsg = errbuf;
9057 }
9058 Columns = MIN_COLUMNS;
9059 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009060 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009061
Bram Moolenaar071d4272004-06-13 20:20:40 +00009062 /*
9063 * If the screen (shell) height has been changed, assume it is the
9064 * physical screenheight.
9065 */
9066 if (old_Rows != Rows || old_Columns != Columns)
9067 {
9068 /* Changing the screen size is not allowed while updating the screen. */
9069 if (updating_screen)
9070 *pp = old_value;
9071 else if (full_screen
9072#ifdef FEAT_GUI
9073 && !gui.starting
9074#endif
9075 )
9076 set_shellsize((int)Columns, (int)Rows, TRUE);
9077 else
9078 {
9079 /* Postpone the resizing; check the size and cmdline position for
9080 * messages. */
9081 check_shellsize();
9082 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9083 cmdline_row = Rows - p_ch;
9084 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009085 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009086 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009087 }
9088
Bram Moolenaar071d4272004-06-13 20:20:40 +00009089 if (curbuf->b_p_ts <= 0)
9090 {
9091 errmsg = e_positive;
9092 curbuf->b_p_ts = 8;
9093 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009094 if (p_tm < 0)
9095 {
9096 errmsg = e_positive;
9097 p_tm = 0;
9098 }
9099 if ((curwin->w_p_scr <= 0
9100 || (curwin->w_p_scr > curwin->w_height
9101 && curwin->w_height > 0))
9102 && full_screen)
9103 {
9104 if (pp == &(curwin->w_p_scr))
9105 {
9106 if (curwin->w_p_scr != 0)
9107 errmsg = e_scroll;
9108 win_comp_scroll(curwin);
9109 }
9110 /* If 'scroll' became invalid because of a side effect silently adjust
9111 * it. */
9112 else if (curwin->w_p_scr <= 0)
9113 curwin->w_p_scr = 1;
9114 else /* curwin->w_p_scr > curwin->w_height */
9115 curwin->w_p_scr = curwin->w_height;
9116 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009117 if (p_hi < 0)
9118 {
9119 errmsg = e_positive;
9120 p_hi = 0;
9121 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009122 else if (p_hi > 10000)
9123 {
9124 errmsg = e_invarg;
9125 p_hi = 10000;
9126 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009127 if (p_re < 0 || p_re > 2)
9128 {
9129 errmsg = e_invarg;
9130 p_re = 0;
9131 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009132 if (p_report < 0)
9133 {
9134 errmsg = e_positive;
9135 p_report = 1;
9136 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009137 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009138 {
9139 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9140 p_sj = Rows / 2;
9141 else
9142 {
9143 errmsg = e_scroll;
9144 p_sj = 1;
9145 }
9146 }
9147 if (p_so < 0 && full_screen)
9148 {
9149 errmsg = e_scroll;
9150 p_so = 0;
9151 }
9152 if (p_siso < 0 && full_screen)
9153 {
9154 errmsg = e_positive;
9155 p_siso = 0;
9156 }
9157#ifdef FEAT_CMDWIN
9158 if (p_cwh < 1)
9159 {
9160 errmsg = e_positive;
9161 p_cwh = 1;
9162 }
9163#endif
9164 if (p_ut < 0)
9165 {
9166 errmsg = e_positive;
9167 p_ut = 2000;
9168 }
9169 if (p_ss < 0)
9170 {
9171 errmsg = e_positive;
9172 p_ss = 0;
9173 }
9174
9175 /* May set global value for local option. */
9176 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9177 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9178
9179 options[opt_idx].flags |= P_WAS_SET;
9180
Bram Moolenaar53744302015-07-17 17:38:22 +02009181#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
9182 if (!starting && errmsg == NULL)
9183 {
9184 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009185 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9186 vim_snprintf((char *)buf_new, 10, "%ld", value);
9187 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009188 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9189 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9190 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9191 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9192 reset_v_option_vars();
9193 }
9194#endif
9195
Bram Moolenaar071d4272004-06-13 20:20:40 +00009196 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009197 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009198 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009199 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009200 check_redraw(options[opt_idx].flags);
9201
9202 return errmsg;
9203}
9204
9205/*
9206 * Called after an option changed: check if something needs to be redrawn.
9207 */
9208 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009209check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009210{
9211 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009212 int doclear = (flags & P_RCLR) == P_RCLR;
9213 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009214
Bram Moolenaar071d4272004-06-13 20:20:40 +00009215 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9216 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009217
9218 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9219 changed_window_setting();
9220 if (flags & P_RBUF)
9221 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009222 if (flags & P_RWINONLY)
9223 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009224 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009225 redraw_all_later(CLEAR);
9226 else if (all)
9227 redraw_all_later(NOT_VALID);
9228}
9229
9230/*
9231 * Find index for option 'arg'.
9232 * Return -1 if not found.
9233 */
9234 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009235findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009236{
9237 int opt_idx;
9238 char *s, *p;
9239 static short quick_tab[27] = {0, 0}; /* quick access table */
9240 int is_term_opt;
9241
9242 /*
9243 * For first call: Initialize the quick-access table.
9244 * It contains the index for the first option that starts with a certain
9245 * letter. There are 26 letters, plus the first "t_" option.
9246 */
9247 if (quick_tab[1] == 0)
9248 {
9249 p = options[0].fullname;
9250 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9251 {
9252 if (s[0] != p[0])
9253 {
9254 if (s[0] == 't' && s[1] == '_')
9255 quick_tab[26] = opt_idx;
9256 else
9257 quick_tab[CharOrdLow(s[0])] = opt_idx;
9258 }
9259 p = s;
9260 }
9261 }
9262
9263 /*
9264 * Check for name starting with an illegal character.
9265 */
9266#ifdef EBCDIC
9267 if (!islower(arg[0]))
9268#else
9269 if (arg[0] < 'a' || arg[0] > 'z')
9270#endif
9271 return -1;
9272
9273 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9274 if (is_term_opt)
9275 opt_idx = quick_tab[26];
9276 else
9277 opt_idx = quick_tab[CharOrdLow(arg[0])];
9278 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9279 {
9280 if (STRCMP(arg, s) == 0) /* match full name */
9281 break;
9282 }
9283 if (s == NULL && !is_term_opt)
9284 {
9285 opt_idx = quick_tab[CharOrdLow(arg[0])];
9286 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9287 {
9288 s = options[opt_idx].shortname;
9289 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9290 break;
9291 s = NULL;
9292 }
9293 }
9294 if (s == NULL)
9295 opt_idx = -1;
9296 return opt_idx;
9297}
9298
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009299#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009300/*
9301 * Get the value for an option.
9302 *
9303 * Returns:
9304 * Number or Toggle option: 1, *numval gets value.
9305 * String option: 0, *stringval gets allocated string.
9306 * Hidden Number or Toggle option: -1.
9307 * hidden String option: -2.
9308 * unknown option: -3.
9309 */
9310 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009311get_option_value(
9312 char_u *name,
9313 long *numval,
9314 char_u **stringval, /* NULL when only checking existence */
9315 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009316{
9317 int opt_idx;
9318 char_u *varp;
9319
9320 opt_idx = findoption(name);
9321 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009322 {
9323 int key;
9324
9325 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9326 && (key = find_key_option(name)) != 0)
9327 {
9328 char_u key_name[2];
9329 char_u *p;
9330
9331 if (key < 0)
9332 {
9333 key_name[0] = KEY2TERMCAP0(key);
9334 key_name[1] = KEY2TERMCAP1(key);
9335 }
9336 else
9337 {
9338 key_name[0] = KS_KEY;
9339 key_name[1] = (key & 0xff);
9340 }
9341 p = find_termcode(key_name);
9342 if (p != NULL)
9343 {
9344 if (stringval != NULL)
9345 *stringval = vim_strsave(p);
9346 return 0;
9347 }
9348 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009349 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009350 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009351
9352 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9353
9354 if (options[opt_idx].flags & P_STRING)
9355 {
9356 if (varp == NULL) /* hidden option */
9357 return -2;
9358 if (stringval != NULL)
9359 {
9360#ifdef FEAT_CRYPT
9361 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009362 if ((char_u **)varp == &curbuf->b_p_key
9363 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009364 *stringval = vim_strsave((char_u *)"*****");
9365 else
9366#endif
9367 *stringval = vim_strsave(*(char_u **)(varp));
9368 }
9369 return 0;
9370 }
9371
9372 if (varp == NULL) /* hidden option */
9373 return -1;
9374 if (options[opt_idx].flags & P_NUM)
9375 *numval = *(long *)varp;
9376 else
9377 {
9378 /* Special case: 'modified' is b_changed, but we also want to consider
9379 * it set when 'ff' or 'fenc' changed. */
9380 if ((int *)varp == &curbuf->b_changed)
9381 *numval = curbufIsChanged();
9382 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009383 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009384 }
9385 return 1;
9386}
9387#endif
9388
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009389#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009390/*
9391 * Returns the option attributes and its value. Unlike the above function it
9392 * will return either global value or local value of the option depending on
9393 * what was requested, but it will never return global value if it was
9394 * requested to return local one and vice versa. Neither it will return
9395 * buffer-local value if it was requested to return window-local one.
9396 *
9397 * Pretends that option is absent if it is not present in the requested scope
9398 * (i.e. has no global, window-local or buffer-local value depending on
9399 * opt_type). Uses
9400 *
9401 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009402 * 0 hidden or unknown option, also option that does not have requested
9403 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009404 * see SOPT_* in vim.h for other flags
9405 *
9406 * Possible opt_type values: see SREQ_* in vim.h
9407 */
9408 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009409get_option_value_strict(
9410 char_u *name,
9411 long *numval,
9412 char_u **stringval, /* NULL when only obtaining attributes */
9413 int opt_type,
9414 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009415{
9416 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009417 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009418 struct vimoption *p;
9419 int r = 0;
9420
9421 opt_idx = findoption(name);
9422 if (opt_idx < 0)
9423 return 0;
9424
9425 p = &(options[opt_idx]);
9426
9427 /* Hidden option */
9428 if (p->var == NULL)
9429 return 0;
9430
9431 if (p->flags & P_BOOL)
9432 r |= SOPT_BOOL;
9433 else if (p->flags & P_NUM)
9434 r |= SOPT_NUM;
9435 else if (p->flags & P_STRING)
9436 r |= SOPT_STRING;
9437
9438 if (p->indir == PV_NONE)
9439 {
9440 if (opt_type == SREQ_GLOBAL)
9441 r |= SOPT_GLOBAL;
9442 else
9443 return 0; /* Did not request global-only option */
9444 }
9445 else
9446 {
9447 if (p->indir & PV_BOTH)
9448 r |= SOPT_GLOBAL;
9449 else if (opt_type == SREQ_GLOBAL)
9450 return 0; /* Requested global option */
9451
9452 if (p->indir & PV_WIN)
9453 {
9454 if (opt_type == SREQ_BUF)
9455 return 0; /* Did not request window-local option */
9456 else
9457 r |= SOPT_WIN;
9458 }
9459 else if (p->indir & PV_BUF)
9460 {
9461 if (opt_type == SREQ_WIN)
9462 return 0; /* Did not request buffer-local option */
9463 else
9464 r |= SOPT_BUF;
9465 }
9466 }
9467
9468 if (stringval == NULL)
9469 return r;
9470
9471 if (opt_type == SREQ_GLOBAL)
9472 varp = p->var;
9473 else
9474 {
9475 if (opt_type == SREQ_BUF)
9476 {
9477 /* Special case: 'modified' is b_changed, but we also want to
9478 * consider it set when 'ff' or 'fenc' changed. */
9479 if (p->indir == PV_MOD)
9480 {
9481 *numval = bufIsChanged((buf_T *) from);
9482 varp = NULL;
9483 }
9484#ifdef FEAT_CRYPT
9485 else if (p->indir == PV_KEY)
9486 {
9487 /* never return the value of the crypt key */
9488 *stringval = NULL;
9489 varp = NULL;
9490 }
9491#endif
9492 else
9493 {
9494 aco_save_T aco;
9495 aucmd_prepbuf(&aco, (buf_T *) from);
9496 varp = get_varp(p);
9497 aucmd_restbuf(&aco);
9498 }
9499 }
9500 else if (opt_type == SREQ_WIN)
9501 {
9502 win_T *save_curwin;
9503 save_curwin = curwin;
9504 curwin = (win_T *) from;
9505 curbuf = curwin->w_buffer;
9506 varp = get_varp(p);
9507 curwin = save_curwin;
9508 curbuf = curwin->w_buffer;
9509 }
9510 if (varp == p->var)
9511 return (r | SOPT_UNSET);
9512 }
9513
9514 if (varp != NULL)
9515 {
9516 if (p->flags & P_STRING)
9517 *stringval = vim_strsave(*(char_u **)(varp));
9518 else if (p->flags & P_NUM)
9519 *numval = *(long *) varp;
9520 else
9521 *numval = *(int *)varp;
9522 }
9523
9524 return r;
9525}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009526
9527/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009528 * Iterate over options. First argument is a pointer to a pointer to a
9529 * structure inside options[] array, second is option type like in the above
9530 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009531 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009532 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009533 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009534 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009535 * first argument to NULL.
9536 *
9537 * Returns full option name for current option on each call.
9538 */
9539 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009540option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009541{
9542 struct vimoption *ret = NULL;
9543 do
9544 {
9545 if (*option == NULL)
9546 *option = (void *) options;
9547 else if (((struct vimoption *) (*option))->fullname == NULL)
9548 {
9549 *option = NULL;
9550 return NULL;
9551 }
9552 else
9553 *option = (void *) (((struct vimoption *) (*option)) + 1);
9554
9555 ret = ((struct vimoption *) (*option));
9556
9557 /* Hidden option */
9558 if (ret->var == NULL)
9559 {
9560 ret = NULL;
9561 continue;
9562 }
9563
9564 switch (opt_type)
9565 {
9566 case SREQ_GLOBAL:
9567 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9568 ret = NULL;
9569 break;
9570 case SREQ_BUF:
9571 if (!(ret->indir & PV_BUF))
9572 ret = NULL;
9573 break;
9574 case SREQ_WIN:
9575 if (!(ret->indir & PV_WIN))
9576 ret = NULL;
9577 break;
9578 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009579 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009580 return NULL;
9581 }
9582 }
9583 while (ret == NULL);
9584
9585 return (char_u *)ret->fullname;
9586}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009587#endif
9588
Bram Moolenaar071d4272004-06-13 20:20:40 +00009589/*
9590 * Set the value of option "name".
9591 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009592 *
9593 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009594 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009595 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009596set_option_value(
9597 char_u *name,
9598 long number,
9599 char_u *string,
9600 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009601{
9602 int opt_idx;
9603 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009604 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009605
9606 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009607 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009608 {
9609 int key;
9610
9611 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9612 && (key = find_key_option(name)) != 0)
9613 {
9614 char_u key_name[2];
9615
9616 if (key < 0)
9617 {
9618 key_name[0] = KEY2TERMCAP0(key);
9619 key_name[1] = KEY2TERMCAP1(key);
9620 }
9621 else
9622 {
9623 key_name[0] = KS_KEY;
9624 key_name[1] = (key & 0xff);
9625 }
9626 add_termcode(key_name, string, FALSE);
9627 if (full_screen)
9628 ttest(FALSE);
9629 redraw_all_later(CLEAR);
9630 return NULL;
9631 }
9632
Bram Moolenaar071d4272004-06-13 20:20:40 +00009633 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009634 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009635 else
9636 {
9637 flags = options[opt_idx].flags;
9638#ifdef HAVE_SANDBOX
9639 /* Disallow changing some options in the sandbox */
9640 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009641 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009642 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009643 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009644 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009645#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009646 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009647 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009648 else
9649 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009650 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009651 if (varp != NULL) /* hidden option is not changed */
9652 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009653 if (number == 0 && string != NULL)
9654 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009655 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009656
9657 /* Either we are given a string or we are setting option
9658 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009659 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009660 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009661 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009662 {
9663 /* There's another character after zeros or the string
9664 * is empty. In both cases, we are trying to set a
9665 * num option using a string. */
9666 EMSG3(_("E521: Number required: &%s = '%s'"),
9667 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009668 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009669
9670 }
9671 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009672 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009673 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009674 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009675 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009676 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009677 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009678 }
9679 }
9680 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009681 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009682}
9683
9684/*
9685 * Get the terminal code for a terminal option.
9686 * Returns NULL when not found.
9687 */
9688 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009689get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009690{
9691 int opt_idx;
9692 char_u *varp;
9693
9694 if (tname[0] != 't' || tname[1] != '_' ||
9695 tname[2] == NUL || tname[3] == NUL)
9696 return NULL;
9697 if ((opt_idx = findoption(tname)) >= 0)
9698 {
9699 varp = get_varp(&(options[opt_idx]));
9700 if (varp != NULL)
9701 varp = *(char_u **)(varp);
9702 return varp;
9703 }
9704 return find_termcode(tname + 2);
9705}
9706
9707 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009708get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009709{
9710 int i;
9711
9712 i = findoption((char_u *)"hl");
9713 if (i >= 0)
9714 return options[i].def_val[VI_DEFAULT];
9715 return (char_u *)NULL;
9716}
9717
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009718#if defined(FEAT_MBYTE) || defined(PROTO)
9719 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009720get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009721{
9722 int i;
9723
9724 i = findoption((char_u *)"enc");
9725 if (i >= 0)
9726 return options[i].def_val[VI_DEFAULT];
9727 return (char_u *)NULL;
9728}
9729#endif
9730
Bram Moolenaar071d4272004-06-13 20:20:40 +00009731/*
9732 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9733 */
9734 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009735find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009736{
9737 int key;
9738 int modifiers;
9739
9740 /*
9741 * Don't use get_special_key_code() for t_xx, we don't want it to call
9742 * add_termcap_entry().
9743 */
9744 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9745 key = TERMCAP2KEY(arg[2], arg[3]);
9746 else
9747 {
9748 --arg; /* put arg at the '<' */
9749 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009750 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009751 if (modifiers) /* can't handle modifiers here */
9752 key = 0;
9753 }
9754 return key;
9755}
9756
9757/*
9758 * if 'all' == 0: show changed options
9759 * if 'all' == 1: show all normal options
9760 * if 'all' == 2: show all terminal options
9761 */
9762 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009763showoptions(
9764 int all,
9765 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009766{
9767 struct vimoption *p;
9768 int col;
9769 int isterm;
9770 char_u *varp;
9771 struct vimoption **items;
9772 int item_count;
9773 int run;
9774 int row, rows;
9775 int cols;
9776 int i;
9777 int len;
9778
9779#define INC 20
9780#define GAP 3
9781
9782 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9783 PARAM_COUNT));
9784 if (items == NULL)
9785 return;
9786
9787 /* Highlight title */
9788 if (all == 2)
9789 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9790 else if (opt_flags & OPT_GLOBAL)
9791 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9792 else if (opt_flags & OPT_LOCAL)
9793 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9794 else
9795 MSG_PUTS_TITLE(_("\n--- Options ---"));
9796
9797 /*
9798 * do the loop two times:
9799 * 1. display the short items
9800 * 2. display the long items (only strings and numbers)
9801 */
9802 for (run = 1; run <= 2 && !got_int; ++run)
9803 {
9804 /*
9805 * collect the items in items[]
9806 */
9807 item_count = 0;
9808 for (p = &options[0]; p->fullname != NULL; p++)
9809 {
9810 varp = NULL;
9811 isterm = istermoption(p);
9812 if (opt_flags != 0)
9813 {
9814 if (p->indir != PV_NONE && !isterm)
9815 varp = get_varp_scope(p, opt_flags);
9816 }
9817 else
9818 varp = get_varp(p);
9819 if (varp != NULL
9820 && ((all == 2 && isterm)
9821 || (all == 1 && !isterm)
9822 || (all == 0 && !optval_default(p, varp))))
9823 {
9824 if (p->flags & P_BOOL)
9825 len = 1; /* a toggle option fits always */
9826 else
9827 {
9828 option_value2string(p, opt_flags);
9829 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9830 }
9831 if ((len <= INC - GAP && run == 1) ||
9832 (len > INC - GAP && run == 2))
9833 items[item_count++] = p;
9834 }
9835 }
9836
9837 /*
9838 * display the items
9839 */
9840 if (run == 1)
9841 {
9842 cols = (Columns + GAP - 3) / INC;
9843 if (cols == 0)
9844 cols = 1;
9845 rows = (item_count + cols - 1) / cols;
9846 }
9847 else /* run == 2 */
9848 rows = item_count;
9849 for (row = 0; row < rows && !got_int; ++row)
9850 {
9851 msg_putchar('\n'); /* go to next line */
9852 if (got_int) /* 'q' typed in more */
9853 break;
9854 col = 0;
9855 for (i = row; i < item_count; i += rows)
9856 {
9857 msg_col = col; /* make columns */
9858 showoneopt(items[i], opt_flags);
9859 col += INC;
9860 }
9861 out_flush();
9862 ui_breakcheck();
9863 }
9864 }
9865 vim_free(items);
9866}
9867
9868/*
9869 * Return TRUE if option "p" has its default value.
9870 */
9871 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009872optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009873{
9874 int dvi;
9875
9876 if (varp == NULL)
9877 return TRUE; /* hidden option is always at default */
9878 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9879 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009880 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009881 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009882 /* the cast to long is required for Manx C, long_i is
9883 * needed for MSVC */
9884 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009885 /* P_STRING */
9886 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9887}
9888
9889/*
9890 * showoneopt: show the value of one option
9891 * must not be called with a hidden option!
9892 */
9893 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009894showoneopt(
9895 struct vimoption *p,
9896 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009897{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009898 char_u *varp;
9899 int save_silent = silent_mode;
9900
9901 silent_mode = FALSE;
9902 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009903
9904 varp = get_varp_scope(p, opt_flags);
9905
9906 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9907 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9908 ? !curbufIsChanged() : !*(int *)varp))
9909 MSG_PUTS("no");
9910 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9911 MSG_PUTS("--");
9912 else
9913 MSG_PUTS(" ");
9914 MSG_PUTS(p->fullname);
9915 if (!(p->flags & P_BOOL))
9916 {
9917 msg_putchar('=');
9918 /* put value string in NameBuff */
9919 option_value2string(p, opt_flags);
9920 msg_outtrans(NameBuff);
9921 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009922
9923 silent_mode = save_silent;
9924 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009925}
9926
9927/*
9928 * Write modified options as ":set" commands to a file.
9929 *
9930 * There are three values for "opt_flags":
9931 * OPT_GLOBAL: Write global option values and fresh values of
9932 * buffer-local options (used for start of a session
9933 * file).
9934 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9935 * curwin (used for a vimrc file).
9936 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9937 * and local values for window-local options of
9938 * curwin. Local values are also written when at the
9939 * default value, because a modeline or autocommand
9940 * may have set them when doing ":edit file" and the
9941 * user has set them back at the default or fresh
9942 * value.
9943 * When "local_only" is TRUE, don't write fresh
9944 * values, only local values (for ":mkview").
9945 * (fresh value = value used for a new buffer or window for a local option).
9946 *
9947 * Return FAIL on error, OK otherwise.
9948 */
9949 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009950makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009951{
9952 struct vimoption *p;
9953 char_u *varp; /* currently used value */
9954 char_u *varp_fresh; /* local value */
9955 char_u *varp_local = NULL; /* fresh value */
9956 char *cmd;
9957 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009958 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009959
9960 /*
9961 * The options that don't have a default (terminal name, columns, lines)
9962 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009963 * Do the loop over "options[]" twice: once for options with the
9964 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009965 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009966 for (pri = 1; pri >= 0; --pri)
9967 {
9968 for (p = &options[0]; !istermoption(p); p++)
9969 if (!(p->flags & P_NO_MKRC)
9970 && !istermoption(p)
9971 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009972 {
9973 /* skip global option when only doing locals */
9974 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9975 continue;
9976
9977 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9978 * file, they are always buffer-specific. */
9979 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9980 continue;
9981
9982 /* Global values are only written when not at the default value. */
9983 varp = get_varp_scope(p, opt_flags);
9984 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9985 continue;
9986
9987 round = 2;
9988 if (p->indir != PV_NONE)
9989 {
9990 if (p->var == VAR_WIN)
9991 {
9992 /* skip window-local option when only doing globals */
9993 if (!(opt_flags & OPT_LOCAL))
9994 continue;
9995 /* When fresh value of window-local option is not at the
9996 * default, need to write it too. */
9997 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9998 {
9999 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10000 if (!optval_default(p, varp_fresh))
10001 {
10002 round = 1;
10003 varp_local = varp;
10004 varp = varp_fresh;
10005 }
10006 }
10007 }
10008 }
10009
10010 /* Round 1: fresh value for window-local options.
10011 * Round 2: other values */
10012 for ( ; round <= 2; varp = varp_local, ++round)
10013 {
10014 if (round == 1 || (opt_flags & OPT_GLOBAL))
10015 cmd = "set";
10016 else
10017 cmd = "setlocal";
10018
10019 if (p->flags & P_BOOL)
10020 {
10021 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10022 return FAIL;
10023 }
10024 else if (p->flags & P_NUM)
10025 {
10026 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10027 return FAIL;
10028 }
10029 else /* P_STRING */
10030 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010031#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10032 int do_endif = FALSE;
10033
Bram Moolenaar071d4272004-06-13 20:20:40 +000010034 /* Don't set 'syntax' and 'filetype' again if the value is
10035 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010036 if (
10037# if defined(FEAT_SYN_HL)
10038 p->indir == PV_SYN
10039# if defined(FEAT_AUTOCMD)
10040 ||
10041# endif
10042# endif
10043# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010044 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010045# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010046 )
Bram Moolenaar071d4272004-06-13 20:20:40 +000010047 {
10048 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10049 *(char_u **)(varp)) < 0
10050 || put_eol(fd) < 0)
10051 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010052 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010053 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010054#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010055 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10056 (p->flags & P_EXPAND) != 0) == FAIL)
10057 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010058#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10059 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010060 {
10061 if (put_line(fd, "endif") == FAIL)
10062 return FAIL;
10063 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010064#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010065 }
10066 }
10067 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010068 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010069 return OK;
10070}
10071
10072#if defined(FEAT_FOLDING) || defined(PROTO)
10073/*
10074 * Generate set commands for the local fold options only. Used when
10075 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10076 */
10077 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010078makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010079{
10080 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10081# ifdef FEAT_EVAL
10082 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10083 == FAIL
10084# endif
10085 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10086 == FAIL
10087 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10088 == FAIL
10089 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10090 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10091 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10092 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10093 )
10094 return FAIL;
10095
10096 return OK;
10097}
10098#endif
10099
10100 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010101put_setstring(
10102 FILE *fd,
10103 char *cmd,
10104 char *name,
10105 char_u **valuep,
10106 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010107{
10108 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010109 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010110
10111 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10112 return FAIL;
10113 if (*valuep != NULL)
10114 {
10115 /* Output 'pastetoggle' as key names. For other
10116 * options some characters have to be escaped with
10117 * CTRL-V or backslash */
10118 if (valuep == &p_pt)
10119 {
10120 s = *valuep;
10121 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010122 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010123 return FAIL;
10124 }
10125 else if (expand)
10126 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010127 buf = alloc(MAXPATHL);
10128 if (buf == NULL)
10129 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010130 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10131 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010132 {
10133 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010134 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010135 }
10136 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010137 }
10138 else if (put_escstr(fd, *valuep, 2) == FAIL)
10139 return FAIL;
10140 }
10141 if (put_eol(fd) < 0)
10142 return FAIL;
10143 return OK;
10144}
10145
10146 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010147put_setnum(
10148 FILE *fd,
10149 char *cmd,
10150 char *name,
10151 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010152{
10153 long wc;
10154
10155 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10156 return FAIL;
10157 if (wc_use_keyname((char_u *)valuep, &wc))
10158 {
10159 /* print 'wildchar' and 'wildcharm' as a key name */
10160 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10161 return FAIL;
10162 }
10163 else if (fprintf(fd, "%ld", *valuep) < 0)
10164 return FAIL;
10165 if (put_eol(fd) < 0)
10166 return FAIL;
10167 return OK;
10168}
10169
10170 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010171put_setbool(
10172 FILE *fd,
10173 char *cmd,
10174 char *name,
10175 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010176{
Bram Moolenaar893de922007-10-02 18:40:57 +000010177 if (value < 0) /* global/local option using global value */
10178 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010179 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10180 || put_eol(fd) < 0)
10181 return FAIL;
10182 return OK;
10183}
10184
10185/*
10186 * Clear all the terminal options.
10187 * If the option has been allocated, free the memory.
10188 * Terminal options are never hidden or indirect.
10189 */
10190 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010191clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010192{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010193 /*
10194 * Reset a few things before clearing the old options. This may cause
10195 * outputting a few things that the terminal doesn't understand, but the
10196 * screen will be cleared later, so this is OK.
10197 */
10198#ifdef FEAT_MOUSE_TTY
10199 mch_setmouse(FALSE); /* switch mouse off */
10200#endif
10201#ifdef FEAT_TITLE
10202 mch_restore_title(3); /* restore window titles */
10203#endif
10204#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10205 /* When starting the GUI close the display opened for the clipboard.
10206 * After restoring the title, because that will need the display. */
10207 if (gui.starting)
10208 clear_xterm_clip();
10209#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010210 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010211
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010212 free_termoptions();
10213}
10214
10215 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010216free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010217{
10218 struct vimoption *p;
10219
Bram Moolenaar071d4272004-06-13 20:20:40 +000010220 for (p = &options[0]; p->fullname != NULL; p++)
10221 if (istermoption(p))
10222 {
10223 if (p->flags & P_ALLOCED)
10224 free_string_option(*(char_u **)(p->var));
10225 if (p->flags & P_DEF_ALLOCED)
10226 free_string_option(p->def_val[VI_DEFAULT]);
10227 *(char_u **)(p->var) = empty_option;
10228 p->def_val[VI_DEFAULT] = empty_option;
10229 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10230 }
10231 clear_termcodes();
10232}
10233
10234/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010235 * Free the string for one term option, if it was allocated.
10236 * Set the string to empty_option and clear allocated flag.
10237 * "var" points to the option value.
10238 */
10239 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010240free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010241{
10242 struct vimoption *p;
10243
10244 for (p = &options[0]; p->fullname != NULL; p++)
10245 if (p->var == var)
10246 {
10247 if (p->flags & P_ALLOCED)
10248 free_string_option(*(char_u **)(p->var));
10249 *(char_u **)(p->var) = empty_option;
10250 p->flags &= ~P_ALLOCED;
10251 break;
10252 }
10253}
10254
10255/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010256 * Set the terminal option defaults to the current value.
10257 * Used after setting the terminal name.
10258 */
10259 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010260set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010261{
10262 struct vimoption *p;
10263
10264 for (p = &options[0]; p->fullname != NULL; p++)
10265 {
10266 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10267 {
10268 if (p->flags & P_DEF_ALLOCED)
10269 {
10270 free_string_option(p->def_val[VI_DEFAULT]);
10271 p->flags &= ~P_DEF_ALLOCED;
10272 }
10273 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10274 if (p->flags & P_ALLOCED)
10275 {
10276 p->flags |= P_DEF_ALLOCED;
10277 p->flags &= ~P_ALLOCED; /* don't free the value now */
10278 }
10279 }
10280 }
10281}
10282
10283/*
10284 * return TRUE if 'p' starts with 't_'
10285 */
10286 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010287istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010288{
10289 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10290}
10291
10292/*
10293 * Compute columns for ruler and shown command. 'sc_col' is also used to
10294 * decide what the maximum length of a message on the status line can be.
10295 * If there is a status line for the last window, 'sc_col' is independent
10296 * of 'ru_col'.
10297 */
10298
10299#define COL_RULER 17 /* columns needed by standard ruler */
10300
10301 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010302comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010303{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010304#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010305 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010306
10307 sc_col = 0;
10308 ru_col = 0;
10309 if (p_ru)
10310 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010311# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010312 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010313# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010314 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010315# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010316 /* no last status line, adjust sc_col */
10317 if (!last_has_status)
10318 sc_col = ru_col;
10319 }
10320 if (p_sc)
10321 {
10322 sc_col += SHOWCMD_COLS;
10323 if (!p_ru || last_has_status) /* no need for separating space */
10324 ++sc_col;
10325 }
10326 sc_col = Columns - sc_col;
10327 ru_col = Columns - ru_col;
10328 if (sc_col <= 0) /* screen too narrow, will become a mess */
10329 sc_col = 1;
10330 if (ru_col <= 0)
10331 ru_col = 1;
10332#else
10333 sc_col = Columns;
10334 ru_col = Columns;
10335#endif
10336}
10337
10338/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010339 * Unset local option value, similar to ":set opt<".
10340 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010341 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010342unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010343{
10344 struct vimoption *p;
10345 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010346 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010347
10348 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010349 if (opt_idx < 0)
10350 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010351 p = &(options[opt_idx]);
10352
10353 switch ((int)p->indir)
10354 {
10355 /* global option with local value: use local value if it's been set */
10356 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010357 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010358 break;
10359 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010360 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010361 break;
10362 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010363 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010364 break;
10365 case PV_AR:
10366 buf->b_p_ar = -1;
10367 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010368 case PV_BKC:
10369 clear_string_option(&buf->b_p_bkc);
10370 buf->b_bkc_flags = 0;
10371 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010372 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010373 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010374 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010375 case PV_TC:
10376 clear_string_option(&buf->b_p_tc);
10377 buf->b_tc_flags = 0;
10378 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010379#ifdef FEAT_FIND_ID
10380 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010381 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010382 break;
10383 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010384 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010385 break;
10386#endif
10387#ifdef FEAT_INS_EXPAND
10388 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010389 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010390 break;
10391 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010392 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010393 break;
10394#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010395 case PV_FP:
10396 clear_string_option(&buf->b_p_fp);
10397 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010398#ifdef FEAT_QUICKFIX
10399 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010400 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010401 break;
10402 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010403 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010404 break;
10405 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010406 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010407 break;
10408#endif
10409#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10410 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010411 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010412 break;
10413#endif
10414#if defined(FEAT_CRYPT)
10415 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010416 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010417 break;
10418#endif
10419#ifdef FEAT_STL_OPT
10420 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010421 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010422 break;
10423#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010424 case PV_UL:
10425 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10426 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010427#ifdef FEAT_LISP
10428 case PV_LW:
10429 clear_string_option(&buf->b_p_lw);
10430 break;
10431#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010432#ifdef FEAT_MBYTE
10433 case PV_MENC:
10434 clear_string_option(&buf->b_p_menc);
10435 break;
10436#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010437 }
10438}
10439
10440/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010441 * Get pointer to option variable, depending on local or global scope.
10442 */
10443 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010444get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010445{
10446 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10447 {
10448 if (p->var == VAR_WIN)
10449 return (char_u *)GLOBAL_WO(get_varp(p));
10450 return p->var;
10451 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010452 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010453 {
10454 switch ((int)p->indir)
10455 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010456 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010457#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010458 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10459 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10460 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010461#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010462 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10463 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10464 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010465 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010466 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010467 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010468#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010469 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10470 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010471#endif
10472#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010473 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10474 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010475#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010476#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10477 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10478#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010479#if defined(FEAT_CRYPT)
10480 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10481#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010482#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010483 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010484#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010485 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010486#ifdef FEAT_LISP
10487 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10488#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010489 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010490#ifdef FEAT_MBYTE
10491 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10492#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010493 }
10494 return NULL; /* "cannot happen" */
10495 }
10496 return get_varp(p);
10497}
10498
10499/*
10500 * Get pointer to option variable.
10501 */
10502 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010503get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010504{
10505 /* hidden option, always return NULL */
10506 if (p->var == NULL)
10507 return NULL;
10508
10509 switch ((int)p->indir)
10510 {
10511 case PV_NONE: return p->var;
10512
10513 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010514 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010515 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010516 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010517 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010518 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010519 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010520 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010521 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010522 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010523 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010524 case PV_TC: return *curbuf->b_p_tc != NUL
10525 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010526 case PV_BKC: return *curbuf->b_p_bkc != NUL
10527 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010528#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010529 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010530 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010531 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010532 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10533#endif
10534#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010535 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010536 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010537 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010538 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10539#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010540 case PV_FP: return *curbuf->b_p_fp != NUL
10541 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010542#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010543 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010544 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010545 case PV_GP: return *curbuf->b_p_gp != NUL
10546 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10547 case PV_MP: return *curbuf->b_p_mp != NUL
10548 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010549#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010550#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10551 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10552 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10553#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010554#if defined(FEAT_CRYPT)
10555 case PV_CM: return *curbuf->b_p_cm != NUL
10556 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10557#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010558#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010559 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010560 ? (char_u *)&(curwin->w_p_stl) : p->var;
10561#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010562 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10563 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010564#ifdef FEAT_LISP
10565 case PV_LW: return *curbuf->b_p_lw != NUL
10566 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10567#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010568#ifdef FEAT_MBYTE
10569 case PV_MENC: return *curbuf->b_p_menc != NUL
10570 ? (char_u *)&(curbuf->b_p_menc) : p->var;
10571#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010572
10573#ifdef FEAT_ARABIC
10574 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10575#endif
10576 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010577#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010578 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10579#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010580#ifdef FEAT_SYN_HL
10581 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10582 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010583 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010584#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010585#ifdef FEAT_DIFF
10586 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10587#endif
10588#ifdef FEAT_FOLDING
10589 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10590 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10591 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10592 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10593 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10594 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10595 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10596# ifdef FEAT_EVAL
10597 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10598 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10599# endif
10600 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10601#endif
10602 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010603 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010604#ifdef FEAT_LINEBREAK
10605 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10606#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010607 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010608 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020010609#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010610 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10611#endif
10612#ifdef FEAT_RIGHTLEFT
10613 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10614 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10615#endif
10616 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10617 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10618#ifdef FEAT_LINEBREAK
10619 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010620 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10621 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010622#endif
10623#ifdef FEAT_SCROLLBIND
10624 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10625#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010626#ifdef FEAT_CURSORBIND
10627 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10628#endif
10629#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010630 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10631 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10632#endif
10633#ifdef FEAT_TERMINAL
Bram Moolenaar1b0675c2017-07-15 14:04:01 +020010634 case PV_TK: return (char_u *)&(curwin->w_p_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010635 case PV_TMS: return (char_u *)&(curwin->w_p_tms);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010636#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010637
10638 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10639 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10640#ifdef FEAT_MBYTE
10641 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10642#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010643 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10644 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010645 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10646 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10647#ifdef FEAT_CINDENT
10648 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10649 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10650 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10651#endif
10652#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10653 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10654#endif
10655#ifdef FEAT_COMMENTS
10656 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10657#endif
10658#ifdef FEAT_FOLDING
10659 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10660#endif
10661#ifdef FEAT_INS_EXPAND
10662 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10663#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010664#ifdef FEAT_COMPL_FUNC
10665 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010666 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010667#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010668 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010669 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010670 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10671#ifdef FEAT_MBYTE
10672 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10673#endif
10674 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10675#ifdef FEAT_AUTOCMD
10676 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10677#endif
10678 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010679 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010680 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10681 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10682 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10683 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10684#ifdef FEAT_FIND_ID
10685# ifdef FEAT_EVAL
10686 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10687# endif
10688#endif
10689#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10690 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10691 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10692#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010693#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010694 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10695#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010696#ifdef FEAT_CRYPT
10697 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10698#endif
10699#ifdef FEAT_LISP
10700 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10701#endif
10702 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10703 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10704 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10705 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10706 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010707 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010708#ifdef FEAT_TEXTOBJ
10709 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10710#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010711 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10712#ifdef FEAT_SMARTINDENT
10713 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10714#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010715 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010716 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10717#ifdef FEAT_SEARCHPATH
10718 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10719#endif
10720 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10721#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010722 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010723 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10724#endif
10725#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010726 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10727 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10728 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010729#endif
10730 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10731 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10732 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10733 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010734#ifdef FEAT_PERSISTENT_UNDO
10735 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10736#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010737 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10738#ifdef FEAT_KEYMAP
10739 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10740#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010741#ifdef FEAT_SIGNS
10742 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10743#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010744 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010745 }
10746 /* always return a valid pointer to avoid a crash! */
10747 return (char_u *)&(curbuf->b_p_wm);
10748}
10749
10750/*
10751 * Get the value of 'equalprg', either the buffer-local one or the global one.
10752 */
10753 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010754get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010755{
10756 if (*curbuf->b_p_ep == NUL)
10757 return p_ep;
10758 return curbuf->b_p_ep;
10759}
10760
Bram Moolenaar071d4272004-06-13 20:20:40 +000010761/*
10762 * Copy options from one window to another.
10763 * Used when splitting a window.
10764 */
10765 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010766win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010767{
10768 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10769 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10770# ifdef FEAT_RIGHTLEFT
10771# ifdef FEAT_FKMAP
10772 /* Is this right? */
10773 wp_to->w_farsi = wp_from->w_farsi;
10774# endif
10775# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010776#if defined(FEAT_LINEBREAK)
10777 briopt_check(wp_to);
10778#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010779}
Bram Moolenaar071d4272004-06-13 20:20:40 +000010780
10781/*
10782 * Copy the options from one winopt_T to another.
10783 * Doesn't free the old option values in "to", use clear_winopt() for that.
10784 * The 'scroll' option is not copied, because it depends on the window height.
10785 * The 'previewwindow' option is reset, there can be only one preview window.
10786 */
10787 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010788copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010789{
10790#ifdef FEAT_ARABIC
10791 to->wo_arab = from->wo_arab;
10792#endif
10793 to->wo_list = from->wo_list;
10794 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010795 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010796#ifdef FEAT_LINEBREAK
10797 to->wo_nuw = from->wo_nuw;
10798#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010799#ifdef FEAT_RIGHTLEFT
10800 to->wo_rl = from->wo_rl;
10801 to->wo_rlc = vim_strsave(from->wo_rlc);
10802#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010803#ifdef FEAT_STL_OPT
10804 to->wo_stl = vim_strsave(from->wo_stl);
10805#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010806 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010807#ifdef FEAT_DIFF
10808 to->wo_wrap_save = from->wo_wrap_save;
10809#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010810#ifdef FEAT_LINEBREAK
10811 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010812 to->wo_bri = from->wo_bri;
10813 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010814#endif
10815#ifdef FEAT_SCROLLBIND
10816 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010817 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010818#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010819#ifdef FEAT_CURSORBIND
10820 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010821 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010822#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010823#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010824 to->wo_spell = from->wo_spell;
10825#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010826#ifdef FEAT_SYN_HL
10827 to->wo_cuc = from->wo_cuc;
10828 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010829 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010830#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010831#ifdef FEAT_DIFF
10832 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010833 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010834#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010835#ifdef FEAT_CONCEAL
10836 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010837 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010838#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010839#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010840 to->wo_tk = vim_strsave(from->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010841 to->wo_tms = vim_strsave(from->wo_tms);
10842#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010843#ifdef FEAT_FOLDING
10844 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010845 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010846 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010847 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010848 to->wo_fdi = vim_strsave(from->wo_fdi);
10849 to->wo_fml = from->wo_fml;
10850 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010851 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010852 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010853 to->wo_fdm_save = from->wo_diff_saved
10854 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010855 to->wo_fdn = from->wo_fdn;
10856# ifdef FEAT_EVAL
10857 to->wo_fde = vim_strsave(from->wo_fde);
10858 to->wo_fdt = vim_strsave(from->wo_fdt);
10859# endif
10860 to->wo_fmr = vim_strsave(from->wo_fmr);
10861#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010862#ifdef FEAT_SIGNS
10863 to->wo_scl = vim_strsave(from->wo_scl);
10864#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010865 check_winopt(to); /* don't want NULL pointers */
10866}
10867
10868/*
10869 * Check string options in a window for a NULL value.
10870 */
10871 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010872check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010873{
10874 check_winopt(&win->w_onebuf_opt);
10875 check_winopt(&win->w_allbuf_opt);
10876}
10877
10878/*
10879 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10880 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010881 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010882check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010883{
10884#ifdef FEAT_FOLDING
10885 check_string_option(&wop->wo_fdi);
10886 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010887 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010888# ifdef FEAT_EVAL
10889 check_string_option(&wop->wo_fde);
10890 check_string_option(&wop->wo_fdt);
10891# endif
10892 check_string_option(&wop->wo_fmr);
10893#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010894#ifdef FEAT_SIGNS
10895 check_string_option(&wop->wo_scl);
10896#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010897#ifdef FEAT_RIGHTLEFT
10898 check_string_option(&wop->wo_rlc);
10899#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010900#ifdef FEAT_STL_OPT
10901 check_string_option(&wop->wo_stl);
10902#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010903#ifdef FEAT_SYN_HL
10904 check_string_option(&wop->wo_cc);
10905#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010906#ifdef FEAT_CONCEAL
10907 check_string_option(&wop->wo_cocu);
10908#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010909#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010910 check_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010911 check_string_option(&wop->wo_tms);
10912#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010913#ifdef FEAT_LINEBREAK
10914 check_string_option(&wop->wo_briopt);
10915#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010916}
10917
10918/*
10919 * Free the allocated memory inside a winopt_T.
10920 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010921 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010922clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010923{
10924#ifdef FEAT_FOLDING
10925 clear_string_option(&wop->wo_fdi);
10926 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010927 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010928# ifdef FEAT_EVAL
10929 clear_string_option(&wop->wo_fde);
10930 clear_string_option(&wop->wo_fdt);
10931# endif
10932 clear_string_option(&wop->wo_fmr);
10933#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010934#ifdef FEAT_SIGNS
10935 clear_string_option(&wop->wo_scl);
10936#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010937#ifdef FEAT_LINEBREAK
10938 clear_string_option(&wop->wo_briopt);
10939#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010940#ifdef FEAT_RIGHTLEFT
10941 clear_string_option(&wop->wo_rlc);
10942#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010943#ifdef FEAT_STL_OPT
10944 clear_string_option(&wop->wo_stl);
10945#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010946#ifdef FEAT_SYN_HL
10947 clear_string_option(&wop->wo_cc);
10948#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010949#ifdef FEAT_CONCEAL
10950 clear_string_option(&wop->wo_cocu);
10951#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010952#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010953 clear_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010954 clear_string_option(&wop->wo_tms);
10955#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010956}
10957
10958/*
10959 * Copy global option values to local options for one buffer.
10960 * Used when creating a new buffer and sometimes when entering a buffer.
10961 * flags:
10962 * BCO_ENTER We will enter the buf buffer.
10963 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10964 * appropriate.
10965 * BCO_NOHELP Don't copy the values to a help buffer.
10966 */
10967 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010968buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010969{
10970 int should_copy = TRUE;
10971 char_u *save_p_isk = NULL; /* init for GCC */
10972 int dont_do_help;
10973 int did_isk = FALSE;
10974
10975 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010976 * Skip this when the option defaults have not been set yet. Happens when
10977 * main() allocates the first buffer.
10978 */
10979 if (p_cpo != NULL)
10980 {
10981 /*
10982 * Always copy when entering and 'cpo' contains 'S'.
10983 * Don't copy when already initialized.
10984 * Don't copy when 'cpo' contains 's' and not entering.
10985 * 'S' BCO_ENTER initialized 's' should_copy
10986 * yes yes X X TRUE
10987 * yes no yes X FALSE
10988 * no X yes X FALSE
10989 * X no no yes FALSE
10990 * X no no no TRUE
10991 * no yes no X TRUE
10992 */
10993 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10994 && (buf->b_p_initialized
10995 || (!(flags & BCO_ENTER)
10996 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10997 should_copy = FALSE;
10998
10999 if (should_copy || (flags & BCO_ALWAYS))
11000 {
11001 /* Don't copy the options specific to a help buffer when
11002 * BCO_NOHELP is given or the options were initialized already
11003 * (jumping back to a help file with CTRL-T or CTRL-O) */
11004 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11005 || buf->b_p_initialized;
11006 if (dont_do_help) /* don't free b_p_isk */
11007 {
11008 save_p_isk = buf->b_p_isk;
11009 buf->b_p_isk = NULL;
11010 }
11011 /*
11012 * Always free the allocated strings.
11013 * If not already initialized, set 'readonly' and copy 'fileformat'.
11014 */
11015 if (!buf->b_p_initialized)
11016 {
11017 free_buf_options(buf, TRUE);
11018 buf->b_p_ro = FALSE; /* don't copy readonly */
11019 buf->b_p_tx = p_tx;
11020#ifdef FEAT_MBYTE
11021 buf->b_p_fenc = vim_strsave(p_fenc);
11022#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011023 switch (*p_ffs)
11024 {
11025 case 'm':
11026 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11027 case 'd':
11028 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11029 case 'u':
11030 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11031 default:
11032 buf->b_p_ff = vim_strsave(p_ff);
11033 }
11034 if (buf->b_p_ff != NULL)
11035 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011036 buf->b_p_bh = empty_option;
11037 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011038 }
11039 else
11040 free_buf_options(buf, FALSE);
11041
11042 buf->b_p_ai = p_ai;
11043 buf->b_p_ai_nopaste = p_ai_nopaste;
11044 buf->b_p_sw = p_sw;
11045 buf->b_p_tw = p_tw;
11046 buf->b_p_tw_nopaste = p_tw_nopaste;
11047 buf->b_p_tw_nobin = p_tw_nobin;
11048 buf->b_p_wm = p_wm;
11049 buf->b_p_wm_nopaste = p_wm_nopaste;
11050 buf->b_p_wm_nobin = p_wm_nobin;
11051 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011052#ifdef FEAT_MBYTE
11053 buf->b_p_bomb = p_bomb;
11054#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020011055 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011056 buf->b_p_et = p_et;
11057 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011058 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011059 buf->b_p_ml = p_ml;
11060 buf->b_p_ml_nobin = p_ml_nobin;
11061 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011062 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011063#ifdef FEAT_INS_EXPAND
11064 buf->b_p_cpt = vim_strsave(p_cpt);
11065#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011066#ifdef FEAT_COMPL_FUNC
11067 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011068 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011069#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011070 buf->b_p_sts = p_sts;
11071 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011072 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011073#ifdef FEAT_COMMENTS
11074 buf->b_p_com = vim_strsave(p_com);
11075#endif
11076#ifdef FEAT_FOLDING
11077 buf->b_p_cms = vim_strsave(p_cms);
11078#endif
11079 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011080 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011081 buf->b_p_nf = vim_strsave(p_nf);
11082 buf->b_p_mps = vim_strsave(p_mps);
11083#ifdef FEAT_SMARTINDENT
11084 buf->b_p_si = p_si;
11085#endif
11086 buf->b_p_ci = p_ci;
11087#ifdef FEAT_CINDENT
11088 buf->b_p_cin = p_cin;
11089 buf->b_p_cink = vim_strsave(p_cink);
11090 buf->b_p_cino = vim_strsave(p_cino);
11091#endif
11092#ifdef FEAT_AUTOCMD
11093 /* Don't copy 'filetype', it must be detected */
11094 buf->b_p_ft = empty_option;
11095#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011096 buf->b_p_pi = p_pi;
11097#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11098 buf->b_p_cinw = vim_strsave(p_cinw);
11099#endif
11100#ifdef FEAT_LISP
11101 buf->b_p_lisp = p_lisp;
11102#endif
11103#ifdef FEAT_SYN_HL
11104 /* Don't copy 'syntax', it must be set */
11105 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011106 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011107 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011108#endif
11109#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011110 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011111 (void)compile_cap_prog(&buf->b_s);
11112 buf->b_s.b_p_spf = vim_strsave(p_spf);
11113 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011114#endif
11115#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11116 buf->b_p_inde = vim_strsave(p_inde);
11117 buf->b_p_indk = vim_strsave(p_indk);
11118#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011119 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011120#if defined(FEAT_EVAL)
11121 buf->b_p_fex = vim_strsave(p_fex);
11122#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011123#ifdef FEAT_CRYPT
11124 buf->b_p_key = vim_strsave(p_key);
11125#endif
11126#ifdef FEAT_SEARCHPATH
11127 buf->b_p_sua = vim_strsave(p_sua);
11128#endif
11129#ifdef FEAT_KEYMAP
11130 buf->b_p_keymap = vim_strsave(p_keymap);
11131 buf->b_kmap_state |= KEYMAP_INIT;
11132#endif
11133 /* This isn't really an option, but copying the langmap and IME
11134 * state from the current buffer is better than resetting it. */
11135 buf->b_p_iminsert = p_iminsert;
11136 buf->b_p_imsearch = p_imsearch;
11137
11138 /* options that are normally global but also have a local value
11139 * are not copied, start using the global value */
11140 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011141 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011142 buf->b_p_bkc = empty_option;
11143 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011144#ifdef FEAT_QUICKFIX
11145 buf->b_p_gp = empty_option;
11146 buf->b_p_mp = empty_option;
11147 buf->b_p_efm = empty_option;
11148#endif
11149 buf->b_p_ep = empty_option;
11150 buf->b_p_kp = empty_option;
11151 buf->b_p_path = empty_option;
11152 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011153 buf->b_p_tc = empty_option;
11154 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011155#ifdef FEAT_FIND_ID
11156 buf->b_p_def = empty_option;
11157 buf->b_p_inc = empty_option;
11158# ifdef FEAT_EVAL
11159 buf->b_p_inex = vim_strsave(p_inex);
11160# endif
11161#endif
11162#ifdef FEAT_INS_EXPAND
11163 buf->b_p_dict = empty_option;
11164 buf->b_p_tsr = empty_option;
11165#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011166#ifdef FEAT_TEXTOBJ
11167 buf->b_p_qe = vim_strsave(p_qe);
11168#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011169#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11170 buf->b_p_bexpr = empty_option;
11171#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011172#if defined(FEAT_CRYPT)
11173 buf->b_p_cm = empty_option;
11174#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011175#ifdef FEAT_PERSISTENT_UNDO
11176 buf->b_p_udf = p_udf;
11177#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011178#ifdef FEAT_LISP
11179 buf->b_p_lw = empty_option;
11180#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011181#ifdef FEAT_MBYTE
11182 buf->b_p_menc = empty_option;
11183#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011184
11185 /*
11186 * Don't copy the options set by ex_help(), use the saved values,
11187 * when going from a help buffer to a non-help buffer.
11188 * Don't touch these at all when BCO_NOHELP is used and going from
11189 * or to a help buffer.
11190 */
11191 if (dont_do_help)
11192 buf->b_p_isk = save_p_isk;
11193 else
11194 {
11195 buf->b_p_isk = vim_strsave(p_isk);
11196 did_isk = TRUE;
11197 buf->b_p_ts = p_ts;
11198 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011199 if (buf->b_p_bt[0] == 'h')
11200 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011201 buf->b_p_ma = p_ma;
11202 }
11203 }
11204
11205 /*
11206 * When the options should be copied (ignoring BCO_ALWAYS), set the
11207 * flag that indicates that the options have been initialized.
11208 */
11209 if (should_copy)
11210 buf->b_p_initialized = TRUE;
11211 }
11212
11213 check_buf_options(buf); /* make sure we don't have NULLs */
11214 if (did_isk)
11215 (void)buf_init_chartab(buf, FALSE);
11216}
11217
11218/*
11219 * Reset the 'modifiable' option and its default value.
11220 */
11221 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011222reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011223{
11224 int opt_idx;
11225
11226 curbuf->b_p_ma = FALSE;
11227 p_ma = FALSE;
11228 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011229 if (opt_idx >= 0)
11230 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011231}
11232
11233/*
11234 * Set the global value for 'iminsert' to the local value.
11235 */
11236 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011237set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011238{
11239 p_iminsert = curbuf->b_p_iminsert;
11240}
11241
11242/*
11243 * Set the global value for 'imsearch' to the local value.
11244 */
11245 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011246set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011247{
11248 p_imsearch = curbuf->b_p_imsearch;
11249}
11250
11251#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11252static int expand_option_idx = -1;
11253static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11254static int expand_option_flags = 0;
11255
11256 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011257set_context_in_set_cmd(
11258 expand_T *xp,
11259 char_u *arg,
11260 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011261{
11262 int nextchar;
11263 long_u flags = 0; /* init for GCC */
11264 int opt_idx = 0; /* init for GCC */
11265 char_u *p;
11266 char_u *s;
11267 int is_term_option = FALSE;
11268 int key;
11269
11270 expand_option_flags = opt_flags;
11271
11272 xp->xp_context = EXPAND_SETTINGS;
11273 if (*arg == NUL)
11274 {
11275 xp->xp_pattern = arg;
11276 return;
11277 }
11278 p = arg + STRLEN(arg) - 1;
11279 if (*p == ' ' && *(p - 1) != '\\')
11280 {
11281 xp->xp_pattern = p + 1;
11282 return;
11283 }
11284 while (p > arg)
11285 {
11286 s = p;
11287 /* count number of backslashes before ' ' or ',' */
11288 if (*p == ' ' || *p == ',')
11289 {
11290 while (s > arg && *(s - 1) == '\\')
11291 --s;
11292 }
11293 /* break at a space with an even number of backslashes */
11294 if (*p == ' ' && ((p - s) & 1) == 0)
11295 {
11296 ++p;
11297 break;
11298 }
11299 --p;
11300 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011301 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011302 {
11303 xp->xp_context = EXPAND_BOOL_SETTINGS;
11304 p += 2;
11305 }
11306 if (STRNCMP(p, "inv", 3) == 0)
11307 {
11308 xp->xp_context = EXPAND_BOOL_SETTINGS;
11309 p += 3;
11310 }
11311 xp->xp_pattern = arg = p;
11312 if (*arg == '<')
11313 {
11314 while (*p != '>')
11315 if (*p++ == NUL) /* expand terminal option name */
11316 return;
11317 key = get_special_key_code(arg + 1);
11318 if (key == 0) /* unknown name */
11319 {
11320 xp->xp_context = EXPAND_NOTHING;
11321 return;
11322 }
11323 nextchar = *++p;
11324 is_term_option = TRUE;
11325 expand_option_name[2] = KEY2TERMCAP0(key);
11326 expand_option_name[3] = KEY2TERMCAP1(key);
11327 }
11328 else
11329 {
11330 if (p[0] == 't' && p[1] == '_')
11331 {
11332 p += 2;
11333 if (*p != NUL)
11334 ++p;
11335 if (*p == NUL)
11336 return; /* expand option name */
11337 nextchar = *++p;
11338 is_term_option = TRUE;
11339 expand_option_name[2] = p[-2];
11340 expand_option_name[3] = p[-1];
11341 }
11342 else
11343 {
11344 /* Allow * wildcard */
11345 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11346 p++;
11347 if (*p == NUL)
11348 return;
11349 nextchar = *p;
11350 *p = NUL;
11351 opt_idx = findoption(arg);
11352 *p = nextchar;
11353 if (opt_idx == -1 || options[opt_idx].var == NULL)
11354 {
11355 xp->xp_context = EXPAND_NOTHING;
11356 return;
11357 }
11358 flags = options[opt_idx].flags;
11359 if (flags & P_BOOL)
11360 {
11361 xp->xp_context = EXPAND_NOTHING;
11362 return;
11363 }
11364 }
11365 }
11366 /* handle "-=" and "+=" */
11367 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11368 {
11369 ++p;
11370 nextchar = '=';
11371 }
11372 if ((nextchar != '=' && nextchar != ':')
11373 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11374 {
11375 xp->xp_context = EXPAND_UNSUCCESSFUL;
11376 return;
11377 }
11378 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11379 {
11380 xp->xp_context = EXPAND_OLD_SETTING;
11381 if (is_term_option)
11382 expand_option_idx = -1;
11383 else
11384 expand_option_idx = opt_idx;
11385 xp->xp_pattern = p + 1;
11386 return;
11387 }
11388 xp->xp_context = EXPAND_NOTHING;
11389 if (is_term_option || (flags & P_NUM))
11390 return;
11391
11392 xp->xp_pattern = p + 1;
11393
11394 if (flags & P_EXPAND)
11395 {
11396 p = options[opt_idx].var;
11397 if (p == (char_u *)&p_bdir
11398 || p == (char_u *)&p_dir
11399 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011400 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011401 || p == (char_u *)&p_rtp
11402#ifdef FEAT_SEARCHPATH
11403 || p == (char_u *)&p_cdpath
11404#endif
11405#ifdef FEAT_SESSION
11406 || p == (char_u *)&p_vdir
11407#endif
11408 )
11409 {
11410 xp->xp_context = EXPAND_DIRECTORIES;
11411 if (p == (char_u *)&p_path
11412#ifdef FEAT_SEARCHPATH
11413 || p == (char_u *)&p_cdpath
11414#endif
11415 )
11416 xp->xp_backslash = XP_BS_THREE;
11417 else
11418 xp->xp_backslash = XP_BS_ONE;
11419 }
11420 else
11421 {
11422 xp->xp_context = EXPAND_FILES;
11423 /* for 'tags' need three backslashes for a space */
11424 if (p == (char_u *)&p_tags)
11425 xp->xp_backslash = XP_BS_THREE;
11426 else
11427 xp->xp_backslash = XP_BS_ONE;
11428 }
11429 }
11430
11431 /* For an option that is a list of file names, find the start of the
11432 * last file name. */
11433 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11434 {
11435 /* count number of backslashes before ' ' or ',' */
11436 if (*p == ' ' || *p == ',')
11437 {
11438 s = p;
11439 while (s > xp->xp_pattern && *(s - 1) == '\\')
11440 --s;
11441 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11442 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11443 {
11444 xp->xp_pattern = p + 1;
11445 break;
11446 }
11447 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011448
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011449#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011450 /* for 'spellsuggest' start at "file:" */
11451 if (options[opt_idx].var == (char_u *)&p_sps
11452 && STRNCMP(p, "file:", 5) == 0)
11453 {
11454 xp->xp_pattern = p + 5;
11455 break;
11456 }
11457#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011458 }
11459
11460 return;
11461}
11462
11463 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011464ExpandSettings(
11465 expand_T *xp,
11466 regmatch_T *regmatch,
11467 int *num_file,
11468 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011469{
11470 int num_normal = 0; /* Nr of matching non-term-code settings */
11471 int num_term = 0; /* Nr of matching terminal code settings */
11472 int opt_idx;
11473 int match;
11474 int count = 0;
11475 char_u *str;
11476 int loop;
11477 int is_term_opt;
11478 char_u name_buf[MAX_KEY_NAME_LEN];
11479 static char *(names[]) = {"all", "termcap"};
11480 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11481
11482 /* do this loop twice:
11483 * loop == 0: count the number of matching options
11484 * loop == 1: copy the matching options into allocated memory
11485 */
11486 for (loop = 0; loop <= 1; ++loop)
11487 {
11488 regmatch->rm_ic = ic;
11489 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11490 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011491 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11492 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011493 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11494 {
11495 if (loop == 0)
11496 num_normal++;
11497 else
11498 (*file)[count++] = vim_strsave((char_u *)names[match]);
11499 }
11500 }
11501 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11502 opt_idx++)
11503 {
11504 if (options[opt_idx].var == NULL)
11505 continue;
11506 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11507 && !(options[opt_idx].flags & P_BOOL))
11508 continue;
11509 is_term_opt = istermoption(&options[opt_idx]);
11510 if (is_term_opt && num_normal > 0)
11511 continue;
11512 match = FALSE;
11513 if (vim_regexec(regmatch, str, (colnr_T)0)
11514 || (options[opt_idx].shortname != NULL
11515 && vim_regexec(regmatch,
11516 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11517 match = TRUE;
11518 else if (is_term_opt)
11519 {
11520 name_buf[0] = '<';
11521 name_buf[1] = 't';
11522 name_buf[2] = '_';
11523 name_buf[3] = str[2];
11524 name_buf[4] = str[3];
11525 name_buf[5] = '>';
11526 name_buf[6] = NUL;
11527 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11528 {
11529 match = TRUE;
11530 str = name_buf;
11531 }
11532 }
11533 if (match)
11534 {
11535 if (loop == 0)
11536 {
11537 if (is_term_opt)
11538 num_term++;
11539 else
11540 num_normal++;
11541 }
11542 else
11543 (*file)[count++] = vim_strsave(str);
11544 }
11545 }
11546 /*
11547 * Check terminal key codes, these are not in the option table
11548 */
11549 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11550 {
11551 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11552 {
11553 if (!isprint(str[0]) || !isprint(str[1]))
11554 continue;
11555
11556 name_buf[0] = 't';
11557 name_buf[1] = '_';
11558 name_buf[2] = str[0];
11559 name_buf[3] = str[1];
11560 name_buf[4] = NUL;
11561
11562 match = FALSE;
11563 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11564 match = TRUE;
11565 else
11566 {
11567 name_buf[0] = '<';
11568 name_buf[1] = 't';
11569 name_buf[2] = '_';
11570 name_buf[3] = str[0];
11571 name_buf[4] = str[1];
11572 name_buf[5] = '>';
11573 name_buf[6] = NUL;
11574
11575 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11576 match = TRUE;
11577 }
11578 if (match)
11579 {
11580 if (loop == 0)
11581 num_term++;
11582 else
11583 (*file)[count++] = vim_strsave(name_buf);
11584 }
11585 }
11586
11587 /*
11588 * Check special key names.
11589 */
11590 regmatch->rm_ic = TRUE; /* ignore case here */
11591 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11592 {
11593 name_buf[0] = '<';
11594 STRCPY(name_buf + 1, str);
11595 STRCAT(name_buf, ">");
11596
11597 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11598 {
11599 if (loop == 0)
11600 num_term++;
11601 else
11602 (*file)[count++] = vim_strsave(name_buf);
11603 }
11604 }
11605 }
11606 if (loop == 0)
11607 {
11608 if (num_normal > 0)
11609 *num_file = num_normal;
11610 else if (num_term > 0)
11611 *num_file = num_term;
11612 else
11613 return OK;
11614 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11615 if (*file == NULL)
11616 {
11617 *file = (char_u **)"";
11618 return FAIL;
11619 }
11620 }
11621 }
11622 return OK;
11623}
11624
11625 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011626ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011627{
11628 char_u *var = NULL; /* init for GCC */
11629 char_u *buf;
11630
11631 *num_file = 0;
11632 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11633 if (*file == NULL)
11634 return FAIL;
11635
11636 /*
11637 * For a terminal key code expand_option_idx is < 0.
11638 */
11639 if (expand_option_idx < 0)
11640 {
11641 var = find_termcode(expand_option_name + 2);
11642 if (var == NULL)
11643 expand_option_idx = findoption(expand_option_name);
11644 }
11645
11646 if (expand_option_idx >= 0)
11647 {
11648 /* put string of option value in NameBuff */
11649 option_value2string(&options[expand_option_idx], expand_option_flags);
11650 var = NameBuff;
11651 }
11652 else if (var == NULL)
11653 var = (char_u *)"";
11654
11655 /* A backslash is required before some characters. This is the reverse of
11656 * what happens in do_set(). */
11657 buf = vim_strsave_escaped(var, escape_chars);
11658
11659 if (buf == NULL)
11660 {
11661 vim_free(*file);
11662 *file = NULL;
11663 return FAIL;
11664 }
11665
11666#ifdef BACKSLASH_IN_FILENAME
11667 /* For MS-Windows et al. we don't double backslashes at the start and
11668 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011669 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011670 if (var[0] == '\\' && var[1] == '\\'
11671 && expand_option_idx >= 0
11672 && (options[expand_option_idx].flags & P_EXPAND)
11673 && vim_isfilec(var[2])
11674 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011675 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011676#endif
11677
11678 *file[0] = buf;
11679 *num_file = 1;
11680 return OK;
11681}
11682#endif
11683
11684/*
11685 * Get the value for the numeric or string option *opp in a nice format into
11686 * NameBuff[]. Must not be called with a hidden option!
11687 */
11688 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011689option_value2string(
11690 struct vimoption *opp,
11691 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011692{
11693 char_u *varp;
11694
11695 varp = get_varp_scope(opp, opt_flags);
11696
11697 if (opp->flags & P_NUM)
11698 {
11699 long wc = 0;
11700
11701 if (wc_use_keyname(varp, &wc))
11702 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11703 else if (wc != 0)
11704 STRCPY(NameBuff, transchar((int)wc));
11705 else
11706 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11707 }
11708 else /* P_STRING */
11709 {
11710 varp = *(char_u **)(varp);
11711 if (varp == NULL) /* just in case */
11712 NameBuff[0] = NUL;
11713#ifdef FEAT_CRYPT
11714 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011715 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011716 STRCPY(NameBuff, "*****");
11717#endif
11718 else if (opp->flags & P_EXPAND)
11719 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11720 /* Translate 'pastetoggle' into special key names */
11721 else if ((char_u **)opp->var == &p_pt)
11722 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11723 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011724 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011725 }
11726}
11727
11728/*
11729 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11730 * printed as a keyname.
11731 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11732 */
11733 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011734wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011735{
11736 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11737 {
11738 *wcp = *(long *)varp;
11739 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11740 return TRUE;
11741 }
11742 return FALSE;
11743}
11744
Bram Moolenaar01615492015-02-03 13:00:38 +010011745#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011746/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011747 * Any character has an equivalent 'langmap' character. This is used for
11748 * keyboards that have a special language mode that sends characters above
11749 * 128 (although other characters can be translated too). The "to" field is a
11750 * Vim command character. This avoids having to switch the keyboard back to
11751 * ASCII mode when leaving Insert mode.
11752 *
11753 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11754 * commands.
11755 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11756 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11757 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011758 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011759# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011760/*
11761 * With multi-byte support use growarray for 'langmap' chars >= 256
11762 */
11763typedef struct
11764{
11765 int from;
11766 int to;
11767} langmap_entry_T;
11768
11769static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011770static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011771
11772/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011773 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11774 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011775 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011776 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011777langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011778{
11779 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011780 int a = 0;
11781 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011782
11783 /* Do a binary search for an existing entry. */
11784 while (a != b)
11785 {
11786 int i = (a + b) / 2;
11787 int d = entries[i].from - from;
11788
11789 if (d == 0)
11790 {
11791 entries[i].to = to;
11792 return;
11793 }
11794 if (d < 0)
11795 a = i + 1;
11796 else
11797 b = i;
11798 }
11799
11800 if (ga_grow(&langmap_mapga, 1) != OK)
11801 return; /* out of memory */
11802
11803 /* insert new entry at position "a" */
11804 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11805 mch_memmove(entries + 1, entries,
11806 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11807 ++langmap_mapga.ga_len;
11808 entries[0].from = from;
11809 entries[0].to = to;
11810}
11811
11812/*
11813 * Apply 'langmap' to multi-byte character "c" and return the result.
11814 */
11815 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011816langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011817{
11818 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11819 int a = 0;
11820 int b = langmap_mapga.ga_len;
11821
11822 while (a != b)
11823 {
11824 int i = (a + b) / 2;
11825 int d = entries[i].from - c;
11826
11827 if (d == 0)
11828 return entries[i].to; /* found matching entry */
11829 if (d < 0)
11830 a = i + 1;
11831 else
11832 b = i;
11833 }
11834 return c; /* no entry found, return "c" unmodified */
11835}
11836# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011837
11838 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011839langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011840{
11841 int i;
11842
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011843 for (i = 0; i < 256; i++)
11844 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11845# ifdef FEAT_MBYTE
11846 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11847# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011848}
11849
11850/*
11851 * Called when langmap option is set; the language map can be
11852 * changed at any time!
11853 */
11854 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011855langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011856{
11857 char_u *p;
11858 char_u *p2;
11859 int from, to;
11860
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011861#ifdef FEAT_MBYTE
11862 ga_clear(&langmap_mapga); /* clear the previous map first */
11863#endif
11864 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011865
11866 for (p = p_langmap; p[0] != NUL; )
11867 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011868 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011869 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011870 {
11871 if (p2[0] == '\\' && p2[1] != NUL)
11872 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011873 }
11874 if (p2[0] == ';')
11875 ++p2; /* abcd;ABCD form, p2 points to A */
11876 else
11877 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11878 while (p[0])
11879 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011880 if (p[0] == ',')
11881 {
11882 ++p;
11883 break;
11884 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011885 if (p[0] == '\\' && p[1] != NUL)
11886 ++p;
11887#ifdef FEAT_MBYTE
11888 from = (*mb_ptr2char)(p);
11889#else
11890 from = p[0];
11891#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011892 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011893 if (p2 == NULL)
11894 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011895 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011896 if (p[0] != ',')
11897 {
11898 if (p[0] == '\\')
11899 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011900#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011901 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011902#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011903 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011904#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011905 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011906 }
11907 else
11908 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011909 if (p2[0] != ',')
11910 {
11911 if (p2[0] == '\\')
11912 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011913#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011914 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011915#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011916 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011917#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011918 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011919 }
11920 if (to == NUL)
11921 {
11922 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11923 transchar(from));
11924 return;
11925 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011926
11927#ifdef FEAT_MBYTE
11928 if (from >= 256)
11929 langmap_set_entry(from, to);
11930 else
11931#endif
11932 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011933
11934 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011935 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011936 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011937 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011938 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011939 if (*p == ';')
11940 {
11941 p = p2;
11942 if (p[0] != NUL)
11943 {
11944 if (p[0] != ',')
11945 {
11946 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11947 return;
11948 }
11949 ++p;
11950 }
11951 break;
11952 }
11953 }
11954 }
11955 }
11956}
11957#endif
11958
11959/*
11960 * Return TRUE if format option 'x' is in effect.
11961 * Take care of no formatting when 'paste' is set.
11962 */
11963 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011964has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011965{
11966 if (p_paste)
11967 return FALSE;
11968 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11969}
11970
11971/*
11972 * Return TRUE if "x" is present in 'shortmess' option, or
11973 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11974 */
11975 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011976shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011977{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011978 return p_shm != NULL &&
11979 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011980 || (vim_strchr(p_shm, 'a') != NULL
11981 && vim_strchr((char_u *)SHM_A, x) != NULL));
11982}
11983
11984/*
11985 * paste_option_changed() - Called after p_paste was set or reset.
11986 */
11987 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011988paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011989{
11990 static int old_p_paste = FALSE;
11991 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011992 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011993#ifdef FEAT_CMDL_INFO
11994 static int save_ru = 0;
11995#endif
11996#ifdef FEAT_RIGHTLEFT
11997 static int save_ri = 0;
11998 static int save_hkmap = 0;
11999#endif
12000 buf_T *buf;
12001
12002 if (p_paste)
12003 {
12004 /*
12005 * Paste switched from off to on.
12006 * Save the current values, so they can be restored later.
12007 */
12008 if (!old_p_paste)
12009 {
12010 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012011 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012012 {
12013 buf->b_p_tw_nopaste = buf->b_p_tw;
12014 buf->b_p_wm_nopaste = buf->b_p_wm;
12015 buf->b_p_sts_nopaste = buf->b_p_sts;
12016 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012017 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012018 }
12019
12020 /* save global options */
12021 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012022 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012023#ifdef FEAT_CMDL_INFO
12024 save_ru = p_ru;
12025#endif
12026#ifdef FEAT_RIGHTLEFT
12027 save_ri = p_ri;
12028 save_hkmap = p_hkmap;
12029#endif
12030 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012031 p_ai_nopaste = p_ai;
12032 p_et_nopaste = p_et;
12033 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012034 p_tw_nopaste = p_tw;
12035 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012036 }
12037
12038 /*
12039 * Always set the option values, also when 'paste' is set when it is
12040 * already on.
12041 */
12042 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012043 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012044 {
12045 buf->b_p_tw = 0; /* textwidth is 0 */
12046 buf->b_p_wm = 0; /* wrapmargin is 0 */
12047 buf->b_p_sts = 0; /* softtabstop is 0 */
12048 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012049 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012050 }
12051
12052 /* set global options */
12053 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012054 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012055#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012056 if (p_ru)
12057 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012058 p_ru = 0; /* no ruler */
12059#endif
12060#ifdef FEAT_RIGHTLEFT
12061 p_ri = 0; /* no reverse insert */
12062 p_hkmap = 0; /* no Hebrew keyboard */
12063#endif
12064 /* set global values for local buffer options */
12065 p_tw = 0;
12066 p_wm = 0;
12067 p_sts = 0;
12068 p_ai = 0;
12069 }
12070
12071 /*
12072 * Paste switched from on to off: Restore saved values.
12073 */
12074 else if (old_p_paste)
12075 {
12076 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012077 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012078 {
12079 buf->b_p_tw = buf->b_p_tw_nopaste;
12080 buf->b_p_wm = buf->b_p_wm_nopaste;
12081 buf->b_p_sts = buf->b_p_sts_nopaste;
12082 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012083 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012084 }
12085
12086 /* restore global options */
12087 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012088 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012089#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012090 if (p_ru != save_ru)
12091 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012092 p_ru = save_ru;
12093#endif
12094#ifdef FEAT_RIGHTLEFT
12095 p_ri = save_ri;
12096 p_hkmap = save_hkmap;
12097#endif
12098 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012099 p_ai = p_ai_nopaste;
12100 p_et = p_et_nopaste;
12101 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012102 p_tw = p_tw_nopaste;
12103 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012104 }
12105
12106 old_p_paste = p_paste;
12107}
12108
12109/*
12110 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12111 *
12112 * Reset 'compatible' and set the values for options that didn't get set yet
12113 * to the Vim defaults.
12114 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012115 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012116 */
12117 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012118vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012119{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012120 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012121 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012122 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012123
12124 if (!option_was_set((char_u *)"cp"))
12125 {
12126 p_cp = FALSE;
12127 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12128 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12129 set_option_default(opt_idx, OPT_FREE, FALSE);
12130 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012131 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012132 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012133
12134 if (fname != NULL)
12135 {
12136 p = vim_getenv(envname, &dofree);
12137 if (p == NULL)
12138 {
12139 /* Set $MYVIMRC to the first vimrc file found. */
12140 p = FullName_save(fname, FALSE);
12141 if (p != NULL)
12142 {
12143 vim_setenv(envname, p);
12144 vim_free(p);
12145 }
12146 }
12147 else if (dofree)
12148 vim_free(p);
12149 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012150}
12151
12152/*
12153 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12154 */
12155 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012156change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012157{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012158 int opt_idx;
12159
Bram Moolenaar071d4272004-06-13 20:20:40 +000012160 if (p_cp != on)
12161 {
12162 p_cp = on;
12163 compatible_set();
12164 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012165 opt_idx = findoption((char_u *)"cp");
12166 if (opt_idx >= 0)
12167 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012168}
12169
12170/*
12171 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012172 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012173 */
12174 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012175option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012176{
12177 int idx;
12178
12179 idx = findoption(name);
12180 if (idx < 0) /* unknown option */
12181 return FALSE;
12182 if (options[idx].flags & P_WAS_SET)
12183 return TRUE;
12184 return FALSE;
12185}
12186
12187/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012188 * Reset the flag indicating option "name" was set.
12189 */
12190 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012191reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012192{
12193 int idx = findoption(name);
12194
12195 if (idx >= 0)
12196 options[idx].flags &= ~P_WAS_SET;
12197}
12198
12199/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012200 * compatible_set() - Called when 'compatible' has been set or unset.
12201 *
12202 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12203 * flag) to a Vi compatible value.
12204 * When 'compatible' is unset: Set all options that have a different default
12205 * for Vim (without the P_VI_DEF flag) to that default.
12206 */
12207 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012208compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012209{
12210 int opt_idx;
12211
12212 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12213 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12214 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12215 set_option_default(opt_idx, OPT_FREE, p_cp);
12216 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012217 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012218}
12219
12220#ifdef FEAT_LINEBREAK
12221
12222# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12223 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012224 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012225# endif
12226
12227/*
12228 * fill_breakat_flags() -- called when 'breakat' changes value.
12229 */
12230 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012231fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012232{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012233 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012234 int i;
12235
12236 for (i = 0; i < 256; i++)
12237 breakat_flags[i] = FALSE;
12238
12239 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012240 for (p = p_breakat; *p; p++)
12241 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012242}
12243
12244# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012245 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012246# endif
12247
12248#endif
12249
12250/*
12251 * Check an option that can be a range of string values.
12252 *
12253 * Return OK for correct value, FAIL otherwise.
12254 * Empty is always OK.
12255 */
12256 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012257check_opt_strings(
12258 char_u *val,
12259 char **values,
12260 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012261{
12262 return opt_strings_flags(val, values, NULL, list);
12263}
12264
12265/*
12266 * Handle an option that can be a range of string values.
12267 * Set a flag in "*flagp" for each string present.
12268 *
12269 * Return OK for correct value, FAIL otherwise.
12270 * Empty is always OK.
12271 */
12272 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012273opt_strings_flags(
12274 char_u *val, /* new value */
12275 char **values, /* array of valid string values */
12276 unsigned *flagp,
12277 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012278{
12279 int i;
12280 int len;
12281 unsigned new_flags = 0;
12282
12283 while (*val)
12284 {
12285 for (i = 0; ; ++i)
12286 {
12287 if (values[i] == NULL) /* val not found in values[] */
12288 return FAIL;
12289
12290 len = (int)STRLEN(values[i]);
12291 if (STRNCMP(values[i], val, len) == 0
12292 && ((list && val[len] == ',') || val[len] == NUL))
12293 {
12294 val += len + (val[len] == ',');
12295 new_flags |= (1 << i);
12296 break; /* check next item in val list */
12297 }
12298 }
12299 }
12300 if (flagp != NULL)
12301 *flagp = new_flags;
12302
12303 return OK;
12304}
12305
12306/*
12307 * Read the 'wildmode' option, fill wim_flags[].
12308 */
12309 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012310check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012311{
12312 char_u new_wim_flags[4];
12313 char_u *p;
12314 int i;
12315 int idx = 0;
12316
12317 for (i = 0; i < 4; ++i)
12318 new_wim_flags[i] = 0;
12319
12320 for (p = p_wim; *p; ++p)
12321 {
12322 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12323 ;
12324 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12325 return FAIL;
12326 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12327 new_wim_flags[idx] |= WIM_LONGEST;
12328 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12329 new_wim_flags[idx] |= WIM_FULL;
12330 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12331 new_wim_flags[idx] |= WIM_LIST;
12332 else
12333 return FAIL;
12334 p += i;
12335 if (*p == NUL)
12336 break;
12337 if (*p == ',')
12338 {
12339 if (idx == 3)
12340 return FAIL;
12341 ++idx;
12342 }
12343 }
12344
12345 /* fill remaining entries with last flag */
12346 while (idx < 3)
12347 {
12348 new_wim_flags[idx + 1] = new_wim_flags[idx];
12349 ++idx;
12350 }
12351
12352 /* only when there are no errors, wim_flags[] is changed */
12353 for (i = 0; i < 4; ++i)
12354 wim_flags[i] = new_wim_flags[i];
12355 return OK;
12356}
12357
12358/*
12359 * Check if backspacing over something is allowed.
12360 */
12361 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012362can_bs(
12363 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012364{
12365 switch (*p_bs)
12366 {
12367 case '2': return TRUE;
12368 case '1': return (what != BS_START);
12369 case '0': return FALSE;
12370 }
12371 return vim_strchr(p_bs, what) != NULL;
12372}
12373
12374/*
12375 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12376 * the file must be considered changed when the value is different.
12377 */
12378 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012379save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012380{
12381 buf->b_start_ffc = *buf->b_p_ff;
12382 buf->b_start_eol = buf->b_p_eol;
12383#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012384 buf->b_start_bomb = buf->b_p_bomb;
12385
Bram Moolenaar071d4272004-06-13 20:20:40 +000012386 /* Only use free/alloc when necessary, they take time. */
12387 if (buf->b_start_fenc == NULL
12388 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12389 {
12390 vim_free(buf->b_start_fenc);
12391 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12392 }
12393#endif
12394}
12395
12396/*
12397 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12398 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012399 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12400 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012401 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012402 * When "ignore_empty" is true don't consider a new, empty buffer to be
12403 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012404 */
12405 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012406file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012407{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012408 /* In a buffer that was never loaded the options are not valid. */
12409 if (buf->b_flags & BF_NEVERLOADED)
12410 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012411 if (ignore_empty
12412 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012413 && buf->b_ml.ml_line_count == 1
12414 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12415 return FALSE;
12416 if (buf->b_start_ffc != *buf->b_p_ff)
12417 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012418 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012419 return TRUE;
12420#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012421 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12422 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012423 if (buf->b_start_fenc == NULL)
12424 return (*buf->b_p_fenc != NUL);
12425 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12426#else
12427 return FALSE;
12428#endif
12429}
12430
12431/*
12432 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12433 */
12434 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012435check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012436{
12437 return check_opt_strings(p, p_ff_values, FALSE);
12438}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012439
12440/*
12441 * Return the effective shiftwidth value for current buffer, using the
12442 * 'tabstop' value when 'shiftwidth' is zero.
12443 */
12444 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012445get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012446{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012447 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012448}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012449
12450/*
12451 * Return the effective softtabstop value for the current buffer, using the
12452 * 'tabstop' value when 'softtabstop' is negative.
12453 */
12454 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012455get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012456{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012457 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012458}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012459
12460/*
12461 * Check matchpairs option for "*initc".
12462 * If there is a match set "*initc" to the matching character and "*findc" to
12463 * the opposite character. Set "*backwards" to the direction.
12464 * When "switchit" is TRUE swap the direction.
12465 */
12466 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012467find_mps_values(
12468 int *initc,
12469 int *findc,
12470 int *backwards,
12471 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012472{
12473 char_u *ptr;
12474
12475 ptr = curbuf->b_p_mps;
12476 while (*ptr != NUL)
12477 {
12478#ifdef FEAT_MBYTE
12479 if (has_mbyte)
12480 {
12481 char_u *prev;
12482
12483 if (mb_ptr2char(ptr) == *initc)
12484 {
12485 if (switchit)
12486 {
12487 *findc = *initc;
12488 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12489 *backwards = TRUE;
12490 }
12491 else
12492 {
12493 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12494 *backwards = FALSE;
12495 }
12496 return;
12497 }
12498 prev = ptr;
12499 ptr += mb_ptr2len(ptr) + 1;
12500 if (mb_ptr2char(ptr) == *initc)
12501 {
12502 if (switchit)
12503 {
12504 *findc = *initc;
12505 *initc = mb_ptr2char(prev);
12506 *backwards = FALSE;
12507 }
12508 else
12509 {
12510 *findc = mb_ptr2char(prev);
12511 *backwards = TRUE;
12512 }
12513 return;
12514 }
12515 ptr += mb_ptr2len(ptr);
12516 }
12517 else
12518#endif
12519 {
12520 if (*ptr == *initc)
12521 {
12522 if (switchit)
12523 {
12524 *backwards = TRUE;
12525 *findc = *initc;
12526 *initc = ptr[2];
12527 }
12528 else
12529 {
12530 *backwards = FALSE;
12531 *findc = ptr[2];
12532 }
12533 return;
12534 }
12535 ptr += 2;
12536 if (*ptr == *initc)
12537 {
12538 if (switchit)
12539 {
12540 *backwards = FALSE;
12541 *findc = *initc;
12542 *initc = ptr[-2];
12543 }
12544 else
12545 {
12546 *backwards = TRUE;
12547 *findc = ptr[-2];
12548 }
12549 return;
12550 }
12551 ++ptr;
12552 }
12553 if (*ptr == ',')
12554 ++ptr;
12555 }
12556}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012557
12558#if defined(FEAT_LINEBREAK) || defined(PROTO)
12559/*
12560 * This is called when 'breakindentopt' is changed and when a window is
12561 * initialized.
12562 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012563 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012564briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012565{
12566 char_u *p;
12567 int bri_shift = 0;
12568 long bri_min = 20;
12569 int bri_sbr = FALSE;
12570
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012571 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012572 while (*p != NUL)
12573 {
12574 if (STRNCMP(p, "shift:", 6) == 0
12575 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12576 {
12577 p += 6;
12578 bri_shift = getdigits(&p);
12579 }
12580 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12581 {
12582 p += 4;
12583 bri_min = getdigits(&p);
12584 }
12585 else if (STRNCMP(p, "sbr", 3) == 0)
12586 {
12587 p += 3;
12588 bri_sbr = TRUE;
12589 }
12590 if (*p != ',' && *p != NUL)
12591 return FAIL;
12592 if (*p == ',')
12593 ++p;
12594 }
12595
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012596 wp->w_p_brishift = bri_shift;
12597 wp->w_p_brimin = bri_min;
12598 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012599
12600 return OK;
12601}
12602#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012603
12604/*
12605 * Get the local or global value of 'backupcopy'.
12606 */
12607 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012608get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012609{
12610 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12611}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012612
12613#if defined(FEAT_SIGNS) || defined(PROTO)
12614/*
12615 * Return TRUE when window "wp" has a column to draw signs in.
12616 */
12617 int
12618signcolumn_on(win_T *wp)
12619{
12620 if (*wp->w_p_scl == 'n')
12621 return FALSE;
12622 if (*wp->w_p_scl == 'y')
12623 return TRUE;
12624 return (wp->w_buffer->b_signlist != NULL
12625# ifdef FEAT_NETBEANS_INTG
12626 || wp->w_buffer->b_has_sign_column
12627# endif
12628 );
12629}
12630#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012631
12632#if defined(FEAT_EVAL) || defined(PROTO)
12633/*
12634 * Get window or buffer local options.
12635 */
12636 dict_T *
12637get_winbuf_options(int bufopt)
12638{
12639 dict_T *d;
12640 int opt_idx;
12641
12642 d = dict_alloc();
12643 if (d == NULL)
12644 return NULL;
12645
12646 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12647 {
12648 struct vimoption *opt = &options[opt_idx];
12649
12650 if ((bufopt && (opt->indir & PV_BUF))
12651 || (!bufopt && (opt->indir & PV_WIN)))
12652 {
12653 char_u *varp = get_varp(opt);
12654
12655 if (varp != NULL)
12656 {
12657 if (opt->flags & P_STRING)
12658 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012659 else if (opt->flags & P_NUM)
12660 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012661 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012662 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012663 }
12664 }
12665 }
12666
12667 return d;
12668}
12669#endif